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>
This commit is contained in:
Antoine Poinsot
2020-07-28 19:12:50 +02:00
parent 03bfeee957
commit 86ff2cf202
11 changed files with 48 additions and 27 deletions

View File

@@ -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);