diff --git a/doc/release-notes.md b/doc/release-notes.md index 2fb87d3b8..e3fe71ebf 100644 --- a/doc/release-notes.md +++ b/doc/release-notes.md @@ -1,8 +1,12 @@ # Bitcoin ABC 0.22.12 Release Notes Bitcoin ABC version 0.22.12 is now available from: This release includes the following features and fixes: - Add an extra 64 bits of entropy in the initial version message. + - The `setexcessiveblock` RPC is deprecated and will be removed in a future + version. The `-excessiveblocksize` option should be used instead. Use the + `-deprecatedrpc=setexcessiveblock` option to continue using the + `setexcessiveblock` RPC. diff --git a/src/rpc/abc.cpp b/src/rpc/abc.cpp index 8d52d2ddf..0845d9038 100644 --- a/src/rpc/abc.cpp +++ b/src/rpc/abc.cpp @@ -1,96 +1,106 @@ // Copyright (c) 2017-2020 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include #include #include #include #include #include #include #include #include static UniValue getexcessiveblock(const Config &config, const JSONRPCRequest &request) { RPCHelpMan{ "getexcessiveblock", "Return the excessive block size.", {}, RPCResult{RPCResult::Type::NUM, "", "excessive block size in bytes"}, RPCExamples{HelpExampleCli("getexcessiveblock", "") + HelpExampleRpc("getexcessiveblock", "")}, } .Check(request); UniValue ret(UniValue::VOBJ); ret.pushKV("excessiveBlockSize", config.GetMaxBlockSize()); return ret; } static UniValue setexcessiveblock(Config &config, const JSONRPCRequest &request) { RPCHelpMan{ "setexcessiveblock", - "Set the excessive block size. Excessive blocks will not be used in " - "the active chain or relayed. This discourages the propagation of " - "blocks that you consider excessively large.", + "DEPRECATED. Set the excessive block size. Excessive blocks will not " + "be used in the active chain or relayed. This discourages the " + "propagation of blocks that you consider excessively large.", { {"blockSize", RPCArg::Type::NUM, RPCArg::Optional::NO, "Excessive block size in bytes. Must be greater than " + ToString(LEGACY_MAX_BLOCK_SIZE) + "."}, }, RPCResult{RPCResult::Type::NUM, "", "excessive block size in bytes"}, RPCExamples{HelpExampleCli("setexcessiveblock", "25000000") + HelpExampleRpc("setexcessiveblock", "25000000")}, } .Check(request); + if (!IsDeprecatedRPCEnabled(gArgs, "setexcessiveblock")) { + // setexcessiveblock is deprecated in v0.22.12 for removal in v0.23 + throw JSONRPCError( + RPC_METHOD_DEPRECATED, + std::string( + "The setexcessiveblock RPC is deprecated and will be removed " + "in a future version. Use the -deprecatedrpc=setexcessiveblock " + "option to continue using it.")); + } + if (!request.params[0].isNum()) { throw JSONRPCError( RPC_INVALID_PARAMETER, std::string( "Invalid parameter, excessiveblock must be an integer")); } int64_t ebs = request.params[0].get_int64(); // Do not allow maxBlockSize to be set below historic 1MB limit if (ebs <= int64_t(LEGACY_MAX_BLOCK_SIZE)) { throw JSONRPCError( RPC_INVALID_PARAMETER, std::string( "Invalid parameter, excessiveblock must be larger than ") + ToString(LEGACY_MAX_BLOCK_SIZE)); } // Set the new max block size. { LOCK(cs_main); if (!config.SetMaxBlockSize(ebs)) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Unexpected error"); } } // settingsToUserAgentString(); std::ostringstream ret; ret << "Excessive Block set to " << ebs << " bytes."; return UniValue(ret.str()); } void RegisterABCRPCCommands(CRPCTable &t) { // clang-format off static const CRPCCommand commands[] = { // category name actor (function) argNames // ------------------- ------------------------ ---------------------- ---------- { "network", "getexcessiveblock", getexcessiveblock, {}}, { "network", "setexcessiveblock", setexcessiveblock, {"maxBlockSize"}}, }; // clang-format on for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) { t.appendCommand(commands[vcidx].name, &commands[vcidx]); } } diff --git a/src/test/excessiveblock_tests.cpp b/src/test/excessiveblock_tests.cpp index 1cf26edc4..2f68d9ba0 100644 --- a/src/test/excessiveblock_tests.cpp +++ b/src/test/excessiveblock_tests.cpp @@ -1,77 +1,81 @@ // Copyright (c) 2017-2020 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include #include #include #include #include #include #include #include #include extern UniValue CallRPC(const std::string &args, const util::Ref &context); class ExcessiveBlockTestingSetup : public TestingSetup { public: + ExcessiveBlockTestingSetup() + : TestingSetup(CBaseChainParams::MAIN, + {"-deprecatedrpc=setexcessiveblock"}){}; + UniValue CallRPC(const std::string &args) { const util::Ref context{m_node}; return ::CallRPC(args, context); } }; BOOST_FIXTURE_TEST_SUITE(excessiveblock_tests, ExcessiveBlockTestingSetup) BOOST_AUTO_TEST_CASE(excessiveblock_rpc) { BOOST_CHECK_NO_THROW(CallRPC("getexcessiveblock")); BOOST_CHECK_THROW(CallRPC("setexcessiveblock"), std::runtime_error); BOOST_CHECK_THROW(CallRPC("setexcessiveblock not_uint"), std::runtime_error); BOOST_CHECK_THROW(CallRPC("setexcessiveblock 1000000 not_uint"), std::runtime_error); BOOST_CHECK_THROW(CallRPC("setexcessiveblock 1000000 1"), std::runtime_error); BOOST_CHECK_THROW(CallRPC("setexcessiveblock -1"), std::runtime_error); BOOST_CHECK_THROW(CallRPC("setexcessiveblock 0"), std::runtime_error); BOOST_CHECK_THROW(CallRPC("setexcessiveblock 1"), std::runtime_error); BOOST_CHECK_THROW(CallRPC("setexcessiveblock 1000"), std::runtime_error); BOOST_CHECK_THROW( CallRPC(std::string("setexcessiveblock ") + ToString(ONE_MEGABYTE - 1)), std::runtime_error); BOOST_CHECK_THROW( CallRPC(std::string("setexcessiveblock ") + ToString(ONE_MEGABYTE)), std::runtime_error); BOOST_CHECK_NO_THROW(CallRPC(std::string("setexcessiveblock ") + ToString(ONE_MEGABYTE + 1))); BOOST_CHECK_NO_THROW(CallRPC(std::string("setexcessiveblock ") + ToString(ONE_MEGABYTE + 10))); // Default can be higher than 1MB in future - test it too BOOST_CHECK_NO_THROW(CallRPC(std::string("setexcessiveblock ") + ToString(DEFAULT_MAX_BLOCK_SIZE))); BOOST_CHECK_NO_THROW(CallRPC(std::string("setexcessiveblock ") + ToString(DEFAULT_MAX_BLOCK_SIZE * 8))); BOOST_CHECK_NO_THROW( CallRPC(std::string("setexcessiveblock ") + ToString(std::numeric_limits::max()))); BOOST_CHECK_THROW( CallRPC(std::string("setexcessiveblock ") + ToString(uint64_t(std::numeric_limits::max()) + 1)), std::runtime_error); BOOST_CHECK_THROW(CallRPC(std::string("setexcessiveblock ") + ToString(std::numeric_limits::max())), std::runtime_error); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/functional/abc_rpc_excessiveblock.py b/test/functional/abc_rpc_excessiveblock.py index 997177051..30b14b53b 100755 --- a/test/functional/abc_rpc_excessiveblock.py +++ b/test/functional/abc_rpc_excessiveblock.py @@ -1,92 +1,92 @@ #!/usr/bin/env python3 # Copyright (c) 2017 The Bitcoin developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. # Exercise the Bitcoin ABC RPC calls. import re from test_framework.cdefs import ( DEFAULT_MAX_BLOCK_SIZE, LEGACY_MAX_BLOCK_SIZE, ONE_MEGABYTE, ) from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal, assert_raises_rpc_error BLOCKSIZE_TOO_LOW = "Invalid parameter, excessiveblock must be larger than {}".format( LEGACY_MAX_BLOCK_SIZE) class ExcessiveBlockSizeRPCTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 1 self.tip = None self.setup_clean_chain = True + self.extra_args = [["-deprecatedrpc=setexcessiveblock"]] def check_subversion(self, pattern_str): # Check that the subversion is set as expected netinfo = self.nodes[0].getnetworkinfo() subversion = netinfo['subversion'] pattern = re.compile(pattern_str) assert pattern.match(subversion) def test_excessiveblock(self): # Check that we start with DEFAULT_MAX_BLOCK_SIZE getsize = self.nodes[0].getexcessiveblock() ebs = getsize['excessiveBlockSize'] assert_equal(ebs, DEFAULT_MAX_BLOCK_SIZE) # Check that setting to legacy size is ok self.nodes[0].setexcessiveblock(LEGACY_MAX_BLOCK_SIZE + 1) getsize = self.nodes[0].getexcessiveblock() ebs = getsize['excessiveBlockSize'] assert_equal(ebs, LEGACY_MAX_BLOCK_SIZE + 1) # Check that going below legacy size is not accepted assert_raises_rpc_error(-8, BLOCKSIZE_TOO_LOW, self.nodes[0].setexcessiveblock, LEGACY_MAX_BLOCK_SIZE) getsize = self.nodes[0].getexcessiveblock() ebs = getsize['excessiveBlockSize'] assert_equal(ebs, LEGACY_MAX_BLOCK_SIZE + 1) # Check that a negative size returns an error assert_raises_rpc_error(-8, BLOCKSIZE_TOO_LOW, self.nodes[0].setexcessiveblock, -2 * LEGACY_MAX_BLOCK_SIZE) getsize = self.nodes[0].getexcessiveblock() ebs = getsize['excessiveBlockSize'] assert_equal(ebs, LEGACY_MAX_BLOCK_SIZE + 1) # Check setting to 2MB self.nodes[0].setexcessiveblock(2 * ONE_MEGABYTE) getsize = self.nodes[0].getexcessiveblock() ebs = getsize['excessiveBlockSize'] assert_equal(ebs, 2 * ONE_MEGABYTE) # Check for EB correctness in the subver string self.check_subversion(r"/Bitcoin ABC:.*\(EB2\.0; .*\)/") # Check setting to 13MB self.nodes[0].setexcessiveblock(13 * ONE_MEGABYTE) getsize = self.nodes[0].getexcessiveblock() ebs = getsize['excessiveBlockSize'] assert_equal(ebs, 13 * ONE_MEGABYTE) # Check for EB correctness in the subver string self.check_subversion(r"/Bitcoin ABC:.*\(EB13\.0; .*\)/") # Check setting to 13.14MB self.nodes[0].setexcessiveblock(13140000) getsize = self.nodes[0].getexcessiveblock() ebs = getsize['excessiveBlockSize'] assert_equal(ebs, 13.14 * ONE_MEGABYTE) # check for EB correctness in the subver string self.check_subversion(r"/Bitcoin ABC:.*\(EB13\.1; .*\)/") def run_test(self): - self.genesis_hash = int(self.nodes[0].getbestblockhash(), 16) self.test_excessiveblock() if __name__ == '__main__': ExcessiveBlockSizeRPCTest().main() diff --git a/test/functional/rpc_deprecated.py b/test/functional/rpc_deprecated.py index e62249b72..4f918ff5c 100755 --- a/test/functional/rpc_deprecated.py +++ b/test/functional/rpc_deprecated.py @@ -1,33 +1,43 @@ #!/usr/bin/env python3 # Copyright (c) 2017-2019 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.cdefs import DEFAULT_MAX_BLOCK_SIZE from test_framework.test_framework import BitcoinTestFramework +from test_framework.util import assert_raises_rpc_error class DeprecatedRpcTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 2 self.setup_clean_chain = True - self.extra_args = [[], ["-deprecatedrpc=banscore"]] + self.extra_args = [[], ["-deprecatedrpc=banscore", + "-deprecatedrpc=setexcessiveblock"]] def run_test(self): # This test should be used to verify correct behaviour of deprecated # RPC methods with and without the -deprecatedrpc flags. For example: # # In set_test_params: # self.extra_args = [[], ["-deprecatedrpc=generate"]] # # In run_test: # self.log.info("Test generate RPC") # assert_raises_rpc_error(-32, 'The wallet generate rpc method is deprecated', self.nodes[0].rpc.generate, 1) # self.nodes[1].generate(1) self.log.info("Test deprecated banscore") assert 'banscore' not in self.nodes[0].getpeerinfo()[0] assert 'banscore' in self.nodes[1].getpeerinfo()[0] + self.log.info("Test deprecated setexcessiveblock RPC") + assert_raises_rpc_error(-32, + 'The setexcessiveblock RPC is deprecated', + self.nodes[0].setexcessiveblock, + DEFAULT_MAX_BLOCK_SIZE) + self.nodes[1].setexcessiveblock(DEFAULT_MAX_BLOCK_SIZE) + if __name__ == '__main__': DeprecatedRpcTest().main()