From d4cdbd6fb6ac3663d069307c4fd0078f4ecf0245 Mon Sep 17 00:00:00 2001 From: John Newbery Date: Fri, 11 Aug 2017 11:25:06 -0400 Subject: [PATCH 1/2] [rpc] Deprecate estimatefee RPC Deprecate estimatefee in v0.16, for final removal in v0.17. This commit introduces a phased removal of RPC methods. RPC method is disabled by default in version x, but can be enabled by using the `-deprecatedrpc=` argument. RPC method is removed entirely in version (x+1). --- src/init.cpp | 1 + src/rpc/mining.cpp | 6 ++++++ src/rpc/protocol.h | 1 + src/rpc/server.cpp | 7 +++++++ src/rpc/server.h | 2 ++ test/functional/smartfees.py | 2 +- 6 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index a997f9740c9a7..a1c49a0992b48 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -430,6 +430,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-checkmempool=", strprintf("Run checks every transactions (default: %u)", defaultChainParams->DefaultConsistencyChecks())); strUsage += HelpMessageOpt("-checkpoints", strprintf("Disable expensive verification for known chain history (default: %u)", DEFAULT_CHECKPOINTS_ENABLED)); strUsage += HelpMessageOpt("-disablesafemode", strprintf("Disable safemode, override a real safe mode event (default: %u)", DEFAULT_DISABLE_SAFEMODE)); + strUsage += HelpMessageOpt("-deprecatedrpc=", "Allows deprecated RPC method(s) to be used"); strUsage += HelpMessageOpt("-testsafemode", strprintf("Force safe mode (default: %u)", DEFAULT_TESTSAFEMODE)); strUsage += HelpMessageOpt("-dropmessagestest=", "Randomly drop 1 of every network messages"); strUsage += HelpMessageOpt("-fuzzmessagestest=", "Randomly fuzz 1 of every network messages"); diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index f0ffa07e12de5..5ac32dc9742a5 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -789,6 +789,12 @@ UniValue estimatefee(const JSONRPCRequest& request) + HelpExampleCli("estimatefee", "6") ); + if (!IsDeprecatedRPCEnabled("estimatefee")) { + throw JSONRPCError(RPC_METHOD_DEPRECATED, "estimatefee is deprecated and will be fully removed in v0.17. " + "To use estimatefee in v0.16, restart bitcoind with -deprecatedrpc=estimatefee.\n" + "Projects should transition to using estimatesmartfee before upgrading to v0.17"); + } + RPCTypeCheck(request.params, {UniValue::VNUM}); int nBlocks = request.params[0].get_int(); diff --git a/src/rpc/protocol.h b/src/rpc/protocol.h index 5c9c64f67d1ce..056f93e7dbaa6 100644 --- a/src/rpc/protocol.h +++ b/src/rpc/protocol.h @@ -57,6 +57,7 @@ enum RPCErrorCode RPC_VERIFY_REJECTED = -26, //!< Transaction or block was rejected by network rules RPC_VERIFY_ALREADY_IN_CHAIN = -27, //!< Transaction already in chain RPC_IN_WARMUP = -28, //!< Client still warming up + RPC_METHOD_DEPRECATED = -32, //!< RPC method is deprecated //! Aliases for backward compatibility RPC_TRANSACTION_ERROR = RPC_VERIFY_ERROR, diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 428ab3b9b0eda..a73b697e01e0b 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -382,6 +382,13 @@ void JSONRPCRequest::parse(const UniValue& valRequest) throw JSONRPCError(RPC_INVALID_REQUEST, "Params must be an array or object"); } +bool IsDeprecatedRPCEnabled(const std::string& method) +{ + const std::vector enabled_methods = gArgs.GetArgs("-deprecatedrpc"); + + return find(enabled_methods.begin(), enabled_methods.end(), method) != enabled_methods.end(); +} + static UniValue JSONRPCExecOne(const UniValue& req) { UniValue rpc_result(UniValue::VOBJ); diff --git a/src/rpc/server.h b/src/rpc/server.h index 777acbcb9417b..31d630427104b 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -171,6 +171,8 @@ class CRPCTable bool appendCommand(const std::string& name, const CRPCCommand* pcmd); }; +bool IsDeprecatedRPCEnabled(const std::string& method); + extern CRPCTable tableRPC; /** diff --git a/test/functional/smartfees.py b/test/functional/smartfees.py index 76632fc57848a..986f4546a8b75 100755 --- a/test/functional/smartfees.py +++ b/test/functional/smartfees.py @@ -151,7 +151,7 @@ def setup_network(self): which we will use to generate our transactions. """ self.add_nodes(3, extra_args=[["-maxorphantx=1000", "-whitelist=127.0.0.1"], - ["-blockmaxsize=17000", "-maxorphantx=1000"], + ["-blockmaxsize=17000", "-maxorphantx=1000", "-deprecatedrpc=estimatefee"], ["-blockmaxsize=8000", "-maxorphantx=1000"]]) # Use node0 to mine blocks for input splitting # Node1 mines small blocks but that are bigger than the expected transaction rate. From 048e0c3e26051e66e027a84128923ea341d5337b Mon Sep 17 00:00:00 2001 From: Cristian Mircea Messel Date: Wed, 23 Aug 2017 17:58:59 +0300 Subject: [PATCH 2/2] [rpc] [tests] Add deprecated RPC test --- test/functional/deprecated_rpc.py | 23 +++++++++++++++++++++++ test/functional/test_runner.py | 1 + 2 files changed, 24 insertions(+) create mode 100755 test/functional/deprecated_rpc.py diff --git a/test/functional/deprecated_rpc.py b/test/functional/deprecated_rpc.py new file mode 100755 index 0000000000000..ec500ccbf9673 --- /dev/null +++ b/test/functional/deprecated_rpc.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +# Copyright (c) 2017 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. +"""Test deprecation of RPC calls.""" +from test_framework.test_framework import BitcoinTestFramework +from test_framework.util import assert_raises_jsonrpc + +class DeprecatedRpcTest(BitcoinTestFramework): + def set_test_params(self): + self.num_nodes = 2 + self.setup_clean_chain = True + self.extra_args = [[], ["-deprecatedrpc=estimatefee"]] + + def run_test(self): + self.log.info("estimatefee: Shows deprecated message") + assert_raises_jsonrpc(-32, 'estimatefee is deprecated', self.nodes[0].estimatefee, 1) + + self.log.info("Using -deprecatedrpc=estimatefee bypasses the error") + self.nodes[1].estimatefee(1) + +if __name__ == '__main__': + DeprecatedRpcTest().main() diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py index 8dbe6247ee5ed..5c8740d7cdc39 100755 --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -98,6 +98,7 @@ 'disconnect_ban.py', 'decodescript.py', 'blockchain.py', + 'deprecated_rpc.py', 'disablewallet.py', 'net.py', 'keypool.py',