Skip to content

Commit 3dd8ed7

Browse files
committed
Delay writing block indexes in invalidate/reconsider
1 parent 798faec commit 3dd8ed7

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
@@ -2137,17 +2137,13 @@ bool InvalidateBlock(CValidationState& state, CBlockIndex *pindex) {
21372137

21382138
// Mark the block itself as invalid.
21392139
pindex->nStatus |= BLOCK_FAILED_VALID;
2140-
if (!pblocktree->WriteBlockIndex(CDiskBlockIndex(pindex))) {
2141-
return state.Abort("Failed to update block index");
2142-
}
2140+
setDirtyBlockIndex.insert(pindex);
21432141
setBlockIndexCandidates.erase(pindex);
21442142

21452143
while (chainActive.Contains(pindex)) {
21462144
CBlockIndex *pindexWalk = chainActive.Tip();
21472145
pindexWalk->nStatus |= BLOCK_FAILED_CHILD;
2148-
if (!pblocktree->WriteBlockIndex(CDiskBlockIndex(pindexWalk))) {
2149-
return state.Abort("Failed to update block index");
2150-
}
2146+
setDirtyBlockIndex.insert(pindexWalk);
21512147
setBlockIndexCandidates.erase(pindexWalk);
21522148
// ActivateBestChain considers blocks already in chainActive
21532149
// unconditionally valid already, so force disconnect away from it.
@@ -2180,9 +2176,7 @@ bool ReconsiderBlock(CValidationState& state, CBlockIndex *pindex) {
21802176
while (it != mapBlockIndex.end()) {
21812177
if (!it->second->IsValid() && it->second->GetAncestor(nHeight) == pindex) {
21822178
it->second->nStatus &= ~BLOCK_FAILED_MASK;
2183-
if (!pblocktree->WriteBlockIndex(CDiskBlockIndex(pindex))) {
2184-
return state.Abort("Failed to update block index");
2185-
}
2179+
setDirtyBlockIndex.insert(it->second);
21862180
if (it->second->IsValid(BLOCK_VALID_TRANSACTIONS) && it->second->nChainTx && setBlockIndexCandidates.value_comp()(chainActive.Tip(), it->second)) {
21872181
setBlockIndexCandidates.insert(it->second);
21882182
}
@@ -2196,9 +2190,9 @@ bool ReconsiderBlock(CValidationState& state, CBlockIndex *pindex) {
21962190

21972191
// Remove the invalidity flag from all ancestors too.
21982192
while (pindex != NULL) {
2199-
pindex->nStatus &= ~BLOCK_FAILED_MASK;
2200-
if (!pblocktree->WriteBlockIndex(CDiskBlockIndex(pindex))) {
2201-
return state.Abort("Failed to update block index");
2193+
if (pindex->nStatus & BLOCK_FAILED_MASK) {
2194+
pindex->nStatus &= ~BLOCK_FAILED_MASK;
2195+
setDirtyBlockIndex.insert(pindex);
22022196
}
22032197
pindex = pindex->pprev;
22042198
}

0 commit comments

Comments
 (0)