diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7b5bcbaf39..8b342f1399 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.13.0 + # cancel previous runs concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} @@ -82,6 +85,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: @@ -93,6 +103,20 @@ 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 + # 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 + # 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 + env: + RUSTFLAGS: "-C debug-assertions -D warnings" + # Job required by "confirmTestPassed" integration-test: needs: [integration-test-matrix] diff --git a/Cargo.lock b/Cargo.lock index 94caf224ec..3f023668cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -642,6 +642,7 @@ dependencies = [ "polkadot-runtime-constants", "primitive-types", "scale-info", + "serde_json", "snowbridge-router-primitives", "sp-api", "sp-block-builder", @@ -775,6 +776,7 @@ dependencies = [ "polkadot-runtime-constants", "primitive-types", "scale-info", + "serde_json", "snowbridge-router-primitives", "sp-api", "sp-block-builder", @@ -1688,7 +1690,6 @@ dependencies = [ "bp-messages", "bp-parachains", "bp-polkadot", - "bp-polkadot-bulletin", "bp-polkadot-core", "bp-relayers", "bp-runtime", @@ -1743,6 +1744,7 @@ dependencies = [ "polkadot-runtime-constants", "scale-info", "serde", + "serde_json", "snowbridge-beacon-primitives", "snowbridge-core", "snowbridge-outbound-queue-runtime-api", @@ -1843,7 +1845,6 @@ dependencies = [ "bp-messages", "bp-parachains", "bp-polkadot", - "bp-polkadot-bulletin", "bp-polkadot-core", "bp-relayers", "bp-runtime", @@ -1896,6 +1897,7 @@ dependencies = [ "polkadot-runtime-constants", "scale-info", "serde", + "serde_json", "snowbridge-beacon-primitives", "snowbridge-core", "snowbridge-outbound-queue-runtime-api", @@ -2184,29 +2186,15 @@ 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", "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", - "staging-xcm", ] [[package]] @@ -2421,6 +2409,7 @@ dependencies = [ "polkadot-runtime-common", "polkadot-runtime-constants", "scale-info", + "serde_json", "sp-api", "sp-arithmetic 26.0.0", "sp-block-builder", @@ -2665,6 +2654,7 @@ dependencies = [ "polkadot-runtime-common", "scale-info", "serde", + "serde_json", "sp-api", "sp-block-builder", "sp-consensus-aura", @@ -3856,6 +3846,7 @@ dependencies = [ "polkadot-primitives", "polkadot-runtime-common", "scale-info", + "serde_json", "smallvec", "sp-api", "sp-block-builder", @@ -4820,6 +4811,7 @@ dependencies = [ "parachains-common", "parity-scale-codec", "scale-info", + "serde_json", "sp-api", "sp-block-builder", "sp-core 34.0.0", @@ -9398,6 +9390,7 @@ dependencies = [ "polkadot-runtime-common", "scale-info", "serde", + "serde_json", "sp-api", "sp-block-builder", "sp-consensus-aura", @@ -9504,6 +9497,7 @@ dependencies = [ "polkadot-runtime-constants", "scale-info", "serde", + "serde_json", "sp-api", "sp-block-builder", "sp-consensus-aura", @@ -14588,7 +14582,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 6cfc0c6c6a..5e9645b14f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -191,7 +191,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 } @@ -271,6 +271,7 @@ members = [ "integration-tests/emulated/tests/coretime/coretime-kusama", "integration-tests/emulated/tests/people/people-kusama", "integration-tests/emulated/tests/people/people-polkadot", + "integration-tests/zombienet", "relay/kusama", "relay/kusama/constants", "relay/polkadot", @@ -291,7 +292,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/Cargo.toml b/chain-spec-generator/Cargo.toml index 7a97e371a7..58415043dd 100644 --- a/chain-spec-generator/Cargo.toml +++ b/chain-spec-generator/Cargo.toml @@ -12,23 +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 } -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,17 +36,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", "polkadot-runtime/runtime-benchmarks", - "runtime-parachains/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", - "encointer-kusama-runtime/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/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/chain-spec-generator/src/system_parachains_specs.rs b/chain-spec-generator/src/system_parachains_specs.rs index 271f4c4479..2e85943521 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, AssetHubPolkadotAuraId, 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)] @@ -52,161 +48,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 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(); - -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(); - -/// 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). -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 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). -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). -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). -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). -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 } -} - -// 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. - 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()); @@ -221,64 +62,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()); @@ -293,64 +82,12 @@ 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(), )) } -// 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()); @@ -366,69 +103,12 @@ 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(), )) } -// 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,69 +124,12 @@ 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(), )) } -// 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()); @@ -521,26 +144,12 @@ 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(), )) } -// 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()); @@ -553,59 +162,16 @@ 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(), )) } -// 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()); @@ -620,64 +186,12 @@ 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.into())) .with_properties(properties) .build(), )) } -// 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()); @@ -692,64 +206,16 @@ 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(), )) } -// 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()); @@ -764,64 +230,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()); @@ -836,9 +254,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/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, 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/relay/kusama/Cargo.toml b/relay/kusama/Cargo.toml index e5c7b53bcb..c2eaa1c153 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 } @@ -109,7 +110,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 } @@ -188,7 +188,7 @@ std = [ "polkadot-runtime-common/std", "runtime-parachains/std", "scale-info/std", - "substrate-wasm-builder", + "serde_json/std", "sp-api/std", "sp-application-crypto/std", "sp-arithmetic/std", @@ -208,10 +208,11 @@ std = [ "sp-tracing/std", "sp-transaction-pool/std", "sp-version/std", + "substrate-wasm-builder", "xcm-builder/std", "xcm-executor/std", + "xcm-fee-payment-runtime-api/std", "xcm/std", - "xcm-fee-payment-runtime-api/std" ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", @@ -263,7 +264,7 @@ runtime-benchmarks = [ "sp-staking/runtime-benchmarks", "xcm-builder/runtime-benchmarks", "xcm-executor/runtime-benchmarks", - "xcm-fee-payment-runtime-api/runtime-benchmarks" + "xcm-fee-payment-runtime-api/runtime-benchmarks", ] try-runtime = [ "frame-election-provider-support/try-runtime", @@ -321,7 +322,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/kusama/src/genesis_config_presets.rs b/relay/kusama/src/genesis_config_presets.rs new file mode 100644 index 0000000000..dda349608b --- /dev/null +++ b/relay/kusama/src/genesis_config_presets.rs @@ -0,0 +1,249 @@ +// 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, +) { + ( + 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), + 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 a37f74740e..bdfb383864 100644 --- a/relay/kusama/src/lib.rs +++ b/relay/kusama/src/lib.rs @@ -112,8 +112,6 @@ use xcm_fee_payment_runtime_api::{ 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))] @@ -124,6 +122,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; @@ -2334,11 +2335,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 968bac44d0..11e6890f00 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 } @@ -106,7 +107,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 } @@ -185,7 +185,7 @@ std = [ "polkadot-runtime-constants/std", "runtime-parachains/std", "scale-info/std", - "substrate-wasm-builder", + "serde_json/std", "sp-api/std", "sp-application-crypto/std", "sp-arithmetic/std", @@ -205,10 +205,11 @@ std = [ "sp-tracing/std", "sp-transaction-pool/std", "sp-version/std", + "substrate-wasm-builder", "xcm-builder/std", "xcm-executor/std", - "xcm/std", "xcm-fee-payment-runtime-api/std", + "xcm/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", @@ -314,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/src/genesis_config_presets.rs b/relay/polkadot/src/genesis_config_presets.rs new file mode 100644 index 0000000000..38abd8e48f --- /dev/null +++ b/relay/polkadot/src/genesis_config_presets.rs @@ -0,0 +1,249 @@ +// 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, +) { + ( + 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), + 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 631fcc9cdc..6fd018a9de 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -112,8 +112,6 @@ use xcm_fee_payment_runtime_api::{ 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))] @@ -126,7 +124,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::{ @@ -2385,11 +2384,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/asset-hubs/asset-hub-kusama/Cargo.toml b/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml index 2e7bd9d438..0031a57feb 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 } @@ -254,6 +255,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", @@ -273,8 +275,8 @@ std = [ "system-parachains-constants/std", "xcm-builder/std", "xcm-executor/std", - "xcm/std", "xcm-fee-payment-runtime-api/std", + "xcm/std", ] # Enable metadata hash generation at compile time for the `CheckMetadataHash` extension. @@ -283,4 +285,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-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..09aef4c37d --- /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 = 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 42b4befc18..b49e9b620d 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; @@ -1384,11 +1386,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 081e61c224..b8b4505163 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 } @@ -235,6 +236,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", @@ -255,8 +257,8 @@ std = [ "system-parachains-constants/std", "xcm-builder/std", "xcm-executor/std", - "xcm/std", "xcm-fee-payment-runtime-api/std", + "xcm/std", ] # Enable metadata hash generation at compile time for the `CheckMetadataHash` extension. @@ -265,4 +267,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/src/genesis_config_presets.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/genesis_config_presets.rs new file mode 100644 index 0000000000..2f87b6b3b8 --- /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 = 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 db4537a508..ad04c2dec6 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; @@ -1345,11 +1347,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/Cargo.toml b/system-parachains/bridge-hubs/bridge-hub-kusama/Cargo.toml index 3d972459a8..ee9b6fbeb5 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 @@ -97,7 +98,6 @@ bp-relayers = { workspace = true } bp-runtime = { workspace = true } bp-kusama = { workspace = true } bp-polkadot = { workspace = true } -bp-polkadot-bulletin = { workspace = true } bridge-hub-common = { workspace = true } bridge-runtime-common = { workspace = true } pallet-bridge-grandpa = { workspace = true } @@ -192,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", @@ -218,12 +219,11 @@ 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", "xcm-fee-payment-runtime-api/std", + "xcm/std", ] runtime-benchmarks = [ @@ -310,4 +310,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/src/genesis_config_presets.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/src/genesis_config_presets.rs new file mode 100644 index 0000000000..a57100ce0c --- /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 = 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()` + }) +} + +pub 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 96784c165d..246ed4c1f0 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,8 @@ 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; @@ -797,11 +799,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-polkadot/Cargo.toml b/system-parachains/bridge-hubs/bridge-hub-polkadot/Cargo.toml index d683b0c496..a583b57e09 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 @@ -95,7 +96,6 @@ bp-relayers = { workspace = true } bp-runtime = { workspace = true } bp-kusama = { workspace = true } bp-polkadot = { workspace = true } -bp-polkadot-bulletin = { workspace = true } bridge-hub-common = { workspace = true } bridge-runtime-common = { workspace = true } pallet-bridge-grandpa = { workspace = true } @@ -188,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", @@ -214,12 +215,11 @@ 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", "xcm-fee-payment-runtime-api/std", + "xcm/std", ] runtime-benchmarks = [ @@ -304,4 +304,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/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/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..0d549d3c2e --- /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 = 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 2c41fa5ee3..62298e79ba 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,8 @@ 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; @@ -806,11 +808,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/collectives/collectives-polkadot/Cargo.toml b/system-parachains/collectives/collectives-polkadot/Cargo.toml index 48e4e56133..4b76893052 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 } @@ -212,6 +213,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", @@ -230,8 +232,8 @@ std = [ "system-parachains-constants/std", "xcm-builder/std", "xcm-executor/std", - "xcm/std", "xcm-fee-payment-runtime-api/std", + "xcm/std", ] # Enable metadata hash generation at compile time for the `CheckMetadataHash` extension. @@ -240,4 +242,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/src/genesis_config_presets.rs b/system-parachains/collectives/collectives-polkadot/src/genesis_config_presets.rs new file mode 100644 index 0000000000..8ad0b4dcdf --- /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 = 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(1001.into()), + Ok("local_testnet") => collectives_polkadot_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/collectives/collectives-polkadot/src/impls.rs b/system-parachains/collectives/collectives-polkadot/src/impls.rs index a897e6b112..c25c21766a 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 PolkadotXcm::get_version_for(&sibling_parachain).is_none() { + 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:?}" + ); + } } } } diff --git a/system-parachains/collectives/collectives-polkadot/src/lib.rs b/system-parachains/collectives/collectives-polkadot/src/lib.rs index 7fb5fc5dfa..b650b26db1 100644 --- a/system-parachains/collectives/collectives-polkadot/src/lib.rs +++ b/system-parachains/collectives/collectives-polkadot/src/lib.rs @@ -37,6 +37,8 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); pub mod ambassador; +// Genesis preset configurations. +pub mod genesis_config_presets; pub mod impls; mod weights; pub mod xcm_config; @@ -1009,11 +1011,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; diff --git a/system-parachains/coretime/coretime-kusama/Cargo.toml b/system-parachains/coretime/coretime-kusama/Cargo.toml index 6af63bf4e1..ce8e72e67f 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 } @@ -130,6 +131,7 @@ std = [ "polkadot-runtime-common/std", "scale-info/std", "serde", + "serde_json/std", "sp-api/std", "sp-block-builder/std", "sp-consensus-aura/std", @@ -147,8 +149,8 @@ std = [ "system-parachains-constants/std", "xcm-builder/std", "xcm-executor/std", - "xcm/std", "xcm-fee-payment-runtime-api/std", + "xcm/std", ] runtime-benchmarks = [ @@ -215,4 +217,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/src/genesis_config_presets.rs b/system-parachains/coretime/coretime-kusama/src/genesis_config_presets.rs new file mode 100644 index 0000000000..9b8c7ec0b2 --- /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 = 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 a2b87a2509..f094e2894e 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; @@ -1088,11 +1090,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/encointer/Cargo.toml b/system-parachains/encointer/Cargo.toml index 0a5082c3d9..78bd708acb 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: @@ -100,17 +101,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"] @@ -210,6 +207,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", @@ -223,10 +221,11 @@ std = [ "sp-transaction-pool/std", "sp-version/std", "substrate-wasm-builder", + "system-parachains-constants/std", "xcm-builder/std", "xcm-executor/std", - "xcm/std", "xcm-fee-payment-runtime-api/std", + "xcm/std", ] @@ -275,4 +274,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/src/genesis_config_presets.rs b/system-parachains/encointer/src/genesis_config_presets.rs new file mode 100644 index 0000000000..906c77e505 --- /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 EncointerKusama runtime + +use crate::*; +use sp_std::vec::Vec; +use system_parachains_constants::genesis_presets::*; + +const ENCOINTER_KUSAMA_ED: Balance = 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, + ..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 61ea918c8c..e765483d4b 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; @@ -1025,11 +1027,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"), + ] } } @@ -1146,251 +1151,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 - } - } - } -} 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"), + ] } } diff --git a/system-parachains/people/people-kusama/Cargo.toml b/system-parachains/people/people-kusama/Cargo.toml index 321df5d416..1fb1c20d8d 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 } @@ -92,8 +93,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,9 +124,11 @@ std = [ "parachain-info/std", "parachains-common/std", "polkadot-parachain-primitives/std", + "polkadot-primitives/std", "polkadot-runtime-common/std", "scale-info/std", "serde", + "serde_json/std", "sp-api/std", "sp-block-builder/std", "sp-consensus-aura/std", @@ -143,9 +146,8 @@ std = [ "system-parachains-constants/std", "xcm-builder/std", "xcm-executor/std", - "xcm/std", - "polkadot-primitives/std", "xcm-fee-payment-runtime-api/std", + "xcm/std", ] runtime-benchmarks = [ @@ -170,11 +172,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", "xcm-fee-payment-runtime-api/runtime-benchmarks", ] @@ -211,4 +213,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/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 0585af8e62..8935f0861b 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; @@ -1078,11 +1080,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 56eb9e8810..35303be6a6 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 } @@ -100,7 +101,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,8 +121,10 @@ std = [ "parachains-common/std", "polkadot-parachain-primitives/std", "polkadot-runtime-common/std", + "polkadot-runtime-constants/std", "scale-info/std", "serde", + "serde_json/std", "sp-api/std", "sp-block-builder/std", "sp-consensus-aura/std", @@ -140,8 +142,8 @@ std = [ "system-parachains-constants/std", "xcm-builder/std", "xcm-executor/std", - "xcm/std", "xcm-fee-payment-runtime-api/std", + "xcm/std", ] runtime-benchmarks = [ @@ -206,4 +208,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/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 3208474c6e..66028a71c4 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; @@ -1028,11 +1030,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"), + ] } } }