From 982d220917d9b497d84124e2a40857aa1f1ebbec Mon Sep 17 00:00:00 2001 From: NachoPal Date: Tue, 21 Jun 2022 12:55:46 +0200 Subject: [PATCH] babe+epoch_time modificaction --- node/service/src/chain_spec.rs | 72 ++++------------------------- runtime/rococo/constants/src/lib.rs | 5 +- runtime/rococo/src/lib.rs | 20 ++++---- 3 files changed, 19 insertions(+), 78 deletions(-) diff --git a/node/service/src/chain_spec.rs b/node/service/src/chain_spec.rs index f6743399f54d..d5b867997b23 100644 --- a/node/service/src/chain_spec.rs +++ b/node/service/src/chain_spec.rs @@ -106,7 +106,7 @@ pub type WestendChainSpec = DummyChainSpec; /// The `ChainSpec` parameterized for the rococo runtime. #[cfg(feature = "rococo-native")] -pub type RococoChainSpec = service::GenericChainSpec; +pub type RococoChainSpec = service::GenericChainSpec; /// The `ChainSpec` parameterized for the `versi` runtime. /// @@ -118,30 +118,6 @@ pub type VersiChainSpec = RococoChainSpec; #[cfg(not(feature = "rococo-native"))] pub type RococoChainSpec = DummyChainSpec; -/// Extension for the Rococo genesis config to support a custom changes to the genesis state. -#[derive(serde::Serialize, serde::Deserialize)] -#[cfg(feature = "rococo-native")] -pub struct RococoGenesisExt { - /// The runtime genesis config. - runtime_genesis_config: rococo::GenesisConfig, - /// The session length in blocks. - /// - /// If `None` is supplied, the default value is used. - session_length_in_blocks: Option, -} - -#[cfg(feature = "rococo-native")] -impl sp_runtime::BuildStorage for RococoGenesisExt { - fn assimilate_storage(&self, storage: &mut sp_core::storage::Storage) -> Result<(), String> { - sp_state_machine::BasicExternalities::execute_with_storage(storage, || { - if let Some(length) = self.session_length_in_blocks.as_ref() { - rococo_runtime_constants::time::EpochDurationInBlocks::set(length); - } - }); - self.runtime_genesis_config.assimilate_storage(storage) - } -} - pub fn polkadot_config() -> Result { PolkadotChainSpec::from_json_bytes(&include_bytes!("../res/polkadot.json")[..]) } @@ -1183,10 +1159,7 @@ pub fn rococo_staging_testnet_config() -> Result { "Rococo Staging Testnet", "rococo_staging_testnet", ChainType::Live, - move || RococoGenesisExt { - runtime_genesis_config: rococo_staging_testnet_config_genesis(wasm_binary), - session_length_in_blocks: None, - }, + move || rococo_staging_testnet_config_genesis(wasm_binary), boot_nodes, Some( TelemetryEndpoints::new(vec![(ROCOCO_STAGING_TELEMETRY_URL.to_string(), 0)]) @@ -1220,10 +1193,7 @@ pub fn versi_staging_testnet_config() -> Result { "Versi Staging Testnet", "versi_staging_testnet", ChainType::Live, - move || RococoGenesisExt { - runtime_genesis_config: rococo_staging_testnet_config_genesis(wasm_binary), - session_length_in_blocks: Some(100), - }, + move || rococo_staging_testnet_config_genesis(wasm_binary), boot_nodes, Some( TelemetryEndpoints::new(vec![(VERSI_STAGING_TELEMETRY_URL.to_string(), 0)]) @@ -1772,11 +1742,7 @@ pub fn rococo_development_config() -> Result { "Development", "rococo_dev", ChainType::Development, - move || RococoGenesisExt { - runtime_genesis_config: rococo_development_config_genesis(wasm_binary), - // Use 1 minute session length. - session_length_in_blocks: Some(10), - }, + move || rococo_development_config_genesis(wasm_binary), vec![], None, Some(DEFAULT_PROTOCOL_ID), @@ -1795,11 +1761,7 @@ pub fn versi_development_config() -> Result { "Development", "versi_dev", ChainType::Development, - move || RococoGenesisExt { - runtime_genesis_config: rococo_development_config_genesis(wasm_binary), - // Use 1 minute session length. - session_length_in_blocks: Some(10), - }, + move || rococo_development_config_genesis(wasm_binary), vec![], None, Some("versi"), @@ -1819,11 +1781,7 @@ pub fn wococo_development_config() -> Result { "Development", "wococo_dev", ChainType::Development, - move || RococoGenesisExt { - runtime_genesis_config: rococo_development_config_genesis(wasm_binary), - // Use 1 minute session length. - session_length_in_blocks: Some(10), - }, + move || rococo_development_config_genesis(wasm_binary), vec![], None, Some(WOCOCO_DEV_PROTOCOL_ID), @@ -1948,11 +1906,7 @@ pub fn rococo_local_testnet_config() -> Result { "Rococo Local Testnet", "rococo_local_testnet", ChainType::Local, - move || RococoGenesisExt { - runtime_genesis_config: rococo_local_testnet_genesis(wasm_binary), - // Use 1 minute session length. - session_length_in_blocks: Some(10), - }, + move || rococo_local_testnet_genesis(wasm_binary), vec![], None, Some(DEFAULT_PROTOCOL_ID), @@ -1987,11 +1941,7 @@ pub fn wococo_local_testnet_config() -> Result { "Wococo Local Testnet", "wococo_local_testnet", ChainType::Local, - move || RococoGenesisExt { - runtime_genesis_config: wococo_local_testnet_genesis(wasm_binary), - // Use 1 minute session length. - session_length_in_blocks: Some(10), - }, + move || wococo_local_testnet_genesis(wasm_binary), vec![], None, Some(DEFAULT_PROTOCOL_ID), @@ -2026,11 +1976,7 @@ pub fn versi_local_testnet_config() -> Result { "Versi Local Testnet", "versi_local_testnet", ChainType::Local, - move || RococoGenesisExt { - runtime_genesis_config: versi_local_testnet_genesis(wasm_binary), - // Use 1 minute session length. - session_length_in_blocks: Some(10), - }, + move || versi_local_testnet_genesis(wasm_binary), vec![], None, Some("versi"), diff --git a/runtime/rococo/constants/src/lib.rs b/runtime/rococo/constants/src/lib.rs index 7aec525fed33..c652ead72cb4 100644 --- a/runtime/rococo/constants/src/lib.rs +++ b/runtime/rococo/constants/src/lib.rs @@ -41,10 +41,7 @@ pub mod time { use runtime_common::prod_or_fast; pub const MILLISECS_PER_BLOCK: Moment = 6000; pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; - pub const DEFAULT_EPOCH_DURATION: BlockNumber = prod_or_fast!(1 * HOURS, 1 * MINUTES); - frame_support::parameter_types! { - pub storage EpochDurationInBlocks: BlockNumber = DEFAULT_EPOCH_DURATION; - } + pub const EPOCH_DURATION_IN_SLOTS: BlockNumber = prod_or_fast!(1 * HOURS, 1 * MINUTES); // These time units are defined in number of blocks. pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index 159acb01620f..48ce748e93d2 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -249,20 +249,18 @@ impl pallet_preimage::Config for Runtime { } parameter_types! { - // pub EpochDuration: u64 = prod_or_fast!( - // EPOCH_DURATION_IN_SLOTS as u64, - // 2 * MINUTES as u64, - // "ROC_EPOCH_DURATION" - // ); + pub EpochDuration: u64 = prod_or_fast!( + EPOCH_DURATION_IN_SLOTS as u64, + 2 * MINUTES as u64, + "ROC_EPOCH_DURATION" + ); pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK; - // TODO: Staking - // pub ReportLongevity: u64 = - // BondingDuration::get() as u64 * SessionsPerEra::get() as u64 * EpochDuration::get(); - pub ReportLongevity: u64 = EpochDurationInBlocks::get() as u64 * 10; + pub ReportLongevity: u64 = + BondingDuration::get() as u64 * SessionsPerEra::get() as u64 * EpochDuration::get(); } impl pallet_babe::Config for Runtime { - type EpochDuration = EpochDurationInBlocks; // TODO: Babe -> type EpochDuration = EpochDuration; + type EpochDuration = EpochDuration; type ExpectedBlockTime = ExpectedBlockTime; // session module is the trigger @@ -2280,7 +2278,7 @@ sp_api::impl_runtime_apis! { // babe_primitives::BabeGenesisConfiguration { slot_duration: Babe::slot_duration(), - epoch_length: EpochDurationInBlocks::get().into(), // TODO: Babe -> epoch_length: EpochDuration::get().into() + epoch_length: EpochDuration::get().into(), c: BABE_GENESIS_EPOCH_CONFIG.c, genesis_authorities: Babe::authorities().to_vec(), randomness: Babe::randomness(),