mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 07:28:59 +01:00
Merge #17407: node: Add reference to mempool in NodeContext
fa538813b1scripted-diff: Replace ::mempool with m_node.mempool in tests (MarcoFalke)8888ad02e2test: Replace recursive lock with locking annotations (MarcoFalke)fac07f2038node: Add reference to mempool in NodeContext (MarcoFalke) Pull request description: This is the first step toward making the mempool a global that is not initialized before main. #### Motivation Currently the mempool is a global that is initialized before the `main` function. This is confusing and easy to get wrong. E.g. the mempool constructor queries state that has not been initialized, like randomness (fixed), or command line arguments (not an issue last time I checked). Also without having the chainstate (chain tip) initialized first, it doesn't make conceptually sense to have a mempool, since the mempool builds txs on top of the utxo set (chain tip). Finally, in the future someone might want to run a consensus-only full node (`-nowallet -noblockfilter -no... -nomempool` command line options) that only verifies blocks and updates the utxo set. This is conceptually the same change that has already been done for the connection manager `CConnman`. ACKs for top commit: jnewbery: utACKfa538813b1ariard: Tested ACKfa53881. Tree-SHA512: 2c446a8a51476354aad7126c2b833500d36b24490caa94f847b2bdc622054de0dae28980f23e3d91b1b492dc32931656d98dbd019af9e4e58f2f8c5375aac694
This commit is contained in:
@@ -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__);
|
||||
}
|
||||
|
||||
@@ -1635,6 +1636,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.
|
||||
|
||||
Reference in New Issue
Block a user