Skip to content

Include PoS NetUpgrades in RegTest when specified from the command line #1021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions common/src/chain/upgrades/netupgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::ops::Range;

use crate::chain::config::ChainType;
use crate::chain::pow::limit;
use crate::chain::PoSChainConfig;
use crate::chain::{create_unittest_pos_config, initial_difficulty, PoSChainConfig};
use crate::primitives::{BlockHeight, Compact};

#[derive(Debug, Clone)]
Expand All @@ -32,15 +32,29 @@ impl NetUpgrades<UpgradeVersion> {
}),
)])
}
}

impl NetUpgrades<UpgradeVersion> {
pub fn unit_tests() -> Self {
Self(vec![(
BlockHeight::zero(),
UpgradeVersion::ConsensusUpgrade(ConsensusUpgrade::IgnoreConsensus),
)])
}

pub fn regtest_with_pos() -> Self {
Self(vec![
(
BlockHeight::zero(),
UpgradeVersion::ConsensusUpgrade(ConsensusUpgrade::IgnoreConsensus),
),
(
BlockHeight::new(1),
UpgradeVersion::ConsensusUpgrade(ConsensusUpgrade::PoS {
initial_difficulty: initial_difficulty(ChainType::Regtest).into(),
config: create_unittest_pos_config(),
}),
),
])
}
}

pub trait Activate {
Expand Down
4 changes: 4 additions & 0 deletions node-lib/src/regtest_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@ pub struct ChainConfigOptions {
/// The maximum smart contracts size ib block in bytes.
#[clap(long)]
pub chain_max_block_size_with_smart_contracts: Option<usize>,

/// PoS NetUpgrade override after Genesis
#[clap(long)]
pub chain_pos_netupgrades: Option<bool>,
}
11 changes: 9 additions & 2 deletions node-lib/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ use paste::paste;

use chainstate::rpc::ChainstateRpcServer;
use common::{
chain::config::{
Builder as ChainConfigBuilder, ChainConfig, ChainType, EmissionScheduleTabular,
chain::{
config::{Builder as ChainConfigBuilder, ChainConfig, ChainType, EmissionScheduleTabular},
NetUpgrades,
},
primitives::semver::SemVer,
};
Expand Down Expand Up @@ -282,6 +283,7 @@ fn regtest_chain_config(options: &ChainConfigOptions) -> Result<ChainConfig> {
chain_max_block_header_size,
chain_max_block_size_with_standard_txs,
chain_max_block_size_with_smart_contracts,
chain_pos_netupgrades,
} = options;

let mut builder = ChainConfigBuilder::new(ChainType::Regtest);
Expand Down Expand Up @@ -319,6 +321,11 @@ fn regtest_chain_config(options: &ChainConfigOptions) -> Result<ChainConfig> {
update_builder!(max_block_size_with_standard_txs);
update_builder!(max_block_size_with_smart_contracts);

if chain_pos_netupgrades.unwrap_or(false) {
let net_upgrades = NetUpgrades::regtest_with_pos();
builder = builder.net_upgrades(net_upgrades);
}

Ok(builder.build())
}

Expand Down