Skip to content

Commit ee9d3dd

Browse files
committed
node/chainstate: Decouple from ArgsManager
1 parent d7419e4 commit ee9d3dd

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

src/init.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,13 +1869,18 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
18691869
chainman,
18701870
node,
18711871
fPruneMode,
1872+
args.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX),
18721873
is_governance_enabled,
1874+
args.GetBoolArg("-spentindex", DEFAULT_SPENTINDEX),
1875+
args.GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX),
1876+
args.GetBoolArg("-txindex", DEFAULT_TXINDEX),
18731877
chainparams,
1874-
args,
18751878
fReindexChainState,
18761879
nBlockTreeDBCache,
18771880
nCoinDBCache,
1878-
nCoinCacheUsage);
1881+
nCoinCacheUsage,
1882+
args.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS),
1883+
args.GetArg("-checklevel", DEFAULT_CHECKLEVEL));
18791884
if (rv.has_value()) {
18801885
switch (rv.value()) {
18811886
case ChainstateLoadingError::ERROR_LOADING_BLOCK_DB:

src/node/chainstate.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,18 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
2828
ChainstateManager& chainman,
2929
NodeContext& node,
3030
bool fPruneMode,
31+
bool is_addrindex_enabled,
3132
bool is_governance_enabled,
33+
bool is_spentindex_enabled,
34+
bool is_timeindex_enabled,
35+
bool is_txindex_enabled,
3236
const CChainParams& chainparams,
33-
const ArgsManager& args,
3437
bool fReindexChainState,
3538
int64_t nBlockTreeDBCache,
3639
int64_t nCoinDBCache,
37-
int64_t nCoinCacheUsage)
40+
int64_t nCoinCacheUsage,
41+
unsigned int check_blocks,
42+
unsigned int check_level)
3843
{
3944
auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
4045
return fReset || fReindexChainState || chainstate->CoinsTip().GetBestBlock().IsNull();
@@ -106,7 +111,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
106111

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

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

125130
if (!fReset && !fReindexChainState) {
126131
// Check for changed -addressindex state
127-
if (!fAddressIndex && fAddressIndex != args.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX)) {
132+
if (!fAddressIndex && fAddressIndex != is_addrindex_enabled) {
128133
return ChainstateLoadingError::ERROR_ADDRIDX_NEEDS_REINDEX;
129134
}
130135

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

136141
// Check for changed -spentindex state
137-
if (!fSpentIndex && fSpentIndex != args.GetBoolArg("-spentindex", DEFAULT_SPENTINDEX)) {
142+
if (!fSpentIndex && fSpentIndex != is_spentindex_enabled) {
138143
return ChainstateLoadingError::ERROR_SPENTIDX_NEEDS_REINDEX;
139144
}
140145
}
@@ -223,7 +228,7 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
223228
for (CChainState* chainstate : chainman.GetAll()) {
224229
if (!is_coinsview_empty(chainstate)) {
225230
uiInterface.InitMessage(_("Verifying blocks…").translated);
226-
if (chainman.m_blockman.m_have_pruned && args.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS) > MIN_BLOCKS_TO_KEEP) {
231+
if (chainman.m_blockman.m_have_pruned && check_blocks > MIN_BLOCKS_TO_KEEP) {
227232
LogPrintf("Prune: pruned datadir may not have more than %d blocks; only checking available blocks\n",
228233
MIN_BLOCKS_TO_KEEP);
229234
}
@@ -242,8 +247,8 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
242247
if (!CVerifyDB().VerifyDB(
243248
*chainstate, chainparams, chainstate->CoinsDB(),
244249
*node.evodb,
245-
args.GetArg("-checklevel", DEFAULT_CHECKLEVEL),
246-
args.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS))) {
250+
check_level,
251+
check_blocks)) {
247252
return ChainstateLoadingError::ERROR_CORRUPTED_BLOCK_DB;
248253
}
249254

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

257-
if (args.GetArg("-checklevel", DEFAULT_CHECKLEVEL) >= 3) {
262+
if (check_level >= 3) {
258263
chainstate->ResetBlockFailureFlags(nullptr);
259264
}
260265

src/node/chainstate.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <cstdint> // for int64_t
99
#include <optional> // for std::optional
1010

11-
class ArgsManager;
1211
class CChainParams;
1312
class ChainstateManager;
1413
struct NodeContext;
@@ -66,12 +65,17 @@ std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
6665
ChainstateManager& chainman,
6766
NodeContext& node,
6867
bool fPruneMode,
68+
bool is_addrindex_enabled,
6969
bool is_governance_enabled,
70+
bool is_spentindex_enabled,
71+
bool is_timeindex_enabled,
72+
bool is_txindex_enabled,
7073
const CChainParams& chainparams,
71-
const ArgsManager& args,
7274
bool fReindexChainState,
7375
int64_t nBlockTreeDBCache,
7476
int64_t nCoinDBCache,
75-
int64_t nCoinCacheUsage);
77+
int64_t nCoinCacheUsage,
78+
unsigned int check_blocks,
79+
unsigned int check_level);
7680

7781
#endif // BITCOIN_NODE_CHAINSTATE_H

0 commit comments

Comments
 (0)