1 Commits

Author SHA1 Message Date
2f3f320d28 Handle ReadBlockFromDisk failure during IBD gracefully
During Initial Block Download, block data may not be flushed to disk
when the wallet notification thread tries to read it. Instead of
crashing with a fatal error, log a message and retry on the next cycle.
2026-03-27 14:01:50 -05:00

View File

@@ -179,6 +179,13 @@ void ThreadNotifyWallets(CBlockIndex *pindexLastTip)
// Read block from disk. // Read block from disk.
CBlock block; CBlock block;
if (!ReadBlockFromDisk(block, pindexLastTip,1)) { if (!ReadBlockFromDisk(block, pindexLastTip,1)) {
if (IsInitialBlockDownload()) {
// During IBD, block data may not be flushed to disk yet.
// Sleep briefly and retry on the next cycle instead of crashing.
LogPrintf("%s: block at height %d not yet readable, will retry\n",
__func__, pindexLastTip->GetHeight());
break;
}
LogPrintf("*** %s\n", "Failed to read block while notifying wallets of block disconnects"); LogPrintf("*** %s\n", "Failed to read block while notifying wallets of block disconnects");
uiInterface.ThreadSafeMessageBox( uiInterface.ThreadSafeMessageBox(
_("Error: A fatal internal error occurred, see debug.log for details"), _("Error: A fatal internal error occurred, see debug.log for details"),
@@ -206,6 +213,14 @@ void ThreadNotifyWallets(CBlockIndex *pindexLastTip)
// Read block from disk. // Read block from disk.
CBlock block; CBlock block;
if (!ReadBlockFromDisk(block, blockData.pindex, 1)) { if (!ReadBlockFromDisk(block, blockData.pindex, 1)) {
if (IsInitialBlockDownload()) {
// During IBD, block data may not be flushed to disk yet.
// Push unprocessed blocks back and retry on the next cycle.
LogPrintf("%s: block at height %d not yet readable, will retry\n",
__func__, blockData.pindex->GetHeight());
blockStack.push_back(blockData);
break;
}
LogPrintf("*** %s\n", "Failed to read block while notifying wallets of block connects"); LogPrintf("*** %s\n", "Failed to read block while notifying wallets of block connects");
uiInterface.ThreadSafeMessageBox( uiInterface.ThreadSafeMessageBox(
_("Error: A fatal internal error occurred, see debug.log for details"), _("Error: A fatal internal error occurred, see debug.log for details"),