diff --git a/src/init.cpp b/src/init.cpp index 60aad46ee8..823c07513a 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -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: diff --git a/src/node/chainstate.cpp b/src/node/chainstate.cpp index b8f7c3ef5a..edb246f5db 100644 --- a/src/node/chainstate.cpp +++ b/src/node/chainstate.cpp @@ -28,13 +28,18 @@ std::optional 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(); @@ -106,7 +111,7 @@ std::optional 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; } @@ -124,17 +129,17 @@ std::optional 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; } } @@ -223,7 +228,7 @@ std::optional 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); } @@ -242,8 +247,8 @@ std::optional 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; } @@ -254,7 +259,7 @@ std::optional 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); } diff --git a/src/node/chainstate.h b/src/node/chainstate.h index 0c8e547cac..d2bd675c95 100644 --- a/src/node/chainstate.h +++ b/src/node/chainstate.h @@ -8,7 +8,6 @@ #include // for int64_t #include // for std::optional -class ArgsManager; class CChainParams; class ChainstateManager; struct NodeContext; @@ -66,12 +65,17 @@ std::optional 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