From 0213fbebe6b2ecde2c7217af6adfe114fb55058b Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Tue, 25 Jun 2024 09:44:28 +0000 Subject: [PATCH] merge bitcoin#21866: Farewell, global Chainstate! --- src/bench/duplicate_inputs.cpp | 1 - src/dsnotificationinterface.cpp | 6 +- src/dsnotificationinterface.h | 3 + src/index/base.cpp | 3 +- src/init.cpp | 44 ++-- src/miner.cpp | 2 - src/net_processing.cpp | 1 - src/node/blockstorage.cpp | 2 +- src/node/coin.cpp | 1 - src/node/coinstats.cpp | 1 - src/node/context.cpp | 1 + src/node/context.h | 2 +- src/node/interfaces.cpp | 54 +--- src/node/transaction.cpp | 1 - src/qt/test/apptests.cpp | 5 - src/qt/test/wallettests.cpp | 4 +- src/rest.cpp | 2 +- src/rpc/blockchain.cpp | 1 - src/rpc/masternode.cpp | 10 +- src/rpc/mining.cpp | 2 - src/test/block_reward_reallocation_tests.cpp | 14 +- src/test/blockfilter_index_tests.cpp | 26 +- src/test/coinstatsindex_tests.cpp | 8 +- src/test/denialofservice_tests.cpp | 4 +- .../dynamic_activation_thresholds_tests.cpp | 30 +-- src/test/evo_assetlocks_tests.cpp | 4 +- src/test/evo_deterministicmns_tests.cpp | 232 +++++++++--------- src/test/fuzz/coins_view.cpp | 4 +- src/test/fuzz/load_external_block_file.cpp | 7 +- src/test/fuzz/validation_load_mempool.cpp | 7 +- src/test/interfaces_tests.cpp | 2 +- src/test/miner_tests.cpp | 87 ++++--- src/test/txindex_tests.cpp | 2 +- src/test/txvalidation_tests.cpp | 2 +- src/test/txvalidationcache_tests.cpp | 38 +-- src/test/util/mining.cpp | 4 +- src/test/util/setup_common.cpp | 36 +-- src/test/validation_block_tests.cpp | 14 +- src/txmempool.cpp | 3 - src/validation.cpp | 68 ----- src/validation.h | 19 +- src/wallet/test/coinjoin_tests.cpp | 8 +- src/wallet/test/wallet_tests.cpp | 50 ++-- 43 files changed, 358 insertions(+), 457 deletions(-) diff --git a/src/bench/duplicate_inputs.cpp b/src/bench/duplicate_inputs.cpp index 173a2faca9027..11fbd361785ae 100644 --- a/src/bench/duplicate_inputs.cpp +++ b/src/bench/duplicate_inputs.cpp @@ -25,7 +25,6 @@ static void DuplicateInputs(benchmark::Bench& bench) CMutableTransaction coinbaseTx{}; CMutableTransaction naughtyTx{}; - assert(std::addressof(::ChainActive()) == std::addressof(testing_setup->m_node.chainman->ActiveChain())); CBlockIndex* pindexPrev = testing_setup->m_node.chainman->ActiveChain().Tip(); assert(pindexPrev != nullptr); block.nBits = GetNextWorkRequired(pindexPrev, &block, chainparams.GetConsensus()); diff --git a/src/dsnotificationinterface.cpp b/src/dsnotificationinterface.cpp index 45931a633b04f..0741ecc91b7b3 100644 --- a/src/dsnotificationinterface.cpp +++ b/src/dsnotificationinterface.cpp @@ -28,6 +28,7 @@ CDSNotificationInterface::CDSNotificationInterface(CConnman& connman, CMasternodeSync& mn_sync, CGovernanceManager& govman, PeerManager& peerman, + const ChainstateManager& chainman, const CActiveMasternodeManager* const mn_activeman, const std::unique_ptr& dmnman, const std::unique_ptr& llmq_ctx, @@ -36,6 +37,7 @@ CDSNotificationInterface::CDSNotificationInterface(CConnman& connman, m_mn_sync(mn_sync), m_govman(govman), m_peerman(peerman), + m_chainman(chainman), m_mn_activeman(mn_activeman), m_dmnman(dmnman), m_llmq_ctx(llmq_ctx), @@ -43,8 +45,8 @@ CDSNotificationInterface::CDSNotificationInterface(CConnman& connman, void CDSNotificationInterface::InitializeCurrentBlockTip() { - SynchronousUpdatedBlockTip(::ChainActive().Tip(), nullptr, ::ChainstateActive().IsInitialBlockDownload()); - UpdatedBlockTip(::ChainActive().Tip(), nullptr, ::ChainstateActive().IsInitialBlockDownload()); + SynchronousUpdatedBlockTip(m_chainman.ActiveChain().Tip(), nullptr, m_chainman.ActiveChainstate().IsInitialBlockDownload()); + UpdatedBlockTip(m_chainman.ActiveChain().Tip(), nullptr, m_chainman.ActiveChainstate().IsInitialBlockDownload()); } void CDSNotificationInterface::AcceptedBlockHeader(const CBlockIndex *pindexNew) diff --git a/src/dsnotificationinterface.h b/src/dsnotificationinterface.h index b715217ac118e..dc4456de40579 100644 --- a/src/dsnotificationinterface.h +++ b/src/dsnotificationinterface.h @@ -11,6 +11,7 @@ class CActiveMasternodeManager; class CConnman; class CDeterministicMNManager; class CGovernanceManager; +class ChainstateManager; class CMasternodeSync; class PeerManager; struct CJContext; @@ -23,6 +24,7 @@ class CDSNotificationInterface : public CValidationInterface CMasternodeSync& mn_sync, CGovernanceManager& govman, PeerManager& peerman, + const ChainstateManager& chainman, const CActiveMasternodeManager* const mn_activeman, const std::unique_ptr& dmnman, const std::unique_ptr& llmq_ctx, @@ -50,6 +52,7 @@ class CDSNotificationInterface : public CValidationInterface CMasternodeSync& m_mn_sync; CGovernanceManager& m_govman; PeerManager& m_peerman; + const ChainstateManager& m_chainman; const CActiveMasternodeManager* const m_mn_activeman; const std::unique_ptr& m_dmnman; const std::unique_ptr& m_llmq_ctx; diff --git a/src/index/base.cpp b/src/index/base.cpp index f5ccd36344dce..7a0afaff8d216 100644 --- a/src/index/base.cpp +++ b/src/index/base.cpp @@ -10,7 +10,7 @@ #include #include #include -#include // For g_chainman +#include #include constexpr uint8_t DB_BEST_BLOCK{'B'}; @@ -349,7 +349,6 @@ void BaseIndex::Interrupt() bool BaseIndex::Start(CChainState& active_chainstate) { - assert(std::addressof(::ChainstateActive()) == std::addressof(active_chainstate)); m_chainstate = &active_chainstate; // Need to register this ValidationInterface before running Init(), so that // callbacks are not missed if Init sets m_synced to true. diff --git a/src/init.cpp b/src/init.cpp index 5b4044b485b06..005cca71c5fa8 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -402,7 +402,7 @@ void Shutdown(NodeContext& node) ECC_Stop(); node.mempool.reset(); node.fee_estimator.reset(); - node.chainman = nullptr; + node.chainman.reset(); node.scheduler.reset(); try { @@ -883,12 +883,12 @@ static void StartupNotify(const ArgsManager& args) } #endif -static void PeriodicStats(ArgsManager& args, const CTxMemPool& mempool) +static void PeriodicStats(ArgsManager& args, ChainstateManager& chainman, const CTxMemPool& mempool) { assert(args.GetBoolArg("-statsenabled", DEFAULT_STATSD_ENABLE)); CCoinsStats stats{CoinStatsHashType::NONE}; - ::ChainstateActive().ForceFlushStateToDisk(); - if (WITH_LOCK(cs_main, return GetUTXOStats(&::ChainstateActive().CoinsDB(), std::ref(g_chainman.m_blockman), stats, RpcInterruptionPoint, ::ChainActive().Tip()))) { + chainman.ActiveChainstate().ForceFlushStateToDisk(); + if (WITH_LOCK(cs_main, return GetUTXOStats(&chainman.ActiveChainstate().CoinsDB(), std::ref(chainman.m_blockman), stats, RpcInterruptionPoint, chainman.ActiveChain().Tip()))) { statsClient.gauge("utxoset.tx", stats.nTransactions, 1.0f); statsClient.gauge("utxoset.txOutputs", stats.nTransactionOutputs, 1.0f); statsClient.gauge("utxoset.dbSizeBytes", stats.nDiskSize, 1.0f); @@ -902,7 +902,7 @@ static void PeriodicStats(ArgsManager& args, const CTxMemPool& mempool) } // short version of GetNetworkHashPS(120, -1); - CBlockIndex *tip = ::ChainActive().Tip(); + CBlockIndex *tip = chainman.ActiveChain().Tip(); CBlockIndex *pindex = tip; int64_t minTime = pindex->GetBlockTime(); int64_t maxTime = minTime; @@ -923,7 +923,7 @@ static void PeriodicStats(ArgsManager& args, const CTxMemPool& mempool) // No need for cs_main, we never use null tip here statsClient.gaugeDouble("network.difficulty", (double)GetDifficulty(tip)); - statsClient.gauge("transactions.txCacheSize", WITH_LOCK(cs_main, return ::ChainstateActive().CoinsTip().GetCacheSize()), 1.0f); + statsClient.gauge("transactions.txCacheSize", WITH_LOCK(cs_main, return chainman.ActiveChainstate().CoinsTip().GetCacheSize()), 1.0f); statsClient.gauge("transactions.totalTransactions", tip->nChainTx, 1.0f); { @@ -1716,8 +1716,8 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc node.mempool = std::make_unique(node.fee_estimator.get(), check_ratio); assert(!node.chainman); - node.chainman = &g_chainman; - ChainstateManager& chainman = *Assert(node.chainman); + node.chainman = std::make_unique(); + ChainstateManager& chainman = *node.chainman; assert(!node.mn_metaman); node.mn_metaman = std::make_unique(); @@ -1913,7 +1913,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc #endif pdsNotificationInterface = new CDSNotificationInterface( - *node.connman, *node.mn_sync, *node.govman, *node.peerman, node.mn_activeman.get(), node.dmnman, node.llmq_ctx, node.cj_ctx + *node.connman, *node.mn_sync, *node.govman, *node.peerman, chainman, node.mn_activeman.get(), node.dmnman, node.llmq_ctx, node.cj_ctx ); RegisterValidationInterface(pdsNotificationInterface); @@ -2016,7 +2016,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc node.llmq_ctx = std::make_unique(chainman.ActiveChainstate(), *node.connman, *node.dmnman, *node.evodb, *node.mn_metaman, *node.mnhf_manager, *node.sporkman, *node.mempool, node.mn_activeman.get(), *node.mn_sync, node.peerman, /* unit_tests = */ false, /* wipe = */ fReset || fReindexChainState); // Enable CMNHFManager::{Process, Undo}Block - node.mnhf_manager->ConnectManagers(node.chainman, node.llmq_ctx->qman.get()); + node.mnhf_manager->ConnectManagers(node.chainman.get(), node.llmq_ctx->qman.get()); // Have to start it early to let VerifyDB check ChainLock signatures in coinbase node.llmq_ctx->Start(); @@ -2050,12 +2050,12 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc // If the loaded chain has a wrong genesis, bail out immediately // (we're likely using a testnet datadir, or the other way around). if (!chainman.BlockIndex().empty() && - !g_chainman.m_blockman.LookupBlockIndex(chainparams.GetConsensus().hashGenesisBlock)) { + !chainman.m_blockman.LookupBlockIndex(chainparams.GetConsensus().hashGenesisBlock)) { return InitError(_("Incorrect or no genesis block found. Wrong datadir for network?")); } if (!chainparams.GetConsensus().hashDevnetGenesisBlock.IsNull() && !chainman.BlockIndex().empty() && - !g_chainman.m_blockman.LookupBlockIndex(chainparams.GetConsensus().hashDevnetGenesisBlock)) { + !chainman.m_blockman.LookupBlockIndex(chainparams.GetConsensus().hashDevnetGenesisBlock)) { return InitError(_("Incorrect or no devnet genesis block found. Wrong datadir for devnet specified?")); } @@ -2088,7 +2088,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc // If we're not mid-reindex (based on disk + args), add a genesis block on disk // (otherwise we use the one already on disk). // This is called again in ThreadImport after the reindex completes. - if (!fReindex && !::ChainstateActive().LoadGenesisBlock()) { + if (!fReindex && !chainman.ActiveChainstate().LoadGenesisBlock()) { strLoadError = _("Error initializing block database"); break; } @@ -2132,7 +2132,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc // TODO: CEvoDB instance should probably be a part of CChainState // (for multiple chainstates to actually work in parallel) // and not a global - if (&::ChainstateActive() == chainstate && !node.evodb->CommitRootTransaction()) { + if (&chainman.ActiveChainstate() == chainstate && !node.evodb->CommitRootTransaction()) { strLoadError = _("Failed to commit EvoDB"); failed_chainstate_init = true; break; @@ -2210,7 +2210,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc // TODO: CEvoDB instance should probably be a part of CChainState // (for multiple chainstates to actually work in parallel) // and not a global - if (&::ChainstateActive() == chainstate && !node.evodb->IsEmpty()) { + if (&chainman.ActiveChainstate() == chainstate && !node.evodb->IsEmpty()) { // EvoDB processed some blocks earlier but we have no blocks anymore, something is wrong strLoadError = _("Error initializing block database"); failed_verification = true; @@ -2271,7 +2271,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc // ********************************************************* Step 7d: Setup other Dash services - bool fLoadCacheFiles = !(fReindex || fReindexChainState) && (::ChainActive().Tip() != nullptr); + bool fLoadCacheFiles = !(fReindex || fReindexChainState) && (chainman.ActiveChain().Tip() != nullptr); if (!node.netfulfilledman->LoadCache(fLoadCacheFiles)) { auto file_path = (GetDataDir() / "netfulfilled.dat").string(); @@ -2302,21 +2302,21 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc // ********************************************************* Step 8: start indexers if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) { g_txindex = std::make_unique(nTxIndexCache, false, fReindex); - if (!g_txindex->Start(::ChainstateActive())) { + if (!g_txindex->Start(chainman.ActiveChainstate())) { return false; } } for (const auto& filter_type : g_enabled_filter_types) { InitBlockFilterIndex(filter_type, filter_index_cache, false, fReindex); - if (!GetBlockFilterIndex(filter_type)->Start(::ChainstateActive())) { + if (!GetBlockFilterIndex(filter_type)->Start(chainman.ActiveChainstate())) { return false; } } if (args.GetBoolArg("-coinstatsindex", DEFAULT_COINSTATSINDEX)) { g_coin_stats_index = std::make_unique(/* cache size */ 0, false, fReindex); - if (!g_coin_stats_index->Start(::ChainstateActive())) { + if (!g_coin_stats_index->Start(chainman.ActiveChainstate())) { return false; } } @@ -2383,7 +2383,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc if (args.GetBoolArg("-statsenabled", DEFAULT_STATSD_ENABLE)) { int nStatsPeriod = std::min(std::max((int)args.GetArg("-statsperiod", DEFAULT_STATSD_PERIOD), MIN_STATSD_PERIOD), MAX_STATSD_PERIOD); - node.scheduler->scheduleEvery(std::bind(&PeriodicStats, std::ref(*node.args), std::cref(*node.mempool)), std::chrono::seconds{nStatsPeriod}); + node.scheduler->scheduleEvery(std::bind(&PeriodicStats, std::ref(*node.args), std::ref(chainman), std::cref(*node.mempool)), std::chrono::seconds{nStatsPeriod}); } // ********************************************************* Step 11: import blocks @@ -2400,7 +2400,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc // Either install a handler to notify us when genesis activates, or set fHaveGenesis directly. // No locking, as this happens before any background thread is started. boost::signals2::connection block_notify_genesis_wait_connection; - if (::ChainActive().Tip() == nullptr) { + if (chainman.ActiveChain().Tip() == nullptr) { block_notify_genesis_wait_connection = uiInterface.NotifyBlockTip_connect(std::bind(BlockNotifyGenesisWait, std::placeholders::_2)); } else { fHaveGenesis = true; @@ -2476,7 +2476,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc tip_info->header_time = ::pindexBestHeader->GetBlockTime(); } } - LogPrintf("::ChainActive().Height() = %d\n", chain_active_height); + LogPrintf("nBestHeight = %d\n", chain_active_height); if (node.peerman) node.peerman->SetBestHeight(chain_active_height); // Map ports with UPnP or NAT-PMP. diff --git a/src/miner.cpp b/src/miner.cpp index 273ebcc94da4e..12ea59def7404 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -132,7 +132,6 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc pblocktemplate->vTxSigOps.push_back(-1); // updated at end LOCK2(cs_main, m_mempool.cs); - assert(std::addressof(*::ChainActive().Tip()) == std::addressof(*m_chainstate.m_chain.Tip())); CBlockIndex* pindexPrev = m_chainstate.m_chain.Tip(); assert(pindexPrev != nullptr); nHeight = pindexPrev->nHeight + 1; @@ -265,7 +264,6 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(*pblock->vtx[0]); BlockValidationState state; - assert(std::addressof(::ChainstateActive()) == std::addressof(m_chainstate)); if (!TestBlockValidity(state, m_clhandler, m_evoDb, chainparams, m_chainstate, *pblock, pindexPrev, false, false)) { throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s", __func__, state.ToString())); } diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 1e003a688d2cd..0504616f3847f 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1899,7 +1899,6 @@ PeerManagerImpl::PeerManagerImpl(const CChainParams& chainparams, CConnman& conn m_mn_activeman(mn_activeman), m_ignore_incoming_txs(ignore_incoming_txs) { - assert(std::addressof(g_chainman) == std::addressof(m_chainman)); // Stale tip checking and peer eviction are on two different timers, but we // don't want them to get out of sync due to drift in the scheduler, so we // combine them in one function and schedule at the quicker (peer-eviction) diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp index a0ea4ab33bcf2..d271f93ccac07 100644 --- a/src/node/blockstorage.cpp +++ b/src/node/blockstorage.cpp @@ -210,7 +210,7 @@ void ThreadImport(ChainstateManager& chainman, CDeterministicMNManager& dmnman, } if (mn_activeman != nullptr) { - mn_activeman->Init(::ChainActive().Tip()); + mn_activeman->Init(chainman.ActiveTip()); } g_wallet_init_interface.AutoLockMasternodeCollaterals(); diff --git a/src/node/coin.cpp b/src/node/coin.cpp index 23d4fa2aaef8f..50fddf3ab0dc3 100644 --- a/src/node/coin.cpp +++ b/src/node/coin.cpp @@ -13,7 +13,6 @@ void FindCoins(const NodeContext& node, std::map& coins) assert(node.mempool); assert(node.chainman); LOCK2(cs_main, node.mempool->cs); - assert(std::addressof(::ChainstateActive()) == std::addressof(node.chainman->ActiveChainstate())); CCoinsViewCache& chain_view = node.chainman->ActiveChainstate().CoinsTip(); CCoinsViewMemPool mempool_view(&chain_view, *node.mempool); for (auto& coin : coins) { diff --git a/src/node/coinstats.cpp b/src/node/coinstats.cpp index d86e6ae3160fe..222e7c5bf814a 100644 --- a/src/node/coinstats.cpp +++ b/src/node/coinstats.cpp @@ -113,7 +113,6 @@ static bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& if (!pindex) { LOCK(cs_main); - assert(std::addressof(g_chainman.m_blockman) == std::addressof(blockman)); pindex = blockman.LookupBlockIndex(view->GetBestBlock()); } stats.nHeight = Assert(pindex)->nHeight; diff --git a/src/node/context.cpp b/src/node/context.cpp index ba850e80af53b..075ad5eb0693a 100644 --- a/src/node/context.cpp +++ b/src/node/context.cpp @@ -26,6 +26,7 @@ #include #include #include +#include NodeContext::NodeContext() {} NodeContext::~NodeContext() {} diff --git a/src/node/context.h b/src/node/context.h index ed435f31fce7d..129c6d73ec294 100644 --- a/src/node/context.h +++ b/src/node/context.h @@ -58,7 +58,7 @@ struct NodeContext { std::unique_ptr mempool; std::unique_ptr fee_estimator; std::unique_ptr peerman; - ChainstateManager* chainman{nullptr}; // Currently a raw pointer because the memory is not managed by this struct + std::unique_ptr chainman; std::unique_ptr banman; ArgsManager* args{nullptr}; // Currently a raw pointer because the memory is not managed by this struct std::unique_ptr chain; diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index 051c5ea785fae..be4a3de4217dc 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -428,26 +428,16 @@ class NodeImpl : public Node int getNumBlocks() override { LOCK(::cs_main); - assert(std::addressof(::ChainActive()) == std::addressof(chainman().ActiveChain())); return chainman().ActiveChain().Height(); } uint256 getBestBlockHash() override { - const CBlockIndex* tip; - { - // TODO: Temporary scope to check correctness of refactored code. - // Should be removed manually after merge of - // https://github.com/bitcoin/bitcoin/pull/20158 - LOCK(cs_main); - assert(std::addressof(::ChainActive()) == std::addressof(chainman().ActiveChain())); - tip = chainman().ActiveChain().Tip(); - } + const CBlockIndex* tip = WITH_LOCK(::cs_main, return chainman().ActiveChain().Tip()); return tip ? tip->GetBlockHash() : Params().GenesisBlock().GetHash(); } int64_t getLastBlockTime() override { LOCK(::cs_main); - assert(std::addressof(::ChainActive()) == std::addressof(chainman().ActiveChain())); if (chainman().ActiveChain().Tip()) { return chainman().ActiveChain().Tip()->GetBlockTime(); } @@ -456,7 +446,6 @@ class NodeImpl : public Node std::string getLastBlockHash() override { LOCK(::cs_main); - assert(std::addressof(::ChainActive()) == std::addressof(m_context->chainman->ActiveChain())); if (m_context->chainman->ActiveChain().Tip()) { return m_context->chainman->ActiveChain().Tip()->GetBlockHash().ToString(); } @@ -467,22 +456,12 @@ class NodeImpl : public Node const CBlockIndex* tip; { LOCK(::cs_main); - assert(std::addressof(::ChainActive()) == std::addressof(chainman().ActiveChain())); tip = chainman().ActiveChain().Tip(); } return GuessVerificationProgress(Params().TxData(), tip); } bool isInitialBlockDownload() override { - const CChainState* active_chainstate; - { - // TODO: Temporary scope to check correctness of refactored code. - // Should be removed manually after merge of - // https://github.com/bitcoin/bitcoin/pull/20158 - LOCK(::cs_main); - active_chainstate = &m_context->chainman->ActiveChainstate(); - assert(std::addressof(::ChainstateActive()) == std::addressof(*active_chainstate)); - } - return active_chainstate->IsInitialBlockDownload(); + return chainman().ActiveChainstate().IsInitialBlockDownload(); } bool isMasternode() override { @@ -512,7 +491,6 @@ class NodeImpl : public Node bool getUnspentOutput(const COutPoint& output, Coin& coin) override { LOCK(::cs_main); - assert(std::addressof(::ChainstateActive()) == std::addressof(chainman().ActiveChainstate())); return chainman().ActiveChainstate().CoinsTip().GetCoin(output, coin); } WalletLoader& walletLoader() override @@ -761,8 +739,8 @@ class ChainImpl : public Chain std::optional findFork(const uint256& hash, std::optional* height) override { LOCK(cs_main); - const CChain& active = Assert(m_node.chainman)->ActiveChain(); - const CBlockIndex* block = g_chainman.m_blockman.LookupBlockIndex(hash); + const CChain& active = chainman().ActiveChain(); + const CBlockIndex* block = chainman().m_blockman.LookupBlockIndex(hash); const CBlockIndex* fork = block ? active.FindFork(block) : nullptr; if (height) { if (block) { @@ -779,14 +757,12 @@ class ChainImpl : public Chain CBlockLocator getTipLocator() override { LOCK(cs_main); - assert(std::addressof(::ChainActive()) == std::addressof(chainman().ActiveChain())); return chainman().ActiveChain().GetLocator(); } std::optional findLocatorFork(const CBlockLocator& locator) override { LOCK(cs_main); const CChain& active = Assert(m_node.chainman)->ActiveChain(); - assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman)); if (CBlockIndex* fork = m_node.chainman->m_blockman.FindForkInGlobalIndex(active, locator)) { return fork->nHeight; } @@ -795,7 +771,6 @@ class ChainImpl : public Chain bool checkFinalTx(const CTransaction& tx) override { LOCK(cs_main); - assert(std::addressof(::ChainActive()) == std::addressof(m_node.chainman->ActiveChain())); return CheckFinalTx(m_node.chainman->ActiveChain().Tip(), tx); } bool isInstantSendLockedTx(const uint256& hash) override @@ -810,7 +785,7 @@ class ChainImpl : public Chain } std::vector listMNCollaterials(const std::vector>& outputs) override { - const CBlockIndex *tip = WITH_LOCK(::cs_main, return ::ChainActive().Tip()); + const CBlockIndex *tip = WITH_LOCK(::cs_main, return chainman().ActiveChain().Tip()); CDeterministicMNList mnList{}; if (tip != nullptr && m_node.dmnman != nullptr) { mnList = m_node.dmnman->GetListForBlock(tip); @@ -828,7 +803,6 @@ class ChainImpl : public Chain { WAIT_LOCK(cs_main, lock); const CChain& active = Assert(m_node.chainman)->ActiveChain(); - assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman)); return FillBlock(m_node.chainman->m_blockman.LookupBlockIndex(hash), block, lock, active); } bool findFirstBlockWithTimeAndHeight(int64_t min_time, int min_height, const FoundBlock& block) override @@ -841,7 +815,6 @@ class ChainImpl : public Chain { WAIT_LOCK(cs_main, lock); const CChain& active = Assert(m_node.chainman)->ActiveChain(); - assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman)); if (const CBlockIndex* block = m_node.chainman->m_blockman.LookupBlockIndex(block_hash)) { if (const CBlockIndex* ancestor = block->GetAncestor(ancestor_height)) { return FillBlock(ancestor, ancestor_out, lock, active); @@ -853,9 +826,7 @@ class ChainImpl : public Chain { WAIT_LOCK(cs_main, lock); const CChain& active = Assert(m_node.chainman)->ActiveChain(); - assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman)); const CBlockIndex* block = m_node.chainman->m_blockman.LookupBlockIndex(block_hash); - assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman)); const CBlockIndex* ancestor = m_node.chainman->m_blockman.LookupBlockIndex(ancestor_hash); if (block && ancestor && block->GetAncestor(ancestor->nHeight) != ancestor) ancestor = nullptr; return FillBlock(ancestor, ancestor_out, lock, active); @@ -864,9 +835,7 @@ class ChainImpl : public Chain { WAIT_LOCK(cs_main, lock); const CChain& active = Assert(m_node.chainman)->ActiveChain(); - assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman)); const CBlockIndex* block1 = m_node.chainman->m_blockman.LookupBlockIndex(block_hash1); - assert(std::addressof(g_chainman) == std::addressof(*m_node.chainman)); const CBlockIndex* block2 = m_node.chainman->m_blockman.LookupBlockIndex(block_hash2); const CBlockIndex* ancestor = block1 && block2 ? LastCommonAncestor(block1, block2) : nullptr; // Using & instead of && below to avoid short circuiting and leaving @@ -880,7 +849,6 @@ class ChainImpl : public Chain double guessVerificationProgress(const uint256& block_hash) override { LOCK(cs_main); - assert(std::addressof(g_chainman.m_blockman) == std::addressof(chainman().m_blockman)); return GuessVerificationProgress(Params().TxData(), chainman().m_blockman.LookupBlockIndex(block_hash)); } bool hasBlocks(const uint256& block_hash, int min_height, std::optional max_height) override @@ -893,7 +861,6 @@ class ChainImpl : public Chain // used to limit the range, and passing min_height that's too low or // max_height that's too high will not crash or change the result. LOCK(::cs_main); - assert(std::addressof(g_chainman.m_blockman) == std::addressof(chainman().m_blockman)); if (CBlockIndex* block = chainman().m_blockman.LookupBlockIndex(block_hash)) { if (max_height && block->nHeight >= *max_height) block = block->GetAncestor(*max_height); for (; block->nStatus & BLOCK_HAVE_DATA; block = block->pprev) { @@ -976,16 +943,7 @@ class ChainImpl : public Chain } bool isReadyToBroadcast() override { return !::fImporting && !::fReindex && !isInitialBlockDownload(); } bool isInitialBlockDownload() override { - const CChainState* active_chainstate; - { - // TODO: Temporary scope to check correctness of refactored code. - // Should be removed manually after merge of - // https://github.com/bitcoin/bitcoin/pull/20158 - LOCK(::cs_main); - active_chainstate = &chainman().ActiveChainstate(); - assert(std::addressof(::ChainstateActive()) == std::addressof(*active_chainstate)); - } - return active_chainstate->IsInitialBlockDownload(); + return chainman().ActiveChainstate().IsInitialBlockDownload(); } bool shutdownRequested() override { return ShutdownRequested(); } void initMessage(const std::string& message) override { ::uiInterface.InitMessage(message); } diff --git a/src/node/transaction.cpp b/src/node/transaction.cpp index 1196233457f27..76264ffb1cfda 100644 --- a/src/node/transaction.cpp +++ b/src/node/transaction.cpp @@ -42,7 +42,6 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t { // cs_main scope assert(node.chainman); LOCK(cs_main); - assert(std::addressof(::ChainstateActive()) == std::addressof(node.chainman->ActiveChainstate())); // If the transaction is already confirmed in the chain, don't do anything // and return early. CCoinsViewCache &view = node.chainman->ActiveChainstate().CoinsTip(); diff --git a/src/qt/test/apptests.cpp b/src/qt/test/apptests.cpp index ba92dc9ea0727..92a7d351d0e02 100644 --- a/src/qt/test/apptests.cpp +++ b/src/qt/test/apptests.cpp @@ -87,11 +87,6 @@ void AppTests::appTests() // Reset global state to avoid interfering with later tests. LogInstance().DisconnectTestLogger(); AbortShutdown(); - { - LOCK(cs_main); - UnloadBlockIndex(/* mempool */ nullptr, g_chainman); - g_chainman.Reset(); - } } //! Entry point for BitcoinGUI tests. diff --git a/src/qt/test/wallettests.cpp b/src/qt/test/wallettests.cpp index bff6c979a3361..f66dd73830bba 100644 --- a/src/qt/test/wallettests.cpp +++ b/src/qt/test/wallettests.cpp @@ -117,14 +117,14 @@ void TestGUI(interfaces::Node& node) LOCK2(wallet->cs_wallet, spk_man->cs_KeyStore); wallet->SetAddressBook(PKHash(test.coinbaseKey.GetPubKey()), "", "receive"); spk_man->AddKeyPubKey(test.coinbaseKey, test.coinbaseKey.GetPubKey()); - wallet->SetLastBlockProcessed(105, ::ChainActive().Tip()->GetBlockHash()); + wallet->SetLastBlockProcessed(105, node.context()->chainman->ActiveChain().Tip()->GetBlockHash()); } { WalletRescanReserver reserver(*wallet); reserver.reserve(); CWallet::ScanResult result = wallet->ScanForWalletTransactions(Params().GetConsensus().hashGenesisBlock, 0 /* start_height */, {} /* max_height */, reserver, true /* fUpdate */); QCOMPARE(result.status, CWallet::ScanResult::SUCCESS); - QCOMPARE(result.last_scanned_block, ::ChainActive().Tip()->GetBlockHash()); + QCOMPARE(result.last_scanned_block, node.context()->chainman->ActiveChain().Tip()->GetBlockHash()); QVERIFY(result.last_failed_block.IsNull()); } wallet->SetBroadcastTransactions(true); diff --git a/src/rest.cpp b/src/rest.cpp index dcdf327c604a3..afae27398f8f4 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -124,7 +124,7 @@ static ChainstateManager* GetChainman(const CoreContext& context, HTTPRequest* r __FILE__, __LINE__, __func__, PACKAGE_BUGREPORT)); return nullptr; } - return node_context->chainman; + return node_context->chainman.get(); } static RetFormat ParseDataFormat(std::string& param, const std::string& strReq) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 3d6b7478f308b..49b39817f164e 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -100,7 +100,6 @@ ChainstateManager& EnsureChainman(const NodeContext& node) if (!node.chainman) { throw JSONRPCError(RPC_INTERNAL_ERROR, "Node chainman not found"); } - WITH_LOCK(::cs_main, CHECK_NONFATAL(std::addressof(g_chainman) == std::addressof(*node.chainman))); return *node.chainman; } diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index dd58dbfd4d531..762925f21647e 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -99,9 +99,9 @@ static RPCHelpMan masternode_count() }; } -static UniValue GetNextMasternodeForPayment(CDeterministicMNManager& dmnman, int heightShift) +static UniValue GetNextMasternodeForPayment(const CChain& active_chain, CDeterministicMNManager& dmnman, int heightShift) { - const CBlockIndex *tip = WITH_LOCK(::cs_main, return ::ChainActive().Tip()); + const CBlockIndex *tip = WITH_LOCK(::cs_main, return active_chain.Tip()); auto mnList = dmnman.GetListForBlock(tip); auto payees = mnList.GetProjectedMNPayees(tip, heightShift); if (payees.empty()) @@ -136,8 +136,9 @@ static RPCHelpMan masternode_winner() } const NodeContext& node = EnsureAnyNodeContext(request.context); + const ChainstateManager& chainman = EnsureChainman(node); CHECK_NONFATAL(node.dmnman); - return GetNextMasternodeForPayment(*node.dmnman, 10); + return GetNextMasternodeForPayment(chainman.ActiveChain(), *node.dmnman, 10); }, }; } @@ -156,8 +157,9 @@ static RPCHelpMan masternode_current() } const NodeContext& node = EnsureAnyNodeContext(request.context); + const ChainstateManager& chainman = EnsureChainman(node); CHECK_NONFATAL(node.dmnman); - return GetNextMasternodeForPayment(*node.dmnman, 1); + return GetNextMasternodeForPayment(chainman.ActiveChain(), *node.dmnman, 1); }, }; } diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 3683f4ce6dd4c..a486053b3503b 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -128,7 +128,6 @@ static bool GenerateBlock(ChainstateManager& chainman, CBlock& block, uint64_t& { LOCK(cs_main); - CHECK_NONFATAL(std::addressof(::ChainActive()) == std::addressof(chainman.ActiveChain())); IncrementExtraNonce(&block, chainman.ActiveChain().Tip(), extra_nonce); } @@ -164,7 +163,6 @@ static UniValue generateBlocks(ChainstateManager& chainman, const NodeContext& n { // Don't keep cs_main locked LOCK(cs_main); - CHECK_NONFATAL(std::addressof(::ChainActive()) == std::addressof(chainman.ActiveChain())); nHeight = chainman.ActiveChain().Height(); nHeightEnd = nHeight+nGenerate; } diff --git a/src/test/block_reward_reallocation_tests.cpp b/src/test/block_reward_reallocation_tests.cpp index ad74c369603b9..e8dde8cfb2fd6 100644 --- a/src/test/block_reward_reallocation_tests.cpp +++ b/src/test/block_reward_reallocation_tests.cpp @@ -55,7 +55,7 @@ static SimpleUTXOMap BuildSimpleUtxoMap(const std::vector& txs) return utxos; } -static std::vector SelectUTXOs(SimpleUTXOMap& utoxs, CAmount amount, CAmount& changeRet) +static std::vector SelectUTXOs(const CChain& active_chain, SimpleUTXOMap& utoxs, CAmount amount, CAmount& changeRet) { changeRet = 0; @@ -64,7 +64,7 @@ static std::vector SelectUTXOs(SimpleUTXOMap& utoxs, CAmount amount, while (!utoxs.empty()) { bool found = false; for (auto it = utoxs.begin(); it != utoxs.end(); ++it) { - if (::ChainActive().Height() - it->second.first < 101) { + if (active_chain.Height() - it->second.first < 101) { continue; } @@ -84,10 +84,10 @@ static std::vector SelectUTXOs(SimpleUTXOMap& utoxs, CAmount amount, return selectedUtxos; } -static void FundTransaction(CMutableTransaction& tx, SimpleUTXOMap& utoxs, const CScript& scriptPayout, CAmount amount) +static void FundTransaction(const CChain& active_chain, CMutableTransaction& tx, SimpleUTXOMap& utoxs, const CScript& scriptPayout, CAmount amount) { CAmount change; - auto inputs = SelectUTXOs(utoxs, amount, change); + auto inputs = SelectUTXOs(active_chain, utoxs, amount, change); for (const auto& input : inputs) { tx.vin.emplace_back(input); } @@ -110,7 +110,7 @@ static void SignTransaction(const CTxMemPool& mempool, CMutableTransaction& tx, } } -static CMutableTransaction CreateProRegTx(const CTxMemPool& mempool, SimpleUTXOMap& utxos, int port, const CScript& scriptPayout, const CKey& coinbaseKey, CKey& ownerKeyRet, CBLSSecretKey& operatorKeyRet) +static CMutableTransaction CreateProRegTx(const CChain& active_chain, const CTxMemPool& mempool, SimpleUTXOMap& utxos, int port, const CScript& scriptPayout, const CKey& coinbaseKey, CKey& ownerKeyRet, CBLSSecretKey& operatorKeyRet) { ownerKeyRet.MakeNewKey(true); operatorKeyRet.MakeNewKey(); @@ -127,7 +127,7 @@ static CMutableTransaction CreateProRegTx(const CTxMemPool& mempool, SimpleUTXOM CMutableTransaction tx; tx.nVersion = 3; tx.nType = TRANSACTION_PROVIDER_REGISTER; - FundTransaction(tx, utxos, scriptPayout, dmn_types::Regular.collat_amount); + FundTransaction(active_chain, tx, utxos, scriptPayout, dmn_types::Regular.collat_amount); proTx.inputsHash = CalcTxInputsHash(CTransaction(tx)); SetTxPayload(tx, proTx); SignTransaction(mempool, tx, coinbaseKey); @@ -157,7 +157,7 @@ BOOST_FIXTURE_TEST_CASE(block_reward_reallocation, TestChainBRRBeforeActivationS CKey ownerKey; CBLSSecretKey operatorKey; auto utxos = BuildSimpleUtxoMap(m_coinbase_txns); - auto tx = CreateProRegTx(*m_node.mempool, utxos, 1, GenerateRandomAddress(), coinbaseKey, ownerKey, operatorKey); + auto tx = CreateProRegTx(m_node.chainman->ActiveChain(), *m_node.mempool, utxos, 1, GenerateRandomAddress(), coinbaseKey, ownerKey, operatorKey); CreateAndProcessBlock({tx}, coinbaseKey); diff --git a/src/test/blockfilter_index_tests.cpp b/src/test/blockfilter_index_tests.cpp index 46c3a28744d9b..339dcf1f1b991 100644 --- a/src/test/blockfilter_index_tests.cpp +++ b/src/test/blockfilter_index_tests.cpp @@ -69,7 +69,7 @@ CBlock BuildChainTestingSetup::CreateBlock(const CBlockIndex* prev, const CScript& scriptPubKey) { const CChainParams& chainparams = Params(); - std::unique_ptr pblocktemplate = BlockAssembler(::ChainstateActive(), m_node, *m_node.mempool, chainparams).CreateNewBlock(scriptPubKey); + std::unique_ptr pblocktemplate = BlockAssembler(m_node.chainman->ActiveChainstate(), m_node, *m_node.mempool, chainparams).CreateNewBlock(scriptPubKey); CBlock& block = pblocktemplate->block; block.hashPrevBlock = prev->GetBlockHash(); block.nTime = prev->nTime + 1; @@ -124,9 +124,9 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup) std::vector filters; std::vector filter_hashes; - for (const CBlockIndex* block_index = ::ChainActive().Genesis(); + for (const CBlockIndex* block_index = m_node.chainman->ActiveChain().Genesis(); block_index != nullptr; - block_index = ::ChainActive().Next(block_index)) { + block_index = m_node.chainman->ActiveChain().Next(block_index)) { BOOST_CHECK(!filter_index.LookupFilter(block_index, filter)); BOOST_CHECK(!filter_index.LookupFilterHeader(block_index, filter_header)); BOOST_CHECK(!filter_index.LookupFilterRange(block_index->nHeight, block_index, filters)); @@ -138,7 +138,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup) // BlockUntilSyncedToCurrentChain should return false before index is started. BOOST_CHECK(!filter_index.BlockUntilSyncedToCurrentChain()); - BOOST_REQUIRE(filter_index.Start(::ChainstateActive())); + BOOST_REQUIRE(filter_index.Start(m_node.chainman->ActiveChainstate())); // Allow filter index to catch up with the block index. IndexWaitSynced(filter_index); @@ -147,9 +147,9 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup) { LOCK(cs_main); const CBlockIndex* block_index; - for (block_index = ::ChainActive().Genesis(); + for (block_index = m_node.chainman->ActiveChain().Genesis(); block_index != nullptr; - block_index = ::ChainActive().Next(block_index)) { + block_index = m_node.chainman->ActiveChain().Next(block_index)) { CheckFilterLookups(filter_index, block_index, last_header); } } @@ -158,7 +158,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup) const CBlockIndex* tip; { LOCK(cs_main); - tip = ::ChainActive().Tip(); + tip = m_node.chainman->ActiveChain().Tip(); } CKey coinbase_key_A, coinbase_key_B; coinbase_key_A.MakeNewKey(true); @@ -180,7 +180,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup) const CBlockIndex* block_index; { LOCK(cs_main); - block_index = g_chainman.m_blockman.LookupBlockIndex(block->GetHash()); + block_index = m_node.chainman->m_blockman.LookupBlockIndex(block->GetHash()); } BOOST_CHECK(filter_index.BlockUntilSyncedToCurrentChain()); @@ -198,7 +198,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup) const CBlockIndex* block_index; { LOCK(cs_main); - block_index = g_chainman.m_blockman.LookupBlockIndex(block->GetHash()); + block_index = m_node.chainman->m_blockman.LookupBlockIndex(block->GetHash()); } BOOST_CHECK(filter_index.BlockUntilSyncedToCurrentChain()); @@ -212,7 +212,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup) const CBlockIndex* block_index; { LOCK(cs_main); - block_index = g_chainman.m_blockman.LookupBlockIndex(block->GetHash()); + block_index = m_node.chainman->m_blockman.LookupBlockIndex(block->GetHash()); } BOOST_CHECK(filter_index.BlockUntilSyncedToCurrentChain()); @@ -233,14 +233,14 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup) { LOCK(cs_main); - block_index = g_chainman.m_blockman.LookupBlockIndex(chainA[i]->GetHash()); + block_index = m_node.chainman->m_blockman.LookupBlockIndex(chainA[i]->GetHash()); } BOOST_CHECK(filter_index.BlockUntilSyncedToCurrentChain()); CheckFilterLookups(filter_index, block_index, chainA_last_header); { LOCK(cs_main); - block_index = g_chainman.m_blockman.LookupBlockIndex(chainB[i]->GetHash()); + block_index = m_node.chainman->m_blockman.LookupBlockIndex(chainB[i]->GetHash()); } BOOST_CHECK(filter_index.BlockUntilSyncedToCurrentChain()); CheckFilterLookups(filter_index, block_index, chainB_last_header); @@ -252,7 +252,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup) { LOCK(cs_main); - tip = ::ChainActive().Tip(); + tip = m_node.chainman->ActiveChain().Tip(); } BOOST_CHECK(filter_index.LookupFilterRange(0, tip, filters)); BOOST_CHECK(filter_index.LookupFilterHashRange(0, tip, filter_hashes)); diff --git a/src/test/coinstatsindex_tests.cpp b/src/test/coinstatsindex_tests.cpp index 33154879aefee..6ba80397a31eb 100644 --- a/src/test/coinstatsindex_tests.cpp +++ b/src/test/coinstatsindex_tests.cpp @@ -20,7 +20,7 @@ BOOST_FIXTURE_TEST_CASE(coinstatsindex_initial_sync, TestChain100Setup) const CBlockIndex* block_index; { LOCK(cs_main); - block_index = ChainActive().Tip(); + block_index = m_node.chainman->ActiveChain().Tip(); } // CoinStatsIndex should not be found before it is started. @@ -30,7 +30,7 @@ BOOST_FIXTURE_TEST_CASE(coinstatsindex_initial_sync, TestChain100Setup) // is started. BOOST_CHECK(!coin_stats_index.BlockUntilSyncedToCurrentChain()); - BOOST_REQUIRE(coin_stats_index.Start(::ChainstateActive())); + BOOST_REQUIRE(coin_stats_index.Start(m_node.chainman->ActiveChainstate())); IndexWaitSynced(coin_stats_index); @@ -38,7 +38,7 @@ BOOST_FIXTURE_TEST_CASE(coinstatsindex_initial_sync, TestChain100Setup) const CBlockIndex* genesis_block_index; { LOCK(cs_main); - genesis_block_index = ChainActive().Genesis(); + genesis_block_index = m_node.chainman->ActiveChain().Genesis(); } BOOST_CHECK(coin_stats_index.LookUpStats(genesis_block_index, coin_stats)); @@ -56,7 +56,7 @@ BOOST_FIXTURE_TEST_CASE(coinstatsindex_initial_sync, TestChain100Setup) const CBlockIndex* new_block_index; { LOCK(cs_main); - new_block_index = ChainActive().Tip(); + new_block_index = m_node.chainman->ActiveChain().Tip(); } coin_stats_index.LookUpStats(new_block_index, new_coin_stats); diff --git a/src/test/denialofservice_tests.cpp b/src/test/denialofservice_tests.cpp index 72dd09af0162c..909c671cbab3c 100644 --- a/src/test/denialofservice_tests.cpp +++ b/src/test/denialofservice_tests.cpp @@ -92,8 +92,8 @@ BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction) // This test requires that we have a chain with non-zero work. { LOCK(cs_main); - BOOST_CHECK(::ChainActive().Tip() != nullptr); - BOOST_CHECK(::ChainActive().Tip()->nChainWork > 0); + BOOST_CHECK(m_node.chainman->ActiveChain().Tip() != nullptr); + BOOST_CHECK(m_node.chainman->ActiveChain().Tip()->nChainWork > 0); } // Test starts here diff --git a/src/test/dynamic_activation_thresholds_tests.cpp b/src/test/dynamic_activation_thresholds_tests.cpp index c5c06fdf91a95..963d06b4af957 100644 --- a/src/test/dynamic_activation_thresholds_tests.cpp +++ b/src/test/dynamic_activation_thresholds_tests.cpp @@ -55,9 +55,9 @@ struct TestChainDATSetup : public TestChainSetup } LOCK(cs_main); if (expected_lockin) { - BOOST_CHECK_EQUAL(g_versionbitscache.State(::ChainActive().Tip(), consensus_params, deployment_id), ThresholdState::LOCKED_IN); + BOOST_CHECK_EQUAL(g_versionbitscache.State(m_node.chainman->ActiveChain().Tip(), consensus_params, deployment_id), ThresholdState::LOCKED_IN); } else { - BOOST_CHECK_EQUAL(g_versionbitscache.State(::ChainActive().Tip(), consensus_params, deployment_id), ThresholdState::STARTED); + BOOST_CHECK_EQUAL(g_versionbitscache.State(m_node.chainman->ActiveChain().Tip(), consensus_params, deployment_id), ThresholdState::STARTED); } } @@ -68,8 +68,8 @@ struct TestChainDATSetup : public TestChainSetup { LOCK(cs_main); - BOOST_CHECK_EQUAL(::ChainActive().Height(), window - 2); - BOOST_CHECK_EQUAL(g_versionbitscache.State(::ChainActive().Tip(), consensus_params, deployment_id), ThresholdState::DEFINED); + BOOST_CHECK_EQUAL(m_node.chainman->ActiveChain().Height(), window - 2); + BOOST_CHECK_EQUAL(g_versionbitscache.State(m_node.chainman->ActiveChain().Tip(), consensus_params, deployment_id), ThresholdState::DEFINED); } CreateAndProcessBlock({}, coinbaseKey); @@ -77,13 +77,13 @@ struct TestChainDATSetup : public TestChainSetup { LOCK(cs_main); // Advance from DEFINED to STARTED at height = window - 1 - BOOST_CHECK_EQUAL(::ChainActive().Height(), window - 1); - BOOST_CHECK_EQUAL(g_versionbitscache.State(::ChainActive().Tip(), consensus_params, deployment_id), ThresholdState::STARTED); - BOOST_CHECK_EQUAL(g_versionbitscache.Statistics(::ChainActive().Tip(), consensus_params, deployment_id).threshold, threshold(0)); + BOOST_CHECK_EQUAL(m_node.chainman->ActiveChain().Height(), window - 1); + BOOST_CHECK_EQUAL(g_versionbitscache.State(m_node.chainman->ActiveChain().Tip(), consensus_params, deployment_id), ThresholdState::STARTED); + BOOST_CHECK_EQUAL(g_versionbitscache.Statistics(m_node.chainman->ActiveChain().Tip(), consensus_params, deployment_id).threshold, threshold(0)); // Next block should be signaling by default - const auto pblocktemplate = BlockAssembler(::ChainstateActive(), m_node, *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey); + const auto pblocktemplate = BlockAssembler(m_node.chainman->ActiveChainstate(), m_node, *m_node.mempool, Params()).CreateNewBlock(coinbasePubKey); const uint32_t bitmask = ((uint32_t)1) << consensus_params.vDeployments[deployment_id].bit; - BOOST_CHECK_EQUAL(::ChainActive().Tip()->nVersion & bitmask, 0); + BOOST_CHECK_EQUAL(m_node.chainman->ActiveChain().Tip()->nVersion & bitmask, 0); BOOST_CHECK_EQUAL(pblocktemplate->block.nVersion & bitmask, bitmask); } @@ -94,18 +94,18 @@ struct TestChainDATSetup : public TestChainSetup { // Still STARTED but with a (potentially) new threshold LOCK(cs_main); - BOOST_CHECK_EQUAL(::ChainActive().Height(), window * (i + 2) - 1); - BOOST_CHECK_EQUAL(g_versionbitscache.State(::ChainActive().Tip(), consensus_params, deployment_id), ThresholdState::STARTED); - const auto vbts = g_versionbitscache.Statistics(::ChainActive().Tip(), consensus_params, deployment_id); + BOOST_CHECK_EQUAL(m_node.chainman->ActiveChain().Height(), window * (i + 2) - 1); + BOOST_CHECK_EQUAL(g_versionbitscache.State(m_node.chainman->ActiveChain().Tip(), consensus_params, deployment_id), ThresholdState::STARTED); + const auto vbts = g_versionbitscache.Statistics(m_node.chainman->ActiveChain().Tip(), consensus_params, deployment_id); BOOST_CHECK_EQUAL(vbts.threshold, threshold(i + 1)); BOOST_CHECK(vbts.threshold <= th_start); BOOST_CHECK(vbts.threshold >= th_end); } } if (LOCK(cs_main); check_activation_at_min) { - BOOST_CHECK_EQUAL(g_versionbitscache.Statistics(::ChainActive().Tip(), consensus_params, deployment_id).threshold, th_end); + BOOST_CHECK_EQUAL(g_versionbitscache.Statistics(m_node.chainman->ActiveChain().Tip(), consensus_params, deployment_id).threshold, th_end); } else { - BOOST_CHECK(g_versionbitscache.Statistics(::ChainActive().Tip(), consensus_params, deployment_id).threshold > th_end); + BOOST_CHECK(g_versionbitscache.Statistics(m_node.chainman->ActiveChain().Tip(), consensus_params, deployment_id).threshold > th_end); } // activate @@ -115,7 +115,7 @@ struct TestChainDATSetup : public TestChainSetup } { LOCK(cs_main); - BOOST_CHECK_EQUAL(g_versionbitscache.State(::ChainActive().Tip(), consensus_params, deployment_id), ThresholdState::ACTIVE); + BOOST_CHECK_EQUAL(g_versionbitscache.State(m_node.chainman->ActiveChain().Tip(), consensus_params, deployment_id), ThresholdState::ACTIVE); } } diff --git a/src/test/evo_assetlocks_tests.cpp b/src/test/evo_assetlocks_tests.cpp index a568bcdb39376..92b3c760138a5 100644 --- a/src/test/evo_assetlocks_tests.cpp +++ b/src/test/evo_assetlocks_tests.cpp @@ -14,7 +14,7 @@ #include