Skip to content

Commit 73c3648

Browse files
MarcoFalkevijaydasmp
authored andcommitted
Merge bitcoin#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
1 parent 6c20a7b commit 73c3648

File tree

6 files changed

+12
-79
lines changed

6 files changed

+12
-79
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
@@ -30,8 +30,6 @@ static const CRPCConvertParam vRPCConvertParams[] =
3030
{
3131
{ "setmocktime", 0, "timestamp" },
3232
#if ENABLE_MINER
33-
{ "generate", 0, "nblocks" },
34-
{ "generate", 1, "maxtries" },
3533
{ "generatetoaddress", 0, "nblocks" },
3634
{ "generatetoaddress", 2, "maxtries" },
3735
#endif // ENABLE_MINER

src/wallet/rpcwallet.cpp

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <node/transaction.h>
1818
#include <policy/feerate.h>
1919
#include <policy/fees.h>
20-
#include <rpc/mining.h>
2120
#include <rpc/rawtransaction_util.h>
2221
#include <rpc/server.h>
2322
#include <rpc/util.h>
@@ -3530,63 +3529,6 @@ UniValue signrawtransactionwithwallet(const JSONRPCRequest& request)
35303529
return SignTransaction(pwallet->chain(), mtx, request.params[1], pwallet, false, request.params[2]);
35313530
}
35323531

3533-
#if ENABLE_MINER
3534-
UniValue generate(const JSONRPCRequest& request)
3535-
{
3536-
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
3537-
CWallet* const pwallet = wallet.get();
3538-
3539-
3540-
if (!EnsureWalletIsAvailable(pwallet, request.fHelp)) {
3541-
return NullUniValue;
3542-
}
3543-
3544-
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) {
3545-
throw std::runtime_error(
3546-
RPCHelpMan{"generate",
3547-
"\nMine up to nblocks blocks immediately (before the RPC call returns) to an address in the wallet.\n",
3548-
{
3549-
{"nblocks", RPCArg::Type::NUM, RPCArg::Optional::NO, "How many blocks are generated immediately."},
3550-
{"maxtries", RPCArg::Type::NUM, /* default */ "1000000", "How many iterations to try."},
3551-
},
3552-
RPCResult{
3553-
"[ blockhashes ] (array) hashes of blocks generated\n"
3554-
},
3555-
RPCExamples{
3556-
"\nGenerate 11 blocks\n"
3557-
+ HelpExampleCli("generate", "11")
3558-
},
3559-
}.ToString());
3560-
}
3561-
3562-
int num_generate = request.params[0].get_int();
3563-
uint64_t max_tries = 1000000;
3564-
if (!request.params[1].isNull()) {
3565-
max_tries = request.params[1].get_int();
3566-
}
3567-
3568-
std::shared_ptr<CReserveScript> coinbase_script;
3569-
pwallet->GetScriptForMining(coinbase_script);
3570-
3571-
// If the keypool is exhausted, no script is returned at all. Catch this.
3572-
if (!coinbase_script) {
3573-
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
3574-
}
3575-
3576-
//throw an error if no script was provided
3577-
if (coinbase_script->reserveScript.empty()) {
3578-
throw JSONRPCError(RPC_INTERNAL_ERROR, "No coinbase script available");
3579-
}
3580-
3581-
return generateBlocks(coinbase_script, num_generate, max_tries, true);
3582-
}
3583-
#else
3584-
UniValue generate(const JSONRPCRequest& request)
3585-
{
3586-
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "This call is not available because RPC miner isn't compiled");
3587-
}
3588-
#endif //ENABLE_MINING
3589-
35903532
static UniValue rescanblockchain(const JSONRPCRequest& request)
35913533
{
35923534
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
@@ -4202,11 +4144,6 @@ UniValue walletcreatefundedpsbt(const JSONRPCRequest& request)
42024144
static const CRPCCommand commands[] =
42034145
{ // category name actor (function) argNames
42044146
// --------------------- ------------------------ ----------------------- ----------
4205-
#if ENABLE_MINER
4206-
{ "generating", "generate", &generate, {"nblocks","maxtries"} },
4207-
#else
4208-
{ "hidden", "generate", &generate, {"nblocks","maxtries"} }, // Hidden as it isn't functional, just an error to let people know if miner isn't compiled
4209-
#endif //ENABLE_MINER
42104147
{ "hidden", "instantsendtoaddress", &instantsendtoaddress, {} },
42114148
{ "hidden", "resendwallettransactions", &resendwallettransactions, {} },
42124149
{ "rawtransactions", "fundrawtransaction", &fundrawtransaction, {"hexstring","options"} },

src/wallet/wallet.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4592,17 +4592,6 @@ void CWallet::MarkReserveKeysAsUsed(int64_t keypool_id)
45924592
}
45934593
}
45944594

4595-
void CWallet::GetScriptForMining(std::shared_ptr<CReserveScript> &script)
4596-
{
4597-
std::shared_ptr<CReserveKey> rKey = std::make_shared<CReserveKey>(this);
4598-
CPubKey pubkey;
4599-
if (!rKey->GetReservedKey(pubkey, false))
4600-
return;
4601-
4602-
script = rKey;
4603-
script->reserveScript = CScript() << ToByteVector(pubkey) << OP_CHECKSIG;
4604-
}
4605-
46064595
void CWallet::LockCoin(const COutPoint& output)
46074596
{
46084597
AssertLockHeld(cs_wallet); // setLockedCoins

src/wallet/wallet.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,8 +1132,6 @@ class CWallet final : public CCryptoKeyStore, private interfaces::Chain::Notific
11321132

11331133
const std::string& GetLabelName(const CScript& scriptPubKey) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
11341134

1135-
void GetScriptForMining(std::shared_ptr<CReserveScript> &script);
1136-
11371135
unsigned int GetKeyPoolSize() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
11381136
{
11391137
AssertLockHeld(cs_wallet); // set{Ex,In}ternalKeyPool

test/functional/feature_dip3_deterministicmns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def start_controller_node(self):
4646
def run_test(self):
4747
self.log.info("funding controller node")
4848
while self.nodes[0].getbalance() < (self.num_initial_mn + 3) * 1000:
49-
self.nodes[0].generate(10) # generate enough for collaterals
49+
self.nodes[0].generatetoaddress(10, self.nodes[0].get_deterministic_priv_key().address) # generate enough for collaterals
5050
self.log.info("controller node has {} dash".format(self.nodes[0].getbalance()))
5151

5252
# Make sure we're below block 135 (which activates dip3)

0 commit comments

Comments
 (0)