[rpc] remove deprecated generate method
This commit is contained in:
parent
d88f7f8764
commit
8bb3e4c487
4 changed files with 21 additions and 73 deletions
11
doc/release-notes-15492.md
Normal file
11
doc/release-notes-15492.md
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
Deprecated or removed RPCs
|
||||||
|
--------------------------
|
||||||
|
- The wallet's `generate` RPC method was deprecated in v0.18 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.
|
|
@ -28,8 +28,6 @@ public:
|
||||||
static const CRPCConvertParam vRPCConvertParams[] =
|
static const CRPCConvertParam vRPCConvertParams[] =
|
||||||
{
|
{
|
||||||
{ "setmocktime", 0, "timestamp" },
|
{ "setmocktime", 0, "timestamp" },
|
||||||
{ "generate", 0, "nblocks" },
|
|
||||||
{ "generate", 1, "maxtries" },
|
|
||||||
{ "generatetoaddress", 0, "nblocks" },
|
{ "generatetoaddress", 0, "nblocks" },
|
||||||
{ "generatetoaddress", 2, "maxtries" },
|
{ "generatetoaddress", 2, "maxtries" },
|
||||||
{ "getnetworkhashps", 0, "nblocks" },
|
{ "getnetworkhashps", 0, "nblocks" },
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
#include <policy/fees.h>
|
#include <policy/fees.h>
|
||||||
#include <policy/policy.h>
|
#include <policy/policy.h>
|
||||||
#include <policy/rbf.h>
|
#include <policy/rbf.h>
|
||||||
#include <rpc/mining.h>
|
|
||||||
#include <rpc/rawtransaction.h>
|
#include <rpc/rawtransaction.h>
|
||||||
#include <rpc/server.h>
|
#include <rpc/server.h>
|
||||||
#include <rpc/util.h>
|
#include <rpc/util.h>
|
||||||
|
@ -3358,62 +3357,6 @@ static UniValue bumpfee(const JSONRPCRequest& request)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue generate(const JSONRPCRequest& request)
|
|
||||||
{
|
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
|
||||||
CWallet* const pwallet = wallet.get();
|
|
||||||
|
|
||||||
|
|
||||||
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
|
|
||||||
return NullUniValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) {
|
|
||||||
throw std::runtime_error(
|
|
||||||
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")
|
|
||||||
},
|
|
||||||
}.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!IsDeprecatedRPCEnabled("generate")) {
|
|
||||||
throw JSONRPCError(RPC_METHOD_DEPRECATED, "The wallet generate rpc method is deprecated and will be fully removed in v0.19. "
|
|
||||||
"To use generate in v0.18, 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<CReserveScript> 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(coinbase_script, num_generate, max_tries, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
UniValue rescanblockchain(const JSONRPCRequest& request)
|
UniValue rescanblockchain(const JSONRPCRequest& request)
|
||||||
{
|
{
|
||||||
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
|
||||||
|
@ -4156,7 +4099,6 @@ UniValue importmulti(const JSONRPCRequest& request);
|
||||||
static const CRPCCommand commands[] =
|
static const CRPCCommand commands[] =
|
||||||
{ // category name actor (function) argNames
|
{ // category name actor (function) argNames
|
||||||
// --------------------- ------------------------ ----------------------- ----------
|
// --------------------- ------------------------ ----------------------- ----------
|
||||||
{ "generating", "generate", &generate, {"nblocks","maxtries"} },
|
|
||||||
{ "hidden", "resendwallettransactions", &resendwallettransactions, {} },
|
{ "hidden", "resendwallettransactions", &resendwallettransactions, {} },
|
||||||
{ "rawtransactions", "fundrawtransaction", &fundrawtransaction, {"hexstring","options","iswitness"} },
|
{ "rawtransactions", "fundrawtransaction", &fundrawtransaction, {"hexstring","options","iswitness"} },
|
||||||
{ "wallet", "abandontransaction", &abandontransaction, {"txid"} },
|
{ "wallet", "abandontransaction", &abandontransaction, {"txid"} },
|
||||||
|
|
|
@ -4,29 +4,26 @@
|
||||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
"""Test deprecation of RPC calls."""
|
"""Test deprecation of RPC calls."""
|
||||||
from test_framework.test_framework import BitcoinTestFramework
|
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):
|
class DeprecatedRpcTest(BitcoinTestFramework):
|
||||||
def set_test_params(self):
|
def set_test_params(self):
|
||||||
self.num_nodes = 2
|
self.num_nodes = 2
|
||||||
self.setup_clean_chain = True
|
self.setup_clean_chain = True
|
||||||
self.extra_args = [[], ["-deprecatedrpc=generate"]]
|
self.extra_args = [[], []]
|
||||||
|
|
||||||
def skip_test_if_missing_module(self):
|
|
||||||
# The generate RPC method requires the wallet to be compiled
|
|
||||||
self.skip_if_no_wallet()
|
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
# This test should be used to verify correct behaviour of deprecated
|
# This test should be used to verify correct behaviour of deprecated
|
||||||
# RPC methods with and without the -deprecatedrpc flags. For example:
|
# RPC methods with and without the -deprecatedrpc flags. For example:
|
||||||
#
|
#
|
||||||
# self.log.info("Make sure that -deprecatedrpc=createmultisig allows it to take addresses")
|
# In set_test_params:
|
||||||
# assert_raises_rpc_error(-5, "Invalid public key", self.nodes[0].createmultisig, 1, [self.nodes[0].getnewaddress()])
|
# self.extra_args = [[], ["-deprecatedrpc=generate"]]
|
||||||
# self.nodes[1].createmultisig(1, [self.nodes[1].getnewaddress()])
|
#
|
||||||
|
# In run_test:
|
||||||
self.log.info("Test generate RPC")
|
# self.log.info("Test generate RPC")
|
||||||
assert_raises_rpc_error(-32, 'The wallet generate rpc method is deprecated', self.nodes[0].rpc.generate, 1)
|
# assert_raises_rpc_error(-32, 'The wallet generate rpc method is deprecated', self.nodes[0].rpc.generate, 1)
|
||||||
self.nodes[1].generate(1)
|
# self.nodes[1].generate(1)
|
||||||
|
self.log.info("No tested deprecated RPC methods")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
DeprecatedRpcTest().main()
|
DeprecatedRpcTest().main()
|
||||||
|
|
Loading…
Reference in a new issue