diff options
author | Carl Dong <contact@carldong.me> | 2021-08-18 13:39:34 -0400 |
---|---|---|
committer | Carl Dong <contact@carldong.me> | 2021-12-06 16:41:33 -0500 |
commit | b345979a2b03b671c0984edd7e48e0baec2e2f34 (patch) | |
tree | 9b4950b2309eb78dbadb6711c3406205dfb8eff5 | |
parent | ca7c0b934db68acdc410e3a82f1ed898382da2e5 (diff) |
node/chainstate: Decouple from concept of uiInterface
...instead allow the caller to optionally pass in callbacks which are
triggered for certain events.
Behaviour change: The string "Verifying blocks..." was previously
printed for each chainstate in chainman which did not have an
effectively empty coinsview, now it will be printed once unconditionally
before we call VerifyLoadedChain.
-rw-r--r-- | src/init.cpp | 8 | ||||
-rw-r--r-- | src/node/chainstate.cpp | 13 | ||||
-rw-r--r-- | src/node/chainstate.h | 4 |
3 files changed, 15 insertions, 10 deletions
diff --git a/src/init.cpp b/src/init.cpp index e52ea57bdb..80f767a431 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1427,7 +1427,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: @@ -1463,6 +1468,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) break; } } else { + uiInterface.InitMessage(_("Verifying blocks…").translated); auto rv2 = VerifyLoadedChainstate(chainman, fReset, fReindexChainState, diff --git a/src/node/chainstate.cpp b/src/node/chainstate.cpp index 7dbaedb483..36d10e99d9 100644 --- a/src/node/chainstate.cpp +++ b/src/node/chainstate.cpp @@ -8,7 +8,6 @@ #include <rpc/blockchain.h> // for RPCNotifyBlockChange #include <util/time.h> // for GetTime #include <node/blockstorage.h> // for CleanupBlockRevFiles, fHavePruned, fReindex -#include <node/ui_interface.h> // for InitError, uiInterface, and CClientUIInterface member access #include <shutdown.h> // for ShutdownRequested #include <validation.h> // for a lot of things @@ -20,7 +19,8 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset, bool fReindexChainState, int64_t nBlockTreeDBCache, int64_t nCoinDBCache, - int64_t nCoinCacheUsage) + int64_t nCoinCacheUsage, + std::function<void()> coins_error_cb) { auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) { return fReset || fReindexChainState || chainstate->CoinsTip().GetBestBlock().IsNull(); @@ -86,11 +86,9 @@ std::optional<ChainstateLoadingError> 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 @@ -148,7 +146,6 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage for (CChainState* chainstate : chainman.GetAll()) { if (!is_coinsview_empty(chainstate)) { - uiInterface.InitMessage(_("Verifying blocks…").translated); if (fHavePruned && 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 c122391a41..84a86a082b 100644 --- a/src/node/chainstate.h +++ b/src/node/chainstate.h @@ -6,6 +6,7 @@ #define BITCOIN_NODE_CHAINSTATE_H #include <cstdint> // for int64_t +#include <functional> // for std::function #include <optional> // for std::optional class CChainParams; @@ -59,7 +60,8 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset, bool fReindexChainState, int64_t nBlockTreeDBCache, int64_t nCoinDBCache, - int64_t nCoinCacheUsage); + int64_t nCoinCacheUsage, + std::function<void()> coins_error_cb = nullptr); enum class ChainstateLoadVerifyError { ERROR_BLOCK_FROM_FUTURE, |