Skip to content

Commit

Permalink
node/chainstate: Decouple from ArgsManager
Browse files Browse the repository at this point in the history
  • Loading branch information
kwvg committed Dec 15, 2024
1 parent d7419e4 commit ee9d3dd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
9 changes: 7 additions & 2 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1869,13 +1869,18 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
chainman,
node,
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,
args,
fReindexChainState,
nBlockTreeDBCache,
nCoinDBCache,
nCoinCacheUsage);
nCoinCacheUsage,
args.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS),
args.GetArg("-checklevel", DEFAULT_CHECKLEVEL));
if (rv.has_value()) {
switch (rv.value()) {
case ChainstateLoadingError::ERROR_LOADING_BLOCK_DB:
Expand Down
25 changes: 15 additions & 10 deletions src/node/chainstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
ChainstateManager& chainman,
NodeContext& node,
bool fPruneMode,
bool is_addrindex_enabled,
bool is_governance_enabled,
bool is_spentindex_enabled,
bool is_timeindex_enabled,
bool is_txindex_enabled,
const CChainParams& chainparams,
const ArgsManager& args,
bool fReindexChainState,
int64_t nBlockTreeDBCache,
int64_t nCoinDBCache,
int64_t nCoinCacheUsage)
int64_t nCoinCacheUsage,
unsigned int check_blocks,
unsigned int check_level)
{
auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
return fReset || fReindexChainState || chainstate->CoinsTip().GetBestBlock().IsNull();
Expand Down Expand Up @@ -106,7 +111,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,

// TODO: Remove this when pruning is fixed.
// See https://github.com/dashpay/dash/pull/1817 and https://github.com/dashpay/dash/pull/1743
if (is_governance_enabled && !args.GetBoolArg("-txindex", DEFAULT_TXINDEX) && chainparams.NetworkIDString() != CBaseChainParams::REGTEST) {
if (is_governance_enabled && !is_txindex_enabled && chainparams.NetworkIDString() != CBaseChainParams::REGTEST) {
return ChainstateLoadingError::ERROR_TXINDEX_DISABLED_WHEN_GOV_ENABLED;
}

Expand All @@ -124,17 +129,17 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,

if (!fReset && !fReindexChainState) {
// Check for changed -addressindex state
if (!fAddressIndex && fAddressIndex != args.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX)) {
if (!fAddressIndex && fAddressIndex != is_addrindex_enabled) {
return ChainstateLoadingError::ERROR_ADDRIDX_NEEDS_REINDEX;
}

// Check for changed -timestampindex state
if (!fTimestampIndex && fTimestampIndex != args.GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX)) {
if (!fTimestampIndex && fTimestampIndex != is_timeindex_enabled) {
return ChainstateLoadingError::ERROR_TIMEIDX_NEEDS_REINDEX;
}

// Check for changed -spentindex state
if (!fSpentIndex && fSpentIndex != args.GetBoolArg("-spentindex", DEFAULT_SPENTINDEX)) {
if (!fSpentIndex && fSpentIndex != is_spentindex_enabled) {
return ChainstateLoadingError::ERROR_SPENTIDX_NEEDS_REINDEX;
}
}
Expand Down Expand Up @@ -223,7 +228,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
for (CChainState* chainstate : chainman.GetAll()) {
if (!is_coinsview_empty(chainstate)) {
uiInterface.InitMessage(_("Verifying blocks…").translated);
if (chainman.m_blockman.m_have_pruned && args.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS) > 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",
MIN_BLOCKS_TO_KEEP);
}
Expand All @@ -242,8 +247,8 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
if (!CVerifyDB().VerifyDB(
*chainstate, chainparams, chainstate->CoinsDB(),
*node.evodb,
args.GetArg("-checklevel", DEFAULT_CHECKLEVEL),
args.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS))) {
check_level,
check_blocks)) {
return ChainstateLoadingError::ERROR_CORRUPTED_BLOCK_DB;
}

Expand All @@ -254,7 +259,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
LogPrintf("%s: bls_legacy_scheme=%d\n", __func__, bls::bls_legacy_scheme.load());
}

if (args.GetArg("-checklevel", DEFAULT_CHECKLEVEL) >= 3) {
if (check_level >= 3) {
chainstate->ResetBlockFailureFlags(nullptr);
}

Expand Down
10 changes: 7 additions & 3 deletions src/node/chainstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <cstdint> // for int64_t
#include <optional> // for std::optional

class ArgsManager;
class CChainParams;
class ChainstateManager;
struct NodeContext;
Expand Down Expand Up @@ -66,12 +65,17 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
ChainstateManager& chainman,
NodeContext& node,
bool fPruneMode,
bool is_addrindex_enabled,
bool is_governance_enabled,
bool is_spentindex_enabled,
bool is_timeindex_enabled,
bool is_txindex_enabled,
const CChainParams& chainparams,
const ArgsManager& args,
bool fReindexChainState,
int64_t nBlockTreeDBCache,
int64_t nCoinDBCache,
int64_t nCoinCacheUsage);
int64_t nCoinCacheUsage,
unsigned int check_blocks,
unsigned int check_level);

#endif // BITCOIN_NODE_CHAINSTATE_H

0 comments on commit ee9d3dd

Please sign in to comment.