diff --git a/src/avalanche/test/processor_tests.cpp b/src/avalanche/test/processor_tests.cpp --- a/src/avalanche/test/processor_tests.cpp +++ b/src/avalanche/test/processor_tests.cpp @@ -2197,7 +2197,6 @@ } BOOST_AUTO_TEST_CASE(block_reconcile_initial_vote) { - const auto &config = GetConfig(); auto &chainman = Assert(m_node.chainman); Chainstate &chainstate = chainman->ActiveChainstate(); @@ -2209,7 +2208,7 @@ CBlockIndex *blockindex; { LOCK(cs_main); - BOOST_CHECK(chainstate.AcceptBlock(config, block, state, + BOOST_CHECK(chainstate.AcceptBlock(block, state, /*fRequested=*/true, /*dbp=*/nullptr, /*fNewBlock=*/nullptr, /*min_pow_checked=*/true)); diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -2683,9 +2683,9 @@ vImportFiles.push_back(fs::PathFromString(strFile)); } - chainman.m_load_block = std::thread( - &util::TraceThread, "loadblk", [=, &config, &chainman, &args] { - ThreadImport(config, chainman, vImportFiles, args, + chainman.m_load_block = + std::thread(&util::TraceThread, "loadblk", [=, &chainman, &args] { + ThreadImport(chainman, vImportFiles, args, ShouldPersistMempool(args) ? MempoolPath(args) : fs::path{}); }); diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h --- a/src/node/blockstorage.h +++ b/src/node/blockstorage.h @@ -238,7 +238,7 @@ bool ReadTxFromDisk(CMutableTransaction &tx, const FlatFilePos &pos); bool ReadTxUndoFromDisk(CTxUndo &tx, const FlatFilePos &pos); -void ThreadImport(const Config &config, ChainstateManager &chainman, +void ThreadImport(ChainstateManager &chainman, std::vector vImportFiles, const ArgsManager &args, const fs::path &mempool_path); } // namespace node diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -869,14 +869,12 @@ } }; -void ThreadImport(const Config &config, ChainstateManager &chainman, +void ThreadImport(ChainstateManager &chainman, std::vector vImportFiles, const ArgsManager &args, const fs::path &mempool_path) { ScheduleBatchPriority(); { - const CChainParams &chainParams = config.GetChainParams(); - CImportingNow imp; // -reindex @@ -900,7 +898,7 @@ LogPrintf("Reindexing block file blk%05u.dat...\n", (unsigned int)nFile); chainman.ActiveChainstate().LoadExternalBlockFile( - config, file, &pos, &blocks_with_unknown_parent); + file, &pos, &blocks_with_unknown_parent); if (ShutdownRequested()) { LogPrintf("Shutdown requested. Exit %s\n", __func__); return; @@ -923,7 +921,7 @@ if (file) { LogPrintf("Importing blocks file %s...\n", fs::PathToString(path)); - chainman.ActiveChainstate().LoadExternalBlockFile(config, file); + chainman.ActiveChainstate().LoadExternalBlockFile(file); if (ShutdownRequested()) { LogPrintf("Shutdown requested. Exit %s\n", __func__); return; @@ -938,7 +936,7 @@ // invalid by, for instance, running an outdated version of the node // software. const MapCheckpoints &checkpoints = - chainParams.Checkpoints().mapCheckpoints; + chainman.GetParams().Checkpoints().mapCheckpoints; for (const MapCheckpoints::value_type &i : checkpoints) { const BlockHash &hash = i.second; diff --git a/src/node/chainstate.cpp b/src/node/chainstate.cpp --- a/src/node/chainstate.cpp +++ b/src/node/chainstate.cpp @@ -275,9 +275,9 @@ "that your computer's date and time are correct")}; } - VerifyDBResult result = CVerifyDB().VerifyDB( - *chainstate, chainman.GetConfig(), chainstate->CoinsDB(), - options.check_level, options.check_blocks); + VerifyDBResult result = + CVerifyDB().VerifyDB(*chainstate, chainstate->CoinsDB(), + options.check_level, options.check_blocks); switch (result) { case VerifyDBResult::SUCCESS: case VerifyDBResult::SKIPPED_MISSING_BLOCKS: diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1277,7 +1277,7 @@ Chainstate &active_chainstate = chainman.ActiveChainstate(); return CVerifyDB().VerifyDB( - active_chainstate, config, active_chainstate.CoinsTip(), + active_chainstate, active_chainstate.CoinsTip(), check_level, check_depth) == VerifyDBResult::SUCCESS; }, }; diff --git a/src/test/coinstatsindex_tests.cpp b/src/test/coinstatsindex_tests.cpp --- a/src/test/coinstatsindex_tests.cpp +++ b/src/test/coinstatsindex_tests.cpp @@ -108,8 +108,8 @@ BlockValidationOptions options{config}; BOOST_CHECK(CheckBlock( block, state, config.GetChainParams().GetConsensus(), options)); - BOOST_CHECK(chainstate.AcceptBlock(config, new_block, state, true, - nullptr, nullptr, true)); + BOOST_CHECK(chainstate.AcceptBlock(new_block, state, true, nullptr, + nullptr, true)); // Get the block index (not returned by AcceptBlock since D2127) auto it{m_node.chainman->m_blockman.m_block_index.find( diff --git a/src/test/fuzz/load_external_block_file.cpp b/src/test/fuzz/load_external_block_file.cpp --- a/src/test/fuzz/load_external_block_file.cpp +++ b/src/test/fuzz/load_external_block_file.cpp @@ -37,12 +37,11 @@ FlatFilePos flat_file_pos; std::multimap blocks_with_unknown_parent; g_setup->m_node.chainman->ActiveChainstate().LoadExternalBlockFile( - GetConfig(), fuzzed_block_file, &flat_file_pos, - &blocks_with_unknown_parent); + fuzzed_block_file, &flat_file_pos, &blocks_with_unknown_parent); } else { // Corresponds to the -loadblock= case (orphan blocks aren't tracked // across files). g_setup->m_node.chainman->ActiveChainstate().LoadExternalBlockFile( - GetConfig(), fuzzed_block_file); + fuzzed_block_file); } } diff --git a/src/test/validation_chainstate_tests.cpp b/src/test/validation_chainstate_tests.cpp --- a/src/test/validation_chainstate_tests.cpp +++ b/src/test/validation_chainstate_tests.cpp @@ -145,8 +145,8 @@ bool checked = CheckBlock( *pblock, state, config.GetChainParams().GetConsensus(), options); BOOST_CHECK(checked); - bool accepted = background_cs.AcceptBlock(config, pblock, state, true, - nullptr, &newblock, true); + bool accepted = background_cs.AcceptBlock(pblock, state, true, nullptr, + &newblock, true); BOOST_CHECK(accepted); } // UpdateTip is called here diff --git a/src/test/validation_tests.cpp b/src/test/validation_tests.cpp --- a/src/test/validation_tests.cpp +++ b/src/test/validation_tests.cpp @@ -100,8 +100,7 @@ BOOST_CHECK(fp != nullptr); - const Config &config = GetConfig(); - const CChainParams &chainparams = config.GetChainParams(); + const CChainParams &chainparams = m_node.chainman->GetParams(); // serialization format is: // message start magic, size of block, block @@ -129,10 +128,8 @@ } fseek(fp, 0, SEEK_SET); - BOOST_CHECK_NO_THROW({ - m_node.chainman->ActiveChainstate().LoadExternalBlockFile(config, fp, - 0); - }); + BOOST_CHECK_NO_THROW( + { m_node.chainman->ActiveChainstate().LoadExternalBlockFile(fp, 0); }); } //! Test retrieval of valid assumeutxo values. diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -576,9 +576,9 @@ ~CVerifyDB(); - [[nodiscard]] VerifyDBResult - VerifyDB(Chainstate &chainstate, const Config &config, - CCoinsView &coinsview, int nCheckLevel, int nCheckDepth) + [[nodiscard]] VerifyDBResult VerifyDB(Chainstate &chainstate, + CCoinsView &coinsview, + int nCheckLevel, int nCheckDepth) EXCLUSIVE_LOCKS_REQUIRED(cs_main); }; @@ -851,11 +851,11 @@ * unknown parent, key is parent block hash * (only used for reindex) */ - void LoadExternalBlockFile( - const Config &config, FILE *fileIn, FlatFilePos *dbp = nullptr, - std::multimap *blocks_with_unknown_parent = - nullptr) EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex, - !cs_avalancheFinalizedBlockIndex); + void LoadExternalBlockFile(FILE *fileIn, FlatFilePos *dbp = nullptr, + std::multimap + *blocks_with_unknown_parent = nullptr) + EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex, + !cs_avalancheFinalizedBlockIndex); /** * Update the on-disk chain state. @@ -905,8 +905,7 @@ !cs_avalancheFinalizedBlockIndex) LOCKS_EXCLUDED(cs_main); - bool AcceptBlock(const Config &config, - const std::shared_ptr &pblock, + bool AcceptBlock(const std::shared_ptr &pblock, BlockValidationState &state, bool fRequested, const FlatFilePos *dbp, bool *fNewBlock, bool min_pow_checked) EXCLUSIVE_LOCKS_REQUIRED(cs_main); diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -4288,7 +4288,6 @@ /** * Store a block on disk. * - * @param[in] config The global config. * @param[in,out] pblock The block we want to accept. * @param[in] fRequested A boolean to indicate if this block was requested * from our peers. @@ -4298,8 +4297,7 @@ * been done by caller for headers chain * @return True if the block is accepted as a valid block and written to disk. */ -bool Chainstate::AcceptBlock(const Config &config, - const std::shared_ptr &pblock, +bool Chainstate::AcceptBlock(const std::shared_ptr &pblock, BlockValidationState &state, bool fRequested, const FlatFilePos *dbp, bool *fNewBlock, bool min_pow_checked) { @@ -4398,7 +4396,7 @@ const Consensus::Params &consensusParams = params.GetConsensus(); if (!CheckBlock(block, state, consensusParams, - BlockValidationOptions(config)) || + BlockValidationOptions(m_chainman.GetConfig())) || !ContextualCheckBlock(block, state, consensusParams, pindex->pprev)) { if (state.IsInvalid() && state.GetResult() != BlockValidationResult::BLOCK_MUTATED) { @@ -4488,9 +4486,9 @@ BlockValidationOptions(this->GetConfig())); if (ret) { // Store to disk - ret = ActiveChainstate().AcceptBlock( - this->GetConfig(), block, state, force_processing, nullptr, - new_block, min_pow_checked); + ret = ActiveChainstate().AcceptBlock(block, state, force_processing, + nullptr, new_block, + min_pow_checked); } if (!ret) { @@ -4627,11 +4625,12 @@ uiInterface.ShowProgress("", 100, false); } -VerifyDBResult CVerifyDB::VerifyDB(Chainstate &chainstate, const Config &config, +VerifyDBResult CVerifyDB::VerifyDB(Chainstate &chainstate, CCoinsView &coinsview, int nCheckLevel, int nCheckDepth) { AssertLockHeld(cs_main); + const Config &config = chainstate.m_chainman.GetConfig(); const CChainParams ¶ms = config.GetChainParams(); const Consensus::Params &consensusParams = params.GetConsensus(); @@ -5114,7 +5113,7 @@ } void Chainstate::LoadExternalBlockFile( - const Config &config, FILE *fileIn, FlatFilePos *dbp, + FILE *fileIn, FlatFilePos *dbp, std::multimap *blocks_with_unknown_parent) { AssertLockNotHeld(m_chainstate_mutex); @@ -5199,8 +5198,8 @@ m_blockman.LookupBlockIndex(hash); if (!pindex || !pindex->nStatus.hasData()) { BlockValidationState state; - if (AcceptBlock(config, pblock, state, true, dbp, - nullptr, true)) { + if (AcceptBlock(pblock, state, true, dbp, nullptr, + true)) { nLoaded++; } if (state.IsError()) { @@ -5270,8 +5269,8 @@ head.ToString()); LOCK(cs_main); BlockValidationState dummy; - if (AcceptBlock(config, pblockrecursive, dummy, - true, &it->second, nullptr, true)) { + if (AcceptBlock(pblockrecursive, dummy, true, + &it->second, nullptr, true)) { nLoaded++; queue.push_back(pblockrecursive->GetHash()); }