Skip to content

Commit a840dab

Browse files
author
MarcoFalke
committed
Merge #18541: rpc: Make verifychain default values static, not depend on global args
fad691c rpc: Make verifychain default values static, not depend on global args (MarcoFalke) Pull request description: This fixes several issues: * The documentation is not compile-time static and depends on run-time arguments, making it impossible to host it on a static resource like a website or pdf. See also a similar change in the wallet rpc code: #18499 * The same call (relying on default values) will run different code on different machines, depending on the command line args that were used to start the server. This might lead to hard-to-debug-remote issues. This is a small behaviour change, and I will add release notes. ACKs for top commit: theStack: ACK bitcoin/bitcoin@fad691c promag: Code review ACK fad691c. Tree-SHA512: 1c7a253ff0ec13a973b10d3777b71c70954ded5805b65a3ab06317327014de4cd0601d71d30c6ce89a581722c150cb5567acc1bd3e0c789cb51bab6ef0dcfc4a
2 parents 3347ca4 + fad691c commit a840dab

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/rpc/blockchain.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,13 +1078,11 @@ UniValue gettxout(const JSONRPCRequest& request)
10781078

10791079
static UniValue verifychain(const JSONRPCRequest& request)
10801080
{
1081-
int nCheckLevel = gArgs.GetArg("-checklevel", DEFAULT_CHECKLEVEL);
1082-
int nCheckDepth = gArgs.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS);
10831081
RPCHelpMan{"verifychain",
10841082
"\nVerifies blockchain database.\n",
10851083
{
1086-
{"checklevel", RPCArg::Type::NUM, /* default */ strprintf("%d, range=0-4", nCheckLevel), "How thorough the block verification is."},
1087-
{"nblocks", RPCArg::Type::NUM, /* default */ strprintf("%d, 0=all", nCheckDepth), "The number of blocks to check."},
1084+
{"checklevel", RPCArg::Type::NUM, /* default */ strprintf("%d, range=0-4", DEFAULT_CHECKLEVEL), "How thorough the block verification is."},
1085+
{"nblocks", RPCArg::Type::NUM, /* default */ strprintf("%d, 0=all", DEFAULT_CHECKBLOCKS), "The number of blocks to check."},
10881086
},
10891087
RPCResult{
10901088
RPCResult::Type::BOOL, "", "Verified or not"},
@@ -1094,15 +1092,12 @@ static UniValue verifychain(const JSONRPCRequest& request)
10941092
},
10951093
}.Check(request);
10961094

1097-
LOCK(cs_main);
1095+
const int check_level(request.params[0].isNull() ? DEFAULT_CHECKLEVEL : request.params[0].get_int());
1096+
const int check_depth{request.params[1].isNull() ? DEFAULT_CHECKBLOCKS : request.params[1].get_int()};
10981097

1099-
if (!request.params[0].isNull())
1100-
nCheckLevel = request.params[0].get_int();
1101-
if (!request.params[1].isNull())
1102-
nCheckDepth = request.params[1].get_int();
1098+
LOCK(cs_main);
11031099

1104-
return CVerifyDB().VerifyDB(
1105-
Params(), &::ChainstateActive().CoinsTip(), nCheckLevel, nCheckDepth);
1100+
return CVerifyDB().VerifyDB(Params(), &::ChainstateActive().CoinsTip(), check_level, check_depth);
11061101
}
11071102

11081103
static void BuriedForkDescPushBack(UniValue& softforks, const std::string &name, int height) EXCLUSIVE_LOCKS_REQUIRED(cs_main)

0 commit comments

Comments
 (0)