Line data Source code
1 : // Copyright (c) 2010 Satoshi Nakamoto
2 : // Copyright (c) 2009-2020 The Bitcoin Core developers
3 : // Distributed under the MIT software license, see the accompanying
4 : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 :
6 : #include <chainparams.h>
7 :
8 : #include <chainparamsseeds.h>
9 : #include <consensus/merkle.h>
10 : #include <tinyformat.h>
11 : #include <util/system.h>
12 : #include <util/strencodings.h>
13 : #include <versionbitsinfo.h>
14 :
15 : #include <assert.h>
16 :
17 : #include <boost/algorithm/string/classification.hpp>
18 : #include <boost/algorithm/string/split.hpp>
19 :
20 4439 : static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesisOutputScript, uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
21 : {
22 4439 : CMutableTransaction txNew;
23 4439 : txNew.nVersion = 1;
24 4439 : txNew.vin.resize(1);
25 4439 : txNew.vout.resize(1);
26 4439 : txNew.vin[0].scriptSig = CScript() << 486604799 << CScriptNum(4) << std::vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
27 4439 : txNew.vout[0].nValue = genesisReward;
28 4439 : txNew.vout[0].scriptPubKey = genesisOutputScript;
29 :
30 4439 : CBlock genesis;
31 4439 : genesis.nTime = nTime;
32 4439 : genesis.nBits = nBits;
33 4439 : genesis.nNonce = nNonce;
34 4439 : genesis.nVersion = nVersion;
35 4439 : genesis.vtx.push_back(MakeTransactionRef(std::move(txNew)));
36 4439 : genesis.hashPrevBlock.SetNull();
37 4439 : genesis.hashMerkleRoot = BlockMerkleRoot(genesis);
38 : return genesis;
39 4439 : }
40 :
41 : /**
42 : * Build the genesis block. Note that the output of its generation
43 : * transaction cannot be spent since it did not originally exist in the
44 : * database.
45 : *
46 : * CBlock(hash=000000000019d6, ver=1, hashPrevBlock=00000000000000, hashMerkleRoot=4a5e1e, nTime=1231006505, nBits=1d00ffff, nNonce=2083236893, vtx=1)
47 : * CTransaction(hash=4a5e1e, ver=1, vin.size=1, vout.size=1, nLockTime=0)
48 : * CTxIn(COutPoint(000000, -1), coinbase 04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73)
49 : * CTxOut(nValue=50.00000000, scriptPubKey=0x5F1DF16B2B704C8A578D0B)
50 : * vMerkleTree: 4a5e1e
51 : */
52 4439 : static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward)
53 : {
54 : const char* pszTimestamp = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";
55 4439 : const CScript genesisOutputScript = CScript() << ParseHex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f") << OP_CHECKSIG;
56 4439 : return CreateGenesisBlock(pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
57 4439 : }
58 :
59 : /**
60 : * Main network
61 : */
62 : class CMainParams : public CChainParams {
63 : public:
64 3300 : CMainParams() {
65 1650 : strNetworkID = CBaseChainParams::MAIN;
66 1650 : consensus.nSubsidyHalvingInterval = 210000;
67 1650 : consensus.BIP16Exception = uint256S("0x00000000000002dc756eebf4f49723ed8d30cc28a5f108eb94b1ba88ac4f9c22");
68 1650 : consensus.BIP34Height = 227931;
69 1650 : consensus.BIP34Hash = uint256S("0x000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8");
70 1650 : consensus.BIP65Height = 388381; // 000000000000000004c2b624ed5d7756c508d90fd0da2c7c679febfa6c4735f0
71 1650 : consensus.BIP66Height = 363725; // 00000000000000000379eaa19dce8c9b722d46ae6a57c2f1a988119488b50931
72 1650 : consensus.CSVHeight = 419328; // 000000000000000004a1b34462cb8aeebd5799177f7a29cf28f2d1961716b5b5
73 1650 : consensus.SegwitHeight = 481824; // 0000000000000000001c8018d9cb3b742ef25114f27563e3fc4a1902167f9893
74 1650 : consensus.MinBIP9WarningHeight = 483840; // segwit activation height + miner confirmation window
75 1650 : consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
76 1650 : consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
77 1650 : consensus.nPowTargetSpacing = 10 * 60;
78 1650 : consensus.fPowAllowMinDifficultyBlocks = false;
79 1650 : consensus.fPowNoRetargeting = false;
80 1650 : consensus.nRuleChangeActivationThreshold = 1916; // 95% of 2016
81 1650 : consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
82 1650 : consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
83 1650 : consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008
84 1650 : consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008
85 :
86 : // The best chain should have at least this much work.
87 1650 : consensus.nMinimumChainWork = uint256S("0x00000000000000000000000000000000000000000e1ab5ec9348e9f4b8eb8154");
88 :
89 : // By default assume that the signatures in ancestors of this block are valid.
90 1650 : consensus.defaultAssumeValid = uint256S("0x0000000000000000000f2adce67e49b0b6bdeb9de8b7c3d7e93b21e7fc1e819d"); // 623950
91 :
92 : /**
93 : * The message start string is designed to be unlikely to occur in normal data.
94 : * The characters are rarely used upper ASCII, not valid as UTF-8, and produce
95 : * a large 32-bit integer with any alignment.
96 : */
97 1650 : pchMessageStart[0] = 0xf9;
98 1650 : pchMessageStart[1] = 0xbe;
99 1650 : pchMessageStart[2] = 0xb4;
100 1650 : pchMessageStart[3] = 0xd9;
101 1650 : nDefaultPort = 8333;
102 1650 : nPruneAfterHeight = 100000;
103 1650 : m_assumed_blockchain_size = 320;
104 1650 : m_assumed_chain_state_size = 4;
105 :
106 1650 : genesis = CreateGenesisBlock(1231006505, 2083236893, 0x1d00ffff, 1, 50 * COIN);
107 1650 : consensus.hashGenesisBlock = genesis.GetHash();
108 1650 : assert(consensus.hashGenesisBlock == uint256S("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"));
109 1650 : assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
110 :
111 : // Note that of those which support the service bits prefix, most only support a subset of
112 : // possible options.
113 : // This is fine at runtime as we'll fall back to using them as an addrfetch if they don't support the
114 : // service bits we want, but we should get them updated to support all service bits wanted by any
115 : // release ASAP to avoid it where possible.
116 1650 : vSeeds.emplace_back("seed.bitcoin.sipa.be"); // Pieter Wuille, only supports x1, x5, x9, and xd
117 1650 : vSeeds.emplace_back("dnsseed.bluematt.me"); // Matt Corallo, only supports x9
118 1650 : vSeeds.emplace_back("dnsseed.bitcoin.dashjr.org"); // Luke Dashjr
119 1650 : vSeeds.emplace_back("seed.bitcoinstats.com"); // Christian Decker, supports x1 - xf
120 1650 : vSeeds.emplace_back("seed.bitcoin.jonasschnelli.ch"); // Jonas Schnelli, only supports x1, x5, x9, and xd
121 1650 : vSeeds.emplace_back("seed.btc.petertodd.org"); // Peter Todd, only supports x1, x5, x9, and xd
122 1650 : vSeeds.emplace_back("seed.bitcoin.sprovoost.nl"); // Sjors Provoost
123 1650 : vSeeds.emplace_back("dnsseed.emzy.de"); // Stephan Oeste
124 1650 : vSeeds.emplace_back("seed.bitcoin.wiz.biz"); // Jason Maurice
125 :
126 1650 : base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,0);
127 1650 : base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,5);
128 1650 : base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,128);
129 1650 : base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x88, 0xB2, 0x1E};
130 1650 : base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x88, 0xAD, 0xE4};
131 :
132 1650 : bech32_hrp = "bc";
133 :
134 1650 : vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_main, pnSeed6_main + ARRAYLEN(pnSeed6_main));
135 :
136 1650 : fDefaultConsistencyChecks = false;
137 1650 : fRequireStandard = true;
138 1650 : m_is_test_chain = false;
139 1650 : m_is_mockable_chain = false;
140 :
141 3300 : checkpointData = {
142 1650 : {
143 1650 : { 11111, uint256S("0x0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d")},
144 1650 : { 33333, uint256S("0x000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6")},
145 1650 : { 74000, uint256S("0x0000000000573993a3c9e41ce34471c079dcf5f52a0e824a81e7f953b8661a20")},
146 1650 : {105000, uint256S("0x00000000000291ce28027faea320c8d2b054b2e0fe44a773f3eefb151d6bdc97")},
147 1650 : {134444, uint256S("0x00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe")},
148 1650 : {168000, uint256S("0x000000000000099e61ea72015e79632f216fe6cb33d7899acb35b75c8303b763")},
149 1650 : {193000, uint256S("0x000000000000059f452a5f7340de6682a977387c17010ff6e6c3bd83ca8b1317")},
150 1650 : {210000, uint256S("0x000000000000048b95347e83192f69cf0366076336c639f9b7228e9ba171342e")},
151 1650 : {216116, uint256S("0x00000000000001b4f4b433e81ee46494af945cf96014816a4e2370f11b23df4e")},
152 1650 : {225430, uint256S("0x00000000000001c108384350f74090433e7fcf79a606b8e797f065b130575932")},
153 1650 : {250000, uint256S("0x000000000000003887df1f29024b06fc2200b55f8af8f35453d7be294df2d214")},
154 1650 : {279000, uint256S("0x0000000000000001ae8c72a0b0c301f67e3afca10e819efa9041e458e9bd7e40")},
155 1650 : {295000, uint256S("0x00000000000000004d9b4ef50f0f9d686fd69db2e03af35a100370c64632a983")},
156 : }
157 : };
158 :
159 1650 : chainTxData = ChainTxData{
160 : // Data from RPC: getchaintxstats 4096 0000000000000000000f2adce67e49b0b6bdeb9de8b7c3d7e93b21e7fc1e819d
161 : /* nTime */ 1585764811,
162 : /* nTxCount */ 517186863,
163 : /* dTxRate */ 3.305709665792344,
164 : };
165 3300 : }
166 : };
167 :
168 : /**
169 : * Testnet (v3)
170 : */
171 : class CTestNetParams : public CChainParams {
172 : public:
173 2250 : CTestNetParams() {
174 1125 : strNetworkID = CBaseChainParams::TESTNET;
175 1125 : consensus.nSubsidyHalvingInterval = 210000;
176 1125 : consensus.BIP16Exception = uint256S("0x00000000dd30457c001f4095d208cc1296b0eed002427aa599874af7a432b105");
177 1125 : consensus.BIP34Height = 21111;
178 1125 : consensus.BIP34Hash = uint256S("0x0000000023b3a96d3484e5abb3755c413e7d41500f8e2a5c3f0dd01299cd8ef8");
179 1125 : consensus.BIP65Height = 581885; // 00000000007f6655f22f98e72ed80d8b06dc761d5da09df0fa1dc4be4f861eb6
180 1125 : consensus.BIP66Height = 330776; // 000000002104c8c45e99a8853285a3b592602a3ccde2b832481da85e9e4ba182
181 1125 : consensus.CSVHeight = 770112; // 00000000025e930139bac5c6c31a403776da130831ab85be56578f3fa75369bb
182 1125 : consensus.SegwitHeight = 834624; // 00000000002b980fcd729daaa248fd9316a5200e9b367f4ff2c42453e84201ca
183 1125 : consensus.MinBIP9WarningHeight = 836640; // segwit activation height + miner confirmation window
184 1125 : consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
185 1125 : consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
186 1125 : consensus.nPowTargetSpacing = 10 * 60;
187 1125 : consensus.fPowAllowMinDifficultyBlocks = true;
188 1125 : consensus.fPowNoRetargeting = false;
189 1125 : consensus.nRuleChangeActivationThreshold = 1512; // 75% for testchains
190 1125 : consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
191 1125 : consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
192 1125 : consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // January 1, 2008
193 1125 : consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // December 31, 2008
194 :
195 : // The best chain should have at least this much work.
196 1125 : consensus.nMinimumChainWork = uint256S("0x0000000000000000000000000000000000000000000001495c1d5a01e2af8a23");
197 :
198 : // By default assume that the signatures in ancestors of this block are valid.
199 1125 : consensus.defaultAssumeValid = uint256S("0x000000000000056c49030c174179b52a928c870e6e8a822c75973b7970cfbd01"); // 1692000
200 :
201 1125 : pchMessageStart[0] = 0x0b;
202 1125 : pchMessageStart[1] = 0x11;
203 1125 : pchMessageStart[2] = 0x09;
204 1125 : pchMessageStart[3] = 0x07;
205 1125 : nDefaultPort = 18333;
206 1125 : nPruneAfterHeight = 1000;
207 1125 : m_assumed_blockchain_size = 40;
208 1125 : m_assumed_chain_state_size = 2;
209 :
210 1125 : genesis = CreateGenesisBlock(1296688602, 414098458, 0x1d00ffff, 1, 50 * COIN);
211 1125 : consensus.hashGenesisBlock = genesis.GetHash();
212 1125 : assert(consensus.hashGenesisBlock == uint256S("0x000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"));
213 1125 : assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
214 :
215 1125 : vFixedSeeds.clear();
216 1125 : vSeeds.clear();
217 : // nodes with support for servicebits filtering should be at the top
218 1125 : vSeeds.emplace_back("testnet-seed.bitcoin.jonasschnelli.ch");
219 1125 : vSeeds.emplace_back("seed.tbtc.petertodd.org");
220 1125 : vSeeds.emplace_back("seed.testnet.bitcoin.sprovoost.nl");
221 1125 : vSeeds.emplace_back("testnet-seed.bluematt.me"); // Just a static list of stable node(s), only supports x9
222 :
223 1125 : base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
224 1125 : base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
225 1125 : base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,239);
226 1125 : base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x35, 0x87, 0xCF};
227 1125 : base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94};
228 :
229 1125 : bech32_hrp = "tb";
230 :
231 1125 : vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_test, pnSeed6_test + ARRAYLEN(pnSeed6_test));
232 :
233 1125 : fDefaultConsistencyChecks = false;
234 1125 : fRequireStandard = false;
235 1125 : m_is_test_chain = true;
236 1125 : m_is_mockable_chain = false;
237 :
238 2250 : checkpointData = {
239 1125 : {
240 1125 : {546, uint256S("000000002a936ca763904c3c35fce2f3556c559c0214345d31b1bcebf76acb70")},
241 : }
242 : };
243 :
244 1125 : chainTxData = ChainTxData{
245 : // Data from RPC: getchaintxstats 4096 000000000000056c49030c174179b52a928c870e6e8a822c75973b7970cfbd01
246 : /* nTime */ 1585561140,
247 : /* nTxCount */ 13483,
248 : /* dTxRate */ 0.08523187013249722,
249 : };
250 2250 : }
251 : };
252 :
253 : /**
254 : * Regression test
255 : */
256 : class CRegTestParams : public CChainParams {
257 : public:
258 3328 : explicit CRegTestParams(const ArgsManager& args) {
259 1664 : strNetworkID = CBaseChainParams::REGTEST;
260 1664 : consensus.nSubsidyHalvingInterval = 150;
261 1664 : consensus.BIP16Exception = uint256();
262 1664 : consensus.BIP34Height = 500; // BIP34 activated on regtest (Used in functional tests)
263 1664 : consensus.BIP34Hash = uint256();
264 1664 : consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in functional tests)
265 1664 : consensus.BIP66Height = 1251; // BIP66 activated on regtest (Used in functional tests)
266 1664 : consensus.CSVHeight = 432; // CSV activated on regtest (Used in rpc activation tests)
267 1664 : consensus.SegwitHeight = 0; // SEGWIT is always activated on regtest unless overridden
268 1664 : consensus.MinBIP9WarningHeight = 0;
269 1664 : consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
270 1664 : consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
271 1664 : consensus.nPowTargetSpacing = 10 * 60;
272 1664 : consensus.fPowAllowMinDifficultyBlocks = true;
273 1664 : consensus.fPowNoRetargeting = true;
274 1664 : consensus.nRuleChangeActivationThreshold = 108; // 75% for testchains
275 1664 : consensus.nMinerConfirmationWindow = 144; // Faster than normal for regtest (144 instead of 2016)
276 1664 : consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
277 1664 : consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 0;
278 1664 : consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
279 :
280 : // The best chain should have at least this much work.
281 1664 : consensus.nMinimumChainWork = uint256S("0x00");
282 :
283 : // By default assume that the signatures in ancestors of this block are valid.
284 1664 : consensus.defaultAssumeValid = uint256S("0x00");
285 :
286 1664 : pchMessageStart[0] = 0xfa;
287 1664 : pchMessageStart[1] = 0xbf;
288 1664 : pchMessageStart[2] = 0xb5;
289 1664 : pchMessageStart[3] = 0xda;
290 1664 : nDefaultPort = 18444;
291 1664 : nPruneAfterHeight = 1000;
292 1664 : m_assumed_blockchain_size = 0;
293 1664 : m_assumed_chain_state_size = 0;
294 :
295 1664 : UpdateActivationParametersFromArgs(args);
296 :
297 1664 : genesis = CreateGenesisBlock(1296688602, 2, 0x207fffff, 1, 50 * COIN);
298 1664 : consensus.hashGenesisBlock = genesis.GetHash();
299 1664 : assert(consensus.hashGenesisBlock == uint256S("0x0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"));
300 1664 : assert(genesis.hashMerkleRoot == uint256S("0x4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"));
301 :
302 1664 : vFixedSeeds.clear(); //!< Regtest mode doesn't have any fixed seeds.
303 1664 : vSeeds.clear(); //!< Regtest mode doesn't have any DNS seeds.
304 :
305 1664 : fDefaultConsistencyChecks = true;
306 1664 : fRequireStandard = true;
307 1664 : m_is_test_chain = true;
308 1664 : m_is_mockable_chain = true;
309 :
310 3328 : checkpointData = {
311 1664 : {
312 1664 : {0, uint256S("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206")},
313 : }
314 : };
315 :
316 1664 : chainTxData = ChainTxData{
317 : 0,
318 : 0,
319 : 0
320 : };
321 :
322 1664 : base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,111);
323 1664 : base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,196);
324 1664 : base58Prefixes[SECRET_KEY] = std::vector<unsigned char>(1,239);
325 1664 : base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x35, 0x87, 0xCF};
326 1664 : base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x35, 0x83, 0x94};
327 :
328 1664 : bech32_hrp = "bcrt";
329 3328 : }
330 :
331 : /**
332 : * Allows modifying the Version Bits regtest parameters.
333 : */
334 0 : void UpdateVersionBitsParameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout)
335 : {
336 0 : consensus.vDeployments[d].nStartTime = nStartTime;
337 0 : consensus.vDeployments[d].nTimeout = nTimeout;
338 0 : }
339 : void UpdateActivationParametersFromArgs(const ArgsManager& args);
340 : };
341 :
342 1664 : void CRegTestParams::UpdateActivationParametersFromArgs(const ArgsManager& args)
343 : {
344 1664 : if (args.IsArgSet("-segwitheight")) {
345 115 : int64_t height = args.GetArg("-segwitheight", consensus.SegwitHeight);
346 115 : if (height < -1 || height >= std::numeric_limits<int>::max()) {
347 0 : throw std::runtime_error(strprintf("Activation height %ld for segwit is out of valid range. Use -1 to disable segwit.", height));
348 115 : } else if (height == -1) {
349 1 : LogPrintf("Segwit disabled for testing\n");
350 1 : height = std::numeric_limits<int>::max();
351 1 : }
352 115 : consensus.SegwitHeight = static_cast<int>(height);
353 115 : }
354 :
355 1664 : if (!args.IsArgSet("-vbparams")) return;
356 :
357 0 : for (const std::string& strDeployment : args.GetArgs("-vbparams")) {
358 0 : std::vector<std::string> vDeploymentParams;
359 0 : boost::split(vDeploymentParams, strDeployment, boost::is_any_of(":"));
360 0 : if (vDeploymentParams.size() != 3) {
361 0 : throw std::runtime_error("Version bits parameters malformed, expecting deployment:start:end");
362 : }
363 0 : int64_t nStartTime, nTimeout;
364 0 : if (!ParseInt64(vDeploymentParams[1], &nStartTime)) {
365 0 : throw std::runtime_error(strprintf("Invalid nStartTime (%s)", vDeploymentParams[1]));
366 : }
367 0 : if (!ParseInt64(vDeploymentParams[2], &nTimeout)) {
368 0 : throw std::runtime_error(strprintf("Invalid nTimeout (%s)", vDeploymentParams[2]));
369 : }
370 : bool found = false;
371 0 : for (int j=0; j < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++j) {
372 0 : if (vDeploymentParams[0] == VersionBitsDeploymentInfo[j].name) {
373 0 : UpdateVersionBitsParameters(Consensus::DeploymentPos(j), nStartTime, nTimeout);
374 : found = true;
375 0 : LogPrintf("Setting version bits activation parameters for %s to start=%ld, timeout=%ld\n", vDeploymentParams[0], nStartTime, nTimeout);
376 0 : break;
377 : }
378 : }
379 0 : if (!found) {
380 0 : throw std::runtime_error(strprintf("Invalid deployment (%s)", vDeploymentParams[0]));
381 : }
382 0 : }
383 1664 : }
384 :
385 731 : static std::unique_ptr<const CChainParams> globalChainParams;
386 :
387 598552 : const CChainParams &Params() {
388 598552 : assert(globalChainParams);
389 598551 : return *globalChainParams;
390 : }
391 :
392 4439 : std::unique_ptr<const CChainParams> CreateChainParams(const std::string& chain)
393 : {
394 4439 : if (chain == CBaseChainParams::MAIN)
395 1650 : return std::unique_ptr<CChainParams>(new CMainParams());
396 2789 : else if (chain == CBaseChainParams::TESTNET)
397 1125 : return std::unique_ptr<CChainParams>(new CTestNetParams());
398 1664 : else if (chain == CBaseChainParams::REGTEST)
399 1664 : return std::unique_ptr<CChainParams>(new CRegTestParams(gArgs));
400 0 : throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
401 4439 : }
402 :
403 1393 : void SelectParams(const std::string& network)
404 : {
405 1393 : SelectBaseParams(network);
406 1393 : globalChainParams = CreateChainParams(network);
407 1393 : }
|