Skip to content
Bitcoin Roots

v30.3-roots.1 · Commit 2: [PATCH 02/68] feat(runtime): preserve Roots operator controls on Core 30.3

src/common/config.cpp

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

File metadata
index 42f5e283348a6820b8cfbacdb099cbbd0d1764ef..2b54d9fa2725e167c94527c02b89213f2aeb81fb 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. The two line-number columns refer to before and after.

src/common/config.cpp CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  #include <common/args.h>
6
6
 
7
+ #include <chainparamsbase.h>
7
8
  #include <common/settings.h>
8
9
  #include <logging.h>
9
10
  #include <sync.h>
@@ -84,13 +85,13 @@ bool IsConfSupported(KeyInfo& key, std::string& error) {
84
85
  if (key.name == "reindex") {
85
86
  // reindex can be set in a config file but it is strongly discouraged as this will cause the node to reindex on
86
87
  // 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
+ 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");
88
89
  return true;
89
90
  }
90
91
  return true;
91
92
  }
92
93
 
93
- bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& filepath, std::string& error, bool ignore_invalid_keys)
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)
94
95
  {
95
96
  LOCK(cs_args);
96
97
  std::vector<std::pair<std::string, std::string>> options;
@@ -106,10 +107,13 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& file
106
107
  if (!value) {
107
108
  return false;
108
109
  }
110
+ if (settings_target) {
111
+ (*settings_target)[key.name].push_back(*value);
112
+ } else
109
113
  m_settings.ro_config[key.section][key.name].push_back(*value);
110
114
  } else {
111
115
  if (ignore_invalid_keys) {
112
- LogPrintf("Ignoring unknown configuration value %s\n", option.first);
116
+ LogWarning("Ignoring unknown configuration value %s", option.first);
113
117
  } else {
114
118
  error = strprintf("Invalid configuration value %s", option.first);
115
119
  return false;
@@ -124,6 +128,8 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
124
128
  {
125
129
  LOCK(cs_args);
126
130
  m_settings.ro_config.clear();
131
+ m_settings.rw_config.clear();
132
+ m_rwconf_had_prune_option = false;
127
133
  m_config_sections.clear();
128
134
  m_config_path = AbsPathForConfigVal(*this, GetPathArg("-conf", BITCOIN_CONF_FILENAME), /*net_specific=*/false);
129
135
  }
@@ -214,12 +220,32 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
214
220
  }
215
221
  }
216
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
+
217
231
  // If datadir is changed in .conf file:
218
232
  ClearPathCache();
219
233
  if (!CheckDataDirOption(*this)) {
220
234
  error = strprintf("specified data directory \"%s\" does not exist.", GetArg("-datadir", ""));
221
235
  return false;
222
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
+
223
249
  return true;
224
250
  }
225
251