Skip to content

Commit a356832

Browse files
authored
Merge pull request #4826 from UdjinM6/de_generate
backport 14468, 14631, 15492
2 parents b47d484 + e743af5 commit a356832

29 files changed

+93
-138
lines changed

doc/release-notes-14468.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Wallet `generate` RPC method deprecated
2+
---------------------------------------
3+
4+
The wallet's `generate` RPC method has been deprecated and will be fully
5+
removed in v0.19.
6+
7+
`generate` is only used for testing. The RPC call reaches across multiple
8+
subsystems (wallet and mining), so is deprecated to simplify the wallet-node
9+
interface. Projects that are using `generate` for testing purposes should
10+
transition to using the `generatetoaddress` call, which does not require or use
11+
the wallet component. Calling `generatetoaddress` with an address returned by
12+
`getnewaddress` gives the same functionality as the old `generate` method.
13+
14+
To continue using `generate` in v0.18, restart bitcoind with the
15+
`-deprecatedrpc=generate` configuration.

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
@@ -29,8 +29,6 @@ static const CRPCConvertParam vRPCConvertParams[] =
2929
{ "setmocktime", 0, "timestamp" },
3030
{ "mockscheduler", 0, "delta_time" },
3131
#if ENABLE_MINER
32-
{ "generate", 0, "nblocks" },
33-
{ "generate", 1, "maxtries" },
3432
{ "generatetoaddress", 0, "nblocks" },
3533
{ "generatetoaddress", 2, "maxtries" },
3634
{ "generatetodescriptor", 0, "num_blocks" },

src/rpc/mining.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ static UniValue generatetoaddress(const JSONRPCRequest& request)
263263
RPCExamples{
264264
"\nGenerate 11 blocks to myaddress\n"
265265
+ HelpExampleCli("generatetoaddress", "11 \"myaddress\"")
266+
+ "If you are running the Dash Core wallet, you can get a new address to send the newly generated coins to with:\n"
267+
+ HelpExampleCli("getnewaddress", "")
266268
},
267269
}.ToString());
268270

src/wallet/rpcwallet.cpp

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <policy/feerate.h>
1414
#include <policy/fees.h>
1515
#include <rpc/blockchain.h>
16-
#include <rpc/mining.h>
1716
#include <rpc/rawtransaction_util.h>
1817
#include <rpc/server.h>
1918
#include <rpc/util.h>
@@ -3326,61 +3325,6 @@ UniValue signrawtransactionwithwallet(const JSONRPCRequest& request)
33263325
return SignTransaction(mtx, request.params[1], pwallet, coins, false, request.params[2]);
33273326
}
33283327

