Skip to content

Commit

Permalink
Delay writing block indexes in invalidate/reconsider
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa committed Nov 26, 2014
1 parent 9b0a8d3 commit 0dd06b2
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2140,17 +2140,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.
Expand Down Expand Up @@ -2183,9 +2179,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);
}
Expand All @@ -2199,9 +2193,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;
}
Expand Down

0 comments on commit 0dd06b2

Please sign in to comment.