index: Don't commit a best block before indexing it during sync

Committing a block prior to indexing would leave the index database
in an inconsistent state until it is indexed, which could corrupt the
index in case of a unclean shutdown. Thus commit its predecessor.

Co-authored-by: Luke Dashjr <luke-jr+git@utopios.org>
This commit is contained in:
Martin Zumsande 2022-05-06 14:07:51 +02:00
parent 59ac8bacd5
commit 7171ebc7cb

View file

@ -168,7 +168,7 @@ void BaseIndex::ThreadSync()
}
if (last_locator_write_time + SYNC_LOCATOR_WRITE_INTERVAL < current_time) {
SetBestBlockIndex(pindex);
SetBestBlockIndex(pindex->pprev);
last_locator_write_time = current_time;
// No need to handle errors in Commit. See rationale above.
Commit();