diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2014-11-25 12:33:43 +0100 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2014-11-25 12:33:43 +0100 |
commit | 3dd8ed72e570e9289635cfb5c3c12c807c3e8c27 (patch) | |
tree | 51021659e60966e5351a7f8e9b5ad84d873710c3 | |
parent | 798faec3ea208166a5a4e0676b9b565ce9e59c1e (diff) |
Delay writing block indexes in invalidate/reconsider
-rw-r--r-- | src/main.cpp | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/main.cpp b/src/main.cpp index 025577a940..621f213338 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2137,17 +2137,13 @@ bool InvalidateBlock(CValidationState& state, CBlockIndex *pindex) { // Mark the block itself as invalid. pindex->nStatus |= BLOCK_FAILED_VALID; - if (!pblocktree->WriteBlockIndex(CDiskBlockIndex(pindex))) { - return state.Abort("Failed to update block index"); - } + setDirtyBlockIndex.insert(pindex); setBlockIndexCandidates.erase(pindex); while (chainActive.Contains(pindex)) { CBlockIndex *pindexWalk = chainActive.Tip(); pindexWalk->nStatus |= BLOCK_FAILED_CHILD; - if (!pblocktree->WriteBlockIndex(CDiskBlockIndex(pindexWalk))) { - return state.Abort("Failed to update block index"); - } + setDirtyBlockIndex.insert(pindexWalk); setBlockIndexCandidates.erase(pindexWalk); // ActivateBestChain considers blocks already in chainActive // unconditionally valid already, so force disconnect away from it. @@ -2180,9 +2176,7 @@ bool ReconsiderBlock(CValidationState& state, CBlockIndex *pindex) { while (it != mapBlockIndex.end()) { if (!it->second->IsValid() && it->second->GetAncestor(nHeight) == pindex) { it->second->nStatus &= ~BLOCK_FAILED_MASK; - if (!pblocktree->WriteBlockIndex(CDiskBlockIndex(pindex))) { - return state.Abort("Failed to update block index"); - } + setDirtyBlockIndex.insert(it->second); if (it->second->IsValid(BLOCK_VALID_TRANSACTIONS) && it->second->nChainTx && setBlockIndexCandidates.value_comp()(chainActive.Tip(), it->second)) { setBlockIndexCandidates.insert(it->second); } @@ -2196,9 +2190,9 @@ bool ReconsiderBlock(CValidationState& state, CBlockIndex *pindex) { // Remove the invalidity flag from all ancestors too. while (pindex != NULL) { - pindex->nStatus &= ~BLOCK_FAILED_MASK; - if (!pblocktree->WriteBlockIndex(CDiskBlockIndex(pindex))) { - return state.Abort("Failed to update block index"); + if (pindex->nStatus & BLOCK_FAILED_MASK) { + pindex->nStatus &= ~BLOCK_FAILED_MASK; + setDirtyBlockIndex.insert(pindex); } pindex = pindex->pprev; } |