From fa693c870a5a1ac398d3effcdcfbaa7a19fe7697 Mon Sep 17 00:00:00 2001 From: Rhett Creighton Date: Fri, 5 Jun 2026 23:40:12 +0000 Subject: [PATCH] =?UTF-8?q?beta7:=20beta7:=20crash-safety=20=E2=80=94=20gr?= =?UTF-8?q?aceful=20DB-flush=20failure=20+=20ThreadImport=20exception=20gu?= =?UTF-8?q?ard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- src/init.cpp | 4 ++++ src/main.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index ac853e6b495..ab716356f32 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -664,6 +664,7 @@ void CleanupBlockRevFiles() void ThreadImport(std::vector vImportFiles) { RenameThread("zcl-loadblk"); + try { // -reindex if (fReindex) { CImportingNow imp; @@ -717,6 +718,9 @@ void ThreadImport(std::vector vImportFiles) LogPrintf("Stopping after block import\n"); StartShutdown(); } + } catch (const std::exception& e) { + LogPrintf("%s: failed: %s\n", __func__, e.what()); + } } void ThreadNotifyRecentlyAdded() diff --git a/src/main.cpp b/src/main.cpp index eb98a68c72d..28de64f7f84 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2998,7 +2998,8 @@ bool static DisconnectTip(CValidationState &state, bool fBare = false) { CCoinsViewCache view(pcoinsTip); if (DisconnectBlock(block, pindexDelete, view) != DISCONNECT_OK) return error("DisconnectTip(): DisconnectBlock %s failed", pindexDelete->GetBlockHash().ToString()); - assert(view.Flush()); + if (!view.Flush()) + return AbortNode(state, "Failed to write to coin database"); } LogPrint("bench", "- Disconnect block: %.2fms\n", (GetTimeMicros() - nStart) * 0.001); uint256 sproutAnchorAfterDisconnect = pcoinsTip->GetBestAnchor(SPROUT); @@ -3409,7 +3410,8 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * mapBlockSource.erase(pindexNew->GetBlockHash()); nTime3 = GetTimeMicros(); nTimeConnectTotal += nTime3 - nTime2; LogPrint("bench", " - Connect total: %.2fms [%.2fs]\n", (nTime3 - nTime2) * 0.001, nTimeConnectTotal * 0.000001); - assert(view.Flush()); + if (!view.Flush()) + return AbortNode(state, "Failed to write to coin database"); } int64_t nTime4 = GetTimeMicros(); nTimeFlush += nTime4 - nTime3; LogPrint("bench", " - Flush: %.2fms [%.2fs]\n", (nTime4 - nTime3) * 0.001, nTimeFlush * 0.000001);