0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-03-06 14:19:59 -05:00

validation: Use existing chainstate in ChainstateManager::ProcessNewBlockHeaders

[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-08-26 14:42:01 -04:00
parent e0dc305727
commit ea4fed9021

View file

@ -3644,6 +3644,7 @@ bool BlockManager::AcceptBlockHeader(const CBlockHeader& block, BlockValidationS
// Exposed wrapper for AcceptBlockHeader // Exposed wrapper for AcceptBlockHeader
bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>& headers, BlockValidationState& state, const CChainParams& chainparams, const CBlockIndex** ppindex) bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>& headers, BlockValidationState& state, const CChainParams& chainparams, const CBlockIndex** ppindex)
{ {
assert(std::addressof(::ChainstateActive()) == std::addressof(ActiveChainstate()));
AssertLockNotHeld(cs_main); AssertLockNotHeld(cs_main);
{ {
LOCK(cs_main); LOCK(cs_main);
@ -3651,7 +3652,7 @@ bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>&
CBlockIndex *pindex = nullptr; // Use a temp pindex instead of ppindex to avoid a const_cast CBlockIndex *pindex = nullptr; // Use a temp pindex instead of ppindex to avoid a const_cast
bool accepted = m_blockman.AcceptBlockHeader( bool accepted = m_blockman.AcceptBlockHeader(
header, state, chainparams, &pindex); header, state, chainparams, &pindex);
::ChainstateActive().CheckBlockIndex(chainparams.GetConsensus()); ActiveChainstate().CheckBlockIndex(chainparams.GetConsensus());
if (!accepted) { if (!accepted) {
return false; return false;
@ -3661,8 +3662,8 @@ bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>&
} }
} }
} }
if (NotifyHeaderTip(::ChainstateActive())) { if (NotifyHeaderTip(ActiveChainstate())) {
if (::ChainstateActive().IsInitialBlockDownload() && ppindex && *ppindex) { if (ActiveChainstate().IsInitialBlockDownload() && ppindex && *ppindex) {
LogPrintf("Synchronizing blockheaders, height: %d (~%.2f%%)\n", (*ppindex)->nHeight, 100.0/((*ppindex)->nHeight+(GetAdjustedTime() - (*ppindex)->GetBlockTime()) / Params().GetConsensus().nPowTargetSpacing) * (*ppindex)->nHeight); LogPrintf("Synchronizing blockheaders, height: %d (~%.2f%%)\n", (*ppindex)->nHeight, 100.0/((*ppindex)->nHeight+(GetAdjustedTime() - (*ppindex)->GetBlockTime()) / Params().GetConsensus().nPowTargetSpacing) * (*ppindex)->nHeight);
} }
} }