Skip to content

Commit bf1b638

Browse files
committed
Merge bitcoin/bitcoin#29671: index: avoid "failed to commit" errors on initialization
f65b0f6 index: Move last_locator_write_time and logging to end of threadsync loop (Fabian Jahr) Pull request description: In the index sync thread, when initializing an index for the first time, stop callng BaseIndex::Commit when m_best_block_index is null, to avoid a spurious "failed to commit" error from that function. This error started happening in commit bitcoin/bitcoin@7878f97 from bitcoin/bitcoin#25494 and was reported by pstratem in bitcoin/bitcoin#26903 with an alternate fix. ACKs for top commit: achow101: ACK f65b0f6 ryanofsky: Code review ACK f65b0f6. Just moved log "Syncing" log line since last commit to avoid having to call now() twice. furszy: ACK f65b0f6 TheCharlatan: ACK f65b0f6 Tree-SHA512: afa8f05786318d36346d167ff53ea0b3bc8abdb0ad04465d199dc3eb91e9f837369e24fcb7e24b5757b02d698ec504e61da6ac365eaf006c874fc07a424a7e20
2 parents b50554b + f65b0f6 commit bf1b638

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/index/base.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,20 +174,6 @@ void BaseIndex::Sync()
174174
pindex = pindex_next;
175175

176176

177-
auto current_time{std::chrono::steady_clock::now()};
178-
if (last_log_time + SYNC_LOG_INTERVAL < current_time) {
179-
LogPrintf("Syncing %s with block chain from height %d\n",
180-
GetName(), pindex->nHeight);
181-
last_log_time = current_time;
182-
}
183-
184-
if (last_locator_write_time + SYNC_LOCATOR_WRITE_INTERVAL < current_time) {
185-
SetBestBlockIndex(pindex->pprev);
186-
last_locator_write_time = current_time;
187-
// No need to handle errors in Commit. See rationale above.
188-
Commit();
189-
}
190-
191177
CBlock block;
192178
interfaces::BlockInfo block_info = kernel::MakeBlockInfo(pindex);
193179
if (!m_chainstate->m_blockman.ReadBlockFromDisk(block, *pindex)) {
@@ -202,6 +188,20 @@ void BaseIndex::Sync()
202188
__func__, pindex->GetBlockHash().ToString());
203189
return;
204190
}
191+
192+
auto current_time{std::chrono::steady_clock::now()};
193+
if (last_log_time + SYNC_LOG_INTERVAL < current_time) {
194+
LogPrintf("Syncing %s with block chain from height %d\n",
195+
GetName(), pindex->nHeight);
196+
last_log_time = current_time;
197+
}
198+
199+
if (last_locator_write_time + SYNC_LOCATOR_WRITE_INTERVAL < current_time) {
200+
SetBestBlockIndex(pindex);
201+
last_locator_write_time = current_time;
202+
// No need to handle errors in Commit. See rationale above.
203+
Commit();
204+
}
205205
}
206206
}
207207

0 commit comments

Comments
 (0)