14 #include <txmempool.h>
32 "\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n"
33 "confirmation within conf_target blocks if possible and return the number of blocks\n"
34 "for which the estimate is valid. Uses virtual transaction size as defined\n"
35 "in BIP 141 (witness data is discounted).\n",
39 "Whether to return a more conservative estimate which also satisfies\n"
40 "a longer history. A conservative estimate potentially returns a\n"
41 "higher feerate and is more likely to be sufficient for the desired\n"
42 "target, but is not as responsive to short term drops in the\n"
43 "prevailing fee market. Must be one of (case insensitive):\n"
50 {
RPCResult::Type::ARR,
"errors",
true,
"Errors encountered during processing (if there are any)",
55 "The request target will be clamped between 2 and the highest target\n"
56 "fee estimation is able to return based on how long it has been running.\n"
57 "An error is returned if not enough transactions and blocks\n"
58 "have been observed to make an estimate for any number of blocks."},
72 bool conservative =
true;
73 if (!request.params[1].isNull()) {
88 feeRate = std::max({feeRate, min_mempool_feerate, min_relay_feerate});
91 errors.
push_back(
"Insufficient data or no feerate found");
92 result.
pushKV(
"errors", errors);
103 "\nWARNING: This interface is unstable and may disappear or change!\n"
104 "\nWARNING: This is an advanced API call that is tightly coupled to the specific\n"
105 "implementation of fee estimation. The parameters it can be called with\n"
106 "and the results it returns will change if the internal implementation changes.\n"
107 "\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n"
108 "confirmation within conf_target blocks if possible. Uses virtual transaction size as\n"
109 "defined in BIP 141 (witness data is discounted).\n",
113 "confirmed within conf_target in order to consider those feerates as high enough and proceed to check\n"
117 RPCResult::Type::OBJ,
"",
"Results are returned for any horizon which tracks blocks up to the confirmation target",
122 {
RPCResult::Type::NUM,
"decay",
"exponential decay (per block) for historical moving average of confirmation data"},
124 {
RPCResult::Type::OBJ,
"pass",
true,
"information about the lowest range of feerates to succeed in meeting the threshold",
128 {
RPCResult::Type::NUM,
"withintarget",
"number of txs over history horizon in the feerate range that were confirmed within target"},
129 {
RPCResult::Type::NUM,
"totalconfirmed",
"number of txs over history horizon in the feerate range that were confirmed at any point"},
130 {
RPCResult::Type::NUM,
"inmempool",
"current number of txs in mempool in the feerate range unconfirmed for at least target blocks"},
131 {
RPCResult::Type::NUM,
"leftmempool",
"number of txs over history horizon in the feerate range that left mempool unconfirmed after target"},
133 {
RPCResult::Type::OBJ,
"fail",
true,
"information about the highest range of feerates to fail to meet the threshold",
137 {
RPCResult::Type::ARR,
"errors",
true,
"Errors encountered during processing (if there are any)",
160 double threshold = 0.95;
161 if (!request.params[1].isNull()) {
162 threshold = request.params[1].get_real();
164 if (threshold < 0 || threshold > 1) {
177 feeRate = fee_estimator.
estimateRawFee(conf_target, threshold, horizon, &buckets);
199 horizon_result.
pushKV(
"scale", (
int)buckets.
scale);
200 horizon_result.
pushKV(
"pass", passbucket);
202 if (buckets.
fail.
start != -1) horizon_result.
pushKV(
"fail", failbucket);
206 horizon_result.
pushKV(
"scale", (
int)buckets.
scale);
207 horizon_result.
pushKV(
"fail", failbucket);
208 errors.
push_back(
"Insufficient data or no feerate found which meets threshold");
209 horizon_result.
pushKV(
"errors", errors);
224 for (
const auto& c : commands) {
225 t.appendCommand(c.name, &c);
The BlockPolicyEstimator is used for estimating the feerate needed for a transaction to be included i...
CFeeRate estimateSmartFee(int confTarget, FeeCalculation *feeCalc, bool conservative) const EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator)
Estimate feerate needed to get be included in a block within confTarget blocks.
unsigned int HighestTargetTracked(FeeEstimateHorizon horizon) const EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator)
Calculation of highest target that estimates are tracked for.
CFeeRate estimateRawFee(int confTarget, double successThreshold, FeeEstimateHorizon horizon, EstimationResult *result=nullptr) const EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator)
Return a specific fee estimate calculation with a given success threshold and time horizon,...
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
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
const CFeeRate m_min_relay_feerate
void push_back(UniValue val)
void pushKV(std::string key, UniValue val)
UniValue ValueFromAmount(const CAmount amount)
const std::string CURRENCY_UNIT
@ ECONOMICAL
Force estimateSmartFee to use non-conservative estimates.
std::string StringForFeeEstimateHorizon(FeeEstimateHorizon horizon)
static constexpr auto ALL_FEE_ESTIMATE_HORIZONS
UniValue JSONRPCError(int code, const std::string &message)
static RPCHelpMan estimatesmartfee()
void RegisterFeeRPCCommands(CRPCTable &t)
static RPCHelpMan estimaterawfee()
@ RPC_INVALID_PARAMETER
Invalid, missing or duplicate parameter.
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
unsigned int ParseConfirmTarget(const UniValue &value, unsigned int max_target)
Parse a confirm target option and raise an RPC error if it is invalid.
NodeContext & EnsureAnyNodeContext(const std::any &context)
CBlockPolicyEstimator & EnsureAnyFeeEstimator(const std::any &context)
CTxMemPool & EnsureMemPool(const NodeContext &node)
@ ELISION
Special type to denote elision (...)
NodeContext struct containing references to chain state and connection state.
std::string FeeModes(const std::string &delimiter)
std::string InvalidEstimateModeErrorMessage()
bool FeeModeFromString(const std::string &mode_string, FeeEstimateMode &fee_estimate_mode)