@@ -399,7 +399,8 @@ void ReadSigNetArgs(const ArgsManager& args, CChainParams::SigNetOptions& option
399399class CRegTestParams : public CChainParams
400400{
401401public:
402- explicit CRegTestParams (const ArgsManager& args) {
402+ explicit CRegTestParams (const RegTestOptions& opts)
403+ {
403404 strNetworkID = CBaseChainParams::REGTEST;
404405 consensus.signet_blocks = false ;
405406 consensus.signet_challenge .clear ();
@@ -437,11 +438,33 @@ class CRegTestParams : public CChainParams
437438 pchMessageStart[2 ] = 0xb5 ;
438439 pchMessageStart[3 ] = 0xda ;
439440 nDefaultPort = 18444 ;
440- nPruneAfterHeight = args. GetBoolArg ( " - fastprune" , false ) ? 100 : 1000 ;
441+ nPruneAfterHeight = opts. fastprune ? 100 : 1000 ;
441442 m_assumed_blockchain_size = 0 ;
442443 m_assumed_chain_state_size = 0 ;
443444
444- UpdateActivationParametersFromArgs (args);
445+ for (const auto & [dep, height] : opts.activation_heights ) {
446+ switch (dep) {
447+ case Consensus::BuriedDeployment::DEPLOYMENT_SEGWIT:
448+ consensus.SegwitHeight = int {height};
449+ break ;
450+ case Consensus::BuriedDeployment::DEPLOYMENT_HEIGHTINCB:
451+ consensus.BIP34Height = int {height};
452+ break ;
453+ case Consensus::BuriedDeployment::DEPLOYMENT_DERSIG:
454+ consensus.BIP66Height = int {height};
455+ break ;
456+ case Consensus::BuriedDeployment::DEPLOYMENT_CLTV:
457+ consensus.BIP65Height = int {height};
458+ break ;
459+ case Consensus::BuriedDeployment::DEPLOYMENT_CSV:
460+ consensus.CSVHeight = int {height};
461+ break ;
462+ }
463+ }
464+
465+ for (const auto & [deployment_pos, version_bits_params] : opts.version_bits_parameters ) {
466+ UpdateVersionBitsParameters (deployment_pos, version_bits_params.start_time , version_bits_params.timeout , version_bits_params.min_activation_height );
467+ }
445468
446469 genesis = CreateGenesisBlock (1296688602 , 2 , 0x207fffff , 1 , 50 * COIN);
447470 consensus.hashGenesisBlock = genesis.GetHash ();
@@ -498,41 +521,31 @@ class CRegTestParams : public CChainParams
498521 consensus.vDeployments [d].nTimeout = nTimeout;
499522 consensus.vDeployments [d].min_activation_height = min_activation_height;
500523 }
501- void UpdateActivationParametersFromArgs (const ArgsManager& args);
502524};
503525
504- static void MaybeUpdateHeights (const ArgsManager& args, Consensus::Params& consensus )
526+ void ReadRegTestArgs (const ArgsManager& args, CChainParams::RegTestOptions& options )
505527{
528+ if (auto value = args.GetBoolArg (" -fastprune" )) options.fastprune = *value;
529+
506530 for (const std::string& arg : args.GetArgs (" -testactivationheight" )) {
507531 const auto found{arg.find (' @' )};
508532 if (found == std::string::npos) {
509533 throw std::runtime_error (strprintf (" Invalid format (%s) for -testactivationheight=name@height." , arg));
510534 }
511- const auto name{arg. substr ( 0 , found)};
535+
512536 const auto value{arg.substr (found + 1 )};
513537 int32_t height;
514538 if (!ParseInt32 (value, &height) || height < 0 || height >= std::numeric_limits<int >::max ()) {
515539 throw std::runtime_error (strprintf (" Invalid height value (%s) for -testactivationheight=name@height." , arg));
516540 }
517- if (name == " segwit" ) {
518- consensus.SegwitHeight = int {height};
519- } else if (name == " bip34" ) {
520- consensus.BIP34Height = int {height};
521- } else if (name == " dersig" ) {
522- consensus.BIP66Height = int {height};
523- } else if (name == " cltv" ) {
524- consensus.BIP65Height = int {height};
525- } else if (name == " csv" ) {
526- consensus.CSVHeight = int {height};
541+
542+ const auto deployment_name{arg.substr (0 , found)};
543+ if (const auto buried_deployment = GetBuriedDeployment (deployment_name)) {
544+ options.activation_heights [*buried_deployment] = height;
527545 } else {
528546 throw std::runtime_error (strprintf (" Invalid name (%s) for -testactivationheight=name@height." , arg));
529547 }
530548 }
531- }
532-
533- void CRegTestParams::UpdateActivationParametersFromArgs (const ArgsManager& args)
534- {
535- MaybeUpdateHeights (args, consensus);
536549
537550 if (!args.IsArgSet (" -vbparams" )) return ;
538551
@@ -541,23 +554,26 @@ void CRegTestParams::UpdateActivationParametersFromArgs(const ArgsManager& args)
541554 if (vDeploymentParams.size () < 3 || 4 < vDeploymentParams.size ()) {
542555 throw std::runtime_error (" Version bits parameters malformed, expecting deployment:start:end[:min_activation_height]" );
543556 }
544- int64_t nStartTime, nTimeout;
545- int min_activation_height = 0 ;
546- if (!ParseInt64 (vDeploymentParams[1 ], &nStartTime)) {
557+ CChainParams::VersionBitsParameters vbparams{};
558+ if (!ParseInt64 (vDeploymentParams[1 ], &vbparams.start_time )) {
547559 throw std::runtime_error (strprintf (" Invalid nStartTime (%s)" , vDeploymentParams[1 ]));
548560 }
549- if (!ParseInt64 (vDeploymentParams[2 ], &nTimeout )) {
561+ if (!ParseInt64 (vDeploymentParams[2 ], &vbparams. timeout )) {
550562 throw std::runtime_error (strprintf (" Invalid nTimeout (%s)" , vDeploymentParams[2 ]));
551563 }
552- if (vDeploymentParams.size () >= 4 && !ParseInt32 (vDeploymentParams[3 ], &min_activation_height)) {
553- throw std::runtime_error (strprintf (" Invalid min_activation_height (%s)" , vDeploymentParams[3 ]));
564+ if (vDeploymentParams.size () >= 4 ) {
565+ if (!ParseInt32 (vDeploymentParams[3 ], &vbparams.min_activation_height )) {
566+ throw std::runtime_error (strprintf (" Invalid min_activation_height (%s)" , vDeploymentParams[3 ]));
567+ }
568+ } else {
569+ vbparams.min_activation_height = 0 ;
554570 }
555571 bool found = false ;
556572 for (int j=0 ; j < (int )Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++j) {
557573 if (vDeploymentParams[0 ] == VersionBitsDeploymentInfo[j].name ) {
558- UpdateVersionBitsParameters ( Consensus::DeploymentPos (j), nStartTime, nTimeout, min_activation_height) ;
574+ options. version_bits_parameters [ Consensus::DeploymentPos (j)] = vbparams ;
559575 found = true ;
560- LogPrintf (" Setting version bits activation parameters for %s to start=%ld, timeout=%ld, min_activation_height=%d\n " , vDeploymentParams[0 ], nStartTime, nTimeout, min_activation_height);
576+ LogPrintf (" Setting version bits activation parameters for %s to start=%ld, timeout=%ld, min_activation_height=%d\n " , vDeploymentParams[0 ], vbparams. start_time , vbparams. timeout , vbparams. min_activation_height );
561577 break ;
562578 }
563579 }
@@ -585,7 +601,9 @@ std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, c
585601 ReadSigNetArgs (args, opts);
586602 return std::make_unique<const SigNetParams>(opts);
587603 } else if (chain == CBaseChainParams::REGTEST) {
588- return std::unique_ptr<CChainParams>(new CRegTestParams (args));
604+ auto opts = CChainParams::RegTestOptions{};
605+ ReadRegTestArgs (args, opts);
606+ return std::make_unique<const CRegTestParams>(opts);
589607 }
590608 throw std::runtime_error (strprintf (" %s: Unknown chain %s." , __func__, chain));
591609}
0 commit comments