Skip to content

Commit 9e3122d

Browse files
author
MarcoFalke
committed
Merge #15492: [rpc] remove deprecated generate method
07cae52 [wallet] remove unused GetScriptForMining (Sjors Provoost) 8bb3e4c [rpc] remove deprecated generate method (Sjors Provoost) Pull request description: As announced in v0.18, the wallet generate rpc method is deprecated and will be fully removed in v0.19. Clients should transition to using the node rpc method `generatetoaddress`. Tree-SHA512: 9e5e913b59f3e18440b2b7b356124c7b87ad19f81a1ab6ada06a6c396b84e734895465f569296f1ba8c12abf74863bab5fd77765c9e806c239713aa83a59485f
2 parents e47d8a1 + 07cae52 commit 9e3122d

File tree

6 files changed

+21
-86
lines changed

6 files changed

+21
-86
lines changed

doc/release-notes-15492.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Deprecated or removed RPCs
2+
--------------------------
3+
- The wallet's `generate` RPC method was deprecated in v0.18 and has now
4+
been fully removed. This RPC is only used for
5+
testing, but its implementation reached across multiple subsystems
6+
(wallet and mining), so it has been removed to simplify the
7+
wallet-node interface. Projects that are using `generate` for testing
8+
purposes should transition to using the `generatetoaddress` RPC, which
9+
does not require or use the wallet component. Calling
10+
`generatetoaddress` with an address returned by the `getnewaddress`
11+
RPC gives the same functionality as the old `generate` RPC.

src/rpc/client.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ class CRPCConvertParam
2828
static const CRPCConvertParam vRPCConvertParams[] =
2929
{
3030
{ "setmocktime", 0, "timestamp" },
31-
{ "generate", 0, "nblocks" },
32-
{ "generate", 1, "maxtries" },
3331
{ "generatetoaddress", 0, "nblocks" },
3432
{ "generatetoaddress", 2, "maxtries" },
3533
{ "getnetworkhashps", 0, "nblocks" },

src/wallet/rpcwallet.cpp

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <policy/fees.h>
2020
#include <policy/policy.h>
2121
#include <policy/rbf.h>
22-
#include <rpc/mining.h>
2322
#include <rpc/rawtransaction.h>
2423
#include <rpc/server.h>
2524
#include <rpc/util.h>
@@ -3358,62 +3357,6 @@ static UniValue bumpfee(const JSONRPCRequest& request)
33583357
return result;
33593358
}
33603359

3361-
UniValue generate(const JSONRPCRequest& request)
3362-
{
3363-
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
3364-
CWallet* const pwallet = wallet.get();
3365-
3366-
3367-
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
3368-
return NullUniValue;
3369-
}
3370-
3371-
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) {
3372-
throw std::runtime_error(
3373-
RPCHelpMan{"generate",
3374-
"\nMine up to nblocks blocks immediately (before the RPC call returns) to an address in the wallet.\n",
3375-
{
3376-
{"nblocks", RPCArg::Type::NUM, RPCArg::Optional::NO, "How many blocks are generated immediately."},
3377-
{"maxtries", RPCArg::Type::NUM, /* default */ "1000000", "How many iterations to try."},
3378-
},
3379-
RPCResult{
3380-
"[ blockhashes ] (array) hashes of blocks generated\n"
3381-
},
3382-
RPCExamples{
3383-
"\nGenerate 11 blocks\n"
3384-
+ HelpExampleCli("generate", "11")
3385-
},
3386-
}.ToString());
3387-
}
3388-
3389-
if (!IsDeprecatedRPCEnabled("generate")) {
3390-
throw JSONRPCError(RPC_METHOD_DEPRECATED, "The wallet generate rpc method is deprecated and will be fully removed in v0.19. "
3391-
"To use generate in v0.18, restart bitcoind with -deprecatedrpc=generate.\n"
3392-
"Clients should transition to using the node rpc method generatetoaddress\n");
3393-
}
3394-
3395-
int num_generate = request.params[0].get_int();
3396-
uint64_t max_tries = 1000000;
3397-
if (!request.params[1].isNull()) {
3398-
max_tries = request.params[1].get_int();
3399-
}
3400-
3401-
std::shared_ptr<CReserveScript> coinbase_script;
3402-
pwallet->GetScriptForMining(coinbase_script);
3403-
3404-
// If the keypool is exhausted, no script is returned at all. Catch this.
3405-
if (!coinbase_script) {
3406-
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
3407-
}
3408-
3409-
//throw an error if no script was provided
3410-
if (coinbase_script->reserveScript.empty()) {
3411-
throw JSONRPCError(RPC_INTERNAL_ERROR, "No coinbase script available");
3412-
}
3413-
3414-
return generateBlocks(coinbase_script, num_generate, max_tries, true);
3415-
}
3416-
34173360
UniValue rescanblockchain(const JSONRPCRequest& request)
34183361
{
34193362
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
@@ -4156,7 +4099,6 @@ UniValue importmulti(const JSONRPCRequest& request);
41564099
static const CRPCCommand commands[] =
41574100
{ // category name actor (function) argNames
41584101
// --------------------- ------------------------ ----------------------- ----------
4159-
{ "generating", "generate", &generate, {"nblocks","maxtries"} },
41604102
{ "hidden", "resendwallettransactions", &resendwallettransactions, {} },
41614103
{ "rawtransactions", "fundrawtransaction", &fundrawtransaction, {"hexstring","options","iswitness"} },
41624104
{ "wallet", "abandontransaction", &abandontransaction, {"txid"} },

src/wallet/wallet.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3819,17 +3819,6 @@ void CWallet::MarkReserveKeysAsUsed(int64_t keypool_id)
38193819
}
38203820
}
38213821

