Browse Source

Make PruneBlockIndexCandidates safer

0.10
Pieter Wuille 10 years ago
parent
commit
34559c7c73
  1. 6
      src/main.cpp

6
src/main.cpp

@ -1954,9 +1954,11 @@ static void PruneBlockIndexCandidates() {
// Note that we can't delete the current block itself, as we may need to return to it later in case a // Note that we can't delete the current block itself, as we may need to return to it later in case a
// reorganization to a better block fails. // reorganization to a better block fails.
std::set<CBlockIndex*, CBlockIndexWorkComparator>::iterator it = setBlockIndexCandidates.begin(); std::set<CBlockIndex*, CBlockIndexWorkComparator>::iterator it = setBlockIndexCandidates.begin();
while (setBlockIndexCandidates.value_comp()(*it, chainActive.Tip())) { while (it != setBlockIndexCandidates.end() && setBlockIndexCandidates.value_comp()(*it, chainActive.Tip())) {
setBlockIndexCandidates.erase(it++); setBlockIndexCandidates.erase(it++);
} }
// Either the current tip or a successor of it we're working towards is left in setBlockIndexCandidates.
assert(!setBlockIndexCandidates.empty());
} }
// Try to make some progress towards making pindexMostWork the active block. // Try to make some progress towards making pindexMostWork the active block.
@ -2007,8 +2009,6 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo
} }
} else { } else {
PruneBlockIndexCandidates(); PruneBlockIndexCandidates();
// Either the current tip or a successor of it we're working towards is left in setBlockIndexCandidates.
assert(!setBlockIndexCandidates.empty());
if (!pindexOldTip || chainActive.Tip()->nChainWork > pindexOldTip->nChainWork) { if (!pindexOldTip || chainActive.Tip()->nChainWork > pindexOldTip->nChainWork) {
// We're in a better position than we were. Return temporarily to release the lock. // We're in a better position than we were. Return temporarily to release the lock.
fContinue = false; fContinue = false;

Loading…
Cancel
Save