mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01: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:
@@ -10,6 +10,7 @@
|
||||
|
||||
class BanMan;
|
||||
class CConnman;
|
||||
class CTxMemPool;
|
||||
class PeerLogicValidation;
|
||||
namespace interfaces {
|
||||
class Chain;
|
||||
@@ -22,13 +23,13 @@ class ChainClient;
|
||||
//! This is used by init, rpc, and test code to pass object references around
|
||||
//! without needing to declare the same variables and parameters repeatedly, or
|
||||
//! to use globals. More variables could be added to this struct (particularly
|
||||
//! references to validation and mempool objects) to eliminate use of globals
|
||||
//! references to validation objects) to eliminate use of globals
|
||||
//! and make code more modular and testable. The struct isn't intended to have
|
||||
//! any member functions. It should just be a collection of references that can
|
||||
//! be used without pulling in unwanted dependencies or functionality.
|
||||
struct NodeContext
|
||||
{
|
||||
struct NodeContext {
|
||||
std::unique_ptr<CConnman> connman;
|
||||
CTxMemPool* mempool{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
|
||||
std::unique_ptr<PeerLogicValidation> peer_logic;
|
||||
std::unique_ptr<BanMan> banman;
|
||||
std::unique_ptr<interfaces::Chain> chain;
|
||||
|
||||
Reference in New Issue
Block a user