diff --git a/src/init.cpp b/src/init.cpp index 81a03cb100..d58ef908ca 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1892,7 +1892,12 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) fReindexChainState, nBlockTreeDBCache, nCoinDBCache, - nCoinCacheUsage); + nCoinCacheUsage, + []() { + uiInterface.ThreadSafeMessageBox( + _("Error reading from database, shutting down."), + "", CClientUIInterface::MSG_ERROR); + }); if (rv.has_value()) { switch (rv.value()) { case ChainstateLoadingError::ERROR_LOADING_BLOCK_DB: @@ -1946,6 +1951,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) break; } } else { + uiInterface.InitMessage(_("Verifying blocks…").translated); auto rv2 = VerifyLoadedChainstate(chainman, *Assert(node.evodb.get()), fReset, diff --git a/src/node/chainstate.cpp b/src/node/chainstate.cpp index 350daec44c..4562d750b5 100644 --- a/src/node/chainstate.cpp +++ b/src/node/chainstate.cpp @@ -9,7 +9,6 @@ #include // for RPCNotifyBlockChange #include // for GetTime #include // for CleanupBlockRevFiles, fHavePruned, fReindex -#include // for InitError, uiInterface, and CClientUIInterface member access #include // for ShutdownRequested #include // for a lot of things @@ -50,7 +49,8 @@ std::optional LoadChainstate(bool fReset, bool fReindexChainState, int64_t nBlockTreeDBCache, int64_t nCoinDBCache, - int64_t nCoinCacheUsage) + int64_t nCoinCacheUsage, + std::function coins_error_cb) { auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) { return fReset || fReindexChainState || chainstate->CoinsTip().GetBestBlock().IsNull(); @@ -181,11 +181,9 @@ std::optional LoadChainstate(bool fReset, /* in_memory */ false, /* should_wipe */ fReset || fReindexChainState); - chainstate->CoinsErrorCatcher().AddReadErrCallback([]() { - uiInterface.ThreadSafeMessageBox( - _("Error reading from database, shutting down."), - "", CClientUIInterface::MSG_ERROR); - }); + if (coins_error_cb) { + chainstate->CoinsErrorCatcher().AddReadErrCallback(coins_error_cb); + } // If necessary, upgrade from older database format. // This is a no-op if we cleared the coinsviewdb with -reindex or -reindex-chainstate @@ -250,7 +248,6 @@ std::optional VerifyLoadedChainstate(ChainstateManage for (CChainState* chainstate : chainman.GetAll()) { if (!is_coinsview_empty(chainstate)) { - uiInterface.InitMessage(_("Verifying blocks…").translated); if (chainman.m_blockman.m_have_pruned && check_blocks > MIN_BLOCKS_TO_KEEP) { LogPrintf("Prune: pruned datadir may not have more than %d blocks; only checking available blocks\n", MIN_BLOCKS_TO_KEEP); diff --git a/src/node/chainstate.h b/src/node/chainstate.h index ad35f9ecc8..442d8b5f92 100644 --- a/src/node/chainstate.h +++ b/src/node/chainstate.h @@ -6,6 +6,7 @@ #define BITCOIN_NODE_CHAINSTATE_H #include // for int64_t +#include // for std::function #include // for std::unique_ptr #include // for std::optional @@ -103,7 +104,8 @@ std::optional LoadChainstate(bool fReset, bool fReindexChainState, int64_t nBlockTreeDBCache, int64_t nCoinDBCache, - int64_t nCoinCacheUsage); + int64_t nCoinCacheUsage, + std::function coins_error_cb = nullptr); enum class ChainstateLoadVerifyError { ERROR_BLOCK_FROM_FUTURE,