Skip to content

Commit 68797e2

Browse files
committed
ArgsManager: Warn when ignoring network-specific config setting
When network-specific options such as -addnode, -connect, etc are specified in the default section of the config file, but that setting is ignored due to testnet or regtest being in use, and it is not overridden by either a command line option or a setting in the [regtest] or [test] section of the config file, a warning is added to the log, eg: Warning: Config setting for -connect only applied on regtest network when in [regtest] section.
1 parent d1fc4d9 commit 68797e2

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

src/init.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,11 @@ void InitParameterInteraction()
803803
if (gArgs.SoftSetBoolArg("-whitelistrelay", true))
804804
LogPrintf("%s: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1\n", __func__);
805805
}
806+
807+
// Warn if network-specific options (-addnode, -connect, etc) are
808+
// specified in default section of config file, but not overridden
809+
// on the command line or in this network's section of the config file.
810+
gArgs.WarnForSectionOnlyArgs();
806811
}
807812

808813
static std::string ResolveErrMsg(const char * const optname, const std::string& strBind)

src/util.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,34 @@ ArgsManager::ArgsManager() :
600600
// nothing to do
601601
}
602602

603+
void ArgsManager::WarnForSectionOnlyArgs()
604+
{
605+
// if there's no section selected, don't worry
606+
if (m_network.empty()) return;
607+
608+
// if it's okay to use the default section for this network, don't worry
609+
if (m_network == CBaseChainParams::MAIN) return;
610+
611+
for (const auto& arg : m_network_only_args) {
612+
std::pair<bool, std::string> found_result;
613+
614+
// if this option is overridden it's fine
615+
found_result = ArgsManagerHelper::GetArgHelper(m_override_args, arg);
616+
if (found_result.first) continue;
617+
618+
// if there's a network-specific value for this option, it's fine
619+
found_result = ArgsManagerHelper::GetArgHelper(m_config_args, ArgsManagerHelper::NetworkArg(*this, arg));
620+
if (found_result.first) continue;
621+
622+
// if there isn't a default value for this option, it's fine
623+
found_result = ArgsManagerHelper::GetArgHelper(m_config_args, arg);
624+
if (!found_result.first) continue;
625+
626+
// otherwise, issue a warning
627+
LogPrintf("Warning: Config setting for %s only applied on %s network when in [%s] section.\n", arg, m_network, m_network);
628+
}
629+
}
630+
603631
void ArgsManager::SelectConfigNetwork(const std::string& network)
604632
{
605633
m_network = network;

src/util.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,14 @@ class ArgsManager
245245
void ParseParameters(int argc, const char*const argv[]);
246246
void ReadConfigFile(const std::string& confPath);
247247

248+
/**
249+
* Log warnings for options in m_section_only_args when
250+
* they are specified in the default section but not overridden
251+
* on the command line or in a network-specific section in the
252+
* config file.
253+
*/
254+
void WarnForSectionOnlyArgs();
255+
248256
/**
249257
* Return a vector of strings of the given argument
250258
*

0 commit comments

Comments
 (0)