diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -1857,13 +1857,6 @@ fCheckBlockIndex = args.GetBoolArg("-checkblockindex", chainparams.DefaultConsistencyChecks()); - fCheckpointsEnabled = - args.GetBoolArg("-checkpoints", DEFAULT_CHECKPOINTS_ENABLED); - if (fCheckpointsEnabled) { - LogPrintf("Checkpoints will be verified.\n"); - } else { - LogPrintf("Skipping checkpoint verification.\n"); - } // Configure excessive block size. const int64_t nProposedExcessiveBlockSize = @@ -2393,6 +2386,12 @@ // no error can happen, already checked in AppInitParameterInteraction Assert(!ApplyArgsManOptions(args, chainman_opts)); + if (chainman_opts.checkpoints_enabled) { + LogPrintf("Checkpoints will be verified.\n"); + } else { + LogPrintf("Skipping checkpoint verification.\n"); + } + // cache size calculations CacheSizes cache_sizes = CalculateCacheSizes(args, g_enabled_filter_types.size()); diff --git a/src/kernel/chainstatemanager_opts.h b/src/kernel/chainstatemanager_opts.h --- a/src/kernel/chainstatemanager_opts.h +++ b/src/kernel/chainstatemanager_opts.h @@ -15,6 +15,7 @@ class Config; +static constexpr bool DEFAULT_CHECKPOINTS_ENABLED{true}; static constexpr auto DEFAULT_MAX_TIP_AGE{24h}; namespace kernel { @@ -28,6 +29,7 @@ const Config &config; const std::function adjusted_time_callback{ nullptr}; + bool checkpoints_enabled{DEFAULT_CHECKPOINTS_ENABLED}; //! If set, it will override the minimum work we will assume exists on some //! valid chain. std::optional minimum_chain_work{}; diff --git a/src/node/chainstatemanager_args.cpp b/src/node/chainstatemanager_args.cpp --- a/src/node/chainstatemanager_args.cpp +++ b/src/node/chainstatemanager_args.cpp @@ -19,6 +19,10 @@ namespace node { std::optional ApplyArgsManOptions(const ArgsManager &args, ChainstateManager::Options &opts) { + if (auto value{args.GetBoolArg("-checkpoints")}) { + opts.checkpoints_enabled = *value; + } + if (auto value{args.GetArg("-minimumchainwork")}) { if (!IsHexNumber(*value)) { return strprintf( diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -37,6 +37,9 @@ namespace miner_tests { struct MinerTestingSetup : public TestingSetup { + MinerTestingSetup(const std::vector &extra_args = {}) + : TestingSetup(CBaseChainParams::MAIN, extra_args) {} + void TestPackageSelection(const CChainParams &chainparams, const CScript &scriptPubKey, const std::vector &txFirst) @@ -59,6 +62,11 @@ } BlockAssembler AssemblerForTest(const CChainParams ¶ms); }; + +struct MinerTestingSetupNoCheckpoints : public MinerTestingSetup { + MinerTestingSetupNoCheckpoints() : MinerTestingSetup({"-checkpoints=0"}) {} +}; + } // namespace miner_tests BOOST_FIXTURE_TEST_SUITE(miner_tests, MinerTestingSetup) @@ -672,7 +680,8 @@ } // NOTE: These tests rely on CreateNewBlock doing its own self-validation! -BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) { +BOOST_FIXTURE_TEST_CASE(CreateNewBlock_validity, + MinerTestingSetupNoCheckpoints) { // FIXME Update the below blocks to create a valid miner fund coinbase. // This requires to update the blockinfo nonces. gArgs.ForceSetArg("-enableminerfund", "0"); @@ -686,8 +695,6 @@ << OP_CHECKSIG; std::unique_ptr pblocktemplate; - fCheckpointsEnabled = false; - // Simple block creation, nothing special yet: BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey)); @@ -748,8 +755,6 @@ TestPrioritisedMining(chainparams, scriptPubKey, txFirst); - fCheckpointsEnabled = true; - gArgs.ClearForcedArg("-enableminerfund"); } diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -210,10 +211,11 @@ m_cache_sizes = CalculateCacheSizes(m_args); - const ChainstateManager::Options chainman_opts{ + ChainstateManager::Options chainman_opts{ .config = config, .adjusted_time_callback = GetAdjustedTime, }; + ApplyArgsManOptions(*m_node.args, chainman_opts); m_node.chainman = std::make_unique(chainman_opts); m_node.chainman->m_blockman.m_block_tree_db = std::make_unique(m_cache_sizes.block_tree_db, true); diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -82,7 +82,6 @@ static const int MAX_SCRIPTCHECK_THREADS = 15; /** -par default (number of script-checking threads, 0 = auto) */ static const int DEFAULT_SCRIPTCHECK_THREADS = 0; -static const bool DEFAULT_CHECKPOINTS_ENABLED = true; static const bool DEFAULT_PEERBLOOMFILTERS = true; @@ -118,7 +117,6 @@ /** Used to notify getblocktemplate RPC of new tips. */ extern uint256 g_best_block; extern bool fCheckBlockIndex; -extern bool fCheckpointsEnabled; /** Documentation for argument 'checklevel'. */ extern const std::vector CHECKLEVEL_DOC; diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -110,7 +110,6 @@ std::condition_variable g_best_block_cv; uint256 g_best_block; bool fCheckBlockIndex = false; -bool fCheckpointsEnabled = DEFAULT_CHECKPOINTS_ENABLED; BlockValidationOptions::BlockValidationOptions(const Config &config) : excessiveBlockSize(config.GetMaxBlockSize()), checkPoW(true), @@ -3901,7 +3900,7 @@ } // Check against checkpoints - if (fCheckpointsEnabled) { + if (chainman.m_options.checkpoints_enabled) { const CCheckpointData &checkpoints = params.Checkpoints(); // Check that the block chain matches the known block chain up to a