diff --git a/doc/release-notes.md b/doc/release-notes.md --- a/doc/release-notes.md +++ b/doc/release-notes.md @@ -5,3 +5,14 @@ This release includes the following features and fixes: - Upgrade minimum supported boost version to 1.59 +Deprecated or removed RPCs +-------------------------- +- The wallet's `generate` RPC method was deprecated in v0.21.5 and has now + been fully removed. This RPC is only used for + testing, but its implementation reached across multiple subsystems + (wallet and mining), so it has been removed to simplify the + wallet-node interface. Projects that are using `generate` for testing + purposes should transition to using the `generatetoaddress` RPC, which + does not require or use the wallet component. Calling + `generatetoaddress` with an address returned by the `getnewaddress` + RPC gives the same functionality as the old `generate` RPC. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -447,7 +447,7 @@ warnings.cpp ) -target_link_libraries(common util secp256k1) +target_link_libraries(common util secp256k1 script) # script library add_library(script diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -25,8 +25,6 @@ static const CRPCConvertParam vRPCConvertParams[] = { {"setmocktime", 0, "timestamp"}, {"mockscheduler", 0, "delta_time"}, - {"generate", 0, "nblocks"}, - {"generate", 1, "maxtries"}, {"utxoupdatepsbt", 1, "descriptors"}, {"generatetoaddress", 0, "nblocks"}, {"generatetoaddress", 2, "maxtries"}, diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -3856,64 +3855,6 @@ request.params[2]); } -UniValue generate(const Config &config, const JSONRPCRequest &request) { - std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); - CWallet *const pwallet = wallet.get(); - - if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) { - return NullUniValue; - } - - RPCHelpMan{ - "generate", - "\nMine up to nblocks blocks immediately (before the RPC call returns) " - "to an address in the wallet.\n", - { - {"nblocks", RPCArg::Type::NUM, RPCArg::Optional::NO, - "How many blocks are generated immediately."}, - {"maxtries", RPCArg::Type::NUM, /* default */ "1000000", - "How many iterations to try."}, - }, - RPCResult{"[ blockhashes ] (array) hashes of blocks generated\n"}, - RPCExamples{"\nGenerate 11 blocks\n" + - HelpExampleCli("generate", "11")}} - .Check(request); - - if (!IsDeprecatedRPCEnabled(gArgs, "generate")) { - throw JSONRPCError(RPC_METHOD_DEPRECATED, - "The wallet generate rpc method is deprecated and " - "will be fully removed in v0.22. " - "To use generate in v0.21, restart bitcoind with " - "-deprecatedrpc=generate.\n" - "Clients should transition to using the node rpc " - "method generatetoaddress\n"); - } - - int num_generate = request.params[0].get_int(); - uint64_t max_tries = 1000000; - if (!request.params[1].isNull()) { - max_tries = request.params[1].get_int(); - } - - std::shared_ptr coinbase_script; - pwallet->GetScriptForMining(coinbase_script); - - // If the keypool is exhausted, no script is returned at all. Catch this. - if (!coinbase_script) { - throw JSONRPCError( - RPC_WALLET_KEYPOOL_RAN_OUT, - "Error: Keypool ran out, please call keypoolrefill first"); - } - - // throw an error if no script was provided - if (coinbase_script->reserveScript.empty()) { - throw JSONRPCError(RPC_INTERNAL_ERROR, "No coinbase script available"); - } - - return generateBlocks(config, coinbase_script, num_generate, max_tries, - true); -} - UniValue rescanblockchain(const Config &config, const JSONRPCRequest &request) { std::shared_ptr const wallet = GetWalletForJSONRPCRequest(request); CWallet *const pwallet = wallet.get(); @@ -4754,7 +4695,6 @@ static const CRPCCommand commands[] = { // category name actor (function) argNames // ------------------- ------------------------ ---------------------- ---------- - { "generating", "generate", generate, {"nblocks","maxtries"} }, { "rawtransactions", "fundrawtransaction", fundrawtransaction, {"hexstring","options"} }, { "wallet", "abandontransaction", abandontransaction, {"txid"} }, { "wallet", "addmultisigaddress", addmultisigaddress, {"nrequired","keys","label"} }, diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1427,8 +1427,6 @@ const std::string &GetLabelName(const CScript &scriptPubKey) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet); - void GetScriptForMining(std::shared_ptr &script); - unsigned int GetKeyPoolSize() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { // set{Ex,In}ternalKeyPool AssertLockHeld(cs_wallet); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4382,17 +4382,6 @@ } } -void CWallet::GetScriptForMining(std::shared_ptr &script) { - std::shared_ptr rKey = std::make_shared(this); - CPubKey pubkey; - if (!rKey->GetReservedKey(pubkey)) { - return; - } - - script = rKey; - script->reserveScript = CScript() << ToByteVector(pubkey) << OP_CHECKSIG; -} - void CWallet::LockCoin(const COutPoint &output) { // setLockedCoins AssertLockHeld(cs_wallet); diff --git a/test/functional/rpc_deprecated.py b/test/functional/rpc_deprecated.py --- a/test/functional/rpc_deprecated.py +++ b/test/functional/rpc_deprecated.py @@ -4,32 +4,27 @@ # 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_rpc_error +# 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=generate"]] - - def skip_test_if_missing_module(self): - # The generate RPC method requires the wallet to be compiled - self.skip_if_no_wallet() + self.extra_args = [[], []] 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: # - # self.log.info("Make sure that -deprecatedrpc=createmultisig allows it to take addresses") - # assert_raises_rpc_error(-5, "Invalid public key", self.nodes[0].createmultisig, 1, [self.nodes[0].getnewaddress()]) - # self.nodes[1].createmultisig(1, [self.nodes[1].getnewaddress()]) - 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) + # 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("No tested deprecated RPC methods") if __name__ == '__main__':