diff options
author | Suhail Saqan <suhailsaqan@users.noreply.github.com> | 2022-05-17 14:44:20 -0700 |
---|---|---|
committer | Suhail Saqan <suhailsaqan@users.noreply.github.com> | 2022-05-18 10:50:59 -0700 |
commit | b953ea6cc691ba61bf08eb186e76e7e8b7ba8120 (patch) | |
tree | 26a896590ceb5d383c017eb2df56cd85be9630f6 | |
parent | 002411dc53753b52fef645484258e8baf41585a1 (diff) |
rpc: Put undocumented JSON failure mode behind a runtime flag
rpc: Put undocumented JSON failure mode behind a runtime flag
-rw-r--r-- | src/init.cpp | 1 | ||||
-rw-r--r-- | src/rpc/util.cpp | 5 | ||||
-rw-r--r-- | src/rpc/util.h | 2 | ||||
-rw-r--r-- | test/functional/test_framework/util.py | 1 |
4 files changed, 8 insertions, 1 deletions
diff --git a/src/init.cpp b/src/init.cpp index e180a2b5cd..f06b5bd0d0 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -570,6 +570,7 @@ void SetupServerArgs(ArgsManager& argsman) argsman.AddArg("-rpcallowip=<ip>", "Allow JSON-RPC connections from specified source. Valid for <ip> are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. 1.2.3.4/255.255.255.0) or a network/CIDR (e.g. 1.2.3.4/24). This option can be specified multiple times", ArgsManager::ALLOW_ANY, OptionsCategory::RPC); argsman.AddArg("-rpcauth=<userpw>", "Username and HMAC-SHA-256 hashed password for JSON-RPC connections. The field <userpw> comes in the format: <USERNAME>:<SALT>$<HASH>. A canonical python script is included in share/rpcauth. The client then connects normally using the rpcuser=<USERNAME>/rpcpassword=<PASSWORD> pair of arguments. This option can be specified multiple times", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::RPC); argsman.AddArg("-rpcbind=<addr>[:port]", "Bind to given address to listen for JSON-RPC connections. Do not expose the RPC server to untrusted networks such as the public internet! This option is ignored unless -rpcallowip is also passed. Port is optional and overrides -rpcport. Use [host]:port notation for IPv6. This option can be specified multiple times (default: 127.0.0.1 and ::1 i.e., localhost)", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY | ArgsManager::SENSITIVE, OptionsCategory::RPC); + argsman.AddArg("-rpcdoccheck", strprintf("Throw a non-fatal error at runtime if the documentation for an RPC is incorrect (default: %u)", DEFAULT_RPC_DOC_CHECK), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::RPC); argsman.AddArg("-rpccookiefile=<loc>", "Location of the auth cookie. Relative paths will be prefixed by a net-specific datadir location. (default: data dir)", ArgsManager::ALLOW_ANY, OptionsCategory::RPC); argsman.AddArg("-rpcpassword=<pw>", "Password for JSON-RPC connections", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::RPC); argsman.AddArg("-rpcport=<port>", strprintf("Listen for JSON-RPC connections on <port> (default: %u, testnet: %u, signet: %u, regtest: %u)", defaultBaseParams->RPCPort(), testnetBaseParams->RPCPort(), signetBaseParams->RPCPort(), regtestBaseParams->RPCPort()), ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::RPC); diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index ef3e58494e..48ce33e7eb 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -12,6 +12,7 @@ #include <util/check.h> #include <util/strencodings.h> #include <util/string.h> +#include <util/system.h> #include <util/translation.h> #include <tuple> @@ -581,7 +582,9 @@ UniValue RPCHelpMan::HandleRequest(const JSONRPCRequest& request) const throw std::runtime_error(ToString()); } const UniValue ret = m_fun(*this, request); - CHECK_NONFATAL(std::any_of(m_results.m_results.begin(), m_results.m_results.end(), [ret](const RPCResult& res) { return res.MatchesType(ret); })); + if (gArgs.GetBoolArg("-rpcdoccheck", DEFAULT_RPC_DOC_CHECK)) { + CHECK_NONFATAL(std::any_of(m_results.m_results.begin(), m_results.m_results.end(), [ret](const RPCResult& res) { return res.MatchesType(ret); })); + } return ret; } diff --git a/src/rpc/util.h b/src/rpc/util.h index e16fed75bc..6e23caff6c 100644 --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -22,6 +22,8 @@ #include <variant> #include <vector> +static constexpr bool DEFAULT_RPC_DOC_CHECK{false}; + /** * String used to describe UNIX epoch time in documentation, factored out to a * constant for consistency. diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index 8651bcf636..b043d1a70d 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -378,6 +378,7 @@ def write_config(config_path, *, n, chain, extra_config="", disable_autoconnect= f.write("[{}]\n".format(chain_name_conf_section)) f.write("port=" + str(p2p_port(n)) + "\n") f.write("rpcport=" + str(rpc_port(n)) + "\n") + f.write("rpcdoccheck=1\n") f.write("fallbackfee=0.0002\n") f.write("server=1\n") f.write("keypool=1\n") |