mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-17 19:10:40 +01:00
Merge #18766: Disable fee estimation in blocksonly mode (by removing the fee estimates global)
4e28753f60feestimator: encapsulate estimation file logic (Antoine Poinsot)e8ea6ad9c1init: don't create a CBlockPolicyEstimator if we don't relay transactions (Antoine Poinsot)86ff2cf202Remove the remaining fee estimation globals (Antoine Poinsot)03bfeee957interface: remove unused estimateSmartFee method from node (Antoine Poinsot) Pull request description: If the `blocksonly` mode is turned on after running with transaction relay enabled for a while, the fee estimation will serve outdated data to both the internal wallet and to external applications that might be feerate-sensitive and make use of `estimatesmartfee` (for example a Lightning Network node). This has already caused issues (for example https://github.com/bitcoin/bitcoin/issues/16840 (C-lightning), or https://github.com/lightningnetwork/lnd/issues/2562 (LND)) and it seems prudent to fail rather than to give inaccurate values. This fixes #16840, and closes #16890 which tried to fix the symptoms (RPC) but not the cause as mentioned by sdaftuar : > If this is a substantial problem, then I would think we should take action to protect our own wallet users as well (rather than hide the results of what our fee estimation would do!). ACKs for top commit: MarcoFalke: re-ACK4e28753f60👋 jnewbery: utACK4e28753f60Tree-SHA512: c869cf03b86d8194002970bbc84662dae76874967949b9be0d9a4511a1eabcb1627c38aca3154da9dcece1a4c49ec02bd4f9fcca2ec310986e07904559e63ba8
This commit is contained in:
41
src/init.cpp
41
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;
|
||||
@@ -99,8 +98,6 @@ static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false;
|
||||
#define MIN_CORE_FILEDESCRIPTORS 150
|
||||
#endif
|
||||
|
||||
static const char* FEE_ESTIMATES_FILENAME="fee_estimates.dat";
|
||||
|
||||
static const char* DEFAULT_ASMAP_FILENAME="ip_asn.map";
|
||||
|
||||
/**
|
||||
@@ -236,17 +233,8 @@ void Shutdown(NodeContext& node)
|
||||
DumpMempool(*node.mempool);
|
||||
}
|
||||
|
||||
if (fFeeEstimatesInitialized)
|
||||
{
|
||||
::feeEstimator.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
|
||||
LogPrintf("%s: Failed to write fee estimates to %s\n", __func__, est_path.string());
|
||||
fFeeEstimatesInitialized = false;
|
||||
}
|
||||
// Drop transactions we were still watching, and record fee estimations.
|
||||
if (node.fee_estimator) node.fee_estimator->Flush();
|
||||
|
||||
// FlushStateToDisk generates a ChainStateFlushed callback, which we should avoid missing
|
||||
if (node.chainman) {
|
||||
@@ -304,6 +292,7 @@ void Shutdown(NodeContext& node)
|
||||
globalVerifyHandle.reset();
|
||||
ECC_Stop();
|
||||
node.mempool.reset();
|
||||
node.fee_estimator.reset();
|
||||
node.chainman = nullptr;
|
||||
node.scheduler.reset();
|
||||
|
||||
@@ -1384,14 +1373,24 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
|
||||
// is not yet setup and may end up being set up twice if we
|
||||
// need to reindex later.
|
||||
|
||||
// see Step 2: parameter interactions for more information about these
|
||||
fListen = args.GetBoolArg("-listen", DEFAULT_LISTEN);
|
||||
fDiscover = args.GetBoolArg("-discover", true);
|
||||
g_relay_txes = !args.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY);
|
||||
|
||||
assert(!node.banman);
|
||||
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));
|
||||
|
||||
assert(!node.fee_estimator);
|
||||
// Don't initialize fee estimation with old data if we don't relay transactions,
|
||||
// as they would never get updated.
|
||||
if (g_relay_txes) 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;
|
||||
@@ -1473,11 +1472,6 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
|
||||
}
|
||||
}
|
||||
|
||||
// see Step 2: parameter interactions for more information about these
|
||||
fListen = args.GetBoolArg("-listen", DEFAULT_LISTEN);
|
||||
fDiscover = args.GetBoolArg("-discover", true);
|
||||
g_relay_txes = !args.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY);
|
||||
|
||||
for (const std::string& strAddr : args.GetArgs("-externalip")) {
|
||||
CService addrLocal;
|
||||
if (Lookup(strAddr, addrLocal, GetListenPort(), fNameLookup) && addrLocal.IsValid())
|
||||
@@ -1785,13 +1779,6 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
// ********************************************************* Step 8: start indexers
|
||||
if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
|
||||
g_txindex = MakeUnique<TxIndex>(nTxIndexCache, false, fReindex);
|
||||
|
||||
Reference in New Issue
Block a user