Skip to content

Commit 0e42c1b

Browse files
committed
Merge bitcoin#30648: doc: Deduplicate list of possible chain strings in RPC help texts
9b29755 Deduplicate list of chain strings in RPC help texts (Martin Saposnic) Pull request description: As mentioned in issue bitcoin#30645: Many command line parameter and RPC help texts currently contain the list of chain/network names hardcoded ("main, test, testnet4, signet, regtest"), which is error-prone as it can easily happen to miss an instance if the list ever changes again. This PR deduplicates the list of possible chain/network strings in RPC/parameter help texts, and it creates a macro `LIST_CHAIN_NAMES` in src/chainparamsbase.h. In the future, there is only 1 place where that list of possible values lives, so maintainability is improved and errors are avoided. All three places where this change impacts: ``` ./bitcoin-cli --help ./bitcoin-cli help getblockchaininfo ./bitcoin-cli help getmininginfo ``` They all return the correct string `"main, test, testnet4, signet, regtest"` See bitcoin#30642 (comment) ACKs for top commit: maflcko: lgtm ACK 9b29755 achow101: ACK 9b29755 MarnixCroes: ACK 9b29755 theStack: ACK 9b29755 danielabrozzoni: ACK 9b29755 Tree-SHA512: 1e961bcbe40b0f17a87a2437eb4ba1bb89468fd1b5a39599d72a00ef75cb4009e7d2f05d0a621bb904fecf681c55b8a219fcfe4d44d5d27f27cdda20882b1323
2 parents 9264d62 + 9b29755 commit 0e42c1b

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

src/chainparamsbase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
void SetupChainParamsBaseOptions(ArgsManager& argsman)
1515
{
16-
argsman.AddArg("-chain=<chain>", "Use the chain <chain> (default: main). Allowed values: main, test, testnet4, signet, regtest", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
16+
argsman.AddArg("-chain=<chain>", "Use the chain <chain> (default: main). Allowed values: " LIST_CHAIN_NAMES, ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
1717
argsman.AddArg("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
1818
"This is intended for regression testing tools and app development. Equivalent to -chain=regtest.", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
1919
argsman.AddArg("-testactivationheight=name@height.", "Set the activation height of 'name' (segwit, bip34, dersig, cltv, csv). (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);

src/chainparamsbase.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,7 @@ const CBaseChainParams& BaseParams();
5353
/** Sets the params returned by Params() to those for the given chain. */
5454
void SelectBaseParams(const ChainType chain);
5555

56+
/** List of possible chain / network names */
57+
#define LIST_CHAIN_NAMES "main, test, testnet4, signet, regtest"
58+
5659
#endif // BITCOIN_CHAINPARAMSBASE_H

src/rpc/blockchain.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <blockfilter.h>
99
#include <chain.h>
1010
#include <chainparams.h>
11+
#include <chainparamsbase.h>
1112
#include <clientversion.h>
1213
#include <coins.h>
1314
#include <common/args.h>
@@ -1273,7 +1274,7 @@ RPCHelpMan getblockchaininfo()
12731274
RPCResult{
12741275
RPCResult::Type::OBJ, "", "",
12751276
{
1276-
{RPCResult::Type::STR, "chain", "current network name (main, test, testnet4, signet, regtest)"},
1277+
{RPCResult::Type::STR, "chain", "current network name (" LIST_CHAIN_NAMES ")"},
12771278
{RPCResult::Type::NUM, "blocks", "the height of the most-work fully-validated chain. The genesis block has height 0"},
12781279
{RPCResult::Type::NUM, "headers", "the current number of headers we have validated"},
12791280
{RPCResult::Type::STR, "bestblockhash", "the hash of the currently best block"},

src/rpc/mining.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <chain.h>
99
#include <chainparams.h>
10+
#include <chainparamsbase.h>
1011
#include <common/system.h>
1112
#include <consensus/amount.h>
1213
#include <consensus/consensus.h>
@@ -422,7 +423,7 @@ static RPCHelpMan getmininginfo()
422423
{RPCResult::Type::NUM, "difficulty", "The current difficulty"},
423424
{RPCResult::Type::NUM, "networkhashps", "The network hashes per second"},
424425
{RPCResult::Type::NUM, "pooledtx", "The size of the mempool"},
425-
{RPCResult::Type::STR, "chain", "current network name (main, test, testnet4, signet, regtest)"},
426+
{RPCResult::Type::STR, "chain", "current network name (" LIST_CHAIN_NAMES ")"},
426427
(IsDeprecatedRPCEnabled("warnings") ?
427428
RPCResult{RPCResult::Type::STR, "warnings", "any network and blockchain warnings (DEPRECATED)"} :
428429
RPCResult{RPCResult::Type::ARR, "warnings", "any network and blockchain warnings (run with `-deprecatedrpc=warnings` to return the latest warning as a single string)",

0 commit comments

Comments
 (0)