diff --git a/doc/release-notes.md b/doc/release-notes.md --- a/doc/release-notes.md +++ b/doc/release-notes.md @@ -4,4 +4,5 @@ This release includes the following features and fixes: - Add `signrawtransactionwithkey` and `signrawtransactionwithwallet` RPCs. - These are specialized subsets of the `signrawtransaction` RPC. \ No newline at end of file + These are specialized subsets of the `signrawtransaction` RPC. + - Deprecate `nblocks` parameter in `estimatefee`. See `bitcoin-cli help estimatefee` for more info. Use `-deprecatedrpc=estimatefee` to temporarily re-enable the old behavior while you migrate. diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -774,36 +774,29 @@ static UniValue estimatefee(const Config &config, const JSONRPCRequest &request) { - if (request.fHelp || request.params.size() != 1) { + if (request.fHelp || request.params.size() > 1) { throw std::runtime_error( - "estimatefee nblocks\n" + "estimatefee\n" "\nEstimates the approximate fee per kilobyte needed for a " - "transaction to begin\n" - "confirmation within nblocks blocks.\n" - "\nArguments:\n" - "1. nblocks (numeric, required)\n" + "transaction\n" "\nResult:\n" "n (numeric) estimated fee-per-kilobyte\n" - "\n" - "A negative value is returned if not enough transactions and " - "blocks\n" - "have been observed to make an estimate.\n" - "-1 is always returned for nblocks == 1 as it is impossible to " - "calculate\n" - "a fee that is high enough to get reliably included in the next " - "block.\n" "\nExample:\n" + - HelpExampleCli("estimatefee", "6")); + HelpExampleCli("estimatefee", "")); } - RPCTypeCheck(request.params, {UniValue::VNUM}); - - CFeeRate feeRate = g_mempool.estimateFee(); - if (feeRate == CFeeRate(Amount::zero())) { - return -1.0; + if ((request.params.size() == 1) && + !IsDeprecatedRPCEnabled(gArgs, "estimatefee")) { + // FIXME: Remove this message in 0.20 + throw JSONRPCError( + RPC_METHOD_DEPRECATED, + "estimatefee with the nblocks argument is no longer supported\n" + "Please call estimatefee with no arguments instead.\n" + "\nExample:\n" + + HelpExampleCli("estimatefee", "")); } - return ValueFromAmount(feeRate.GetFeePerK()); + return ValueFromAmount(g_mempool.estimateFee().GetFeePerK()); } // clang-format off diff --git a/test/functional/rpc_estimatefee.py b/test/functional/rpc_estimatefee.py --- a/test/functional/rpc_estimatefee.py +++ b/test/functional/rpc_estimatefee.py @@ -6,27 +6,40 @@ from decimal import Decimal from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal +from test_framework.util import assert_equal, assert_raises_rpc_error class EstimateFeeTest(BitcoinTestFramework): def set_test_params(self): self.setup_clean_chain = True - self.num_nodes = 2 - self.extra_args = [[], ["-minrelaytxfee=0.001"]] + self.num_nodes = 3 + self.extra_args = [[], ["-minrelaytxfee=0.001"], + ["-deprecatedrpc=estimatefee"]] def run_test(self): + default_node = self.nodes[0] + diff_relay_fee_node = self.nodes[1] + deprecated_node = self.nodes[2] for i in range(5): self.nodes[0].generate(1) # estimatefee is 0.00001 by default, regardless of block contents - assert_equal(self.nodes[0].estimatefee(i), Decimal('0.00001')) - # Also test named arguments - assert_equal(self.nodes[0].estimatefee( - nblocks=i), Decimal('0.00001')) + assert_equal(default_node.estimatefee(), Decimal('0.00001')) + assert_equal(deprecated_node.estimatefee(), Decimal('0.00001')) # estimatefee may be different for nodes that set it in their config - assert_equal(self.nodes[1].estimatefee(i), Decimal('0.001')) + assert_equal(diff_relay_fee_node.estimatefee(), Decimal('0.001')) + + # nblocks arg is no longer supported. Make sure the error message + # indicates this. + assert_raises_rpc_error(-32, "estimatefee with the nblocks argument is no longer supported", + default_node.estimatefee, 1) + + # When marked as deprecated, estimatfee with nblocks set succeeds + assert_equal(deprecated_node.estimatefee(1), Decimal('0.00001')) + # Also test named arguments + assert_equal(deprecated_node.estimatefee( + nblocks=1), Decimal('0.00001')) if __name__ == '__main__':