Skip to content

Commit 2a69647

Browse files
committed
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.
1 parent 9c300cc commit 2a69647

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/validation.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2770,7 +2770,7 @@ static SynchronizationState GetSynchronizationState(bool init)
27702770
return SynchronizationState::INIT_DOWNLOAD;
27712771
}
27722772

2773-
static bool NotifyHeaderTip() LOCKS_EXCLUDED(cs_main) {
2773+
static bool NotifyHeaderTip(CChainState& chainstate) LOCKS_EXCLUDED(cs_main) {
27742774
bool fNotify = false;
27752775
bool fInitialBlockDownload = false;
27762776
static CBlockIndex* pindexHeaderOld = nullptr;
@@ -2781,7 +2781,8 @@ static bool NotifyHeaderTip() LOCKS_EXCLUDED(cs_main) {
27812781

27822782
if (pindexHeader != pindexHeaderOld) {
27832783
fNotify = true;
2784-
fInitialBlockDownload = ::ChainstateActive().IsInitialBlockDownload();
2784+
assert(std::addressof(::ChainstateActive()) == std::addressof(chainstate));
2785+
fInitialBlockDownload = chainstate.IsInitialBlockDownload();
27852786
pindexHeaderOld = pindexHeader;
27862787
}
27872788
}
@@ -3664,7 +3665,7 @@ bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>&
36643665
}
36653666
}
36663667
}
3667-
if (NotifyHeaderTip()) {
3668+
if (NotifyHeaderTip(::ChainstateActive())) {
36683669
if (::ChainstateActive().IsInitialBlockDownload() && ppindex && *ppindex) {
36693670
LogPrintf("Synchronizing blockheaders, height: %d (~%.2f%%)\n", (*ppindex)->nHeight, 100.0/((*ppindex)->nHeight+(GetAdjustedTime() - (*ppindex)->GetBlockTime()) / Params().GetConsensus().nPowTargetSpacing) * (*ppindex)->nHeight);
36703671
}
@@ -3800,7 +3801,7 @@ bool ChainstateManager::ProcessNewBlock(const CChainParams& chainparams, const s
38003801
}
38013802
}
38023803

3803-
NotifyHeaderTip();
3804+
NotifyHeaderTip(::ChainstateActive());
38043805

38053806
BlockValidationState state; // Only used to report errors, not invalidity - ignore it
38063807
if (!::ChainstateActive().ActivateBestChain(state, chainparams, pblock))
@@ -4685,7 +4686,7 @@ void LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, FlatFi
46854686
}
46864687
}
46874688

4688-
NotifyHeaderTip();
4689+
NotifyHeaderTip(::ChainstateActive());
46894690

46904691
// Recursively process earlier encountered successors of this block
46914692
std::deque<uint256> queue;
@@ -4711,7 +4712,7 @@ void LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, FlatFi
47114712
}
47124713
range.first++;
47134714
mapBlocksUnknownParent.erase(it);
4714-
NotifyHeaderTip();
4715+
NotifyHeaderTip(::ChainstateActive());
47154716
}
47164717
}
47174718
} catch (const std::exception& e) {

0 commit comments

Comments
 (0)