3822-
void CWallet::GetScriptForMining(std::shared_ptr<CReserveScript> &script)
3823-
{
3824-
std::shared_ptr<CReserveKey> rKey = std::make_shared<CReserveKey>(this);
3825-
CPubKey pubkey;
3826-
if (!rKey->GetReservedKey(pubkey))
3827-
return;
3828-
3829-
script = rKey;
3830-
script->reserveScript = CScript() << ToByteVector(pubkey) << OP_CHECKSIG;
3831-
}
3832-
38333822
void CWallet::LockCoin(const COutPoint& output)
38343823
{
38353824
AssertLockHeld(cs_wallet); // setLockedCoins

src/wallet/wallet.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,8 +1065,6 @@ class CWallet final : public CCryptoKeyStore, public CValidationInterface
10651065

10661066
const std::string& GetLabelName(const CScript& scriptPubKey) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
10671067

1068-
void GetScriptForMining(std::shared_ptr<CReserveScript> &script);
1069-
10701068
unsigned int GetKeyPoolSize() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
10711069
{
10721070
AssertLockHeld(cs_wallet); // set{Ex,In}ternalKeyPool

test/functional/rpc_deprecated.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,26 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test deprecation of RPC calls."""
66
from test_framework.test_framework import BitcoinTestFramework
7-
from test_framework.util import assert_raises_rpc_error
7+
# from test_framework.util import assert_raises_rpc_error
88

99
class DeprecatedRpcTest(BitcoinTestFramework):
1010
def set_test_params(self):
1111
self.num_nodes = 2
1212
self.setup_clean_chain = True
13-
self.extra_args = [[], ["-deprecatedrpc=generate"]]
14-
15-
def skip_test_if_missing_module(self):
16-
# The generate RPC method requires the wallet to be compiled
17-
self.skip_if_no_wallet()
13+
self.extra_args = [[], []]
1814

1915
def run_test(self):
2016
# This test should be used to verify correct behaviour of deprecated
2117
# RPC methods with and without the -deprecatedrpc flags. For example:
2218
#
23-
# self.log.info("Make sure that -deprecatedrpc=createmultisig allows it to take addresses")
24-
# assert_raises_rpc_error(-5, "Invalid public key", self.nodes[0].createmultisig, 1, [self.nodes[0].getnewaddress()])
25-
# self.nodes[1].createmultisig(1, [self.nodes[1].getnewaddress()])
26-
27-
self.log.info("Test generate RPC")
28-
assert_raises_rpc_error(-32, 'The wallet generate rpc method is deprecated', self.nodes[0].rpc.generate, 1)
29-
self.nodes[1].generate(1)
19+
# In set_test_params:
20+
# self.extra_args = [[], ["-deprecatedrpc=generate"]]
21+
#
22+
# In run_test:
23+
# self.log.info("Test generate RPC")
24+
# assert_raises_rpc_error(-32, 'The wallet generate rpc method is deprecated', self.nodes[0].rpc.generate, 1)
25+
# self.nodes[1].generate(1)
26+
self.log.info("No tested deprecated RPC methods")
3027

3128
if __name__ == '__main__':
3229
DeprecatedRpcTest().main()

0 commit comments

Comments
 (0)