v31.1-roots.1 · Commit 7: [PATCH 07/17] feat(rpc): preserve Roots operator interfaces on v31
src/common/config.cpp
Before: src/common/config.cpp · After: src/common/config.cpp
File metadata
index a2cf9381af296650fb5712bc88eb245a312a1b28..cff0917ecb2385d4a753c686e6d390328921988b 100644
Download original patch · Release notes
Diff rows 1–81 of 81. 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>
|
|
@@ -73,6 +74,10 @@ static bool GetConfigOptions(std::istream& stream, const std::string& filepath,
|
|
|
73
74
|
}
|
|
74
75
|
++linenr;
|
|
75
76
|
}
|
|
77
|
+
if (stream.bad() || !stream.eof()) {
|
|
78
|
+
error = strprintf("Failed to read config file \"%s\".", filepath);
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
76
81
|
return true;
|
|
77
82
|
}
|
|
78
83
|
|
|
@@ -90,7 +95,7 @@ bool IsConfSupported(KeyInfo& key, std::string& error) {
|
|
|
90
95
|
return true;
|
|
91
96
|
}
|
|
92
97
|
|
|
93
|
-
bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& filepath, std::string& error, bool ignore_invalid_keys)
|
|
98
|
+
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
99
|
{
|
|
95
100
|
LOCK(cs_args);
|
|
96
101
|
std::vector<std::pair<std::string, std::string>> options;
|
|
@@ -106,7 +111,11 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& file
|
|
|
106
111
|
if (!value) {
|
|
107
112
|
return false;
|
|
108
113
|
}
|
|
109
|
-
m_settings.ro_config[key.section][key.name].push_back(*value);
|
|
114
|
+
if (settings_target) {
|
|
115
|
+
(*settings_target)[key.name].push_back(*value);
|
|
116
|
+
} else {
|
|
117
|
+
m_settings.ro_config[key.section][key.name].push_back(*value);
|
|
118
|
+
}
|
|
110
119
|
} else {
|
|
111
120
|
if (ignore_invalid_keys) {
|
|
112
121
|
LogWarning("Ignoring unknown configuration value %s", option.first);
|
|
@@ -124,6 +133,8 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
|
|
|
124
133
|
{
|
|
125
134
|
LOCK(cs_args);
|
|
126
135
|
m_settings.ro_config.clear();
|
|
136
|
+
m_settings.rw_config.clear();
|
|
137
|
+
m_rwconf_had_prune_option = false;
|
|
127
138
|
m_config_sections.clear();
|
|
128
139
|
m_config_path = AbsPathForConfigVal(*this, GetPathArg("-conf", BITCOIN_CONF_FILENAME), /*net_specific=*/false);
|
|
129
140
|
}
|
|
@@ -214,12 +225,36 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
|
|
|
214
225
|
}
|
|
215
226
|
}
|
|
216
227
|
|
|
228
|
+
// Check for chain settings (BaseParams() calls are only valid after this clause)
|
|
229
|
+
try {
|
|
230
|
+
SelectBaseParams(gArgs.GetChainType());
|
|
231
|
+
} catch (const std::exception& e) {
|
|
232
|
+
error = e.what();
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
|
|
217
236
|
// If datadir is changed in .conf file:
|
|
218
237
|
ClearPathCache();
|
|
219
238
|
if (!CheckDataDirOption(*this)) {
|
|
220
239
|
error = strprintf("specified data directory \"%s\" does not exist.", GetArg("-datadir", ""));
|
|
221
240
|
return false;
|
|
222
241
|
}
|
|
242
|
+
|
|
243
|
+
LOCK(cs_args);
|
|
244
|
+
m_rwconf_path = AbsPathForConfigVal(*this, GetPathArg("-confrw", BITCOIN_RW_CONF_FILENAME));
|
|
245
|
+
const auto rwconf_path{GetRWConfigFilePath()};
|
|
246
|
+
std::ifstream rwconf_stream(rwconf_path.std_path());
|
|
247
|
+
if (fs::exists(rwconf_path) && !rwconf_stream.is_open()) {
|
|
248
|
+
error = strprintf("Config file \"%s\" could not be opened.", fs::PathToString(rwconf_path));
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
if (rwconf_stream.good()) {
|
|
252
|
+
if (!ReadConfigStream(rwconf_stream, fs::PathToString(rwconf_path), error, ignore_invalid_keys, &m_settings.rw_config)) {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
m_rwconf_had_prune_option = m_settings.rw_config.count("prune");
|
|
256
|
+
}
|
|
257
|
+
|
|
223
258
|
return true;
|
|
224
259
|
}
|
|
225
260
|
|