mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 07:01:05 +00:00
Support variable session length for Rococo chains at genesis (#2167)
This pr adds support to change the session length of a Rococo chain at genesis. This is rather useful because Rococo has a session length of 1 hour, while on rococo-local you will now get 1 minute. This improves the dev experience, because a parachain is only going live at the start of a new session.
This commit is contained in:
@@ -66,7 +66,32 @@ pub type KusamaChainSpec = service::GenericChainSpec<kusama::GenesisConfig, Exte
|
||||
pub type WestendChainSpec = service::GenericChainSpec<westend::GenesisConfig, Extensions>;
|
||||
|
||||
/// The `ChainSpec` parametrized for the rococo runtime.
|
||||
pub type RococoChainSpec = service::GenericChainSpec<rococo::GenesisConfig, Extensions>;
|
||||
pub type RococoChainSpec = service::GenericChainSpec<RococoGenesisExt, Extensions>;
|
||||
|
||||
/// Extension for the Rococo genesis config to support a custom changes to the genesis state.
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
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<u32>,
|
||||
}
|
||||
|
||||
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::constants::time::EpochDurationInBlocks::set(length);
|
||||
}
|
||||
});
|
||||
self.runtime_genesis_config.assimilate_storage(storage)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn polkadot_config() -> Result<PolkadotChainSpec, String> {
|
||||
PolkadotChainSpec::from_json_bytes(&include_bytes!("../res/polkadot.json")[..])
|
||||
@@ -925,7 +950,10 @@ pub fn rococo_staging_testnet_config() -> Result<RococoChainSpec, String> {
|
||||
"Rococo Staging Testnet",
|
||||
"rococo_staging_testnet",
|
||||
ChainType::Live,
|
||||
move || rococo_staging_testnet_config_genesis(wasm_binary),
|
||||
move || RococoGenesisExt {
|
||||
runtime_genesis_config: rococo_staging_testnet_config_genesis(wasm_binary),
|
||||
session_length_in_blocks: None,
|
||||
},
|
||||
boot_nodes,
|
||||
Some(
|
||||
TelemetryEndpoints::new(vec![(ROCOCO_STAGING_TELEMETRY_URL.to_string(), 0)])
|
||||
@@ -1542,7 +1570,11 @@ pub fn rococo_local_testnet_config() -> Result<RococoChainSpec, String> {
|
||||
"Rococo Local Testnet",
|
||||
"rococo_local_testnet",
|
||||
ChainType::Local,
|
||||
move || rococo_local_testnet_genesis(wasm_binary),
|
||||
move || RococoGenesisExt {
|
||||
runtime_genesis_config: rococo_local_testnet_genesis(wasm_binary),
|
||||
// Use 1 minute session length.
|
||||
session_length_in_blocks: Some(10),
|
||||
},
|
||||
vec![],
|
||||
None,
|
||||
Some(DEFAULT_PROTOCOL_ID),
|
||||
|
||||
Reference in New Issue
Block a user