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:
MarcoFalke
2019-11-08 10:29:41 -05:00
parent 270616228b
commit fac07f2038
7 changed files with 28 additions and 5 deletions

View File

@@ -284,6 +284,7 @@ void Shutdown(NodeContext& node)
GetMainSignals().UnregisterWithMempoolSignals(mempool);
globalVerifyHandle.reset();
ECC_Stop();
if (node.mempool) node.mempool = nullptr;
LogPrintf("%s: done\n", __func__);
}
@@ -1632,6 +1633,11 @@ bool AppInitMain(NodeContext& node)
return false;
}
// Now that the chain state is loaded, make mempool generally available in the node context. For example the
// connection manager, wallet, or RPC threads, which are all started after this, may use it from the node context.
assert(!node.mempool);
node.mempool = &::mempool;
fs::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME;
CAutoFile est_filein(fsbridge::fopen(est_path, "rb"), SER_DISK, CLIENT_VERSION);
// Allowed to fail as this file IS missing on first startup.