Skip to content

Commit fafb381

Browse files
author
MarcoFalke
committed
Remove mempool global
1 parent fa0359c commit fafb381

File tree

8 files changed

+11
-12
lines changed

8 files changed

+11
-12
lines changed

src/init.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ void Shutdown(NodeContext& node)
302302
GetMainSignals().UnregisterBackgroundSignalScheduler();
303303
globalVerifyHandle.reset();
304304
ECC_Stop();
305-
node.mempool = nullptr;
305+
node.mempool.reset();
306306
node.chainman = nullptr;
307307
node.scheduler.reset();
308308

@@ -1364,7 +1364,7 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
13641364
// Make mempool generally available in the node context. For example the connection manager, wallet, or RPC threads,
13651365
// which are all started after this, may use it from the node context.
13661366
assert(!node.mempool);
1367-
node.mempool = &::mempool;
1367+
node.mempool = MakeUnique<CTxMemPool>(&::feeEstimator);
13681368
if (node.mempool) {
13691369
int ratio = std::min<int>(std::max<int>(args.GetArg("-checkmempool", chainparams.DefaultConsistencyChecks() ? 1 : 0), 0), 1000000);
13701370
if (ratio != 0) {
@@ -1559,7 +1559,7 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
15591559
chainman.m_total_coinstip_cache = nCoinCacheUsage;
15601560
chainman.m_total_coinsdb_cache = nCoinDBCache;
15611561

1562-
UnloadBlockIndex(node.mempool);
1562+
UnloadBlockIndex(node.mempool.get());
15631563

15641564
// new CBlockTreeDB tries to delete the existing file, which
15651565
// fails if it's still open from the previous loop. Close it first:

src/node/context.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <net.h>
1010
#include <net_processing.h>
1111
#include <scheduler.h>
12+
#include <txmempool.h>
1213

1314
NodeContext::NodeContext() {}
1415
NodeContext::~NodeContext() {}

src/node/context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class WalletClient;
3535
//! be used without pulling in unwanted dependencies or functionality.
3636
struct NodeContext {
3737
std::unique_ptr<CConnman> connman;
38-
CTxMemPool* mempool{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
38+
std::unique_ptr<CTxMemPool> mempool;
3939
std::unique_ptr<PeerLogicValidation> peer_logic;
4040
ChainstateManager* chainman{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
4141
std::unique_ptr<BanMan> banman;

src/rest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static CTxMemPool* GetMemPool(const util::Ref& context, HTTPRequest* req)
102102
RESTERR(req, HTTP_NOT_FOUND, "Mempool disabled or instance not found");
103103
return nullptr;
104104
}
105-
return node->mempool;
105+
return node->mempool.get();
106106
}
107107

108108
static RetFormat ParseDataFormat(std::string& param, const std::string& strReq)
@@ -393,7 +393,7 @@ static bool rest_tx(const util::Ref& context, HTTPRequest* req, const std::strin
393393
const NodeContext* const node = GetNodeContext(context, req);
394394
if (!node) return false;
395395
uint256 hashBlock = uint256();
396-
const CTransactionRef tx = GetTransaction(/* block_index */ nullptr, node->mempool, hash, Params().GetConsensus(), hashBlock);
396+
const CTransactionRef tx = GetTransaction(/* block_index */ nullptr, node->mempool.get(), hash, Params().GetConsensus(), hashBlock);
397397
if (!tx) {
398398
return RESTERR(req, HTTP_NOT_FOUND, hashStr + " not found");
399399
}

src/rpc/rawtransaction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ static UniValue getrawtransaction(const JSONRPCRequest& request)
191191
}
192192

193193
uint256 hash_block;
194-
const CTransactionRef tx = GetTransaction(blockindex, node.mempool, hash, Params().GetConsensus(), hash_block);
194+
const CTransactionRef tx = GetTransaction(blockindex, node.mempool.get(), hash, Params().GetConsensus(), hash_block);
195195
if (!tx) {
196196
std::string errmsg;
197197
if (blockindex) {

src/test/util/setup_common.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
141141

142142
pblocktree.reset(new CBlockTreeDB(1 << 20, true));
143143

144-
m_node.mempool = &::mempool;
144+
m_node.mempool = MakeUnique<CTxMemPool>(&::feeEstimator);
145145
m_node.mempool->setSanityCheck(1.0);
146146

147147
m_node.chainman = &::g_chainman;
@@ -187,8 +187,8 @@ TestingSetup::~TestingSetup()
187187
m_node.connman.reset();
188188
m_node.banman.reset();
189189
m_node.args = nullptr;
190-
UnloadBlockIndex(m_node.mempool);
191-
m_node.mempool = nullptr;
190+
UnloadBlockIndex(m_node.mempool.get());
191+
m_node.mempool.reset();
192192
m_node.scheduler.reset();
193193
m_node.chainman->Reset();
194194
m_node.chainman = nullptr;

src/validation.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ arith_uint256 nMinimumChainWork;
148148
CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE);
149149

150150
CBlockPolicyEstimator feeEstimator;
151-
CTxMemPool mempool(&feeEstimator);
152151

153152
// Internal stuff
154153
namespace {

src/validation.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ enum class SynchronizationState {
113113

114114
extern RecursiveMutex cs_main;
115115
extern CBlockPolicyEstimator feeEstimator;
116-
extern CTxMemPool mempool;
117116
typedef std::unordered_map<uint256, CBlockIndex*, BlockHasher> BlockMap;
118117
extern Mutex g_best_block_mutex;
119118
extern std::condition_variable g_best_block_cv;

0 commit comments

Comments
 (0)