Skip to content
Bitcoin Roots

v29.4-roots.1 · Commit 2: [PATCH 02/13] runtime: preserve shared operator controls

src/common/config.cpp

Before: src/common/config.cpp · After: src/common/config.cpp

File metadata
index fac4aa314c54ae976a8464d29da1dbdb0c495548..59dec7566bf602bcf756f29936d49c7405725798 100644

Download original patch · Release notes

Diff rows 1–76 of 76. Line numbers refer to the original before/after files.

+ Added− RemovedUnmarked lines are context.

Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.

src/common/config.cpp CHANGED
@@ -4,6 +4,7 @@
4
 
5
  #include <common/args.h>
6
 
 
7
  #include <common/settings.h>
8
  #include <logging.h>
9
  #include <sync.h>
@@ -84,13 +85,13 @@ bool IsConfSupported(KeyInfo& key, std::string& error) {
84
  if (key.name == "reindex") {
85
  // reindex can be set in a config file but it is strongly discouraged as this will cause the node to reindex on
86
  // every restart. Allow the config but throw a warning
87
- LogPrintf("Warning: reindex=1 is set in the configuration file, which will significantly slow down startup. Consider removing or commenting out this option for better performance, unless there is currently a condition which makes rebuilding the indexes necessary\n");
88
  return true;
89
  }
90
  return true;
91
  }
92
 
93
- bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& filepath, std::string& error, bool ignore_invalid_keys)
94
  {
95
  LOCK(cs_args);
96
  std::vector<std::pair<std::string, std::string>> options;
@@ -106,10 +107,13 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& file
106
  if (!value) {
107
  return false;
108
  }
 
 
 
109
  m_settings.ro_config[key.section][key.name].push_back(*value);
110
  } else {
111
  if (ignore_invalid_keys) {
112
- LogPrintf("Ignoring unknown configuration value %s\n", option.first);
113
  } else {
114
  error = strprintf("Invalid configuration value %s", option.first);
115
  return false;
@@ -124,6 +128,8 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
124
  {
125
  LOCK(cs_args);
126
  m_settings.ro_config.clear();
 
 
127
  m_config_sections.clear();
128
  m_config_path = AbsPathForConfigVal(*this, GetPathArg("-conf", BITCOIN_CONF_FILENAME), /*net_specific=*/false);
129
  }
@@ -214,12 +220,32 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
214
  }
215
  }
216
 
 
 
 
 
 
 
 
 
217
  // If datadir is changed in .conf file:
218
  ClearPathCache();
219
  if (!CheckDataDirOption(*this)) {
220
  error = strprintf("specified data directory \"%s\" does not exist.", GetArg("-datadir", ""));
221
  return false;
222
  }
 
 
 
 
 
 
 
 
 
 
 
 
223
  return true;
224
  }
225
 
 
4
 
5
  #include <common/args.h>
6
 
7
+ #include <chainparamsbase.h>
8
  #include <common/settings.h>
9
  #include <logging.h>
10
  #include <sync.h>
 
85
  if (key.name == "reindex") {
86
  // reindex can be set in a config file but it is strongly discouraged as this will cause the node to reindex on
87
  // every restart. Allow the config but throw a warning
88
+ LogWarning("reindex=1 is set in the configuration file, which will significantly slow down startup. Consider removing or commenting out this option for better performance, unless there is currently a condition which makes rebuilding the indexes necessary");
89
  return true;
90
  }
91
  return true;
92
  }
93
 
94
+ bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& filepath, std::string& error, bool ignore_invalid_keys, std::map<std::string, std::vector<common::SettingsValue>>* settings_target)
95
  {
96
  LOCK(cs_args);
97
  std::vector<std::pair<std::string, std::string>> options;
 
107
  if (!value) {
108
  return false;
109
  }
110
+ if (settings_target) {
111
+ (*settings_target)[key.name].push_back(*value);
112
+ } else
113
  m_settings.ro_config[key.section][key.name].push_back(*value);
114
  } else {
115
  if (ignore_invalid_keys) {
116
+ LogWarning("Ignoring unknown configuration value %s", option.first);
117
  } else {
118
  error = strprintf("Invalid configuration value %s", option.first);
119
  return false;
 
128
  {
129
  LOCK(cs_args);
130
  m_settings.ro_config.clear();
131
+ m_settings.rw_config.clear();
132
+ m_rwconf_had_prune_option = false;
133
  m_config_sections.clear();
134
  m_config_path = AbsPathForConfigVal(*this, GetPathArg("-conf", BITCOIN_CONF_FILENAME), /*net_specific=*/false);
135
  }
 
220
  }
221
  }
222
 
223
+ // Check for chain settings (BaseParams() calls are only valid after this clause)
224
+ try {
225
+ SelectBaseParams(gArgs.GetChainType());
226
+ } catch (const std::exception& e) {
227
+ error = e.what();
228
+ return false;
229
+ }
230
+
231
  // If datadir is changed in .conf file:
232
  ClearPathCache();
233
  if (!CheckDataDirOption(*this)) {
234
  error = strprintf("specified data directory \"%s\" does not exist.", GetArg("-datadir", ""));
235
  return false;
236
  }
237
+
238
+ LOCK(cs_args);
239
+ m_rwconf_path = AbsPathForConfigVal(*this, GetPathArg("-confrw", BITCOIN_RW_CONF_FILENAME));
240
+ const auto rwconf_path{GetRWConfigFilePath()};
241
+ std::ifstream rwconf_stream(rwconf_path);
242
+ if (rwconf_stream.good()) {
243
+ if (!ReadConfigStream(rwconf_stream, fs::PathToString(rwconf_path), error, ignore_invalid_keys, &m_settings.rw_config)) {
244
+ return false;
245
+ }
246
+ m_rwconf_had_prune_option = m_settings.rw_config.count("prune");
247
+ }
248
+
249
  return true;
250
  }
251