Skip to content

Commit d686c42

Browse files
authored
Merge pull request #1021 from mintlayer/alfie/pos-netupgrades
Include PoS NetUpgrades in RegTest when specified from the command line
2 parents fd8951a + e2e1be2 commit d686c42

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

common/src/chain/upgrades/netupgrade.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::ops::Range;
1717

1818
use crate::chain::config::ChainType;
1919
use crate::chain::pow::limit;
20-
use crate::chain::PoSChainConfig;
20+
use crate::chain::{create_unittest_pos_config, initial_difficulty, PoSChainConfig};
2121
use crate::primitives::{BlockHeight, Compact};
2222

2323
#[derive(Debug, Clone)]
@@ -32,15 +32,29 @@ impl NetUpgrades<UpgradeVersion> {
3232
}),
3333
)])
3434
}
35-
}
3635

37-
impl NetUpgrades<UpgradeVersion> {
3836
pub fn unit_tests() -> Self {
3937
Self(vec![(
4038
BlockHeight::zero(),
4139
UpgradeVersion::ConsensusUpgrade(ConsensusUpgrade::IgnoreConsensus),
4240
)])
4341
}
42+
43+
pub fn regtest_with_pos() -> Self {
44+
Self(vec![
45+
(
46+
BlockHeight::zero(),
47+
UpgradeVersion::ConsensusUpgrade(ConsensusUpgrade::IgnoreConsensus),
48+
),
49+
(
50+
BlockHeight::new(1),
51+
UpgradeVersion::ConsensusUpgrade(ConsensusUpgrade::PoS {
52+
initial_difficulty: initial_difficulty(ChainType::Regtest).into(),
53+
config: create_unittest_pos_config(),
54+
}),
55+
),
56+
])
57+
}
4458
}
4559

4660
pub trait Activate {

node-lib/src/regtest_options.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,8 @@ pub struct ChainConfigOptions {
6161
/// The maximum smart contracts size ib block in bytes.
6262
#[clap(long)]
6363
pub chain_max_block_size_with_smart_contracts: Option<usize>,
64+
65+
/// PoS NetUpgrade override after Genesis
66+
#[clap(long)]
67+
pub chain_pos_netupgrades: Option<bool>,
6468
}

node-lib/src/runner.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ use paste::paste;
2929

3030
use chainstate::rpc::ChainstateRpcServer;
3131
use common::{
32-
chain::config::{
33-
Builder as ChainConfigBuilder, ChainConfig, ChainType, EmissionScheduleTabular,
32+
chain::{
33+
config::{Builder as ChainConfigBuilder, ChainConfig, ChainType, EmissionScheduleTabular},
34+
NetUpgrades,
3435
},
3536
primitives::semver::SemVer,
3637
};
@@ -282,6 +283,7 @@ fn regtest_chain_config(options: &ChainConfigOptions) -> Result<ChainConfig> {
282283
chain_max_block_header_size,
283284
chain_max_block_size_with_standard_txs,
284285
chain_max_block_size_with_smart_contracts,
286+
chain_pos_netupgrades,
285287
} = options;
286288

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

324+
if chain_pos_netupgrades.unwrap_or(false) {
325+
let net_upgrades = NetUpgrades::regtest_with_pos();
326+
builder = builder.net_upgrades(net_upgrades);
327+
}
328+
322329
Ok(builder.build())
323330
}
324331

0 commit comments

Comments
 (0)