Skip to content

Commit 34559c7

Browse files
committed
Make PruneBlockIndexCandidates safer
1 parent cca48f6 commit 34559c7

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,9 +1954,11 @@ static void PruneBlockIndexCandidates() {
19541954
// Note that we can't delete the current block itself, as we may need to return to it later in case a
19551955
// reorganization to a better block fails.
19561956
std::set<CBlockIndex*, CBlockIndexWorkComparator>::iterator it = setBlockIndexCandidates.begin();
1957-
while (setBlockIndexCandidates.value_comp()(*it, chainActive.Tip())) {
1957+
while (it != setBlockIndexCandidates.end() && setBlockIndexCandidates.value_comp()(*it, chainActive.Tip())) {
19581958
setBlockIndexCandidates.erase(it++);
19591959
}
1960+
// Either the current tip or a successor of it we're working towards is left in setBlockIndexCandidates.
1961+
assert(!setBlockIndexCandidates.empty());
19601962
}
19611963

19621964
// Try to make some progress towards making pindexMostWork the active block.
@@ -2007,8 +2009,6 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo
20072009
}
20082010
} else {
20092011
PruneBlockIndexCandidates();
2010-
// Either the current tip or a successor of it we're working towards is left in setBlockIndexCandidates.
2011-
assert(!setBlockIndexCandidates.empty());
20122012
if (!pindexOldTip || chainActive.Tip()->nChainWork > pindexOldTip->nChainWork) {
20132013
// We're in a better position than we were. Return temporarily to release the lock.
20142014
fContinue = false;

0 commit comments

Comments
 (0)