rococo-runtime: RococoGenesisExt removed (#1490)

[`RococoGenesisExt`](https://github.com/paritytech/polkadot-sdk/blob/a414ea7515c9cdc81f1d12410e646afc148250e8/polkadot/node/service/src/chain_spec.rs#L152-L171)
is removed. It was the hack to allow overwriting
`EpochDurationInBlocks`. Removal of `RococGenesisExt` prevents from
manipulating the state to change the runtime constants.

Changes:
- Environment variable which controls the `time::EpochDurationInBlocks`
value was added: `ROCOCO_EPOCH_DURATION` (epoch duration will be set to
the value of env),
- `10,100,600` versions of rococo-runtime are built in CI and put into `polkadot-debug` docker image.

`rococo-runtime` building examples:
- to build runtime for `versi_staging_testnet` which had
EpochDurationInBlocks set to 100:
  ```
ROCOCO_EPOCH_DURATION=100 cargo build --features=fast-runtime -p
rococo-runtime
  ```
- to build runtime for `wococo_development`
  ```
ROCOCO_EPOCH_DURATION=10 cargo build --features=fast-runtime -p
rococo-runtime
  ```
- to build `versi-staging` chain spec:
  ```
ROCOCO_EPOCH_DURATION=100 cargo run -p polkadot --features=fast-runtime
-- build-spec --chain versi-staging --raw
  ```
- to build `wococo-dev` chain spec:
  ```
ROCOCO_EPOCH_DURATION=10 cargo run -p polkadot --features=fast-runtime
-- build-spec --chain wococo-dev --raw
  ```

It is also possible to change the epoch duration by replacing the `code` field in the chain spec with the hex dump of pre-built runtime wasm blob (because the epoch duration is hard-coded into wasm blob).

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
Michal Kucharczyk
2023-09-28 18:29:12 +02:00
committed by GitHub
parent c1eb342b14
commit 50242a61d7
10 changed files with 46 additions and 75 deletions
+9 -63
View File
@@ -84,7 +84,7 @@ pub type WestendChainSpec = GenericChainSpec;
/// The `ChainSpec` parameterized for the rococo runtime.
#[cfg(feature = "rococo-native")]
pub type RococoChainSpec = service::GenericChainSpec<RococoGenesisExt, Extensions>;
pub type RococoChainSpec = service::GenericChainSpec<rococo::RuntimeGenesisConfig, Extensions>;
/// The `ChainSpec` parameterized for the `versi` runtime.
///
@@ -96,30 +96,6 @@ pub type VersiChainSpec = RococoChainSpec;
#[cfg(not(feature = "rococo-native"))]
pub type RococoChainSpec = GenericChainSpec;
/// 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::RuntimeGenesisConfig,
/// The session length in blocks.
///
/// If `None` is supplied, the default value is used.
session_length_in_blocks: Option<u32>,
}
#[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<GenericChainSpec, String> {
GenericChainSpec::from_json_bytes(&include_bytes!("../chain-specs/polkadot.json")[..])
}
@@ -780,10 +756,7 @@ pub fn rococo_staging_testnet_config() -> Result<RococoChainSpec, String> {
"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)])
@@ -817,10 +790,7 @@ pub fn versi_staging_testnet_config() -> Result<RococoChainSpec, String> {
"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)])
@@ -1130,11 +1100,7 @@ pub fn rococo_development_config() -> Result<RococoChainSpec, String> {
"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),
@@ -1153,11 +1119,7 @@ pub fn versi_development_config() -> Result<RococoChainSpec, String> {
"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"),
@@ -1177,11 +1139,7 @@ pub fn wococo_development_config() -> Result<RococoChainSpec, String> {
"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),
@@ -1239,11 +1197,7 @@ pub fn rococo_local_testnet_config() -> Result<RococoChainSpec, String> {
"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),
@@ -1278,11 +1232,7 @@ pub fn wococo_local_testnet_config() -> Result<RococoChainSpec, String> {
"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),
@@ -1317,11 +1267,7 @@ pub fn versi_local_testnet_config() -> Result<RococoChainSpec, String> {
"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"),