From e9b745a7dff8bf98a11b4f440e7dbf68d631f82d Mon Sep 17 00:00:00 2001 From: clangenb <37865735+clangenb@users.noreply.github.com> Date: Wed, 19 Feb 2025 16:36:32 +0100 Subject: [PATCH] add genesis presets for coretime parachains (#7476) Extracted from #7473. Part of: https://github.com/paritytech/polkadot-sdk/issues/5704. --------- Co-authored-by: Guillaume Thiolliere <guillaume.thiolliere@parity.io> Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .github/workflows/runtimes-matrix.json | 4 +- Cargo.lock | 4 + .../coretime/coretime-rococo/Cargo.toml | 4 + .../src/genesis_config_presets.rs | 103 +++++++++++++++ .../coretime/coretime-rococo/src/lib.rs | 5 +- .../coretime/coretime-westend/Cargo.toml | 4 + .../src/genesis_config_presets.rs | 104 +++++++++++++++ .../coretime/coretime-westend/src/lib.rs | 5 +- .../src/chain_spec/coretime.rs | 120 +++--------------- prdoc/pr_7476.prdoc | 14 ++ 10 files changed, 256 insertions(+), 111 deletions(-) create mode 100644 cumulus/parachains/runtimes/coretime/coretime-rococo/src/genesis_config_presets.rs create mode 100644 cumulus/parachains/runtimes/coretime/coretime-westend/src/genesis_config_presets.rs create mode 100644 prdoc/pr_7476.prdoc diff --git a/.github/workflows/runtimes-matrix.json b/.github/workflows/runtimes-matrix.json index 587ea19d890..fbee38f7150 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 }, @@ -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 }, diff --git a/Cargo.lock b/Cargo.lock index 78529a28733..1449652b434 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4161,12 +4161,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", @@ -4260,12 +4262,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-rococo/Cargo.toml b/cumulus/parachains/runtimes/coretime/coretime-rococo/Cargo.toml index 668b4cc6c7b..844166c17c2 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 00000000000..296def2ce27 --- /dev/null +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/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 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(); +pub const CORETIME_PARA_ID: ParaId = ParaId::new(1005); + +fn coretime_rococo_genesis( + invulnerables: Vec<(AccountId, AuraId)>, + endowed_accounts: Vec<AccountId>, + 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) }, + sudo: SudoConfig { key: Some(Sr25519Keyring::Alice.to_account_id()) } + }) +} + +/// Provides the JSON representation of predefined genesis config for given `id`. +pub fn get_preset(id: &PresetId) -> Option<Vec<u8>> { + 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(), + ROC * 1_000_000, + CORETIME_PARA_ID, + ), + 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, + CORETIME_PARA_ID, + ), + _ => 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<PresetId> { + 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 b477bb4850d..9aade1f4d29 100644 --- a/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/coretime/coretime-rococo/src/lib.rs @@ -30,6 +30,7 @@ pub mod fast_runtime_binary { } mod coretime; +mod genesis_config_presets; mod weights; pub mod xcm_config; @@ -1171,11 +1172,11 @@ impl_runtime_apis! { } fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> { - get_preset::<RuntimeGenesisConfig>(id, |_| None) + get_preset::<RuntimeGenesisConfig>(id, &genesis_config_presets::get_preset) } fn preset_names() -> Vec<sp_genesis_builder::PresetId> { - vec![] + genesis_config_presets::preset_names() } } diff --git a/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml b/cumulus/parachains/runtimes/coretime/coretime-westend/Cargo.toml index 915926ff989..b0a54b7d620 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 00000000000..da8ecfdfcb6 --- /dev/null +++ b/cumulus/parachains/runtimes/coretime/coretime-westend/src/genesis_config_presets.rs @@ -0,0 +1,104 @@ +// 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(); +pub const CORETIME_PARA_ID: ParaId = ParaId::new(1005); + +fn coretime_westend_genesis( + invulnerables: Vec<(AccountId, AuraId)>, + endowed_accounts: Vec<AccountId>, + 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<Vec<u8>> { + 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, + CORETIME_PARA_ID, + ), + 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, + CORETIME_PARA_ID, + ), + _ => 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<PresetId> { + 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 964351575de..9a0988da720 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; @@ -1166,11 +1167,11 @@ impl_runtime_apis! { } fn get_preset(id: &Option<sp_genesis_builder::PresetId>) -> Option<Vec<u8>> { - get_preset::<RuntimeGenesisConfig>(id, |_| None) + get_preset::<RuntimeGenesisConfig>(id, &genesis_config_presets::get_preset) } fn preset_names() -> Vec<sp_genesis_builder::PresetId> { - vec![] + genesis_config_presets::preset_names() } } diff --git a/cumulus/polkadot-parachain/src/chain_spec/coretime.rs b/cumulus/polkadot-parachain/src/chain_spec/coretime.rs index 0b619444447..9894b743805 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/coretime.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/coretime.rs @@ -145,17 +145,13 @@ pub fn chain_type_name(chain_type: &ChainType) -> Cow<str> { /// 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 super::{chain_type_name, CoretimeRuntimeType}; 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 @@ -182,72 +178,26 @@ pub mod rococo { ) .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, - )) + .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() } - - fn genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec<AccountId>, - id: ParaId, - ) -> serde_json::Value { - serde_json::json!({ - "balances": { - "balances": endowed_accounts.iter().cloned().map(|k| (k, CORETIME_ROCOCO_ED * 4096)).collect::<Vec<_>>(), - }, - "parachainInfo": { - "parachainId": id, - }, - "collatorSelection": { - "invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::<Vec<_>>(), - "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::<Vec<_>>(), - }, - "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 super::{chain_type_name, CoretimeRuntimeType, GenericChainSpec}; use polkadot_omni_node_lib::chain_spec::Extensions; - use sp_keyring::Sr25519Keyring; + use sc_chain_spec::ChainType; 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 @@ -267,55 +217,15 @@ pub mod westend { ) .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, - )) + .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() } - - fn genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec<AccountId>, - id: ParaId, - ) -> serde_json::Value { - serde_json::json!({ - "balances": { - "balances": endowed_accounts.iter().cloned().map(|k| (k, CORETIME_WESTEND_ED * 4096)).collect::<Vec<_>>(), - }, - "parachainInfo": { - "parachainId": id, - }, - "collatorSelection": { - "invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::<Vec<_>>(), - "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::<Vec<_>>(), - }, - "polkadotXcm": { - "safeXcmVersion": Some(SAFE_XCM_VERSION), - } - }) - } } pub mod kusama { diff --git a/prdoc/pr_7476.prdoc b/prdoc/pr_7476.prdoc new file mode 100644 index 00000000000..3bb0970b4c3 --- /dev/null +++ b/prdoc/pr_7476.prdoc @@ -0,0 +1,14 @@ +title: add genesis presets for coretime parachains +doc: +- audience: Runtime Dev + description: |- + Extracted from #7473. + + Part of: https://github.com/paritytech/polkadot-sdk/issues/5704. +crates: +- name: coretime-westend-runtime + bump: minor +- name: coretime-rococo-runtime + bump: minor +- name: polkadot-parachain-bin + bump: minor -- GitLab