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>
2021-06-27 08:33:13 +02:00
# include <util/system.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
2022-05-21 10:27:30 +02:00
void SetupChainParamsBaseOptions ( ArgsManager & argsman )
2015-05-25 09:00:17 +02:00
{
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -budgetparams=<masternode>:<budget>:<superblock> " , " Override masternode, budget and superblock start heights (regtest-only) " , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : CHAINPARAMS ) ;
argsman . AddArg ( " -devnet=<name> " , " Use devnet chain with provided name " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CHAINPARAMS ) ;
argsman . AddArg ( " -dip3params=<activation>:<enforcement> " , " Override DIP3 activation and enforcement heights (regtest-only) " , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : CHAINPARAMS ) ;
argsman . AddArg ( " -dip8params=<activation> " , " Override DIP8 activation height (regtest-only) " , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : CHAINPARAMS ) ;
argsman . AddArg ( " -highsubsidyblocks=<n> " , " The number of blocks with a higher than normal subsidy to mine at the start of a chain (default: 0, devnet-only) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CHAINPARAMS ) ;
argsman . AddArg ( " -highsubsidyfactor=<n> " , " The factor to multiply the normal block subsidy by while in the highsubsidyblocks window of a chain (default: 1, devnet-only) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CHAINPARAMS ) ;
argsman . AddArg ( " -llmqchainlocks=<quorum name> " , " Override the default LLMQ type used for ChainLocks. Allows using ChainLocks with smaller LLMQs. (default: llmq_50_60, devnet-only) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CHAINPARAMS ) ;
argsman . AddArg ( " -llmqdevnetparams=<size>:<threshold> " , " Override the default LLMQ size for the LLMQ_DEVNET quorum (default: 3:2, devnet-only) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CHAINPARAMS ) ;
argsman . AddArg ( " -llmqinstantsend=<quorum name> " , " Override the default LLMQ type used for InstantSend. Allows using InstantSend with smaller LLMQs. (default: llmq_50_60, devnet-only) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CHAINPARAMS ) ;
argsman . AddArg ( " -llmqinstantsenddip0024=<quorum name> " , " Override the default LLMQ type used for InstantSendDIP0024. (default: llmq_60_75, devnet-only) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CHAINPARAMS ) ;
2023-02-19 17:53:29 +01:00
argsman . AddArg ( " -llmqplatform=<quorum name> " , " Override the default LLMQ type used for Platform. (default: llmq_100_67, devnet-only) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CHAINPARAMS ) ;
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -llmqtestparams=<size>:<threshold> " , " Override the default LLMQ size for the LLMQ_TEST quorum (default: 3:2, regtest-only) " , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : CHAINPARAMS ) ;
argsman . AddArg ( " -llmqtestinstantsendparams=<size>:<threshold> " , " Override the default LLMQ size for the LLMQ_TEST_INSTANTSEND quorums (default: 3:2, regtest-only) " , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : CHAINPARAMS ) ;
argsman . AddArg ( " -powtargetspacing=<n> " , " Override the default PowTargetSpacing value in seconds (default: 2.5 minutes, devnet-only) " , ArgsManager : : ALLOW_INT , OptionsCategory : : CHAINPARAMS ) ;
argsman . AddArg ( " -minimumdifficultyblocks=<n> " , " The number of blocks that can be mined with the minimum difficulty at the start of a chain (default: 0, devnet-only) " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CHAINPARAMS ) ;
argsman . AddArg ( " -regtest " , " Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
merge bitcoin#16097: Add Flags enum to ArgsManager class (#4569)
* merge bitcoin#16097: Check IsArgKnown() early
* merge bitcoin#16097: Refactor InterpretNegatedOption() function
* merge bitcoin#16097: Add Flags enum to ArgsManager
* scripted-diff: Use Flags enum in AddArg()
-BEGIN VERIFY SCRIPT-
sed -i 's/const bool debug_only,/unsigned int flags, &/' src/util/system.h src/util/system.cpp
sed -i -E 's/(true|false), OptionsCategory::/ArgsManager::ALLOW_ANY, &/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* scripted-diff: Use ArgsManager::DEBUG_ONLY flag
-BEGIN VERIFY SCRIPT-
sed -i 's/unsigned int flags, const bool debug_only,/unsigned int flags,/' src/util/system.h src/util/system.cpp
sed -i 's/ArgsManager::NONE, debug_only/flags, false/' src/util/system.cpp
sed -i 's/arg.second.m_debug_only/(arg.second.m_flags \& ArgsManager::DEBUG_ONLY)/' src/util/system.cpp
sed -i 's/ArgsManager::ALLOW_ANY, true, OptionsCategory::/ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
sed -i 's/ArgsManager::ALLOW_ANY, false, OptionsCategory::/ArgsManager::ALLOW_ANY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* merge bitcoin#16097: Remove unused m_debug_only member from Arg struct
* merge bitcoin#16097: Use ArgsManager::NETWORK_ONLY flag
* merge bitcoin#16097: Replace IsArgKnown() with FlagsOfKnownArg()
* merge bitcoin#16097: Revamp option negating policy
* merge bitcoin#16097: Make tests arg type specific
2021-11-13 01:25:46 +01:00
" This is intended for regression testing tools and app development. " , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : CHAINPARAMS ) ;
2022-05-21 10:27:30 +02:00
argsman . AddArg ( " -testnet " , " Use the test chain " , ArgsManager : : ALLOW_ANY , OptionsCategory : : CHAINPARAMS ) ;
argsman . AddArg ( " -vbparams=<deployment>:<start>:<end>(:<window>:<threshold/thresholdstart>(:<thresholdmin>:<falloffcoeff>)) " ,
2021-09-03 00:36:11 +02:00
" Use given start/end times for specified version bits deployment (regtest-only). "
merge bitcoin#16097: Add Flags enum to ArgsManager class (#4569)
* merge bitcoin#16097: Check IsArgKnown() early
* merge bitcoin#16097: Refactor InterpretNegatedOption() function
* merge bitcoin#16097: Add Flags enum to ArgsManager
* scripted-diff: Use Flags enum in AddArg()
-BEGIN VERIFY SCRIPT-
sed -i 's/const bool debug_only,/unsigned int flags, &/' src/util/system.h src/util/system.cpp
sed -i -E 's/(true|false), OptionsCategory::/ArgsManager::ALLOW_ANY, &/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* scripted-diff: Use ArgsManager::DEBUG_ONLY flag
-BEGIN VERIFY SCRIPT-
sed -i 's/unsigned int flags, const bool debug_only,/unsigned int flags,/' src/util/system.h src/util/system.cpp
sed -i 's/ArgsManager::NONE, debug_only/flags, false/' src/util/system.cpp
sed -i 's/arg.second.m_debug_only/(arg.second.m_flags \& ArgsManager::DEBUG_ONLY)/' src/util/system.cpp
sed -i 's/ArgsManager::ALLOW_ANY, true, OptionsCategory::/ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
sed -i 's/ArgsManager::ALLOW_ANY, false, OptionsCategory::/ArgsManager::ALLOW_ANY, OptionsCategory::/' $(git grep --files-with-matches 'AddArg(' src)
-END VERIFY SCRIPT-
* merge bitcoin#16097: Remove unused m_debug_only member from Arg struct
* merge bitcoin#16097: Use ArgsManager::NETWORK_ONLY flag
* merge bitcoin#16097: Replace IsArgKnown() with FlagsOfKnownArg()
* merge bitcoin#16097: Revamp option negating policy
* merge bitcoin#16097: Make tests arg type specific
2021-11-13 01:25:46 +01:00
" Specifying window, threshold/thresholdstart, thresholdmin and falloffcoeff is optional. " , ArgsManager : : ALLOW_ANY | ArgsManager : : DEBUG_ONLY , OptionsCategory : : CHAINPARAMS ) ;
2021-09-03 00:36:11 +02:00
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
}
2023-04-17 10:27:07 +02:00
/**
* Port numbers for incoming Tor connections ( 9996 , 19996 , 19796 , 19896 ) have
* been chosen arbitrarily to keep ranges of used ports tight .
*/
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 )
2023-04-17 10:27:07 +02:00
return std : : make_unique < CBaseChainParams > ( " " , 9998 , 9996 ) ;
2015-06-30 21:39:49 +02:00
else if ( chain = = CBaseChainParams : : TESTNET )
2023-04-17 10:27:07 +02:00
return std : : make_unique < CBaseChainParams > ( " testnet3 " , 19998 , 19996 ) ;
2020-12-11 00:12:26 +01:00
else if ( chain = = CBaseChainParams : : DEVNET )
2023-04-17 10:27:07 +02:00
return std : : make_unique < CBaseChainParams > ( gArgs . GetDevNetName ( ) , 19798 , 19796 ) ;
2020-12-11 00:12:26 +01:00
else if ( chain = = CBaseChainParams : : REGTEST )
2023-04-17 10:27:07 +02:00
return std : : make_unique < CBaseChainParams > ( " regtest " , 19898 , 19896 ) ;
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
}