Skip to content

Commit c899aed

Browse files
dongcarlFabcien
authored andcommitted
node/chainstate: Decouple from ArgsManager
Summary: ``` ...instead pass in only the necessary information ``` Partial backport of [[bitcoin/bitcoin#23280 | core#23280]]: bitcoin/bitcoin@c7a5c46 Test Plan: ninja all check-all Reviewers: #bitcoin_abc, PiRK Reviewed By: #bitcoin_abc, PiRK Differential Revision: https://reviews.bitcoinabc.org/D12565
1 parent edeb35d commit c899aed

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

src/init.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -2465,9 +2465,11 @@ bool AppInitMain(Config &config, RPCServer &rpcServer,
24652465

24662466
const int64_t load_block_index_start_time = GetTimeMillis();
24672467

2468-
auto rv = LoadChainstate(fReset, chainman, node, fPruneMode, config,
2469-
args, fReindexChainState, nBlockTreeDBCache,
2470-
nCoinDBCache, nCoinCacheUsage);
2468+
auto rv = LoadChainstate(
2469+
fReset, chainman, node, fPruneMode, config, fReindexChainState,
2470+
nBlockTreeDBCache, nCoinDBCache, nCoinCacheUsage,
2471+
args.GetIntArg("-checkblocks", DEFAULT_CHECKBLOCKS),
2472+
args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL));
24712473

24722474
if (rv.has_value()) {
24732475
switch (rv.value()) {

src/node/chainstate.cpp

+8-11
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616

1717
std::optional<ChainstateLoadingError>
1818
LoadChainstate(bool fReset, ChainstateManager &chainman, NodeContext &node,
19-
bool fPruneMode_, const Config &config, const ArgsManager &args,
20-
bool fReindexChainState, int64_t nBlockTreeDBCache,
21-
int64_t nCoinDBCache, int64_t nCoinCacheUsage) {
19+
bool fPruneMode_, const Config &config, bool fReindexChainState,
20+
int64_t nBlockTreeDBCache, int64_t nCoinDBCache,
21+
int64_t nCoinCacheUsage, unsigned int check_blocks,
22+
unsigned int check_level) {
2223
const CChainParams &chainparams = config.GetChainParams();
2324

2425
auto is_coinsview_empty =
@@ -147,9 +148,7 @@ LoadChainstate(bool fReset, ChainstateManager &chainman, NodeContext &node,
147148
if (!is_coinsview_empty(chainstate)) {
148149
uiInterface.InitMessage(
149150
_("Verifying blocks...").translated);
150-
if (fHavePruned &&
151-
args.GetIntArg("-checkblocks", DEFAULT_CHECKBLOCKS) >
152-
MIN_BLOCKS_TO_KEEP) {
151+
if (fHavePruned && check_blocks > MIN_BLOCKS_TO_KEEP) {
153152
LogPrintf(
154153
"Prune: pruned datadir may not have more than %d "
155154
"blocks; only checking available blocks\n",
@@ -162,11 +161,9 @@ LoadChainstate(bool fReset, ChainstateManager &chainman, NodeContext &node,
162161
return ChainstateLoadingError::ERROR_BLOCK_FROM_FUTURE;
163162
}
164163

165-
if (!CVerifyDB().VerifyDB(
166-
*chainstate, config, chainstate->CoinsDB(),
167-
args.GetIntArg("-checklevel", DEFAULT_CHECKLEVEL),
168-
args.GetIntArg("-checkblocks",
169-
DEFAULT_CHECKBLOCKS))) {
164+
if (!CVerifyDB().VerifyDB(*chainstate, config,
165+
chainstate->CoinsDB(),
166+
check_level, check_blocks)) {
170167
return ChainstateLoadingError::ERROR_CORRUPTED_BLOCK_DB;
171168
}
172169
}

src/node/chainstate.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <cstdint>
99
#include <optional>
1010

11-
class ArgsManager;
1211
struct bilingual_str;
1312
class Config;
1413
class ChainstateManager;
@@ -58,8 +57,9 @@ enum class ChainstateLoadingError {
5857
*/
5958
std::optional<ChainstateLoadingError>
6059
LoadChainstate(bool fReset, ChainstateManager &chainman, NodeContext &node,
61-
bool fPruneMode, const Config &config, const ArgsManager &args,
62-
bool fReindexChainState, int64_t nBlockTreeDBCache,
63-
int64_t nCoinDBCache, int64_t nCoinCacheUsage);
60+
bool fPruneMode, const Config &config, bool fReindexChainState,
61+
int64_t nBlockTreeDBCache, int64_t nCoinDBCache,
62+
int64_t nCoinCacheUsage, unsigned int check_blocks,
63+
unsigned int check_level);
6464

6565
#endif // BITCOIN_NODE_CHAINSTATE_H

0 commit comments

Comments
 (0)