1010#include < tinyformat.h>
1111#include < util/system.h>
1212#include < util/strencodings.h>
13+ #include < versionbits.h>
1314#include < versionbitsinfo.h>
1415
1516#include < assert.h>
@@ -56,12 +57,30 @@ static CBlock CreateGenesisBlock(uint32_t nTime, uint32_t nNonce, uint32_t nBits
5657 return CreateGenesisBlock (pszTimestamp, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward);
5758}
5859
60+ /* *
61+ * Add a UASF-able deployment
62+ */
63+ template <int bit, int signal_height, uint16_t signal_periods=26 , uint16_t quiet_periods=13 , uint16_t uasf_periods=52 , uint16_t period=2016 , uint16_t threshold=1916 >
64+ inline void SetDeployment (Consensus::Params& params, Consensus::DeploymentPos pos, const ArgsManager& args, bool force_uasf=false )
65+ {
66+ static_assert (signal_periods >= 0 && quiet_periods >= 0 && uasf_periods >= 0 , " Must specify signal/quiet/uasf periods" );
67+
68+ bool uasf = force_uasf;
69+ for (const std::string& strDeployment : args.GetArgs (" -uasf" )) {
70+ if (strDeployment == VersionBitsDeploymentInfo[(int )pos].name ) {
71+ uasf = true ;
72+ break ;
73+ }
74+ }
75+ params.vDeployments [(int )pos] = Deployment<bit,signal_height,signal_periods,quiet_periods,uasf_periods,period,threshold>(uasf);
76+ }
77+
5978/* *
6079 * Main network
6180 */
6281class CMainParams : public CChainParams {
6382public:
64- CMainParams () {
83+ explicit CMainParams (const ArgsManager& args ) {
6584 strNetworkID = CBaseChainParams::MAIN;
6685 consensus.nSubsidyHalvingInterval = 210000 ;
6786 consensus.BIP16Exception = uint256S (" 0x00000000000002dc756eebf4f49723ed8d30cc28a5f108eb94b1ba88ac4f9c22" );
@@ -71,17 +90,15 @@ class CMainParams : public CChainParams {
7190 consensus.BIP66Height = 363725 ; // 00000000000000000379eaa19dce8c9b722d46ae6a57c2f1a988119488b50931
7291 consensus.CSVHeight = 419328 ; // 000000000000000004a1b34462cb8aeebd5799177f7a29cf28f2d1961716b5b5
7392 consensus.SegwitHeight = 481824 ; // 0000000000000000001c8018d9cb3b742ef25114f27563e3fc4a1902167f9893
74- consensus.MinBIP9WarningHeight = 483840 ; // segwit activation height + miner confirmation window
93+ consensus.MinModernDeploymentWarningHeight = 483840 ; // segwit activation height + miner confirmation window
7594 consensus.powLimit = uint256S (" 00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff" );
7695 consensus.nPowTargetTimespan = 14 * 24 * 60 * 60 ; // two weeks
7796 consensus.nPowTargetSpacing = 10 * 60 ;
7897 consensus.fPowAllowMinDifficultyBlocks = false ;
7998 consensus.fPowNoRetargeting = false ;
8099 consensus.nRuleChangeActivationThreshold = 1916 ; // 95% of 2016
81100 consensus.nMinerConfirmationWindow = 2016 ; // nPowTargetTimespan / nPowTargetSpacing
82- consensus.vDeployments [Consensus::DEPLOYMENT_TESTDUMMY].bit = 28 ;
83- consensus.vDeployments [Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601 ; // January 1, 2008
84- consensus.vDeployments [Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999 ; // December 31, 2008
101+ consensus.vDeployments [Consensus::DEPLOYMENT_TESTDUMMY] = DeploymentDisabled<28 >();
85102
86103 // The best chain should have at least this much work.
87104 consensus.nMinimumChainWork = uint256S (" 0x00000000000000000000000000000000000000000e1ab5ec9348e9f4b8eb8154" );
@@ -169,7 +186,7 @@ class CMainParams : public CChainParams {
169186 */
170187class CTestNetParams : public CChainParams {
171188public:
172- CTestNetParams () {
189+ explicit CTestNetParams (const ArgsManager& args ) {
173190 strNetworkID = CBaseChainParams::TESTNET;
174191 consensus.nSubsidyHalvingInterval = 210000 ;
175192 consensus.BIP16Exception = uint256S (" 0x00000000dd30457c001f4095d208cc1296b0eed002427aa599874af7a432b105" );
@@ -179,17 +196,15 @@ class CTestNetParams : public CChainParams {
179196 consensus.BIP66Height = 330776 ; // 000000002104c8c45e99a8853285a3b592602a3ccde2b832481da85e9e4ba182
180197 consensus.CSVHeight = 770112 ; // 00000000025e930139bac5c6c31a403776da130831ab85be56578f3fa75369bb
181198 consensus.SegwitHeight = 834624 ; // 00000000002b980fcd729daaa248fd9316a5200e9b367f4ff2c42453e84201ca
182- consensus.MinBIP9WarningHeight = 836640 ; // segwit activation height + miner confirmation window
199+ consensus.MinModernDeploymentWarningHeight = 836640 ; // segwit activation height + miner confirmation window
183200 consensus.powLimit = uint256S (" 00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff" );
184201 consensus.nPowTargetTimespan = 14 * 24 * 60 * 60 ; // two weeks
185202 consensus.nPowTargetSpacing = 10 * 60 ;
186203 consensus.fPowAllowMinDifficultyBlocks = true ;
187204 consensus.fPowNoRetargeting = false ;
188205 consensus.nRuleChangeActivationThreshold = 1512 ; // 75% for testchains
189206 consensus.nMinerConfirmationWindow = 2016 ; // nPowTargetTimespan / nPowTargetSpacing
190- consensus.vDeployments [Consensus::DEPLOYMENT_TESTDUMMY].bit = 28 ;
191- consensus.vDeployments [Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601 ; // January 1, 2008
192- consensus.vDeployments [Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999 ; // December 31, 2008
207+ SetDeployment<28 , 0 >(consensus, Consensus::DEPLOYMENT_TESTDUMMY, args);
193208
194209 // The best chain should have at least this much work.
195210 consensus.nMinimumChainWork = uint256S (" 0x0000000000000000000000000000000000000000000001495c1d5a01e2af8a23" );
@@ -264,17 +279,15 @@ class CRegTestParams : public CChainParams {
264279 consensus.BIP66Height = 1251 ; // BIP66 activated on regtest (Used in functional tests)
265280 consensus.CSVHeight = 432 ; // CSV activated on regtest (Used in rpc activation tests)
266281 consensus.SegwitHeight = 0 ; // SEGWIT is always activated on regtest unless overridden
267- consensus.MinBIP9WarningHeight = 0 ;
282+ consensus.MinModernDeploymentWarningHeight = 0 ;
268283 consensus.powLimit = uint256S (" 7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" );
269284 consensus.nPowTargetTimespan = 14 * 24 * 60 * 60 ; // two weeks
270285 consensus.nPowTargetSpacing = 10 * 60 ;
271286 consensus.fPowAllowMinDifficultyBlocks = true ;
272287 consensus.fPowNoRetargeting = true ;
273288 consensus.nRuleChangeActivationThreshold = 108 ; // 75% for testchains
274289 consensus.nMinerConfirmationWindow = 144 ; // Faster than normal for regtest (144 instead of 2016)
275- consensus.vDeployments [Consensus::DEPLOYMENT_TESTDUMMY].bit = 28 ;
276- consensus.vDeployments [Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 0 ;
277- consensus.vDeployments [Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
290+ consensus.vDeployments [Consensus::DEPLOYMENT_TESTDUMMY] = DeploymentAlwaysSignal<28 ,144 ,108 >();
278291
279292 // The best chain should have at least this much work.
280293 consensus.nMinimumChainWork = uint256S (" 0x00" );
@@ -330,10 +343,14 @@ class CRegTestParams : public CChainParams {
330343 /* *
331344 * Allows modifying the Version Bits regtest parameters.
332345 */
333- void UpdateVersionBitsParameters (Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout )
346+ void UpdateVersionBitsParameters (Consensus::DeploymentPos d, int signal_height, int16_t signal_periods )
334347 {
335- consensus.vDeployments [d].nStartTime = nStartTime;
336- consensus.vDeployments [d].nTimeout = nTimeout;
348+ consensus.vDeployments [d].signal_height = signal_height;
349+ consensus.vDeployments [d].signal_periods = signal_periods;
350+ consensus.vDeployments [d].quiet_periods = -1 ;
351+ consensus.vDeployments [d].uasf_periods = 0 ;
352+ consensus.vDeployments [d].threshold = consensus.nRuleChangeActivationThreshold ;
353+ consensus.vDeployments [d].period = consensus.nMinerConfirmationWindow ;
337354 }
338355 void UpdateActivationParametersFromArgs (const ArgsManager& args);
339356};
@@ -359,19 +376,20 @@ void CRegTestParams::UpdateActivationParametersFromArgs(const ArgsManager& args)
359376 if (vDeploymentParams.size () != 3 ) {
360377 throw std::runtime_error (" Version bits parameters malformed, expecting deployment:start:end" );
361378 }
362- int64_t nStartTime, nTimeout;
363- if (!ParseInt64 (vDeploymentParams[1 ], &nStartTime)) {
364- throw std::runtime_error (strprintf (" Invalid nStartTime (%s)" , vDeploymentParams[1 ]));
379+ int32_t signal_height;
380+ int32_t signal_periods;
381+ if (!ParseInt32 (vDeploymentParams[1 ], &signal_height) || signal_height < 0 ) {
382+ throw std::runtime_error (strprintf (" Invalid signal_height (%s)" , vDeploymentParams[1 ]));
365383 }
366- if (!ParseInt64 (vDeploymentParams[2 ], &nTimeout) ) {
367- throw std::runtime_error (strprintf (" Invalid nTimeout (%s)" , vDeploymentParams[2 ]));
384+ if (!ParseInt32 (vDeploymentParams[2 ], &signal_periods) || signal_periods < 0 || signal_periods > 10000 ) {
385+ throw std::runtime_error (strprintf (" Invalid signal_periods (%s)" , vDeploymentParams[2 ]));
368386 }
369387 bool found = false ;
370388 for (int j=0 ; j < (int )Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++j) {
371389 if (vDeploymentParams[0 ] == VersionBitsDeploymentInfo[j].name ) {
372- UpdateVersionBitsParameters (Consensus::DeploymentPos (j), nStartTime, nTimeout );
390+ UpdateVersionBitsParameters (Consensus::DeploymentPos (j), signal_height, signal_periods );
373391 found = true ;
374- LogPrintf (" Setting version bits activation parameters for %s to start =%ld, timeout =%ld\n " , vDeploymentParams[0 ], nStartTime, nTimeout );
392+ LogPrintf (" Setting version bits activation parameters for %s to signal_height =%ld, signal_periods =%ld\n " , vDeploymentParams[0 ], signal_height, signal_periods );
375393 break ;
376394 }
377395 }
@@ -391,9 +409,9 @@ const CChainParams &Params() {
391409std::unique_ptr<const CChainParams> CreateChainParams (const std::string& chain)
392410{
393411 if (chain == CBaseChainParams::MAIN)
394- return std::unique_ptr<CChainParams>(new CMainParams ());
412+ return std::unique_ptr<CChainParams>(new CMainParams (gArgs ));
395413 else if (chain == CBaseChainParams::TESTNET)
396- return std::unique_ptr<CChainParams>(new CTestNetParams ());
414+ return std::unique_ptr<CChainParams>(new CTestNetParams (gArgs ));
397415 else if (chain == CBaseChainParams::REGTEST)
398416 return std::unique_ptr<CChainParams>(new CRegTestParams (gArgs ));
399417 throw std::runtime_error (strprintf (" %s: Unknown chain %s." , __func__, chain));
0 commit comments