diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -80,7 +80,8 @@ defaultBaseParams->RPCPort(), testnetBaseParams->RPCPort(), regtestBaseParams->RPCPort()), - ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); + ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, + OptionsCategory::OPTIONS); gArgs.AddArg("-rpcwait", "Wait for RPC server to start", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); gArgs.AddArg("-rpcuser=", "Username for JSON-RPC connections", diff --git a/src/bitcoin-wallet.cpp b/src/bitcoin-wallet.cpp --- a/src/bitcoin-wallet.cpp +++ b/src/bitcoin-wallet.cpp @@ -26,7 +26,8 @@ gArgs.AddArg("-datadir=", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); gArgs.AddArg("-wallet=", "Specify wallet name", - ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); + ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, + OptionsCategory::OPTIONS); gArgs.AddArg("-debug=", "Output debugging information (default: 0).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -565,7 +565,8 @@ gArgs.AddArg("-addnode=", "Add a node to connect to and attempt to keep the connection " "open (see the `addnode` RPC command help for more info)", - ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION); + ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, + OptionsCategory::CONNECTION); gArgs.AddArg( "-banscore=", strprintf("Threshold for disconnecting misbehaving peers (default: %u)", @@ -579,12 +580,14 @@ gArgs.AddArg("-bind=", "Bind to given address and always listen on it. Use " "[host]:port notation for IPv6", - ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION); + ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, + OptionsCategory::CONNECTION); gArgs.AddArg( "-connect=", "Connect only to the specified node(s); -connect=0 disables automatic " "connections (the rules for this peer are the same as for -addnode)", - ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION); + ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, + OptionsCategory::CONNECTION); gArgs.AddArg("-discover", "Discover own IP addresses (default: 1 when listening and no " "-externalip or -proxy)", @@ -666,7 +669,8 @@ defaultChainParams->GetDefaultPort(), testnetChainParams->GetDefaultPort(), regtestChainParams->GetDefaultPort()), - ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION); + ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, + OptionsCategory::CONNECTION); gArgs.AddArg("-proxy=", _("Connect through SOCKS5 proxy"), ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION); gArgs.AddArg("-proxyrandomize", @@ -1024,7 +1028,8 @@ "can be specified multiple times (default: 127.0.0.1 and ::1 i.e., " "localhost, or if -rpcallowip has been specified, 0.0.0.0 and :: i.e., " "all addresses)", - ArgsManager::ALLOW_ANY, OptionsCategory::RPC); + ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, + OptionsCategory::RPC); gArgs.AddArg("-rpccookiefile=", "Location of the auth cookie. Relative paths will be prefixed " "by a net-specific datadir location. (default: data dir)", @@ -1047,7 +1052,8 @@ defaultBaseParams->RPCPort(), testnetBaseParams->RPCPort(), regtestBaseParams->RPCPort()), - ArgsManager::ALLOW_ANY, OptionsCategory::RPC); + ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, + OptionsCategory::RPC); gArgs.AddArg("-rpcallowip=", "Allow JSON-RPC connections from specified source. Valid for " " are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. " diff --git a/src/util/system.h b/src/util/system.h --- a/src/util/system.h +++ b/src/util/system.h @@ -312,6 +312,7 @@ void ClearArgs() { LOCK(cs_args); m_available_args.clear(); + m_network_only_args.clear(); } /** diff --git a/src/util/system.cpp b/src/util/system.cpp --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -337,16 +337,7 @@ args[key].push_back(val); } -ArgsManager::ArgsManager() - : /* These options would cause cross-contamination if values for mainnet - * were used while running on regtest/testnet (or vice-versa). - * Setting them as section_only_args ensures that sharing a config file - * between mainnet and regtest/testnet won't cause problems due to these - * parameters by accident. */ - m_network_only_args{ - "-addnode", "-connect", "-port", "-bind", - "-rpcport", "-rpcbind", "-wallet", - } { +ArgsManager::ArgsManager() { // nothing to do } @@ -633,14 +624,19 @@ if (eq_index == std::string::npos) { eq_index = name.size(); } + std::string arg_name = name.substr(0, eq_index); LOCK(cs_args); std::map &arg_map = m_available_args[cat]; auto ret = arg_map.emplace( - name.substr(0, eq_index), + arg_name, Arg{name.substr(eq_index, name.size() - eq_index), help, flags}); // Make sure an insertion actually happened. assert(ret.second); + + if (flags & ArgsManager::NETWORK_ONLY) { + m_network_only_args.emplace(arg_name); + } } void ArgsManager::AddHiddenArgs(const std::vector &names) { diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -103,7 +103,8 @@ "it does not exist (as a directory containing a wallet.dat " "file and log files). For backwards compatibility this will " "also accept names of existing data files in .)", - ArgsManager::ALLOW_ANY, OptionsCategory::WALLET); + ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, + OptionsCategory::WALLET); gArgs.AddArg( "-walletbroadcast", strprintf("Make the wallet broadcast transactions (default: %d)", diff --git a/test/functional/feature_config_args.py b/test/functional/feature_config_args.py --- a/test/functional/feature_config_args.py +++ b/test/functional/feature_config_args.py @@ -39,10 +39,11 @@ self.nodes[0].assert_start_raises_init_error( expected_msg='Error reading configuration file: parse error on line 1: -dash=1, options in configuration file must be specified without leading -') - with open(inc_conf_file_path, 'w', encoding='utf8') as conf: - conf.write("wallet=foo\n") - self.nodes[0].assert_start_raises_init_error( - expected_msg='Error: Config setting for -wallet only applied on regtest network when in [regtest] section.') + if self.is_wallet_compiled(): + with open(inc_conf_file_path, 'w', encoding='utf8') as conf: + conf.write("wallet=foo\n") + self.nodes[0].assert_start_raises_init_error( + expected_msg='Error: Config setting for -wallet only applied on regtest network when in [regtest] section.') with open(inc_conf_file_path, 'w', encoding='utf-8') as conf: conf.write('nono\n')