mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
Merge #11862: Network specific conf sections
c25321fAdd config changes to release notes (Anthony Towns)5e3cbe0[tests] Unit tests for -testnet/-regtest in [test]/[regtest] sections (Anthony Towns)005ad26ArgsManager: special handling for -regtest and -testnet (Anthony Towns)608415d[tests] Unit tests for network-specific config entries (Anthony Towns)68797e2ArgsManager: Warn when ignoring network-specific config setting (Anthony Towns)d1fc4d9ArgsManager: 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)95eb66dArgsManager: support config file sections (Anthony Towns)4d34fccArgsManager: drop m_negated_args (Anthony Towns)3673ca3ArgsManager: 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
This commit is contained in:
30
src/util.h
30
src/util.h
@@ -24,6 +24,7 @@
|
||||
#include <exception>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
@@ -225,17 +226,35 @@ 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
|
||||
*
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user