diff --git a/Cargo.lock b/Cargo.lock index f3e94719d68a2..048d77b03857f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2138,6 +2138,7 @@ dependencies = [ "rococo-runtime-constants", "scale-info", "serde", + "serde_json", "snowbridge-beacon-primitives", "snowbridge-core", "snowbridge-outbound-queue-runtime-api", diff --git a/bridges/modules/messages/src/lib.rs b/bridges/modules/messages/src/lib.rs index c36313a147644..4c50a72aa3f0c 100644 --- a/bridges/modules/messages/src/lib.rs +++ b/bridges/modules/messages/src/lib.rs @@ -561,8 +561,9 @@ pub mod pallet { pub operating_mode: MessagesOperatingMode, /// Initial pallet owner. pub owner: Option, + #[serde(skip)] /// Dummy marker. - pub phantom: sp_std::marker::PhantomData, + pub _config: sp_std::marker::PhantomData, } #[pallet::genesis_build] 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 033da3e567095..265d0e59d3b05 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 @@ -93,3 +93,11 @@ pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option sp_std::vec::Vec { + sp_std::vec![ + sp_genesis_builder::PresetId::from("local_testnet"), + sp_genesis_builder::PresetId::from("development"), + ] +} 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 834d30004d861..8c81dcc4ac8e3 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -1776,10 +1776,7 @@ impl_runtime_apis! { } fn preset_names() -> Vec { - vec![ - sp_genesis_builder::PresetId::from("local_testnet"), - sp_genesis_builder::PresetId::from("development"), - ] + genesis_config_presets::preset_names() } } } diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml index 6d0fbd7d5c660..749c59563c390 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml @@ -22,6 +22,7 @@ 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 } @@ -192,6 +193,7 @@ std = [ "rococo-runtime-constants/std", "scale-info/std", "serde", + "serde_json/std", "snowbridge-beacon-primitives/std", "snowbridge-core/std", "snowbridge-outbound-queue-runtime-api/std", diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/genesis_config_presets.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/genesis_config_presets.rs new file mode 100644 index 0000000000000..6ace972170b37 --- /dev/null +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/genesis_config_presets.rs @@ -0,0 +1,137 @@ +// 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. + +//! Genesis configs presets for the BridgeHubRococo runtime + +use crate::*; +use sp_core::sr25519; +use sp_std::vec::Vec; +use testnet_parachains_constants::genesis_presets::*; + +const BRIDGE_HUB_ROCOCO_ED: Balance = ExistentialDeposit::get(); + +/// Default genesis pallet configurations for BridgeHubRococo +pub fn bridge_hub_rococo_genesis( + invulnerables: Vec<(AccountId, AuraId)>, + endowed_accounts: Vec, + id: ParaId, + bridges_pallet_owner: Option, + asset_hub_para_id: ParaId, +) -> serde_json::Value { + serde_json::json!({ + "balances": BalancesConfig { + balances: endowed_accounts.iter().cloned().map(|k| (k, 1u128 << 60)).collect::>(), + }, + "parachainInfo": ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + "collatorSelection": CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: BRIDGE_HUB_ROCOCO_ED * 16, + ..Default::default() + }, + "session": SessionConfig { + keys: invulnerables + .into_iter() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc, // validator id + SessionKeys { aura }, // session keys + ) + }) + .collect(), + ..Default::default() + }, + "polkadotXcm": PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + "bridgeWestendGrandpa": BridgeWestendGrandpaConfig { + owner: bridges_pallet_owner.clone(), + ..Default::default() + }, + "bridgeWestendMessages": BridgeWestendMessagesConfig { + owner: bridges_pallet_owner.clone(), + ..Default::default() + }, + "ethereumSystem": EthereumSystemConfig { + para_id: id, + asset_hub_para_id, + ..Default::default() + } + }) +} + +/// Default genesis setup for `local_testnet` preset id. +pub fn bridge_hub_rococo_local_testnet_genesis( + para_id: ParaId, + bridges_pallet_owner: Option, + asset_hub_para_id: ParaId, +) -> serde_json::Value { + bridge_hub_rococo_genesis( + test_invulnerables(), + testnet_accounts(), + para_id, + bridges_pallet_owner, + asset_hub_para_id, + ) +} + +/// Default genesis setup for `development` preset id. +pub fn bridge_hub_rococo_development_genesis( + para_id: ParaId, + bridges_pallet_owner: Option, + asset_hub_para_id: ParaId, +) -> serde_json::Value { + bridge_hub_rococo_genesis( + test_invulnerables(), + testnet_accounts(), + para_id, + bridges_pallet_owner, + asset_hub_para_id, + ) +} + +/// Provides the JSON representation of predefined genesis config for given `id`. +pub fn get_preset(id: &sp_genesis_builder::PresetId) -> Option> { + let patch = match id.try_into() { + Ok("development") => bridge_hub_rococo_development_genesis( + 1013.into(), + Some(get_account_id_from_seed::("Bob")), + rococo_runtime_constants::system_parachain::ASSET_HUB_ID.into(), + ), + Ok("local_testnet") => bridge_hub_rococo_local_testnet_genesis( + 1013.into(), + Some(get_account_id_from_seed::("Bob")), + rococo_runtime_constants::system_parachain::ASSET_HUB_ID.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() -> sp_std::vec::Vec { + sp_std::vec![ + sp_genesis_builder::PresetId::from("local_testnet"), + sp_genesis_builder::PresetId::from("development"), + ] +} diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index c65880771e086..6b9535f2c2258 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -32,6 +32,8 @@ pub mod bridge_common_config; pub mod bridge_to_bulletin_config; pub mod bridge_to_ethereum_config; pub mod bridge_to_westend_config; +// Genesis preset configurations. +pub mod genesis_config_presets; mod weights; pub mod xcm_config; @@ -1569,11 +1571,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() } } } diff --git a/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs b/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs index 8858502c4cea3..281c6fa867259 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Cumulus. If not, see . +use crate::chain_spec::{Extensions, GenericChainSpec}; use asset_hub_rococo_runtime::genesis_config_presets::{ asset_hub_rococo_development_genesis, asset_hub_rococo_genesis, asset_hub_rococo_local_testnet_genesis, @@ -23,7 +24,7 @@ use asset_hub_westend_runtime::genesis_config_presets::{ asset_hub_westend_local_testnet_genesis, }; use hex_literal::hex; -use parachains_common::{Balance as AssetHubBalance}; +use parachains_common::Balance as AssetHubBalance; use polkadot_parachain_lib::chain_spec::{Extensions, GenericChainSpec}; use sc_service::ChainType; use sp_core::crypto::UncheckedInto; @@ -35,16 +36,17 @@ pub fn asset_hub_westend_development_config() -> GenericChainSpec { let mut properties = sc_chain_spec::Properties::new(); properties.insert("tokenSymbol".into(), "WND".into()); properties.insert("tokenDecimals".into(), 12.into()); + let para_id = 1000; GenericChainSpec::builder( asset_hub_westend_runtime::WASM_BINARY .expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: "westend".into(), para_id: 1000 }, + Extensions { relay_chain: "westend".into(), para_id }, ) .with_name("Westend Asset Hub Development") .with_id("asset-hub-westend-dev") .with_chain_type(ChainType::Local) - .with_genesis_config_patch(asset_hub_westend_development_genesis(1000.into())) + .with_genesis_config_patch(asset_hub_westend_development_genesis(para_id.into())) .with_properties(properties) .build() } @@ -53,16 +55,17 @@ pub fn asset_hub_westend_local_config() -> GenericChainSpec { let mut properties = sc_chain_spec::Properties::new(); properties.insert("tokenSymbol".into(), "WND".into()); properties.insert("tokenDecimals".into(), 12.into()); + let para_id = 1000; GenericChainSpec::builder( asset_hub_westend_runtime::WASM_BINARY .expect("WASM binary was not built, please build it!"), - Extensions { relay_chain: "westend-local".into(), para_id: 1000 }, + Extensions { relay_chain: "westend-local".into(), para_id }, ) .with_name("Westend Asset Hub Local") .with_id("asset-hub-westend-local") .with_chain_type(ChainType::Local) - .with_genesis_config_patch(asset_hub_westend_local_testnet_genesis(1000)) + .with_genesis_config_patch(asset_hub_westend_local_testnet_genesis(para_id.into())) .with_properties(properties) .build() } diff --git a/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs b/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs index 754bd851b40ad..efc7db41cf75f 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs @@ -18,7 +18,7 @@ use crate::chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed}; use cumulus_primitives_core::ParaId; use parachains_common::Balance as BridgeHubBalance; use polkadot_parachain_lib::chain_spec::GenericChainSpec; -use sc_chain_spec::ChainSpec; +use sc_chain_spec::{ChainSpec, ChainType}; use sp_core::sr25519; use std::str::FromStr; @@ -100,6 +100,7 @@ impl BridgeHubRuntimeType { ParaId::new(1013), Some("Bob".to_string()), |_| (), + ChainType::Local, ))), BridgeHubRuntimeType::RococoDevelopment => Ok(Box::new(rococo::local_config( rococo::BRIDGE_HUB_ROCOCO_DEVELOPMENT, @@ -108,6 +109,7 @@ impl BridgeHubRuntimeType { ParaId::new(1013), Some("Bob".to_string()), |_| (), + ChainType::Development, ))), other => Err(std::format!("No default config present for {:?}", other)), } @@ -129,19 +131,15 @@ fn ensure_id(id: &str) -> Result<&str, String> { /// Sub-module for Rococo setup pub mod rococo { - use super::{get_account_id_from_seed, get_collator_keys_from_seed, sr25519, ParaId}; - use crate::chain_spec::SAFE_XCM_VERSION; - use parachains_common::{AccountId, AuraId}; + use super::{get_account_id_from_seed, sr25519, ChainType, ParaId}; + use bridge_hub_rococo_runtime::genesis_config_presets::{ + bridge_hub_rococo_development_genesis, bridge_hub_rococo_local_testnet_genesis, + }; use polkadot_parachain_lib::chain_spec::{Extensions, GenericChainSpec}; - use sc_chain_spec::ChainType; - - use super::BridgeHubBalance; pub(crate) const BRIDGE_HUB_ROCOCO: &str = "bridge-hub-rococo"; pub(crate) const BRIDGE_HUB_ROCOCO_LOCAL: &str = "bridge-hub-rococo-local"; pub(crate) const BRIDGE_HUB_ROCOCO_DEVELOPMENT: &str = "bridge-hub-rococo-dev"; - const BRIDGE_HUB_ROCOCO_ED: BridgeHubBalance = - bridge_hub_rococo_runtime::ExistentialDeposit::get(); pub fn local_config( id: &str, @@ -150,6 +148,7 @@ pub mod rococo { para_id: ParaId, bridges_pallet_owner_seed: Option, modify_props: ModifyProperties, + chain_type: ChainType, ) -> GenericChainSpec { // Rococo defaults let mut properties = sc_chain_spec::Properties::new(); @@ -165,86 +164,27 @@ pub mod rococo { ) .with_name(chain_name) .with_id(super::ensure_id(id).expect("invalid id")) - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(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"), - ], - para_id, - bridges_pallet_owner_seed - .as_ref() - .map(|seed| get_account_id_from_seed::(seed)), - )) + .with_chain_type(chain_type.clone()) + .with_genesis_config_patch(match chain_type { + ChainType::Development => bridge_hub_rococo_development_genesis( + para_id, + bridges_pallet_owner_seed + .as_ref() + .map(|seed| get_account_id_from_seed::(seed)), + 1000.into(), + ), + ChainType::Local => bridge_hub_rococo_local_testnet_genesis( + para_id, + bridges_pallet_owner_seed + .as_ref() + .map(|seed| get_account_id_from_seed::(seed)), + 1000.into(), + ), + _ => panic!("chain_type: {chain_type:?} not supported here!"), + }) .with_properties(properties) .build() } - - fn genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - id: ParaId, - bridges_pallet_owner: Option, - ) -> serde_json::Value { - serde_json::json!({ - "balances": { - "balances": endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::>(), - }, - "parachainInfo": { - "parachainId": id, - }, - "collatorSelection": { - "invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::>(), - "candidacyBond": BRIDGE_HUB_ROCOCO_ED * 16, - }, - "session": { - "keys": invulnerables - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - bridge_hub_rococo_runtime::SessionKeys { aura }, // session keys - ) - }) - .collect::>(), - }, - "polkadotXcm": { - "safeXcmVersion": Some(SAFE_XCM_VERSION), - }, - "bridgeWestendGrandpa": { - "owner": bridges_pallet_owner.clone(), - }, - "bridgeWestendMessages": { - "owner": bridges_pallet_owner.clone(), - }, - "ethereumSystem": { - "paraId": id, - "assetHubParaId": 1000 - } - }) - } } /// Sub-module for Kusama setup @@ -255,11 +195,12 @@ pub mod kusama { /// Sub-module for Westend setup. pub mod westend { - use super::{get_account_id_from_seed, get_collator_keys_from_seed, sr25519, ParaId}; + use super::{ + get_account_id_from_seed, get_collator_keys_from_seed, sr25519, ChainType, ParaId, + }; use crate::chain_spec::SAFE_XCM_VERSION; use parachains_common::{AccountId, AuraId}; use polkadot_parachain_lib::chain_spec::{Extensions, GenericChainSpec}; - use sc_chain_spec::ChainType; use super::BridgeHubBalance;