diff options
author | fanquake <fanquake@gmail.com> | 2022-10-21 16:31:04 +0800 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2022-10-21 16:39:44 +0800 |
commit | f2859c3aa86ebd01b7245135ef043bb5e60c1e17 (patch) | |
tree | 8453ce8d1ce36e1e657d129dbc27d7e25869a59f /src/util | |
parent | 6da45649c2730f180a6629aec7c8a4ad5c1a7450 (diff) | |
parent | deba6fe3158cd0b2283e0901a072e434ba5b594e (diff) | |
download | bitcoin-f2859c3aa86ebd01b7245135ef043bb5e60c1e17.tar.xz |
Merge bitcoin/bitcoin#25727: util, config: error on startup if `conf` or `reindex` are set in config file
deba6fe3158cd0b2283e0901a072e434ba5b594e test: update feature_config_args.py (josibake)
2e3826cbcd675dcd1d03970233ba5e143e09eb75 util: warn if reindex is used in conf (josibake)
5e744f423838fe7d45453541271bc1a07cd62eac util: disallow setting conf in bitcoin.conf (josibake)
Pull request description:
In help from `bitcoind -h` it specifes that `conf` can only be used from the commandline. However, if `conf` is set in a `bitcoin.conf` file, there is no error and from reading the logs it seems as if the `conf=<other file>` is being used, despite it being ignored. To recreate, you can setup a `bitcoin.conf` file in the default directory, add `conf=<some other file>.conf` and in the separate config file set whichever config value you want and verify that it is being ignored. alternatively, if you set `includeconf=<some other file>.conf` , your config in `<some other file>` will be picked up.
This PR fixes this by having the node error when reading the config file if `conf=` is set.
Additionally, it was mentioned in a recent [PR review club](https://bitcoincore.reviews/24858) that if `reindex=1` is set in the config file, the node will reindex on every startup, which is undesirable:
```irc
17:14 <larryruane> michaelfolkson: Reindex is requested by the user (node operator) as a configuration option (command line or in the config file, tho you probably would never put it in the file, or else it would reindex on every startup!)
```
This PR also has a commit to warn if `reindex=1` is set in the config file.
ACKs for top commit:
hebasto:
ACK deba6fe3158cd0b2283e0901a072e434ba5b594e, tested on Ubuntu 22.04.
aureleoules:
tACK deba6fe3158cd0b2283e0901a072e434ba5b594e
ryanofsky:
Code review ACK deba6fe3158cd0b2283e0901a072e434ba5b594e.
Tree-SHA512: 619fd0aa14e98af1166d6beb92651f5ba3f10d38b8ee132957f094f19c3a37313d9f4d7be2e4019f3fc9a2ca5fa42d03eb539ad820e27efec7ee58a26eb520b1
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/system.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/util/system.cpp b/src/util/system.cpp index ce5d846eb9..d7a0793ea8 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -922,6 +922,20 @@ static bool GetConfigOptions(std::istream& stream, const std::string& filepath, return true; } +bool IsConfSupported(KeyInfo& key, std::string& error) { + if (key.name == "conf") { + error = "conf cannot be set in the configuration file; use includeconf= if you want to include additional config files"; + return false; + } + if (key.name == "reindex") { + // reindex can be set in a config file but it is strongly discouraged as this will cause the node to reindex on + // every restart. Allow the config but throw a warning + 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"); + return true; + } + return true; +} + bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& filepath, std::string& error, bool ignore_invalid_keys) { LOCK(cs_args); @@ -932,6 +946,7 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& file for (const std::pair<std::string, std::string>& option : options) { KeyInfo key = InterpretKey(option.first); std::optional<unsigned int> flags = GetArgFlags('-' + key.name); + if (!IsConfSupported(key, error)) return false; if (flags) { std::optional<util::SettingsValue> value = InterpretValue(key, &option.second, *flags, error); if (!value) { |