diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -317,7 +317,7 @@ GetMainSignals().UnregisterBackgroundSignalScheduler(); globalVerifyHandle.reset(); ECC_Stop(); - node.mempool = nullptr; + node.mempool.reset(); node.chainman = nullptr; node.scheduler.reset(); @@ -2284,7 +2284,7 @@ // connection manager, wallet, or RPC threads, which are all started after // this, may use it from the node context. assert(!node.mempool); - node.mempool = &::g_mempool; + node.mempool = std::make_unique(); if (node.mempool) { int ratio = std::min( std::max( @@ -2563,7 +2563,7 @@ chainman.m_total_coinstip_cache = nCoinCacheUsage; chainman.m_total_coinsdb_cache = nCoinDBCache; - UnloadBlockIndex(node.mempool); + UnloadBlockIndex(node.mempool.get()); // new CBlockTreeDB tries to delete the existing file, which // fails if it's still open from the previous loop. Close it diff --git a/src/node/context.h b/src/node/context.h --- a/src/node/context.h +++ b/src/node/context.h @@ -34,8 +34,7 @@ //! be used without pulling in unwanted dependencies or functionality. struct NodeContext { std::unique_ptr connman; - // Currently a raw pointer because the memory is not managed by this struct - CTxMemPool *mempool{nullptr}; + std::unique_ptr mempool; std::unique_ptr peerman; // Currently a raw pointer because the memory is not managed by this struct ChainstateManager *chainman{nullptr}; diff --git a/src/node/context.cpp b/src/node/context.cpp --- a/src/node/context.cpp +++ b/src/node/context.cpp @@ -9,6 +9,7 @@ #include #include #include +#include NodeContext::NodeContext() {} NodeContext::~NodeContext() {} diff --git a/src/rest.cpp b/src/rest.cpp --- a/src/rest.cpp +++ b/src/rest.cpp @@ -104,7 +104,7 @@ RESTERR(req, HTTP_NOT_FOUND, "Mempool disabled or instance not found"); return nullptr; } - return node->mempool; + return node->mempool.get(); } static RetFormat ParseDataFormat(std::string ¶m, @@ -446,7 +446,7 @@ } BlockHash hashBlock; const CTransactionRef tx = - GetTransaction(/* block_index */ nullptr, node->mempool, txid, + GetTransaction(/* block_index */ nullptr, node->mempool.get(), txid, Params().GetConsensus(), hashBlock); if (!tx) { return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found"); diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -232,8 +232,9 @@ } BlockHash hash_block; - const CTransactionRef tx = GetTransaction( - blockindex, node.mempool, txid, params.GetConsensus(), hash_block); + const CTransactionRef tx = + GetTransaction(blockindex, node.mempool.get(), txid, + params.GetConsensus(), hash_block); if (!tx) { std::string errmsg; if (blockindex) { 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 @@ -177,7 +177,7 @@ pblocktree.reset(new CBlockTreeDB(1 << 20, true)); - m_node.mempool = &::g_mempool; + m_node.mempool = std::make_unique(); m_node.mempool->setSanityCheck(1.0); m_node.chainman = &::g_chainman; @@ -229,8 +229,8 @@ m_node.connman.reset(); m_node.banman.reset(); m_node.args = nullptr; - UnloadBlockIndex(m_node.mempool); - m_node.mempool = nullptr; + UnloadBlockIndex(m_node.mempool.get()); + m_node.mempool.reset(); m_node.scheduler.reset(); m_node.chainman->Reset(); m_node.chainman = nullptr; diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -129,7 +129,6 @@ enum class SynchronizationState { INIT_REINDEX, INIT_DOWNLOAD, POST_INIT }; extern RecursiveMutex cs_main; -extern CTxMemPool g_mempool; typedef std::unordered_map BlockMap; extern Mutex g_best_block_mutex; extern std::condition_variable g_best_block_cv; diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -121,8 +121,6 @@ CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE_PER_KB); -CTxMemPool g_mempool; - // Internal stuff namespace { CBlockIndex *pindexBestInvalid = nullptr;