Skip to content

Commit b345979

Browse files
committed
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.
1 parent ca7c0b9 commit b345979

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/init.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1427,7 +1427,12 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14271427
fReindexChainState,
14281428
nBlockTreeDBCache,
14291429
nCoinDBCache,
1430-
nCoinCacheUsage);
1430+
nCoinCacheUsage,
1431+
[]() {
1432+
uiInterface.ThreadSafeMessageBox(
1433+
_("Error reading from database, shutting down."),
1434+
"", CClientUIInterface::MSG_ERROR);
1435+
});
14311436
if (rv.has_value()) {
14321437
switch (rv.value()) {
14331438
case ChainstateLoadingError::ERROR_LOADING_BLOCK_DB:
@@ -1463,6 +1468,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
14631468
break;
14641469
}
14651470
} else {
1471+
uiInterface.InitMessage(_("Verifying blocks…").translated);
14661472
auto rv2 = VerifyLoadedChainstate(chainman,
14671473
fReset,
14681474
fReindexChainState,

src/node/chainstate.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <rpc/blockchain.h> // for RPCNotifyBlockChange
99
#include <util/time.h> // for GetTime
1010
#include <node/blockstorage.h> // for CleanupBlockRevFiles, fHavePruned, fReindex
11-
#include <node/ui_interface.h> // for InitError, uiInterface, and CClientUIInterface member access
1211
#include <shutdown.h> // for ShutdownRequested
1312
#include <validation.h> // for a lot of things
1413

@@ -20,7 +19,8 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
2019
bool fReindexChainState,
2120
int64_t nBlockTreeDBCache,
2221
int64_t nCoinDBCache,
23-
int64_t nCoinCacheUsage)
22+
int64_t nCoinCacheUsage,
23+
std::function<void()> coins_error_cb)
2424
{
2525
auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
2626
return fReset || fReindexChainState || chainstate->CoinsTip().GetBestBlock().IsNull();
@@ -86,11 +86,9 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
8686
/* in_memory */ false,
8787
/* should_wipe */ fReset || fReindexChainState);
8888

89-
chainstate->CoinsErrorCatcher().AddReadErrCallback([]() {
90-
uiInterface.ThreadSafeMessageBox(
91-
_("Error reading from database, shutting down."),
92-
"", CClientUIInterface::MSG_ERROR);
93-
});
89+
if (coins_error_cb) {
90+
chainstate->CoinsErrorCatcher().AddReadErrCallback(coins_error_cb);
91+
}
9492

9593
// If necessary, upgrade from older database format.
9694
// This is a no-op if we cleared the coinsviewdb with -reindex or -reindex-chainstate
@@ -148,7 +146,6 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage
148146

149147
for (CChainState* chainstate : chainman.GetAll()) {
150148
if (!is_coinsview_empty(chainstate)) {
151-
uiInterface.InitMessage(_("Verifying blocks…").translated);
152149
if (fHavePruned && check_blocks > MIN_BLOCKS_TO_KEEP) {
153150
LogPrintf("Prune: pruned datadir may not have more than %d blocks; only checking available blocks\n",
154151
MIN_BLOCKS_TO_KEEP);

src/node/chainstate.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define BITCOIN_NODE_CHAINSTATE_H
77

88
#include <cstdint> // for int64_t
9+
#include <functional> // for std::function
910
#include <optional> // for std::optional
1011

1112
class CChainParams;
@@ -59,7 +60,8 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
5960
bool fReindexChainState,
6061
int64_t nBlockTreeDBCache,
6162
int64_t nCoinDBCache,
62-
int64_t nCoinCacheUsage);
63+
int64_t nCoinCacheUsage,
64+
std::function<void()> coins_error_cb = nullptr);
6365

6466
enum class ChainstateLoadVerifyError {
6567
ERROR_BLOCK_FROM_FUTURE,

0 commit comments

Comments
 (0)