Skip to content

Commit c2dfbb4

Browse files
committed
Add unavailable options to hidden options category
Options that are not available (but known in the source code) will cause an error if they are specified. Make these options "available" by adding them to the hidden options category to prevent conf files from failing when shared between binaries that have different options available.
1 parent 7c32b41 commit c2dfbb4

File tree

4 files changed

+47
-20
lines changed

4 files changed

+47
-20
lines changed

src/bitcoind.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@ static bool AppInit(int argc, char* argv[])
6262
//
6363
// If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main()
6464
SetupServerArgs();
65-
#if HAVE_DECL_DAEMON
66-
gArgs.AddArg("-daemon", "Run in the background as a daemon and accept commands", false, OptionsCategory::OPTIONS);
67-
#endif
6865
std::string error;
6966
if (!gArgs.ParseParameters(argc, argv, error)) {
7067
fprintf(stderr, "Error parsing command line arguments: %s\n", error.c_str());

src/init.cpp

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ std::unique_ptr<PeerLogicValidation> peerLogic;
7676
class DummyWalletInit : public WalletInitInterface {
7777
public:
7878

79-
void AddWalletOptions() const override {}
79+
void AddWalletOptions() const override;
8080
bool ParameterInteraction() const override {return true;}
8181
void RegisterRPC(CRPCTable &) const override {}
8282
bool Verify() const override {return true;}
@@ -87,6 +87,15 @@ class DummyWalletInit : public WalletInitInterface {
8787
void Close() const override {}
8888
};
8989

90+
void DummyWalletInit::AddWalletOptions() const
91+
{
92+
std::vector<std::string> opts = {"-addresstype", "-changetype", "-disablewallet", "-discardfee=<amt>", "-fallbackfee=<amt>",
93+
"-keypool=<n>", "-mintxfee=<amt>", "-paytxfee=<amt>", "-rescan", "-salvagewallet", "-spendzeroconfchange", "-txconfirmtarget=<n>",
94+
"-upgradewallet", "-wallet=<path>", "-walletbroadcast", "-walletdir=<dir>", "-walletnotify=<cmd>", "-walletrbf", "-zapwallettxes=<mode>",
95+
"-dblogsize=<n>", "-flushwallet", "-privdb", "-walletrejectlongchains"};
96+
gArgs.AddHiddenArgs(opts);
97+
}
98+
9099
const WalletInitInterface& g_wallet_init_interface = DummyWalletInit();
91100
#endif
92101

@@ -348,6 +357,12 @@ void SetupServerArgs()
348357
const auto defaultChainParams = CreateChainParams(CBaseChainParams::MAIN);
349358
const auto testnetChainParams = CreateChainParams(CBaseChainParams::TESTNET);
350359

360+
// Hidden Options
361+
std::vector<std::string> hidden_args = {"-rpcssl", "-benchmark", "-h", "-help", "-socks", "-tor", "-debugnet", "-whitelistalwaysrelay",
362+
"-prematurewitness", "-walletprematurewitness", "-promiscuousmempoolflags", "-blockminsize", "-dbcrashratio", "-forcecompactdb", "-usehd",
363+
// GUI args. These will be overwritten by SetupUIArgs for the GUI
364+
"-allowselfsignedrootcertificates", "-choosedatadir", "-lang=<lang>", "-min", "-resetguisettings", "-rootcertificates=<file>", "-splash", "-uiplatform"};
365+
351366
// Set all of the args and their help
352367
// When adding new options to the categories, please keep and ensure alphabetical ordering.
353368
gArgs.AddArg("-?", "Print this help message and exit", false, OptionsCategory::OPTIONS);
@@ -375,6 +390,8 @@ void SetupServerArgs()
375390
gArgs.AddArg("-persistmempool", strprintf("Whether to save the mempool on shutdown and load on restart (default: %u)", DEFAULT_PERSIST_MEMPOOL), false, OptionsCategory::OPTIONS);
376391
#ifndef WIN32
377392
gArgs.AddArg("-pid=<file>", strprintf("Specify pid file. Relative paths will be prefixed by a net-specific datadir location. (default: %s)", BITCOIN_PID_FILENAME), false, OptionsCategory::OPTIONS);
393+
#else
394+
hidden_args.emplace_back("-pid");
378395
#endif
379396
gArgs.AddArg("-prune=<n>", strprintf("Reduce storage requirements by enabling pruning (deleting) of old blocks. This allows the pruneblockchain RPC to be called to delete specific blocks, and enables automatic pruning of old blocks if a target size in MiB is provided. This mode is incompatible with -txindex and -rescan. "
380397
"Warning: Reverting this setting requires re-downloading the entire blockchain. "
@@ -383,6 +400,8 @@ void SetupServerArgs()
383400
gArgs.AddArg("-reindex-chainstate", "Rebuild chain state from the currently indexed blocks", false, OptionsCategory::OPTIONS);
384401
#ifndef WIN32
385402
gArgs.AddArg("-sysperms", "Create new files with system default permissions, instead of umask 077 (only effective with disabled wallet functionality)", false, OptionsCategory::OPTIONS);
403+
#else
404+
hidden_args.emplace_back("-sysperms");
386405
#endif
387406
gArgs.AddArg("-txindex", strprintf("Maintain a full transaction index, used by the getrawtransaction rpc call (default: %u)", DEFAULT_TXINDEX), false, OptionsCategory::OPTIONS);
388407

@@ -421,6 +440,8 @@ void SetupServerArgs()
421440
#else
422441
gArgs.AddArg("-upnp", strprintf("Use UPnP to map the listening port (default: %u)", 0), false, OptionsCategory::CONNECTION);
423442
#endif
443+
#else
444+
hidden_args.emplace_back("-upnp");
424445
#endif
425446
gArgs.AddArg("-whitebind=<addr>", "Bind to given address and whitelist peers connecting to it. Use [host]:port notation for IPv6", false, OptionsCategory::CONNECTION);
426447
gArgs.AddArg("-whitelist=<IP address or network>", "Whitelist peers connecting from the given IP address (e.g. 1.2.3.4) or CIDR notated network (e.g. 1.2.3.0/24). Can be specified multiple times."
@@ -433,6 +454,11 @@ void SetupServerArgs()
433454
gArgs.AddArg("-zmqpubhashtx=<address>", "Enable publish hash transaction in <address>", false, OptionsCategory::ZMQ);
434455
gArgs.AddArg("-zmqpubrawblock=<address>", "Enable publish raw block in <address>", false, OptionsCategory::ZMQ);
435456
gArgs.AddArg("-zmqpubrawtx=<address>", "Enable publish raw transaction in <address>", false, OptionsCategory::ZMQ);
457+
#else
458+
hidden_args.emplace_back("-zmqpubhashblock=<address>");
459+
hidden_args.emplace_back("-zmqpubhashtx=<address>");
460+
hidden_args.emplace_back("-zmqpubrawblock=<address>");
461+
hidden_args.emplace_back("-zmqpubrawtx=<address>");
436462
#endif
437463

438464
gArgs.AddArg("-checkblocks=<n>", strprintf("How many blocks to check at startup (default: %u, 0 = all)", DEFAULT_CHECKBLOCKS), true, OptionsCategory::DEBUG_TEST);
@@ -500,22 +526,14 @@ void SetupServerArgs()
500526
gArgs.AddArg("-rpcworkqueue=<n>", strprintf("Set the depth of the work queue to service RPC calls (default: %d)", DEFAULT_HTTP_WORKQUEUE), true, OptionsCategory::RPC);
501527
gArgs.AddArg("-server", "Accept command line and JSON-RPC commands", false, OptionsCategory::RPC);
502528

503-
// Hidden options
504-
gArgs.AddArg("-rpcssl", "", false, OptionsCategory::HIDDEN);
505-
gArgs.AddArg("-benchmark", "", false, OptionsCategory::HIDDEN);
506-
gArgs.AddArg("-h", "", false, OptionsCategory::HIDDEN);
507-
gArgs.AddArg("-help", "", false, OptionsCategory::HIDDEN);
508-
gArgs.AddArg("-socks", "", false, OptionsCategory::HIDDEN);
509-
gArgs.AddArg("-tor", "", false, OptionsCategory::HIDDEN);
510-
gArgs.AddArg("-debugnet", "", false, OptionsCategory::HIDDEN);
511-
gArgs.AddArg("-whitelistalwaysrelay", "", false, OptionsCategory::HIDDEN);
512-
gArgs.AddArg("-prematurewitness", "", false, OptionsCategory::HIDDEN);
513-
gArgs.AddArg("-walletprematurewitness", "", false, OptionsCategory::HIDDEN);
514-
gArgs.AddArg("-promiscuousmempoolflags", "", false, OptionsCategory::HIDDEN);
515-
gArgs.AddArg("-blockminsize", "", false, OptionsCategory::HIDDEN);
516-
gArgs.AddArg("-dbcrashratio", "", false, OptionsCategory::HIDDEN);
517-
gArgs.AddArg("-forcecompactdb", "", false, OptionsCategory::HIDDEN);
518-
gArgs.AddArg("-usehd", "", false, OptionsCategory::HIDDEN);
529+
#if HAVE_DECL_DAEMON
530+
gArgs.AddArg("-daemon", "Run in the background as a daemon and accept commands", false, OptionsCategory::OPTIONS);
531+
#else
532+
hidden_args.emplace_back("-daemon");
533+
#endif
534+
535+
// Add the hidden options
536+
gArgs.AddHiddenArgs(hidden_args);
519537
}
520538

521539
std::string LicenseInfo()

src/util.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,13 @@ void ArgsManager::AddArg(const std::string& name, const std::string& help, const
585585
assert(ret.second); // Make sure an insertion actually happened
586586
}
587587

588+
void ArgsManager::AddHiddenArgs(const std::vector<std::string>& names)
589+
{
590+
for (const std::string& name : names) {
591+
AddArg(name, "", false, OptionsCategory::HIDDEN);
592+
}
593+
}
594+
588595
std::string ArgsManager::GetHelpMessage()
589596
{
590597
const bool show_debug = gArgs.GetBoolArg("-help-debug", false);

src/util.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ class ArgsManager
263263
*/
264264
void AddArg(const std::string& name, const std::string& help, const bool debug_only, const OptionsCategory& cat);
265265

266+
/**
267+
* Add many hidden arguments
268+
*/
269+
void AddHiddenArgs(const std::vector<std::string>& args);
270+
266271
/**
267272
* Clear available arguments
268273
*/

0 commit comments

Comments
 (0)