mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
merge bitcoin#22722: update estimatesmartfee rpc to return max of estimateSmartFee, mempoolMinFee and minRelayTxFee.
This commit is contained in:
parent
07e4c2cdd0
commit
63ac87f011
@ -1142,6 +1142,8 @@ static RPCHelpMan estimatesmartfee()
|
|||||||
RPCTypeCheckArgument(request.params[0], UniValue::VNUM);
|
RPCTypeCheckArgument(request.params[0], UniValue::VNUM);
|
||||||
|
|
||||||
CBlockPolicyEstimator& fee_estimator = EnsureAnyFeeEstimator(request.context);
|
CBlockPolicyEstimator& fee_estimator = EnsureAnyFeeEstimator(request.context);
|
||||||
|
const NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||||
|
const CTxMemPool& mempool = EnsureMemPool(node);
|
||||||
|
|
||||||
unsigned int max_target = fee_estimator.HighestTargetTracked(FeeEstimateHorizon::LONG_HALFLIFE);
|
unsigned int max_target = fee_estimator.HighestTargetTracked(FeeEstimateHorizon::LONG_HALFLIFE);
|
||||||
unsigned int conf_target = ParseConfirmTarget(request.params[0], max_target);
|
unsigned int conf_target = ParseConfirmTarget(request.params[0], max_target);
|
||||||
@ -1157,7 +1159,10 @@ static RPCHelpMan estimatesmartfee()
|
|||||||
UniValue result(UniValue::VOBJ);
|
UniValue result(UniValue::VOBJ);
|
||||||
UniValue errors(UniValue::VARR);
|
UniValue errors(UniValue::VARR);
|
||||||
FeeCalculation feeCalc;
|
FeeCalculation feeCalc;
|
||||||
CFeeRate feeRate = fee_estimator.estimateSmartFee(conf_target, &feeCalc, conservative);
|
CFeeRate feeRate{fee_estimator.estimateSmartFee(conf_target, &feeCalc, conservative)};
|
||||||
|
CFeeRate min_mempool_feerate{mempool.GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000)};
|
||||||
|
CFeeRate min_relay_feerate{::minRelayTxFee};
|
||||||
|
feeRate = std::max({feeRate, min_mempool_feerate, min_relay_feerate});
|
||||||
if (feeRate != CFeeRate(0)) {
|
if (feeRate != CFeeRate(0)) {
|
||||||
result.pushKV("feerate", ValueFromAmount(feeRate.GetFeePerK()));
|
result.pushKV("feerate", ValueFromAmount(feeRate.GetFeePerK()));
|
||||||
} else {
|
} else {
|
||||||
|
@ -135,9 +135,13 @@ def check_smart_estimates(node, fees_seen):
|
|||||||
delta = 1.0e-6 # account for rounding error
|
delta = 1.0e-6 # account for rounding error
|
||||||
last_feerate = float(max(fees_seen))
|
last_feerate = float(max(fees_seen))
|
||||||
all_smart_estimates = [node.estimatesmartfee(i) for i in range(1, 26)]
|
all_smart_estimates = [node.estimatesmartfee(i) for i in range(1, 26)]
|
||||||
|
mempoolMinFee = node.getmempoolinfo()['mempoolminfee']
|
||||||
|
minRelaytxFee = node.getmempoolinfo()['minrelaytxfee']
|
||||||
for i, e in enumerate(all_smart_estimates): # estimate is for i+1
|
for i, e in enumerate(all_smart_estimates): # estimate is for i+1
|
||||||
feerate = float(e["feerate"])
|
feerate = float(e["feerate"])
|
||||||
assert_greater_than(feerate, 0)
|
assert_greater_than(feerate, 0)
|
||||||
|
assert_greater_than_or_equal(feerate, float(mempoolMinFee))
|
||||||
|
assert_greater_than_or_equal(feerate, float(minRelaytxFee))
|
||||||
|
|
||||||
if feerate + delta < min(fees_seen) or feerate - delta > max(fees_seen):
|
if feerate + delta < min(fees_seen) or feerate - delta > max(fees_seen):
|
||||||
raise AssertionError("Estimated fee (%f) out of range (%f,%f)"
|
raise AssertionError("Estimated fee (%f) out of range (%f,%f)"
|
||||||
@ -281,6 +285,13 @@ class EstimateFeeTest(BitcoinTestFramework):
|
|||||||
self.log.info("Final estimates after emptying mempools")
|
self.log.info("Final estimates after emptying mempools")
|
||||||
check_estimates(self.nodes[1], self.fees_per_kb)
|
check_estimates(self.nodes[1], self.fees_per_kb)
|
||||||
|
|
||||||
|
# check that the effective feerate is greater than or equal to the mempoolminfee even for high mempoolminfee
|
||||||
|
self.log.info("Test fee rate estimation after restarting node with high MempoolMinFee")
|
||||||
|
high_val = 3*self.nodes[1].estimatesmartfee(1)['feerate']
|
||||||
|
self.restart_node(1, extra_args=[f'-minrelaytxfee={high_val}'])
|
||||||
|
check_estimates(self.nodes[1], self.fees_per_kb)
|
||||||
|
self.stop_node(1, expected_stderr="Warning: -minrelaytxfee is set very high! The wallet will avoid paying less than the minimum relay fee.")
|
||||||
|
|
||||||
self.log.info("Testing that fee estimation is disabled in blocksonly.")
|
self.log.info("Testing that fee estimation is disabled in blocksonly.")
|
||||||
self.restart_node(0, ["-blocksonly"])
|
self.restart_node(0, ["-blocksonly"])
|
||||||
assert_raises_rpc_error(-32603, "Fee estimation disabled",
|
assert_raises_rpc_error(-32603, "Fee estimation disabled",
|
||||||
|
Loading…
Reference in New Issue
Block a user