Merge #18541: rpc: Make verifychain default values static, not depend on global args

fad691cafe083743a26f434488990f060ae4ac45 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 fad691cafe
  promag:
    Code review ACK fad691cafe083743a26f434488990f060ae4ac45.

Tree-SHA512: 1c7a253ff0ec13a973b10d3777b71c70954ded5805b65a3ab06317327014de4cd0601d71d30c6ce89a581722c150cb5567acc1bd3e0c789cb51bab6ef0dcfc4a
This commit is contained in:
MarcoFalke 2020-04-10 11:21:19 -04:00 committed by PastaPastaPasta
parent c999483d63
commit a85255ea06

View File

@ -1386,13 +1386,11 @@ static UniValue gettxout(const JSONRPCRequest& request)
static UniValue verifychain(const JSONRPCRequest& request) static UniValue verifychain(const JSONRPCRequest& request)
{ {
int nCheckLevel = gArgs.GetArg("-checklevel", DEFAULT_CHECKLEVEL);
int nCheckDepth = gArgs.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS);
RPCHelpMan{"verifychain", RPCHelpMan{"verifychain",
"\nVerifies blockchain database.\n", "\nVerifies blockchain database.\n",
{ {
{"checklevel", RPCArg::Type::NUM, /* default */ strprintf("%d, range=0-4", nCheckLevel), "How thorough the block verification is."}, {"checklevel", RPCArg::Type::NUM, /* default */ strprintf("%d, range=0-4", DEFAULT_CHECKLEVEL), "How thorough the block verification is."},
{"nblocks", RPCArg::Type::NUM, /* default */ strprintf("%d, 0=all", nCheckDepth), "The number of blocks to check."}, {"nblocks", RPCArg::Type::NUM, /* default */ strprintf("%d, 0=all", DEFAULT_CHECKBLOCKS), "The number of blocks to check."},
}, },
RPCResult{ RPCResult{
RPCResult::Type::BOOL, "", "Verified or not"}, RPCResult::Type::BOOL, "", "Verified or not"},
@ -1402,17 +1400,15 @@ static UniValue verifychain(const JSONRPCRequest& request)
}, },
}.Check(request); }.Check(request);
LOCK(cs_main); const int check_level(request.params[0].isNull() ? DEFAULT_CHECKLEVEL : request.params[0].get_int());
const int check_depth{request.params[1].isNull() ? DEFAULT_CHECKBLOCKS : request.params[1].get_int()};
if (!request.params[0].isNull()) LOCK(cs_main);
nCheckLevel = request.params[0].get_int();
if (!request.params[1].isNull())
nCheckDepth = request.params[1].get_int();
const NodeContext& node_context = EnsureNodeContext(request.context); const NodeContext& node_context = EnsureNodeContext(request.context);
return CVerifyDB().VerifyDB( return CVerifyDB().VerifyDB(
Params(), &::ChainstateActive().CoinsTip(), *node_context.evodb, nCheckLevel, nCheckDepth); Params(), &::ChainstateActive().CoinsTip(), *node_context.evodb, check_level, check_depth);
} }
/** Implementation of IsSuperMajority with better feedback */ /** Implementation of IsSuperMajority with better feedback */