mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
Rewrite estimateSmartFee
Change the logic of estimateSmartFee to check a 60% threshold at half the target, a 85% threshold at the target and a 95% threshold at double the target. Always check the shortest time horizon possible and ensure that estimates are monotonically decreasing. Add a conservative mode, which makes sure that the 95% threshold is also met at longer time horizons as well.
This commit is contained in:
@@ -828,16 +828,20 @@ UniValue estimatefee(const JSONRPCRequest& request)
|
||||
|
||||
UniValue estimatesmartfee(const JSONRPCRequest& request)
|
||||
{
|
||||
if (request.fHelp || request.params.size() != 1)
|
||||
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
|
||||
throw std::runtime_error(
|
||||
"estimatesmartfee nblocks\n"
|
||||
"estimatesmartfee nblocks (conservative)\n"
|
||||
"\nWARNING: This interface is unstable and may disappear or change!\n"
|
||||
"\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n"
|
||||
"confirmation within nblocks blocks if possible and return the number of blocks\n"
|
||||
"for which the estimate is valid. Uses virtual transaction size as defined\n"
|
||||
"in BIP 141 (witness data is discounted).\n"
|
||||
"\nArguments:\n"
|
||||
"1. nblocks (numeric)\n"
|
||||
"1. nblocks (numeric)\n"
|
||||
"2. conservative (bool, optional, default=true) Whether to return a more conservative estimate which\n"
|
||||
" also satisfies a longer history. A conservative estimate potentially returns a higher\n"
|
||||
" feerate and is more likely to be sufficient for the desired target, but is not as\n"
|
||||
" responsive to short term drops in the prevailing fee market\n"
|
||||
"\nResult:\n"
|
||||
"{\n"
|
||||
" \"feerate\" : x.x, (numeric) estimate fee-per-kilobyte (in BTC)\n"
|
||||
@@ -854,10 +858,15 @@ UniValue estimatesmartfee(const JSONRPCRequest& request)
|
||||
RPCTypeCheck(request.params, boost::assign::list_of(UniValue::VNUM));
|
||||
|
||||
int nBlocks = request.params[0].get_int();
|
||||
bool conservative = true;
|
||||
if (request.params.size() > 1 && !request.params[1].isNull()) {
|
||||
RPCTypeCheckArgument(request.params[1], UniValue::VBOOL);
|
||||
conservative = request.params[1].get_bool();
|
||||
}
|
||||
|
||||
UniValue result(UniValue::VOBJ);
|
||||
int answerFound;
|
||||
CFeeRate feeRate = ::feeEstimator.estimateSmartFee(nBlocks, &answerFound, ::mempool);
|
||||
CFeeRate feeRate = ::feeEstimator.estimateSmartFee(nBlocks, &answerFound, ::mempool, conservative);
|
||||
result.push_back(Pair("feerate", feeRate == CFeeRate(0) ? -1.0 : ValueFromAmount(feeRate.GetFeePerK())));
|
||||
result.push_back(Pair("blocks", answerFound));
|
||||
return result;
|
||||
@@ -951,7 +960,7 @@ static const CRPCCommand commands[] =
|
||||
{ "generating", "generatetoaddress", &generatetoaddress, true, {"nblocks","address","maxtries"} },
|
||||
|
||||
{ "util", "estimatefee", &estimatefee, true, {"nblocks"} },
|
||||
{ "util", "estimatesmartfee", &estimatesmartfee, true, {"nblocks"} },
|
||||
{ "util", "estimatesmartfee", &estimatesmartfee, true, {"nblocks", "conservative"} },
|
||||
|
||||
{ "hidden", "estimaterawfee", &estimaterawfee, true, {"nblocks", "threshold", "horizon"} },
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user