Skip to content

Commit 0dd06b2

Browse files
committed
Delay writing block indexes in invalidate/reconsider
1 parent 9b0a8d3 commit 0dd06b2

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/main.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,17 +2140,13 @@ bool InvalidateBlock(CValidationState& state, CBlockIndex *pindex) {
21402140

21412141
// Mark the block itself as invalid.
21422142
pindex->nStatus |= BLOCK_FAILED_VALID;
2143-
if (!pblocktree->WriteBlockIndex(CDiskBlockIndex(pindex))) {
2144-
return state.Abort("Failed to update block index");
2145-
}
2143+
setDirtyBlockIndex.insert(pindex);
21462144
setBlockIndexCandidates.erase(pindex);
21472145

21482146
while (chainActive.Contains(pindex)) {
21492147
CBlockIndex *pindexWalk = chainActive.Tip();
21502148
pindexWalk->nStatus |= BLOCK_FAILED_CHILD;
2151-
if (!pblocktree->WriteBlockIndex(CDiskBlockIndex(pindexWalk))) {
2152-
return state.Abort("Failed to update block index");
2153-
}
2149+
setDirtyBlockIndex.insert(pindexWalk);
21542150
setBlockIndexCandidates.erase(pindexWalk);
21552151
// ActivateBestChain considers blocks already in chainActive
21562152
// unconditionally valid already, so force disconnect away from it.
@@ -2183,9 +2179,7 @@ bool ReconsiderBlock(CValidationState& state, CBlockIndex *pindex) {
21832179
while (it != mapBlockIndex.end()) {
21842180
if (!it->second->IsValid() && it->second->GetAncestor(nHeight) == pindex) {
21852181
it->second->nStatus &= ~BLOCK_FAILED_MASK;
2186-
if (!pblocktree->WriteBlockIndex(CDiskBlockIndex(pindex))) {
2187-
return state.Abort("Failed to update block index");
2188-
}
2182+
setDirtyBlockIndex.insert(it->second);
21892183
if (it->second->IsValid(BLOCK_VALID_TRANSACTIONS) && it->second->nChainTx && setBlockIndexCandidates.value_comp()(chainActive.Tip(), it->second)) {
21902184
setBlockIndexCandidates.insert(it->second);
21912185
}
@@ -2199,9 +2193,9 @@ bool ReconsiderBlock(CValidationState& state, CBlockIndex *pindex) {
21992193

22002194
// Remove the invalidity flag from all ancestors too.
22012195
while (pindex != NULL) {
2202-
pindex->nStatus &= ~BLOCK_FAILED_MASK;
2203-
if (!pblocktree->WriteBlockIndex(CDiskBlockIndex(pindex))) {
2204-
return state.Abort("Failed to update block index");
2196+
if (pindex->nStatus & BLOCK_FAILED_MASK) {
2197+
pindex->nStatus &= ~BLOCK_FAILED_MASK;
2198+
setDirtyBlockIndex.insert(pindex);
22052199
}
22062200
pindex = pindex->pprev;
22072201
}

0 commit comments

Comments
 (0)