Skip to content

Commit e18fd47

Browse files
committed
Merge bitcoin/bitcoin#25074: index: During sync, commit best block after indexing
7171ebc index: Don't commit a best block before indexing it during sync (Martin Zumsande) Pull request description: This changes the periodic commit of the best block during the index sync phase to use the already indexed predecessor of the current block index, instead of committing the current one that will only be indexed (by calling `WriteBlock()`) after committing the best block. The previous code would leave the index database in an inconsistent state until the block is actually indexed - if an unclean shutdown happened at just this point in time, the index could get corrupted because at next startup, we'd assume that we have already indexed this block. ACKs for top commit: ryanofsky: Code review ACK 7171ebc. Looks great! Just commit message changes since last review Tree-SHA512: a008de511dd6a1731b7fdf6a90add48d1e53f7f7d6402672adb83e362677fc5b9f5cd021d3111728cb41d73f1b9c2140db79d7e183df0ab359cda8c01b0ef928
2 parents 345d860 + 7171ebc commit e18fd47

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)