Skip to content

Commit 4366f61

Browse files
committed
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
2 parents 6a278e0 + c25321f commit 4366f61

File tree

8 files changed

+480
-115
lines changed

8 files changed

+480
-115
lines changed

doc/release-notes-pr12823.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Configuration sections for testnet and regtest
2+
----------------------------------------------
3+
4+
It is now possible for a single configuration file to set different
5+
options for different networks. This is done by using sections or by
6+
prefixing the option with the network, such as:
7+
8+
main.uacomment=bitcoin
9+
test.uacomment=bitcoin-testnet
10+
regtest.uacomment=regtest
11+
[main]
12+
mempoolsize=300
13+
[test]
14+
mempoolsize=100
15+
[regtest]
16+
mempoolsize=20
17+
18+
The `addnode=`, `connect=`, `port=`, `bind=`, `rpcport=`, `rpcbind=`
19+
and `wallet=` options will only apply to mainnet when specified in the
20+
configuration file, unless a network is specified.

src/chainparamsbase.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain
4747
void SelectBaseParams(const std::string& chain)
4848
{
4949
globalChainBaseParams = CreateBaseChainParams(chain);
50+
gArgs.SelectConfigNetwork(chain);
5051
}

src/init.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,11 @@ void InitParameterInteraction()
803803
if (gArgs.SoftSetBoolArg("-whitelistrelay", true))
804804
LogPrintf("%s: parameter interaction: -whitelistforcerelay=1 -> setting -whitelistrelay=1\n", __func__);
805805
}
806+
807+
// Warn if network-specific options (-addnode, -connect, etc) are
808+
// specified in default section of config file, but not overridden
809+
// on the command line or in this network's section of the config file.
810+
gArgs.WarnForSectionOnlyArgs();
806811
}
807812

808813
static std::string ResolveErrMsg(const char * const optname, const std::string& strBind)

src/test/util_tests.cpp

Lines changed: 189 additions & 63 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)