From b9b5455a02b114d033171d530e97b4d373363fc5 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 5 Apr 2024 12:31:08 +0200 Subject: [PATCH 01/11] asset-hub-rococo: presets added --- .../assets/asset-hub-rococo/Cargo.toml | 1 + .../src/genesis_config_presets.rs | 203 ++++++++++++++++++ .../assets/asset-hub-rococo/src/lib.rs | 14 +- .../src/chain_spec/asset_hubs.rs | 129 +---------- 4 files changed, 217 insertions(+), 130 deletions(-) create mode 100644 cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml index 0733156716c1..c606cb9c2d98 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml @@ -14,6 +14,7 @@ codec = { package = "parity-scale-codec", version = "3.0.0", default-features = hex-literal = { version = "0.4.1" } log = { workspace = true } scale-info = { version = "2.11.1", default-features = false, features = ["derive"] } +serde_json = { features = ["alloc"], workspace = true } # Substrate frame-benchmarking = { path = "../../../../../substrate/frame/benchmarking", default-features = false, optional = true } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs new file mode 100644 index 000000000000..c0d89497e0d2 --- /dev/null +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs @@ -0,0 +1,203 @@ +// 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. + +//! # Asset Hub Rococo Runtime genesis config presets + +#[cfg(not(feature = "std"))] +use crate::vec; +use crate::Vec; +use cumulus_primitives_core::ParaId; +use hex_literal::hex; +use parachains_common::{AccountId, AuraId, Balance as AssetHubBalance}; +use sp_core::{crypto::UncheckedInto, sr25519}; +#[cfg(not(feature = "std"))] +use sp_std::alloc::format; + +const ASSET_HUB_ROCOCO_ED: AssetHubBalance = crate::ExistentialDeposit::get(); + +//--------------------------------------------------------------- +// copied from: cumulus/polkadot-parachain/src/chain_spec/mod.rs + +use parachains_common::Signature; +// use serde::{Deserialize, Serialize}; +use sp_core::{Pair, Public}; +use sp_runtime::traits::{IdentifyAccount, Verify}; + +/// The default XCM version to set in genesis config. +const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; + +/// Helper function to generate a crypto pair from seed +pub fn get_from_seed(seed: &str) -> ::Public { + TPublic::Pair::from_string(&format!("//{}", seed), None) + .expect("static values are valid; qed") + .public() +} + +type AccountPublic = ::Signer; + +/// Helper function to generate an account ID from seed +pub fn get_account_id_from_seed(seed: &str) -> AccountId +where + AccountPublic: From<::Public>, +{ + AccountPublic::from(get_from_seed::(seed)).into_account() +} + +/// Generate collator keys from seed. +/// +/// This function's return type must always match the session keys of the chain in tuple format. +pub fn get_collator_keys_from_seed(seed: &str) -> ::Public { + get_from_seed::(seed) +} + +//--------------------------------------------------------------- + +/// Generate the session keys from individual elements. +/// +/// The input must be a tuple of individual keys (a single arg for now since we have just one key). +pub fn asset_hub_rococo_session_keys(keys: AuraId) -> crate::SessionKeys { + crate::SessionKeys { aura: keys } +} + +fn asset_hub_rococo_genesis( + invulnerables: Vec<(AccountId, AuraId)>, + endowed_accounts: Vec, + endowment: AssetHubBalance, + id: ParaId, +) -> serde_json::Value { + serde_json::json!({ + "balances": crate::BalancesConfig { + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, endowment)) + .collect(), + }, + "parachainInfo": crate::ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + "collatorSelection": crate::CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: ASSET_HUB_ROCOCO_ED * 16, + ..Default::default() + }, + "session": crate::SessionConfig { + keys: invulnerables + .into_iter() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc, // validator id + asset_hub_rococo_session_keys(aura), // session keys + ) + }) + .collect(), + }, + "polkadotXcm": crate::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + } + }) +} + +pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option> { + let patch = match id.try_into() { + Ok("genesis") => asset_hub_rococo_genesis( + // initial collators. + vec![ + // E8XC6rTJRsioKCp6KMy6zd24ykj4gWsusZ3AkSeyavpVBAG + ( + hex!("44cb62d1d6cdd2fff2a5ef3bb7ef827be5b3e117a394ecaa634d8dd9809d5608").into(), + hex!("44cb62d1d6cdd2fff2a5ef3bb7ef827be5b3e117a394ecaa634d8dd9809d5608") + .unchecked_into(), + ), + // G28iWEybndgGRbhfx83t7Q42YhMPByHpyqWDUgeyoGF94ri + ( + hex!("9864b85e23aa4506643db9879c3dbbeabaa94d269693a4447f537dd6b5893944").into(), + hex!("9864b85e23aa4506643db9879c3dbbeabaa94d269693a4447f537dd6b5893944") + .unchecked_into(), + ), + // G839e2eMiq7UXbConsY6DS1XDAYG2XnQxAmLuRLGGQ3Px9c + ( + hex!("9ce5741ee2f1ac3bdedbde9f3339048f4da2cb88ddf33a0977fa0b4cf86e2948").into(), + hex!("9ce5741ee2f1ac3bdedbde9f3339048f4da2cb88ddf33a0977fa0b4cf86e2948") + .unchecked_into(), + ), + // GLao4ukFUW6qhexuZowdFrKa2NLCfnEjZMftSXXfvGv1vvt + ( + hex!("a676ed15f5a325eab49ed8d5f8c00f3f814b19bb58cda14ad10894c078dd337f").into(), + hex!("a676ed15f5a325eab49ed8d5f8c00f3f814b19bb58cda14ad10894c078dd337f") + .unchecked_into(), + ), + ], + Vec::new(), + ASSET_HUB_ROCOCO_ED * 524_288, + 1000.into(), + ), + + Ok("local") => asset_hub_rococo_genesis( + // initial collators. + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + testnet_parachains_constants::rococo::currency::UNITS * 1_000_000, + 1000.into(), + ), + Ok("development") => asset_hub_rococo_genesis( + // initial collators. + vec![( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + )], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + ], + testnet_parachains_constants::rococo::currency::UNITS * 1_000_000, + 1000.into(), + ), + Err(_) | Ok(_) => return None, + }; + + Some( + serde_json::to_string(&patch) + .expect("serialization to json is expected to work. qed.") + .into_bytes(), + ) +} diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 9e21d1133237..278fbd817a7c 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -24,6 +24,7 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); +mod genesis_config_presets; mod weights; pub mod xcm_config; @@ -37,6 +38,7 @@ use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; use cumulus_primitives_core::AggregateMessageOrigin; use sp_api::impl_runtime_apis; use sp_core::{crypto::KeyTypeId, OpaqueMetadata}; +use sp_genesis_builder::PresetId; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, traits::{AccountIdConversion, BlakeTwo256, Block as BlockT, Saturating, Verify}, @@ -1653,12 +1655,16 @@ impl_runtime_apis! { build_state::(config) } - fn get_preset(id: &Option) -> Option> { - get_preset::(id, |_| None) + fn get_preset(id: &Option) -> Option> { + get_preset::(id, &genesis_config_presets::get_preset) } - fn preset_names() -> Vec { - vec![] + fn preset_names() -> Vec { + vec![ + PresetId::from("genesis"), + PresetId::from("development"), + PresetId::from("local"), + ] } } } diff --git a/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs b/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs index 45920cdb6146..718e921684ff 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs @@ -25,14 +25,6 @@ use sc_service::ChainType; use sp_core::{crypto::UncheckedInto, sr25519}; const ASSET_HUB_WESTEND_ED: AssetHubBalance = asset_hub_westend_runtime::ExistentialDeposit::get(); -const ASSET_HUB_ROCOCO_ED: AssetHubBalance = asset_hub_rococo_runtime::ExistentialDeposit::get(); - -/// Generate the session keys from individual elements. -/// -/// The input must be a tuple of individual keys (a single arg for now since we have just one key). -pub fn asset_hub_rococo_session_keys(keys: AuraId) -> asset_hub_rococo_runtime::SessionKeys { - asset_hub_rococo_runtime::SessionKeys { aura: keys } -} /// Generate the session keys from individual elements. /// @@ -229,21 +221,7 @@ fn asset_hub_rococo_like_development_config( .with_name(name) .with_id(chain_id) .with_chain_type(ChainType::Local) - .with_genesis_config_patch(asset_hub_rococo_genesis( - // initial collators. - vec![( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - )], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - ], - testnet_parachains_constants::rococo::currency::UNITS * 1_000_000, - para_id.into(), - )) + .with_genesis_config_preset_name("development") .with_properties(properties) .build() } @@ -274,35 +252,7 @@ fn asset_hub_rococo_like_local_config( .with_name(name) .with_id(chain_id) .with_chain_type(ChainType::Local) - .with_genesis_config_patch(asset_hub_rococo_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - testnet_parachains_constants::rococo::currency::UNITS * 1_000_000, - para_id.into(), - )) + .with_genesis_config_preset_name("local") .with_properties(properties) .build() } @@ -319,80 +269,7 @@ pub fn asset_hub_rococo_genesis_config() -> GenericChainSpec { .with_name("Rococo Asset Hub") .with_id("asset-hub-rococo") .with_chain_type(ChainType::Live) - .with_genesis_config_patch(asset_hub_rococo_genesis( - // initial collators. - vec![ - // E8XC6rTJRsioKCp6KMy6zd24ykj4gWsusZ3AkSeyavpVBAG - ( - hex!("44cb62d1d6cdd2fff2a5ef3bb7ef827be5b3e117a394ecaa634d8dd9809d5608").into(), - hex!("44cb62d1d6cdd2fff2a5ef3bb7ef827be5b3e117a394ecaa634d8dd9809d5608") - .unchecked_into(), - ), - // G28iWEybndgGRbhfx83t7Q42YhMPByHpyqWDUgeyoGF94ri - ( - hex!("9864b85e23aa4506643db9879c3dbbeabaa94d269693a4447f537dd6b5893944").into(), - hex!("9864b85e23aa4506643db9879c3dbbeabaa94d269693a4447f537dd6b5893944") - .unchecked_into(), - ), - // G839e2eMiq7UXbConsY6DS1XDAYG2XnQxAmLuRLGGQ3Px9c - ( - hex!("9ce5741ee2f1ac3bdedbde9f3339048f4da2cb88ddf33a0977fa0b4cf86e2948").into(), - hex!("9ce5741ee2f1ac3bdedbde9f3339048f4da2cb88ddf33a0977fa0b4cf86e2948") - .unchecked_into(), - ), - // GLao4ukFUW6qhexuZowdFrKa2NLCfnEjZMftSXXfvGv1vvt - ( - hex!("a676ed15f5a325eab49ed8d5f8c00f3f814b19bb58cda14ad10894c078dd337f").into(), - hex!("a676ed15f5a325eab49ed8d5f8c00f3f814b19bb58cda14ad10894c078dd337f") - .unchecked_into(), - ), - ], - Vec::new(), - ASSET_HUB_ROCOCO_ED * 524_288, - para_id.into(), - )) + .with_genesis_config_preset_name("genesis") .with_properties(properties) .build() } - -fn asset_hub_rococo_genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - endowment: AssetHubBalance, - id: ParaId, -) -> serde_json::Value { - serde_json::json!({ - "balances": asset_hub_rococo_runtime::BalancesConfig { - balances: endowed_accounts - .iter() - .cloned() - .map(|k| (k, endowment)) - .collect(), - }, - "parachainInfo": asset_hub_rococo_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() - }, - "collatorSelection": asset_hub_rococo_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: ASSET_HUB_ROCOCO_ED * 16, - ..Default::default() - }, - "session": asset_hub_rococo_runtime::SessionConfig { - keys: invulnerables - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - asset_hub_rococo_session_keys(aura), // session keys - ) - }) - .collect(), - }, - "polkadotXcm": asset_hub_rococo_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - } - }) -} From 5d1fa2b0832eed21adbddbfd6a4ed3dbef20be90 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 5 Apr 2024 12:35:56 +0200 Subject: [PATCH 02/11] Cargo.lock --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.lock b/Cargo.lock index c3cf0b953f7b..2e3f1e43d95a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -908,6 +908,7 @@ dependencies = [ "primitive-types", "rococo-runtime-constants", "scale-info", + "serde_json", "snowbridge-router-primitives", "sp-api", "sp-block-builder", From 38f67dd3ef47585ca2e9120efab85546560c97c2 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 5 Apr 2024 12:47:05 +0200 Subject: [PATCH 03/11] make zepter happy --- cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml index c606cb9c2d98..494f3d20e0be 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml @@ -232,6 +232,7 @@ std = [ "primitive-types/std", "rococo-runtime-constants/std", "scale-info/std", + "serde_json/std", "snowbridge-router-primitives/std", "sp-api/std", "sp-block-builder/std", From f3e7e4d7cc90ed5bf7d4062cacf670ab40da2122 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Sat, 8 Jun 2024 15:38:24 +0200 Subject: [PATCH 04/11] some improvements --- .../common/src/genesis_config_helpers.rs | 49 ++++++++++++++++ cumulus/parachains/common/src/lib.rs | 1 + .../src/genesis_config_presets.rs | 57 +++++-------------- .../assets/asset-hub-rococo/src/lib.rs | 7 ++- 4 files changed, 67 insertions(+), 47 deletions(-) create mode 100644 cumulus/parachains/common/src/genesis_config_helpers.rs diff --git a/cumulus/parachains/common/src/genesis_config_helpers.rs b/cumulus/parachains/common/src/genesis_config_helpers.rs new file mode 100644 index 000000000000..807470ea860c --- /dev/null +++ b/cumulus/parachains/common/src/genesis_config_helpers.rs @@ -0,0 +1,49 @@ +// 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. + +//! Some common helpers for declaring runtime's presets +// note: copied from: cumulus/polkadot-parachain/src/chain_spec/mod.rs + +use crate::{AccountId, Signature}; +use sp_core::{Pair, Public}; +use sp_runtime::traits::{IdentifyAccount, Verify}; +#[cfg(not(feature = "std"))] +use sp_std::alloc::format; + +/// The default XCM version to set in genesis config. +pub const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; + +/// Helper function to generate a crypto pair from seed +pub fn get_from_seed(seed: &str) -> ::Public { + TPublic::Pair::from_string(&format!("//{}", seed), None) + .expect("static values are valid; qed") + .public() +} + +type AccountPublic = ::Signer; + +pub fn get_account_id_from_seed(seed: &str) -> AccountId +where + AccountPublic: From<::Public>, +{ + AccountPublic::from(get_from_seed::(seed)).into_account() +} + +/// Generate collator keys from seed. +/// +/// This function's return type must always match the session keys of the chain in tuple format. +pub fn get_collator_keys_from_seed(seed: &str) -> ::Public { + get_from_seed::(seed) +} diff --git a/cumulus/parachains/common/src/lib.rs b/cumulus/parachains/common/src/lib.rs index b01d623d2b93..2605c82c2d11 100644 --- a/cumulus/parachains/common/src/lib.rs +++ b/cumulus/parachains/common/src/lib.rs @@ -15,6 +15,7 @@ #![cfg_attr(not(feature = "std"), no_std)] +pub mod genesis_config_helpers; pub mod impls; pub mod message_queue; pub mod xcm_config; diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs index c0d89497e0d2..2b5693b8198e 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs @@ -20,50 +20,11 @@ use crate::vec; use crate::Vec; use cumulus_primitives_core::ParaId; use hex_literal::hex; -use parachains_common::{AccountId, AuraId, Balance as AssetHubBalance}; +use parachains_common::{genesis_config_helpers::*, AccountId, AuraId, Balance as AssetHubBalance}; use sp_core::{crypto::UncheckedInto, sr25519}; -#[cfg(not(feature = "std"))] -use sp_std::alloc::format; const ASSET_HUB_ROCOCO_ED: AssetHubBalance = crate::ExistentialDeposit::get(); -//--------------------------------------------------------------- -// copied from: cumulus/polkadot-parachain/src/chain_spec/mod.rs - -use parachains_common::Signature; -// use serde::{Deserialize, Serialize}; -use sp_core::{Pair, Public}; -use sp_runtime::traits::{IdentifyAccount, Verify}; - -/// The default XCM version to set in genesis config. -const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; - -/// Helper function to generate a crypto pair from seed -pub fn get_from_seed(seed: &str) -> ::Public { - TPublic::Pair::from_string(&format!("//{}", seed), None) - .expect("static values are valid; qed") - .public() -} - -type AccountPublic = ::Signer; - -/// Helper function to generate an account ID from seed -pub fn get_account_id_from_seed(seed: &str) -> AccountId -where - AccountPublic: From<::Public>, -{ - AccountPublic::from(get_from_seed::(seed)).into_account() -} - -/// Generate collator keys from seed. -/// -/// This function's return type must always match the session keys of the chain in tuple format. -pub fn get_collator_keys_from_seed(seed: &str) -> ::Public { - get_from_seed::(seed) -} - -//--------------------------------------------------------------- - /// Generate the session keys from individual elements. /// /// The input must be a tuple of individual keys (a single arg for now since we have just one key). @@ -113,9 +74,18 @@ fn asset_hub_rococo_genesis( }) } +/// Encapsulates names of predefined presets. +pub mod preset_names { + pub const PRESET_DEVELOPMENT: &str = "development"; + pub const PRESET_LOCAL: &str = "local"; + pub const PRESET_GENESIS: &str = "genesis"; +} + +/// Provides the JSON representation of predefined genesis config for given `id`. pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option> { + use preset_names::*; let patch = match id.try_into() { - Ok("genesis") => asset_hub_rococo_genesis( + Ok(PRESET_GENESIS) => asset_hub_rococo_genesis( // initial collators. vec![ // E8XC6rTJRsioKCp6KMy6zd24ykj4gWsusZ3AkSeyavpVBAG @@ -147,8 +117,7 @@ pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option asset_hub_rococo_genesis( + Ok(PRESET_LOCAL) => asset_hub_rococo_genesis( // initial collators. vec![ ( @@ -177,7 +146,7 @@ pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option asset_hub_rococo_genesis( + Ok(PRESET_DEVELOPMENT) => asset_hub_rococo_genesis( // initial collators. vec![( get_account_id_from_seed::("Alice"), diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 0afeaabf2d64..cc2a34b74b6d 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -1728,10 +1728,11 @@ impl_runtime_apis! { } fn preset_names() -> Vec { + use crate::genesis_config_presets::preset_names::*; vec![ - PresetId::from("genesis"), - PresetId::from("development"), - PresetId::from("local"), + PresetId::from(PRESET_GENESIS), + PresetId::from(PRESET_DEVELOPMENT), + PresetId::from(PRESET_LOCAL), ] } } From 0df7dc53bf6432b066d1c12bc64dbd791dd4005c Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 10 Jun 2024 11:47:54 +0200 Subject: [PATCH 05/11] SAFE_XCM_VERSION move to constants --- cumulus/parachains/common/src/genesis_config_helpers.rs | 3 --- .../assets/asset-hub-rococo/src/genesis_config_presets.rs | 1 + cumulus/parachains/runtimes/constants/src/rococo.rs | 5 +++++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cumulus/parachains/common/src/genesis_config_helpers.rs b/cumulus/parachains/common/src/genesis_config_helpers.rs index 807470ea860c..4cb96e8caa83 100644 --- a/cumulus/parachains/common/src/genesis_config_helpers.rs +++ b/cumulus/parachains/common/src/genesis_config_helpers.rs @@ -22,9 +22,6 @@ use sp_runtime::traits::{IdentifyAccount, Verify}; #[cfg(not(feature = "std"))] use sp_std::alloc::format; -/// The default XCM version to set in genesis config. -pub const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; - /// Helper function to generate a crypto pair from seed pub fn get_from_seed(seed: &str) -> ::Public { TPublic::Pair::from_string(&format!("//{}", seed), None) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs index 2b5693b8198e..2fee71130182 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs @@ -22,6 +22,7 @@ use cumulus_primitives_core::ParaId; use hex_literal::hex; use parachains_common::{genesis_config_helpers::*, AccountId, AuraId, Balance as AssetHubBalance}; use sp_core::{crypto::UncheckedInto, sr25519}; +use testnet_parachains_constants::rococo::xcm_version::SAFE_XCM_VERSION; const ASSET_HUB_ROCOCO_ED: AssetHubBalance = crate::ExistentialDeposit::get(); diff --git a/cumulus/parachains/runtimes/constants/src/rococo.rs b/cumulus/parachains/runtimes/constants/src/rococo.rs index d10b5e7d3af4..56f4868371c1 100644 --- a/cumulus/parachains/runtimes/constants/src/rococo.rs +++ b/cumulus/parachains/runtimes/constants/src/rococo.rs @@ -161,3 +161,8 @@ pub mod snowbridge { pub EthereumNetwork: NetworkId = NetworkId::Ethereum { chain_id: 11155111 }; } } + +pub mod xcm_version { + /// The default XCM version to set in genesis config. + pub const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; +} From 6db7077856c55853372b9a288c0750f8199ac9dd Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 18 Jun 2024 17:45:12 +0200 Subject: [PATCH 06/11] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dónal Murray --- cumulus/parachains/common/src/genesis_config_helpers.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cumulus/parachains/common/src/genesis_config_helpers.rs b/cumulus/parachains/common/src/genesis_config_helpers.rs index 4cb96e8caa83..55fc289fb08d 100644 --- a/cumulus/parachains/common/src/genesis_config_helpers.rs +++ b/cumulus/parachains/common/src/genesis_config_helpers.rs @@ -22,7 +22,7 @@ use sp_runtime::traits::{IdentifyAccount, Verify}; #[cfg(not(feature = "std"))] use sp_std::alloc::format; -/// Helper function to generate a crypto pair from seed +/// Helper function to generate a crypto pair from seed. pub fn get_from_seed(seed: &str) -> ::Public { TPublic::Pair::from_string(&format!("//{}", seed), None) .expect("static values are valid; qed") @@ -31,6 +31,7 @@ pub fn get_from_seed(seed: &str) -> ::Pu type AccountPublic = ::Signer; +/// Helper function to generate an account id from seed. pub fn get_account_id_from_seed(seed: &str) -> AccountId where AccountPublic: From<::Public>, From 7e82cae8ffcc76397b1cbce5b826875975fe5f34 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 30 Aug 2024 12:59:06 +0200 Subject: [PATCH 07/11] Update cumulus/parachains/common/src/genesis_config_helpers.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- cumulus/parachains/common/src/genesis_config_helpers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/parachains/common/src/genesis_config_helpers.rs b/cumulus/parachains/common/src/genesis_config_helpers.rs index 55fc289fb08d..6fc76a261653 100644 --- a/cumulus/parachains/common/src/genesis_config_helpers.rs +++ b/cumulus/parachains/common/src/genesis_config_helpers.rs @@ -24,7 +24,7 @@ use sp_std::alloc::format; /// Helper function to generate a crypto pair from seed. pub fn get_from_seed(seed: &str) -> ::Public { - TPublic::Pair::from_string(&format!("//{}", seed), None) + TPublic::Pair::from_string(&format!("//{seed}"), None) .expect("static values are valid; qed") .public() } From 362d8a2fd3fda78348bba06d02464dc1c12a26d7 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 30 Aug 2024 14:57:37 +0200 Subject: [PATCH 08/11] after merge fix --- .../assets/asset-hub-rococo/src/genesis_config_presets.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs index 2fee71130182..9a43f8f74100 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs @@ -67,6 +67,7 @@ fn asset_hub_rococo_genesis( ) }) .collect(), + ..Default::default() }, "polkadotXcm": crate::PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION), From e7dac38e3060b75b062eb79e9256cf5d91184fa6 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 30 Aug 2024 15:21:50 +0200 Subject: [PATCH 09/11] use vec / format fixes --- cumulus/parachains/common/src/genesis_config_helpers.rs | 4 ++-- .../assets/asset-hub-rococo/src/genesis_config_presets.rs | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/cumulus/parachains/common/src/genesis_config_helpers.rs b/cumulus/parachains/common/src/genesis_config_helpers.rs index 6fc76a261653..d70b8d5b9c11 100644 --- a/cumulus/parachains/common/src/genesis_config_helpers.rs +++ b/cumulus/parachains/common/src/genesis_config_helpers.rs @@ -17,10 +17,10 @@ // note: copied from: cumulus/polkadot-parachain/src/chain_spec/mod.rs use crate::{AccountId, Signature}; +#[cfg(not(feature = "std"))] +use alloc::format; use sp_core::{Pair, Public}; use sp_runtime::traits::{IdentifyAccount, Verify}; -#[cfg(not(feature = "std"))] -use sp_std::alloc::format; /// Helper function to generate a crypto pair from seed. pub fn get_from_seed(seed: &str) -> ::Public { diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs index 9a43f8f74100..bd4c411058a1 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs @@ -15,9 +15,7 @@ //! # Asset Hub Rococo Runtime genesis config presets -#[cfg(not(feature = "std"))] -use crate::vec; -use crate::Vec; +use alloc::{vec, vec::Vec}; use cumulus_primitives_core::ParaId; use hex_literal::hex; use parachains_common::{genesis_config_helpers::*, AccountId, AuraId, Balance as AssetHubBalance}; @@ -84,7 +82,7 @@ pub mod preset_names { } /// Provides the JSON representation of predefined genesis config for given `id`. -pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option> { +pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option> { use preset_names::*; let patch = match id.try_into() { Ok(PRESET_GENESIS) => asset_hub_rococo_genesis( From ccdfe51b7019984fab113b2e06a76170bd5985bd Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 30 Aug 2024 16:03:51 +0200 Subject: [PATCH 10/11] prdoc added --- prdoc/pr_3996.prdoc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 prdoc/pr_3996.prdoc diff --git a/prdoc/pr_3996.prdoc b/prdoc/pr_3996.prdoc new file mode 100644 index 000000000000..7590d8992368 --- /dev/null +++ b/prdoc/pr_3996.prdoc @@ -0,0 +1,20 @@ +title: asset-hub-rococo - genesis config presets added + +doc: + - audience: Node Dev + description: | + `asset-hub-rococo` genesis state was moved to runtime. + - audience: Runtime Dev + description: | + `asset-hub-rococo` genesis state was moved to runtime. + + +crates: + - name: parachains-common + bump: minor + - name: testnet-parachains-constants + bump: minor + - name: asset-hub-rococo-runtime + bump: minor + - name: polkadot-parachain-bin + bump: minor From 13f411d622f0ca5e0f6e4ad168108ef368205673 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 30 Aug 2024 16:49:53 +0200 Subject: [PATCH 11/11] fn preset_names added --- .../src/genesis_config_presets.rs | 15 +++++++++++++-- .../runtimes/assets/asset-hub-rococo/src/lib.rs | 7 +------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs index bd4c411058a1..41b7e622b1b2 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/genesis_config_presets.rs @@ -20,6 +20,7 @@ use cumulus_primitives_core::ParaId; use hex_literal::hex; use parachains_common::{genesis_config_helpers::*, AccountId, AuraId, Balance as AssetHubBalance}; use sp_core::{crypto::UncheckedInto, sr25519}; +use sp_genesis_builder::PresetId; use testnet_parachains_constants::rococo::xcm_version::SAFE_XCM_VERSION; const ASSET_HUB_ROCOCO_ED: AssetHubBalance = crate::ExistentialDeposit::get(); @@ -75,14 +76,14 @@ fn asset_hub_rococo_genesis( } /// Encapsulates names of predefined presets. -pub mod preset_names { +mod preset_names { pub const PRESET_DEVELOPMENT: &str = "development"; pub const PRESET_LOCAL: &str = "local"; pub const PRESET_GENESIS: &str = "genesis"; } /// Provides the JSON representation of predefined genesis config for given `id`. -pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option> { +pub fn get_preset(id: &PresetId) -> Option> { use preset_names::*; let patch = match id.try_into() { Ok(PRESET_GENESIS) => asset_hub_rococo_genesis( @@ -170,3 +171,13 @@ pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option> { .into_bytes(), ) } + +/// List of supported presets. +pub fn preset_names() -> Vec { + use preset_names::*; + vec![ + PresetId::from(PRESET_GENESIS), + PresetId::from(PRESET_DEVELOPMENT), + PresetId::from(PRESET_LOCAL), + ] +} diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 6dd1bc2de659..896edd012dd5 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -1776,12 +1776,7 @@ impl_runtime_apis! { } fn preset_names() -> Vec { - use crate::genesis_config_presets::preset_names::*; - vec![ - PresetId::from(PRESET_GENESIS), - PresetId::from(PRESET_DEVELOPMENT), - PresetId::from(PRESET_LOCAL), - ] + genesis_config_presets::preset_names() } } }