aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Towns <aj@erisian.com.au>2018-04-04 18:07:00 +1000
committerAnthony Towns <aj@erisian.com.au>2018-04-11 23:15:28 +1000
commit68797e20f478d835b7ff691a656242c14283446a (patch)
treee64f31bebc1497fbb733805dba721e130e32e11c
parentd1fc4d95afc191072fc650581a9b668b68b47b15 (diff)
downloadbitcoin-68797e20f478d835b7ff691a656242c14283446a.tar.xz
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.
-rw-r--r--src/init.cpp5
-rw-r--r--src/util.cpp28
-rw-r--r--src/util.h8
3 files changed, 41 insertions, 0 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 9edd93000f..8db1b922c4 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -803,6 +803,11 @@ void InitParameterInteraction()
if (gArgs.SoftSetBoolArg("-whitelistrelay", true))
LogPrintf("%s: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1\n", __func__);
}
+
+ // Warn if network-specific options (-addnode, -connect, etc) are
+ // specified in default section of config file, but not overridden
+ // on the command line or in this network's section of the config file.
+ gArgs.WarnForSectionOnlyArgs();
}
static std::string ResolveErrMsg(const char * const optname, const std::string& strBind)
diff --git a/src/util.cpp b/src/util.cpp
index 51c28349f3..4101173091 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -600,6 +600,34 @@ ArgsManager::ArgsManager() :
// nothing to do
}
+void ArgsManager::WarnForSectionOnlyArgs()
+{
+ // if there's no section selected, don't worry
+ if (m_network.empty()) return;
+
+ // if it's okay to use the default section for this network, don't worry
+ if (m_network == CBaseChainParams::MAIN) return;
+
+ for (const auto& arg : m_network_only_args) {
+ std::pair<bool, std::string> found_result;
+
+ // if this option is overridden it's fine
+ found_result = ArgsManagerHelper::GetArgHelper(m_override_args, arg);
+ if (found_result.first) continue;
+
+ // if there's a network-specific value for this option, it's fine
+ found_result = ArgsManagerHelper::GetArgHelper(m_config_args, ArgsManagerHelper::NetworkArg(*this, arg));
+ if (found_result.first) continue;
+
+ // if there isn't a default value for this option, it's fine
+ found_result = ArgsManagerHelper::GetArgHelper(m_config_args, arg);
+ if (!found_result.first) continue;
+
+ // otherwise, issue a warning
+ LogPrintf("Warning: Config setting for %s only applied on %s network when in [%s] section.\n", arg, m_network, m_network);
+ }
+}
+
void ArgsManager::SelectConfigNetwork(const std::string& network)
{
m_network = network;
diff --git a/src/util.h b/src/util.h
index 8132435628..ba80c21ddc 100644
--- a/src/util.h
+++ b/src/util.h
@@ -246,6 +246,14 @@ public:
void ReadConfigFile(const std::string& confPath);
/**
+ * Log warnings for options in m_section_only_args when
+ * they are specified in the default section but not overridden
+ * on the command line or in a network-specific section in the
+ * config file.
+ */
+ void WarnForSectionOnlyArgs();
+
+ /**
* Return a vector of strings of the given argument
*
* @param strArg Argument to get (e.g. "-foo")