aboutsummaryrefslogtreecommitdiff
path: root/src/init.cpp
diff options
context:
space:
mode:
authorMarcoFalke <[email protected]>2020-09-07 09:47:14 +0200
committerMarcoFalke <[email protected]>2020-09-07 09:47:28 +0200
commit07087051afe9cd5a66ea3e9c0a05079b1ffff47f (patch)
tree4a6dc9263bfb221450f046ca422ad26b1d474733 /src/init.cpp
parentMerge #19738: wallet: Avoid multiple BerkeleyBatch in DelAddressBook (diff)
parentRemove mempool global (diff)
downloaddiscoin-07087051afe9cd5a66ea3e9c0a05079b1ffff47f.tar.xz
discoin-07087051afe9cd5a66ea3e9c0a05079b1ffff47f.zip
Merge #19556: Remove mempool global
fafb381af8279b2d2ca768df0bf68d7eb036a2f9 Remove mempool global (MarcoFalke) fa0359c5b30730744aa8a7cd9ffab79ded91041f Remove mempool global from p2p (MarcoFalke) eeee1104d78eb59a582ee1709ff4ac2c33ee1190 Remove mempool global from init (MarcoFalke) Pull request description: This refactor unlocks some nice potential features, such as, but not limited to: * Removing the fee estimates global (would avoid slightly fragile workarounds such as #18766) * Making the mempool optional for a "blocksonly" operation mode Even absent those features, the new code without the global should be easier to maintain, read and write tests for. ACKs for top commit: jnewbery: utACK fafb381af8279b2d2ca768df0bf68d7eb036a2f9 hebasto: ACK fafb381af8279b2d2ca768df0bf68d7eb036a2f9, I have reviewed the code and it looks OK, I agree it can be merged. darosior: ACK fafb381af8279b2d2ca768df0bf68d7eb036a2f9 Tree-SHA512: a2e696dc377e2e81eaf9c389e6d13dde4a48d81f3538df88f4da502d3012dd61078495140ab5a5854f360a06249fe0e1f6a094c4e006d8b5cc2552a946becf26
Diffstat (limited to 'src/init.cpp')
-rw-r--r--src/init.cpp30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/init.cpp b/src/init.cpp
index bb93f5c79..633dd8cef 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -187,7 +187,7 @@ void Shutdown(NodeContext& node)
/// Be sure that anything that writes files or flushes caches only does this if the respective
/// module was initialized.
util::ThreadRename("shutoff");
- mempool.AddTransactionsUpdated(1);
+ if (node.mempool) node.mempool->AddTransactionsUpdated(1);
StopHTTPRPC();
StopREST();
@@ -231,8 +231,8 @@ void Shutdown(NodeContext& node)
node.connman.reset();
node.banman.reset();
- if (::mempool.IsLoaded() && node.args->GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
- DumpMempool(::mempool);
+ if (node.mempool && node.mempool->IsLoaded() && node.args->GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
+ DumpMempool(*node.mempool);
}
if (fFeeEstimatesInitialized)
@@ -302,7 +302,7 @@ void Shutdown(NodeContext& node)
GetMainSignals().UnregisterBackgroundSignalScheduler();
globalVerifyHandle.reset();
ECC_Stop();
- node.mempool = nullptr;
+ node.mempool.reset();
node.chainman = nullptr;
node.scheduler.reset();
@@ -738,10 +738,7 @@ static void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImp
return;
}
} // End scope of CImportingNow
- if (args.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
- LoadMempool(::mempool);
- }
- ::mempool.SetIsLoaded(!ShutdownRequested());
+ chainman.ActiveChainstate().LoadMempool(args);
}
/** Sanity checks
@@ -1054,11 +1051,6 @@ bool AppInitParameterInteraction(const ArgsManager& args)
}
}
- // Checkmempool and checkblockindex default to true in regtest mode
- int ratio = std::min<int>(std::max<int>(args.GetArg("-checkmempool", chainparams.DefaultConsistencyChecks() ? 1 : 0), 0), 1000000);
- if (ratio != 0) {
- mempool.setSanityCheck(1.0 / ratio);
- }
fCheckBlockIndex = args.GetBoolArg("-checkblockindex", chainparams.DefaultConsistencyChecks());
fCheckpointsEnabled = args.GetBoolArg("-checkpoints", DEFAULT_CHECKPOINTS_ENABLED);
@@ -1368,10 +1360,18 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
node.banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", &uiInterface, args.GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME));
assert(!node.connman);
node.connman = MakeUnique<CConnman>(GetRand(std::numeric_limits<uint64_t>::max()), GetRand(std::numeric_limits<uint64_t>::max()), args.GetBoolArg("-networkactive", true));
+
// 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;
+ node.mempool = MakeUnique<CTxMemPool>(&::feeEstimator);
+ if (node.mempool) {
+ int ratio = std::min<int>(std::max<int>(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;
ChainstateManager& chainman = *Assert(node.chainman);
@@ -1559,7 +1559,7 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
chainman.m_total_coinstip_cache = nCoinCacheUsage;
chainman.m_total_coinsdb_cache = nCoinDBCache;
- UnloadBlockIndex(node.mempool);
+ UnloadBlockIndex(node.mempool.get());
// new CBlockTreeDB tries to delete the existing file, which
// fails if it's still open from the previous loop. Close it first: