From 12c84fd465527c63c779286fcd4d929d9c119b29 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Tue, 30 Apr 2024 13:15:52 +0200 Subject: [PATCH 01/23] PoC for short benchmarking in CI with `frame-omni-bencher` Update .github/workflows/test.yml Co-authored-by: Oliver Tale-Yazdi add time to cmd --- .github/workflows/test.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 57135cf99f..3eea5d9871 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -94,6 +94,30 @@ jobs: RUSTFLAGS: "-C debug-assertions -D warnings" SKIP_WASM_BUILD: 1 + - name: Test benchmarks ${{ matrix.runtime.name }} + run: | + PACKAGE_NAME=${{ matrix.runtime.package }} + RUNTIME_BLOB_NAME=$(echo $PACKAGE_NAME | sed 's/-/_/g').compact.compressed.wasm + RUNTIME_BLOB_PATH=./target/production/wbuild/$PACKAGE_NAME/$RUNTIME_BLOB_NAME + # TODO: remove + echo "Running benchmarking for RUNTIME_BLOB_PATH=$RUNTIME_BLOB_PATH" + # build wasm + cargo build --profile production -p ${{ matrix.runtime.package }} --features=runtime-benchmarks -q --locked + # TODO: remove + ls -lrt $RUNTIME_BLOB_PATH + # TODO: get `frame-omni-bencher` somehow - GHA? or download released binary? or whatever? + # TODO: we just try to build in-place + time git clone https://github.com/paritytech/polkadot-sdk --branch master --depth 1 + git branch + cd ./polkadot-sdk + time cargo build --locked --release -p frame-omni-bencher + cd .. + # run benchmarking + echo "Running benchmarking for RUNTIME_BLOB_PATH=$RUNTIME_BLOB_PATH" + ./polkadot-sdk/target/release/frame-omni-bencher v1 benchmark pallet --runtime $RUNTIME_BLOB_PATH --all --steps 2 --repeat 1 + env: + RUSTFLAGS: "-C debug-assertions -D warnings" + # Job required by "confirmTestPassed" integration-test: needs: [integration-test-matrix] From 7c20fd93c1680a328a6ff06fa2d59010a7a69eb3 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 29 May 2024 22:53:55 +0200 Subject: [PATCH 02/23] Download `frame-omni-bencher` from release artifacts --- .github/workflows/test.yml | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3eea5d9871..08d67ef01c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,6 +9,9 @@ on: pull_request: workflow_dispatch: +env: + FRAME_OMNI_BENCHER_RELEASE_VERSION: polkadot-v1.11.0 + # cancel previous runs concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} @@ -83,6 +86,13 @@ jobs: with: shared-key: "fellowship-cache-tests" + - name: Download frame-omni-bencher + run: | + curl -sL https://github.com/paritytech/polkadot-sdk/releases/download/$FRAME_OMNI_BENCHER_RELEASE_VERSION/frame-omni-bencher -o frame-omni-bencher + chmod +x ./frame-omni-bencher + ./frame-omni-bencher --version + shell: bash + - name: Test ${{ matrix.runtime.name }} run: cargo test -p ${{ matrix.runtime.package }} --release --locked -q env: @@ -99,22 +109,13 @@ jobs: PACKAGE_NAME=${{ matrix.runtime.package }} RUNTIME_BLOB_NAME=$(echo $PACKAGE_NAME | sed 's/-/_/g').compact.compressed.wasm RUNTIME_BLOB_PATH=./target/production/wbuild/$PACKAGE_NAME/$RUNTIME_BLOB_NAME - # TODO: remove - echo "Running benchmarking for RUNTIME_BLOB_PATH=$RUNTIME_BLOB_PATH" # build wasm + echo "Preparing wasm for benchmarking RUNTIME_BLOB_PATH=$RUNTIME_BLOB_PATH" cargo build --profile production -p ${{ matrix.runtime.package }} --features=runtime-benchmarks -q --locked - # TODO: remove ls -lrt $RUNTIME_BLOB_PATH - # TODO: get `frame-omni-bencher` somehow - GHA? or download released binary? or whatever? - # TODO: we just try to build in-place - time git clone https://github.com/paritytech/polkadot-sdk --branch master --depth 1 - git branch - cd ./polkadot-sdk - time cargo build --locked --release -p frame-omni-bencher - cd .. # run benchmarking echo "Running benchmarking for RUNTIME_BLOB_PATH=$RUNTIME_BLOB_PATH" - ./polkadot-sdk/target/release/frame-omni-bencher v1 benchmark pallet --runtime $RUNTIME_BLOB_PATH --all --steps 2 --repeat 1 + ./frame-omni-bencher v1 benchmark pallet --runtime $RUNTIME_BLOB_PATH --all --steps 2 --repeat 1 env: RUSTFLAGS: "-C debug-assertions -D warnings" From 143d09adcc99ce197dedc5150bc1fc859c7f1d10 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 26 Jun 2024 10:51:31 +0200 Subject: [PATCH 03/23] Change bencher from 11 to 13 --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 08d67ef01c..438ac833ba 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ on: workflow_dispatch: env: - FRAME_OMNI_BENCHER_RELEASE_VERSION: polkadot-v1.11.0 + FRAME_OMNI_BENCHER_RELEASE_VERSION: polkadot-v1.13.0 # cancel previous runs concurrency: From 87dd772c8451f44e134a4a647fd05216b87a8c90 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 26 Jun 2024 12:25:15 +0200 Subject: [PATCH 04/23] Set `get_preset` for BridgeHubKusama --- Cargo.lock | 4 + Cargo.toml | 2 +- .../bridge-hubs/bridge-hub-kusama/Cargo.toml | 2 + .../src/genesis_config_presets.rs | 92 +++++++++++++++++++ .../bridge-hubs/bridge-hub-kusama/src/lib.rs | 8 +- system-parachains/constants/Cargo.toml | 6 ++ .../constants/src/genesis_presets.rs | 68 ++++++++++++++ system-parachains/constants/src/lib.rs | 1 + 8 files changed, 180 insertions(+), 3 deletions(-) create mode 100644 system-parachains/bridge-hubs/bridge-hub-kusama/src/genesis_config_presets.rs create mode 100644 system-parachains/constants/src/genesis_presets.rs diff --git a/Cargo.lock b/Cargo.lock index 8e57740176..a89ca5f014 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1738,6 +1738,7 @@ dependencies = [ "polkadot-runtime-constants", "scale-info", "serde", + "serde_json", "snowbridge-beacon-primitives", "snowbridge-core", "snowbridge-outbound-queue-runtime-api", @@ -14527,7 +14528,10 @@ dependencies = [ "polkadot-primitives", "polkadot-runtime-constants", "smallvec", + "sp-core 34.0.0", "sp-runtime 38.0.0", + "sp-std", + "staging-xcm", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 066fe70f4d..1cbddedb06 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -189,7 +189,7 @@ sc-chain-spec = { version = "34.0.0" } scale-info = { version = "2.10.0", default-features = false } separator = { version = "0.4.1" } serde = { version = "1.0.196" } -serde_json = { version = "1.0.113" } +serde_json = { version = "1.0.113", default-features = false } smallvec = { version = "1.13.1" } snowbridge-beacon-primitives = { version = "0.7.0", default-features = false } snowbridge-core = { version = "0.7.0", default-features = false } diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml b/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml index 6eb8dea2a9..bdf8043fd2 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml @@ -17,6 +17,7 @@ hex-literal = { workspace = true } log = { workspace = true } scale-info = { features = ["derive"], workspace = true } serde = { optional = true, features = ["derive"], workspace = true } +serde_json = { features = ["alloc"], workspace = true } tuplex = { workspace = true } # Local @@ -191,6 +192,7 @@ std = [ "polkadot-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/system-parachains/bridge-hubs/bridge-hub-kusama/src/genesis_config_presets.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/src/genesis_config_presets.rs new file mode 100644 index 0000000000..60711fe915 --- /dev/null +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/src/genesis_config_presets.rs @@ -0,0 +1,92 @@ +// 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 BridgeHubKusama runtime + +use crate::*; +use sp_std::vec::Vec; +use system_parachains_constants::genesis_presets::*; + +const BRIDGE_HUB_KUSAMA_ED: Balance = crate::ExistentialDeposit::get(); + +fn bridge_hub_kusama_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, BRIDGE_HUB_KUSAMA_ED * 4096 * 4096)) + .collect(), + }, + "parachainInfo": ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + "collatorSelection": CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: BRIDGE_HUB_KUSAMA_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), + }, + "ethereumSystem": EthereumSystemConfig { + para_id: id, + asset_hub_para_id: kusama_runtime_constants::system_parachain::ASSET_HUB_ID.into(), + ..Default::default() + }, + // 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 bridge_hub_kusama_local_testnet_genesis(para_id: ParaId) -> serde_json::Value { + bridge_hub_kusama_genesis(invulnerables(), testnet_accounts(), para_id) +} + +fn bridge_hub_kusama_development_genesis(para_id: ParaId) -> serde_json::Value { + bridge_hub_kusama_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") => bridge_hub_kusama_development_genesis(1002.into()), + Ok("local_testnet") => bridge_hub_kusama_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/bridge-hubs/bridge-hub-kusama/src/lib.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs index 48fa7da454..758ce35515 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs @@ -24,6 +24,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); pub mod bridge_to_ethereum_config; pub mod bridge_to_polkadot_config; +mod genesis_config_presets; mod weights; pub mod xcm_config; @@ -751,11 +752,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"), + ] } } diff --git a/system-parachains/constants/Cargo.toml b/system-parachains/constants/Cargo.toml index 27dd92e1f5..17582f7785 100644 --- a/system-parachains/constants/Cargo.toml +++ b/system-parachains/constants/Cargo.toml @@ -16,7 +16,10 @@ parachains-common = { workspace = true } polkadot-core-primitives = { workspace = true } polkadot-primitives = { workspace = true } polkadot-runtime-constants = { workspace = true } +sp-core = { workspace = true } sp-runtime = { workspace = true } +sp-std = { workspace = true } +xcm = { workspace = true } [features] default = ["std"] @@ -27,5 +30,8 @@ std = [ "polkadot-core-primitives/std", "polkadot-primitives/std", "polkadot-runtime-constants/std", + "sp-core/std", "sp-runtime/std", + "sp-std/std", + "xcm/std", ] diff --git a/system-parachains/constants/src/genesis_presets.rs b/system-parachains/constants/src/genesis_presets.rs new file mode 100644 index 0000000000..abb1f8b955 --- /dev/null +++ b/system-parachains/constants/src/genesis_presets.rs @@ -0,0 +1,68 @@ +// Copyright (C) Parity Technologies and the various Polkadot contributors, see Contributions.md +// for a list of specific contributors. +// 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 . + +use parachains_common::AuraId; +use polkadot_primitives::{AccountId, AccountPublic}; +use sp_core::{sr25519, Pair, Public}; +use sp_runtime::traits::IdentifyAccount; +#[cfg(not(feature = "std"))] +use sp_std::alloc::format; +use sp_std::vec::Vec; + +/// Invulnerable Collators +pub fn invulnerables() -> Vec<(parachains_common::AccountId, AuraId)> { + Vec::from([ + (get_account_id_from_seed::("Alice"), get_from_seed::("Alice")), + (get_account_id_from_seed::("Bob"), get_from_seed::("Bob")), + ]) +} + +/// Test accounts +pub fn testnet_accounts() -> Vec { + Vec::from([ + 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"), + ]) +} + +/// 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() +} + +/// 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() +} + +/// The default XCM version to set in genesis config. +pub const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; diff --git a/system-parachains/constants/src/lib.rs b/system-parachains/constants/src/lib.rs index d0d320d968..7f31f7e149 100644 --- a/system-parachains/constants/src/lib.rs +++ b/system-parachains/constants/src/lib.rs @@ -16,6 +16,7 @@ #![cfg_attr(not(feature = "std"), no_std)] +pub mod genesis_presets; pub mod kusama; pub mod polkadot; From 8793672aec7e08e331d72b6cffedc8e8ce6f607a Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 12 Jul 2024 15:19:09 +0200 Subject: [PATCH 05/23] Set `get_preset` for BridgeHubPolkadot --- Cargo.lock | 1 + .../src/system_parachains_specs.rs | 68 +------------- .../bridge-hub-polkadot/Cargo.toml | 2 + .../src/genesis_config_presets.rs | 92 +++++++++++++++++++ .../bridge-hub-polkadot/src/lib.rs | 8 +- 5 files changed, 102 insertions(+), 69 deletions(-) create mode 100644 system-parachains/bridge-hubs/bridge-hub-polkadot/src/genesis_config_presets.rs diff --git a/Cargo.lock b/Cargo.lock index a89ca5f014..25101e74fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1890,6 +1890,7 @@ dependencies = [ "polkadot-runtime-constants", "scale-info", "serde", + "serde_json", "snowbridge-beacon-primitives", "snowbridge-core", "snowbridge-outbound-queue-runtime-api", diff --git a/chain-spec-generator/src/system_parachains_specs.rs b/chain-spec-generator/src/system_parachains_specs.rs index 271f4c4479..3e1a3670e3 100644 --- a/chain-spec-generator/src/system_parachains_specs.rs +++ b/chain-spec-generator/src/system_parachains_specs.rs @@ -58,8 +58,6 @@ const ASSET_HUB_KUSAMA_ED: Balance = asset_hub_kusama_runtime::ExistentialDeposi const COLLECTIVES_POLKADOT_ED: Balance = collectives_polkadot_runtime::ExistentialDeposit::get(); -const BRIDGE_HUB_POLKADOT_ED: Balance = bridge_hub_polkadot_runtime::ExistentialDeposit::get(); - const BRIDGE_HUB_KUSAMA_ED: Balance = bridge_hub_kusama_runtime::ExistentialDeposit::get(); const ENCOINTER_KUSAMA_ED: Balance = encointer_kusama_runtime::ExistentialDeposit::get(); @@ -127,13 +125,6 @@ pub fn collectives_polkadot_session_keys( 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). -pub fn bridge_hub_polkadot_session_keys(keys: AuraId) -> bridge_hub_polkadot_runtime::SessionKeys { - bridge_hub_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). @@ -372,63 +363,6 @@ pub fn collectives_polkadot_local_testnet_config() -> Result, )) } -// BridgeHubPolkadot -fn bridge_hub_polkadot_genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - id: ParaId, -) -> serde_json::Value { - serde_json::json!({ - "balances": bridge_hub_polkadot_runtime::BalancesConfig { - balances: endowed_accounts - .iter() - .cloned() - .map(|k| (k, BRIDGE_HUB_POLKADOT_ED * 4096 * 4096)) - .collect(), - }, - "parachainInfo": bridge_hub_polkadot_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() - }, - "collatorSelection": bridge_hub_polkadot_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: BRIDGE_HUB_POLKADOT_ED * 16, - ..Default::default() - }, - "session": bridge_hub_polkadot_runtime::SessionConfig { - keys: invulnerables - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - bridge_hub_polkadot_session_keys(aura), // session keys - ) - }) - .collect(), - }, - "polkadotXcm": { - "safeXcmVersion": Some(SAFE_XCM_VERSION), - }, - "ethereumSystem": bridge_hub_polkadot_runtime::EthereumSystemConfig { - para_id: id, - asset_hub_para_id: polkadot_runtime_constants::system_parachain::ASSET_HUB_ID.into(), - ..Default::default() - }, - // 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 bridge_hub_polkadot_local_genesis(para_id: ParaId) -> serde_json::Value { - bridge_hub_polkadot_genesis( - // initial collators. - invulnerables(), - testnet_accounts(), - para_id, - ) -} - pub fn bridge_hub_polkadot_local_testnet_config() -> Result, String> { let mut properties = sc_chain_spec::Properties::new(); properties.insert("ss58Format".into(), 0.into()); @@ -444,7 +378,7 @@ pub fn bridge_hub_polkadot_local_testnet_config() -> Result, .with_name("Polkadot Bridge Hub Local") .with_id("bridge-hub-polkadot-local") .with_chain_type(ChainType::Local) - .with_genesis_config_patch(bridge_hub_polkadot_local_genesis(1002.into())) + .with_genesis_config_patch(bridge_hub_polkadot_runtime::genesis_config_presets::bridge_hub_polkadot_local_testnet_genesis(1002.into())) .with_properties(properties) .build(), )) diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml b/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml index 7ce786eb5b..50287e87fb 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml @@ -17,6 +17,7 @@ hex-literal = { workspace = true } log = { workspace = true } scale-info = { features = ["derive"], workspace = true } serde = { optional = true, features = ["derive"], workspace = true } +serde_json = { features = ["alloc"], workspace = true } tuplex = { workspace = true } # Local @@ -187,6 +188,7 @@ std = [ "polkadot-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/system-parachains/bridge-hubs/bridge-hub-polkadot/src/genesis_config_presets.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/genesis_config_presets.rs new file mode 100644 index 0000000000..9a1ed6657b --- /dev/null +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/genesis_config_presets.rs @@ -0,0 +1,92 @@ +// 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 BridgeHubPolkadot runtime + +use crate::*; +use sp_std::vec::Vec; +use system_parachains_constants::genesis_presets::*; + +const BRIDGE_HUB_POLKADOT_ED: Balance = crate::ExistentialDeposit::get(); + +fn bridge_hub_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, BRIDGE_HUB_POLKADOT_ED * 4096 * 4096)) + .collect(), + }, + "parachainInfo": ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + "collatorSelection": CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: BRIDGE_HUB_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), + }, + "ethereumSystem": EthereumSystemConfig { + para_id: id, + asset_hub_para_id: polkadot_runtime_constants::system_parachain::ASSET_HUB_ID.into(), + ..Default::default() + }, + // 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 bridge_hub_polkadot_local_testnet_genesis(para_id: ParaId) -> serde_json::Value { + bridge_hub_polkadot_genesis(invulnerables(), testnet_accounts(), para_id) +} + +fn bridge_hub_polkadot_development_genesis(para_id: ParaId) -> serde_json::Value { + bridge_hub_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") => bridge_hub_polkadot_development_genesis(1002.into()), + Ok("local_testnet") => bridge_hub_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/bridge-hubs/bridge-hub-polkadot/src/lib.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs index 7adceeecf3..b8ded62b94 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs @@ -24,6 +24,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); pub mod bridge_to_ethereum_config; pub mod bridge_to_kusama_config; +pub mod genesis_config_presets; mod weights; pub mod xcm_config; @@ -760,11 +761,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"), + ] } } From 26061e160a4d25ff8b97e7eb1d02b3ca3a0ec4b0 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Fri, 12 Jul 2024 15:32:05 +0200 Subject: [PATCH 06/23] Clean up chain-spec-generator for BridgeHubKusama --- .../src/system_parachains_specs.rs | 68 +------------------ .../src/genesis_config_presets.rs | 2 +- .../bridge-hubs/bridge-hub-kusama/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 69 deletions(-) diff --git a/chain-spec-generator/src/system_parachains_specs.rs b/chain-spec-generator/src/system_parachains_specs.rs index 3e1a3670e3..059d59122f 100644 --- a/chain-spec-generator/src/system_parachains_specs.rs +++ b/chain-spec-generator/src/system_parachains_specs.rs @@ -58,8 +58,6 @@ const ASSET_HUB_KUSAMA_ED: Balance = asset_hub_kusama_runtime::ExistentialDeposi const COLLECTIVES_POLKADOT_ED: Balance = collectives_polkadot_runtime::ExistentialDeposit::get(); -const BRIDGE_HUB_KUSAMA_ED: Balance = bridge_hub_kusama_runtime::ExistentialDeposit::get(); - const ENCOINTER_KUSAMA_ED: Balance = encointer_kusama_runtime::ExistentialDeposit::get(); const CORETIME_KUSAMA_ED: Balance = coretime_kusama_runtime::ExistentialDeposit::get(); @@ -125,13 +123,6 @@ pub fn collectives_polkadot_session_keys( 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). -pub fn bridge_hub_kusama_session_keys(keys: AuraId) -> bridge_hub_kusama_runtime::SessionKeys { - bridge_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). @@ -384,63 +375,6 @@ pub fn bridge_hub_polkadot_local_testnet_config() -> Result, )) } -// BridgeHubKusama -fn bridge_hub_kusama_genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - id: ParaId, -) -> serde_json::Value { - serde_json::json!({ - "balances": bridge_hub_kusama_runtime::BalancesConfig { - balances: endowed_accounts - .iter() - .cloned() - .map(|k| (k, BRIDGE_HUB_KUSAMA_ED * 4096 * 4096)) - .collect(), - }, - "parachainInfo": bridge_hub_kusama_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() - }, - "collatorSelection": bridge_hub_kusama_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: BRIDGE_HUB_KUSAMA_ED * 16, - ..Default::default() - }, - "session": bridge_hub_kusama_runtime::SessionConfig { - keys: invulnerables - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - bridge_hub_kusama_session_keys(aura), // session keys - ) - }) - .collect(), - }, - "polkadotXcm": { - "safeXcmVersion": Some(SAFE_XCM_VERSION), - }, - "ethereumSystem": bridge_hub_kusama_runtime::EthereumSystemConfig { - para_id: id, - asset_hub_para_id: kusama_runtime_constants::system_parachain::ASSET_HUB_ID.into(), - ..Default::default() - }, - // 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 bridge_hub_kusama_local_genesis(para_id: ParaId) -> serde_json::Value { - bridge_hub_kusama_genesis( - // initial collators. - invulnerables(), - testnet_accounts(), - para_id, - ) -} - pub fn bridge_hub_kusama_local_testnet_config() -> Result, String> { let mut properties = sc_chain_spec::Properties::new(); properties.insert("ss58Format".into(), 2.into()); @@ -455,7 +389,7 @@ pub fn bridge_hub_kusama_local_testnet_config() -> Result, St .with_name("Kusama Bridge Hub Local") .with_id("bridge-hub-kusama-local") .with_chain_type(ChainType::Local) - .with_genesis_config_patch(bridge_hub_kusama_local_genesis(1002.into())) + .with_genesis_config_patch(bridge_hub_kusama_runtime::genesis_config_presets::bridge_hub_kusama_local_testnet_genesis(1002.into())) .with_properties(properties) .build(), )) diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/src/genesis_config_presets.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/src/genesis_config_presets.rs index 60711fe915..c8cf7b22ca 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/src/genesis_config_presets.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/src/genesis_config_presets.rs @@ -69,7 +69,7 @@ fn bridge_hub_kusama_genesis( }) } -fn bridge_hub_kusama_local_testnet_genesis(para_id: ParaId) -> serde_json::Value { +pub fn bridge_hub_kusama_local_testnet_genesis(para_id: ParaId) -> serde_json::Value { bridge_hub_kusama_genesis(invulnerables(), testnet_accounts(), para_id) } diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs index 758ce35515..35d4e6318e 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs @@ -24,7 +24,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); pub mod bridge_to_ethereum_config; pub mod bridge_to_polkadot_config; -mod genesis_config_presets; +pub mod genesis_config_presets; mod weights; pub mod xcm_config; From 255e6702f547a2dda4e08cae69e9b0b547532924 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Tue, 16 Jul 2024 15:55:21 +0200 Subject: [PATCH 07/23] Set `get_preset` for CollectivesPolkadot --- Cargo.lock | 1 + Cargo.toml | 2 +- .../src/system_parachains_specs.rs | 65 +------------- integration-tests/zombienet/Cargo.toml | 2 +- .../collectives-polkadot/Cargo.toml | 2 + .../src/genesis_config_presets.rs | 87 +++++++++++++++++++ .../collectives-polkadot/src/lib.rs | 8 +- 7 files changed, 99 insertions(+), 68 deletions(-) create mode 100644 system-parachains/collectives/collectives-polkadot/src/genesis_config_presets.rs diff --git a/Cargo.lock b/Cargo.lock index 25101e74fb..a9d7b7ffc5 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"), + ] } } From 32e958b63b5b22ee837c1180868cbde53d957da1 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 17 Jul 2024 18:13:07 +0200 Subject: [PATCH 08/23] Set `get_preset` for AssetHubs --- .../src/system_parachains_specs.rs | 143 +----------------- .../asset-hubs/asset-hub-kusama/Cargo.toml | 2 + .../src/genesis_config_presets.rs | 87 +++++++++++ .../asset-hubs/asset-hub-kusama/src/lib.rs | 9 +- .../asset-hubs/asset-hub-polkadot/Cargo.toml | 2 + .../src/genesis_config_presets.rs | 103 +++++++++++++ .../asset-hubs/asset-hub-polkadot/src/lib.rs | 9 +- .../bridge-hubs/bridge-hub-kusama/src/lib.rs | 1 + .../bridge-hub-polkadot/src/lib.rs | 1 + .../src/genesis_config_presets.rs | 4 +- .../collectives-polkadot/src/lib.rs | 1 + 11 files changed, 216 insertions(+), 146 deletions(-) create mode 100644 system-parachains/asset-hubs/asset-hub-kusama/src/genesis_config_presets.rs create mode 100644 system-parachains/asset-hubs/asset-hub-polkadot/src/genesis_config_presets.rs diff --git a/chain-spec-generator/src/system_parachains_specs.rs b/chain-spec-generator/src/system_parachains_specs.rs index 17164b32fa..b3d20e9c87 100644 --- a/chain-spec-generator/src/system_parachains_specs.rs +++ b/chain-spec-generator/src/system_parachains_specs.rs @@ -17,7 +17,7 @@ use crate::common::{get_account_id_from_seed, get_from_seed, testnet_accounts}; use cumulus_primitives_core::ParaId; -use parachains_common::{AccountId, AssetHubPolkadotAuraId, AuraId, Balance}; +use parachains_common::{AccountId, AuraId, Balance}; use sc_chain_spec::{ChainSpec, ChainSpecExtension, ChainSpecGroup, ChainType}; use serde::{Deserialize, Serialize}; use sp_core::sr25519; @@ -52,10 +52,6 @@ pub type PeopleKusamaChainSpec = sc_chain_spec::GenericChainSpec; pub type PeoplePolkadotChainSpec = sc_chain_spec::GenericChainSpec; -const ASSET_HUB_POLKADOT_ED: Balance = asset_hub_polkadot_runtime::ExistentialDeposit::get(); - -const ASSET_HUB_KUSAMA_ED: Balance = asset_hub_kusama_runtime::ExistentialDeposit::get(); - const ENCOINTER_KUSAMA_ED: Balance = encointer_kusama_runtime::ExistentialDeposit::get(); const CORETIME_KUSAMA_ED: Balance = coretime_kusama_runtime::ExistentialDeposit::get(); @@ -67,28 +63,6 @@ const PEOPLE_POLKADOT_ED: Balance = people_polkadot_runtime::ExistentialDeposit: /// The default XCM version to set in genesis config. const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; -/// Invulnerable Collators -pub fn invulnerables() -> Vec<(AccountId, AuraId)> { - vec![ - (get_account_id_from_seed::("Alice"), get_from_seed::("Alice")), - (get_account_id_from_seed::("Bob"), get_from_seed::("Bob")), - ] -} - -/// Invulnerable Collators for the particular case of AssetHubPolkadot -pub fn invulnerables_asset_hub_polkadot() -> Vec<(AccountId, AssetHubPolkadotAuraId)> { - vec![ - ( - get_account_id_from_seed::("Alice"), - get_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_from_seed::("Bob"), - ), - ] -} - /// 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). @@ -96,22 +70,6 @@ pub fn coretime_kusama_session_keys(keys: AuraId) -> coretime_kusama_runtime::Se coretime_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 asset_hub_polkadot_session_keys( - keys: AssetHubPolkadotAuraId, -) -> asset_hub_polkadot_runtime::SessionKeys { - asset_hub_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). -pub fn asset_hub_kusama_session_keys(keys: AuraId) -> asset_hub_kusama_runtime::SessionKeys { - 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). @@ -126,49 +84,6 @@ pub fn people_polkadot_session_keys(keys: AuraId) -> people_polkadot_runtime::Se people_polkadot_runtime::SessionKeys { aura: keys } } -// AssetHubPolkadot -fn asset_hub_polkadot_genesis( - invulnerables: Vec<(AccountId, AssetHubPolkadotAuraId)>, - endowed_accounts: Vec, - id: ParaId, -) -> serde_json::Value { - serde_json::json!({ - "balances": asset_hub_polkadot_runtime::BalancesConfig { - balances: endowed_accounts - .iter() - .cloned() - .map(|k| (k, ASSET_HUB_POLKADOT_ED * 4096 * 4096)) - .collect(), - }, - "parachainInfo": asset_hub_polkadot_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() - }, - "collatorSelection": asset_hub_polkadot_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: ASSET_HUB_POLKADOT_ED * 16, - ..Default::default() - }, - "session": asset_hub_polkadot_runtime::SessionConfig { - keys: invulnerables - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - asset_hub_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 asset_hub_polkadot_local_genesis(para_id: ParaId) -> serde_json::Value { asset_hub_polkadot_genesis( // initial collators. @@ -192,64 +107,12 @@ pub fn asset_hub_polkadot_local_testnet_config() -> Result, S .with_name("Polkadot Asset Hub Local") .with_id("asset-hub-polkadot-local") .with_chain_type(ChainType::Local) - .with_genesis_config_patch(asset_hub_polkadot_local_genesis(1000.into())) + .with_genesis_config_patch(asset_hub_polkadot_runtime::genesis_config_presets::asset_hub_polkadot_local_testnet_genesis(1000.into())) .with_properties(properties) .build(), )) } -// AssetHubKusama -fn asset_hub_kusama_genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - id: ParaId, -) -> serde_json::Value { - serde_json::json!({ - "balances": asset_hub_kusama_runtime::BalancesConfig { - balances: endowed_accounts - .iter() - .cloned() - .map(|k| (k, ASSET_HUB_KUSAMA_ED * 4096 * 4096)) - .collect(), - }, - "parachainInfo": asset_hub_kusama_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() - }, - "collatorSelection": asset_hub_kusama_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: ASSET_HUB_KUSAMA_ED * 16, - ..Default::default() - }, - "session": asset_hub_kusama_runtime::SessionConfig { - keys: invulnerables - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - asset_hub_kusama_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 asset_hub_kusama_local_genesis(para_id: ParaId) -> serde_json::Value { - asset_hub_kusama_genesis( - // initial collators. - invulnerables(), - testnet_accounts(), - para_id, - ) -} - pub fn asset_hub_kusama_local_testnet_config() -> Result, String> { let mut properties = sc_chain_spec::Properties::new(); properties.insert("ss58Format".into(), 2.into()); @@ -264,7 +127,7 @@ pub fn asset_hub_kusama_local_testnet_config() -> Result, Str .with_name("Kusama Asset Hub Local") .with_id("asset-hub-kusama-local") .with_chain_type(ChainType::Local) - .with_genesis_config_patch(asset_hub_kusama_local_genesis(1000.into())) + .with_genesis_config_patch(asset_hub_kusama_runtime::genesis_config_presets::asset_hub_kusama_local_testnet_genesis(1000.into())) .with_properties(properties) .build(), )) diff --git a/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml b/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml index 1184dfc2f2..fe21cc7e7c 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml +++ b/system-parachains/asset-hubs/asset-hub-kusama/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 } # Local bp-asset-hub-kusama = { workspace = true } @@ -252,6 +253,7 @@ std = [ "polkadot-runtime-constants/std", "primitive-types/std", "scale-info/std", + "serde_json/std", "snowbridge-router-primitives/std", "sp-api/std", "sp-block-builder/std", diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/genesis_config_presets.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/genesis_config_presets.rs new file mode 100644 index 0000000000..a5ca1c2c7f --- /dev/null +++ b/system-parachains/asset-hubs/asset-hub-kusama/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 AssetHubKusama runtime + +use crate::*; +use sp_std::vec::Vec; +use system_parachains_constants::genesis_presets::*; + +const ASSET_HUB_KUSAMA_ED: Balance = crate::ExistentialDeposit::get(); + +fn asset_hub_kusama_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, ASSET_HUB_KUSAMA_ED * 4096 * 4096)) + .collect(), + }, + "parachainInfo": ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + "collatorSelection": CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: ASSET_HUB_KUSAMA_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 asset_hub_kusama_local_testnet_genesis(para_id: ParaId) -> serde_json::Value { + asset_hub_kusama_genesis(invulnerables(), testnet_accounts(), para_id) +} + +fn asset_hub_kusama_development_genesis(para_id: ParaId) -> serde_json::Value { + asset_hub_kusama_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") => asset_hub_kusama_development_genesis(1000.into()), + Ok("local_testnet") => asset_hub_kusama_local_testnet_genesis(1000.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/asset-hubs/asset-hub-kusama/src/lib.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs index 09be6931df..8045a075a8 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs @@ -24,6 +24,8 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); +// Genesis preset configurations. +pub mod genesis_config_presets; mod impls; mod weights; pub mod xcm_config; @@ -1335,11 +1337,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"), + ] } } diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml b/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml index 4dce9f6a45..22a6d4ead8 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml +++ b/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml @@ -13,6 +13,7 @@ codec = { features = ["derive", "max-encoded-len"], workspace = true } hex-literal = { optional = true, workspace = true } log = { workspace = true } scale-info = { features = ["derive"], workspace = true } +serde_json = { features = ["alloc"], workspace = true } # Local bp-asset-hub-kusama = { workspace = true } @@ -233,6 +234,7 @@ std = [ "polkadot-runtime-constants/std", "primitive-types/std", "scale-info/std", + "serde_json/std", "snowbridge-router-primitives/std", "sp-api/std", "sp-block-builder/std", diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/genesis_config_presets.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/genesis_config_presets.rs new file mode 100644 index 0000000000..29cc27fb6b --- /dev/null +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/genesis_config_presets.rs @@ -0,0 +1,103 @@ +// 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 AssetHubPolkadot runtime + +use crate::*; +use parachains_common::AssetHubPolkadotAuraId; +use sp_core::sr25519; +use sp_std::vec::Vec; +use system_parachains_constants::genesis_presets::*; + +const ASSET_HUB_POLKADOT_ED: Balance = crate::ExistentialDeposit::get(); + +/// Invulnerable Collators for the particular case of AssetHubPolkadot +pub fn invulnerables_asset_hub_polkadot() -> Vec<(AccountId, AssetHubPolkadotAuraId)> { + vec![ + ( + get_account_id_from_seed::("Alice"), + get_from_seed::("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_from_seed::("Bob"), + ), + ] +} + +fn asset_hub_polkadot_genesis( + invulnerables: Vec<(AccountId, AssetHubPolkadotAuraId)>, + endowed_accounts: Vec, + id: ParaId, +) -> serde_json::Value { + serde_json::json!({ + "balances": BalancesConfig { + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, ASSET_HUB_POLKADOT_ED * 4096 * 4096)) + .collect(), + }, + "parachainInfo": ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + "collatorSelection": CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: ASSET_HUB_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 asset_hub_polkadot_local_testnet_genesis(para_id: ParaId) -> serde_json::Value { + asset_hub_polkadot_genesis(invulnerables_asset_hub_polkadot(), testnet_accounts(), para_id) +} + +fn asset_hub_polkadot_development_genesis(para_id: ParaId) -> serde_json::Value { + asset_hub_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") => asset_hub_polkadot_development_genesis(1000.into()), + Ok("local_testnet") => asset_hub_polkadot_local_testnet_genesis(1000.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/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index f163a6bcfa..1809e3112c 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -59,6 +59,8 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); +// Genesis preset configurations. +pub mod genesis_config_presets; mod impls; mod weights; pub mod xcm_config; @@ -1296,11 +1298,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"), + ] } } diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs index 35d4e6318e..9c44619577 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs @@ -24,6 +24,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); pub mod bridge_to_ethereum_config; pub mod bridge_to_polkadot_config; +// Genesis preset configurations. pub mod genesis_config_presets; mod weights; pub mod xcm_config; diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs index b8ded62b94..35461a3879 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/lib.rs @@ -24,6 +24,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); pub mod bridge_to_ethereum_config; pub mod bridge_to_kusama_config; +// Genesis preset configurations. pub mod genesis_config_presets; mod weights; pub mod xcm_config; diff --git a/system-parachains/collectives/collectives-polkadot/src/genesis_config_presets.rs b/system-parachains/collectives/collectives-polkadot/src/genesis_config_presets.rs index ff4af3e739..10f3973efa 100644 --- a/system-parachains/collectives/collectives-polkadot/src/genesis_config_presets.rs +++ b/system-parachains/collectives/collectives-polkadot/src/genesis_config_presets.rs @@ -75,8 +75,8 @@ fn collectives_polkadot_development_genesis(para_id: ParaId) -> serde_json::Valu /// 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()), + Ok("development") => collectives_polkadot_development_genesis(1001.into()), + Ok("local_testnet") => collectives_polkadot_local_testnet_genesis(1001.into()), _ => return None, }; Some( diff --git a/system-parachains/collectives/collectives-polkadot/src/lib.rs b/system-parachains/collectives/collectives-polkadot/src/lib.rs index b97f3160fc..891438694c 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; +// Genesis preset configurations. pub mod genesis_config_presets; pub mod impls; mod weights; From b39eabc1612aa039f40df0c5b595413613fa4bd3 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 17 Jul 2024 18:19:51 +0200 Subject: [PATCH 09/23] Set `get_preset` for CoretimeKusama --- .../src/system_parachains_specs.rs | 90 ++----------------- .../coretime/coretime-kusama/Cargo.toml | 2 + .../src/genesis_config_presets.rs | 87 ++++++++++++++++++ .../coretime/coretime-kusama/src/lib.rs | 9 +- 4 files changed, 101 insertions(+), 87 deletions(-) create mode 100644 system-parachains/coretime/coretime-kusama/src/genesis_config_presets.rs diff --git a/chain-spec-generator/src/system_parachains_specs.rs b/chain-spec-generator/src/system_parachains_specs.rs index b3d20e9c87..af259f4ff2 100644 --- a/chain-spec-generator/src/system_parachains_specs.rs +++ b/chain-spec-generator/src/system_parachains_specs.rs @@ -54,8 +54,6 @@ pub type PeoplePolkadotChainSpec = sc_chain_spec::GenericChainSpec; const ENCOINTER_KUSAMA_ED: Balance = encointer_kusama_runtime::ExistentialDeposit::get(); -const CORETIME_KUSAMA_ED: Balance = coretime_kusama_runtime::ExistentialDeposit::get(); - const PEOPLE_KUSAMA_ED: Balance = people_kusama_runtime::ExistentialDeposit::get(); const PEOPLE_POLKADOT_ED: Balance = people_polkadot_runtime::ExistentialDeposit::get(); @@ -63,36 +61,6 @@ const PEOPLE_POLKADOT_ED: Balance = people_polkadot_runtime::ExistentialDeposit: /// The default XCM version to set in genesis config. const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; -/// 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 coretime_kusama_session_keys(keys: AuraId) -> coretime_kusama_runtime::SessionKeys { - coretime_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 people_kusama_session_keys(keys: AuraId) -> people_kusama_runtime::SessionKeys { - people_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 people_polkadot_session_keys(keys: AuraId) -> people_polkadot_runtime::SessionKeys { - people_polkadot_runtime::SessionKeys { aura: keys } -} - -fn asset_hub_polkadot_local_genesis(para_id: ParaId) -> serde_json::Value { - asset_hub_polkadot_genesis( - // initial collators. - invulnerables_asset_hub_polkadot(), - testnet_accounts(), - para_id, - ) -} - pub fn asset_hub_polkadot_local_testnet_config() -> Result, String> { let mut properties = sc_chain_spec::Properties::new(); properties.insert("ss58Format".into(), 0.into()); @@ -294,58 +262,6 @@ pub fn encointer_kusama_local_testnet_config() -> Result, Str )) } -// CoretimeKusama -fn coretime_kusama_genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - id: ParaId, -) -> serde_json::Value { - serde_json::json!({ - "balances": coretime_kusama_runtime::BalancesConfig { - balances: endowed_accounts - .iter() - .cloned() - .map(|k| (k, CORETIME_KUSAMA_ED * 4096 * 4096)) - .collect(), - }, - "parachainInfo": coretime_kusama_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() - }, - "collatorSelection": coretime_kusama_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: CORETIME_KUSAMA_ED * 16, - ..Default::default() - }, - "session": coretime_kusama_runtime::SessionConfig { - keys: invulnerables - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - coretime_kusama_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 coretime_kusama_local_genesis(para_id: ParaId) -> serde_json::Value { - coretime_kusama_genesis( - // initial collators. - invulnerables(), - testnet_accounts(), - para_id, - ) -} - pub fn coretime_kusama_local_testnet_config() -> Result, String> { let mut properties = sc_chain_spec::Properties::new(); properties.insert("ss58Format".into(), 2.into()); @@ -360,7 +276,11 @@ pub fn coretime_kusama_local_testnet_config() -> Result, Stri .with_name("Kusama Coretime Local") .with_id("coretime-kusama-local") .with_chain_type(ChainType::Local) - .with_genesis_config_patch(coretime_kusama_local_genesis(1005.into())) + .with_genesis_config_patch( + coretime_kusama_runtime::genesis_config_presets::coretime_kusama_local_testnet_genesis( + 1005.into(), + ), + ) .with_properties(properties) .build(), )) diff --git a/system-parachains/coretime/coretime-kusama/Cargo.toml b/system-parachains/coretime/coretime-kusama/Cargo.toml index 810e50bffd..2a5c98b37a 100644 --- a/system-parachains/coretime/coretime-kusama/Cargo.toml +++ b/system-parachains/coretime/coretime-kusama/Cargo.toml @@ -14,6 +14,7 @@ hex-literal = { workspace = true } log = { workspace = true } scale-info = { features = ["derive"], workspace = true } serde = { optional = true, features = ["derive"], workspace = true } +serde_json = { features = ["alloc"], workspace = true } # Local kusama-runtime-constants = { workspace = true } @@ -128,6 +129,7 @@ std = [ "polkadot-parachain-primitives/std", "polkadot-runtime-common/std", "scale-info/std", + "serde_json/std", "serde", "sp-api/std", "sp-block-builder/std", diff --git a/system-parachains/coretime/coretime-kusama/src/genesis_config_presets.rs b/system-parachains/coretime/coretime-kusama/src/genesis_config_presets.rs new file mode 100644 index 0000000000..6234d65baf --- /dev/null +++ b/system-parachains/coretime/coretime-kusama/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 CoretimeKusama runtime + +use crate::*; +use sp_std::vec::Vec; +use system_parachains_constants::genesis_presets::*; + +const CORETIME_KUSAMA_ED: Balance = crate::ExistentialDeposit::get(); + +fn coretime_kusama_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, CORETIME_KUSAMA_ED * 4096 * 4096)) + .collect(), + }, + "parachainInfo": ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + "collatorSelection": CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: CORETIME_KUSAMA_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 coretime_kusama_local_testnet_genesis(para_id: ParaId) -> serde_json::Value { + coretime_kusama_genesis(invulnerables(), testnet_accounts(), para_id) +} + +fn coretime_kusama_development_genesis(para_id: ParaId) -> serde_json::Value { + coretime_kusama_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") => coretime_kusama_development_genesis(1005.into()), + Ok("local_testnet") => coretime_kusama_local_testnet_genesis(1005.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/coretime/coretime-kusama/src/lib.rs b/system-parachains/coretime/coretime-kusama/src/lib.rs index aefd31d6f8..8eb280697e 100644 --- a/system-parachains/coretime/coretime-kusama/src/lib.rs +++ b/system-parachains/coretime/coretime-kusama/src/lib.rs @@ -23,6 +23,8 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); mod coretime; +// Genesis preset configurations. +pub mod genesis_config_presets; #[cfg(test)] mod tests; mod weights; @@ -1042,11 +1044,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"), + ] } } } From 36170a33914f8c31e934a86980922e4ef3707aa6 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 17 Jul 2024 18:32:44 +0200 Subject: [PATCH 10/23] Set `get_preset` for Encointer --- .../src/system_parachains_specs.rs | 51 +--- system-parachains/encointer/Cargo.toml | 9 +- .../encointer/src/genesis_config_presets.rs | 87 ++++++ system-parachains/encointer/src/lib.rs | 251 +----------------- 4 files changed, 99 insertions(+), 299 deletions(-) create mode 100644 system-parachains/encointer/src/genesis_config_presets.rs diff --git a/chain-spec-generator/src/system_parachains_specs.rs b/chain-spec-generator/src/system_parachains_specs.rs index af259f4ff2..646f86e544 100644 --- a/chain-spec-generator/src/system_parachains_specs.rs +++ b/chain-spec-generator/src/system_parachains_specs.rs @@ -52,8 +52,6 @@ pub type PeopleKusamaChainSpec = sc_chain_spec::GenericChainSpec; pub type PeoplePolkadotChainSpec = sc_chain_spec::GenericChainSpec; -const ENCOINTER_KUSAMA_ED: Balance = encointer_kusama_runtime::ExistentialDeposit::get(); - const PEOPLE_KUSAMA_ED: Balance = people_kusama_runtime::ExistentialDeposit::get(); const PEOPLE_POLKADOT_ED: Balance = people_polkadot_runtime::ExistentialDeposit::get(); @@ -195,53 +193,6 @@ pub fn glutton_kusama_local_testnet_config() -> Result, Strin )) } -// EncointerKusama -fn encointer_kusama_genesis(endowed_accounts: Vec, id: u32) -> serde_json::Value { - serde_json::json!({ - "balances": asset_hub_kusama_runtime::BalancesConfig { - balances: endowed_accounts - .iter() - .cloned() - .map(|k| (k, ENCOINTER_KUSAMA_ED * 4096)) - .collect(), - }, - "parachainInfo": encointer_kusama_runtime::ParachainInfoConfig { - parachain_id: id.into(), - ..Default::default() - }, - "collatorSelection": encointer_kusama_runtime::CollatorSelectionConfig { - invulnerables: invulnerables().iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: ENCOINTER_KUSAMA_ED * 16, - ..Default::default() - }, - "session": asset_hub_kusama_runtime::SessionConfig { - keys: invulnerables() - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - asset_hub_kusama_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 encointer_kusama_local_genesis(para_id: u32) -> serde_json::Value { - encointer_kusama_genesis( - // initial collators. - testnet_accounts(), - para_id, - ) -} - pub fn encointer_kusama_local_testnet_config() -> Result, String> { let mut properties = sc_chain_spec::Properties::new(); properties.insert("ss58Format".into(), 2.into()); @@ -256,7 +207,7 @@ pub fn encointer_kusama_local_testnet_config() -> Result, Str .with_name("Kusama Encointer Local") .with_id("encointer-kusama-local") .with_chain_type(ChainType::Local) - .with_genesis_config_patch(encointer_kusama_local_genesis(1001)) + .with_genesis_config_patch(encointer_kusama_runtime::genesis_config_presets::encointer_kusama_local_testnet_genesis(1001)) .with_properties(properties) .build(), )) diff --git a/system-parachains/encointer/Cargo.toml b/system-parachains/encointer/Cargo.toml index 0f75e3365b..37b8fc9ac6 100644 --- a/system-parachains/encointer/Cargo.toml +++ b/system-parachains/encointer/Cargo.toml @@ -14,6 +14,7 @@ hex-literal = { workspace = true } log = { workspace = true } scale-info = { features = ["derive"], workspace = true } smallvec = { workspace = true } +serde_json = { features = ["alloc"], workspace = true } # Encointer pallet versioning follows these rules: @@ -99,17 +100,13 @@ parachain-info = { workspace = true } parachains-common = { workspace = true } polkadot-core-primitives = { workspace = true } polkadot-primitives = { workspace = true } +system-parachains-constants = { workspace = true } [build-dependencies] substrate-wasm-builder = { optional = true, workspace = true } [dev-dependencies] -# The Encointer pallets might not have compatible versions of `polkadot-sdk` with the rest of the system parachains, -# so we need to copy all the contents from `system-parachains-constants` and `kusama-runtime-constants`. -# We use these crates only for testing to ensure compatible values. -# NOTE: Do not add this to the `[dependencies]` kusama-runtime-constants = { workspace = true, default-features = true } -system-parachains-constants = { workspace = true, default-features = true } [features] default = ["std"] @@ -208,6 +205,7 @@ std = [ "polkadot-primitives/std", "polkadot-runtime-common/std", "scale-info/std", + "serde_json/std", "sp-api/std", "sp-block-builder/std", "sp-consensus-aura/std", @@ -221,6 +219,7 @@ std = [ "sp-transaction-pool/std", "sp-version/std", "substrate-wasm-builder", + "system-parachains-constants/std", "xcm-builder/std", "xcm-executor/std", "xcm/std", diff --git a/system-parachains/encointer/src/genesis_config_presets.rs b/system-parachains/encointer/src/genesis_config_presets.rs new file mode 100644 index 0000000000..19d4dcce3d --- /dev/null +++ b/system-parachains/encointer/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 EincointerKusama runtime + +use crate::*; +use sp_std::vec::Vec; +use system_parachains_constants::genesis_presets::*; + +const ENCOINTER_KUSAMA_ED: Balance = crate::ExistentialDeposit::get(); + +fn encointer_kusama_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, ENCOINTER_KUSAMA_ED * 4096)) + .collect(), + }, + "parachainInfo": ParachainInfoConfig { + parachain_id: id.into(), + ..Default::default() + }, + "collatorSelection": CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: ENCOINTER_KUSAMA_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 encointer_kusama_local_testnet_genesis(para_id: ParaId) -> serde_json::Value { + encointer_kusama_genesis(invulnerables(), testnet_accounts(), para_id) +} + +fn encointer_kusama_development_genesis(para_id: ParaId) -> serde_json::Value { + encointer_kusama_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") => encointer_kusama_development_genesis(1001.into()), + Ok("local_testnet") => encointer_kusama_local_testnet_genesis(1001.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/encointer/src/lib.rs b/system-parachains/encointer/src/lib.rs index 0cce8191c3..1591d802fa 100644 --- a/system-parachains/encointer/src/lib.rs +++ b/system-parachains/encointer/src/lib.rs @@ -31,6 +31,8 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); +// Genesis preset configurations. +pub mod genesis_config_presets; mod migrations_fix; mod weights; pub mod xcm_config; @@ -976,11 +978,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"), + ] } } @@ -1097,251 +1102,9 @@ fn test_ed_is_one_tenth_of_relay() { assert_eq!(relay_ed / 10, encointer_ed); } -#[test] -fn test_constants_compatiblity() { - assert_eq!( - ::kusama_runtime_constants::currency::EXISTENTIAL_DEPOSIT, - system_parachains_constants::kusama_runtime_constants::currency::EXISTENTIAL_DEPOSIT - ); - assert_eq!( - ::kusama_runtime_constants::currency::deposit(5, 3), - system_parachains_constants::kusama_runtime_constants::currency::deposit(5, 3) - ); - assert_eq!( - ::system_parachains_constants::AVERAGE_ON_INITIALIZE_RATIO * 1u32, - system_parachains_constants::AVERAGE_ON_INITIALIZE_RATIO * 1u32 - ); - assert_eq!( - ::system_parachains_constants::NORMAL_DISPATCH_RATIO * 1u32, - system_parachains_constants::NORMAL_DISPATCH_RATIO * 1u32 - ); - assert_eq!( - ::system_parachains_constants::MAXIMUM_BLOCK_WEIGHT.encode(), - system_parachains_constants::MAXIMUM_BLOCK_WEIGHT.encode() - ); - assert_eq!(::system_parachains_constants::MINUTES, system_parachains_constants::MINUTES); - assert_eq!(::system_parachains_constants::HOURS, system_parachains_constants::HOURS); - assert_eq!(::system_parachains_constants::DAYS, system_parachains_constants::DAYS); - assert_eq!( - ::system_parachains_constants::kusama::currency::SYSTEM_PARA_EXISTENTIAL_DEPOSIT, - system_parachains_constants::kusama::currency::SYSTEM_PARA_EXISTENTIAL_DEPOSIT - ); - assert_eq!( - ::system_parachains_constants::kusama::currency::UNITS, - system_parachains_constants::kusama::currency::UNITS - ); - assert_eq!( - ::system_parachains_constants::kusama::currency::QUID, - system_parachains_constants::kusama::currency::QUID - ); - assert_eq!( - ::system_parachains_constants::kusama::currency::CENTS, - system_parachains_constants::kusama::currency::CENTS - ); - assert_eq!( - ::system_parachains_constants::kusama::currency::MILLICENTS, - system_parachains_constants::kusama::currency::MILLICENTS - ); - assert_eq!( - ::system_parachains_constants::kusama::currency::system_para_deposit(5, 3), - system_parachains_constants::kusama::currency::system_para_deposit(5, 3) - ); - assert_eq!( - ::system_parachains_constants::kusama::fee::TRANSACTION_BYTE_FEE, - system_parachains_constants::kusama::fee::TRANSACTION_BYTE_FEE - ); - assert_eq!( - ::system_parachains_constants::kusama::fee::calculate_weight_to_fee( - &::system_parachains_constants::MAXIMUM_BLOCK_WEIGHT - ), - system_parachains_constants::kusama::fee::calculate_weight_to_fee( - &system_parachains_constants::MAXIMUM_BLOCK_WEIGHT - ) - ); -} - #[test] fn test_transasction_byte_fee_is_one_tenth_of_relay() { let relay_tbf = ::kusama_runtime_constants::fee::TRANSACTION_BYTE_FEE; let parachain_tbf = TransactionByteFee::get(); assert_eq!(relay_tbf / 10, parachain_tbf); } - -// The Encointer pallets do not have compatible versions with `polkadot-sdk`, making it difficult -// for us to reuse the `system-parachains-constants` module. Therefore, we have copies of it here -// with `test_constants_compatiblity`. -mod system_parachains_constants { - use super::*; - use frame_support::weights::constants::WEIGHT_REF_TIME_PER_SECOND; - - /// This determines the average expected block time that we are targeting. Blocks will be - /// produced at a minimum duration defined by `SLOT_DURATION`. `SLOT_DURATION` is picked up by - /// `pallet_timestamp` which is in turn picked up by `pallet_aura` to implement `fn - /// slot_duration()`. - /// - /// Change this to adjust the block time. - pub const MILLISECS_PER_BLOCK: u64 = 12000; - pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; - - // Time is measured by number of blocks. - pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); - pub const HOURS: BlockNumber = MINUTES * 60; - pub const DAYS: BlockNumber = HOURS * 24; - - /// We assume that ~5% of the block weight is consumed by `on_initialize` handlers. This is - /// used to limit the maximal weight of a single extrinsic. - pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5); - /// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used by - /// Operational extrinsics. - pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); - - /// We allow for 0.5 seconds of compute with a 6 second average block time. - pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts( - WEIGHT_REF_TIME_PER_SECOND.saturating_div(2), - polkadot_primitives::MAX_POV_SIZE as u64, - ); - - pub(crate) mod kusama { - /// Consensus-related. - pub mod consensus { - /// Maximum number of blocks simultaneously accepted by the Runtime, not yet included - /// into the relay chain. - pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = 1; - /// How many parachain blocks are processed by the relay chain per parent. Limits the - /// number of blocks authored per slot. - pub const BLOCK_PROCESSING_VELOCITY: u32 = 1; - /// Relay chain slot duration, in milliseconds. - pub const RELAY_CHAIN_SLOT_DURATION_MILLIS: u32 = 6000; - } - - /// Constants relating to KSM. - pub mod currency { - use super::super::kusama_runtime_constants; - use polkadot_core_primitives::Balance; - - /// The default existential deposit for system chains. 1/10th of the Relay Chain's - /// existential deposit. Individual system parachains may modify this in special cases. - pub const SYSTEM_PARA_EXISTENTIAL_DEPOSIT: Balance = - kusama_runtime_constants::currency::EXISTENTIAL_DEPOSIT / 10; - - /// One "KSM" that a UI would show a user. - pub const UNITS: Balance = 1_000_000_000_000; - pub const QUID: Balance = UNITS / 30; - pub const CENTS: Balance = QUID / 100; - pub const MILLICENTS: Balance = CENTS / 1_000; - - /// Deposit rate for stored data. 1/100th of the Relay Chain's deposit rate. `items` is - /// the number of keys in storage and `bytes` is the size of the value. - pub const fn system_para_deposit(items: u32, bytes: u32) -> Balance { - kusama_runtime_constants::currency::deposit(items, bytes) / 100 - } - } - - /// Constants related to Kusama fee payment. - pub mod fee { - use frame_support::{ - pallet_prelude::Weight, - weights::{ - constants::ExtrinsicBaseWeight, FeePolynomial, WeightToFeeCoefficient, - WeightToFeeCoefficients, WeightToFeePolynomial, - }, - }; - use polkadot_core_primitives::Balance; - use smallvec::smallvec; - pub use sp_runtime::Perbill; - - /// Cost of every transaction byte at Kusama system parachains. - /// - /// It is the Relay Chain (Kusama) `TransactionByteFee` / 10. - pub const TRANSACTION_BYTE_FEE: Balance = super::currency::MILLICENTS; - - /// Handles converting a weight scalar to a fee value, based on the scale and - /// granularity of the node's balance type. - /// - /// This should typically create a mapping between the following ranges: - /// - [0, MAXIMUM_BLOCK_WEIGHT] - /// - [Balance::min, Balance::max] - /// - /// Yet, it can be used for any other sort of change to weight-fee. Some examples being: - /// - Setting it to `0` will essentially disable the weight fee. - /// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged. - pub struct WeightToFee; - - impl frame_support::weights::WeightToFee for WeightToFee { - type Balance = Balance; - - fn weight_to_fee(weight: &Weight) -> Self::Balance { - let time_poly: FeePolynomial = RefTimeToFee::polynomial().into(); - let proof_poly: FeePolynomial = ProofSizeToFee::polynomial().into(); - - // Take the maximum instead of the sum to charge by the more scarce resource. - time_poly.eval(weight.ref_time()).max(proof_poly.eval(weight.proof_size())) - } - } - - /// Maps the reference time component of `Weight` to a fee. - pub struct RefTimeToFee; - - impl WeightToFeePolynomial for RefTimeToFee { - type Balance = Balance; - fn polynomial() -> WeightToFeeCoefficients { - // In Kusama, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 - // CENT: The standard system parachain configuration is 1/10 of that, as in - // 1/100 CENT. - let p = super::currency::CENTS; - let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time()); - - smallvec![WeightToFeeCoefficient { - degree: 1, - negative: false, - coeff_frac: Perbill::from_rational(p % q, q), - coeff_integer: p / q, - }] - } - } - - /// Maps the proof size component of `Weight` to a fee. - pub struct ProofSizeToFee; - - impl WeightToFeePolynomial for ProofSizeToFee { - type Balance = Balance; - fn polynomial() -> WeightToFeeCoefficients { - // Map 10kb proof to 1 CENT. - let p = super::currency::CENTS; - let q = 10_000; - - smallvec![WeightToFeeCoefficient { - degree: 1, - negative: false, - coeff_frac: Perbill::from_rational(p % q, q), - coeff_integer: p / q, - }] - } - } - - #[cfg(test)] - pub fn calculate_weight_to_fee(weight: &Weight) -> Balance { - ::weight_to_fee(weight) - } - } - } - - pub(crate) mod kusama_runtime_constants { - /// Money matters. - pub mod currency { - use polkadot_primitives::Balance; - - /// The existential deposit. - pub const EXISTENTIAL_DEPOSIT: Balance = CENTS; - - pub const UNITS: Balance = 1_000_000_000_000; - pub const QUID: Balance = UNITS / 30; - pub const CENTS: Balance = QUID / 100; - pub const MILLICENTS: Balance = CENTS / 1_000; - - pub const fn deposit(items: u32, bytes: u32) -> Balance { - items as Balance * 2_000 * CENTS + (bytes as Balance) * 100 * MILLICENTS - } - } - } -} From 7b12737da52147ad0e95b6a997d777feb666fe84 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 17 Jul 2024 21:39:59 +0200 Subject: [PATCH 11/23] Set `get_preset` for GluttonKusama --- .../src/system_parachains_specs.rs | 20 ++------ .../encointer/src/genesis_config_presets.rs | 2 +- .../gluttons/glutton-kusama/Cargo.toml | 2 + .../src/genesis_config_presets.rs | 51 +++++++++++++++++++ .../gluttons/glutton-kusama/src/lib.rs | 9 +++- 5 files changed, 66 insertions(+), 18 deletions(-) create mode 100644 system-parachains/gluttons/glutton-kusama/src/genesis_config_presets.rs diff --git a/chain-spec-generator/src/system_parachains_specs.rs b/chain-spec-generator/src/system_parachains_specs.rs index 646f86e544..2b623fce96 100644 --- a/chain-spec-generator/src/system_parachains_specs.rs +++ b/chain-spec-generator/src/system_parachains_specs.rs @@ -161,20 +161,6 @@ pub fn bridge_hub_kusama_local_testnet_config() -> Result, St )) } -// GluttonKusama -fn glutton_kusama_genesis(id: ParaId) -> serde_json::Value { - serde_json::json!({ - "parachainInfo": glutton_kusama_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() - }, - }) -} - -fn glutton_kusama_local_genesis(id: ParaId) -> serde_json::Value { - glutton_kusama_genesis(id) -} - pub fn glutton_kusama_local_testnet_config() -> Result, String> { let mut properties = sc_chain_spec::Properties::new(); properties.insert("ss58Format".into(), 2.into()); @@ -187,7 +173,11 @@ pub fn glutton_kusama_local_testnet_config() -> Result, Strin .with_name("Kusama Glutton Local") .with_id("glutton-kusama-local") .with_chain_type(ChainType::Local) - .with_genesis_config_patch(glutton_kusama_local_genesis(1300.into())) + .with_genesis_config_patch( + glutton_kusama_runtime::genesis_config_presets::glutton_kusama_local_testnet_genesis( + 1300.into(), + ), + ) .with_properties(properties) .build(), )) diff --git a/system-parachains/encointer/src/genesis_config_presets.rs b/system-parachains/encointer/src/genesis_config_presets.rs index 19d4dcce3d..a73c8248b3 100644 --- a/system-parachains/encointer/src/genesis_config_presets.rs +++ b/system-parachains/encointer/src/genesis_config_presets.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -//! Genesis configs presets for the EincointerKusama runtime +//! Genesis configs presets for the EncointerKusama runtime use crate::*; use sp_std::vec::Vec; diff --git a/system-parachains/gluttons/glutton-kusama/Cargo.toml b/system-parachains/gluttons/glutton-kusama/Cargo.toml index 9886cf18e6..d3aa109541 100644 --- a/system-parachains/gluttons/glutton-kusama/Cargo.toml +++ b/system-parachains/gluttons/glutton-kusama/Cargo.toml @@ -11,6 +11,7 @@ version.workspace = true [dependencies] codec = { features = ["derive"], workspace = true } scale-info = { features = ["derive"], workspace = true } +serde_json = { features = ["alloc"], workspace = true } # Substrate frame-benchmarking = { optional = true, workspace = true } @@ -87,6 +88,7 @@ std = [ "parachain-info/std", "parachains-common/std", "scale-info/std", + "serde_json/std", "sp-api/std", "sp-block-builder/std", "sp-core/std", diff --git a/system-parachains/gluttons/glutton-kusama/src/genesis_config_presets.rs b/system-parachains/gluttons/glutton-kusama/src/genesis_config_presets.rs new file mode 100644 index 0000000000..aa6b3f67ba --- /dev/null +++ b/system-parachains/gluttons/glutton-kusama/src/genesis_config_presets.rs @@ -0,0 +1,51 @@ +// 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 GluttonKusama runtime + +use crate::*; +use cumulus_primitives_core::ParaId; + +fn glutton_kusama_genesis(id: ParaId) -> serde_json::Value { + serde_json::json!({ + "parachainInfo": ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + }) +} + +pub fn glutton_kusama_local_testnet_genesis(para_id: ParaId) -> serde_json::Value { + glutton_kusama_genesis(para_id) +} + +fn glutton_kusama_development_genesis(para_id: ParaId) -> serde_json::Value { + glutton_kusama_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") => glutton_kusama_development_genesis(1300.into()), + Ok("local_testnet") => glutton_kusama_local_testnet_genesis(1300.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/gluttons/glutton-kusama/src/lib.rs b/system-parachains/gluttons/glutton-kusama/src/lib.rs index 591157b7bb..6b61f2053f 100644 --- a/system-parachains/gluttons/glutton-kusama/src/lib.rs +++ b/system-parachains/gluttons/glutton-kusama/src/lib.rs @@ -43,6 +43,8 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); +// Genesis preset configurations. +pub mod genesis_config_presets; pub mod weights; pub mod xcm_config; @@ -393,11 +395,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"), + ] } } From 5c0b9b0c7eb30f3f9ec6491e27db75e98b3d72e5 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 17 Jul 2024 22:08:40 +0200 Subject: [PATCH 12/23] Set `get_preset` for People* --- .../src/system_parachains_specs.rs | 122 ++---------------- .../src/genesis_config_presets.rs | 2 +- .../src/genesis_config_presets.rs | 2 +- .../src/genesis_config_presets.rs | 2 +- .../src/genesis_config_presets.rs | 2 +- .../src/genesis_config_presets.rs | 2 +- .../src/genesis_config_presets.rs | 2 +- .../encointer/src/genesis_config_presets.rs | 2 +- .../people/people-kusama/Cargo.toml | 2 + .../src/genesis_config_presets.rs | 87 +++++++++++++ .../people/people-kusama/src/lib.rs | 9 +- .../people/people-polkadot/Cargo.toml | 2 + .../src/genesis_config_presets.rs | 87 +++++++++++++ .../people/people-polkadot/src/lib.rs | 9 +- 14 files changed, 209 insertions(+), 123 deletions(-) create mode 100644 system-parachains/people/people-kusama/src/genesis_config_presets.rs create mode 100644 system-parachains/people/people-polkadot/src/genesis_config_presets.rs diff --git a/chain-spec-generator/src/system_parachains_specs.rs b/chain-spec-generator/src/system_parachains_specs.rs index 2b623fce96..0505ef5b95 100644 --- a/chain-spec-generator/src/system_parachains_specs.rs +++ b/chain-spec-generator/src/system_parachains_specs.rs @@ -52,10 +52,6 @@ pub type PeopleKusamaChainSpec = sc_chain_spec::GenericChainSpec; pub type PeoplePolkadotChainSpec = sc_chain_spec::GenericChainSpec; -const PEOPLE_KUSAMA_ED: Balance = people_kusama_runtime::ExistentialDeposit::get(); - -const PEOPLE_POLKADOT_ED: Balance = people_polkadot_runtime::ExistentialDeposit::get(); - /// The default XCM version to set in genesis config. const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; @@ -227,58 +223,6 @@ pub fn coretime_kusama_local_testnet_config() -> Result, Stri )) } -// PeopleKusama -fn people_kusama_genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - id: ParaId, -) -> serde_json::Value { - serde_json::json!({ - "balances": people_kusama_runtime::BalancesConfig { - balances: endowed_accounts - .iter() - .cloned() - .map(|k| (k, PEOPLE_KUSAMA_ED * 4096 * 4096)) - .collect(), - }, - "parachainInfo": people_kusama_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() - }, - "collatorSelection": people_kusama_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: PEOPLE_KUSAMA_ED * 16, - ..Default::default() - }, - "session": people_kusama_runtime::SessionConfig { - keys: invulnerables - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - people_kusama_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 people_kusama_local_genesis(para_id: ParaId) -> serde_json::Value { - people_kusama_genesis( - // initial collators. - invulnerables(), - testnet_accounts(), - para_id, - ) -} - pub fn people_kusama_local_testnet_config() -> Result, String> { let mut properties = sc_chain_spec::Properties::new(); properties.insert("ss58Format".into(), 2.into()); @@ -293,64 +237,16 @@ pub fn people_kusama_local_testnet_config() -> Result, String .with_name("Kusama People Local") .with_id("people-kusama-local") .with_chain_type(ChainType::Local) - .with_genesis_config_patch(people_kusama_local_genesis(1004.into())) + .with_genesis_config_patch( + people_kusama_runtime::genesis_config_presets::people_kusama_local_testnet_genesis( + 1004.into(), + ), + ) .with_properties(properties) .build(), )) } -// PeoplePolkadot -fn people_polkadot_genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - id: ParaId, -) -> serde_json::Value { - serde_json::json!({ - "balances": people_polkadot_runtime::BalancesConfig { - balances: endowed_accounts - .iter() - .cloned() - .map(|k| (k, PEOPLE_POLKADOT_ED * 4096 * 4096)) - .collect(), - }, - "parachainInfo": people_polkadot_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() - }, - "collatorSelection": people_polkadot_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: PEOPLE_POLKADOT_ED * 16, - ..Default::default() - }, - "session": people_polkadot_runtime::SessionConfig { - keys: invulnerables - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - people_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 people_polkadot_local_genesis(para_id: ParaId) -> serde_json::Value { - crate::system_parachains_specs::people_polkadot_genesis( - // initial collators. - invulnerables(), - testnet_accounts(), - para_id, - ) -} - pub fn people_polkadot_local_testnet_config() -> Result, String> { let mut properties = sc_chain_spec::Properties::new(); properties.insert("ss58Format".into(), 0.into()); @@ -365,9 +261,11 @@ pub fn people_polkadot_local_testnet_config() -> Result, Stri .with_name("Polkadot People Local") .with_id("people-polkadot-local") .with_chain_type(ChainType::Local) - .with_genesis_config_patch(crate::system_parachains_specs::people_polkadot_local_genesis( - 1004.into(), - )) + .with_genesis_config_patch( + people_polkadot_runtime::genesis_config_presets::people_polkadot_local_testnet_genesis( + 1004.into(), + ), + ) .with_properties(properties) .build(), )) diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/genesis_config_presets.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/genesis_config_presets.rs index a5ca1c2c7f..09aef4c37d 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/genesis_config_presets.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/genesis_config_presets.rs @@ -20,7 +20,7 @@ use crate::*; use sp_std::vec::Vec; use system_parachains_constants::genesis_presets::*; -const ASSET_HUB_KUSAMA_ED: Balance = crate::ExistentialDeposit::get(); +const ASSET_HUB_KUSAMA_ED: Balance = ExistentialDeposit::get(); fn asset_hub_kusama_genesis( invulnerables: Vec<(AccountId, AuraId)>, diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/genesis_config_presets.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/genesis_config_presets.rs index 29cc27fb6b..2f87b6b3b8 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/genesis_config_presets.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/genesis_config_presets.rs @@ -22,7 +22,7 @@ use sp_core::sr25519; use sp_std::vec::Vec; use system_parachains_constants::genesis_presets::*; -const ASSET_HUB_POLKADOT_ED: Balance = crate::ExistentialDeposit::get(); +const ASSET_HUB_POLKADOT_ED: Balance = ExistentialDeposit::get(); /// Invulnerable Collators for the particular case of AssetHubPolkadot pub fn invulnerables_asset_hub_polkadot() -> Vec<(AccountId, AssetHubPolkadotAuraId)> { diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/src/genesis_config_presets.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/src/genesis_config_presets.rs index c8cf7b22ca..a57100ce0c 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/src/genesis_config_presets.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/src/genesis_config_presets.rs @@ -20,7 +20,7 @@ use crate::*; use sp_std::vec::Vec; use system_parachains_constants::genesis_presets::*; -const BRIDGE_HUB_KUSAMA_ED: Balance = crate::ExistentialDeposit::get(); +const BRIDGE_HUB_KUSAMA_ED: Balance = ExistentialDeposit::get(); fn bridge_hub_kusama_genesis( invulnerables: Vec<(AccountId, AuraId)>, diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/genesis_config_presets.rs b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/genesis_config_presets.rs index 9a1ed6657b..0d549d3c2e 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/src/genesis_config_presets.rs +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/src/genesis_config_presets.rs @@ -20,7 +20,7 @@ use crate::*; use sp_std::vec::Vec; use system_parachains_constants::genesis_presets::*; -const BRIDGE_HUB_POLKADOT_ED: Balance = crate::ExistentialDeposit::get(); +const BRIDGE_HUB_POLKADOT_ED: Balance = ExistentialDeposit::get(); fn bridge_hub_polkadot_genesis( invulnerables: Vec<(AccountId, AuraId)>, diff --git a/system-parachains/collectives/collectives-polkadot/src/genesis_config_presets.rs b/system-parachains/collectives/collectives-polkadot/src/genesis_config_presets.rs index 10f3973efa..8ad0b4dcdf 100644 --- a/system-parachains/collectives/collectives-polkadot/src/genesis_config_presets.rs +++ b/system-parachains/collectives/collectives-polkadot/src/genesis_config_presets.rs @@ -20,7 +20,7 @@ use crate::*; use sp_std::vec::Vec; use system_parachains_constants::genesis_presets::*; -const COLLECTIVES_POLKADOT_ED: Balance = crate::ExistentialDeposit::get(); +const COLLECTIVES_POLKADOT_ED: Balance = ExistentialDeposit::get(); fn collectives_polkadot_genesis( invulnerables: Vec<(AccountId, AuraId)>, diff --git a/system-parachains/coretime/coretime-kusama/src/genesis_config_presets.rs b/system-parachains/coretime/coretime-kusama/src/genesis_config_presets.rs index 6234d65baf..9b8c7ec0b2 100644 --- a/system-parachains/coretime/coretime-kusama/src/genesis_config_presets.rs +++ b/system-parachains/coretime/coretime-kusama/src/genesis_config_presets.rs @@ -20,7 +20,7 @@ use crate::*; use sp_std::vec::Vec; use system_parachains_constants::genesis_presets::*; -const CORETIME_KUSAMA_ED: Balance = crate::ExistentialDeposit::get(); +const CORETIME_KUSAMA_ED: Balance = ExistentialDeposit::get(); fn coretime_kusama_genesis( invulnerables: Vec<(AccountId, AuraId)>, diff --git a/system-parachains/encointer/src/genesis_config_presets.rs b/system-parachains/encointer/src/genesis_config_presets.rs index a73c8248b3..8261042b14 100644 --- a/system-parachains/encointer/src/genesis_config_presets.rs +++ b/system-parachains/encointer/src/genesis_config_presets.rs @@ -20,7 +20,7 @@ use crate::*; use sp_std::vec::Vec; use system_parachains_constants::genesis_presets::*; -const ENCOINTER_KUSAMA_ED: Balance = crate::ExistentialDeposit::get(); +const ENCOINTER_KUSAMA_ED: Balance = ExistentialDeposit::get(); fn encointer_kusama_genesis( invulnerables: Vec<(AccountId, AuraId)>, diff --git a/system-parachains/people/people-kusama/Cargo.toml b/system-parachains/people/people-kusama/Cargo.toml index 9ebd65ac38..465451505d 100644 --- a/system-parachains/people/people-kusama/Cargo.toml +++ b/system-parachains/people/people-kusama/Cargo.toml @@ -15,6 +15,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 } @@ -125,6 +126,7 @@ std = [ "polkadot-runtime-common/std", "scale-info/std", "serde", + "serde_json/std", "sp-api/std", "sp-block-builder/std", "sp-consensus-aura/std", diff --git a/system-parachains/people/people-kusama/src/genesis_config_presets.rs b/system-parachains/people/people-kusama/src/genesis_config_presets.rs new file mode 100644 index 0000000000..74aa13cf80 --- /dev/null +++ b/system-parachains/people/people-kusama/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 PeopleKusama runtime + +use crate::*; +use sp_std::vec::Vec; +use system_parachains_constants::genesis_presets::*; + +const PEOPLE_KUSAMA_ED: Balance = ExistentialDeposit::get(); + +fn people_kusama_genesis( + invulnerables: Vec<(AccountId, parachains_common::AuraId)>, + endowed_accounts: Vec, + id: ParaId, +) -> serde_json::Value { + serde_json::json!({ + "balances": BalancesConfig { + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, PEOPLE_KUSAMA_ED * 4096 * 4096)) + .collect(), + }, + "parachainInfo": ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + "collatorSelection": CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: PEOPLE_KUSAMA_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 people_kusama_local_testnet_genesis(para_id: ParaId) -> serde_json::Value { + people_kusama_genesis(invulnerables(), testnet_accounts(), para_id) +} + +fn people_kusama_development_genesis(para_id: ParaId) -> serde_json::Value { + people_kusama_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") => people_kusama_development_genesis(1004.into()), + Ok("local_testnet") => people_kusama_local_testnet_genesis(1004.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/people/people-kusama/src/lib.rs b/system-parachains/people/people-kusama/src/lib.rs index 5e82749ca7..eb99d3268c 100644 --- a/system-parachains/people/people-kusama/src/lib.rs +++ b/system-parachains/people/people-kusama/src/lib.rs @@ -18,6 +18,8 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); +// Genesis preset configurations. +pub mod genesis_config_presets; mod identity_ops; pub mod people; mod weights; @@ -1027,11 +1029,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"), + ] } } } diff --git a/system-parachains/people/people-polkadot/Cargo.toml b/system-parachains/people/people-polkadot/Cargo.toml index 5fbf1bc4d0..80c2ac98ee 100644 --- a/system-parachains/people/people-polkadot/Cargo.toml +++ b/system-parachains/people/people-polkadot/Cargo.toml @@ -15,6 +15,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 } @@ -122,6 +123,7 @@ std = [ "polkadot-runtime-common/std", "scale-info/std", "serde", + "serde_json/std", "sp-api/std", "sp-block-builder/std", "sp-consensus-aura/std", diff --git a/system-parachains/people/people-polkadot/src/genesis_config_presets.rs b/system-parachains/people/people-polkadot/src/genesis_config_presets.rs new file mode 100644 index 0000000000..6847d7ca73 --- /dev/null +++ b/system-parachains/people/people-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 PeoplePolkadot runtime + +use crate::*; +use sp_std::vec::Vec; +use system_parachains_constants::genesis_presets::*; + +const PEOPLE_POLKADOT_ED: Balance = ExistentialDeposit::get(); + +fn people_polkadot_genesis( + invulnerables: Vec<(AccountId, parachains_common::AuraId)>, + endowed_accounts: Vec, + id: ParaId, +) -> serde_json::Value { + serde_json::json!({ + "balances": BalancesConfig { + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, PEOPLE_POLKADOT_ED * 4096 * 4096)) + .collect(), + }, + "parachainInfo": ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + "collatorSelection": CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: PEOPLE_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 people_polkadot_local_testnet_genesis(para_id: ParaId) -> serde_json::Value { + people_polkadot_genesis(invulnerables(), testnet_accounts(), para_id) +} + +fn people_polkadot_development_genesis(para_id: ParaId) -> serde_json::Value { + people_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") => people_polkadot_development_genesis(1004.into()), + Ok("local_testnet") => people_polkadot_local_testnet_genesis(1004.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/people/people-polkadot/src/lib.rs b/system-parachains/people/people-polkadot/src/lib.rs index 001115df32..eb437f8d3e 100644 --- a/system-parachains/people/people-polkadot/src/lib.rs +++ b/system-parachains/people/people-polkadot/src/lib.rs @@ -18,6 +18,8 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); +// Genesis preset configurations. +pub mod genesis_config_presets; pub mod people; mod weights; pub mod xcm_config; @@ -979,11 +981,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"), + ] } } } From c00d688c38c18b48fc40ea3afbdbc878eb068ed5 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 17 Jul 2024 22:32:09 +0200 Subject: [PATCH 13/23] More chain-spec-generator clean up --- Cargo.lock | 9 +++- chain-spec-generator/Cargo.toml | 4 -- chain-spec-generator/src/common.rs | 42 +++---------------- .../src/system_parachains_specs.rs | 4 -- 4 files changed, 12 insertions(+), 47 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a9d7b7ffc5..b81bebe34c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -641,6 +641,7 @@ dependencies = [ "polkadot-runtime-constants", "primitive-types", "scale-info", + "serde_json", "snowbridge-router-primitives", "sp-api", "sp-block-builder", @@ -772,6 +773,7 @@ dependencies = [ "polkadot-runtime-constants", "primitive-types", "scale-info", + "serde_json", "snowbridge-router-primitives", "sp-api", "sp-block-builder", @@ -2178,12 +2180,10 @@ dependencies = [ "clap", "collectives-polkadot-runtime", "coretime-kusama-runtime", - "cumulus-primitives-core", "encointer-kusama-runtime", "glutton-kusama-runtime", "kusama-runtime-constants", "pallet-staking", - "parachains-common", "people-kusama-runtime", "people-polkadot-runtime", "polkadot-primitives", @@ -2620,6 +2620,7 @@ dependencies = [ "polkadot-runtime-common", "scale-info", "serde", + "serde_json", "sp-api", "sp-block-builder", "sp-consensus-aura", @@ -3810,6 +3811,7 @@ dependencies = [ "polkadot-primitives", "polkadot-runtime-common", "scale-info", + "serde_json", "smallvec", "sp-api", "sp-block-builder", @@ -4773,6 +4775,7 @@ dependencies = [ "parachains-common", "parity-scale-codec", "scale-info", + "serde_json", "sp-api", "sp-block-builder", "sp-core 34.0.0", @@ -9348,6 +9351,7 @@ dependencies = [ "polkadot-runtime-common", "scale-info", "serde", + "serde_json", "sp-api", "sp-block-builder", "sp-consensus-aura", @@ -9451,6 +9455,7 @@ dependencies = [ "polkadot-runtime-constants", "scale-info", "serde", + "serde_json", "sp-api", "sp-block-builder", "sp-consensus-aura", diff --git a/chain-spec-generator/Cargo.toml b/chain-spec-generator/Cargo.toml index 7a97e371a7..bf3d176d38 100644 --- a/chain-spec-generator/Cargo.toml +++ b/chain-spec-generator/Cargo.toml @@ -27,8 +27,6 @@ grandpa = { workspace = true } sp-runtime = { workspace = true, default-features = true } beefy-primitives = { workspace = true, default-features = true } xcm = { workspace = true, default-features = true } -parachains-common = { workspace = true, default-features = true } -cumulus-primitives-core = { workspace = true, default-features = true } asset-hub-polkadot-runtime = { workspace = true } asset-hub-kusama-runtime = { workspace = true } @@ -50,12 +48,10 @@ runtime-benchmarks = [ "bridge-hub-polkadot-runtime/runtime-benchmarks", "collectives-polkadot-runtime/runtime-benchmarks", "coretime-kusama-runtime/runtime-benchmarks", - "cumulus-primitives-core/runtime-benchmarks", "encointer-kusama-runtime/runtime-benchmarks", "glutton-kusama-runtime/runtime-benchmarks", "kusama-runtime/runtime-benchmarks", "pallet-staking/runtime-benchmarks", - "parachains-common/runtime-benchmarks", "people-kusama-runtime/runtime-benchmarks", "people-polkadot-runtime/runtime-benchmarks", "polkadot-primitives/runtime-benchmarks", diff --git a/chain-spec-generator/src/common.rs b/chain-spec-generator/src/common.rs index 24162a4600..79f68a8ab5 100644 --- a/chain-spec-generator/src/common.rs +++ b/chain-spec-generator/src/common.rs @@ -19,46 +19,12 @@ use crate::{ relay_chain_specs::{KusamaChainSpec, PolkadotChainSpec}, system_parachains_specs::{ AssetHubKusamaChainSpec, AssetHubPolkadotChainSpec, BridgeHubKusamaChainSpec, - BridgeHubPolkadotChainSpec, CollectivesPolkadotChainSpec, EncointerKusamaChainSpec, - GluttonKusamaChainSpec, PeopleKusamaChainSpec, PeoplePolkadotChainSpec, + BridgeHubPolkadotChainSpec, CollectivesPolkadotChainSpec, CoretimeKusamaChainSpec, + EncointerKusamaChainSpec, GluttonKusamaChainSpec, PeopleKusamaChainSpec, + PeoplePolkadotChainSpec, }, ChainSpec, }; -use polkadot_primitives::{AccountId, AccountPublic}; -use sp_core::{sr25519, Pair, Public}; -use sp_runtime::traits::IdentifyAccount; - -pub fn testnet_accounts() -> Vec { - 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"), - ] -} - -/// 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() -} - -/// 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() -} #[derive(Debug, serde::Deserialize)] struct EmptyChainSpecWithId { @@ -86,6 +52,8 @@ pub fn from_json_file(filepath: &str, supported: String) -> Result Ok(Box::new(BridgeHubKusamaChainSpec::from_json_file(path)?)), + x if x.starts_with("coretime-kusama") => + Ok(Box::new(CoretimeKusamaChainSpec::from_json_file(path)?)), x if x.starts_with("glutton-kusama") => Ok(Box::new(GluttonKusamaChainSpec::from_json_file(path)?)), x if x.starts_with("encointer-kusama") => diff --git a/chain-spec-generator/src/system_parachains_specs.rs b/chain-spec-generator/src/system_parachains_specs.rs index 0505ef5b95..c62bdee763 100644 --- a/chain-spec-generator/src/system_parachains_specs.rs +++ b/chain-spec-generator/src/system_parachains_specs.rs @@ -15,12 +15,8 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -use crate::common::{get_account_id_from_seed, get_from_seed, testnet_accounts}; -use cumulus_primitives_core::ParaId; -use parachains_common::{AccountId, AuraId, Balance}; use sc_chain_spec::{ChainSpec, ChainSpecExtension, ChainSpecGroup, ChainType}; use serde::{Deserialize, Serialize}; -use sp_core::sr25519; /// Generic extensions for Parachain ChainSpecs. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)] From 7a8fb153b2ae01393e36b20b86acc6505d263c65 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 17 Jul 2024 22:51:12 +0200 Subject: [PATCH 14/23] Nits --- relay/kusama/Cargo.toml | 3 ++- relay/polkadot/Cargo.toml | 3 ++- system-parachains/encointer/src/genesis_config_presets.rs | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/relay/kusama/Cargo.toml b/relay/kusama/Cargo.toml index b2df38038f..992abb0203 100644 --- a/relay/kusama/Cargo.toml +++ b/relay/kusama/Cargo.toml @@ -11,6 +11,7 @@ version.workspace = true [dependencies] codec = { features = ["derive", "max-encoded-len"], workspace = true } scale-info = { features = ["derive"], workspace = true } +serde_json = { features = ["alloc"], workspace = true } log = { workspace = true } authority-discovery-primitives = { workspace = true } @@ -107,7 +108,6 @@ sp-debug-derive = { workspace = true } sp-keyring = { workspace = true } sp-trie = { workspace = true } separator = { workspace = true } -serde_json = { workspace = true } remote-externalities = { workspace = true } tokio = { features = ["macros"], workspace = true } sp-tracing = { workspace = true } @@ -185,6 +185,7 @@ std = [ "polkadot-runtime-common/std", "runtime-parachains/std", "scale-info/std", + "serde_json/std", "substrate-wasm-builder", "sp-api/std", "sp-application-crypto/std", diff --git a/relay/polkadot/Cargo.toml b/relay/polkadot/Cargo.toml index c7f8c92b6b..274de022a6 100644 --- a/relay/polkadot/Cargo.toml +++ b/relay/polkadot/Cargo.toml @@ -10,6 +10,7 @@ license.workspace = true [dependencies] codec = { features = ["derive", "max-encoded-len"], workspace = true } scale-info = { features = ["derive"], workspace = true } +serde_json = { features = ["alloc"], workspace = true } log = { workspace = true } authority-discovery-primitives = { workspace = true } @@ -104,7 +105,6 @@ sp-debug-derive = { workspace = true } [dev-dependencies] sp-keyring = { workspace = true } sp-trie = { workspace = true } -serde_json = { workspace = true } separator = { workspace = true } remote-externalities = { workspace = true } tokio = { features = ["macros"], workspace = true } @@ -182,6 +182,7 @@ std = [ "polkadot-runtime-constants/std", "runtime-parachains/std", "scale-info/std", + "serde_json/std", "substrate-wasm-builder", "sp-api/std", "sp-application-crypto/std", diff --git a/system-parachains/encointer/src/genesis_config_presets.rs b/system-parachains/encointer/src/genesis_config_presets.rs index 8261042b14..906c77e505 100644 --- a/system-parachains/encointer/src/genesis_config_presets.rs +++ b/system-parachains/encointer/src/genesis_config_presets.rs @@ -36,7 +36,7 @@ fn encointer_kusama_genesis( .collect(), }, "parachainInfo": ParachainInfoConfig { - parachain_id: id.into(), + parachain_id: id, ..Default::default() }, "collatorSelection": CollatorSelectionConfig { From c6997c3204f9dcb79a1cbde4e7503cb6105f11a3 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 17 Jul 2024 22:58:02 +0200 Subject: [PATCH 15/23] Clippy --- chain-spec-generator/src/system_parachains_specs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chain-spec-generator/src/system_parachains_specs.rs b/chain-spec-generator/src/system_parachains_specs.rs index c62bdee763..4a6d3b9966 100644 --- a/chain-spec-generator/src/system_parachains_specs.rs +++ b/chain-spec-generator/src/system_parachains_specs.rs @@ -189,7 +189,7 @@ pub fn encointer_kusama_local_testnet_config() -> Result, Str .with_name("Kusama Encointer Local") .with_id("encointer-kusama-local") .with_chain_type(ChainType::Local) - .with_genesis_config_patch(encointer_kusama_runtime::genesis_config_presets::encointer_kusama_local_testnet_genesis(1001)) + .with_genesis_config_patch(encointer_kusama_runtime::genesis_config_presets::encointer_kusama_local_testnet_genesis(1001.into())) .with_properties(properties) .build(), )) From 21e98957605ae04363b3fbf273aa516b57c99995 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 17 Jul 2024 23:31:21 +0200 Subject: [PATCH 16/23] More chain-spec-generator clean up --- Cargo.lock | 1 - chain-spec-generator/Cargo.toml | 1 - chain-spec-generator/src/system_parachains_specs.rs | 3 --- 3 files changed, 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b81bebe34c..61a51152e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2200,7 +2200,6 @@ dependencies = [ "sp-core 34.0.0", "sp-runtime 38.0.0", "staging-kusama-runtime", - "staging-xcm", ] [[package]] diff --git a/chain-spec-generator/Cargo.toml b/chain-spec-generator/Cargo.toml index bf3d176d38..26bc137f98 100644 --- a/chain-spec-generator/Cargo.toml +++ b/chain-spec-generator/Cargo.toml @@ -26,7 +26,6 @@ pallet-staking = { workspace = true, default-features = true } grandpa = { workspace = true } sp-runtime = { workspace = true, default-features = true } beefy-primitives = { workspace = true, default-features = true } -xcm = { workspace = true, default-features = true } asset-hub-polkadot-runtime = { workspace = true } asset-hub-kusama-runtime = { workspace = true } diff --git a/chain-spec-generator/src/system_parachains_specs.rs b/chain-spec-generator/src/system_parachains_specs.rs index 4a6d3b9966..2e85943521 100644 --- a/chain-spec-generator/src/system_parachains_specs.rs +++ b/chain-spec-generator/src/system_parachains_specs.rs @@ -48,9 +48,6 @@ pub type PeopleKusamaChainSpec = sc_chain_spec::GenericChainSpec; pub type PeoplePolkadotChainSpec = sc_chain_spec::GenericChainSpec; -/// The default XCM version to set in genesis config. -const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; - pub fn asset_hub_polkadot_local_testnet_config() -> Result, String> { let mut properties = sc_chain_spec::Properties::new(); properties.insert("ss58Format".into(), 0.into()); From df53a950d6ddb8f10347b87f16b12fdf32e2a236 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Thu, 18 Jul 2024 00:33:29 +0200 Subject: [PATCH 17/23] Set `get_preset` for Kusama/Polkadot + chain-spec-generator clean up + taplo --- Cargo.lock | 11 - chain-spec-generator/Cargo.toml | 16 - chain-spec-generator/src/relay_chain_specs.rs | 347 +----------------- relay/kusama/Cargo.toml | 2 +- relay/kusama/src/genesis_config_presets.rs | 256 +++++++++++++ relay/kusama/src/lib.rs | 12 +- relay/polkadot/Cargo.toml | 2 +- relay/polkadot/src/genesis_config_presets.rs | 256 +++++++++++++ relay/polkadot/src/lib.rs | 12 +- .../bridge-hubs/bridge-hub-kusama/Cargo.toml | 4 +- .../bridge-hub-polkadot/Cargo.toml | 4 +- .../bridge-hub-polkadot/primitives/Cargo.toml | 2 +- .../coretime/coretime-kusama/Cargo.toml | 2 +- .../people/people-kusama/Cargo.toml | 6 +- .../people/people-polkadot/Cargo.toml | 2 +- 15 files changed, 551 insertions(+), 383 deletions(-) create mode 100644 relay/kusama/src/genesis_config_presets.rs create mode 100644 relay/polkadot/src/genesis_config_presets.rs diff --git a/Cargo.lock b/Cargo.lock index 61a51152e6..e9c6bb7c65 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2182,23 +2182,12 @@ dependencies = [ "coretime-kusama-runtime", "encointer-kusama-runtime", "glutton-kusama-runtime", - "kusama-runtime-constants", - "pallet-staking", "people-kusama-runtime", "people-polkadot-runtime", - "polkadot-primitives", "polkadot-runtime", - "polkadot-runtime-constants", - "polkadot-runtime-parachains", "sc-chain-spec", - "sc-consensus-grandpa", "serde", "serde_json", - "sp-authority-discovery", - "sp-consensus-babe", - "sp-consensus-beefy", - "sp-core 34.0.0", - "sp-runtime 38.0.0", "staging-kusama-runtime", ] diff --git a/chain-spec-generator/Cargo.toml b/chain-spec-generator/Cargo.toml index 26bc137f98..58415043dd 100644 --- a/chain-spec-generator/Cargo.toml +++ b/chain-spec-generator/Cargo.toml @@ -12,20 +12,9 @@ serde_json = { workspace = true } serde = { features = ["derive"], workspace = true } polkadot-runtime = { workspace = true } -polkadot-runtime-constants = { workspace = true, default-features = true } kusama-runtime = { workspace = true } -kusama-runtime-constants = { workspace = true, default-features = true } sc-chain-spec = { workspace = true } -runtime-parachains = { default-features = true, workspace = true } -polkadot-primitives = { workspace = true, default-features = true } -babe-primitives = { workspace = true, default-features = true } -authority-discovery-primitives = { workspace = true, default-features = true } -sp-core = { workspace = true, default-features = true } -pallet-staking = { workspace = true, default-features = true } -grandpa = { workspace = true } -sp-runtime = { workspace = true, default-features = true } -beefy-primitives = { workspace = true, default-features = true } asset-hub-polkadot-runtime = { workspace = true } asset-hub-kusama-runtime = { workspace = true } @@ -50,12 +39,7 @@ runtime-benchmarks = [ "encointer-kusama-runtime/runtime-benchmarks", "glutton-kusama-runtime/runtime-benchmarks", "kusama-runtime/runtime-benchmarks", - "pallet-staking/runtime-benchmarks", "people-kusama-runtime/runtime-benchmarks", "people-polkadot-runtime/runtime-benchmarks", - "polkadot-primitives/runtime-benchmarks", "polkadot-runtime/runtime-benchmarks", - "runtime-parachains/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", - "encointer-kusama-runtime/runtime-benchmarks" ] diff --git a/chain-spec-generator/src/relay_chain_specs.rs b/chain-spec-generator/src/relay_chain_specs.rs index fafc276d9d..d2c793b99b 100644 --- a/chain-spec-generator/src/relay_chain_specs.rs +++ b/chain-spec-generator/src/relay_chain_specs.rs @@ -15,21 +15,7 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; -use babe_primitives::AuthorityId as BabeId; -use beefy_primitives::ecdsa_crypto::AuthorityId as BeefyId; -use grandpa::AuthorityId as GrandpaId; -use kusama_runtime_constants::currency::UNITS as KSM; -use pallet_staking::Forcing; -use polkadot_primitives::{ - AccountId, AccountPublic, ApprovalVotingParams, AssignmentId, AsyncBackingParams, NodeFeatures, - ValidatorId, -}; -use polkadot_runtime_constants::currency::UNITS as DOT; -use runtime_parachains::configuration::HostConfiguration; use sc_chain_spec::{ChainSpec, ChainType, NoExtension}; -use sp_core::{sr25519, Pair, Public}; -use sp_runtime::{traits::IdentifyAccount, Perbill}; pub type PolkadotChainSpec = sc_chain_spec::GenericChainSpec; @@ -47,297 +33,6 @@ pub fn polkadot_chain_spec_properties() -> serde_json::map::Map HostConfiguration { - use polkadot_primitives::{MAX_CODE_SIZE, MAX_POV_SIZE}; - - runtime_parachains::configuration::HostConfiguration { - validation_upgrade_cooldown: 2u32, - validation_upgrade_delay: 2, - code_retention_period: 1200, - max_code_size: MAX_CODE_SIZE, - max_pov_size: MAX_POV_SIZE, - max_head_data_size: 32 * 1024, - max_upward_queue_count: 8, - max_upward_queue_size: 1024 * 1024, - max_downward_message_size: 1024 * 1024, - max_upward_message_size: 50 * 1024, - max_upward_message_num_per_candidate: 5, - hrmp_sender_deposit: 0, - hrmp_recipient_deposit: 0, - hrmp_channel_max_capacity: 8, - hrmp_channel_max_total_size: 8 * 1024, - hrmp_max_parachain_inbound_channels: 4, - hrmp_channel_max_message_size: 1024 * 1024, - hrmp_max_parachain_outbound_channels: 4, - hrmp_max_message_num_per_candidate: 5, - dispute_period: 6, - no_show_slots: 2, - n_delay_tranches: 25, - needed_approvals: 2, - relay_vrf_modulo_samples: 2, - zeroth_delay_tranche_width: 0, - minimum_validation_upgrade_delay: 5, - scheduler_params: polkadot_primitives::vstaging::SchedulerParams { - group_rotation_frequency: 20, - paras_availability_period: 4, - ..Default::default() - }, - dispute_post_conclusion_acceptance_period: 100u32, - minimum_backing_votes: 1, - node_features: NodeFeatures::EMPTY, - async_backing_params: AsyncBackingParams { - max_candidate_depth: 2, - allowed_ancestry_len: 2, - }, - executor_params: Default::default(), - max_validators: None, - pvf_voting_ttl: 2, - approval_voting_params: ApprovalVotingParams { max_approval_coalesce_count: 1 }, - } -} - -fn polkadot_session_keys( - babe: BabeId, - grandpa: GrandpaId, - para_validator: ValidatorId, - para_assignment: AssignmentId, - authority_discovery: AuthorityDiscoveryId, - beefy: BeefyId, -) -> polkadot_runtime::SessionKeys { - polkadot_runtime::SessionKeys { - babe, - grandpa, - para_validator, - para_assignment, - authority_discovery, - beefy, - } -} - -fn kusama_session_keys( - babe: BabeId, - grandpa: GrandpaId, - para_validator: ValidatorId, - para_assignment: AssignmentId, - authority_discovery: AuthorityDiscoveryId, - beefy: BeefyId, -) -> kusama_runtime::SessionKeys { - kusama_runtime::SessionKeys { - babe, - grandpa, - para_validator, - para_assignment, - authority_discovery, - beefy, - } -} - -/// 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() -} - -/// 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() -} - -/// Helper function to generate stash, controller and session key from seed -pub fn get_authority_keys_from_seed( - seed: &str, -) -> ( - AccountId, - AccountId, - BabeId, - GrandpaId, - ValidatorId, - AssignmentId, - AuthorityDiscoveryId, - BeefyId, -) { - let keys = get_authority_keys_from_seed_no_beefy(seed); - (keys.0, keys.1, keys.2, keys.3, keys.4, keys.5, keys.6, get_from_seed::(seed)) -} - -/// Helper function to generate stash, controller and session key from seed -pub fn get_authority_keys_from_seed_no_beefy( - seed: &str, -) -> (AccountId, AccountId, BabeId, GrandpaId, ValidatorId, AssignmentId, AuthorityDiscoveryId) { - ( - get_account_id_from_seed::(&format!("{}//stash", seed)), - get_account_id_from_seed::(seed), - get_from_seed::(seed), - get_from_seed::(seed), - get_from_seed::(seed), - get_from_seed::(seed), - get_from_seed::(seed), - ) -} - -fn testnet_accounts() -> Vec { - 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"), - ] -} - -#[allow(clippy::type_complexity)] -pub fn polkadot_testnet_genesis( - initial_authorities: Vec<( - AccountId, - AccountId, - BabeId, - GrandpaId, - ValidatorId, - AssignmentId, - AuthorityDiscoveryId, - BeefyId, - )>, - _root_key: AccountId, - endowed_accounts: Option>, -) -> serde_json::Value { - let endowed_accounts: Vec = endowed_accounts.unwrap_or_else(testnet_accounts); - - const ENDOWMENT: u128 = 1_000_000 * DOT; - const STASH: u128 = 100 * DOT; - - serde_json::json!({ - "balances": { - "balances": endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect::>(), - }, - "session": { - "keys": initial_authorities - .iter() - .map(|x| { - ( - x.0.clone(), - x.0.clone(), - polkadot_session_keys( - x.2.clone(), - x.3.clone(), - x.4.clone(), - x.5.clone(), - x.6.clone(), - x.7.clone(), - ), - ) - }) - .collect::>(), - }, - "staking": { - "minimumValidatorCount": 1, - "validatorCount": initial_authorities.len() as u32, - "stakers": initial_authorities - .iter() - .map(|x| (x.0.clone(), x.0.clone(), STASH, polkadot_runtime::StakerStatus::::Validator)) - .collect::>(), - "invulnerables": initial_authorities.iter().map(|x| x.0.clone()).collect::>(), - "forceEra": Forcing::NotForcing, - "slashRewardFraction": Perbill::from_percent(10), - }, - "babe": { - "epochConfig": Some(polkadot_runtime::BABE_GENESIS_EPOCH_CONFIG), - }, - "configuration": { - "config": default_parachains_host_configuration(), - }, - }) -} - -#[allow(clippy::type_complexity)] -pub fn kusama_testnet_genesis( - initial_authorities: Vec<( - AccountId, - AccountId, - BabeId, - GrandpaId, - ValidatorId, - AssignmentId, - AuthorityDiscoveryId, - BeefyId, - )>, - _root_key: AccountId, - endowed_accounts: Option>, -) -> serde_json::Value { - let endowed_accounts: Vec = endowed_accounts.unwrap_or_else(testnet_accounts); - - const ENDOWMENT: u128 = 1_000_000 * KSM; - const STASH: u128 = 100 * KSM; - - serde_json::json!({ - "balances": { - "balances": endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect::>(), - }, - "session": { - "keys": initial_authorities - .iter() - .map(|x| { - ( - x.0.clone(), - x.0.clone(), - kusama_session_keys( - x.2.clone(), - x.3.clone(), - x.4.clone(), - x.5.clone(), - x.6.clone(), - x.7.clone(), - ), - ) - }) - .collect::>(), - }, - "staking": { - "minimumValidatorCount": 1, - "validatorCount": initial_authorities.len() as u32, - "stakers": initial_authorities - .iter() - .map(|x| (x.0.clone(), x.0.clone(), STASH, kusama_runtime::StakerStatus::::Validator)) - .collect::>(), - "invulnerables": initial_authorities.iter().map(|x| x.0.clone()).collect::>(), - "forceEra": Forcing::NotForcing, - "slashRewardFraction": Perbill::from_percent(10), - }, - "babe": { - "epochConfig": Some(kusama_runtime::BABE_GENESIS_EPOCH_CONFIG), - }, - "configuration": { - "config": default_parachains_host_configuration(), - }, - }) -} - -fn polkadot_development_config_genesis() -> serde_json::Value { - polkadot_testnet_genesis( - vec![get_authority_keys_from_seed("Alice")], - get_account_id_from_seed::("Alice"), - None, - ) -} - -fn kusama_development_config_genesis() -> serde_json::Value { - kusama_testnet_genesis( - vec![get_authority_keys_from_seed("Alice")], - get_account_id_from_seed::("Alice"), - None, - ) -} - /// Polkadot development config (single validator Alice) pub fn polkadot_development_config() -> Result, String> { Ok(Box::new( @@ -348,7 +43,9 @@ pub fn polkadot_development_config() -> Result, String> { .with_name("Polakdot Development") .with_id("polkadot-dev") .with_chain_type(ChainType::Development) - .with_genesis_config_patch(polkadot_development_config_genesis()) + .with_genesis_config_patch( + polkadot_runtime::genesis_config_presets::polkadot_development_config_genesis(), + ) .with_protocol_id(DEFAULT_PROTOCOL_ID) .with_properties(polkadot_chain_spec_properties()) .build(), @@ -365,20 +62,14 @@ pub fn kusama_development_config() -> Result, String> { .with_name("Kusama Development") .with_id("kusama-dev") .with_chain_type(ChainType::Development) - .with_genesis_config_patch(kusama_development_config_genesis()) + .with_genesis_config_patch( + kusama_runtime::genesis_config_presets::kusama_development_config_genesis(), + ) .with_protocol_id(DEFAULT_PROTOCOL_ID) .build(), )) } -fn polkadot_local_testnet_genesis() -> serde_json::Value { - polkadot_testnet_genesis( - vec![get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob")], - get_account_id_from_seed::("Alice"), - None, - ) -} - /// Polkadot local testnet config (multivalidator Alice + Bob) pub fn polkadot_local_testnet_config() -> Result, String> { Ok(Box::new( @@ -389,21 +80,15 @@ pub fn polkadot_local_testnet_config() -> Result, String> { .with_name("Polkadot Local Testnet") .with_id("polkadot-local") .with_chain_type(ChainType::Local) - .with_genesis_config_patch(polkadot_local_testnet_genesis()) + .with_genesis_config_patch( + polkadot_runtime::genesis_config_presets::polkadot_local_testnet_genesis(), + ) .with_protocol_id(DEFAULT_PROTOCOL_ID) .with_properties(polkadot_chain_spec_properties()) .build(), )) } -fn kusama_local_testnet_genesis() -> serde_json::Value { - kusama_testnet_genesis( - vec![get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob")], - get_account_id_from_seed::("Alice"), - None, - ) -} - /// Kusama local testnet config (multivalidator Alice + Bob) pub fn kusama_local_testnet_config() -> Result, String> { Ok(Box::new( @@ -414,18 +99,10 @@ pub fn kusama_local_testnet_config() -> Result, String> { .with_name("Kusama Local Testnet") .with_id("kusama-local") .with_chain_type(ChainType::Local) - .with_genesis_config_patch(kusama_local_testnet_genesis()) + .with_genesis_config_patch( + kusama_runtime::genesis_config_presets::kusama_local_testnet_genesis(), + ) .with_protocol_id(DEFAULT_PROTOCOL_ID) .build(), )) } - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn default_parachains_host_configuration_is_consistent() { - default_parachains_host_configuration().panic_if_not_consistent(); - } -} diff --git a/relay/kusama/Cargo.toml b/relay/kusama/Cargo.toml index 992abb0203..87d385c0a9 100644 --- a/relay/kusama/Cargo.toml +++ b/relay/kusama/Cargo.toml @@ -186,7 +186,6 @@ std = [ "runtime-parachains/std", "scale-info/std", "serde_json/std", - "substrate-wasm-builder", "sp-api/std", "sp-application-crypto/std", "sp-arithmetic/std", @@ -206,6 +205,7 @@ std = [ "sp-tracing/std", "sp-transaction-pool/std", "sp-version/std", + "substrate-wasm-builder", "xcm-builder/std", "xcm-executor/std", "xcm/std", diff --git a/relay/kusama/src/genesis_config_presets.rs b/relay/kusama/src/genesis_config_presets.rs new file mode 100644 index 0000000000..da4f73b109 --- /dev/null +++ b/relay/kusama/src/genesis_config_presets.rs @@ -0,0 +1,256 @@ +// 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 Kusama runtime + +use crate::*; +use babe_primitives::AuthorityId as BabeId; +use kusama_runtime_constants::currency::UNITS as KSM; +use pallet_staking::{Forcing, StakerStatus}; +use polkadot_primitives::{AccountPublic, AssignmentId, AsyncBackingParams}; +use runtime_parachains::configuration::HostConfiguration; +use sp_core::{sr25519, Pair, Public}; +use sp_runtime::{traits::IdentifyAccount, Perbill}; +#[cfg(not(feature = "std"))] +use sp_std::alloc::format; +use sp_std::vec::Vec; + +/// Helper function to generate a crypto pair from seed +fn get_from_seed(seed: &str) -> ::Public { + TPublic::Pair::from_string(&format!("//{}", seed), None) + .expect("static values are valid; qed") + .public() +} + +/// Helper function to generate an account ID from seed +fn get_account_id_from_seed(seed: &str) -> AccountId +where + AccountPublic: From<::Public>, +{ + AccountPublic::from(get_from_seed::(seed)).into_account() +} + +/// Helper function to generate stash, controller and session key from seed +fn get_authority_keys_from_seed( + seed: &str, +) -> ( + AccountId, + AccountId, + BabeId, + GrandpaId, + ValidatorId, + AssignmentId, + AuthorityDiscoveryId, + BeefyId, +) { + let keys = get_authority_keys_from_seed_no_beefy(seed); + (keys.0, keys.1, keys.2, keys.3, keys.4, keys.5, keys.6, get_from_seed::(seed)) +} + +/// Helper function to generate stash, controller and session key from seed +fn get_authority_keys_from_seed_no_beefy( + seed: &str, +) -> (AccountId, AccountId, BabeId, GrandpaId, ValidatorId, AssignmentId, AuthorityDiscoveryId) { + ( + get_account_id_from_seed::(&format!("{}//stash", seed)), + get_account_id_from_seed::(seed), + get_from_seed::(seed), + get_from_seed::(seed), + get_from_seed::(seed), + get_from_seed::(seed), + get_from_seed::(seed), + ) +} + +fn testnet_accounts() -> Vec { + 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"), + ] +} + +fn default_parachains_host_configuration() -> HostConfiguration { + use polkadot_primitives::{MAX_CODE_SIZE, MAX_POV_SIZE}; + + runtime_parachains::configuration::HostConfiguration { + validation_upgrade_cooldown: 2u32, + validation_upgrade_delay: 2, + code_retention_period: 1200, + max_code_size: MAX_CODE_SIZE, + max_pov_size: MAX_POV_SIZE, + max_head_data_size: 32 * 1024, + max_upward_queue_count: 8, + max_upward_queue_size: 1024 * 1024, + max_downward_message_size: 1024 * 1024, + max_upward_message_size: 50 * 1024, + max_upward_message_num_per_candidate: 5, + hrmp_sender_deposit: 0, + hrmp_recipient_deposit: 0, + hrmp_channel_max_capacity: 8, + hrmp_channel_max_total_size: 8 * 1024, + hrmp_max_parachain_inbound_channels: 4, + hrmp_channel_max_message_size: 1024 * 1024, + hrmp_max_parachain_outbound_channels: 4, + hrmp_max_message_num_per_candidate: 5, + dispute_period: 6, + no_show_slots: 2, + n_delay_tranches: 25, + needed_approvals: 2, + relay_vrf_modulo_samples: 2, + zeroth_delay_tranche_width: 0, + minimum_validation_upgrade_delay: 5, + scheduler_params: polkadot_primitives::vstaging::SchedulerParams { + group_rotation_frequency: 20, + paras_availability_period: 4, + ..Default::default() + }, + dispute_post_conclusion_acceptance_period: 100u32, + minimum_backing_votes: 1, + node_features: NodeFeatures::EMPTY, + async_backing_params: AsyncBackingParams { + max_candidate_depth: 2, + allowed_ancestry_len: 2, + }, + executor_params: Default::default(), + max_validators: None, + pvf_voting_ttl: 2, + approval_voting_params: ApprovalVotingParams { max_approval_coalesce_count: 1 }, + } +} + +#[allow(clippy::type_complexity)] +fn kusama_testnet_genesis( + initial_authorities: Vec<( + AccountId, + AccountId, + BabeId, + GrandpaId, + ValidatorId, + AssignmentId, + AuthorityDiscoveryId, + BeefyId, + )>, + _root_key: AccountId, + endowed_accounts: Option>, +) -> serde_json::Value { + let endowed_accounts: Vec = endowed_accounts.unwrap_or_else(testnet_accounts); + + const ENDOWMENT: u128 = 1_000_000 * KSM; + const STASH: u128 = 100 * KSM; + + serde_json::json!({ + "balances": { + "balances": endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect::>(), + }, + "session": { + "keys": initial_authorities + .iter() + .map(|x| { + ( + x.0.clone(), + x.0.clone(), + kusama_session_keys( + x.2.clone(), + x.3.clone(), + x.4.clone(), + x.5.clone(), + x.6.clone(), + x.7.clone(), + ), + ) + }) + .collect::>(), + }, + "staking": { + "minimumValidatorCount": 1, + "validatorCount": initial_authorities.len() as u32, + "stakers": initial_authorities + .iter() + .map(|x| (x.0.clone(), x.0.clone(), STASH, StakerStatus::::Validator)) + .collect::>(), + "invulnerables": initial_authorities.iter().map(|x| x.0.clone()).collect::>(), + "forceEra": Forcing::NotForcing, + "slashRewardFraction": Perbill::from_percent(10), + }, + "babe": { + "epochConfig": Some(BABE_GENESIS_EPOCH_CONFIG), + }, + "configuration": { + "config": default_parachains_host_configuration(), + }, + }) +} + +fn kusama_session_keys( + babe: BabeId, + grandpa: GrandpaId, + para_validator: ValidatorId, + para_assignment: AssignmentId, + authority_discovery: AuthorityDiscoveryId, + beefy: BeefyId, +) -> SessionKeys { + SessionKeys { babe, grandpa, para_validator, para_assignment, authority_discovery, beefy } +} + +pub fn kusama_local_testnet_genesis() -> serde_json::Value { + kusama_testnet_genesis( + vec![get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob")], + get_account_id_from_seed::("Alice"), + None, + ) +} + +pub fn kusama_development_config_genesis() -> serde_json::Value { + kusama_testnet_genesis( + vec![get_authority_keys_from_seed("Alice")], + get_account_id_from_seed::("Alice"), + None, + ) +} + +/// 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") => kusama_development_config_genesis(), + Ok("local_testnet") => kusama_local_testnet_genesis(), + _ => return None, + }; + Some( + serde_json::to_string(&patch) + .expect("serialization to json is expected to work. qed.") + .into_bytes(), + ) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn default_parachains_host_configuration_is_consistent() { + default_parachains_host_configuration().panic_if_not_consistent(); + } +} diff --git a/relay/kusama/src/lib.rs b/relay/kusama/src/lib.rs index 98a6447987..92de3de80e 100644 --- a/relay/kusama/src/lib.rs +++ b/relay/kusama/src/lib.rs @@ -111,8 +111,6 @@ use xcm_builder::PayOverXcm; pub use frame_system::Call as SystemCall; pub use pallet_balances::Call as BalancesCall; pub use pallet_election_provider_multi_phase::{Call as EPMCall, GeometricDepositBase}; -#[cfg(feature = "std")] -pub use pallet_staking::StakerStatus; use pallet_staking::UseValidatorsMap; use sp_runtime::traits::Get; #[cfg(any(feature = "std", test))] @@ -123,6 +121,9 @@ use kusama_runtime_constants::{ currency::*, fee::*, system_parachain, time::*, TREASURY_PALLET_ID, }; +// Genesis preset configurations. +pub mod genesis_config_presets; + // Weights used in the runtime. mod weights; @@ -2339,11 +2340,14 @@ sp_api::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"), + ] } } diff --git a/relay/polkadot/Cargo.toml b/relay/polkadot/Cargo.toml index 274de022a6..1ba8f6ee76 100644 --- a/relay/polkadot/Cargo.toml +++ b/relay/polkadot/Cargo.toml @@ -183,7 +183,6 @@ std = [ "runtime-parachains/std", "scale-info/std", "serde_json/std", - "substrate-wasm-builder", "sp-api/std", "sp-application-crypto/std", "sp-arithmetic/std", @@ -203,6 +202,7 @@ std = [ "sp-tracing/std", "sp-transaction-pool/std", "sp-version/std", + "substrate-wasm-builder", "xcm-builder/std", "xcm-executor/std", "xcm/std", diff --git a/relay/polkadot/src/genesis_config_presets.rs b/relay/polkadot/src/genesis_config_presets.rs new file mode 100644 index 0000000000..cbcca69296 --- /dev/null +++ b/relay/polkadot/src/genesis_config_presets.rs @@ -0,0 +1,256 @@ +// 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 Polkadot runtime + +use crate::*; +use babe_primitives::AuthorityId as BabeId; +use pallet_staking::{Forcing, StakerStatus}; +use polkadot_primitives::{AccountPublic, AssignmentId, AsyncBackingParams}; +use polkadot_runtime_constants::currency::UNITS as DOT; +use runtime_parachains::configuration::HostConfiguration; +use sp_core::{sr25519, Pair, Public}; +use sp_runtime::{traits::IdentifyAccount, Perbill}; +#[cfg(not(feature = "std"))] +use sp_std::alloc::format; +use sp_std::vec::Vec; + +/// Helper function to generate a crypto pair from seed +fn get_from_seed(seed: &str) -> ::Public { + TPublic::Pair::from_string(&format!("//{}", seed), None) + .expect("static values are valid; qed") + .public() +} + +/// Helper function to generate an account ID from seed +fn get_account_id_from_seed(seed: &str) -> AccountId +where + AccountPublic: From<::Public>, +{ + AccountPublic::from(get_from_seed::(seed)).into_account() +} + +/// Helper function to generate stash, controller and session key from seed +fn get_authority_keys_from_seed( + seed: &str, +) -> ( + AccountId, + AccountId, + BabeId, + GrandpaId, + ValidatorId, + AssignmentId, + AuthorityDiscoveryId, + BeefyId, +) { + let keys = get_authority_keys_from_seed_no_beefy(seed); + (keys.0, keys.1, keys.2, keys.3, keys.4, keys.5, keys.6, get_from_seed::(seed)) +} + +/// Helper function to generate stash, controller and session key from seed +fn get_authority_keys_from_seed_no_beefy( + seed: &str, +) -> (AccountId, AccountId, BabeId, GrandpaId, ValidatorId, AssignmentId, AuthorityDiscoveryId) { + ( + get_account_id_from_seed::(&format!("{}//stash", seed)), + get_account_id_from_seed::(seed), + get_from_seed::(seed), + get_from_seed::(seed), + get_from_seed::(seed), + get_from_seed::(seed), + get_from_seed::(seed), + ) +} + +fn testnet_accounts() -> Vec { + 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"), + ] +} + +fn default_parachains_host_configuration() -> HostConfiguration { + use polkadot_primitives::{MAX_CODE_SIZE, MAX_POV_SIZE}; + + runtime_parachains::configuration::HostConfiguration { + validation_upgrade_cooldown: 2u32, + validation_upgrade_delay: 2, + code_retention_period: 1200, + max_code_size: MAX_CODE_SIZE, + max_pov_size: MAX_POV_SIZE, + max_head_data_size: 32 * 1024, + max_upward_queue_count: 8, + max_upward_queue_size: 1024 * 1024, + max_downward_message_size: 1024 * 1024, + max_upward_message_size: 50 * 1024, + max_upward_message_num_per_candidate: 5, + hrmp_sender_deposit: 0, + hrmp_recipient_deposit: 0, + hrmp_channel_max_capacity: 8, + hrmp_channel_max_total_size: 8 * 1024, + hrmp_max_parachain_inbound_channels: 4, + hrmp_channel_max_message_size: 1024 * 1024, + hrmp_max_parachain_outbound_channels: 4, + hrmp_max_message_num_per_candidate: 5, + dispute_period: 6, + no_show_slots: 2, + n_delay_tranches: 25, + needed_approvals: 2, + relay_vrf_modulo_samples: 2, + zeroth_delay_tranche_width: 0, + minimum_validation_upgrade_delay: 5, + scheduler_params: polkadot_primitives::vstaging::SchedulerParams { + group_rotation_frequency: 20, + paras_availability_period: 4, + ..Default::default() + }, + dispute_post_conclusion_acceptance_period: 100u32, + minimum_backing_votes: 1, + node_features: NodeFeatures::EMPTY, + async_backing_params: AsyncBackingParams { + max_candidate_depth: 2, + allowed_ancestry_len: 2, + }, + executor_params: Default::default(), + max_validators: None, + pvf_voting_ttl: 2, + approval_voting_params: ApprovalVotingParams { max_approval_coalesce_count: 1 }, + } +} + +#[allow(clippy::type_complexity)] +fn polkadot_testnet_genesis( + initial_authorities: Vec<( + AccountId, + AccountId, + BabeId, + GrandpaId, + ValidatorId, + AssignmentId, + AuthorityDiscoveryId, + BeefyId, + )>, + _root_key: AccountId, + endowed_accounts: Option>, +) -> serde_json::Value { + let endowed_accounts: Vec = endowed_accounts.unwrap_or_else(testnet_accounts); + + const ENDOWMENT: u128 = 1_000_000 * DOT; + const STASH: u128 = 100 * DOT; + + serde_json::json!({ + "balances": { + "balances": endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect::>(), + }, + "session": { + "keys": initial_authorities + .iter() + .map(|x| { + ( + x.0.clone(), + x.0.clone(), + polkadot_session_keys( + x.2.clone(), + x.3.clone(), + x.4.clone(), + x.5.clone(), + x.6.clone(), + x.7.clone(), + ), + ) + }) + .collect::>(), + }, + "staking": { + "minimumValidatorCount": 1, + "validatorCount": initial_authorities.len() as u32, + "stakers": initial_authorities + .iter() + .map(|x| (x.0.clone(), x.0.clone(), STASH, StakerStatus::::Validator)) + .collect::>(), + "invulnerables": initial_authorities.iter().map(|x| x.0.clone()).collect::>(), + "forceEra": Forcing::NotForcing, + "slashRewardFraction": Perbill::from_percent(10), + }, + "babe": { + "epochConfig": Some(BABE_GENESIS_EPOCH_CONFIG), + }, + "configuration": { + "config": default_parachains_host_configuration(), + }, + }) +} + +fn polkadot_session_keys( + babe: BabeId, + grandpa: GrandpaId, + para_validator: ValidatorId, + para_assignment: AssignmentId, + authority_discovery: AuthorityDiscoveryId, + beefy: BeefyId, +) -> SessionKeys { + SessionKeys { babe, grandpa, para_validator, para_assignment, authority_discovery, beefy } +} + +pub fn polkadot_local_testnet_genesis() -> serde_json::Value { + polkadot_testnet_genesis( + vec![get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob")], + get_account_id_from_seed::("Alice"), + None, + ) +} + +pub fn polkadot_development_config_genesis() -> serde_json::Value { + polkadot_testnet_genesis( + vec![get_authority_keys_from_seed("Alice")], + get_account_id_from_seed::("Alice"), + None, + ) +} + +/// 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") => polkadot_development_config_genesis(), + Ok("local_testnet") => polkadot_local_testnet_genesis(), + _ => return None, + }; + Some( + serde_json::to_string(&patch) + .expect("serialization to json is expected to work. qed.") + .into_bytes(), + ) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn default_parachains_host_configuration_is_consistent() { + default_parachains_host_configuration().panic_if_not_consistent(); + } +} diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index cf6ad4efcd..e2c3c09850 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -111,8 +111,6 @@ use xcm_builder::PayOverXcm; pub use frame_system::Call as SystemCall; pub use pallet_balances::Call as BalancesCall; pub use pallet_election_provider_multi_phase::{Call as EPMCall, GeometricDepositBase}; -#[cfg(feature = "std")] -pub use pallet_staking::StakerStatus; use pallet_staking::UseValidatorsMap; pub use pallet_timestamp::Call as TimestampCall; #[cfg(any(feature = "std", test))] @@ -125,7 +123,8 @@ use polkadot_runtime_constants::{currency::*, fee::*, time::*, TREASURY_PALLET_I mod weights; mod bag_thresholds; - +// Genesis preset configurations. +pub mod genesis_config_presets; // Governance configurations. pub mod governance; use governance::{ @@ -2399,11 +2398,14 @@ sp_api::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"), + ] } } diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml b/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml index bdf8043fd2..b842ac0972 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml @@ -139,6 +139,7 @@ std = [ "bp-kusama/std", "bp-messages/std", "bp-parachains/std", + "bp-polkadot-bulletin/std", "bp-polkadot-core/std", "bp-polkadot/std", "bp-relayers/std", @@ -219,11 +220,10 @@ std = [ "sp-version/std", "substrate-wasm-builder", "system-parachains-constants/std", + "tuplex/std", "xcm-builder/std", "xcm-executor/std", "xcm/std", - "bp-polkadot-bulletin/std", - "tuplex/std" ] runtime-benchmarks = [ diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml b/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml index 50287e87fb..8feeccec40 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml @@ -137,6 +137,7 @@ std = [ "bp-kusama/std", "bp-messages/std", "bp-parachains/std", + "bp-polkadot-bulletin/std", "bp-polkadot-core/std", "bp-polkadot/std", "bp-relayers/std", @@ -215,11 +216,10 @@ std = [ "sp-version/std", "substrate-wasm-builder", "system-parachains-constants/std", + "tuplex/std", "xcm-builder/std", "xcm-executor/std", "xcm/std", - "bp-polkadot-bulletin/std", - "tuplex/std" ] runtime-benchmarks = [ diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/primitives/Cargo.toml b/system-parachains/bridge-hubs/bridge-hub-polkadot/primitives/Cargo.toml index 833d4b1d27..1b83619b6b 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/primitives/Cargo.toml +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/primitives/Cargo.toml @@ -35,6 +35,7 @@ default = ["std"] std = [ "bp-bridge-hub-cumulus/std", "bp-messages/std", + "bp-polkadot-bulletin/std", "bp-runtime/std", "frame-support/std", "kusama-runtime-constants/std", @@ -45,5 +46,4 @@ std = [ "sp-std/std", "system-parachains-constants/std", "xcm/std", - "bp-polkadot-bulletin/std" ] diff --git a/system-parachains/coretime/coretime-kusama/Cargo.toml b/system-parachains/coretime/coretime-kusama/Cargo.toml index 2a5c98b37a..8b6c21542b 100644 --- a/system-parachains/coretime/coretime-kusama/Cargo.toml +++ b/system-parachains/coretime/coretime-kusama/Cargo.toml @@ -129,8 +129,8 @@ std = [ "polkadot-parachain-primitives/std", "polkadot-runtime-common/std", "scale-info/std", - "serde_json/std", "serde", + "serde_json/std", "sp-api/std", "sp-block-builder/std", "sp-consensus-aura/std", diff --git a/system-parachains/people/people-kusama/Cargo.toml b/system-parachains/people/people-kusama/Cargo.toml index 465451505d..9c93afbceb 100644 --- a/system-parachains/people/people-kusama/Cargo.toml +++ b/system-parachains/people/people-kusama/Cargo.toml @@ -92,8 +92,8 @@ std = [ "cumulus-pallet-xcmp-queue/std", "cumulus-primitives-aura/std", "cumulus-primitives-core/std", - "cumulus-primitives-utility/std", "cumulus-primitives-storage-weight-reclaim/std", + "cumulus-primitives-utility/std", "enumflags2/std", "frame-benchmarking?/std", "frame-executive/std", @@ -123,6 +123,7 @@ std = [ "parachain-info/std", "parachains-common/std", "polkadot-parachain-primitives/std", + "polkadot-primitives/std", "polkadot-runtime-common/std", "scale-info/std", "serde", @@ -145,7 +146,6 @@ std = [ "xcm-builder/std", "xcm-executor/std", "xcm/std", - "polkadot-primitives/std" ] runtime-benchmarks = [ @@ -170,11 +170,11 @@ runtime-benchmarks = [ "pallet-xcm/runtime-benchmarks", "parachains-common/runtime-benchmarks", "polkadot-parachain-primitives/runtime-benchmarks", + "polkadot-primitives/runtime-benchmarks", "polkadot-runtime-common/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "xcm-builder/runtime-benchmarks", "xcm-executor/runtime-benchmarks", - "polkadot-primitives/runtime-benchmarks" ] try-runtime = [ diff --git a/system-parachains/people/people-polkadot/Cargo.toml b/system-parachains/people/people-polkadot/Cargo.toml index 80c2ac98ee..26c75e5167 100644 --- a/system-parachains/people/people-polkadot/Cargo.toml +++ b/system-parachains/people/people-polkadot/Cargo.toml @@ -100,7 +100,6 @@ std = [ "frame-system-rpc-runtime-api/std", "frame-system/std", "frame-try-runtime?/std", - "polkadot-runtime-constants/std", "log/std", "pallet-aura/std", "pallet-authorship/std", @@ -121,6 +120,7 @@ std = [ "parachains-common/std", "polkadot-parachain-primitives/std", "polkadot-runtime-common/std", + "polkadot-runtime-constants/std", "scale-info/std", "serde", "serde_json/std", From c05940ed1ad212843297915e8eff474e25a2ab48 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Thu, 18 Jul 2024 00:33:44 +0200 Subject: [PATCH 18/23] taplo --- relay/kusama/Cargo.toml | 2 +- relay/polkadot/Cargo.toml | 2 +- system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml | 2 +- system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml | 2 +- system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml | 2 +- system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml | 2 +- system-parachains/collectives/collectives-polkadot/Cargo.toml | 2 +- system-parachains/coretime/coretime-kusama/Cargo.toml | 2 +- system-parachains/encointer/Cargo.toml | 2 +- system-parachains/people/people-kusama/Cargo.toml | 2 +- system-parachains/people/people-polkadot/Cargo.toml | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/relay/kusama/Cargo.toml b/relay/kusama/Cargo.toml index 87d385c0a9..8f081e18f2 100644 --- a/relay/kusama/Cargo.toml +++ b/relay/kusama/Cargo.toml @@ -315,7 +315,7 @@ metadata-hash = ["substrate-wasm-builder?/metadata-hash"] # A feature that should be enabled when the runtime should be built for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller, like logging for example. -on-chain-release-build = ["sp-api/disable-logging", "metadata-hash"] +on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"] # Set timing constants (e.g. session period) to faster versions to speed up testing. fast-runtime = [] diff --git a/relay/polkadot/Cargo.toml b/relay/polkadot/Cargo.toml index 1ba8f6ee76..b6c20f2649 100644 --- a/relay/polkadot/Cargo.toml +++ b/relay/polkadot/Cargo.toml @@ -308,7 +308,7 @@ metadata-hash = ["substrate-wasm-builder?/metadata-hash"] # A feature that should be enabled when the runtime should be built for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller, like logging for example. -on-chain-release-build = ["sp-api/disable-logging", "metadata-hash"] +on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"] # Set timing constants (e.g. session period) to faster versions to speed up testing. fast-runtime = [] diff --git a/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml b/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml index fe21cc7e7c..94b5b46356 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml +++ b/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml @@ -282,4 +282,4 @@ metadata-hash = ["substrate-wasm-builder?/metadata-hash"] # A feature that should be enabled when the runtime should be built for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller, like logging for example. -on-chain-release-build = ["sp-api/disable-logging", "metadata-hash"] +on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"] diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml b/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml index 22a6d4ead8..caeebc8b6e 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml +++ b/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml @@ -264,4 +264,4 @@ metadata-hash = ["substrate-wasm-builder?/metadata-hash"] # A feature that should be enabled when the runtime should be built for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller, like logging for example. -on-chain-release-build = ["sp-api/disable-logging", "metadata-hash"] +on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"] diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml b/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml index b842ac0972..a08f197000 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml @@ -309,4 +309,4 @@ metadata-hash = ["substrate-wasm-builder?/metadata-hash"] # A feature that should be enabled when the runtime should be built for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller, like logging for example. -on-chain-release-build = ["sp-api/disable-logging", "metadata-hash"] +on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"] diff --git a/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml b/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml index 8feeccec40..2b568756ec 100644 --- a/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml +++ b/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml @@ -303,4 +303,4 @@ metadata-hash = ["substrate-wasm-builder?/metadata-hash"] # A feature that should be enabled when the runtime should be built for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller, like logging for example. -on-chain-release-build = ["sp-api/disable-logging", "metadata-hash"] +on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"] diff --git a/system-parachains/collectives/collectives-polkadot/Cargo.toml b/system-parachains/collectives/collectives-polkadot/Cargo.toml index 9c219af64f..30d635797c 100644 --- a/system-parachains/collectives/collectives-polkadot/Cargo.toml +++ b/system-parachains/collectives/collectives-polkadot/Cargo.toml @@ -239,4 +239,4 @@ metadata-hash = ["substrate-wasm-builder?/metadata-hash"] # A feature that should be enabled when the runtime should be built for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller, like logging for example. -on-chain-release-build = ["sp-api/disable-logging", "metadata-hash"] +on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"] diff --git a/system-parachains/coretime/coretime-kusama/Cargo.toml b/system-parachains/coretime/coretime-kusama/Cargo.toml index 8b6c21542b..f2167f4954 100644 --- a/system-parachains/coretime/coretime-kusama/Cargo.toml +++ b/system-parachains/coretime/coretime-kusama/Cargo.toml @@ -214,4 +214,4 @@ metadata-hash = ["substrate-wasm-builder?/metadata-hash"] # A feature that should be enabled when the runtime should be built for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller, like logging for example. -on-chain-release-build = ["sp-api/disable-logging", "metadata-hash"] +on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"] diff --git a/system-parachains/encointer/Cargo.toml b/system-parachains/encointer/Cargo.toml index 37b8fc9ac6..50ec0e70ca 100644 --- a/system-parachains/encointer/Cargo.toml +++ b/system-parachains/encointer/Cargo.toml @@ -271,4 +271,4 @@ metadata-hash = ["substrate-wasm-builder?/metadata-hash"] # A feature that should be enabled when the runtime should be built for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller, like logging for example. -on-chain-release-build = ["sp-api/disable-logging", "metadata-hash"] +on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"] diff --git a/system-parachains/people/people-kusama/Cargo.toml b/system-parachains/people/people-kusama/Cargo.toml index 9c93afbceb..1e9fb673a4 100644 --- a/system-parachains/people/people-kusama/Cargo.toml +++ b/system-parachains/people/people-kusama/Cargo.toml @@ -210,4 +210,4 @@ metadata-hash = ["substrate-wasm-builder/metadata-hash"] # A feature that should be enabled when the runtime should be built for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller, like logging for example. -on-chain-release-build = ["sp-api/disable-logging", "metadata-hash"] +on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"] diff --git a/system-parachains/people/people-polkadot/Cargo.toml b/system-parachains/people/people-polkadot/Cargo.toml index 26c75e5167..74a9f9d14f 100644 --- a/system-parachains/people/people-polkadot/Cargo.toml +++ b/system-parachains/people/people-polkadot/Cargo.toml @@ -205,4 +205,4 @@ metadata-hash = ["substrate-wasm-builder?/metadata-hash"] # A feature that should be enabled when the runtime should be built for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller, like logging for example. -on-chain-release-build = ["sp-api/disable-logging", "metadata-hash"] +on-chain-release-build = ["metadata-hash", "sp-api/disable-logging"] From 18adcbca4fd8c486d7758c201d11965bab1a688b Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Thu, 18 Jul 2024 00:40:21 +0200 Subject: [PATCH 19/23] Clippy --- .../emulated/chains/relays/polkadot/src/genesis.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/integration-tests/emulated/chains/relays/polkadot/src/genesis.rs b/integration-tests/emulated/chains/relays/polkadot/src/genesis.rs index 0f9877edb4..ce483f1b67 100644 --- a/integration-tests/emulated/chains/relays/polkadot/src/genesis.rs +++ b/integration-tests/emulated/chains/relays/polkadot/src/genesis.rs @@ -112,9 +112,7 @@ pub fn genesis() -> Storage { minimum_validator_count: 1, stakers: validators::initial_authorities() .iter() - .map(|x| { - (x.0.clone(), x.1.clone(), STASH, polkadot_runtime::StakerStatus::Validator) - }) + .map(|x| (x.0.clone(), x.1.clone(), STASH, pallet_staking::StakerStatus::Validator)) .collect(), invulnerables: validators::initial_authorities().iter().map(|x| x.0.clone()).collect(), force_era: pallet_staking::Forcing::ForceNone, From 1398b624b24d64e5e87ee8d517e23c30d357dfc9 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Thu, 18 Jul 2024 11:36:03 +0200 Subject: [PATCH 20/23] Fix collectives-polkadot benchmarks --- .../collectives-polkadot/src/impls.rs | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/system-parachains/collectives/collectives-polkadot/src/impls.rs b/system-parachains/collectives/collectives-polkadot/src/impls.rs index a897e6b112..61d1f768f8 100644 --- a/system-parachains/collectives/collectives-polkadot/src/impls.rs +++ b/system-parachains/collectives/collectives-polkadot/src/impls.rs @@ -241,8 +241,25 @@ pub mod benchmarks { pub struct OpenHrmpChannel(PhantomData); impl> EnsureSuccessful for OpenHrmpChannel { fn ensure_successful() { - if let ChannelStatus::Closed = ParachainSystem::get_channel_status(I::get().into()) { - ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(I::get().into()) + let para_id = I::get(); + + // open HRMP channel + if let ChannelStatus::Closed = ParachainSystem::get_channel_status(para_id.into()) { + ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(para_id.into()) + } + + // set XCM version for sibling parachain + let sibling_parachain = Location::new(1, [Parachain(para_id)]); + if let None = PolkadotXcm::get_version_for(&sibling_parachain) { + if let Err(e) = PolkadotXcm::force_xcm_version( + RuntimeOrigin::root(), + sibling_parachain.into(), + system_parachains_constants::genesis_presets::SAFE_XCM_VERSION, + ) { + log::error!( + "Failed to `force_xcm_version` for para_id: {para_id:?}, error: {e:?}" + ); + } } } } From 4fb1acffe036449afc7f14cf8a5427506586a6ba Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Tue, 23 Jul 2024 09:40:11 +0200 Subject: [PATCH 21/23] Update .github/workflows/test.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- .github/workflows/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 438ac833ba..1e44b02c08 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -112,7 +112,6 @@ jobs: # build wasm echo "Preparing wasm for benchmarking RUNTIME_BLOB_PATH=$RUNTIME_BLOB_PATH" cargo build --profile production -p ${{ matrix.runtime.package }} --features=runtime-benchmarks -q --locked - ls -lrt $RUNTIME_BLOB_PATH # run benchmarking echo "Running benchmarking for RUNTIME_BLOB_PATH=$RUNTIME_BLOB_PATH" ./frame-omni-bencher v1 benchmark pallet --runtime $RUNTIME_BLOB_PATH --all --steps 2 --repeat 1 From 5e652c2adcdb92113c8f146a4476383760b89d90 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Tue, 23 Jul 2024 09:40:37 +0200 Subject: [PATCH 22/23] Update system-parachains/collectives/collectives-polkadot/src/impls.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- system-parachains/collectives/collectives-polkadot/src/impls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system-parachains/collectives/collectives-polkadot/src/impls.rs b/system-parachains/collectives/collectives-polkadot/src/impls.rs index 61d1f768f8..c25c21766a 100644 --- a/system-parachains/collectives/collectives-polkadot/src/impls.rs +++ b/system-parachains/collectives/collectives-polkadot/src/impls.rs @@ -250,7 +250,7 @@ pub mod benchmarks { // set XCM version for sibling parachain let sibling_parachain = Location::new(1, [Parachain(para_id)]); - if let None = PolkadotXcm::get_version_for(&sibling_parachain) { + if PolkadotXcm::get_version_for(&sibling_parachain).is_none() { if let Err(e) = PolkadotXcm::force_xcm_version( RuntimeOrigin::root(), sibling_parachain.into(), From 7c05a7a0c186b7883aef41b078d13d61e732a8f2 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Wed, 24 Jul 2024 18:28:12 +0200 Subject: [PATCH 23/23] Removed `get_authority_keys_from_seed_no_beefy` --- relay/kusama/src/genesis_config_presets.rs | 9 +-------- relay/polkadot/src/genesis_config_presets.rs | 9 +-------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/relay/kusama/src/genesis_config_presets.rs b/relay/kusama/src/genesis_config_presets.rs index da4f73b109..dda349608b 100644 --- a/relay/kusama/src/genesis_config_presets.rs +++ b/relay/kusama/src/genesis_config_presets.rs @@ -56,14 +56,6 @@ fn get_authority_keys_from_seed( AuthorityDiscoveryId, BeefyId, ) { - let keys = get_authority_keys_from_seed_no_beefy(seed); - (keys.0, keys.1, keys.2, keys.3, keys.4, keys.5, keys.6, get_from_seed::(seed)) -} - -/// Helper function to generate stash, controller and session key from seed -fn get_authority_keys_from_seed_no_beefy( - seed: &str, -) -> (AccountId, AccountId, BabeId, GrandpaId, ValidatorId, AssignmentId, AuthorityDiscoveryId) { ( get_account_id_from_seed::(&format!("{}//stash", seed)), get_account_id_from_seed::(seed), @@ -72,6 +64,7 @@ fn get_authority_keys_from_seed_no_beefy( get_from_seed::(seed), get_from_seed::(seed), get_from_seed::(seed), + get_from_seed::(seed), ) } diff --git a/relay/polkadot/src/genesis_config_presets.rs b/relay/polkadot/src/genesis_config_presets.rs index cbcca69296..38abd8e48f 100644 --- a/relay/polkadot/src/genesis_config_presets.rs +++ b/relay/polkadot/src/genesis_config_presets.rs @@ -56,14 +56,6 @@ fn get_authority_keys_from_seed( AuthorityDiscoveryId, BeefyId, ) { - let keys = get_authority_keys_from_seed_no_beefy(seed); - (keys.0, keys.1, keys.2, keys.3, keys.4, keys.5, keys.6, get_from_seed::(seed)) -} - -/// Helper function to generate stash, controller and session key from seed -fn get_authority_keys_from_seed_no_beefy( - seed: &str, -) -> (AccountId, AccountId, BabeId, GrandpaId, ValidatorId, AssignmentId, AuthorityDiscoveryId) { ( get_account_id_from_seed::(&format!("{}//stash", seed)), get_account_id_from_seed::(seed), @@ -72,6 +64,7 @@ fn get_authority_keys_from_seed_no_beefy( get_from_seed::(seed), get_from_seed::(seed), get_from_seed::(seed), + get_from_seed::(seed), ) }