@@ -399,7 +399,8 @@ void ReadSigNetArgs(const ArgsManager& args, CChainParams::SigNetOptions& option
399
399
class CRegTestParams : public CChainParams
400
400
{
401
401
public:
402
- explicit CRegTestParams (const ArgsManager& args) {
402
+ explicit CRegTestParams (const RegTestOptions& opts)
403
+ {
403
404
strNetworkID = CBaseChainParams::REGTEST;
404
405
consensus.signet_blocks = false ;
405
406
consensus.signet_challenge .clear ();
@@ -437,11 +438,33 @@ class CRegTestParams : public CChainParams
437
438
pchMessageStart[2 ] = 0xb5 ;
438
439
pchMessageStart[3 ] = 0xda ;
439
440
nDefaultPort = 18444 ;
440
- nPruneAfterHeight = args. GetBoolArg ( " - fastprune" , false ) ? 100 : 1000 ;
441
+ nPruneAfterHeight = opts. fastprune ? 100 : 1000 ;
441
442
m_assumed_blockchain_size = 0 ;
442
443
m_assumed_chain_state_size = 0 ;
443
444
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
+ }
445
468
446
469
genesis = CreateGenesisBlock (1296688602 , 2 , 0x207fffff , 1 , 50 * COIN);
447
470
consensus.hashGenesisBlock = genesis.GetHash ();
@@ -498,41 +521,31 @@ class CRegTestParams : public CChainParams
498
521
consensus.vDeployments [d].nTimeout = nTimeout;
499
522
consensus.vDeployments [d].min_activation_height = min_activation_height;
500
523
}
501
- void UpdateActivationParametersFromArgs (const ArgsManager& args);
502
524
};
503
525
504
- static void MaybeUpdateHeights (const ArgsManager& args, Consensus::Params& consensus )
526
+ void ReadRegTestArgs (const ArgsManager& args, CChainParams::RegTestOptions& options )
505
527
{
528
+ if (auto value = args.GetBoolArg (" -fastprune" )) options.fastprune = *value;
529
+
506
530
for (const std::string& arg : args.GetArgs (" -testactivationheight" )) {
507
531
const auto found{arg.find (' @' )};
508
532
if (found == std::string::npos) {
509
533
throw std::runtime_error (strprintf (" Invalid format (%s) for -testactivationheight=name@height." , arg));
510
534
}
511
- const auto name{arg. substr ( 0 , found)};
535
+
512
536
const auto value{arg.substr (found + 1 )};
513
537
int32_t height;
514
538
if (!ParseInt32 (value, &height) || height < 0 || height >= std::numeric_limits<int >::max ()) {
515
539
throw std::runtime_error (strprintf (" Invalid height value (%s) for -testactivationheight=name@height." , arg));
516
540
}
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;
527
545
} else {
528
546
throw std::runtime_error (strprintf (" Invalid name (%s) for -testactivationheight=name@height." , arg));
529
547
}
530
548
}
531
- }
532
-
533
- void CRegTestParams::UpdateActivationParametersFromArgs (const ArgsManager& args)
534
- {
535
- MaybeUpdateHeights (args, consensus);
536
549
537
550
if (!args.IsArgSet (" -vbparams" )) return ;
538
551
@@ -541,23 +554,26 @@ void CRegTestParams::UpdateActivationParametersFromArgs(const ArgsManager& args)
541
554
if (vDeploymentParams.size () < 3 || 4 < vDeploymentParams.size ()) {
542
555
throw std::runtime_error (" Version bits parameters malformed, expecting deployment:start:end[:min_activation_height]" );
543
556
}
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 )) {
547
559
throw std::runtime_error (strprintf (" Invalid nStartTime (%s)" , vDeploymentParams[1 ]));
548
560
}
549
- if (!ParseInt64 (vDeploymentParams[2 ], &nTimeout )) {
561
+ if (!ParseInt64 (vDeploymentParams[2 ], &vbparams. timeout )) {
550
562
throw std::runtime_error (strprintf (" Invalid nTimeout (%s)" , vDeploymentParams[2 ]));
551
563
}
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 ;
554
570
}
555
571
bool found = false ;
556
572
for (int j=0 ; j < (int )Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++j) {
557
573
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 ;
559
575
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 );
561
577
break ;
562
578
}
563
579
}
@@ -585,7 +601,9 @@ std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, c
585
601
ReadSigNetArgs (args, opts);
586
602
return std::make_unique<const SigNetParams>(opts);
587
603
} 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);
589
607
}
590
608
throw std::runtime_error (strprintf (" %s: Unknown chain %s." , __func__, chain));
591
609
}
0 commit comments