mirror of https://github.com/bitcoin/bitcoin.git
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.
Github-Pull: #33212
Rebased-From: 01b95ac6f4
This commit is contained in:
parent
027a60d218
commit
16b1710d97
|
@ -253,18 +253,13 @@ bool BaseIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* new_ti
|
|||
return false;
|
||||
}
|
||||
|
||||
// In the case of a reorg, ensure persisted block locator is not stale.
|
||||
// Don't commit here - the committed index state must never be ahead of the
|
||||
// flushed chainstate, otherwise unclean restarts would lead to index corruption.
|
||||
// Pruning has a minimum of 288 blocks-to-keep and getting the index
|
||||
// out of sync may be possible but a users fault.
|
||||
// In case we reorg beyond the pruned depth, ReadBlock would
|
||||
// throw and lead to a graceful shutdown
|
||||
SetBestBlockIndex(new_tip);
|
||||
if (!Commit()) {
|
||||
// If commit fails, revert the best block index to avoid corruption.
|
||||
SetBestBlockIndex(current_tip);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue