Skip to content

Commit bdb2fa6

Browse files
achow101PastaPastaPasta
authored andcommitted
Merge 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@7878f97 from bitcoin#25494 and was reported by pstratem in 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
1 parent 65377ea commit bdb2fa6

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/index/base.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,18 @@ void BaseIndex::ThreadSync()
160160
pindex = pindex_next;
161161
}
162162

163+
CBlock block;
164+
if (!ReadBlockFromDisk(block, pindex, consensus_params)) {
165+
FatalError("%s: Failed to read block %s from disk",
166+
__func__, pindex->GetBlockHash().ToString());
167+
return;
168+
}
169+
if (!WriteBlock(block, pindex)) {
170+
FatalError("%s: Failed to write block %s to index database",
171+
__func__, pindex->GetBlockHash().ToString());
172+
return;
173+
}
174+
163175
auto current_time{std::chrono::steady_clock::now()};
164176
if (last_log_time + SYNC_LOG_INTERVAL < current_time) {
165177
LogPrintf("Syncing %s with block chain from height %d\n",
@@ -168,23 +180,11 @@ void BaseIndex::ThreadSync()
168180
}
169181

170182
if (last_locator_write_time + SYNC_LOCATOR_WRITE_INTERVAL < current_time) {
171-
SetBestBlockIndex(pindex->pprev);
183+
SetBestBlockIndex(pindex);
172184
last_locator_write_time = current_time;
173185
// No need to handle errors in Commit. See rationale above.
174186
Commit();
175187
}
176-
177-
CBlock block;
178-
if (!ReadBlockFromDisk(block, pindex, consensus_params)) {
179-
FatalError("%s: Failed to read block %s from disk",
180-
__func__, pindex->GetBlockHash().ToString());
181-
return;
182-
}
183-
if (!WriteBlock(block, pindex)) {
184-
FatalError("%s: Failed to write block %s to index database",
185-
__func__, pindex->GetBlockHash().ToString());
186-
return;
187-
}
188188
}
189189
}
190190

0 commit comments

Comments
 (0)