node/chainstate: Decouple from concept of uiInterface

This commit is contained in:
Kittywhiskers Van Gogh 2021-08-18 13:39:34 -04:00
parent 913411ed73
commit a141f5d9a7
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
3 changed files with 15 additions and 10 deletions

View File

@ -1892,7 +1892,12 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
fReindexChainState, fReindexChainState,
nBlockTreeDBCache, nBlockTreeDBCache,
nCoinDBCache, nCoinDBCache,
nCoinCacheUsage); nCoinCacheUsage,
[]() {
uiInterface.ThreadSafeMessageBox(
_("Error reading from database, shutting down."),
"", CClientUIInterface::MSG_ERROR);
});
if (rv.has_value()) { if (rv.has_value()) {
switch (rv.value()) { switch (rv.value()) {
case ChainstateLoadingError::ERROR_LOADING_BLOCK_DB: case ChainstateLoadingError::ERROR_LOADING_BLOCK_DB:
@ -1946,6 +1951,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
break; break;
} }
} else { } else {
uiInterface.InitMessage(_("Verifying blocks…").translated);
auto rv2 = VerifyLoadedChainstate(chainman, auto rv2 = VerifyLoadedChainstate(chainman,
*Assert(node.evodb.get()), *Assert(node.evodb.get()),
fReset, fReset,

View File

@ -9,7 +9,6 @@
#include <rpc/blockchain.h> // for RPCNotifyBlockChange #include <rpc/blockchain.h> // for RPCNotifyBlockChange
#include <util/time.h> // for GetTime #include <util/time.h> // for GetTime
#include <node/blockstorage.h> // for CleanupBlockRevFiles, fHavePruned, fReindex #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 <shutdown.h> // for ShutdownRequested
#include <validation.h> // for a lot of things #include <validation.h> // for a lot of things
@ -50,7 +49,8 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
bool fReindexChainState, bool fReindexChainState,
int64_t nBlockTreeDBCache, int64_t nBlockTreeDBCache,
int64_t nCoinDBCache, 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) { auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
return fReset || fReindexChainState || chainstate->CoinsTip().GetBestBlock().IsNull(); return fReset || fReindexChainState || chainstate->CoinsTip().GetBestBlock().IsNull();
@ -181,11 +181,9 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
/* in_memory */ false, /* in_memory */ false,
/* should_wipe */ fReset || fReindexChainState); /* should_wipe */ fReset || fReindexChainState);
chainstate->CoinsErrorCatcher().AddReadErrCallback([]() { if (coins_error_cb) {
uiInterface.ThreadSafeMessageBox( chainstate->CoinsErrorCatcher().AddReadErrCallback(coins_error_cb);
_("Error reading from database, shutting down."), }
"", CClientUIInterface::MSG_ERROR);
});
// If necessary, upgrade from older database format. // If necessary, upgrade from older database format.
// This is a no-op if we cleared the coinsviewdb with -reindex or -reindex-chainstate // This is a no-op if we cleared the coinsviewdb with -reindex or -reindex-chainstate
@ -250,7 +248,6 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage
for (CChainState* chainstate : chainman.GetAll()) { for (CChainState* chainstate : chainman.GetAll()) {
if (!is_coinsview_empty(chainstate)) { if (!is_coinsview_empty(chainstate)) {
uiInterface.InitMessage(_("Verifying blocks…").translated);
if (chainman.m_blockman.m_have_pruned && check_blocks > MIN_BLOCKS_TO_KEEP) { 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", LogPrintf("Prune: pruned datadir may not have more than %d blocks; only checking available blocks\n",
MIN_BLOCKS_TO_KEEP); MIN_BLOCKS_TO_KEEP);

View File

@ -6,6 +6,7 @@
#define BITCOIN_NODE_CHAINSTATE_H #define BITCOIN_NODE_CHAINSTATE_H
#include <cstdint> // for int64_t #include <cstdint> // for int64_t
#include <functional> // for std::function
#include <memory> // for std::unique_ptr #include <memory> // for std::unique_ptr
#include <optional> // for std::optional #include <optional> // for std::optional
@ -103,7 +104,8 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
bool fReindexChainState, bool fReindexChainState,
int64_t nBlockTreeDBCache, int64_t nBlockTreeDBCache,
int64_t nCoinDBCache, int64_t nCoinDBCache,
int64_t nCoinCacheUsage); int64_t nCoinCacheUsage,
std::function<void()> coins_error_cb = nullptr);
enum class ChainstateLoadVerifyError { enum class ChainstateLoadVerifyError {
ERROR_BLOCK_FROM_FUTURE, ERROR_BLOCK_FROM_FUTURE,