Skip to content

Commit 7171ebc

Browse files
mzumsandeluke-jr
andcommitted
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 <[email protected]>
1 parent 59ac8ba commit 7171ebc

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/index/base.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ void BaseIndex::ThreadSync()
168168
}
169169

170170
if (last_locator_write_time + SYNC_LOCATOR_WRITE_INTERVAL < current_time) {
171-
SetBestBlockIndex(pindex);
171+
SetBestBlockIndex(pindex->pprev);
172172
last_locator_write_time = current_time;
173173
// No need to handle errors in Commit. See rationale above.
174174
Commit();

0 commit comments

Comments
 (0)