45 "Estimates the approximate fee per kilobyte needed for a transaction to begin\n"
46 "confirmation within conf_target blocks if possible and return the number of blocks\n"
47 "for which the estimate is valid. Uses virtual transaction size as defined\n"
48 "in BIP 141 (witness data is discounted).\n",
56 "Selects which fee rate estimator to use.\n"
57 "\"none\" returns the lower of the block policy and mempool estimates. If the mempool\n"
58 "estimate is unavailable, it returns that error instead of falling back to the block\n"
59 "policy estimate; use \"block_policy\" in that case to get the block policy estimate.\n"
60 "\"block_policy\" uses only the block policy fee rate estimator.\n"
61 "\"mempool_policy\" uses only the mempool fee rate estimator.\n"
62 "Unknown values are treated as \"none\"."},
64 "1 returns feerate or errors. 2 also returns \"mempool_health_statistics\"."},
72 {
RPCResult::Type::STR,
"estimator",
true,
"the fee estimator used to produce the result (only present for successful estimates when fee_rate_estimator is \"none\")"},
73 {
RPCResult::Type::ARR,
"errors",
true,
"Errors encountered during processing (if there are any)",
77 {
RPCResult::Type::NUM,
"blocks",
"the confirmation target in blocks for the returned fee rate estimate.\n"
78 "For the block policy fee rate estimator, this is the target the estimate was found at, clamped to at\n"
79 "least 2 and at most the estimator's maximum usable target. For the mempool fee rate\n"
80 "estimator, it is always 2."},
81 {
RPCResult::Type::ARR,
"mempool_health_statistics",
true,
"Health statistics for the most recently mined blocks tracked by the mempool fee rate estimator (only present when verbosity >= 2)",
86 {
RPCResult::Type::NUM,
"block_weight",
"Total weight of non-coinbase transactions in the block"},
87 {
RPCResult::Type::NUM,
"mempool_txs_weight",
"Total weight of transactions removed from the mempool for this block"},
115 options[
"fee_rate_estimator"].isNull() ?
"none" : options[
"fee_rate_estimator"].get_str())};
120 const auto estimate{fee_estimator_man.
GetFeeRateEstimate(fee_rate_estimator, conf_target, conservative)};
124 const auto fee_rate{std::max({
CFeeRate(estimate->feerate), min_mempool_feerate, min_relay_feerate})};
127 errors.
push_back(estimate.error().reason);
128 result.
pushKV(
"errors", std::move(errors));
134 result.
pushKV(
"blocks", estimation.returned_target);
135 if (verbosity >= 2) {
138 for (
auto it = blocks_data.rbegin(); it != blocks_data.rend(); ++it) {
140 entry.
pushKV(
"block_height", it->m_height);
141 entry.
pushKV(
"block_weight", it->m_block_weight);
142 entry.
pushKV(
"mempool_txs_weight", it->m_removed_block_txs_weight);
143 mempool_health_stats.
push_back(std::move(entry));
145 result.
pushKV(
"mempool_health_statistics", std::move(mempool_health_stats));
154 auto fields = std::vector<RPCResult>{
157 {
RPCResult::Type::NUM,
"withintarget",
"number of txs over history horizon in the feerate range that were confirmed within target"},
158 {
RPCResult::Type::NUM,
"totalconfirmed",
"number of txs over history horizon in the feerate range that were confirmed at any point"},
159 {
RPCResult::Type::NUM,
"inmempool",
"current number of txs in mempool in the feerate range unconfirmed for at least target blocks"},
160 {
RPCResult::Type::NUM,
"leftmempool",
"number of txs over history horizon in the feerate range that left mempool unconfirmed after target"},
162 return elide ?
ElideGroup(std::move(fields)) : fields;
167 auto fields = std::vector<RPCResult>{
169 {
RPCResult::Type::NUM,
"decay",
"exponential decay (per block) for historical moving average of confirmation data"},
173 {
RPCResult::Type::ARR,
"errors",
true,
"Errors encountered during processing (if there are any)",
178 return elide ?
ElideGroup(std::move(fields)) : fields;
185 "WARNING: This interface is unstable and may disappear or change!\n"
186 "\nWARNING: This is an advanced API call that is tightly coupled to the specific\n"
187 "implementation of fee estimation. The parameters it can be called with\n"
188 "and the results it returns will change if the internal implementation changes.\n"
189 "\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n"
190 "confirmation within conf_target blocks if possible. Uses virtual transaction size as\n"
191 "defined in BIP 141 (witness data is discounted).\n",
195 "confirmed within conf_target in order to consider those feerates as high enough and proceed to check\n"
199 RPCResult::Type::OBJ,
"",
"Results are returned for any horizon which tracks blocks up to the confirmation target",
219 double threshold = 0.95;
220 if (!request.params[1].isNull()) {
221 threshold = request.params[1].get_real();
223 if (threshold < 0 || threshold > 1) {
259 horizon_result.
pushKV(
"pass", std::move(passbucket));
261 if (buckets.
fail.
start != -1) horizon_result.
pushKV(
"fail", std::move(failbucket));
266 horizon_result.
pushKV(
"fail", std::move(failbucket));
267 errors.
push_back(
"Insufficient data or no feerate found which meets threshold");
268 horizon_result.
pushKV(
"errors", std::move(errors));
283 for (
const auto& c : commands) {
284 t.appendCommand(c.name, &c);
constexpr auto ALL_FEE_ESTIMATE_HORIZONS
#define CHECK_NONFATAL(condition)
Identity function.
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
CAmount GetFeePerK() const
Return the fee in satoshis for a vsize of 1000 vbytes.
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
CFeeRate GetMinFee(size_t sizelimit) const
Manages fee rate estimators.
unsigned int BlockPolicyHighestTargetTracked(FeeEstimateHorizon horizon) const
Returns the maximum supported confirmation target of block policy estimator.
virtual util::Expected< FeeRateEstimation, FeeRateEstimationError > GetFeeRateEstimate(int target, bool conservative) const
Get a fee rate estimate from the available fee rate estimators.
std::vector< MinedBlockStats > MempoolPolicyEstimatorBlocksStats() const
Returns per-block weight statistics for the last MEMPOOL_HEALTH_WINDOW_BLOCKS mined blocks.
virtual unsigned int MaximumTarget() const
Returns the maximum supported confirmation target from all fee rate estimators.
CFeeRate BlockPolicyEstimateRawFee(unsigned int target, double threshold, FeeEstimateHorizon horizon, EstimationResult *buckets) const
Delegate to the block policy estimator's estimateRawFee (used by the estimaterawfee RPC).
auto Arg(std::string_view key) const
Helper to get a required or default-valued request argument.
void push_back(UniValue val)
void pushKV(std::string key, UniValue val)
UniValue ValueFromAmount(const CAmount amount)
const std::string CURRENCY_UNIT
is a home for simple string functions returning descriptive messages that are used in RPC and GUI int...
std::string FeeModesDetail(std::string default_info)
bool FeeModeFromString(std::string_view mode_string, FeeEstimateMode &fee_estimate_mode)
std::string InvalidEstimateModeErrorMessage()
std::string StringForFeeEstimateHorizon(FeeEstimateHorizon horizon)
UniValue JSONRPCError(int code, const std::string &message)
static RPCMethod estimaterawfee()
static std::vector< RPCResult > FeeEstimateHorizonDoc(bool elide=false)
static std::vector< RPCResult > FeeRateBucketDoc(bool elide=false)
static RPCMethod estimatesmartfee()
void RegisterFeeRPCCommands(CRPCTable &t)
@ RPC_INVALID_PARAMETER
Invalid, missing or duplicate parameter.
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
std::vector< RPCResult > ElideGroup(std::vector< RPCResult > fields, std::string summary)
Stamp elision onto an entire vector of RPCResult fields at once.
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
int ParseVerbosity(const UniValue &arg, int default_verbosity, bool allow_bool)
Parses verbosity from provided UniValue.
unsigned int ParseConfirmTarget(const UniValue &value, unsigned int max_target)
Parse a confirm target option and raise an RPC error if it is invalid.
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull, bool fStrict)
NodeContext & EnsureAnyNodeContext(const std::any &context)
CTxMemPool & EnsureMemPool(const NodeContext &node)
FeeRateEstimatorManager & EnsureAnyFeeEstimatorMan(const std::any &context)
A successful fee rate estimate returned by a fee rate estimator.
@ OMITTED
Optional argument for which the default value is omitted from help text for one of two reasons:
Wrapper for UniValue::VType, which includes typeAny: Used to denote don't care type.
ValidationSignals * signals
CFeeRate min_relay_feerate
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation)
NodeContext struct containing references to chain state and connection state.
std::string_view FeeRateEstimatorTypeToString(FeeRateEstimatorType feerate_estimator_type)
FeeRateEstimatorType FeeRateEstimatorTypeFromString(std::string_view feerate_estimator_type)
const FeeRateEstimation & FeeRateEstimationRef(const util::Expected< FeeRateEstimation, FeeRateEstimationError > &result LIFETIMEBOUND)
Return the estimation carried by a fee rate estimate result: the successful estimation,...
@ CONSERVATIVE
Force Fee rate estimator to return conservative estimates.