@@ -460,6 +460,13 @@ class ArgsManagerHelper {
460
460
public:
461
461
typedef std::map<std::string, std::vector<std::string>> MapArgs;
462
462
463
+ /* * Determine whether to use config settings in the default section,
464
+ * See also comments around ArgsManager::ArgsManager() below. */
465
+ static inline bool UseDefaultSection (const ArgsManager& am, const std::string& arg)
466
+ {
467
+ return (am.m_network == CBaseChainParams::MAIN || am.m_network_only_args .count (arg) == 0 );
468
+ }
469
+
463
470
/* * Convert regular argument into the network-specific setting */
464
471
static inline std::string NetworkArg (const ArgsManager& am, const std::string& arg)
465
472
{
@@ -521,9 +528,11 @@ class ArgsManagerHelper {
521
528
}
522
529
}
523
530
524
- found_result = GetArgHelper (am.m_config_args , arg);
525
- if (found_result.first ) {
526
- return found_result;
531
+ if (UseDefaultSection (am, arg)) {
532
+ found_result = GetArgHelper (am.m_config_args , arg);
533
+ if (found_result.first ) {
534
+ return found_result;
535
+ }
527
536
}
528
537
529
538
return found_result;
@@ -575,6 +584,22 @@ static bool InterpretNegatedOption(std::string& key, std::string& val)
575
584
return false ;
576
585
}
577
586
587
+ ArgsManager::ArgsManager () :
588
+ /* These options would cause cross-contamination if values for
589
+ * mainnet were used while running on regtest/testnet (or vice-versa).
590
+ * Setting them as section_only_args ensures that sharing a config file
591
+ * between mainnet and regtest/testnet won't cause problems due to these
592
+ * parameters by accident. */
593
+ m_network_only_args{
594
+ " -addnode" , " -connect" ,
595
+ " -port" , " -bind" ,
596
+ " -rpcport" , " -rpcbind" ,
597
+ " -wallet" ,
598
+ }
599
+ {
600
+ // nothing to do
601
+ }
602
+
578
603
void ArgsManager::SelectConfigNetwork (const std::string& network)
579
604
{
580
605
m_network = network;
@@ -621,11 +646,16 @@ std::vector<std::string> ArgsManager::GetArgs(const std::string& strArg) const
621
646
if (IsArgNegated (strArg)) return result; // special case
622
647
623
648
LOCK (cs_args);
649
+
624
650
ArgsManagerHelper::AddArgs (result, m_override_args, strArg);
625
651
if (!m_network.empty ()) {
626
652
ArgsManagerHelper::AddArgs (result, m_config_args, ArgsManagerHelper::NetworkArg (*this , strArg));
627
653
}
628
- ArgsManagerHelper::AddArgs (result, m_config_args, strArg);
654
+
655
+ if (ArgsManagerHelper::UseDefaultSection (*this , strArg)) {
656
+ ArgsManagerHelper::AddArgs (result, m_config_args, strArg);
657
+ }
658
+
629
659
return result;
630
660
}
631
661
0 commit comments