0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-02 09:46:52 -05:00

validation: Pass in chainstate to ::NotifyHeaderTip

[META] This commit should be followed up by removing the comments and
       assertions meant only to show that the change is correct.
This commit is contained in:
Carl Dong 2020-09-15 16:06:45 -04:00
parent 9c300cc8b3
commit 2a696472a1

View file

@ -2770,7 +2770,7 @@ static SynchronizationState GetSynchronizationState(bool init)
return SynchronizationState::INIT_DOWNLOAD;
}
static bool NotifyHeaderTip() LOCKS_EXCLUDED(cs_main) {
static bool NotifyHeaderTip(CChainState& chainstate) LOCKS_EXCLUDED(cs_main) {
bool fNotify = false;
bool fInitialBlockDownload = false;
static CBlockIndex* pindexHeaderOld = nullptr;
@ -2781,7 +2781,8 @@ static bool NotifyHeaderTip() LOCKS_EXCLUDED(cs_main) {
if (pindexHeader != pindexHeaderOld) {
fNotify = true;
fInitialBlockDownload = ::ChainstateActive().IsInitialBlockDownload();
assert(std::addressof(::ChainstateActive()) == std::addressof(chainstate));
fInitialBlockDownload = chainstate.IsInitialBlockDownload();
pindexHeaderOld = pindexHeader;
}
}
@ -3664,7 +3665,7 @@ bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>&
}
}
}
if (NotifyHeaderTip()) {
if (NotifyHeaderTip(::ChainstateActive())) {
if (::ChainstateActive().IsInitialBlockDownload() && ppindex && *ppindex) {
LogPrintf("Synchronizing blockheaders, height: %d (~%.2f%%)\n", (*ppindex)->nHeight, 100.0/((*ppindex)->nHeight+(GetAdjustedTime() - (*ppindex)->GetBlockTime()) / Params().GetConsensus().nPowTargetSpacing) * (*ppindex)->nHeight);
}
@ -3800,7 +3801,7 @@ bool ChainstateManager::ProcessNewBlock(const CChainParams& chainparams, const s
}
}
NotifyHeaderTip();
NotifyHeaderTip(::ChainstateActive());
BlockValidationState state; // Only used to report errors, not invalidity - ignore it
if (!::ChainstateActive().ActivateBestChain(state, chainparams, pblock))
@ -4685,7 +4686,7 @@ void LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, FlatFi
}
}
NotifyHeaderTip();
NotifyHeaderTip(::ChainstateActive());
// Recursively process earlier encountered successors of this block
std::deque<uint256> queue;
@ -4711,7 +4712,7 @@ void LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, FlatFi
}
range.first++;
mapBlocksUnknownParent.erase(it);
NotifyHeaderTip();
NotifyHeaderTip(::ChainstateActive());
}
}
} catch (const std::exception& e) {