diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -193,7 +193,9 @@ /// be locked. Be sure that anything that writes files or flushes caches /// only does this if the respective module was initialized. util::ThreadRename("shutoff"); - g_mempool.AddTransactionsUpdated(1); + if (node.mempool) { + node.mempool->AddTransactionsUpdated(1); + } StopHTTPRPC(); StopREST(); @@ -254,9 +256,9 @@ node.connman.reset(); node.banman.reset(); - if (::g_mempool.IsLoaded() && + if (node.mempool && node.mempool->IsLoaded() && node.args->GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) { - DumpMempool(::g_mempool); + DumpMempool(*node.mempool); } // FlushStateToDisk generates a ChainStateFlushed callback, which we should @@ -1458,10 +1460,7 @@ return; } } // End scope of CImportingNow - if (args.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) { - LoadMempool(config, ::g_mempool); - } - ::g_mempool.SetIsLoaded(!ShutdownRequested()); + chainman.ActiveChainstate().LoadMempool(config, args); } /** Sanity checks @@ -1866,16 +1865,6 @@ } } - // Checkmempool and checkblockindex default to true in regtest mode - int ratio = std::min( - std::max( - args.GetArg("-checkmempool", - chainparams.DefaultConsistencyChecks() ? 1 : 0), - 0), - 1000000); - if (ratio != 0) { - g_mempool.setSanityCheck(1.0 / ratio); - } fCheckBlockIndex = args.GetBoolArg("-checkblockindex", chainparams.DefaultConsistencyChecks()); fCheckpointsEnabled = @@ -2296,6 +2285,17 @@ // this, may use it from the node context. assert(!node.mempool); node.mempool = &::g_mempool; + if (node.mempool) { + int ratio = std::min( + std::max( + args.GetArg("-checkmempool", + chainparams.DefaultConsistencyChecks() ? 1 : 0), + 0), + 1000000); + if (ratio != 0) { + node.mempool->setSanityCheck(1.0 / ratio); + } + } assert(!node.chainman); node.chainman = &g_chainman; diff --git a/src/validation.h b/src/validation.h --- a/src/validation.h +++ b/src/validation.h @@ -945,6 +945,9 @@ */ void CheckBlockIndex(const Consensus::Params &consensusParams); + /** Load the persisted mempool from disk */ + void LoadMempool(const Config &config, const ArgsManager &args); + /** Update the chain tip based on database information, i.e. CoinsTip()'s * best block. */ bool LoadChainTip(const CChainParams &chainparams) diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -4851,6 +4851,13 @@ return true; } +void CChainState::LoadMempool(const Config &config, const ArgsManager &args) { + if (args.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) { + ::LoadMempool(config, m_mempool); + } + m_mempool.SetIsLoaded(!ShutdownRequested()); +} + bool CChainState::LoadChainTip(const CChainParams &chainparams) { AssertLockHeld(cs_main); const CCoinsViewCache &coins_cache = CoinsTip();