aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/settings.cpp11
-rw-r--r--src/qt/test/optiontests.cpp4
-rwxr-xr-xtest/functional/feature_settings.py7
3 files changed, 19 insertions, 3 deletions
diff --git a/src/common/settings.cpp b/src/common/settings.cpp
index cbf794a7c6..913ad6d76a 100644
--- a/src/common/settings.cpp
+++ b/src/common/settings.cpp
@@ -4,6 +4,10 @@
#include <common/settings.h>
+#if defined(HAVE_CONFIG_H)
+#include <config/bitcoin-config.h>
+#endif
+
#include <tinyformat.h>
#include <univalue.h>
#include <util/fs.h>
@@ -116,6 +120,13 @@ bool WriteSettings(const fs::path& path,
std::vector<std::string>& errors)
{
SettingsValue out(SettingsValue::VOBJ);
+ // Add auto-generated warning comment only if it does not exist
+ if (!values.contains("_warning_")) {
+ out.pushKV("_warning_", strprintf("This file is automatically generated and updated by %s. Please do not edit this file while the node "
+ "is running, as any changes might be ignored or overwritten.",
+ PACKAGE_NAME));
+ }
+ // Push settings values
for (const auto& value : values) {
out.pushKVEnd(value.first, value.second);
}
diff --git a/src/qt/test/optiontests.cpp b/src/qt/test/optiontests.cpp
index e5a5179d87..7100603616 100644
--- a/src/qt/test/optiontests.cpp
+++ b/src/qt/test/optiontests.cpp
@@ -61,7 +61,11 @@ void OptionTests::migrateSettings()
QVERIFY(!settings.contains("addrSeparateProxyTor"));
std::ifstream file(gArgs.GetDataDirNet() / "settings.json");
+ std::string default_warning = strprintf("This file is automatically generated and updated by %s. Please do not edit this file while the node "
+ "is running, as any changes might be ignored or overwritten.",
+ PACKAGE_NAME);
QCOMPARE(std::string(std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()).c_str(), "{\n"
+ " \"_warning_\": \""+ default_warning+"\",\n"
" \"dbcache\": \"600\",\n"
" \"listen\": false,\n"
" \"onion\": \"onion:234\",\n"
diff --git a/test/functional/feature_settings.py b/test/functional/feature_settings.py
index 4175699152..0214e781de 100755
--- a/test/functional/feature_settings.py
+++ b/test/functional/feature_settings.py
@@ -23,10 +23,11 @@ class SettingsTest(BitcoinTestFramework):
settings = node.chain_path / "settings.json"
conf = node.datadir_path / "bitcoin.conf"
- # Assert empty settings file was created
+ # Assert default settings file was created
self.stop_node(0)
+ default_settings = {"_warning_": "This file is automatically generated and updated by Bitcoin Core. Please do not edit this file while the node is running, as any changes might be ignored or overwritten."}
with settings.open() as fp:
- assert_equal(json.load(fp), {})
+ assert_equal(json.load(fp), default_settings)
# Assert settings are parsed and logged
with settings.open("w") as fp:
@@ -48,7 +49,7 @@ class SettingsTest(BitcoinTestFramework):
# Assert settings are unchanged after shutdown
with settings.open() as fp:
- assert_equal(json.load(fp), {"string": "string", "num": 5, "bool": True, "null": None, "list": [6, 7]})
+ assert_equal(json.load(fp), {**default_settings, **{"string": "string", "num": 5, "bool": True, "null": None, "list": [6, 7]}})
# Test invalid json
with settings.open("w") as fp: