Skip to content

Commit 01b95ac

Browse files
committed
index: don't commit state in BaseIndex::Rewind
The committed state of an index should never be ahead of the flushed chainstate. Otherwise, in the case of an unclean shutdown, the blocks necessary to revert from the prematurely committed state would not be available, which would corrupt the coinstatsindex in particular. Instead, the index state will be committed with the next ChainStateFlushed notification.
1 parent d31dc8f commit 01b95ac

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

src/index/base.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,18 +301,13 @@ bool BaseIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* new_ti
301301
}
302302
}
303303

304-
// In the case of a reorg, ensure persisted block locator is not stale.
304+
// Don't commit here - the committed index state must never be ahead of the
305+
// flushed chainstate, otherwise unclean restarts would lead to index corruption.
305306
// Pruning has a minimum of 288 blocks-to-keep and getting the index
306307
// out of sync may be possible but a users fault.
307308
// In case we reorg beyond the pruned depth, ReadBlock would
308309
// throw and lead to a graceful shutdown
309310
SetBestBlockIndex(new_tip);
310-
if (!Commit()) {
311-
// If commit fails, revert the best block index to avoid corruption.
312-
SetBestBlockIndex(current_tip);
313-
return false;
314-
}
315-
316311
return true;
317312
}
318313

0 commit comments

Comments
 (0)