From 7c61e9df90579ed42a30016e52355e437733b128 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sat, 22 Jul 2023 01:03:18 +0000 Subject: [PATCH 1/3] Bugfix: RPC: Remove quotes from non-string oneline descriptions --- src/rpc/blockchain.cpp | 2 +- src/rpc/mining.cpp | 2 +- src/wallet/rpc/backup.cpp | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 717a119b5623c..c57cda0483c7b 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -2312,7 +2312,7 @@ static RPCHelpMan scanblocks() { {"filter_false_positives", RPCArg::Type::BOOL, RPCArg::Default{false}, "Filter false positives (slower and may fail on pruned nodes). Otherwise they may occur at a rate of 1/M"}, }, - RPCArgOptions{.oneline_description="\"options\""}}, + RPCArgOptions{.oneline_description="options"}}, }, { scan_result_status_none, diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 1f9b264626566..aa26ba863e2c5 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -569,7 +569,7 @@ static RPCHelpMan getblocktemplate() {"longpollid", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "delay processing request until the result would vary significantly from the \"longpollid\" of a prior template"}, {"data", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "proposed block data to check, encoded in hexadecimal; valid only for mode=\"proposal\""}, }, - RPCArgOptions{.oneline_description="\"template_request\""}}, + RPCArgOptions{.oneline_description="template_request"}}, }, { RPCResult{"If the proposal was accepted with mode=='proposal'", RPCResult::Type::NONE, "", ""}, diff --git a/src/wallet/rpc/backup.cpp b/src/wallet/rpc/backup.cpp index af8043f158e11..f061d581c7c14 100644 --- a/src/wallet/rpc/backup.cpp +++ b/src/wallet/rpc/backup.cpp @@ -1297,12 +1297,12 @@ RPCHelpMan importmulti() }, }, }, - RPCArgOptions{.oneline_description="\"requests\""}}, + RPCArgOptions{.oneline_description="requests"}}, {"options", RPCArg::Type::OBJ_NAMED_PARAMS, RPCArg::Optional::OMITTED, "", { {"rescan", RPCArg::Type::BOOL, RPCArg::Default{true}, "Scan the chain and mempool for wallet transactions after all imports."}, }, - RPCArgOptions{.oneline_description="\"options\""}}, + RPCArgOptions{.oneline_description="options"}}, }, RPCResult{ RPCResult::Type::ARR, "", "Response is an array with the same size as the input that has the execution result", @@ -1617,7 +1617,7 @@ RPCHelpMan importdescriptors() }, }, }, - RPCArgOptions{.oneline_description="\"requests\""}}, + RPCArgOptions{.oneline_description="requests"}}, }, RPCResult{ RPCResult::Type::ARR, "", "Response is an array with the same size as the input that has the execution result", From de319c61759952318364fbcb28c47f0959d89d0e Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sat, 22 Jul 2023 01:03:56 +0000 Subject: [PATCH 2/3] RPC/rpcdoccheck: Error if a oneline_description has a quote for a non-string --- src/rpc/util.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index 19e14f88df208..45bc54ee17465 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -1117,7 +1117,16 @@ std::string RPCArg::ToStringObj(const bool oneline) const std::string RPCArg::ToString(const bool oneline) const { - if (oneline && !m_opts.oneline_description.empty()) return m_opts.oneline_description; + if (oneline && !m_opts.oneline_description.empty()) { + if (m_opts.oneline_description[0] == '\"' && m_type != Type::STR_HEX && m_type != Type::STR && gArgs.GetBoolArg("-rpcdoccheck", DEFAULT_RPC_DOC_CHECK)) { + throw std::runtime_error{ + strprintf("Internal bug detected: non-string RPC arg \"%s\" quotes oneline_description:\n%s\n%s %s\nPlease report this issue here: %s\n", + m_names, m_opts.oneline_description, + PACKAGE_NAME, FormatFullVersion(), + PACKAGE_BUGREPORT)}; + } + return m_opts.oneline_description; + } switch (m_type) { case Type::STR_HEX: From 5e3e83b005518659a69916c373b808da27e51791 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sat, 22 Jul 2023 01:04:57 +0000 Subject: [PATCH 3/3] RPC/Mining: Document template_request better for getblocktemplate --- src/rpc/mining.cpp | 4 ++-- test/functional/mining_basic.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index aa26ba863e2c5..a9f9d485fbd6b 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -554,7 +554,7 @@ static RPCHelpMan getblocktemplate() " https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki#getblocktemplate_changes\n" " https://github.com/bitcoin/bips/blob/master/bip-0145.mediawiki\n", { - {"template_request", RPCArg::Type::OBJ, RPCArg::Default{UniValue::VOBJ}, "Format of the template", + {"template_request", RPCArg::Type::OBJ, RPCArg::Optional::NO, "Format of the template", { {"mode", RPCArg::Type::STR, /* treat as named arg */ RPCArg::Optional::OMITTED, "This must be set to \"template\", \"proposal\" (see BIP 23), or omitted"}, {"capabilities", RPCArg::Type::ARR, /* treat as named arg */ RPCArg::Optional::OMITTED, "A list of strings", @@ -569,7 +569,7 @@ static RPCHelpMan getblocktemplate() {"longpollid", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "delay processing request until the result would vary significantly from the \"longpollid\" of a prior template"}, {"data", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "proposed block data to check, encoded in hexadecimal; valid only for mode=\"proposal\""}, }, - RPCArgOptions{.oneline_description="template_request"}}, + }, }, { RPCResult{"If the proposal was accepted with mode=='proposal'", RPCResult::Type::NONE, "", ""}, diff --git a/test/functional/mining_basic.py b/test/functional/mining_basic.py index 56cd615dacd87..da796d3f70f42 100755 --- a/test/functional/mining_basic.py +++ b/test/functional/mining_basic.py @@ -172,7 +172,7 @@ def assert_submitblock(block, result_str_1, result_str_2=None): block.vtx = [coinbase_tx] self.log.info("getblocktemplate: segwit rule must be set") - assert_raises_rpc_error(-8, "getblocktemplate must be called with the segwit rule set", node.getblocktemplate) + assert_raises_rpc_error(-8, "getblocktemplate must be called with the segwit rule set", node.getblocktemplate, {}) self.log.info("getblocktemplate: Test valid block") assert_template(node, block, None)