3329-
#if ENABLE_MINER
3330-
UniValue generate(const JSONRPCRequest& request)
3331-
{
3332-
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) {
3333-
throw std::runtime_error(
3334-
RPCHelpMan{"generate",
3335-
"\nMine up to nblocks blocks immediately (before the RPC call returns) to an address in the wallet.\n",
3336-
{
3337-
{"nblocks", RPCArg::Type::NUM, RPCArg::Optional::NO, "How many blocks are generated immediately."},
3338-
{"maxtries", RPCArg::Type::NUM, /* default */ "1000000", "How many iterations to try."},
3339-
},
3340-
RPCResult{
3341-
"[ blockhashes ] (json array) hashes of blocks generated\n"
3342-
},
3343-
RPCExamples{
3344-
"\nGenerate 11 blocks\n"
3345-
+ HelpExampleCli("generate", "11")
3346-
},
3347-
}.ToString());
3348-
}
3349-
3350-
std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request);
3351-
if (!wallet) return NullUniValue;
3352-
CWallet* const pwallet = wallet.get();
3353-
3354-
int num_generate = request.params[0].get_int();
3355-
uint64_t max_tries = 1000000;
3356-
if (!request.params[1].isNull()) {
3357-
max_tries = request.params[1].get_int();
3358-
}
3359-
3360-
std::shared_ptr<CReserveScript> coinbase_script;
3361-
pwallet->GetScriptForMining(coinbase_script);
3362-
3363-
// If the keypool is exhausted, no script is returned at all. Catch this.
3364-
if (!coinbase_script) {
3365-
throw JSONRPCError(RPC_WALLET_KEYPOOL_RAN_OUT, "Error: Keypool ran out, please call keypoolrefill first");
3366-
}
3367-
3368-
//throw an error if no script was provided
3369-
if (coinbase_script->reserveScript.empty()) {
3370-
throw JSONRPCError(RPC_INTERNAL_ERROR, "No coinbase script available");
3371-
}
3372-
3373-
const CTxMemPool& mempool = EnsureMemPool();
3374-
3375-
return generateBlocks(mempool, coinbase_script, num_generate, max_tries, true);
3376-
}
3377-
#else
3378-
UniValue generate(const JSONRPCRequest& request)
3379-
{
3380-
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "This call is not available because RPC miner isn't compiled");
3381-
}
3382-
#endif //ENABLE_MINING
3383-
33843328
static UniValue rescanblockchain(const JSONRPCRequest& request)
33853329
{
33863330
if (request.fHelp || request.params.size() > 2) {
@@ -3984,11 +3928,6 @@ UniValue walletcreatefundedpsbt(const JSONRPCRequest& request)
39843928
static const CRPCCommand commands[] =
39853929
{ // category name actor (function) argNames
39863930
// --------------------- ------------------------ ----------------------- ----------
3987-
#if ENABLE_MINER
3988-
{ "generating", "generate", &generate, {"nblocks","maxtries"} },
3989-
#else
3990-
{ "hidden", "generate", &generate, {"nblocks","maxtries"} }, // Hidden as it isn't functional, just an error to let people know if miner isn't compiled
3991-
#endif //ENABLE_MINER
39923931
{ "hidden", "instantsendtoaddress", &instantsendtoaddress, {} },
39933932
{ "rawtransactions", "fundrawtransaction", &fundrawtransaction, {"hexstring","options"} },
39943933
{ "wallet", "abandontransaction", &abandontransaction, {"txid"} },

src/wallet/wallet.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4772,17 +4772,6 @@ void CWallet::MarkReserveKeysAsUsed(int64_t keypool_id)
47724772
}
47734773
}
47744774

4775-
void CWallet::GetScriptForMining(std::shared_ptr<CReserveScript> &script)
4776-
{
4777-
std::shared_ptr<CReserveKey> rKey = std::make_shared<CReserveKey>(this);
4778-
CPubKey pubkey;
4779-
if (!rKey->GetReservedKey(pubkey, false))
4780-
return;
4781-
4782-
script = rKey;
4783-
script->reserveScript = CScript() << ToByteVector(pubkey) << OP_CHECKSIG;
4784-
}
4785-
47864775
void CWallet::LockCoin(const COutPoint& output)
47874776
{
47884777
AssertLockHeld(cs_wallet);

src/wallet/wallet.h

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

11781178
bool DelAddressBook(const CTxDestination& address);
11791179

1180-
void GetScriptForMining(std::shared_ptr<CReserveScript> &script);
1181-
11821180
unsigned int GetKeyPoolSize() EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
11831181
{
11841182
AssertLockHeld(cs_wallet);

test/functional/feature_addressindex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def setup_network(self):
3535
connect_nodes(self.nodes[0], 1)
3636
connect_nodes(self.nodes[0], 2)
3737
connect_nodes(self.nodes[0], 3)
38-
3938
self.sync_all()
39+
self.import_deterministic_coinbase_privkeys()
4040

4141
def run_test(self):
4242
self.log.info("Test that settings can't be changed without -reindex...")

test/functional/feature_dbcrash.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def skip_test_if_missing_module(self):
7474
def setup_network(self):
7575
self.add_nodes(self.num_nodes, extra_args=self.extra_args)
7676
self.start_nodes()
77+
self.import_deterministic_coinbase_privkeys()
7778
# Leave them unconnected, we'll use submitblock directly in this test
7879

7980
def restart_node(self, node_index, expected_tip):

test/functional/feature_dip3_deterministicmns.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def setup_network(self):
3535
self.disable_mocktime()
3636
self.add_nodes(1)
3737
self.start_controller_node()
38+
self.import_deterministic_coinbase_privkeys()
3839

3940
def start_controller_node(self):
4041
self.log.info("starting controller node")

0 commit comments

Comments
 (0)