2014-06-19 15:10:04 +02:00
|
|
|
// Copyright (c) 2010 Satoshi Nakamoto
|
2015-12-13 14:51:43 +01:00
|
|
|
// Copyright (c) 2009-2015 The Bitcoin Core developers
|
2014-10-25 11:24:16 +02:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2014-06-19 15:10:04 +02:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <chainparamsbase.h>
|
2014-06-19 15:10:04 +02:00
|
|
|
|
2020-03-19 23:46:56 +01:00
|
|
|
#include <tinyformat.h>
|
|
|
|
#include <util.h>
|
2018-07-17 20:46:55 +02:00
|
|
|
#include <utilmemory.h>
|
2014-06-19 15:10:04 +02:00
|
|
|
|
2014-08-28 22:56:53 +02:00
|
|
|
#include <assert.h>
|
|
|
|
|
2015-06-30 21:39:49 +02:00
|
|
|
const std::string CBaseChainParams::MAIN = "main";
|
|
|
|
const std::string CBaseChainParams::TESTNET = "test";
|
2020-06-24 10:03:53 +02:00
|
|
|
const std::string CBaseChainParams::DEVNET = "devnet";
|
2015-06-30 21:39:49 +02:00
|
|
|
const std::string CBaseChainParams::REGTEST = "regtest";
|
2014-06-19 15:10:04 +02:00
|
|
|
|
2021-03-19 16:00:24 +01:00
|
|
|
void SetupChainParamsBaseOptions()
|
2015-05-25 09:00:17 +02:00
|
|
|
{
|
2021-03-19 18:23:58 +01:00
|
|
|
gArgs.AddArg("-devnet=<name>", "Use devnet chain with provided name", false, OptionsCategory::CHAINPARAMS);
|
2021-03-19 16:00:24 +01:00
|
|
|
gArgs.AddArg("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
|
|
|
|
"This is intended for regression testing tools and app development.", true, OptionsCategory::CHAINPARAMS);
|
2021-03-19 18:23:58 +01:00
|
|
|
gArgs.AddArg("-testnet", "Use the test chain", false, OptionsCategory::CHAINPARAMS);
|
2015-05-25 09:00:17 +02:00
|
|
|
}
|
2014-06-19 15:10:04 +02:00
|
|
|
|
2017-05-09 09:29:12 +02:00
|
|
|
static std::unique_ptr<CBaseChainParams> globalChainBaseParams;
|
2014-06-19 15:10:04 +02:00
|
|
|
|
2014-09-19 19:21:46 +02:00
|
|
|
const CBaseChainParams& BaseParams()
|
|
|
|
{
|
2017-05-09 09:29:12 +02:00
|
|
|
assert(globalChainBaseParams);
|
|
|
|
return *globalChainBaseParams;
|
2014-06-19 15:10:04 +02:00
|
|
|
}
|
|
|
|
|
2017-05-09 09:29:12 +02:00
|
|
|
std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain)
|
2014-09-19 19:21:46 +02:00
|
|
|
{
|
2015-06-30 21:39:49 +02:00
|
|
|
if (chain == CBaseChainParams::MAIN)
|
2020-12-11 00:12:26 +01:00
|
|
|
return MakeUnique<CBaseChainParams>("", 9998);
|
2015-06-30 21:39:49 +02:00
|
|
|
else if (chain == CBaseChainParams::TESTNET)
|
2020-12-11 00:12:26 +01:00
|
|
|
return MakeUnique<CBaseChainParams>("testnet3", 19998);
|
|
|
|
else if (chain == CBaseChainParams::DEVNET)
|
|
|
|
return MakeUnique<CBaseChainParams>(gArgs.GetDevNetName(), 19798);
|
|
|
|
else if (chain == CBaseChainParams::REGTEST)
|
|
|
|
return MakeUnique<CBaseChainParams>("regtest", 19898);
|
2015-06-30 21:39:49 +02:00
|
|
|
else
|
|
|
|
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
|
2014-06-19 15:10:04 +02:00
|
|
|
}
|
|
|
|
|
2015-06-27 21:21:41 +02:00
|
|
|
void SelectBaseParams(const std::string& chain)
|
|
|
|
{
|
2017-05-09 09:29:12 +02:00
|
|
|
globalChainBaseParams = CreateBaseChainParams(chain);
|
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
2020-04-29 14:50:51 +02:00
|
|
|
gArgs.SelectConfigNetwork(chain);
|
2014-06-19 15:10:04 +02:00
|
|
|
}
|