aboutsummaryrefslogtreecommitdiff
path: root/src/init.cpp
diff options
context:
space:
mode:
authorAntoine Poinsot <darosior@protonmail.com>2020-07-28 19:12:50 +0200
committerAntoine Poinsot <darosior@protonmail.com>2020-12-03 12:56:37 +0100
commit86ff2cf202bfb9d9b50800b8ffe3fead3f77f5fa (patch)
tree112793cb81c576520e0a4e7573556f239d95b87c /src/init.cpp
parent03bfeee957ab7e3b6aece82b9561774648094f54 (diff)
downloadbitcoin-86ff2cf202bfb9d9b50800b8ffe3fead3f77f5fa.tar.xz
Remove the remaining fee estimation globals
This moves the CBlockPolicyEstimator to the NodeContext, which get rids of two globals and allows us to conditionally create the CBlockPolicyEstimator (and to remove a circular dep). Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
Diffstat (limited to 'src/init.cpp')
-rw-r--r--src/init.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 9137050323..5c06b0459d 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -85,7 +85,6 @@
#include <zmq/zmqrpc.h>
#endif
-static bool fFeeEstimatesInitialized = false;
static const bool DEFAULT_PROXYRANDOMIZE = true;
static const bool DEFAULT_REST_ENABLE = false;
static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false;
@@ -236,18 +235,18 @@ void Shutdown(NodeContext& node)
DumpMempool(*node.mempool);
}
- if (fFeeEstimatesInitialized)
- {
- ::feeEstimator.FlushUnconfirmed();
+ if (node.fee_estimator) {
+ node.fee_estimator->FlushUnconfirmed();
fs::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME;
CAutoFile est_fileout(fsbridge::fopen(est_path, "wb"), SER_DISK, CLIENT_VERSION);
- if (!est_fileout.IsNull())
- ::feeEstimator.Write(est_fileout);
- else
+ if (!est_fileout.IsNull()) {
+ node.fee_estimator->Write(est_fileout);
+ } else {
LogPrintf("%s: Failed to write fee estimates to %s\n", __func__, est_path.string());
- fFeeEstimatesInitialized = false;
+ }
}
+
// FlushStateToDisk generates a ChainStateFlushed callback, which we should avoid missing
if (node.chainman) {
LOCK(cs_main);
@@ -304,6 +303,7 @@ void Shutdown(NodeContext& node)
globalVerifyHandle.reset();
ECC_Stop();
node.mempool.reset();
+ node.fee_estimator.reset();
node.chainman = nullptr;
node.scheduler.reset();
@@ -1389,9 +1389,12 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
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));
+ assert(!node.fee_estimator);
+ node.fee_estimator = std::make_unique<CBlockPolicyEstimator>();
+
assert(!node.mempool);
int check_ratio = std::min<int>(std::max<int>(args.GetArg("-checkmempool", chainparams.DefaultConsistencyChecks() ? 1 : 0), 0), 1000000);
- node.mempool = MakeUnique<CTxMemPool>(&::feeEstimator, check_ratio);
+ node.mempool = std::make_unique<CTxMemPool>(node.fee_estimator.get(), check_ratio);
assert(!node.chainman);
node.chainman = &g_chainman;
@@ -1788,10 +1791,9 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
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.
- if (!est_filein.IsNull())
- ::feeEstimator.Read(est_filein);
- fFeeEstimatesInitialized = true;
-
+ if (node.fee_estimator && !est_filein.IsNull()) {
+ node.fee_estimator->Read(est_filein);
+ }
// ********************************************************* Step 8: start indexers
if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
g_txindex = MakeUnique<TxIndex>(nTxIndexCache, false, fReindex);