diff --git a/src/avalanche/test/peermanager_tests.cpp b/src/avalanche/test/peermanager_tests.cpp --- a/src/avalanche/test/peermanager_tests.cpp +++ b/src/avalanche/test/peermanager_tests.cpp @@ -702,8 +702,7 @@ SetMockTime(GetTime() + 20); mineBlocks(1); BlockValidationState state; - BOOST_CHECK( - chainman.ActiveChainstate().ActivateBestChain(GetConfig(), state)); + BOOST_CHECK(chainman.ActiveChainstate().ActivateBestChain(state)); LOCK(chainman.GetMutex()); BOOST_CHECK_EQUAL(chainman.ActiveHeight(), 100); } 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 @@ -1917,7 +1917,7 @@ LOCK(cs_main); activeChainstate.ResetBlockFailureFlags(tip); } - activeChainstate.ActivateBestChain(config, state); + activeChainstate.ActivateBestChain(state); BOOST_CHECK(addToReconcile(tip)); BOOST_CHECK(addToReconcile(alttip)); @@ -2227,7 +2227,7 @@ BOOST_CHECK(!g_avalanche->isAccepted(blockindex)); // Call ActivateBestChain to connect the new block - BOOST_CHECK(chainstate.ActivateBestChain(config, state, block)); + BOOST_CHECK(chainstate.ActivateBestChain(state, block)); // It is a valid block so the tip is updated BOOST_CHECK_EQUAL(chainstate.m_chain.Tip(), blockindex); diff --git a/src/bench/chained_tx.cpp b/src/bench/chained_tx.cpp --- a/src/bench/chained_tx.cpp +++ b/src/bench/chained_tx.cpp @@ -128,8 +128,7 @@ } /// Run benchmark on AcceptToMemoryPool -static void benchATMP(const Config &config, node::NodeContext &node, - benchmark::Bench &bench, +static void benchATMP(node::NodeContext &node, benchmark::Bench &bench, const std::vector chainedTxs) { auto chainman = Assert(node.chainman.get()); Chainstate &activeChainState = chainman->ActiveChainstate(); @@ -141,7 +140,7 @@ LOCK(::cs_main); for (const auto &tx : chainedTxs) { MempoolAcceptResult result = - AcceptToMemoryPool(config, activeChainState, tx, GetTime(), + AcceptToMemoryPool(activeChainState, tx, GetTime(), /*bypass_limits=*/false); assert(result.m_result_type == MempoolAcceptResult::ResultType::VALID); @@ -207,7 +206,7 @@ activeChainState.InvalidateBlock(config, state, blockToInvalidate); assert(state.IsValid()); - activeChainState.ActivateBestChain(config, state); + activeChainState.ActivateBestChain(state); assert(state.IsValid()); assert(activeChainState.m_chain.Tip() == tipBeforeInvalidate); @@ -227,7 +226,7 @@ activeChainState.ResetBlockFailureFlags(blockToInvalidate); } - activeChainState.ActivateBestChain(config, state); + activeChainState.ActivateBestChain(state); assert(state.IsValid()); assert(activeChainState.m_chain.Tip() == mostWorkTip); assert(mempool.size() == 0); @@ -331,7 +330,7 @@ const Config &config = GetConfig(); const std::vector chainedTxs = oneInOneOutChain( config, createUTXOs(config, 1, test_setup.m_node).back(), 50); - benchATMP(config, test_setup.m_node, bench, chainedTxs); + benchATMP(test_setup.m_node, bench, chainedTxs); } /// Tests a chain of 500 1-input-1-output transactions. @@ -340,7 +339,7 @@ const Config &config = GetConfig(); const std::vector chainedTxs = oneInOneOutChain( config, createUTXOs(config, 1, test_setup.m_node).back(), 500); - benchATMP(config, test_setup.m_node, bench, chainedTxs); + benchATMP(test_setup.m_node, bench, chainedTxs); } /// Test a tree of 63 2-inputs-1-output transactions @@ -350,7 +349,7 @@ const std::vector chainedTxs = twoInOneOutTree(config, test_setup.m_node, 5); assert(chainedTxs.size() == 63); - benchATMP(config, test_setup.m_node, bench, chainedTxs); + benchATMP(test_setup.m_node, bench, chainedTxs); } /// Test a tree of 511 2-inputs-1-output transactions @@ -360,7 +359,7 @@ const std::vector chainedTxs = twoInOneOutTree(config, test_setup.m_node, 8); assert(chainedTxs.size() == 511); - benchATMP(config, test_setup.m_node, bench, chainedTxs); + benchATMP(test_setup.m_node, bench, chainedTxs); } /// Try to reorg a chain of depth 10 where each block has a 50 tx diff --git a/src/bitcoin-chainstate.cpp b/src/bitcoin-chainstate.cpp --- a/src/bitcoin-chainstate.cpp +++ b/src/bitcoin-chainstate.cpp @@ -114,7 +114,7 @@ for (Chainstate *chainstate : WITH_LOCK(::cs_main, return chainman.GetAll())) { BlockValidationState state; - if (!chainstate->ActivateBestChain(config, state, nullptr)) { + if (!chainstate->ActivateBestChain(state, nullptr)) { std::cerr << "Failed to connect best block (" << state.ToString() << ")" << std::endl; goto epilogue; diff --git a/src/kernel/disconnected_transactions.h b/src/kernel/disconnected_transactions.h --- a/src/kernel/disconnected_transactions.h +++ b/src/kernel/disconnected_transactions.h @@ -163,8 +163,7 @@ * Passing fAddToMempool=false will skip trying to add the transactions * back, and instead just erase from the mempool as needed. */ - void updateMempoolForReorg(const Config &config, - Chainstate &active_chainstate, + void updateMempoolForReorg(Chainstate &active_chainstate, bool fAddToMempool, CTxMemPool &pool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, pool.cs); }; diff --git a/src/kernel/disconnected_transactions.cpp b/src/kernel/disconnected_transactions.cpp --- a/src/kernel/disconnected_transactions.cpp +++ b/src/kernel/disconnected_transactions.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -173,8 +172,7 @@ } void DisconnectedBlockTransactions::updateMempoolForReorg( - const Config &config, Chainstate &active_chainstate, bool fAddToMempool, - CTxMemPool &pool) { + Chainstate &active_chainstate, bool fAddToMempool, CTxMemPool &pool) { AssertLockHeld(cs_main); AssertLockHeld(pool.cs); @@ -201,7 +199,7 @@ } // ignore validation errors in resurrected transactions auto result = AcceptToMemoryPool( - config, active_chainstate, tx, + active_chainstate, tx, /*accept_time=*/ptxInfo ? ptxInfo->time.count() : GetTime(), /*bypass_limits=*/true, /*test_accept=*/false, /*heightOverride=*/ptxInfo ? ptxInfo->height : 0); diff --git a/src/kernel/mempool_persist.h b/src/kernel/mempool_persist.h --- a/src/kernel/mempool_persist.h +++ b/src/kernel/mempool_persist.h @@ -8,7 +8,6 @@ #include class Chainstate; -class Config; class CTxMemPool; namespace kernel { @@ -19,8 +18,8 @@ bool skip_file_commit = false); /** Load the mempool from disk. */ -bool LoadMempool(const Config &config, CTxMemPool &pool, - const fs::path &load_path, Chainstate &active_chainstate, +bool LoadMempool(CTxMemPool &pool, const fs::path &load_path, + Chainstate &active_chainstate, fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen); } // namespace kernel diff --git a/src/kernel/mempool_persist.cpp b/src/kernel/mempool_persist.cpp --- a/src/kernel/mempool_persist.cpp +++ b/src/kernel/mempool_persist.cpp @@ -5,7 +5,6 @@ #include #include -#include #include #include #include @@ -37,8 +36,8 @@ namespace kernel { static const uint64_t MEMPOOL_DUMP_VERSION = 1; -bool LoadMempool(const Config &config, CTxMemPool &pool, - const fs::path &load_path, Chainstate &active_chainstate, +bool LoadMempool(CTxMemPool &pool, const fs::path &load_path, + Chainstate &active_chainstate, FopenFn mockable_fopen_function) { if (load_path.empty()) { return false; @@ -85,7 +84,7 @@ TicksSinceEpoch(now - pool.m_expiry)) { LOCK(cs_main); const auto &accepted = - AcceptToMemoryPool(config, active_chainstate, tx, nTime, + AcceptToMemoryPool(active_chainstate, tx, nTime, /*bypass_limits=*/false, /*test_accept=*/false); if (accepted.m_result_type == diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -3010,7 +3010,7 @@ } // release cs_main before calling ActivateBestChain if (need_activate_chain) { BlockValidationState state; - if (!m_chainman.ActiveChainstate().ActivateBestChain(config, state, + if (!m_chainman.ActiveChainstate().ActivateBestChain(state, a_recent_block)) { LogPrint(BCLog::NET, "failed to activate chain (%s)\n", state.ToString()); @@ -5021,7 +5021,7 @@ } BlockValidationState state; if (!m_chainman.ActiveChainstate().ActivateBestChain( - config, state, a_recent_block)) { + state, a_recent_block)) { LogPrint(BCLog::NET, "failed to activate chain (%s)\n", state.ToString()); } @@ -6302,8 +6302,7 @@ if (shouldActivateBestChain) { BlockValidationState state; - if (!m_chainman.ActiveChainstate().ActivateBestChain(config, - state)) { + if (!m_chainman.ActiveChainstate().ActivateBestChain(state)) { LogPrintf("failed to activate chain (%s)\n", state.ToString()); } } diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -968,7 +968,7 @@ for (Chainstate *chainstate : WITH_LOCK(::cs_main, return chainman.GetAll())) { BlockValidationState state; - if (!chainstate->ActivateBestChain(config, state, nullptr)) { + if (!chainstate->ActivateBestChain(state, nullptr)) { LogPrintf("Failed to connect best block (%s)\n", state.ToString()); StartShutdown(); @@ -983,6 +983,6 @@ return; } } // End scope of CImportingNow - chainman.ActiveChainstate().LoadMempool(config, mempool_path); + chainman.ActiveChainstate().LoadMempool(mempool_path); } } // namespace node diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1554,8 +1554,7 @@ } BlockValidationState state; - chainman.ActiveChainstate().PreciousBlock(config, state, - pblockindex); + chainman.ActiveChainstate().PreciousBlock(state, pblockindex); if (!state.IsValid()) { throw JSONRPCError(RPC_DATABASE_ERROR, state.GetRejectReason()); @@ -1600,7 +1599,7 @@ pblockindex); if (state.IsValid()) { - chainman.ActiveChainstate().ActivateBestChain(config, state); + chainman.ActiveChainstate().ActivateBestChain(state); } if (!state.IsValid()) { @@ -1653,7 +1652,7 @@ active_chainstate.ParkBlock(config, state, pblockindex); if (state.IsValid()) { - active_chainstate.ActivateBestChain(config, state); + active_chainstate.ActivateBestChain(state); } if (!state.IsValid()) { @@ -1699,7 +1698,7 @@ } BlockValidationState state; - chainman.ActiveChainstate().ActivateBestChain(config, state); + chainman.ActiveChainstate().ActivateBestChain(state); if (!state.IsValid()) { throw JSONRPCError(RPC_DATABASE_ERROR, state.ToString()); @@ -1764,7 +1763,7 @@ } BlockValidationState state; - active_chainstate.ActivateBestChain(config, state); + active_chainstate.ActivateBestChain(state); if (!state.IsValid()) { throw JSONRPCError(RPC_DATABASE_ERROR, state.GetRejectReason()); diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -994,7 +994,7 @@ const PackageMempoolAcceptResult package_result = [&] { LOCK(::cs_main); if (txns.size() > 1) { - return ProcessNewPackage(config, chainstate, mempool, txns, + return ProcessNewPackage(chainstate, mempool, txns, /* test_accept */ true); } return PackageMempoolAcceptResult( diff --git a/src/test/fuzz/validation_load_mempool.cpp b/src/test/fuzz/validation_load_mempool.cpp --- a/src/test/fuzz/validation_load_mempool.cpp +++ b/src/test/fuzz/validation_load_mempool.cpp @@ -47,7 +47,6 @@ auto fuzzed_fopen = [&](const fs::path &, const char *) { return fuzzed_file_provider.open(); }; - (void)chainstate.LoadMempool(GetConfig(), MempoolPath(g_setup->m_args), - fuzzed_fopen); + (void)chainstate.LoadMempool(MempoolPath(g_setup->m_args), fuzzed_fopen); (void)DumpMempool(pool, MempoolPath(g_setup->m_args), fuzzed_fopen, true); } diff --git a/src/test/txpackage_tests.cpp b/src/test/txpackage_tests.cpp --- a/src/test/txpackage_tests.cpp +++ b/src/test/txpackage_tests.cpp @@ -95,9 +95,9 @@ /* output_destination */ child_locking_script, /* output_amount */ Amount(48 * COIN), /* submit */ false); CTransactionRef tx_child = MakeTransactionRef(mtx_child); - const auto result_parent_child = ProcessNewPackage( - GetConfig(), m_node.chainman->ActiveChainstate(), *m_node.mempool, - {tx_parent, tx_child}, /* test_accept */ true); + const auto result_parent_child = + ProcessNewPackage(m_node.chainman->ActiveChainstate(), *m_node.mempool, + {tx_parent, tx_child}, /* test_accept */ true); BOOST_CHECK_MESSAGE(result_parent_child.m_state.IsValid(), "Package validation unexpectedly failed: " << result_parent_child.m_state.GetRejectReason()); @@ -118,8 +118,8 @@ BOOST_CHECK(GetVirtualTransactionSize(*giant_ptx) > MAX_PACKAGE_SIZE * 1000); auto result_single_large = - ProcessNewPackage(GetConfig(), m_node.chainman->ActiveChainstate(), - *m_node.mempool, {giant_ptx}, /* test_accept */ true); + ProcessNewPackage(m_node.chainman->ActiveChainstate(), *m_node.mempool, + {giant_ptx}, /* test_accept */ true); BOOST_CHECK(result_single_large.m_state.IsInvalid()); BOOST_CHECK_EQUAL(result_single_large.m_state.GetResult(), PackageValidationResult::PCKG_TX); @@ -240,7 +240,6 @@ } BOOST_FIXTURE_TEST_CASE(package_submission_tests, TestChain100Setup) { - const Config &config{GetConfig()}; unsigned int expected_pool_size = m_node.mempool->size(); CKey parent_key; parent_key.MakeNewKey(true); @@ -261,7 +260,7 @@ { LOCK(cs_main); auto result_unrelated_submit = ProcessNewPackage( - config, m_node.chainman->ActiveChainstate(), *m_node.mempool, + m_node.chainman->ActiveChainstate(), *m_node.mempool, package_unrelated, /*test_accept=*/false); BOOST_CHECK(result_unrelated_submit.m_state.IsInvalid()); BOOST_CHECK_EQUAL(result_unrelated_submit.m_state.GetResult(), @@ -312,8 +311,8 @@ { LOCK(cs_main); auto result_3gen_submit = ProcessNewPackage( - config, m_node.chainman->ActiveChainstate(), *m_node.mempool, - package_3gen, /*test_accept=*/false); + m_node.chainman->ActiveChainstate(), *m_node.mempool, package_3gen, + /*test_accept=*/false); BOOST_CHECK(result_3gen_submit.m_state.IsInvalid()); BOOST_CHECK_EQUAL(result_3gen_submit.m_state.GetResult(), PackageValidationResult::PCKG_POLICY); @@ -330,7 +329,7 @@ { LOCK(cs_main); const auto result_missing_parent = ProcessNewPackage( - config, m_node.chainman->ActiveChainstate(), *m_node.mempool, + m_node.chainman->ActiveChainstate(), *m_node.mempool, package_missing_parent, /*test_accept=*/false); BOOST_CHECK(result_missing_parent.m_state.IsInvalid()); BOOST_CHECK_EQUAL(result_missing_parent.m_state.GetResult(), @@ -344,7 +343,7 @@ { LOCK(cs_main); const auto submit_parent_child = ProcessNewPackage( - config, m_node.chainman->ActiveChainstate(), *m_node.mempool, + m_node.chainman->ActiveChainstate(), *m_node.mempool, package_parent_child, /*test_accept=*/false); expected_pool_size += 2; BOOST_CHECK_MESSAGE( @@ -369,7 +368,7 @@ { LOCK(cs_main); const auto submit_deduped = ProcessNewPackage( - config, m_node.chainman->ActiveChainstate(), *m_node.mempool, + m_node.chainman->ActiveChainstate(), *m_node.mempool, package_parent_child, /*test_accept=*/false); BOOST_CHECK_MESSAGE(submit_deduped.m_state.IsValid(), "Package validation unexpectedly failed: " @@ -404,7 +403,7 @@ { LOCK(cs_main); const auto result_confirmed_parent = ProcessNewPackage( - config, m_node.chainman->ActiveChainstate(), *m_node.mempool, + m_node.chainman->ActiveChainstate(), *m_node.mempool, package_with_confirmed, /*test_accept=*/false); BOOST_CHECK(result_confirmed_parent.m_state.IsInvalid()); BOOST_CHECK_EQUAL(result_confirmed_parent.m_state.GetResult(), diff --git a/src/test/util/chainstate.h b/src/test/util/chainstate.h --- a/src/test/util/chainstate.h +++ b/src/test/util/chainstate.h @@ -100,8 +100,7 @@ node.chainman->MaybeRebalanceCaches(); } BlockValidationState state; - if (!node.chainman->ActiveChainstate().ActivateBestChain(::GetConfig(), - state)) { + if (!node.chainman->ActiveChainstate().ActivateBestChain(state)) { throw std::runtime_error( strprintf("ActivateBestChain failed. (%s)", state.ToString())); } 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 @@ -260,12 +260,11 @@ auto [status, error] = LoadChainstate(chainman, m_cache_sizes, options); assert(status == node::ChainstateLoadStatus::SUCCESS); - std::tie(status, error) = - VerifyLoadedChainstate(chainman, options, GetConfig()); + std::tie(status, error) = VerifyLoadedChainstate(chainman, options, config); assert(status == node::ChainstateLoadStatus::SUCCESS); BlockValidationState state; - if (!chainman.ActiveChainstate().ActivateBestChain(config, state)) { + if (!chainman.ActiveChainstate().ActivateBestChain(state)) { throw std::runtime_error( strprintf("ActivateBestChain failed. (%s)", state.ToString())); } 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 @@ -150,7 +150,7 @@ BOOST_CHECK(accepted); } // UpdateTip is called here - bool block_added = background_cs.ActivateBestChain(config, state, pblock); + bool block_added = background_cs.ActivateBestChain(state, pblock); // Ensure tip is as expected BOOST_CHECK_EQUAL(background_cs.m_chain.Tip()->GetBlockHash(), diff --git a/src/test/validation_chainstatemanager_tests.cpp b/src/test/validation_chainstatemanager_tests.cpp --- a/src/test/validation_chainstatemanager_tests.cpp +++ b/src/test/validation_chainstatemanager_tests.cpp @@ -83,7 +83,7 @@ // Unlike c1, which doesn't have any blocks. Gets us different tip, height. c2.LoadGenesisBlock(); BlockValidationState _; - BOOST_CHECK(c2.ActivateBestChain(GetConfig(), _, nullptr)); + BOOST_CHECK(c2.ActivateBestChain(_, nullptr)); BOOST_CHECK(manager.IsSnapshotActive()); BOOST_CHECK(WITH_LOCK(::cs_main, return !manager.IsSnapshotValidated())); diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -291,7 +291,6 @@ * exposed only for testing. Client code should use * ChainstateManager::ProcessTransaction() * - * @param[in] config The global configuration. * @param[in] active_chainstate Reference to the active chainstate. * @param[in] tx The transaction to submit for mempool * acceptance. @@ -310,10 +309,9 @@ * accepted/rejected with reason. */ MempoolAcceptResult -AcceptToMemoryPool(const Config &config, Chainstate &active_chainstate, - const CTransactionRef &tx, int64_t accept_time, - bool bypass_limits, bool test_accept = false, - unsigned int heightOverride = 0) +AcceptToMemoryPool(Chainstate &active_chainstate, const CTransactionRef &tx, + int64_t accept_time, bool bypass_limits, + bool test_accept = false, unsigned int heightOverride = 0) EXCLUSIVE_LOCKS_REQUIRED(cs_main); /** @@ -328,8 +326,8 @@ * be partially submitted. */ PackageMempoolAcceptResult -ProcessNewPackage(const Config &config, Chainstate &active_chainstate, - CTxMemPool &pool, const Package &txns, bool test_accept) +ProcessNewPackage(Chainstate &active_chainstate, CTxMemPool &pool, + const Package &txns, bool test_accept) EXCLUSIVE_LOCKS_REQUIRED(cs_main); /** @@ -901,7 +899,7 @@ * * @returns true unless a system error occurred */ - bool ActivateBestChain(const Config &config, BlockValidationState &state, + bool ActivateBestChain(BlockValidationState &state, std::shared_ptr pblock = nullptr) EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex, !cs_avalancheFinalizedBlockIndex) @@ -935,8 +933,7 @@ * * May not be called in a validationinterface callback. */ - bool PreciousBlock(const Config &config, BlockValidationState &state, - CBlockIndex *pindex) + bool PreciousBlock(BlockValidationState &state, CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex, !cs_avalancheFinalizedBlockIndex) LOCKS_EXCLUDED(cs_main); @@ -1020,7 +1017,7 @@ /** Load the persisted mempool from disk */ void - LoadMempool(const Config &config, const fs::path &load_path, + LoadMempool(const fs::path &load_path, fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen); /** Update the chain tip based on database information, i.e. CoinsTip()'s @@ -1047,14 +1044,13 @@ } private: - bool ActivateBestChainStep(const Config &config, - BlockValidationState &state, + bool ActivateBestChainStep(BlockValidationState &state, CBlockIndex *pindexMostWork, const std::shared_ptr &pblock, bool &fInvalidFound, ConnectTrace &connectTrace) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool->cs, !cs_avalancheFinalizedBlockIndex); - bool ConnectTip(const Config &config, BlockValidationState &state, + bool ConnectTip(BlockValidationState &state, BlockPolicyValidationState &blockPolicyState, CBlockIndex *pindexNew, const std::shared_ptr &pblock, @@ -1251,6 +1247,8 @@ Assert(m_options.adjusted_time_callback); } + const Config &GetConfig() const { return m_options.config; } + const CChainParams &GetParams() const { return m_options.config.GetChainParams(); } diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1035,8 +1035,7 @@ } } // namespace -MempoolAcceptResult AcceptToMemoryPool(const Config &config, - Chainstate &active_chainstate, +MempoolAcceptResult AcceptToMemoryPool(Chainstate &active_chainstate, const CTransactionRef &tx, int64_t accept_time, bool bypass_limits, bool test_accept, @@ -1047,8 +1046,8 @@ std::vector coins_to_uncache; auto args = MemPoolAccept::ATMPArgs::SingleAccept( - config, accept_time, bypass_limits, coins_to_uncache, test_accept, - heightOverride); + active_chainstate.m_chainman.GetConfig(), accept_time, bypass_limits, + coins_to_uncache, test_accept, heightOverride); const MempoolAcceptResult result = MemPoolAccept(pool, active_chainstate) .AcceptSingleTransaction(tx, args); if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) { @@ -1070,14 +1069,17 @@ return result; } -PackageMempoolAcceptResult -ProcessNewPackage(const Config &config, Chainstate &active_chainstate, - CTxMemPool &pool, const Package &package, bool test_accept) { +PackageMempoolAcceptResult ProcessNewPackage(Chainstate &active_chainstate, + CTxMemPool &pool, + const Package &package, + bool test_accept) { AssertLockHeld(cs_main); assert(!package.empty()); assert(std::all_of(package.cbegin(), package.cend(), [](const auto &tx) { return tx != nullptr; })); + const Config &config = active_chainstate.m_chainman.GetConfig(); + std::vector coins_to_uncache; const auto result = [&]() EXCLUSIVE_LOCKS_REQUIRED(cs_main) { AssertLockHeld(cs_main); @@ -2524,7 +2526,7 @@ * * The block is added to connectTrace if connection succeeds. */ -bool Chainstate::ConnectTip(const Config &config, BlockValidationState &state, +bool Chainstate::ConnectTip(BlockValidationState &state, BlockPolicyValidationState &blockPolicyState, CBlockIndex *pindexNew, const std::shared_ptr &pblock, @@ -2563,7 +2565,8 @@ Amount blockFees{Amount::zero()}; CCoinsViewCache view(&CoinsTip()); bool rv = ConnectBlock(blockConnecting, state, pindexNew, view, - BlockValidationOptions(config), &blockFees); + BlockValidationOptions(m_chainman.GetConfig()), + &blockFees); GetMainSignals().BlockChecked(blockConnecting, state); if (!rv) { if (state.IsInvalid()) { @@ -2900,9 +2903,9 @@ * @returns true unless a system error occurred */ bool Chainstate::ActivateBestChainStep( - const Config &config, BlockValidationState &state, - CBlockIndex *pindexMostWork, const std::shared_ptr &pblock, - bool &fInvalidFound, ConnectTrace &connectTrace) { + BlockValidationState &state, CBlockIndex *pindexMostWork, + const std::shared_ptr &pblock, bool &fInvalidFound, + ConnectTrace &connectTrace) { AssertLockHeld(cs_main); if (m_mempool) { AssertLockHeld(m_mempool->cs); @@ -2927,8 +2930,7 @@ // This is likely a fatal error, but keep the mempool consistent, // just in case. Only remove from the mempool in this case. if (m_mempool) { - disconnectpool.updateMempoolForReorg(config, *this, false, - *m_mempool); + disconnectpool.updateMempoolForReorg(*this, false, *m_mempool); } // If we're unable to disconnect a block during normal operation, @@ -2963,7 +2965,7 @@ // Connect new blocks. for (CBlockIndex *pindexConnect : reverse_iterate(vpindexToConnect)) { BlockPolicyValidationState blockPolicyState; - if (!ConnectTip(config, state, blockPolicyState, pindexConnect, + if (!ConnectTip(state, blockPolicyState, pindexConnect, pindexConnect == pindexMostWork ? pblock : std::shared_ptr(), @@ -2990,7 +2992,7 @@ // Make the mempool consistent with the current tip, just in // case any observers try to use it before shutdown. if (m_mempool) { - disconnectpool.updateMempoolForReorg(config, *this, false, + disconnectpool.updateMempoolForReorg(*this, false, *m_mempool); } return false; @@ -3016,8 +3018,7 @@ LogPrint(BCLog::MEMPOOL, "Updating mempool due to reorganization or " "rules upgrade/downgrade\n"); - disconnectpool.updateMempoolForReorg(config, *this, true, - *m_mempool); + disconnectpool.updateMempoolForReorg(*this, true, *m_mempool); } m_mempool->check(this->CoinsTip(), this->m_chain.Height() + 1); @@ -3076,8 +3077,7 @@ } } -bool Chainstate::ActivateBestChain(const Config &config, - BlockValidationState &state, +bool Chainstate::ActivateBestChain(BlockValidationState &state, std::shared_ptr pblock) { AssertLockNotHeld(m_chainstate_mutex); @@ -3146,7 +3146,7 @@ bool fInvalidFound = false; std::shared_ptr nullBlockPtr; if (!ActivateBestChainStep( - config, state, pindexMostWork, + state, pindexMostWork, pblock && pblock->GetHash() == pindexMostWork->GetBlockHash() ? pblock @@ -3251,8 +3251,7 @@ return true; } -bool Chainstate::PreciousBlock(const Config &config, - BlockValidationState &state, +bool Chainstate::PreciousBlock(BlockValidationState &state, CBlockIndex *pindex) { AssertLockNotHeld(m_chainstate_mutex); AssertLockNotHeld(::cs_main); @@ -3289,7 +3288,7 @@ } } - return ActivateBestChain(config, state); + return ActivateBestChain(state); } namespace { @@ -3371,7 +3370,7 @@ // DisconnectTip will add transactions to disconnectpool. // When all unwinding is done and we are on a new tip, we must // add all transactions back to the mempool against the new tip. - disconnectpool.updateMempoolForReorg(config, *this, + disconnectpool.updateMempoolForReorg(*this, /* fAddToMempool = */ ret, *m_mempool); } @@ -4509,7 +4508,7 @@ // Only used to report errors, not invalidity - ignore it BlockValidationState state; - if (!ActiveChainstate().ActivateBestChain(config, state, block)) { + if (!ActiveChainstate().ActivateBestChain(state, block)) { return error("%s: ActivateBestChain failed (%s)", __func__, state.ToString()); } @@ -4527,13 +4526,8 @@ state.Invalid(TxValidationResult::TX_NO_MEMPOOL, "no-mempool"); return MempoolAcceptResult::Failure(state); } - // Use GetConfig() temporarily. It will be removed in a follow-up by - // making AcceptToMemoryPool take a CChainParams instead of a Config. - // This avoids passing an extra Config argument to this function that will - // be removed soon. - auto result = - AcceptToMemoryPool(::GetConfig(), active_chainstate, tx, GetTime(), - /*bypass_limits=*/false, test_accept); + auto result = AcceptToMemoryPool(active_chainstate, tx, GetTime(), + /*bypass_limits=*/false, test_accept); active_chainstate.GetMempool()->check( active_chainstate.CoinsTip(), active_chainstate.m_chain.Height() + 1); return result; @@ -4591,13 +4585,12 @@ } } -void Chainstate::LoadMempool(const Config &config, const fs::path &load_path, +void Chainstate::LoadMempool(const fs::path &load_path, FopenFn mockable_fopen_function) { if (!m_mempool) { return; } - ::LoadMempool(config, *m_mempool, load_path, *this, - mockable_fopen_function); + ::LoadMempool(*m_mempool, load_path, *this, mockable_fopen_function); m_mempool->SetLoadTried(!ShutdownRequested()); } @@ -5230,7 +5223,7 @@ // continue if (hash == params.GetConsensus().hashGenesisBlock) { BlockValidationState state; - if (!ActivateBestChain(config, state, nullptr)) { + if (!ActivateBestChain(state, nullptr)) { break; } } @@ -5245,7 +5238,7 @@ // concurrent network message processing, but that is not // reliable for the purpose of pruning while importing. BlockValidationState state; - if (!ActivateBestChain(config, state, pblock)) { + if (!ActivateBestChain(state, pblock)) { LogPrint(BCLog::REINDEX, "failed to activate chain (%s)\n", state.ToString());