Skip to content

Commit eeee110

Browse files
author
MarcoFalke
committed
Remove mempool global from init
Can be reviewed with the git diff options --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space --ignore-all-space
1 parent 3ba25e3 commit eeee110

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

src/init.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ void Shutdown(NodeContext& node)
187187
/// Be sure that anything that writes files or flushes caches only does this if the respective
188188
/// module was initialized.
189189
util::ThreadRename("shutoff");
190-
mempool.AddTransactionsUpdated(1);
190+
if (node.mempool) node.mempool->AddTransactionsUpdated(1);
191191

192192
StopHTTPRPC();
193193
StopREST();
@@ -231,8 +231,8 @@ void Shutdown(NodeContext& node)
231231
node.connman.reset();
232232
node.banman.reset();
233233

234-
if (::mempool.IsLoaded() && node.args->GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
235-
DumpMempool(::mempool);
234+
if (node.mempool && node.mempool->IsLoaded() && node.args->GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
235+
DumpMempool(*node.mempool);
236236
}
237237

238238
if (fFeeEstimatesInitialized)
@@ -738,10 +738,7 @@ static void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImp
738738
return;
739739
}
740740
} // End scope of CImportingNow
741-
if (args.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
742-
LoadMempool(::mempool);
743-
}
744-
::mempool.SetIsLoaded(!ShutdownRequested());
741+
chainman.ActiveChainstate().LoadMempool(args);
745742
}
746743

747744
/** Sanity checks
@@ -1054,11 +1051,6 @@ bool AppInitParameterInteraction(const ArgsManager& args)
10541051
}
10551052
}
10561053

1057-
// Checkmempool and checkblockindex default to true in regtest mode
1058-
int ratio = std::min<int>(std::max<int>(args.GetArg("-checkmempool", chainparams.DefaultConsistencyChecks() ? 1 : 0), 0), 1000000);
1059-
if (ratio != 0) {
1060-
mempool.setSanityCheck(1.0 / ratio);
1061-
}
10621054
fCheckBlockIndex = args.GetBoolArg("-checkblockindex", chainparams.DefaultConsistencyChecks());
10631055
fCheckpointsEnabled = args.GetBoolArg("-checkpoints", DEFAULT_CHECKPOINTS_ENABLED);
10641056

@@ -1368,10 +1360,18 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
13681360
node.banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", &uiInterface, args.GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME));
13691361
assert(!node.connman);
13701362
node.connman = MakeUnique<CConnman>(GetRand(std::numeric_limits<uint64_t>::max()), GetRand(std::numeric_limits<uint64_t>::max()), args.GetBoolArg("-networkactive", true));
1363+
13711364
// Make mempool generally available in the node context. For example the connection manager, wallet, or RPC threads,
13721365
// which are all started after this, may use it from the node context.
13731366
assert(!node.mempool);
13741367
node.mempool = &::mempool;
1368+
if (node.mempool) {
1369+
int ratio = std::min<int>(std::max<int>(args.GetArg("-checkmempool", chainparams.DefaultConsistencyChecks() ? 1 : 0), 0), 1000000);
1370+
if (ratio != 0) {
1371+
node.mempool->setSanityCheck(1.0 / ratio);
1372+
}
1373+
}
1374+
13751375
assert(!node.chainman);
13761376
node.chainman = &g_chainman;
13771377
ChainstateManager& chainman = *Assert(node.chainman);

src/validation.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4227,6 +4227,14 @@ bool static LoadBlockIndexDB(ChainstateManager& chainman, const CChainParams& ch
42274227
return true;
42284228
}
42294229

4230+
void CChainState::LoadMempool(const ArgsManager& args)
4231+
{
4232+
if (args.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
4233+
::LoadMempool(m_mempool);
4234+
}
4235+
m_mempool.SetIsLoaded(!ShutdownRequested());
4236+
}
4237+
42304238
bool CChainState::LoadChainTip(const CChainParams& chainparams)
42314239
{
42324240
AssertLockHeld(cs_main);

src/validation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,9 @@ class CChainState {
671671
*/
672672
void CheckBlockIndex(const Consensus::Params& consensusParams);
673673

674+
/** Load the persisted mempool from disk */
675+
void LoadMempool(const ArgsManager& args);
676+
674677
/** Update the chain tip based on database information, i.e. CoinsTip()'s best block. */
675678
bool LoadChainTip(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
676679

0 commit comments

Comments
 (0)