diff --git a/Cargo.lock b/Cargo.lock index d3434ded76..24418645c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2414,6 +2414,7 @@ dependencies = [ "polkadot-runtime-common", "polkadot-runtime-constants", "scale-info", + "serde_json", "sp-api", "sp-arithmetic 26.0.0", "sp-block-builder", diff --git a/Cargo.toml b/Cargo.toml index 1cbddedb06..681b5d6efd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -266,6 +266,7 @@ members = [ "integration-tests/emulated/tests/collectives/collectives-polkadot", "integration-tests/emulated/tests/people/people-kusama", "integration-tests/emulated/tests/people/people-polkadot", + "integration-tests/zombienet", "relay/kusama", "relay/kusama/constants", "relay/polkadot", @@ -286,7 +287,6 @@ members = [ "system-parachains/gluttons/glutton-kusama", "system-parachains/people/people-kusama", "system-parachains/people/people-polkadot", - "integration-tests/zombienet", ] [profile.release] diff --git a/chain-spec-generator/src/system_parachains_specs.rs b/chain-spec-generator/src/system_parachains_specs.rs index 059d59122f..17164b32fa 100644 --- a/chain-spec-generator/src/system_parachains_specs.rs +++ b/chain-spec-generator/src/system_parachains_specs.rs @@ -56,8 +56,6 @@ const ASSET_HUB_POLKADOT_ED: Balance = asset_hub_polkadot_runtime::ExistentialDe const ASSET_HUB_KUSAMA_ED: Balance = asset_hub_kusama_runtime::ExistentialDeposit::get(); -const COLLECTIVES_POLKADOT_ED: Balance = collectives_polkadot_runtime::ExistentialDeposit::get(); - const ENCOINTER_KUSAMA_ED: Balance = encointer_kusama_runtime::ExistentialDeposit::get(); const CORETIME_KUSAMA_ED: Balance = coretime_kusama_runtime::ExistentialDeposit::get(); @@ -114,15 +112,6 @@ pub fn asset_hub_kusama_session_keys(keys: AuraId) -> asset_hub_kusama_runtime:: asset_hub_kusama_runtime::SessionKeys { aura: keys } } -/// 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 collectives_polkadot_session_keys( - keys: AuraId, -) -> collectives_polkadot_runtime::SessionKeys { - collectives_polkadot_runtime::SessionKeys { aura: keys } -} - /// 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). @@ -281,58 +270,6 @@ pub fn asset_hub_kusama_local_testnet_config() -> Result, Str )) } -// CollectivesPolkadot -fn collectives_polkadot_genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - id: ParaId, -) -> serde_json::Value { - serde_json::json!({ - "balances": collectives_polkadot_runtime::BalancesConfig { - balances: endowed_accounts - .iter() - .cloned() - .map(|k| (k, COLLECTIVES_POLKADOT_ED * 4096 * 4096)) - .collect(), - }, - "parachainInfo": collectives_polkadot_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() - }, - "collatorSelection": collectives_polkadot_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: COLLECTIVES_POLKADOT_ED * 16, - ..Default::default() - }, - "session": collectives_polkadot_runtime::SessionConfig { - keys: invulnerables - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - collectives_polkadot_session_keys(aura), // session keys - ) - }) - .collect(), - }, - "polkadotXcm": { - "safeXcmVersion": Some(SAFE_XCM_VERSION), - }, - // no need to pass anything to aura, in fact it will panic if we do. Session will take care - // of this. `aura: Default::default()` - }) -} - -fn collectives_polkadot_local_genesis(para_id: ParaId) -> serde_json::Value { - collectives_polkadot_genesis( - // initial collators. - invulnerables(), - testnet_accounts(), - para_id, - ) -} - pub fn collectives_polkadot_local_testnet_config() -> Result, String> { let mut properties = sc_chain_spec::Properties::new(); properties.insert("ss58Format".into(), 0.into()); @@ -348,7 +285,7 @@ pub fn collectives_polkadot_local_testnet_config() -> Result, .with_name("Polkadot Collectives Local") .with_id("collectives-polkadot-local") .with_chain_type(ChainType::Local) - .with_genesis_config_patch(collectives_polkadot_local_genesis(1001.into())) + .with_genesis_config_patch(collectives_polkadot_runtime::genesis_config_presets::collectives_polkadot_local_testnet_genesis(1001.into())) .with_properties(properties) .build(), )) diff --git a/integration-tests/zombienet/Cargo.toml b/integration-tests/zombienet/Cargo.toml index d72ed9b9e2..93ce161b5b 100644 --- a/integration-tests/zombienet/Cargo.toml +++ b/integration-tests/zombienet/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] -subxt = { features = ["native"] , workspace = true } +subxt = { features = ["native"], workspace = true } tokio = { workspace = true } tracing-subscriber = { workspace = true } zombienet-sdk = { workspace = true } diff --git a/system-parachains/collectives/collectives-polkadot/Cargo.toml b/system-parachains/collectives/collectives-polkadot/Cargo.toml index 83d9d08b1c..9c219af64f 100644 --- a/system-parachains/collectives/collectives-polkadot/Cargo.toml +++ b/system-parachains/collectives/collectives-polkadot/Cargo.toml @@ -13,6 +13,7 @@ codec = { features = ["derive", "max-encoded-len"], workspace = true } hex-literal = { workspace = true } log = { workspace = true } scale-info = { features = ["derive"], workspace = true } +serde_json = { features = ["alloc"], workspace = true } # Substrate frame-benchmarking = { optional = true, workspace = true } @@ -210,6 +211,7 @@ std = [ "polkadot-runtime-common/std", "polkadot-runtime-constants/std", "scale-info/std", + "serde_json/std", "sp-api/std", "sp-arithmetic/std", "sp-block-builder/std", diff --git a/system-parachains/collectives/collectives-polkadot/src/genesis_config_presets.rs b/system-parachains/collectives/collectives-polkadot/src/genesis_config_presets.rs new file mode 100644 index 0000000000..ff4af3e739 --- /dev/null +++ b/system-parachains/collectives/collectives-polkadot/src/genesis_config_presets.rs @@ -0,0 +1,87 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +//! Genesis configs presets for the CollectivesPolkadot runtime + +use crate::*; +use sp_std::vec::Vec; +use system_parachains_constants::genesis_presets::*; + +const COLLECTIVES_POLKADOT_ED: Balance = crate::ExistentialDeposit::get(); + +fn collectives_polkadot_genesis( + invulnerables: Vec<(AccountId, AuraId)>, + endowed_accounts: Vec, + id: ParaId, +) -> serde_json::Value { + serde_json::json!({ + "balances": BalancesConfig { + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, COLLECTIVES_POLKADOT_ED * 4096 * 4096)) + .collect(), + }, + "parachainInfo": ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + "collatorSelection": CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: COLLECTIVES_POLKADOT_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(), + }, + "polkadotXcm": { + "safeXcmVersion": Some(SAFE_XCM_VERSION), + }, + // no need to pass anything to aura, in fact it will panic if we do. Session will take care + // of this. `aura: Default::default()` + }) +} + +pub fn collectives_polkadot_local_testnet_genesis(para_id: ParaId) -> serde_json::Value { + collectives_polkadot_genesis(invulnerables(), testnet_accounts(), para_id) +} + +fn collectives_polkadot_development_genesis(para_id: ParaId) -> serde_json::Value { + collectives_polkadot_local_testnet_genesis(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") => collectives_polkadot_development_genesis(1002.into()), + Ok("local_testnet") => collectives_polkadot_local_testnet_genesis(1002.into()), + _ => return None, + }; + Some( + serde_json::to_string(&patch) + .expect("serialization to json is expected to work. qed.") + .into_bytes(), + ) +} diff --git a/system-parachains/collectives/collectives-polkadot/src/lib.rs b/system-parachains/collectives/collectives-polkadot/src/lib.rs index e7b06c621f..b97f3160fc 100644 --- a/system-parachains/collectives/collectives-polkadot/src/lib.rs +++ b/system-parachains/collectives/collectives-polkadot/src/lib.rs @@ -37,6 +37,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); pub mod ambassador; +pub mod genesis_config_presets; pub mod impls; mod weights; pub mod xcm_config; @@ -963,11 +964,14 @@ 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![] + vec![ + sp_genesis_builder::PresetId::from("local_testnet"), + sp_genesis_builder::PresetId::from("development"), + ] } }