@@ -1949,6 +1949,16 @@ static CBlockIndex* FindMostWorkChain() {
1949
1949
} while (true );
1950
1950
}
1951
1951
1952
+ // Delete all entries in setBlockIndexCandidates that are worse than the current tip.
1953
+ static void PruneBlockIndexCandidates () {
1954
+ // Note that we can't delete the current block itself, as we may need to return to it later in case a
1955
+ // reorganization to a better block fails.
1956
+ std::set<CBlockIndex*, CBlockIndexWorkComparator>::iterator it = setBlockIndexCandidates.begin ();
1957
+ while (setBlockIndexCandidates.value_comp ()(*it, chainActive.Tip ())) {
1958
+ setBlockIndexCandidates.erase (it++);
1959
+ }
1960
+ }
1961
+
1952
1962
// Try to make some progress towards making pindexMostWork the active block.
1953
1963
// pblock is either NULL or a pointer to a CBlock corresponding to pindexMostWork.
1954
1964
static bool ActivateBestChainStep (CValidationState &state, CBlockIndex *pindexMostWork, CBlock *pblock) {
@@ -1996,13 +2006,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo
1996
2006
return false ;
1997
2007
}
1998
2008
} else {
1999
- // Delete all entries in setBlockIndexCandidates that are worse than our new current block.
2000
- // Note that we can't delete the current block itself, as we may need to return to it later in case a
2001
- // reorganization to a better block fails.
2002
- std::set<CBlockIndex*, CBlockIndexWorkComparator>::iterator it = setBlockIndexCandidates.begin ();
2003
- while (setBlockIndexCandidates.value_comp ()(*it, chainActive.Tip ())) {
2004
- setBlockIndexCandidates.erase (it++);
2005
- }
2009
+ PruneBlockIndexCandidates ();
2006
2010
// Either the current tip or a successor of it we're working towards is left in setBlockIndexCandidates.
2007
2011
assert (!setBlockIndexCandidates.empty ());
2008
2012
if (!pindexOldTip || chainActive.Tip ()->nChainWork > pindexOldTip->nChainWork ) {
@@ -2860,6 +2864,9 @@ bool static LoadBlockIndexDB()
2860
2864
if (it == mapBlockIndex.end ())
2861
2865
return true ;
2862
2866
chainActive.SetTip (it->second );
2867
+
2868
+ PruneBlockIndexCandidates ();
2869
+
2863
2870
LogPrintf (" LoadBlockIndexDB(): hashBestChain=%s height=%d date=%s progress=%f\n " ,
2864
2871
chainActive.Tip ()->GetBlockHash ().ToString (), chainActive.Height (),
2865
2872
DateTimeStrFormat (" %Y-%m-%d %H:%M:%S" , chainActive.Tip ()->GetBlockTime ()),
0 commit comments