mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-03 12:25:54 +02:00
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:
@@ -17,6 +17,7 @@
|
||||
#include <node/coinstats.h>
|
||||
#include <node/context.h>
|
||||
#include <node/utxo_snapshot.h>
|
||||
#include <policy/fees.h>
|
||||
#include <policy/feerate.h>
|
||||
#include <policy/policy.h>
|
||||
#include <policy/rbf.h>
|
||||
@@ -81,6 +82,15 @@ ChainstateManager& EnsureChainman(const util::Ref& context)
|
||||
return *node.chainman;
|
||||
}
|
||||
|
||||
CBlockPolicyEstimator& EnsureFeeEstimator(const util::Ref& context)
|
||||
{
|
||||
NodeContext& node = EnsureNodeContext(context);
|
||||
if (!node.fee_estimator) {
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Fee estimation disabled");
|
||||
}
|
||||
return *node.fee_estimator;
|
||||
}
|
||||
|
||||
/* Calculate the difficulty for a given block index.
|
||||
*/
|
||||
double GetDifficulty(const CBlockIndex* blockindex)
|
||||
|
||||
@@ -15,6 +15,7 @@ extern RecursiveMutex cs_main;
|
||||
|
||||
class CBlock;
|
||||
class CBlockIndex;
|
||||
class CBlockPolicyEstimator;
|
||||
class CTxMemPool;
|
||||
class ChainstateManager;
|
||||
class UniValue;
|
||||
@@ -54,5 +55,6 @@ void CalculatePercentilesByWeight(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES],
|
||||
NodeContext& EnsureNodeContext(const util::Ref& context);
|
||||
CTxMemPool& EnsureMemPool(const util::Ref& context);
|
||||
ChainstateManager& EnsureChainman(const util::Ref& context);
|
||||
CBlockPolicyEstimator& EnsureFeeEstimator(const util::Ref& context);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1059,7 +1059,10 @@ static RPCHelpMan estimatesmartfee()
|
||||
{
|
||||
RPCTypeCheck(request.params, {UniValue::VNUM, UniValue::VSTR});
|
||||
RPCTypeCheckArgument(request.params[0], UniValue::VNUM);
|
||||
unsigned int max_target = ::feeEstimator.HighestTargetTracked(FeeEstimateHorizon::LONG_HALFLIFE);
|
||||
|
||||
CBlockPolicyEstimator& fee_estimator = EnsureFeeEstimator(request.context);
|
||||
|
||||
unsigned int max_target = fee_estimator.HighestTargetTracked(FeeEstimateHorizon::LONG_HALFLIFE);
|
||||
unsigned int conf_target = ParseConfirmTarget(request.params[0], max_target);
|
||||
bool conservative = true;
|
||||
if (!request.params[1].isNull()) {
|
||||
@@ -1073,7 +1076,7 @@ static RPCHelpMan estimatesmartfee()
|
||||
UniValue result(UniValue::VOBJ);
|
||||
UniValue errors(UniValue::VARR);
|
||||
FeeCalculation feeCalc;
|
||||
CFeeRate feeRate = ::feeEstimator.estimateSmartFee(conf_target, &feeCalc, conservative);
|
||||
CFeeRate feeRate = fee_estimator.estimateSmartFee(conf_target, &feeCalc, conservative);
|
||||
if (feeRate != CFeeRate(0)) {
|
||||
result.pushKV("feerate", ValueFromAmount(feeRate.GetFeePerK()));
|
||||
} else {
|
||||
@@ -1144,7 +1147,10 @@ static RPCHelpMan estimaterawfee()
|
||||
{
|
||||
RPCTypeCheck(request.params, {UniValue::VNUM, UniValue::VNUM}, true);
|
||||
RPCTypeCheckArgument(request.params[0], UniValue::VNUM);
|
||||
unsigned int max_target = ::feeEstimator.HighestTargetTracked(FeeEstimateHorizon::LONG_HALFLIFE);
|
||||
|
||||
CBlockPolicyEstimator& fee_estimator = EnsureFeeEstimator(request.context);
|
||||
|
||||
unsigned int max_target = fee_estimator.HighestTargetTracked(FeeEstimateHorizon::LONG_HALFLIFE);
|
||||
unsigned int conf_target = ParseConfirmTarget(request.params[0], max_target);
|
||||
double threshold = 0.95;
|
||||
if (!request.params[1].isNull()) {
|
||||
@@ -1161,9 +1167,9 @@ static RPCHelpMan estimaterawfee()
|
||||
EstimationResult buckets;
|
||||
|
||||
// Only output results for horizons which track the target
|
||||
if (conf_target > ::feeEstimator.HighestTargetTracked(horizon)) continue;
|
||||
if (conf_target > fee_estimator.HighestTargetTracked(horizon)) continue;
|
||||
|
||||
feeRate = ::feeEstimator.estimateRawFee(conf_target, threshold, horizon, &buckets);
|
||||
feeRate = fee_estimator.estimateRawFee(conf_target, threshold, horizon, &buckets);
|
||||
UniValue horizon_result(UniValue::VOBJ);
|
||||
UniValue errors(UniValue::VARR);
|
||||
UniValue passbucket(UniValue::VOBJ);
|
||||
|
||||
Reference in New Issue
Block a user