Skip to content

Commit

Permalink
node/chainstate: Reduce coupling of LogPrintf
Browse files Browse the repository at this point in the history
  • Loading branch information
kwvg committed Dec 16, 2024
1 parent a141f5d commit d3345ee
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 49 deletions.
94 changes: 53 additions & 41 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1865,39 +1865,45 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)

uiInterface.InitMessage(_("Loading block index…").translated);
const auto load_block_index_start_time{SteadyClock::now()};
auto rv = LoadChainstate(fReset,
chainman,
*node.govman,
*node.mn_metaman,
*node.mn_sync,
*node.sporkman,
node.mn_activeman,
node.chain_helper,
node.cpoolman,
node.dmnman,
node.evodb,
node.mnhf_manager,
llmq::chainLocksHandler,
llmq::quorumInstantSendManager,
llmq::quorumSnapshotManager,
node.llmq_ctx,
Assert(node.mempool.get()),
fPruneMode,
args.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX),
is_governance_enabled,
args.GetBoolArg("-spentindex", DEFAULT_SPENTINDEX),
args.GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX),
args.GetBoolArg("-txindex", DEFAULT_TXINDEX),
chainparams,
fReindexChainState,
nBlockTreeDBCache,
nCoinDBCache,
nCoinCacheUsage,
[]() {
uiInterface.ThreadSafeMessageBox(
_("Error reading from database, shutting down."),
"", CClientUIInterface::MSG_ERROR);
});
std::optional<ChainstateLoadingError> rv;
try {
rv = LoadChainstate(fReset,
chainman,
*node.govman,
*node.mn_metaman,
*node.mn_sync,
*node.sporkman,
node.mn_activeman,
node.chain_helper,
node.cpoolman,
node.dmnman,
node.evodb,
node.mnhf_manager,
llmq::chainLocksHandler,
llmq::quorumInstantSendManager,
llmq::quorumSnapshotManager,
node.llmq_ctx,
Assert(node.mempool.get()),
fPruneMode,
args.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX),
is_governance_enabled,
args.GetBoolArg("-spentindex", DEFAULT_SPENTINDEX),
args.GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX),
args.GetBoolArg("-txindex", DEFAULT_TXINDEX),
chainparams,
fReindexChainState,
nBlockTreeDBCache,
nCoinDBCache,
nCoinCacheUsage,
[]() {
uiInterface.ThreadSafeMessageBox(
_("Error reading from database, shutting down."),
"", CClientUIInterface::MSG_ERROR);
});
} catch (const std::exception& e) {
LogPrintf("%s\n", e.what());
rv = ChainstateLoadingError::ERROR_GENERIC_BLOCKDB_OPEN_FAILED;
}
if (rv.has_value()) {
switch (rv.value()) {
case ChainstateLoadingError::ERROR_LOADING_BLOCK_DB:
Expand Down Expand Up @@ -1951,14 +1957,20 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
break;
}
} else {
uiInterface.InitMessage(_("Verifying blocks…").translated);
auto rv2 = VerifyLoadedChainstate(chainman,
*Assert(node.evodb.get()),
fReset,
fReindexChainState,
chainparams,
args.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS),
args.GetArg("-checklevel", DEFAULT_CHECKLEVEL));
std::optional<ChainstateLoadVerifyError> rv2;
try {
uiInterface.InitMessage(_("Verifying blocks…").translated);
rv2 = VerifyLoadedChainstate(chainman,
*Assert(node.evodb.get()),
fReset,
fReindexChainState,
chainparams,
args.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS),
args.GetArg("-checklevel", DEFAULT_CHECKLEVEL));
} catch (const std::exception& e) {
LogPrintf("%s\n", e.what());
rv2 = ChainstateLoadVerifyError::ERROR_GENERIC_FAILURE;
}
if (rv2.has_value()) {
switch (rv2.value()) {
case ChainstateLoadVerifyError::ERROR_BLOCK_FROM_FUTURE:
Expand Down
10 changes: 2 additions & 8 deletions src/node/chainstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
return fReset || fReindexChainState || chainstate->CoinsTip().GetBestBlock().IsNull();
};

try {
{
LOCK(cs_main);

int64_t nEvoDbCache{64 * 1024 * 1024}; // TODO
Expand Down Expand Up @@ -223,9 +223,6 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
if (!mnhf_manager->ForceSignalDBUpdate()) {
return ChainstateLoadingError::ERROR_UPGRADING_SIGNALS_DB;
}
} catch (const std::exception& e) {
LogPrintf("%s\n", e.what());
return ChainstateLoadingError::ERROR_GENERIC_BLOCKDB_OPEN_FAILED;
}

return std::nullopt;
Expand All @@ -243,7 +240,7 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage
return fReset || fReindexChainState || chainstate->CoinsTip().GetBestBlock().IsNull();
};

try {
{
LOCK(cs_main);

for (CChainState* chainstate : chainman.GetAll()) {
Expand Down Expand Up @@ -293,9 +290,6 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage
}
}
}
} catch (const std::exception& e) {
LogPrintf("%s\n", e.what());
return ChainstateLoadVerifyError::ERROR_GENERIC_FAILURE;
}

return std::nullopt;
Expand Down

0 comments on commit d3345ee

Please sign in to comment.