diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -314,7 +314,7 @@ globalVerifyHandle.reset(); ECC_Stop(); node.mempool.reset(); - node.chainman = nullptr; + node.chainman.reset(); node.scheduler.reset(); try { @@ -2403,8 +2403,8 @@ node.mempool = std::make_unique(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.peerman); node.peerman = diff --git a/src/node/context.h b/src/node/context.h --- a/src/node/context.h +++ b/src/node/context.h @@ -37,8 +37,7 @@ std::unique_ptr connman; std::unique_ptr mempool; std::unique_ptr peerman; - // Currently a raw pointer because the memory is not managed by this struct - ChainstateManager *chainman{nullptr}; + std::unique_ptr chainman; std::unique_ptr banman; // Currently a raw pointer because the memory is not managed by this struct ArgsManager *args{nullptr}; diff --git a/src/node/context.cpp b/src/node/context.cpp --- a/src/node/context.cpp +++ b/src/node/context.cpp @@ -10,6 +10,7 @@ #include #include #include +#include NodeContext::NodeContext() {} NodeContext::~NodeContext() {} diff --git a/src/qt/test/apptests.cpp b/src/qt/test/apptests.cpp --- a/src/qt/test/apptests.cpp +++ b/src/qt/test/apptests.cpp @@ -106,11 +106,6 @@ // 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/rest.cpp b/src/rest.cpp --- a/src/rest.cpp +++ b/src/rest.cpp @@ -126,7 +126,7 @@ __FILE__, __LINE__, __func__, PACKAGE_BUGREPORT)); return nullptr; } - return node_context->chainman; + return node_context->chainman.get(); } static RetFormat ParseDataFormat(std::string ¶m, 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 @@ -165,7 +165,7 @@ m_node.mempool = std::make_unique(1); - m_node.chainman = &::g_chainman; + m_node.chainman = std::make_unique(); constexpr int script_check_threads = 2; StartScriptCheckWorkerThreads(script_check_threads); @@ -185,7 +185,7 @@ m_node.mempool.reset(); m_node.scheduler.reset(); m_node.chainman->Reset(); - m_node.chainman = nullptr; + m_node.chainman.reset(); pblocktree.reset(); } diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -1141,10 +1141,6 @@ CAutoFile &coins_file, const SnapshotMetadata &metadata); - // For access to m_active_chainstate. - friend CChainState &ChainstateActive(); - friend CChain &ChainActive(); - public: std::thread m_load_block; //! A single BlockManager instance is shared across each constructed @@ -1293,18 +1289,6 @@ } }; -/** - * DEPRECATED! Please use node.chainman instead. May only be used in - * validation.cpp internally - */ -extern ChainstateManager g_chainman GUARDED_BY(::cs_main); - -/** Please prefer the identical ChainstateManager::ActiveChainstate */ -CChainState &ChainstateActive(); - -/** Please prefer the identical ChainstateManager::ActiveChain */ -CChain &ChainActive(); - /** * Global variable that points to the active block tree (protected by cs_main) */ diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -77,19 +77,6 @@ "each level includes the checks of the previous levels", }; -ChainstateManager g_chainman; - -CChainState &ChainstateActive() { - LOCK(::cs_main); - assert(g_chainman.m_active_chainstate); - return *g_chainman.m_active_chainstate; -} - -CChain &ChainActive() { - LOCK(::cs_main); - return ::ChainstateActive().m_chain; -} - /** * Global state *