From 98a32ac4146c79a7a380631f19d688136a2f4de1 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 5 Feb 2025 11:36:11 +0100 Subject: [PATCH 01/11] add coretime-westend development and local testnet presets --- Cargo.lock | 2 + .../coretime/coretime-westend/Cargo.toml | 4 + .../src/genesis_config_presets.rs | 103 ++++++++++++++++++ .../coretime/coretime-westend/src/lib.rs | 5 +- 4 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 cumulus/parachains/runtimes/coretime/coretime-westend/src/genesis_config_presets.rs diff --git a/Cargo.lock b/Cargo.lock index c09ed4573340..de5fa73e6f74 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4239,12 +4239,14 @@ dependencies = [ "polkadot-runtime-common 7.0.0", "scale-info", "serde", + "serde_json", "sp-api 26.0.0", "sp-block-builder 26.0.0", "sp-consensus-aura 0.32.0", "sp-core 28.0.0", "sp-genesis-builder 0.8.0", "sp-inherents 26.0.0", + "sp-keyring 31.0.0", "sp-offchain 26.0.0", "sp-runtime 31.0.1", "sp-session 27.0.0", diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml b/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml index 915926ff9894..b0a54b7d6204 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml @@ -20,6 +20,7 @@ hex-literal = { workspace = true, default-features = true } log = { workspace = true } scale-info = { features = ["derive"], workspace = true } serde = { optional = true, features = ["derive"], workspace = true, default-features = true } +serde_json = { features = ["alloc"], workspace = true } # Substrate frame-benchmarking = { optional = true, workspace = true } @@ -48,6 +49,7 @@ sp-consensus-aura = { workspace = true } sp-core = { workspace = true } sp-genesis-builder = { workspace = true } sp-inherents = { workspace = true } +sp-keyring = { workspace = true } sp-offchain = { workspace = true } sp-runtime = { workspace = true } sp-session = { workspace = true } @@ -128,12 +130,14 @@ std = [ "polkadot-runtime-common/std", "scale-info/std", "serde", + "serde_json/std", "sp-api/std", "sp-block-builder/std", "sp-consensus-aura/std", "sp-core/std", "sp-genesis-builder/std", "sp-inherents/std", + "sp-keyring/std", "sp-offchain/std", "sp-runtime/std", "sp-session/std", diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/genesis_config_presets.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/genesis_config_presets.rs new file mode 100644 index 000000000000..e521b61f450e --- /dev/null +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/genesis_config_presets.rs @@ -0,0 +1,103 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! # Coretime Westend Runtime genesis config presets + +use crate::*; +use alloc::{vec, vec::Vec}; +use cumulus_primitives_core::ParaId; +use frame_support::build_struct_json_patch; +use parachains_common::{AccountId, AuraId}; +use sp_genesis_builder::PresetId; +use sp_keyring::Sr25519Keyring; +use testnet_parachains_constants::westend::{ + currency::UNITS as WND, xcm_version::SAFE_XCM_VERSION, +}; + +const CORETIME_WESTEND_ED: Balance = ExistentialDeposit::get(); + +fn coretime_westend_genesis( + invulnerables: Vec<(AccountId, AuraId)>, + endowed_accounts: Vec, + endowment: Balance, + id: ParaId, +) -> serde_json::Value { + build_struct_json_patch!(RuntimeGenesisConfig { + balances: BalancesConfig { + balances: endowed_accounts.iter().cloned().map(|k| (k, endowment)).collect(), + }, + parachain_info: ParachainInfoConfig { parachain_id: id }, + collator_selection: CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: CORETIME_WESTEND_ED * 16, + }, + session: SessionConfig { + keys: invulnerables + .into_iter() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc, // validator id + SessionKeys { aura }, // session keys + ) + }) + .collect(), + }, + polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) }, + }) +} + +/// Provides the JSON representation of predefined genesis config for given `id`. +pub fn get_preset(id: &PresetId) -> Option> { + let patch = match id.as_ref() { + sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET => coretime_westend_genesis( + // initial collators. + vec![ + (Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into()), + (Sr25519Keyring::Bob.to_account_id(), Sr25519Keyring::Bob.public().into()), + ], + Sr25519Keyring::well_known().map(|k| k.to_account_id()).collect(), + WND * 1_000_000, + 1000.into(), + ), + sp_genesis_builder::DEV_RUNTIME_PRESET => coretime_westend_genesis( + // initial collators. + vec![(Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into())], + vec![ + Sr25519Keyring::Alice.to_account_id(), + Sr25519Keyring::Bob.to_account_id(), + Sr25519Keyring::AliceStash.to_account_id(), + Sr25519Keyring::BobStash.to_account_id(), + ], + WND * 1_000_000, + 1000.into(), + ), + _ => return None, + }; + + Some( + serde_json::to_string(&patch) + .expect("serialization to json is expected to work. qed.") + .into_bytes(), + ) +} + +/// List of supported presets. +pub fn preset_names() -> Vec { + vec![ + PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET), + PresetId::from(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET), + ] +} diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs index 7312c9c1639d..851831c54348 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/lib.rs @@ -30,6 +30,7 @@ pub mod fast_runtime_binary { } mod coretime; +mod genesis_config_presets; mod weights; pub mod xcm_config; @@ -1161,11 +1162,11 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id, |_| None) + get_preset::(id, &genesis_config_presets::get_preset) } fn preset_names() -> Vec { - vec![] + genesis_config_presets::preset_names() } } From 4ec7b764ec07b0a17c84496793314420ede4a043 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 5 Feb 2025 13:00:59 +0100 Subject: [PATCH 02/11] remove obsolete bench_flags in runtimes-matrix.json --- .github/workflows/runtimes-matrix.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/runtimes-matrix.json b/.github/workflows/runtimes-matrix.json index 747b2bb4ac8f..ff32f2feced7 100644 --- a/.github/workflows/runtimes-matrix.json +++ b/.github/workflows/runtimes-matrix.json @@ -116,7 +116,7 @@ "header": "cumulus/file_header.txt", "template": "cumulus/templates/xcm-bench-template.hbs", "bench_features": "runtime-benchmarks", - "bench_flags": "--genesis-builder-policy=none --exclude-pallets=pallet_xcm,pallet_xcm_benchmarks::fungible,pallet_xcm_benchmarks::generic", + "bench_flags": "", "uri": "wss://westend-coretime-rpc.polkadot.io:443", "is_relay": false }, From b2212b5bacea3847e8dca8469a72ebe818cf78c8 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 5 Feb 2025 11:30:30 +0100 Subject: [PATCH 03/11] add coretime-rococo development and local testnet presets --- Cargo.lock | 2 + .../coretime/coretime-rococo/Cargo.toml | 4 + .../src/genesis_config_presets.rs | 101 ++++++++++++++++++ .../coretime/coretime-rococo/src/lib.rs | 5 +- 4 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 cumulus/parachains/runtimes/coretime/coretime-rococo/src/genesis_config_presets.rs diff --git a/Cargo.lock b/Cargo.lock index de5fa73e6f74..549e37c54c40 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4140,12 +4140,14 @@ dependencies = [ "rococo-runtime-constants 7.0.0", "scale-info", "serde", + "serde_json", "sp-api 26.0.0", "sp-block-builder 26.0.0", "sp-consensus-aura 0.32.0", "sp-core 28.0.0", "sp-genesis-builder 0.8.0", "sp-inherents 26.0.0", + "sp-keyring 31.0.0", "sp-offchain 26.0.0", "sp-runtime 31.0.1", "sp-session 27.0.0", diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml b/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml index 668b4cc6c7b9..844166c17c25 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml @@ -20,6 +20,7 @@ hex-literal = { workspace = true, default-features = true } log = { workspace = true } scale-info = { features = ["derive"], workspace = true } serde = { optional = true, features = ["derive"], workspace = true, default-features = true } +serde_json = { features = ["alloc"], workspace = true } # Substrate frame-benchmarking = { optional = true, workspace = true } @@ -49,6 +50,7 @@ sp-consensus-aura = { workspace = true } sp-core = { workspace = true } sp-genesis-builder = { workspace = true } sp-inherents = { workspace = true } +sp-keyring = { workspace = true } sp-offchain = { workspace = true } sp-runtime = { workspace = true } sp-session = { workspace = true } @@ -131,12 +133,14 @@ std = [ "rococo-runtime-constants/std", "scale-info/std", "serde", + "serde_json/std", "sp-api/std", "sp-block-builder/std", "sp-consensus-aura/std", "sp-core/std", "sp-genesis-builder/std", "sp-inherents/std", + "sp-keyring/std", "sp-offchain/std", "sp-runtime/std", "sp-session/std", diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/genesis_config_presets.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/genesis_config_presets.rs new file mode 100644 index 000000000000..6659ef53f75f --- /dev/null +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/genesis_config_presets.rs @@ -0,0 +1,101 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! # Coretime Rococo Runtime genesis config presets + +use crate::*; +use alloc::{vec, vec::Vec}; +use cumulus_primitives_core::ParaId; +use frame_support::build_struct_json_patch; +use parachains_common::{AccountId, AuraId}; +use sp_genesis_builder::PresetId; +use sp_keyring::Sr25519Keyring; +use testnet_parachains_constants::rococo::{currency::UNITS as ROC, xcm_version::SAFE_XCM_VERSION}; + +const CORETIME_ROCOCO_ED: Balance = ExistentialDeposit::get(); + +fn coretime_rococo_genesis( + invulnerables: Vec<(AccountId, AuraId)>, + endowed_accounts: Vec, + endowment: Balance, + id: ParaId, +) -> serde_json::Value { + build_struct_json_patch!(RuntimeGenesisConfig { + balances: BalancesConfig { + balances: endowed_accounts.iter().cloned().map(|k| (k, endowment)).collect(), + }, + parachain_info: ParachainInfoConfig { parachain_id: id }, + collator_selection: CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: CORETIME_ROCOCO_ED * 16, + }, + session: SessionConfig { + keys: invulnerables + .into_iter() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc, // validator id + SessionKeys { aura }, // session keys + ) + }) + .collect(), + }, + polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) }, + }) +} + +/// Provides the JSON representation of predefined genesis config for given `id`. +pub fn get_preset(id: &PresetId) -> Option> { + let patch = match id.as_ref() { + sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET => coretime_rococo_genesis( + // initial collators. + vec![ + (Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into()), + (Sr25519Keyring::Bob.to_account_id(), Sr25519Keyring::Bob.public().into()), + ], + Sr25519Keyring::well_known().map(|x| x.to_account_id()).collect(), + testnet_parachains_constants::rococo::currency::UNITS * 1_000_000, + 1000.into(), + ), + sp_genesis_builder::DEV_RUNTIME_PRESET => coretime_rococo_genesis( + // initial collators. + vec![(Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into())], + vec![ + Sr25519Keyring::Alice.to_account_id(), + Sr25519Keyring::Bob.to_account_id(), + Sr25519Keyring::AliceStash.to_account_id(), + Sr25519Keyring::BobStash.to_account_id(), + ], + ROC * 1_000_000, + 1000.into(), + ), + _ => return None, + }; + + Some( + serde_json::to_string(&patch) + .expect("serialization to json is expected to work. qed.") + .into_bytes(), + ) +} + +/// List of supported presets. +pub fn preset_names() -> Vec { + vec![ + PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET), + PresetId::from(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET), + ] +} diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index 622a40e1d8dc..28abe8eadff9 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -32,6 +32,7 @@ pub mod fast_runtime_binary { mod coretime; mod weights; pub mod xcm_config; +mod genesis_config_presets; extern crate alloc; @@ -1166,11 +1167,11 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id, |_| None) + get_preset::(id, &genesis_config_presets::get_preset) } fn preset_names() -> Vec { - vec![] + genesis_config_presets::preset_names() } } From c5ac0d11c9eb5e0f750930f4e90c8e108c7d5fc7 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 5 Feb 2025 12:57:24 +0100 Subject: [PATCH 04/11] remove bench_flags from runtime matrix --- .github/workflows/runtimes-matrix.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/runtimes-matrix.json b/.github/workflows/runtimes-matrix.json index ff32f2feced7..5f9815653777 100644 --- a/.github/workflows/runtimes-matrix.json +++ b/.github/workflows/runtimes-matrix.json @@ -105,7 +105,7 @@ "header": "cumulus/file_header.txt", "template": "cumulus/templates/xcm-bench-template.hbs", "bench_features": "runtime-benchmarks", - "bench_flags": "--genesis-builder-policy=none --exclude-pallets=pallet_xcm,pallet_xcm_benchmarks::fungible,pallet_xcm_benchmarks::generic", + "bench_flags": "", "uri": "wss://rococo-coretime-rpc.polkadot.io:443", "is_relay": false }, From 7758ab38e8f2da352780c4d41c0e3be67ce2c965 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 5 Feb 2025 12:58:16 +0100 Subject: [PATCH 05/11] fmt --- .../src/genesis_config_presets.rs | 78 +++++++++---------- .../coretime/coretime-rococo/src/lib.rs | 2 +- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/genesis_config_presets.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/genesis_config_presets.rs index 6659ef53f75f..540cd4731fa8 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/genesis_config_presets.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/genesis_config_presets.rs @@ -27,12 +27,12 @@ use testnet_parachains_constants::rococo::{currency::UNITS as ROC, xcm_version:: const CORETIME_ROCOCO_ED: Balance = ExistentialDeposit::get(); fn coretime_rococo_genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - endowment: Balance, - id: ParaId, + invulnerables: Vec<(AccountId, AuraId)>, + endowed_accounts: Vec, + endowment: Balance, + id: ParaId, ) -> serde_json::Value { - build_struct_json_patch!(RuntimeGenesisConfig { + build_struct_json_patch!(RuntimeGenesisConfig { balances: BalancesConfig { balances: endowed_accounts.iter().cloned().map(|k| (k, endowment)).collect(), }, @@ -59,43 +59,43 @@ fn coretime_rococo_genesis( /// Provides the JSON representation of predefined genesis config for given `id`. pub fn get_preset(id: &PresetId) -> Option> { - let patch = match id.as_ref() { - sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET => coretime_rococo_genesis( - // initial collators. - vec![ - (Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into()), - (Sr25519Keyring::Bob.to_account_id(), Sr25519Keyring::Bob.public().into()), - ], - Sr25519Keyring::well_known().map(|x| x.to_account_id()).collect(), - testnet_parachains_constants::rococo::currency::UNITS * 1_000_000, - 1000.into(), - ), - sp_genesis_builder::DEV_RUNTIME_PRESET => coretime_rococo_genesis( - // initial collators. - vec![(Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into())], - vec![ - Sr25519Keyring::Alice.to_account_id(), - Sr25519Keyring::Bob.to_account_id(), - Sr25519Keyring::AliceStash.to_account_id(), - Sr25519Keyring::BobStash.to_account_id(), - ], - ROC * 1_000_000, - 1000.into(), - ), - _ => return None, - }; + let patch = match id.as_ref() { + sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET => coretime_rococo_genesis( + // initial collators. + vec![ + (Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into()), + (Sr25519Keyring::Bob.to_account_id(), Sr25519Keyring::Bob.public().into()), + ], + Sr25519Keyring::well_known().map(|x| x.to_account_id()).collect(), + testnet_parachains_constants::rococo::currency::UNITS * 1_000_000, + 1000.into(), + ), + sp_genesis_builder::DEV_RUNTIME_PRESET => coretime_rococo_genesis( + // initial collators. + vec![(Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into())], + vec![ + Sr25519Keyring::Alice.to_account_id(), + Sr25519Keyring::Bob.to_account_id(), + Sr25519Keyring::AliceStash.to_account_id(), + Sr25519Keyring::BobStash.to_account_id(), + ], + ROC * 1_000_000, + 1000.into(), + ), + _ => return None, + }; - Some( - serde_json::to_string(&patch) - .expect("serialization to json is expected to work. qed.") - .into_bytes(), - ) + Some( + serde_json::to_string(&patch) + .expect("serialization to json is expected to work. qed.") + .into_bytes(), + ) } /// List of supported presets. pub fn preset_names() -> Vec { - vec![ - PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET), - PresetId::from(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET), - ] + vec![ + PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET), + PresetId::from(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET), + ] } diff --git a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs index 28abe8eadff9..340b48c6d040 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -30,9 +30,9 @@ pub mod fast_runtime_binary { } mod coretime; +mod genesis_config_presets; mod weights; pub mod xcm_config; -mod genesis_config_presets; extern crate alloc; From a8cb013bba0284a05e3038a61fb1665bf2e5bcfc Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 5 Feb 2025 14:00:16 +0100 Subject: [PATCH 06/11] cleanup coretime polkadot-parachain chain_specs --- .../src/chain_spec/coretime.rs | 407 +++++------------- .../polkadot-parachain/src/chain_spec/mod.rs | 22 +- 2 files changed, 132 insertions(+), 297 deletions(-) diff --git a/cumulus/polkadot-parachain/src/chain_spec/coretime.rs b/cumulus/polkadot-parachain/src/chain_spec/coretime.rs index fa865d7458cb..d5d208d402fa 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/coretime.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/coretime.rs @@ -16,314 +16,139 @@ use cumulus_primitives_core::ParaId; use polkadot_omni_node_lib::chain_spec::GenericChainSpec; -use sc_chain_spec::{ChainSpec, ChainType}; -use std::{borrow::Cow, str::FromStr}; +use sc_chain_spec::{ChainType, GenericChainSpec}; -/// Collects all supported Coretime configurations. -#[derive(Debug, PartialEq, Clone, Copy)] -pub enum CoretimeRuntimeType { - Kusama, - KusamaLocal, - - Polkadot, - PolkadotLocal, - - // Live - Rococo, - // Local - RococoLocal, - // Benchmarks - RococoDevelopment, +pub const CORETIME_PARA_ID: ParaId = ParaId::new(1005); - // Live - Westend, - // Local - WestendLocal, - // Benchmarks - WestendDevelopment, +pub fn coretime_westend_development_config() -> GenericChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("tokenSymbol".into(), "WND".into()); + properties.insert("tokenDecimals".into(), 12.into()); + + GenericChainSpec::builder( + coretime_westend_runtime::WASM_BINARY + .expect("WASM binary was not built, please build it!"), + Extensions { relay_chain: "westend".into(), para_id: CORETIME_PARA_ID }, + ) + .with_name("Westend Coretime Development") + .with_id("coretime-westend-dev") + .with_chain_type(ChainType::Local) + .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET) + .with_properties(properties) + .build() } -impl FromStr for CoretimeRuntimeType { - type Err = String; - - fn from_str(value: &str) -> Result { - match value { - kusama::CORETIME_KUSAMA => Ok(CoretimeRuntimeType::Kusama), - kusama::CORETIME_KUSAMA_LOCAL => Ok(CoretimeRuntimeType::KusamaLocal), - polkadot::CORETIME_POLKADOT => Ok(CoretimeRuntimeType::Polkadot), - polkadot::CORETIME_POLKADOT_LOCAL => Ok(CoretimeRuntimeType::PolkadotLocal), - rococo::CORETIME_ROCOCO => Ok(CoretimeRuntimeType::Rococo), - rococo::CORETIME_ROCOCO_LOCAL => Ok(CoretimeRuntimeType::RococoLocal), - rococo::CORETIME_ROCOCO_DEVELOPMENT => Ok(CoretimeRuntimeType::RococoDevelopment), - westend::CORETIME_WESTEND => Ok(CoretimeRuntimeType::Westend), - westend::CORETIME_WESTEND_LOCAL => Ok(CoretimeRuntimeType::WestendLocal), - westend::CORETIME_WESTEND_DEVELOPMENT => Ok(CoretimeRuntimeType::WestendDevelopment), - _ => Err(format!("Value '{}' is not configured yet", value)), - } - } +pub fn coretime_westend_local_config() -> GenericChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("tokenSymbol".into(), "WND".into()); + properties.insert("tokenDecimals".into(), 12.into()); + + GenericChainSpec::builder( + coretime_westend_runtime::WASM_BINARY + .expect("WASM binary was not built, please build it!"), + Extensions { relay_chain: "westend-local".into(), para_id: CORETIME_PARA_ID }, + ) + .with_name("Westend Coretime Local") + .with_id("coretime-westend-local") + .with_chain_type(ChainType::Local) + .with_genesis_config_preset_name(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET) + .with_properties(properties) + .build() } -impl From for &str { - fn from(runtime_type: CoretimeRuntimeType) -> Self { - match runtime_type { - CoretimeRuntimeType::Kusama => kusama::CORETIME_KUSAMA, - CoretimeRuntimeType::KusamaLocal => kusama::CORETIME_KUSAMA_LOCAL, - CoretimeRuntimeType::Polkadot => polkadot::CORETIME_POLKADOT, - CoretimeRuntimeType::PolkadotLocal => polkadot::CORETIME_POLKADOT_LOCAL, - CoretimeRuntimeType::Rococo => rococo::CORETIME_ROCOCO, - CoretimeRuntimeType::RococoLocal => rococo::CORETIME_ROCOCO_LOCAL, - CoretimeRuntimeType::RococoDevelopment => rococo::CORETIME_ROCOCO_DEVELOPMENT, - CoretimeRuntimeType::Westend => westend::CORETIME_WESTEND, - CoretimeRuntimeType::WestendLocal => westend::CORETIME_WESTEND_LOCAL, - CoretimeRuntimeType::WestendDevelopment => westend::CORETIME_WESTEND_DEVELOPMENT, - } - } +pub fn coretime_westend_config() -> GenericChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("tokenSymbol".into(), "WND".into()); + properties.insert("tokenDecimals".into(), 12.into()); + + GenericChainSpec::builder( + coretime_westend_runtime::WASM_BINARY + .expect("WASM binary was not built, please build it!"), + Extensions { relay_chain: "westend".into(), para_id: CORETIME_PARA_ID }, + ) + .with_name("Westend Coretime") + .with_id("coretime-westend") + .with_chain_type(ChainType::Live) + .with_genesis_config_preset_name("genesis") + .with_properties(properties) + .build() } -impl From for ChainType { - fn from(runtime_type: CoretimeRuntimeType) -> Self { - match runtime_type { - CoretimeRuntimeType::Kusama | - CoretimeRuntimeType::Polkadot | - CoretimeRuntimeType::Rococo | - CoretimeRuntimeType::Westend => ChainType::Live, - CoretimeRuntimeType::KusamaLocal | - CoretimeRuntimeType::PolkadotLocal | - CoretimeRuntimeType::RococoLocal | - CoretimeRuntimeType::WestendLocal => ChainType::Local, - CoretimeRuntimeType::RococoDevelopment | CoretimeRuntimeType::WestendDevelopment => - ChainType::Development, - } - } +pub fn coretime_rococo_development_config() -> GenericChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 42.into()); + properties.insert("tokenSymbol".into(), "ROC".into()); + properties.insert("tokenDecimals".into(), 12.into()); + coretime_rococo_like_development_config( + properties, + "Rococo Coretime Development", + "coretime-rococo-dev", + CORETIME_PARA_ID, + ) } -pub const CORETIME_PARA_ID: ParaId = ParaId::new(1005); - -impl CoretimeRuntimeType { - pub const ID_PREFIX: &'static str = "coretime"; - - pub fn load_config(&self) -> Result, String> { - match self { - CoretimeRuntimeType::Kusama => Ok(Box::new(GenericChainSpec::from_json_bytes( - &include_bytes!("../../chain-specs/coretime-kusama.json")[..], - )?)), - CoretimeRuntimeType::Polkadot => Ok(Box::new(GenericChainSpec::from_json_bytes( - &include_bytes!("../../chain-specs/coretime-polkadot.json")[..], - )?)), - CoretimeRuntimeType::Rococo => Ok(Box::new(GenericChainSpec::from_json_bytes( - &include_bytes!("../../chain-specs/coretime-rococo.json")[..], - )?)), - CoretimeRuntimeType::RococoLocal => - Ok(Box::new(rococo::local_config(*self, "rococo-local"))), - CoretimeRuntimeType::RococoDevelopment => - Ok(Box::new(rococo::local_config(*self, "rococo-dev"))), - CoretimeRuntimeType::Westend => Ok(Box::new(GenericChainSpec::from_json_bytes( - &include_bytes!("../../../parachains/chain-specs/coretime-westend.json")[..], - )?)), - CoretimeRuntimeType::WestendLocal => - Ok(Box::new(westend::local_config(*self, "westend-local"))), - CoretimeRuntimeType::WestendDevelopment => - Ok(Box::new(westend::local_config(*self, "westend-dev"))), - other => Err(std::format!( - "No default config present for {:?}, you should provide a chain-spec as json file!", - other - )), - } - } +fn coretime_rococo_like_development_config( + properties: sc_chain_spec::Properties, + name: &str, + chain_id: &str, + para_id: u32, +) -> GenericChainSpec { + GenericChainSpec::builder( + coretime_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), + Extensions { relay_chain: "rococo-dev".into(), para_id }, + ) + .with_name(name) + .with_id(chain_id) + .with_chain_type(ChainType::Local) + .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET) + .with_properties(properties) + .build() } -/// Generate the name directly from the ChainType -pub fn chain_type_name(chain_type: &ChainType) -> Cow { - match chain_type { - ChainType::Development => "Development", - ChainType::Local => "Local", - ChainType::Live => "Live", - ChainType::Custom(name) => name, - } - .into() +pub fn coretime_rococo_local_config() -> GenericChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 42.into()); + properties.insert("tokenSymbol".into(), "ROC".into()); + properties.insert("tokenDecimals".into(), 12.into()); + coretime_rococo_like_local_config( + properties, + "Rococo Coretime Local", + "coretime-rococo-local", + CORETIME_PARA_ID, + ) } -/// Sub-module for Rococo setup. -pub mod rococo { - use super::{chain_type_name, CoretimeRuntimeType, ParaId}; - use crate::chain_spec::SAFE_XCM_VERSION; - use parachains_common::{AccountId, AuraId, Balance}; - use polkadot_omni_node_lib::chain_spec::{Extensions, GenericChainSpec}; - use sc_chain_spec::ChainType; - use sp_keyring::Sr25519Keyring; - - pub(crate) const CORETIME_ROCOCO: &str = "coretime-rococo"; - pub(crate) const CORETIME_ROCOCO_LOCAL: &str = "coretime-rococo-local"; - pub(crate) const CORETIME_ROCOCO_DEVELOPMENT: &str = "coretime-rococo-dev"; - const CORETIME_ROCOCO_ED: Balance = coretime_rococo_runtime::ExistentialDeposit::get(); - - pub fn local_config(runtime_type: CoretimeRuntimeType, relay_chain: &str) -> GenericChainSpec { - // Rococo defaults - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("ss58Format".into(), 42.into()); - properties.insert("tokenSymbol".into(), "ROC".into()); - properties.insert("tokenDecimals".into(), 12.into()); - - let chain_type = runtime_type.into(); - let chain_name = format!("Coretime Rococo {}", chain_type_name(&chain_type)); - let para_id = super::CORETIME_PARA_ID; - - let wasm_binary = if matches!(chain_type, ChainType::Local | ChainType::Development) { - coretime_rococo_runtime::fast_runtime_binary::WASM_BINARY - .expect("WASM binary was not built, please build it!") - } else { - coretime_rococo_runtime::WASM_BINARY - .expect("WASM binary was not built, please build it!") - }; - - GenericChainSpec::builder( - wasm_binary, - Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, - ) - .with_name(&chain_name) - .with_id(runtime_type.into()) - .with_chain_type(chain_type) - .with_genesis_config_patch(genesis( - // initial collators. - vec![(Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into())], - vec![ - Sr25519Keyring::Alice.to_account_id(), - Sr25519Keyring::Bob.to_account_id(), - Sr25519Keyring::AliceStash.to_account_id(), - Sr25519Keyring::BobStash.to_account_id(), - ], - para_id, - )) +fn coretime_rococo_like_local_config( + properties: sc_chain_spec::Properties, + name: &str, + chain_id: &str, + para_id: u32, +) -> GenericChainSpec { + GenericChainSpec::builder( + coretime_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), + Extensions { relay_chain: "rococo-local".into(), para_id }, + ) + .with_name(name) + .with_id(chain_id) + .with_chain_type(ChainType::Local) + .with_genesis_config_preset_name(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET) .with_properties(properties) .build() - } - - fn genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - id: ParaId, - ) -> serde_json::Value { - serde_json::json!({ - "balances": { - "balances": endowed_accounts.iter().cloned().map(|k| (k, CORETIME_ROCOCO_ED * 4096)).collect::>(), - }, - "parachainInfo": { - "parachainId": id, - }, - "collatorSelection": { - "invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::>(), - "candidacyBond": CORETIME_ROCOCO_ED * 16, - }, - "session": { - "keys": invulnerables - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - coretime_rococo_runtime::SessionKeys { aura }, // session keys - ) - }) - .collect::>(), - }, - "polkadotXcm": { - "safeXcmVersion": Some(SAFE_XCM_VERSION), - }, - "sudo": { - "key": Some(Sr25519Keyring::Alice.to_account_id()), - }, - }) - } } -/// Sub-module for Westend setup. -pub mod westend { - use super::{chain_type_name, CoretimeRuntimeType, GenericChainSpec, ParaId}; - use crate::chain_spec::SAFE_XCM_VERSION; - use parachains_common::{AccountId, AuraId, Balance}; - use polkadot_omni_node_lib::chain_spec::Extensions; - use sp_keyring::Sr25519Keyring; - - pub(crate) const CORETIME_WESTEND: &str = "coretime-westend"; - pub(crate) const CORETIME_WESTEND_LOCAL: &str = "coretime-westend-local"; - pub(crate) const CORETIME_WESTEND_DEVELOPMENT: &str = "coretime-westend-dev"; - const CORETIME_WESTEND_ED: Balance = coretime_westend_runtime::ExistentialDeposit::get(); - - pub fn local_config(runtime_type: CoretimeRuntimeType, relay_chain: &str) -> GenericChainSpec { - // westend defaults - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("ss58Format".into(), 42.into()); - properties.insert("tokenSymbol".into(), "WND".into()); - properties.insert("tokenDecimals".into(), 12.into()); - - let chain_type = runtime_type.into(); - let chain_name = format!("Coretime Westend {}", chain_type_name(&chain_type)); - let para_id = super::CORETIME_PARA_ID; - - GenericChainSpec::builder( - coretime_westend_runtime::WASM_BINARY - .expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, - ) - .with_name(&chain_name) - .with_id(runtime_type.into()) - .with_chain_type(chain_type) - .with_genesis_config_patch(genesis( - // initial collators. - vec![(Sr25519Keyring::Alice.to_account_id(), Sr25519Keyring::Alice.public().into())], - vec![ - Sr25519Keyring::Alice.to_account_id(), - Sr25519Keyring::Bob.to_account_id(), - Sr25519Keyring::AliceStash.to_account_id(), - Sr25519Keyring::BobStash.to_account_id(), - ], - para_id, - )) +pub fn coretime_rococo_genesis_config() -> GenericChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("tokenSymbol".into(), "ROC".into()); + properties.insert("tokenDecimals".into(), 12.into()); + let para_id = CORETIME_PARA_ID; + GenericChainSpec::builder( + coretime_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), + Extensions { relay_chain: "rococo".into(), para_id }, + ) + .with_name("Rococo Coretime") + .with_id("coretime-rococo") + .with_chain_type(ChainType::Live) + .with_genesis_config_preset_name("genesis") .with_properties(properties) .build() - } - - fn genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - id: ParaId, - ) -> serde_json::Value { - serde_json::json!({ - "balances": { - "balances": endowed_accounts.iter().cloned().map(|k| (k, CORETIME_WESTEND_ED * 4096)).collect::>(), - }, - "parachainInfo": { - "parachainId": id, - }, - "collatorSelection": { - "invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::>(), - "candidacyBond": CORETIME_WESTEND_ED * 16, - }, - "session": { - "keys": invulnerables - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - coretime_westend_runtime::SessionKeys { aura }, // session keys - ) - }) - .collect::>(), - }, - "polkadotXcm": { - "safeXcmVersion": Some(SAFE_XCM_VERSION), - } - }) - } -} - -pub mod kusama { - pub(crate) const CORETIME_KUSAMA: &str = "coretime-kusama"; - pub(crate) const CORETIME_KUSAMA_LOCAL: &str = "coretime-kusama-local"; -} - -pub mod polkadot { - pub(crate) const CORETIME_POLKADOT: &str = "coretime-polkadot"; - pub(crate) const CORETIME_POLKADOT_LOCAL: &str = "coretime-polkadot-local"; -} +} \ No newline at end of file diff --git a/cumulus/polkadot-parachain/src/chain_spec/mod.rs b/cumulus/polkadot-parachain/src/chain_spec/mod.rs index 00dceabb0069..f7c14cc20254 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/mod.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/mod.rs @@ -117,12 +117,22 @@ impl LoadSpec for ChainSpecLoader { )?), // -- BridgeHub - bridge_like_id - if bridge_like_id.starts_with(bridge_hubs::BridgeHubRuntimeType::ID_PREFIX) => - bridge_like_id - .parse::() - .expect("invalid value") - .load_config()?, + + // -- BridgeHub Rococo + "coretime-rococo-dev" => Box::new(asset_hubs::asset_hub_rococo_development_config()), + "coretime-rococo-local" => Box::new(asset_hubs::asset_hub_rococo_local_config()), + "coretime-rococo" => Box::new(GenericChainSpec::from_json_bytes( + &include_bytes!("../../chain-specs/coretime-rococo.json")[..], + )?), + + // -- BridgeHub Westend + "coretime-westend-dev" | "westmint-dev" => + Box::new(asset_hubs::asset_hub_westend_development_config()), + "coretime-westend-local" | "westmint-local" => + Box::new(asset_hubs::asset_hub_westend_local_config()), + "coretime-westend" => Box::new(GenericChainSpec::from_json_bytes( + &include_bytes!("../../chain-specs/coretime-westend.json")[..], + )?), // -- Coretime coretime_like_id From a39e5df06123359cf60fd07ae58672f9555a7e31 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 5 Feb 2025 14:09:19 +0100 Subject: [PATCH 07/11] cleanup coretime polkadot-parachain chain_specs 2 --- .../src/chain_spec/coretime.rs | 106 ++++-------------- 1 file changed, 22 insertions(+), 84 deletions(-) diff --git a/cumulus/polkadot-parachain/src/chain_spec/coretime.rs b/cumulus/polkadot-parachain/src/chain_spec/coretime.rs index d5d208d402fa..f9fd8e6611dd 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/coretime.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/coretime.rs @@ -21,10 +21,6 @@ use sc_chain_spec::{ChainType, GenericChainSpec}; pub const CORETIME_PARA_ID: ParaId = ParaId::new(1005); pub fn coretime_westend_development_config() -> GenericChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("tokenSymbol".into(), "WND".into()); - properties.insert("tokenDecimals".into(), 12.into()); - GenericChainSpec::builder( coretime_westend_runtime::WASM_BINARY .expect("WASM binary was not built, please build it!"), @@ -34,15 +30,11 @@ pub fn coretime_westend_development_config() -> GenericChainSpec { .with_id("coretime-westend-dev") .with_chain_type(ChainType::Local) .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET) - .with_properties(properties) + .with_properties(westend_properties()) .build() } pub fn coretime_westend_local_config() -> GenericChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("tokenSymbol".into(), "WND".into()); - properties.insert("tokenDecimals".into(), 12.into()); - GenericChainSpec::builder( coretime_westend_runtime::WASM_BINARY .expect("WASM binary was not built, please build it!"), @@ -52,103 +44,49 @@ pub fn coretime_westend_local_config() -> GenericChainSpec { .with_id("coretime-westend-local") .with_chain_type(ChainType::Local) .with_genesis_config_preset_name(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET) - .with_properties(properties) - .build() -} - -pub fn coretime_westend_config() -> GenericChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("tokenSymbol".into(), "WND".into()); - properties.insert("tokenDecimals".into(), 12.into()); - - GenericChainSpec::builder( - coretime_westend_runtime::WASM_BINARY - .expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: "westend".into(), para_id: CORETIME_PARA_ID }, - ) - .with_name("Westend Coretime") - .with_id("coretime-westend") - .with_chain_type(ChainType::Live) - .with_genesis_config_preset_name("genesis") - .with_properties(properties) + .with_properties(westend_properties()) .build() } pub fn coretime_rococo_development_config() -> GenericChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("ss58Format".into(), 42.into()); - properties.insert("tokenSymbol".into(), "ROC".into()); - properties.insert("tokenDecimals".into(), 12.into()); - coretime_rococo_like_development_config( - properties, - "Rococo Coretime Development", - "coretime-rococo-dev", - CORETIME_PARA_ID, - ) -} - -fn coretime_rococo_like_development_config( - properties: sc_chain_spec::Properties, - name: &str, - chain_id: &str, - para_id: u32, -) -> GenericChainSpec { GenericChainSpec::builder( coretime_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: "rococo-dev".into(), para_id }, + Extensions { relay_chain: "rococo-dev".into(), CORETIME_PARA_ID }, ) - .with_name(name) - .with_id(chain_id) + .with_name("Rococo Coretime Development") + .with_id("coretime-rococo-dev") .with_chain_type(ChainType::Local) .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET) - .with_properties(properties) + .with_properties(rococo_properties()) .build() } pub fn coretime_rococo_local_config() -> GenericChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("ss58Format".into(), 42.into()); - properties.insert("tokenSymbol".into(), "ROC".into()); - properties.insert("tokenDecimals".into(), 12.into()); - coretime_rococo_like_local_config( - properties, - "Rococo Coretime Local", - "coretime-rococo-local", - CORETIME_PARA_ID, - ) -} - -fn coretime_rococo_like_local_config( - properties: sc_chain_spec::Properties, - name: &str, - chain_id: &str, - para_id: u32, -) -> GenericChainSpec { GenericChainSpec::builder( coretime_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: "rococo-local".into(), para_id }, + Extensions { relay_chain: "rococo-local".into(), CORETIME_PARA_ID }, ) - .with_name(name) - .with_id(chain_id) + .with_name("Rococo Coretime Local") + .with_id("coretime-rococo-local") .with_chain_type(ChainType::Local) .with_genesis_config_preset_name(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET) - .with_properties(properties) + .with_properties(rococo_properties()) .build() } -pub fn coretime_rococo_genesis_config() -> GenericChainSpec { +pub fn westend_properties() -> sc_chain_spec::Properties { let mut properties = sc_chain_spec::Properties::new(); + properties.insert("tokenSymbol".into(), "WND".into()); + properties.insert("tokenDecimals".into(), 12.into()); + + properties +} + +pub fn rococo_properties() -> sc_chain_spec::Properties { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 42.into()); properties.insert("tokenSymbol".into(), "ROC".into()); properties.insert("tokenDecimals".into(), 12.into()); - let para_id = CORETIME_PARA_ID; - GenericChainSpec::builder( - coretime_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: "rococo".into(), para_id }, - ) - .with_name("Rococo Coretime") - .with_id("coretime-rococo") - .with_chain_type(ChainType::Live) - .with_genesis_config_preset_name("genesis") - .with_properties(properties) - .build() + + properties } \ No newline at end of file From 2ce767ddc37271a10b66ef90db943e7f12b63f18 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 5 Feb 2025 14:14:36 +0100 Subject: [PATCH 08/11] fix chain-spec ids --- .../polkadot-parachain/src/chain_spec/mod.rs | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/cumulus/polkadot-parachain/src/chain_spec/mod.rs b/cumulus/polkadot-parachain/src/chain_spec/mod.rs index f7c14cc20254..73d020404635 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/mod.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/mod.rs @@ -117,31 +117,28 @@ impl LoadSpec for ChainSpecLoader { )?), // -- BridgeHub + bridge_like_id + if bridge_like_id.starts_with(bridge_hubs::BridgeHubRuntimeType::ID_PREFIX) => + bridge_like_id + .parse::() + .expect("invalid value") + .load_config()?, - // -- BridgeHub Rococo + // -- Coretime + // -- Coretime Rococo "coretime-rococo-dev" => Box::new(asset_hubs::asset_hub_rococo_development_config()), "coretime-rococo-local" => Box::new(asset_hubs::asset_hub_rococo_local_config()), "coretime-rococo" => Box::new(GenericChainSpec::from_json_bytes( &include_bytes!("../../chain-specs/coretime-rococo.json")[..], )?), - // -- BridgeHub Westend - "coretime-westend-dev" | "westmint-dev" => - Box::new(asset_hubs::asset_hub_westend_development_config()), - "coretime-westend-local" | "westmint-local" => - Box::new(asset_hubs::asset_hub_westend_local_config()), + // -- Coretime Westend + "coretime-westend-dev" => Box::new(asset_hubs::asset_hub_westend_development_config()), + "coretime-westend-local" => Box::new(asset_hubs::asset_hub_westend_local_config()), "coretime-westend" => Box::new(GenericChainSpec::from_json_bytes( &include_bytes!("../../chain-specs/coretime-westend.json")[..], )?), - // -- Coretime - coretime_like_id - if coretime_like_id.starts_with(coretime::CoretimeRuntimeType::ID_PREFIX) => - coretime_like_id - .parse::() - .expect("invalid value") - .load_config()?, - // -- Penpal id if id.starts_with("penpal-rococo") => { let (_, _, para_id) = extract_parachain_id(&id, &["penpal-rococo-"]); From 2aa136a4e7380723e3ee59b1df3cc39e55a8034b Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 5 Feb 2025 14:48:48 +0100 Subject: [PATCH 09/11] [parachain-bin] revert unnecessary chain-spec changes --- .../src/chain_spec/coretime.rs | 271 ++++++++++++++---- .../polkadot-parachain/src/chain_spec/mod.rs | 19 +- 2 files changed, 218 insertions(+), 72 deletions(-) diff --git a/cumulus/polkadot-parachain/src/chain_spec/coretime.rs b/cumulus/polkadot-parachain/src/chain_spec/coretime.rs index f9fd8e6611dd..e649ff490cc8 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/coretime.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/coretime.rs @@ -16,77 +16,230 @@ use cumulus_primitives_core::ParaId; use polkadot_omni_node_lib::chain_spec::GenericChainSpec; -use sc_chain_spec::{ChainType, GenericChainSpec}; +use sc_chain_spec::{ChainSpec, ChainType}; +use std::{borrow::Cow, str::FromStr}; -pub const CORETIME_PARA_ID: ParaId = ParaId::new(1005); +/// Collects all supported Coretime configurations. +#[derive(Debug, PartialEq, Clone, Copy)] +pub enum CoretimeRuntimeType { + Kusama, + KusamaLocal, -pub fn coretime_westend_development_config() -> GenericChainSpec { - GenericChainSpec::builder( - coretime_westend_runtime::WASM_BINARY - .expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: "westend".into(), para_id: CORETIME_PARA_ID }, - ) - .with_name("Westend Coretime Development") - .with_id("coretime-westend-dev") - .with_chain_type(ChainType::Local) - .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET) - .with_properties(westend_properties()) - .build() + Polkadot, + PolkadotLocal, + + // Live + Rococo, + // Local + RococoLocal, + // Benchmarks + RococoDevelopment, + + // Live + Westend, + // Local + WestendLocal, + // Benchmarks + WestendDevelopment, } -pub fn coretime_westend_local_config() -> GenericChainSpec { - GenericChainSpec::builder( - coretime_westend_runtime::WASM_BINARY - .expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: "westend-local".into(), para_id: CORETIME_PARA_ID }, - ) - .with_name("Westend Coretime Local") - .with_id("coretime-westend-local") - .with_chain_type(ChainType::Local) - .with_genesis_config_preset_name(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET) - .with_properties(westend_properties()) - .build() +impl FromStr for CoretimeRuntimeType { + type Err = String; + + fn from_str(value: &str) -> Result { + match value { + kusama::CORETIME_KUSAMA => Ok(CoretimeRuntimeType::Kusama), + kusama::CORETIME_KUSAMA_LOCAL => Ok(CoretimeRuntimeType::KusamaLocal), + polkadot::CORETIME_POLKADOT => Ok(CoretimeRuntimeType::Polkadot), + polkadot::CORETIME_POLKADOT_LOCAL => Ok(CoretimeRuntimeType::PolkadotLocal), + rococo::CORETIME_ROCOCO => Ok(CoretimeRuntimeType::Rococo), + rococo::CORETIME_ROCOCO_LOCAL => Ok(CoretimeRuntimeType::RococoLocal), + rococo::CORETIME_ROCOCO_DEVELOPMENT => Ok(CoretimeRuntimeType::RococoDevelopment), + westend::CORETIME_WESTEND => Ok(CoretimeRuntimeType::Westend), + westend::CORETIME_WESTEND_LOCAL => Ok(CoretimeRuntimeType::WestendLocal), + westend::CORETIME_WESTEND_DEVELOPMENT => Ok(CoretimeRuntimeType::WestendDevelopment), + _ => Err(format!("Value '{}' is not configured yet", value)), + } + } } -pub fn coretime_rococo_development_config() -> GenericChainSpec { - GenericChainSpec::builder( - coretime_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: "rococo-dev".into(), CORETIME_PARA_ID }, - ) - .with_name("Rococo Coretime Development") - .with_id("coretime-rococo-dev") - .with_chain_type(ChainType::Local) - .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET) - .with_properties(rococo_properties()) - .build() +impl From for &str { + fn from(runtime_type: CoretimeRuntimeType) -> Self { + match runtime_type { + CoretimeRuntimeType::Kusama => kusama::CORETIME_KUSAMA, + CoretimeRuntimeType::KusamaLocal => kusama::CORETIME_KUSAMA_LOCAL, + CoretimeRuntimeType::Polkadot => polkadot::CORETIME_POLKADOT, + CoretimeRuntimeType::PolkadotLocal => polkadot::CORETIME_POLKADOT_LOCAL, + CoretimeRuntimeType::Rococo => rococo::CORETIME_ROCOCO, + CoretimeRuntimeType::RococoLocal => rococo::CORETIME_ROCOCO_LOCAL, + CoretimeRuntimeType::RococoDevelopment => rococo::CORETIME_ROCOCO_DEVELOPMENT, + CoretimeRuntimeType::Westend => westend::CORETIME_WESTEND, + CoretimeRuntimeType::WestendLocal => westend::CORETIME_WESTEND_LOCAL, + CoretimeRuntimeType::WestendDevelopment => westend::CORETIME_WESTEND_DEVELOPMENT, + } + } +} + +impl From for ChainType { + fn from(runtime_type: CoretimeRuntimeType) -> Self { + match runtime_type { + CoretimeRuntimeType::Kusama | + CoretimeRuntimeType::Polkadot | + CoretimeRuntimeType::Rococo | + CoretimeRuntimeType::Westend => ChainType::Live, + CoretimeRuntimeType::KusamaLocal | + CoretimeRuntimeType::PolkadotLocal | + CoretimeRuntimeType::RococoLocal | + CoretimeRuntimeType::WestendLocal => ChainType::Local, + CoretimeRuntimeType::RococoDevelopment | CoretimeRuntimeType::WestendDevelopment => + ChainType::Development, + } + } +} + +pub const CORETIME_PARA_ID: ParaId = ParaId::new(1005); + +impl CoretimeRuntimeType { + pub const ID_PREFIX: &'static str = "coretime"; + + pub fn load_config(&self) -> Result, String> { + match self { + CoretimeRuntimeType::Kusama => Ok(Box::new(GenericChainSpec::from_json_bytes( + &include_bytes!("../../chain-specs/coretime-kusama.json")[..], + )?)), + CoretimeRuntimeType::Polkadot => Ok(Box::new(GenericChainSpec::from_json_bytes( + &include_bytes!("../../chain-specs/coretime-polkadot.json")[..], + )?)), + CoretimeRuntimeType::Rococo => Ok(Box::new(GenericChainSpec::from_json_bytes( + &include_bytes!("../../chain-specs/coretime-rococo.json")[..], + )?)), + CoretimeRuntimeType::RococoLocal => + Ok(Box::new(rococo::local_config(*self, "rococo-local"))), + CoretimeRuntimeType::RococoDevelopment => + Ok(Box::new(rococo::local_config(*self, "rococo-dev"))), + CoretimeRuntimeType::Westend => Ok(Box::new(GenericChainSpec::from_json_bytes( + &include_bytes!("../../../parachains/chain-specs/coretime-westend.json")[..], + )?)), + CoretimeRuntimeType::WestendLocal => + Ok(Box::new(westend::local_config(*self, "westend-local"))), + CoretimeRuntimeType::WestendDevelopment => + Ok(Box::new(westend::local_config(*self, "westend-dev"))), + other => Err(std::format!( + "No default config present for {:?}, you should provide a chain-spec as json file!", + other + )), + } + } } -pub fn coretime_rococo_local_config() -> GenericChainSpec { - GenericChainSpec::builder( - coretime_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: "rococo-local".into(), CORETIME_PARA_ID }, - ) - .with_name("Rococo Coretime Local") - .with_id("coretime-rococo-local") - .with_chain_type(ChainType::Local) - .with_genesis_config_preset_name(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET) - .with_properties(rococo_properties()) +/// Generate the name directly from the ChainType +pub fn chain_type_name(chain_type: &ChainType) -> Cow { + match chain_type { + ChainType::Development => "Development", + ChainType::Local => "Local", + ChainType::Live => "Live", + ChainType::Custom(name) => name, + } + .into() +} + +/// Sub-module for Rococo setup. +pub mod rococo { + use super::{chain_type_name, CoretimeRuntimeType}; + use parachains_common::Balance; + use polkadot_omni_node_lib::chain_spec::{Extensions, GenericChainSpec}; + use sc_chain_spec::ChainType; + use sp_keyring::Sr25519Keyring; + + pub(crate) const CORETIME_ROCOCO: &str = "coretime-rococo"; + pub(crate) const CORETIME_ROCOCO_LOCAL: &str = "coretime-rococo-local"; + pub(crate) const CORETIME_ROCOCO_DEVELOPMENT: &str = "coretime-rococo-dev"; + const CORETIME_ROCOCO_ED: Balance = coretime_rococo_runtime::ExistentialDeposit::get(); + + pub fn local_config(runtime_type: CoretimeRuntimeType, relay_chain: &str) -> GenericChainSpec { + // Rococo defaults + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 42.into()); + properties.insert("tokenSymbol".into(), "ROC".into()); + properties.insert("tokenDecimals".into(), 12.into()); + + let chain_type = runtime_type.into(); + let chain_name = format!("Coretime Rococo {}", chain_type_name(&chain_type)); + let para_id = super::CORETIME_PARA_ID; + + let wasm_binary = if matches!(chain_type, ChainType::Local | ChainType::Development) { + coretime_rococo_runtime::fast_runtime_binary::WASM_BINARY + .expect("WASM binary was not built, please build it!") + } else { + coretime_rococo_runtime::WASM_BINARY + .expect("WASM binary was not built, please build it!") + }; + + GenericChainSpec::builder( + wasm_binary, + Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, + ) + .with_name(&chain_name) + .with_id(runtime_type.into()) + .with_chain_type(chain_type.clone()) + .with_genesis_config_preset_name(match chain_type { + ChainType::Development => sp_genesis_builder::DEV_RUNTIME_PRESET, + ChainType::Local => sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET, + _ => panic!("chain_type: {chain_type:?} not supported here!"), + }) + .with_properties(properties) .build() + } } -pub fn westend_properties() -> sc_chain_spec::Properties { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("tokenSymbol".into(), "WND".into()); - properties.insert("tokenDecimals".into(), 12.into()); +/// Sub-module for Westend setup. +pub mod westend { + use super::{chain_type_name, CoretimeRuntimeType, GenericChainSpec}; + use parachains_common::Balance; + use polkadot_omni_node_lib::chain_spec::Extensions; + use sc_chain_spec::ChainType; + use sp_keyring::Sr25519Keyring; - properties + pub(crate) const CORETIME_WESTEND: &str = "coretime-westend"; + pub(crate) const CORETIME_WESTEND_LOCAL: &str = "coretime-westend-local"; + pub(crate) const CORETIME_WESTEND_DEVELOPMENT: &str = "coretime-westend-dev"; + const CORETIME_WESTEND_ED: Balance = coretime_westend_runtime::ExistentialDeposit::get(); + + pub fn local_config(runtime_type: CoretimeRuntimeType, relay_chain: &str) -> GenericChainSpec { + // westend defaults + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 42.into()); + properties.insert("tokenSymbol".into(), "WND".into()); + properties.insert("tokenDecimals".into(), 12.into()); + + let chain_type = runtime_type.into(); + let chain_name = format!("Coretime Westend {}", chain_type_name(&chain_type)); + let para_id = super::CORETIME_PARA_ID; + + GenericChainSpec::builder( + coretime_westend_runtime::WASM_BINARY + .expect("WASM binary was not built, please build it!"), + Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, + ) + .with_name(&chain_name) + .with_id(runtime_type.into()) + .with_chain_type(chain_type.clone()) + .with_genesis_config_preset_name(match chain_type { + ChainType::Development => sp_genesis_builder::DEV_RUNTIME_PRESET, + ChainType::Local => sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET, + _ => panic!("chain_type: {chain_type:?} not supported here!"), + }) + .with_properties(properties) + .build() + } } -pub fn rococo_properties() -> sc_chain_spec::Properties { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("ss58Format".into(), 42.into()); - properties.insert("tokenSymbol".into(), "ROC".into()); - properties.insert("tokenDecimals".into(), 12.into()); +pub mod kusama { + pub(crate) const CORETIME_KUSAMA: &str = "coretime-kusama"; + pub(crate) const CORETIME_KUSAMA_LOCAL: &str = "coretime-kusama-local"; +} - properties -} \ No newline at end of file +pub mod polkadot { + pub(crate) const CORETIME_POLKADOT: &str = "coretime-polkadot"; + pub(crate) const CORETIME_POLKADOT_LOCAL: &str = "coretime-polkadot-local"; +} diff --git a/cumulus/polkadot-parachain/src/chain_spec/mod.rs b/cumulus/polkadot-parachain/src/chain_spec/mod.rs index 73d020404635..00dceabb0069 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/mod.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/mod.rs @@ -125,19 +125,12 @@ impl LoadSpec for ChainSpecLoader { .load_config()?, // -- Coretime - // -- Coretime Rococo - "coretime-rococo-dev" => Box::new(asset_hubs::asset_hub_rococo_development_config()), - "coretime-rococo-local" => Box::new(asset_hubs::asset_hub_rococo_local_config()), - "coretime-rococo" => Box::new(GenericChainSpec::from_json_bytes( - &include_bytes!("../../chain-specs/coretime-rococo.json")[..], - )?), - - // -- Coretime Westend - "coretime-westend-dev" => Box::new(asset_hubs::asset_hub_westend_development_config()), - "coretime-westend-local" => Box::new(asset_hubs::asset_hub_westend_local_config()), - "coretime-westend" => Box::new(GenericChainSpec::from_json_bytes( - &include_bytes!("../../chain-specs/coretime-westend.json")[..], - )?), + coretime_like_id + if coretime_like_id.starts_with(coretime::CoretimeRuntimeType::ID_PREFIX) => + coretime_like_id + .parse::() + .expect("invalid value") + .load_config()?, // -- Penpal id if id.starts_with("penpal-rococo") => { From 350cfb86bef667de3ea929834a08319c20e8fd21 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 5 Feb 2025 14:54:37 +0100 Subject: [PATCH 10/11] [parachain-bin] remove unused imports --- cumulus/polkadot-parachain/src/chain_spec/coretime.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cumulus/polkadot-parachain/src/chain_spec/coretime.rs b/cumulus/polkadot-parachain/src/chain_spec/coretime.rs index e649ff490cc8..93ad6fc98126 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/coretime.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/coretime.rs @@ -149,12 +149,10 @@ pub mod rococo { use parachains_common::Balance; use polkadot_omni_node_lib::chain_spec::{Extensions, GenericChainSpec}; use sc_chain_spec::ChainType; - use sp_keyring::Sr25519Keyring; pub(crate) const CORETIME_ROCOCO: &str = "coretime-rococo"; pub(crate) const CORETIME_ROCOCO_LOCAL: &str = "coretime-rococo-local"; pub(crate) const CORETIME_ROCOCO_DEVELOPMENT: &str = "coretime-rococo-dev"; - const CORETIME_ROCOCO_ED: Balance = coretime_rococo_runtime::ExistentialDeposit::get(); pub fn local_config(runtime_type: CoretimeRuntimeType, relay_chain: &str) -> GenericChainSpec { // Rococo defaults @@ -198,12 +196,10 @@ pub mod westend { use parachains_common::Balance; use polkadot_omni_node_lib::chain_spec::Extensions; use sc_chain_spec::ChainType; - use sp_keyring::Sr25519Keyring; pub(crate) const CORETIME_WESTEND: &str = "coretime-westend"; pub(crate) const CORETIME_WESTEND_LOCAL: &str = "coretime-westend-local"; pub(crate) const CORETIME_WESTEND_DEVELOPMENT: &str = "coretime-westend-dev"; - const CORETIME_WESTEND_ED: Balance = coretime_westend_runtime::ExistentialDeposit::get(); pub fn local_config(runtime_type: CoretimeRuntimeType, relay_chain: &str) -> GenericChainSpec { // westend defaults From d6460fb450f92050e35c5f0ca85b42a726ef7457 Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 5 Feb 2025 14:55:09 +0100 Subject: [PATCH 11/11] [parachain-bin] remove unused imports --- cumulus/polkadot-parachain/src/chain_spec/coretime.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/cumulus/polkadot-parachain/src/chain_spec/coretime.rs b/cumulus/polkadot-parachain/src/chain_spec/coretime.rs index 93ad6fc98126..055b4028376c 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/coretime.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/coretime.rs @@ -146,7 +146,6 @@ pub fn chain_type_name(chain_type: &ChainType) -> Cow { /// Sub-module for Rococo setup. pub mod rococo { use super::{chain_type_name, CoretimeRuntimeType}; - use parachains_common::Balance; use polkadot_omni_node_lib::chain_spec::{Extensions, GenericChainSpec}; use sc_chain_spec::ChainType; @@ -193,7 +192,6 @@ pub mod rococo { /// Sub-module for Westend setup. pub mod westend { use super::{chain_type_name, CoretimeRuntimeType, GenericChainSpec}; - use parachains_common::Balance; use polkadot_omni_node_lib::chain_spec::Extensions; use sc_chain_spec::ChainType;