aboutsummaryrefslogtreecommitdiff
path: root/src/util.h
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2018-04-16 20:26:42 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2018-04-16 20:52:38 +0200
commit4366f61cc9d417b4c24b7a7605c869fa60d8ddb2 (patch)
tree0db40c35e8606c56816ae7fd27557ab126afcc76 /src/util.h
parent6a278e06400934df0fc6ed81b0d7c645efc50bdf (diff)
parentc25321ff96737bdba80d626d2425ef02c7a4c181 (diff)
downloadbitcoin-4366f61cc9d417b4c24b7a7605c869fa60d8ddb2.tar.xz
Merge #11862: Network specific conf sections
c25321f Add config changes to release notes (Anthony Towns) 5e3cbe0 [tests] Unit tests for -testnet/-regtest in [test]/[regtest] sections (Anthony Towns) 005ad26 ArgsManager: special handling for -regtest and -testnet (Anthony Towns) 608415d [tests] Unit tests for network-specific config entries (Anthony Towns) 68797e2 ArgsManager: Warn when ignoring network-specific config setting (Anthony Towns) d1fc4d9 ArgsManager: limit some options to only apply on mainnet when in default section (Anthony Towns) 8a9817d [tests] Use regtest section in functional tests configs (Anthony Towns) 30f9407 [tests] Unit tests for config file sections (Anthony Towns) 95eb66d ArgsManager: support config file sections (Anthony Towns) 4d34fcc ArgsManager: drop m_negated_args (Anthony Towns) 3673ca3 ArgsManager: keep command line and config file arguments separate (Anthony Towns) Pull request description: The weekly meeting on [2017-12-07](http://www.erisian.com.au/meetbot/bitcoin-core-dev/2017/bitcoin-core-dev.2017-12-07-19.00.log.html) discussed allowing options to bitcoin to have some sensitivity to what network is in use. @theuni suggested having sections in the config file: <cfields> an alternative to that would be sections in a config file. and on the cmdline they'd look like namespaces. so, [testnet] port=5. or -testnet::port=5. This approach is (more or less) supported by `boost::program_options::detail::config_file_iterator` -- when it sees a `[testnet]` section with `port=5`, it will treat that the same as "testnet.port=5". So `[testnet] port=5` (or `testnet.port=5` without the section header) in bitcoin.conf and `-testnet.port=5` on the command line. The other aspect to this question is possibly limiting some options so that there is no possibility of accidental cross-contamination across networks. For example, if you're using a particular wallet.dat on mainnet, you may not want to accidentally use the same wallet on testnet and risk reusing keys. I've set this up so that the `-addnode` and `-wallet` options are `NETWORK_ONLY`, so that if you have a bitcoin.conf: wallet=/secret/wallet.dat upnp=1 and you run `bitcoind -testnet` or `bitcoind -regtest`, then the `wallet=` setting will be ignored, and should behave as if your bitcoin.conf had specified: upnp=1 [main] wallet=/secret/wallet.dat For any `NETWORK_ONLY` options, if you're using `-testnet` or `-regtest`, you'll have to add the prefix to any command line options. This was necessary for `multiwallet.py` for instance. I've left the "default" options as taking precedence over network specific ones, which might be backwards. So if you have: maxmempool=200 [regtest] maxmempool=100 your maxmempool will still be 200 on regtest. The advantage of doing it this way is that if you have `[regtest] maxmempool=100` in bitcoin.conf, and then say `bitcoind -regtest -maxmempool=200`, the same result is probably in line with what you expect... The other thing to note is that I'm using the chain names from `chainparamsbase.cpp` / `ChainNameFromCommandLine`, so the sections are `[main]`, `[test]` and `[regtest]`; not `[mainnet]` or `[testnet]` as might be expected. Thoughts? Ping @MeshCollider @laanwj @jonasschnelli @morcos Tree-SHA512: f00b5eb75f006189987e5c15e154a42b66ee251777768c1e185d764279070fcb7c41947d8794092b912a03d985843c82e5189871416995436a6260520fb7a4db
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/util.h b/src/util.h
index 18d2076a05..ffdee99d27 100644
--- a/src/util.h
+++ b/src/util.h
@@ -24,6 +24,7 @@
#include <exception>
#include <map>
#include <memory>
+#include <set>
#include <stdint.h>
#include <string>
#include <unordered_set>
@@ -225,18 +226,36 @@ inline bool IsSwitchChar(char c)
class ArgsManager
{
protected:
+ friend class ArgsManagerHelper;
+
mutable CCriticalSection cs_args;
- std::map<std::string, std::string> mapArgs;
- std::map<std::string, std::vector<std::string>> mapMultiArgs;
- std::unordered_set<std::string> m_negated_args;
+ std::map<std::string, std::vector<std::string>> m_override_args;
+ std::map<std::string, std::vector<std::string>> m_config_args;
+ std::string m_network;
+ std::set<std::string> m_network_only_args;
void ReadConfigStream(std::istream& stream);
public:
+ ArgsManager();
+
+ /**
+ * Select the network in use
+ */
+ void SelectConfigNetwork(const std::string& network);
+
void ParseParameters(int argc, const char*const argv[]);
void ReadConfigFile(const std::string& confPath);
/**
+ * Log warnings for options in m_section_only_args when
+ * they are specified in the default section but not overridden
+ * on the command line or in a network-specific section in the
+ * config file.
+ */
+ void WarnForSectionOnlyArgs();
+
+ /**
* Return a vector of strings of the given argument
*
* @param strArg Argument to get (e.g. "-foo")
@@ -315,11 +334,6 @@ public:
* @return CBaseChainParams::MAIN by default; raises runtime error if an invalid combination is given.
*/
std::string GetChainName() const;
-
-private:
-
- // Munge -nofoo into -foo=0 and track the value as negated.
- void InterpretNegatedOption(std::string &key, std::string &val);
};
extern ArgsManager gArgs;