mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-09 22:28:51 +02:00
node: Add reference to mempool in NodeContext
Currently it is an alias to the global ::mempool and should be used as follows. * Node code (validation and transaction relay) can use either ::mempool or node.mempool, whichever seems a better fit. * RPC code should use the added convenience getter EnsureMempool, which makes sure the mempool exists before use. This prepares the RPC code to a future where the mempool might be disabled at runtime or compile time. * Test code should use m_node.mempool directly, as the mempool is always initialized for tests.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include <hash.h>
|
||||
#include <index/blockfilterindex.h>
|
||||
#include <node/coinstats.h>
|
||||
#include <node/context.h>
|
||||
#include <node/utxo_snapshot.h>
|
||||
#include <policy/feerate.h>
|
||||
#include <policy/policy.h>
|
||||
@@ -53,6 +54,15 @@ static Mutex cs_blockchange;
|
||||
static std::condition_variable cond_blockchange;
|
||||
static CUpdatedBlock latestblock;
|
||||
|
||||
CTxMemPool& EnsureMemPool()
|
||||
{
|
||||
CHECK_NONFATAL(g_rpc_node);
|
||||
if (!g_rpc_node->mempool) {
|
||||
throw JSONRPCError(RPC_CLIENT_MEMPOOL_DISABLED, "Mempool disabled or instance not found");
|
||||
}
|
||||
return *g_rpc_node->mempool;
|
||||
}
|
||||
|
||||
/* Calculate the difficulty for a given block index.
|
||||
*/
|
||||
double GetDifficulty(const CBlockIndex* blockindex)
|
||||
|
||||
Reference in New Issue
Block a user