Skip to content

Commit cb00510

Browse files
committed
rpc: create rpc/mining.h, hoist default max tries values to constant
1 parent 9bc7751 commit cb00510

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ BITCOIN_CORE_H = \
184184
reverse_iterator.h \
185185
rpc/blockchain.h \
186186
rpc/client.h \
187+
rpc/mining.h \
187188
rpc/protocol.h \
188189
rpc/rawtransaction_util.h \
189190
rpc/register.h \

src/rpc/mining.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <policy/fees.h>
1818
#include <pow.h>
1919
#include <rpc/blockchain.h>
20+
#include <rpc/mining.h>
2021
#include <rpc/server.h>
2122
#include <rpc/util.h>
2223
#include <script/descriptor.h>
@@ -206,7 +207,7 @@ static UniValue generatetodescriptor(const JSONRPCRequest& request)
206207
{
207208
{"num_blocks", RPCArg::Type::NUM, RPCArg::Optional::NO, "How many blocks are generated immediately."},
208209
{"descriptor", RPCArg::Type::STR, RPCArg::Optional::NO, "The descriptor to send the newly generated bitcoin to."},
209-
{"maxtries", RPCArg::Type::NUM, /* default */ "1000000", "How many iterations to try."},
210+
{"maxtries", RPCArg::Type::NUM, /* default */ ToString(DEFAULT_MAX_TRIES), "How many iterations to try."},
210211
},
211212
RPCResult{
212213
RPCResult::Type::ARR, "", "hashes of blocks generated",
@@ -220,7 +221,7 @@ static UniValue generatetodescriptor(const JSONRPCRequest& request)
220221
.Check(request);
221222

222223
const int num_blocks{request.params[0].get_int()};
223-
const int64_t max_tries{request.params[2].isNull() ? 1000000 : request.params[2].get_int()};
224+
const uint64_t max_tries{request.params[2].isNull() ? DEFAULT_MAX_TRIES : request.params[2].get_int()};
224225

225226
CScript coinbase_script;
226227
std::string error;
@@ -241,7 +242,7 @@ static UniValue generatetoaddress(const JSONRPCRequest& request)
241242
{
242243
{"nblocks", RPCArg::Type::NUM, RPCArg::Optional::NO, "How many blocks are generated immediately."},
243244
{"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The address to send the newly generated bitcoin to."},
244-
{"maxtries", RPCArg::Type::NUM, /* default */ "1000000", "How many iterations to try."},
245+
{"maxtries", RPCArg::Type::NUM, /* default */ ToString(DEFAULT_MAX_TRIES), "How many iterations to try."},
245246
},
246247
RPCResult{
247248
RPCResult::Type::ARR, "", "hashes of blocks generated",
@@ -257,7 +258,7 @@ static UniValue generatetoaddress(const JSONRPCRequest& request)
257258
}.Check(request);
258259

259260
int nGenerate = request.params[0].get_int();
260-
uint64_t nMaxTries = 1000000;
261+
uint64_t nMaxTries{DEFAULT_MAX_TRIES};
261262
if (!request.params[2].isNull()) {
262263
nMaxTries = request.params[2].get_int();
263264
}
@@ -370,7 +371,7 @@ static UniValue generateblock(const JSONRPCRequest& request)
370371
}
371372

372373
uint256 block_hash;
373-
uint64_t max_tries{1000000};
374+
uint64_t max_tries{DEFAULT_MAX_TRIES};
374375
unsigned int extra_nonce{0};
375376

376377
if (!GenerateBlock(EnsureChainman(request.context), block, max_tries, extra_nonce, block_hash) || block_hash.IsNull()) {

src/rpc/mining.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) 2020 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_RPC_MINING_H
6+
#define BITCOIN_RPC_MINING_H
7+
8+
/** Default max iterations to try in RPC generatetodescriptor, generatetoaddress, and generateblock. */
9+
static const uint64_t DEFAULT_MAX_TRIES{1000000};
10+
11+
#endif // BITCOIN_RPC_MINING_H

0 commit comments

Comments
 (0)