Skip to content

Commit ef95be3

Browse files
committed
refactor: Add stop_at_height option in ChainstateManager
Remove access to the global gArgs for the stopatheight argument and replace it by adding a field to the existing ChainstateManager Options struct. This should eventually allow users of the ChainstateManager to not rely on the global gArgs and instead pass in their own options.
1 parent 214f8f1 commit ef95be3

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

src/kernel/chainstatemanager_opts.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class CChainParams;
2121

2222
static constexpr bool DEFAULT_CHECKPOINTS_ENABLED{true};
2323
static constexpr auto DEFAULT_MAX_TIP_AGE{24h};
24+
static constexpr int DEFAULT_STOPATHEIGHT{0};
2425

2526
namespace kernel {
2627

@@ -45,6 +46,7 @@ struct ChainstateManagerOpts {
4546
DBOptions coins_db{};
4647
CoinsViewOptions coins_view{};
4748
Notifications& notifications;
49+
int stop_at_height{DEFAULT_STOPATHEIGHT};
4850
};
4951

5052
} // namespace kernel

src/node/chainstatemanager_args.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ util::Result<void> ApplyArgsManOptions(const ArgsManager& args, ChainstateManage
3737

3838
if (auto value{args.GetIntArg("-maxtipage")}) opts.max_tip_age = std::chrono::seconds{*value};
3939

40+
if (auto value{args.GetIntArg("-stopatheight")}) opts.stop_at_height = *value;
41+
4042
ReadDatabaseArgs(args, opts.block_tree_db);
4143
ReadDatabaseArgs(args, opts.coins_db);
4244
ReadCoinsViewArgs(args, opts.coins_view);

src/validation.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3104,7 +3104,6 @@ bool Chainstate::ActivateBestChain(BlockValidationState& state, std::shared_ptr<
31043104

31053105
CBlockIndex *pindexMostWork = nullptr;
31063106
CBlockIndex *pindexNewTip = nullptr;
3107-
int nStopAtHeight = gArgs.GetIntArg("-stopatheight", DEFAULT_STOPATHEIGHT);
31083107
do {
31093108
// Block until the validation queue drains. This should largely
31103109
// never happen in normal operation, however may happen during
@@ -3179,7 +3178,7 @@ bool Chainstate::ActivateBestChain(BlockValidationState& state, std::shared_ptr<
31793178
}
31803179
// When we reach this point, we switched to a new tip (stored in pindexNewTip).
31813180

3182-
if (nStopAtHeight && pindexNewTip && pindexNewTip->nHeight >= nStopAtHeight) StartShutdown();
3181+
if (m_chainman.StopAtHeight() && pindexNewTip && pindexNewTip->nHeight >= m_chainman.StopAtHeight()) StartShutdown();
31833182

31843183
if (WITH_LOCK(::cs_main, return m_disabled)) {
31853184
// Background chainstate has reached the snapshot base block, so exit.

src/validation.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ struct Params;
6565
static const int MAX_SCRIPTCHECK_THREADS = 15;
6666
/** -par default (number of script-checking threads, 0 = auto) */
6767
static const int DEFAULT_SCRIPTCHECK_THREADS = 0;
68-
/** Default for -stopatheight */
69-
static const int DEFAULT_STOPATHEIGHT = 0;
7068
/** Block files containing a block-height within MIN_BLOCKS_TO_KEEP of ActiveChain().Tip() will not be pruned. */
7169
static const unsigned int MIN_BLOCKS_TO_KEEP = 288;
7270
static const signed int DEFAULT_CHECKBLOCKS = 6;
@@ -960,6 +958,7 @@ class ChainstateManager
960958
const arith_uint256& MinimumChainWork() const { return *Assert(m_options.minimum_chain_work); }
961959
const uint256& AssumedValidBlock() const { return *Assert(m_options.assumed_valid_block); }
962960
kernel::Notifications& GetNotifications() const { return m_options.notifications; };
961+
int StopAtHeight() const { return m_options.stop_at_height; };
963962

964963
/**
965964
* Alias for ::cs_main.

0 commit comments

Comments
 (0)