@@ -371,15 +371,17 @@ ArgsManager::ArgsManager() :
371371 // nothing to do
372372}
373373
374- void ArgsManager::WarnForSectionOnlyArgs ()
374+ const std::set<std::string> ArgsManager::GetUnsuitableSectionOnlyArgs () const
375375{
376+ std::set<std::string> unsuitables;
377+
376378 LOCK (cs_args);
377379
378380 // if there's no section selected, don't worry
379- if (m_network.empty ()) return ;
381+ if (m_network.empty ()) return std::set<std::string> {} ;
380382
381383 // if it's okay to use the default section for this network, don't worry
382- if (m_network == CBaseChainParams::MAIN) return ;
384+ if (m_network == CBaseChainParams::MAIN) return std::set<std::string> {} ;
383385
384386 for (const auto & arg : m_network_only_args) {
385387 std::pair<bool , std::string> found_result;
@@ -397,8 +399,28 @@ void ArgsManager::WarnForSectionOnlyArgs()
397399 if (!found_result.first ) continue ;
398400
399401 // otherwise, issue a warning
400- LogPrintf ( " Warning: Config setting for %s only applied on %s network when in [%s] section. \n " , arg, m_network, m_network );
402+ unsuitables. insert ( arg);
401403 }
404+ return unsuitables;
405+ }
406+
407+
408+ const std::set<std::string> ArgsManager::GetUnrecognizedSections () const
409+ {
410+ // Section names to be recognized in the config file.
411+ static const std::set<std::string> available_sections{
412+ CBaseChainParams::REGTEST,
413+ CBaseChainParams::TESTNET,
414+ CBaseChainParams::MAIN
415+ };
416+ std::set<std::string> diff;
417+
418+ LOCK (cs_args);
419+ std::set_difference (
420+ m_config_sections.begin (), m_config_sections.end (),
421+ available_sections.begin (), available_sections.end (),
422+ std::inserter (diff, diff.end ()));
423+ return diff;
402424}
403425
404426void ArgsManager::SelectConfigNetwork (const std::string& network)
@@ -819,7 +841,7 @@ static std::string TrimString(const std::string& str, const std::string& pattern
819841 return str.substr (front, end - front + 1 );
820842}
821843
822- static bool GetConfigOptions (std::istream& stream, std::string& error, std::vector<std::pair<std::string, std::string>> & options)
844+ static bool GetConfigOptions (std::istream& stream, std::string& error, std::vector<std::pair<std::string, std::string>>& options, std::set<std::string>& sections )
823845{
824846 std::string str, prefix;
825847 std::string::size_type pos;
@@ -834,7 +856,9 @@ static bool GetConfigOptions(std::istream& stream, std::string& error, std::vect
834856 str = TrimString (str, pattern);
835857 if (!str.empty ()) {
836858 if (*str.begin () == ' [' && *str.rbegin () == ' ]' ) {
837- prefix = str.substr (1 , str.size () - 2 ) + ' .' ;
859+ const std::string section = str.substr (1 , str.size () - 2 );
860+ sections.insert (section);
861+ prefix = section + ' .' ;
838862 } else if (*str.begin () == ' -' ) {
839863 error = strprintf (" parse error on line %i: %s, options in configuration file must be specified without leading -" , linenr, str);
840864 return false ;
@@ -846,6 +870,9 @@ static bool GetConfigOptions(std::istream& stream, std::string& error, std::vect
846870 return false ;
847871 }
848872 options.emplace_back (name, value);
873+ if ((pos = name.rfind (' .' )) != std::string::npos) {
874+ sections.insert (name.substr (0 , pos));
875+ }
849876 } else {
850877 error = strprintf (" parse error on line %i: %s" , linenr, str);
851878 if (str.size () >= 2 && str.substr (0 , 2 ) == " no" ) {
@@ -863,7 +890,8 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, std::string& error, boo
863890{
864891 LOCK (cs_args);
865892 std::vector<std::pair<std::string, std::string>> options;
866- if (!GetConfigOptions (stream, error, options)) {
893+ m_config_sections.clear ();
894+ if (!GetConfigOptions (stream, error, options, m_config_sections)) {
867895 return false ;
868896 }
869897 for (const std::pair<std::string, std::string>& option : options) {
0 commit comments