diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2014-07-31 00:04:55 +0200 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2014-07-31 00:07:47 +0200 |
commit | e8cb5c30b0db15a1c6786d6575098a66320ffec4 (patch) | |
tree | b6a8dd7c90fb418e3d54a66309bcae3aa5e9c1b4 /src | |
parent | 1de2992e0786f4de0f0cae10eb27a3b69ec6e3de (diff) | |
parent | 714a3e6505d986d064d3a34038a724ac1cad5308 (diff) |
Merge pull request #4497
714a3e6 Only keep setBlockIndexValid entries that are possible improvements (Pieter Wuille)
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/main.cpp b/src/main.cpp index 85e0851895..353cde0bd7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -95,7 +95,9 @@ namespace { }; CBlockIndex *pindexBestInvalid; - // may contain all CBlockIndex*'s that have validness >=BLOCK_VALID_TRANSACTIONS, and must contain those who aren't failed + + // The set of all CBlockIndex entries with BLOCK_VALID_TRANSACTIONS or better that are at least + // as good as our current tip. Entries may be failed, though. set<CBlockIndex*, CBlockIndexWorkComparator> setBlockIndexValid; CCriticalSection cs_LastBlockFile; @@ -2097,6 +2099,15 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo return false; } } else { + // Delete all entries in setBlockIndexValid that are worse than our new current block. + // 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. + std::set<CBlockIndex*, CBlockIndexWorkComparator>::iterator it = setBlockIndexValid.begin(); + while (setBlockIndexValid.value_comp()(*it, chainActive.Tip())) { + setBlockIndexValid.erase(it++); + } + // Either the current tip or a successor of it we're working towards is left in setBlockIndexValid. + assert(!setBlockIndexValid.empty()); if (!pindexOldTip || chainActive.Tip()->nChainWork > pindexOldTip->nChainWork) { // We're in a better position than we were. Return temporarily to release the lock. break; |