From 1446ea320364fddd788bdbd8e249626124090f3b Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 28 Aug 2023 13:47:06 +0200 Subject: [PATCH 01/98] sc-chain-spec: getting ready for non-native world - adds support for: - JSON based GenesisConfig (patch/full-config) to ChainSpec allowing interaction with runtime GenesisBuilder API. - interacting with arbitrary runtime wasm blob to chain-spec-builder command line util, - GenesisBuilder API in kitchensink runtime - removes `code` from system_pallet - adds `code` to the ChainSpec - deprecates ChainSpec::from_genesis, but also changes the signature of this method extending it with code argument. ChainSpec::builder() should be used instead. - implements GenesisBuilder API for node-template-runtime and kitchensink-runtime. Squash commit of work made in: https://github.com/paritytech/substrate/pull/14562 --- substrate/bin/node-template/node/Cargo.toml | 1 + .../bin/node-template/node/src/chain_spec.rs | 163 ++--- .../bin/node-template/runtime/Cargo.toml | 19 +- .../bin/node-template/runtime/src/lib.rs | 13 + substrate/bin/node/cli/Cargo.toml | 1 - substrate/bin/node/cli/src/chain_spec.rs | 552 +++++++++++---- substrate/bin/node/executor/Cargo.toml | 7 +- substrate/bin/node/executor/benches/bench.rs | 2 +- substrate/bin/node/executor/tests/basic.rs | 14 + substrate/bin/node/executor/tests/common.rs | 2 +- .../tests/res/default_genesis_config.json | 1 + substrate/bin/node/runtime/Cargo.toml | 22 +- substrate/bin/node/runtime/src/lib.rs | 11 + substrate/bin/node/testing/src/bench.rs | 22 +- substrate/bin/node/testing/src/client.rs | 7 +- substrate/bin/node/testing/src/genesis.rs | 18 +- .../bin/utils/chain-spec-builder/Cargo.toml | 4 + .../bin/utils/chain-spec-builder/bin/main.rs | 76 +- .../bin/utils/chain-spec-builder/src/lib.rs | 314 ++++++--- substrate/client/chain-spec/Cargo.toml | 13 + .../client/chain-spec/res/raw_no_code.json | 18 + .../client/chain-spec/res/raw_with_code.json | 19 + .../res/raw_with_code_no_encoded.json | 19 + .../substrate_test_runtime_from_config.json | 126 ++++ ...bstrate_test_runtime_from_config__raw.json | 53 ++ .../substrate_test_runtime_from_patch.json | 30 + ...ubstrate_test_runtime_from_patch__raw.json | 32 + substrate/client/chain-spec/src/chain_spec.rs | 659 ++++++++++++++++-- .../src/{genesis.rs => genesis_block.rs} | 0 .../chain-spec/src/genesis_config_builder.rs | 178 +++++ substrate/client/chain-spec/src/lib.rs | 17 +- .../client/cli/src/commands/insert_key.rs | 22 +- substrate/client/cli/src/runner.rs | 22 +- substrate/frame/system/src/lib.rs | 3 - substrate/test-utils/runtime/Cargo.toml | 4 +- .../runtime/{src/test_json => res}/README.md | 0 .../default_genesis_config.json | 4 +- .../default_genesis_config_incomplete.json | 4 +- .../default_genesis_config_invalid.json | 4 +- .../res/default_genesis_config_invalid_2.json | 113 +++ .../test-utils/runtime/src/genesismap.rs | 10 +- substrate/test-utils/runtime/src/lib.rs | 42 +- 42 files changed, 2132 insertions(+), 509 deletions(-) create mode 100644 substrate/bin/node/executor/tests/res/default_genesis_config.json create mode 100644 substrate/client/chain-spec/res/raw_no_code.json create mode 100644 substrate/client/chain-spec/res/raw_with_code.json create mode 100644 substrate/client/chain-spec/res/raw_with_code_no_encoded.json create mode 100644 substrate/client/chain-spec/res/substrate_test_runtime_from_config.json create mode 100644 substrate/client/chain-spec/res/substrate_test_runtime_from_config__raw.json create mode 100644 substrate/client/chain-spec/res/substrate_test_runtime_from_patch.json create mode 100644 substrate/client/chain-spec/res/substrate_test_runtime_from_patch__raw.json rename substrate/client/chain-spec/src/{genesis.rs => genesis_block.rs} (100%) create mode 100644 substrate/client/chain-spec/src/genesis_config_builder.rs rename substrate/test-utils/runtime/{src/test_json => res}/README.md (100%) rename substrate/test-utils/runtime/{src/test_json => res}/default_genesis_config.json (98%) rename substrate/test-utils/runtime/{src/test_json => res}/default_genesis_config_incomplete.json (98%) rename substrate/test-utils/runtime/{src/test_json => res}/default_genesis_config_invalid.json (98%) create mode 100644 substrate/test-utils/runtime/res/default_genesis_config_invalid_2.json diff --git a/substrate/bin/node-template/node/Cargo.toml b/substrate/bin/node-template/node/Cargo.toml index fc3fa64da993..0abf7f0abd07 100644 --- a/substrate/bin/node-template/node/Cargo.toml +++ b/substrate/bin/node-template/node/Cargo.toml @@ -19,6 +19,7 @@ name = "node-template" [dependencies] clap = { version = "4.2.5", features = ["derive"] } futures = { version = "0.3.21", features = ["thread-pool"]} +serde_json = "1.0.85" sc-cli = { path = "../../../client/cli" } sp-core = { path = "../../../primitives/core" } diff --git a/substrate/bin/node-template/node/src/chain_spec.rs b/substrate/bin/node-template/node/src/chain_spec.rs index 2cd2d0729302..ee5a206e3b95 100644 --- a/substrate/bin/node-template/node/src/chain_spec.rs +++ b/substrate/bin/node-template/node/src/chain_spec.rs @@ -1,7 +1,4 @@ -use node_template_runtime::{ - AccountId, AuraConfig, BalancesConfig, GrandpaConfig, RuntimeGenesisConfig, Signature, - SudoConfig, SystemConfig, WASM_BINARY, -}; +use node_template_runtime::{AccountId, RuntimeGenesisConfig, Signature, WASM_BINARY}; use sc_service::ChainType; use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_consensus_grandpa::AuthorityId as GrandpaId; @@ -37,122 +34,82 @@ pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) { } pub fn development_config() -> Result { - let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?; - - Ok(ChainSpec::from_genesis( - // Name - "Development", - // ID - "dev", - ChainType::Development, - move || { - testnet_genesis( - wasm_binary, - // Initial PoA authorities - vec![authority_keys_from_seed("Alice")], - // Sudo account + Ok(ChainSpec::builder() + .with_name("Development") + .with_id("dev") + .with_chain_type(ChainType::Development) + .with_extensions(None) + .with_code(WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?) + .with_genesis_config_patch(testnet_genesis( + // Initial PoA authorities + vec![authority_keys_from_seed("Alice")], + // Sudo account + get_account_id_from_seed::("Alice"), + // Pre-funded accounts + vec![ get_account_id_from_seed::("Alice"), - // Pre-funded accounts - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - ], - true, - ) - }, - // Bootnodes - vec![], - // Telemetry - None, - // Protocol ID - None, - None, - // Properties - None, - // Extensions - None, - )) + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + ], + true, + )) + .build()) } pub fn local_testnet_config() -> Result { - let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?; - - Ok(ChainSpec::from_genesis( - // Name - "Local Testnet", - // ID - "local_testnet", - ChainType::Local, - move || { - testnet_genesis( - wasm_binary, - // Initial PoA authorities - vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")], - // Sudo account + Ok(ChainSpec::builder() + .with_name("Local Testnet") + .with_id("local_testnet") + .with_chain_type(ChainType::Local) + .with_extensions(None) + .with_code(WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?) + .with_genesis_config_patch(testnet_genesis( + // Initial PoA authorities + vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")], + // Sudo account + get_account_id_from_seed::("Alice"), + // Pre-funded accounts + vec![ get_account_id_from_seed::("Alice"), - // Pre-funded accounts - 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"), - ], - true, - ) - }, - // Bootnodes - vec![], - // Telemetry - None, - // Protocol ID - None, - // Properties - None, - None, - // Extensions - None, - )) + 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"), + ], + true, + )) + .build()) } /// Configure initial storage state for FRAME modules. fn testnet_genesis( - wasm_binary: &[u8], initial_authorities: Vec<(AuraId, GrandpaId)>, root_key: AccountId, endowed_accounts: Vec, _enable_println: bool, -) -> RuntimeGenesisConfig { - RuntimeGenesisConfig { - system: SystemConfig { - // Add Wasm runtime to storage. - code: wasm_binary.to_vec(), - ..Default::default() - }, - balances: BalancesConfig { +) -> serde_json::Value { + serde_json::json!({ + "balances": { // Configure endowed accounts with initial balance of 1 << 60. - balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), + "balances": endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::>(), }, - aura: AuraConfig { - authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(), + "aura": { + "authorities": initial_authorities.iter().map(|x| (x.0.clone())).collect::>(), }, - grandpa: GrandpaConfig { - authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(), - ..Default::default() + "grandpa": { + "authorities": initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect::>(), }, - sudo: SudoConfig { + "sudo": { // Assign network admin rights. - key: Some(root_key), + "key": Some(root_key), }, - transaction_payment: Default::default(), - } + }) } diff --git a/substrate/bin/node-template/runtime/Cargo.toml b/substrate/bin/node-template/runtime/Cargo.toml index c816013c8255..1042eb7e2d28 100644 --- a/substrate/bin/node-template/runtime/Cargo.toml +++ b/substrate/bin/node-template/runtime/Cargo.toml @@ -14,7 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] } -scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } +scale-info = { version = "2.5.0", default-features = false, features = ["derive", "serde"] } pallet-aura = { path = "../../../frame/aura", default-features = false} pallet-balances = { path = "../../../frame/balances", default-features = false} @@ -28,17 +28,19 @@ pallet-transaction-payment = { path = "../../../frame/transaction-payment", defa frame-executive = { path = "../../../frame/executive", default-features = false} sp-api = { path = "../../../primitives/api", default-features = false} sp-block-builder = { path = "../../../primitives/block-builder", default-features = false} -sp-consensus-aura = { path = "../../../primitives/consensus/aura", default-features = false} -sp-consensus-grandpa = { path = "../../../primitives/consensus/grandpa", default-features = false} -sp-core = { path = "../../../primitives/core", default-features = false} +sp-consensus-aura = { path = "../../../primitives/consensus/aura", default-features = false, features = ["serde"] } +sp-consensus-grandpa = { path = "../../../primitives/consensus/grandpa", default-features = false, features = ["serde"] } +sp-core = { path = "../../../primitives/core", default-features = false, features = ["serde"]} sp-inherents = { path = "../../../primitives/inherents", default-features = false} sp-offchain = { path = "../../../primitives/offchain", default-features = false} -sp-runtime = { path = "../../../primitives/runtime", default-features = false} +sp-runtime = { path = "../../../primitives/runtime", default-features = false, features = ["serde"] } sp-session = { path = "../../../primitives/session", default-features = false} sp-std = { path = "../../../primitives/std", default-features = false} sp-storage = { path = "../../../primitives/storage", default-features = false} sp-transaction-pool = { path = "../../../primitives/transaction-pool", default-features = false} -sp-version = { path = "../../../primitives/version", default-features = false} +sp-version = { path = "../../../primitives/version", default-features = false, features = ["serde"] } +serde_json = { version = "1.0.85", default-features = false, features = ["alloc"] } +sp-genesis-builder = { version = "0.1.0-dev", default-features = false, path = "../../../primitives/genesis-builder" } # Used for the node template's RPCs frame-system-rpc-runtime-api = { path = "../../../frame/system/rpc/runtime-api", default-features = false} @@ -89,6 +91,8 @@ std = [ "sp-transaction-pool/std", "sp-version/std", "substrate-wasm-builder", + "serde_json/std", + "sp-genesis-builder/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", @@ -117,3 +121,6 @@ try-runtime = [ "sp-runtime/try-runtime", ] experimental = [ "pallet-aura/experimental" ] + +#Enabling this flag will disable GenesisBuilder API implementation in runtime. +disable-genesis-builder = [] diff --git a/substrate/bin/node-template/runtime/src/lib.rs b/substrate/bin/node-template/runtime/src/lib.rs index 216be9588bca..a7ac104e3943 100644 --- a/substrate/bin/node-template/runtime/src/lib.rs +++ b/substrate/bin/node-template/runtime/src/lib.rs @@ -23,6 +23,8 @@ use sp_std::prelude::*; use sp_version::NativeVersion; use sp_version::RuntimeVersion; +#[cfg(not(feature = "disable-genesis-builder"))] +use frame_support::genesis_builder_helper::{build_config, create_default_config}; // A few exports that help ease life for downstream crates. pub use frame_support::{ construct_runtime, parameter_types, @@ -571,4 +573,15 @@ impl_runtime_apis! { Executive::try_execute_block(block, state_root_check, signature_check, select).expect("execute-block failed") } } + + #[cfg(not(feature = "disable-genesis-builder"))] + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } } diff --git a/substrate/bin/node/cli/Cargo.toml b/substrate/bin/node/cli/Cargo.toml index 41e2399f89e2..57241c720380 100644 --- a/substrate/bin/node/cli/Cargo.toml +++ b/substrate/bin/node/cli/Cargo.toml @@ -122,7 +122,6 @@ futures = "0.3.21" tempfile = "3.1.0" assert_cmd = "2.0.2" nix = { version = "0.26.1", features = ["signal"] } -serde_json = "1.0" regex = "1.6.0" platforms = "3.0" soketto = "0.7.1" diff --git a/substrate/bin/node/cli/src/chain_spec.rs b/substrate/bin/node/cli/src/chain_spec.rs index 51beaad03688..f7d5a94659a8 100644 --- a/substrate/bin/node/cli/src/chain_spec.rs +++ b/substrate/bin/node/cli/src/chain_spec.rs @@ -20,10 +20,7 @@ use grandpa_primitives::AuthorityId as GrandpaId; use kitchensink_runtime::{ - constants::currency::*, wasm_binary_unwrap, BabeConfig, BalancesConfig, Block, CouncilConfig, - DemocracyConfig, ElectionsConfig, ImOnlineConfig, IndicesConfig, MaxNominations, - NominationPoolsConfig, SessionConfig, SessionKeys, SocietyConfig, StakerStatus, StakingConfig, - SudoConfig, SystemConfig, TechnicalCommitteeConfig, + constants::currency::*, wasm_binary_unwrap, Block, MaxNominations, SessionKeys, StakerStatus, }; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use sc_chain_spec::ChainSpecExtension; @@ -44,6 +41,8 @@ pub use node_primitives::{AccountId, Balance, Signature}; type AccountPublic = ::Signer; const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; +const ENDOWMENT: Balance = 10_000_000 * DOLLARS; +const STASH: Balance = ENDOWMENT / 1000; /// Node `ChainSpec` extensions. /// @@ -76,7 +75,11 @@ fn session_keys( SessionKeys { grandpa, babe, im_online, authority_discovery } } -fn staging_testnet_config_genesis() -> RuntimeGenesisConfig { +fn configure_accounts_for_staging_testnet() -> ( + Vec<(AccountId, AccountId, GrandpaId, BabeId, ImOnlineId, AuthorityDiscoveryId)>, + AccountId, + Vec, +) { #[rustfmt::skip] // stash, controller, session-key // generated with secret: @@ -175,28 +178,29 @@ fn staging_testnet_config_genesis() -> RuntimeGenesisConfig { ); let endowed_accounts: Vec = vec![root_key.clone()]; + (initial_authorities, root_key, endowed_accounts) +} +fn staging_testnet_config_genesis() -> serde_json::Value { + let (initial_authorities, root_key, endowed_accounts) = + configure_accounts_for_staging_testnet(); testnet_genesis(initial_authorities, vec![], root_key, Some(endowed_accounts)) } /// Staging testnet config. pub fn staging_testnet_config() -> ChainSpec { - let boot_nodes = vec![]; - ChainSpec::from_genesis( - "Staging Testnet", - "staging_testnet", - ChainType::Live, - staging_testnet_config_genesis, - boot_nodes, - Some( + ChainSpec::builder() + .with_name("Staging Testnet") + .with_id("staging_testnet") + .with_chain_type(ChainType::Live) + .with_genesis_config_patch(staging_testnet_config_genesis()) + .with_telemetry_endpoints( TelemetryEndpoints::new(vec![(STAGING_TELEMETRY_URL.to_string(), 0)]) .expect("Staging telemetry url is valid; qed"), - ), - None, - None, - None, - Default::default(), - ) + ) + .with_extensions(Default::default()) + .with_code(wasm_binary_unwrap()) + .build() } /// Helper function to generate a crypto pair from seed. @@ -228,8 +232,7 @@ pub fn authority_keys_from_seed( ) } -/// Helper function to create RuntimeGenesisConfig for testing. -pub fn testnet_genesis( +fn configure_accounts( initial_authorities: Vec<( AccountId, AccountId, @@ -239,9 +242,14 @@ pub fn testnet_genesis( AuthorityDiscoveryId, )>, initial_nominators: Vec, - root_key: AccountId, endowed_accounts: Option>, -) -> RuntimeGenesisConfig { + stash: Balance, +) -> ( + Vec<(AccountId, AccountId, GrandpaId, BabeId, ImOnlineId, AuthorityDiscoveryId)>, + Vec, + usize, + Vec<(AccountId, AccountId, Balance, StakerStatus)>, +) { let mut endowed_accounts: Vec = endowed_accounts.unwrap_or_else(|| { vec![ get_account_id_from_seed::("Alice"), @@ -273,7 +281,7 @@ pub fn testnet_genesis( let mut rng = rand::thread_rng(); let stakers = initial_authorities .iter() - .map(|x| (x.0.clone(), x.0.clone(), STASH, StakerStatus::Validator)) + .map(|x| (x.0.clone(), x.0.clone(), stash, StakerStatus::Validator)) .chain(initial_nominators.iter().map(|x| { use rand::{seq::SliceRandom, Rng}; let limit = (MaxNominations::get() as usize).min(initial_authorities.len()); @@ -284,23 +292,38 @@ pub fn testnet_genesis( .into_iter() .map(|choice| choice.0.clone()) .collect::>(); - (x.clone(), x.clone(), STASH, StakerStatus::Nominator(nominations)) + (x.clone(), x.clone(), stash, StakerStatus::Nominator(nominations)) })) .collect::>(); let num_endowed_accounts = endowed_accounts.len(); - const ENDOWMENT: Balance = 10_000_000 * DOLLARS; - const STASH: Balance = ENDOWMENT / 1000; + (initial_authorities, endowed_accounts, num_endowed_accounts, stakers) +} - RuntimeGenesisConfig { - system: SystemConfig { code: wasm_binary_unwrap().to_vec(), ..Default::default() }, - balances: BalancesConfig { - balances: endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect(), +/// Helper function to create RuntimeGenesisConfig json patch for testing. +pub fn testnet_genesis( + initial_authorities: Vec<( + AccountId, + AccountId, + GrandpaId, + BabeId, + ImOnlineId, + AuthorityDiscoveryId, + )>, + initial_nominators: Vec, + root_key: AccountId, + endowed_accounts: Option>, +) -> serde_json::Value { + let (initial_authorities, endowed_accounts, num_endowed_accounts, stakers) = + configure_accounts(initial_authorities, initial_nominators, endowed_accounts, STASH); + + let json = serde_json::json!({ + "balances": { + "balances": endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect::>(), }, - indices: IndicesConfig { indices: vec![] }, - session: SessionConfig { - keys: initial_authorities + "session": { + "keys": initial_authorities .iter() .map(|x| { ( @@ -311,66 +334,46 @@ pub fn testnet_genesis( }) .collect::>(), }, - staking: StakingConfig { - validator_count: initial_authorities.len() as u32, - minimum_validator_count: initial_authorities.len() as u32, - invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(), - slash_reward_fraction: Perbill::from_percent(10), - stakers, - ..Default::default() + "staking": { + "validatorCount": initial_authorities.len() as u32, + "minimumValidatorCount": initial_authorities.len() as u32, + "invulnerables": initial_authorities.iter().map(|x| x.0.clone()).collect::>(), + "slashRewardFraction": Perbill::from_percent(10), + "stakers": stakers.clone(), }, - democracy: DemocracyConfig::default(), - elections: ElectionsConfig { - members: endowed_accounts + "elections": { + "members": endowed_accounts .iter() .take((num_endowed_accounts + 1) / 2) .cloned() .map(|member| (member, STASH)) - .collect(), + .collect::>(), }, - council: CouncilConfig::default(), - technical_committee: TechnicalCommitteeConfig { - members: endowed_accounts + "technicalCommittee": { + "members": endowed_accounts .iter() .take((num_endowed_accounts + 1) / 2) .cloned() - .collect(), - phantom: Default::default(), + .collect::>(), }, - sudo: SudoConfig { key: Some(root_key) }, - babe: BabeConfig { - epoch_config: Some(kitchensink_runtime::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() + "sudo": { "key": Some(root_key.clone()) }, + "babe": { + "epochConfig": Some(kitchensink_runtime::BABE_GENESIS_EPOCH_CONFIG), }, - im_online: ImOnlineConfig { keys: vec![] }, - authority_discovery: Default::default(), - grandpa: Default::default(), - technical_membership: Default::default(), - treasury: Default::default(), - society: SocietyConfig { pot: 0 }, - vesting: Default::default(), - assets: pallet_assets::GenesisConfig { + "society": { "pot": 0 }, + "assets": { // This asset is used by the NIS pallet as counterpart currency. - assets: vec![(9, get_account_id_from_seed::("Alice"), true, 1)], - ..Default::default() + "assets": vec![(9, get_account_id_from_seed::("Alice"), true, 1)], }, - pool_assets: Default::default(), - transaction_storage: Default::default(), - transaction_payment: Default::default(), - alliance: Default::default(), - safe_mode: Default::default(), - tx_pause: Default::default(), - alliance_motion: Default::default(), - nomination_pools: NominationPoolsConfig { - min_create_bond: 10 * DOLLARS, - min_join_bond: 1 * DOLLARS, - ..Default::default() + "nominationPools": { + "minCreateBond": 10 * DOLLARS, + "minJoinBond": 1 * DOLLARS, }, - glutton: Default::default(), - } + }); + json } -fn development_config_genesis() -> RuntimeGenesisConfig { +fn development_config_genesis_json() -> serde_json::Value { testnet_genesis( vec![authority_keys_from_seed("Alice")], vec![], @@ -381,21 +384,17 @@ fn development_config_genesis() -> RuntimeGenesisConfig { /// Development config (single validator Alice). pub fn development_config() -> ChainSpec { - ChainSpec::from_genesis( - "Development", - "dev", - ChainType::Development, - development_config_genesis, - vec![], - None, - None, - None, - None, - Default::default(), - ) + ChainSpec::builder() + .with_name("Development") + .with_id("dev") + .with_chain_type(ChainType::Development) + .with_genesis_config_patch(development_config_genesis_json()) + .with_extensions(Default::default()) + .with_code(wasm_binary_unwrap()) + .build() } -fn local_testnet_genesis() -> RuntimeGenesisConfig { +fn local_testnet_genesis() -> serde_json::Value { testnet_genesis( vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")], vec![], @@ -406,18 +405,14 @@ fn local_testnet_genesis() -> RuntimeGenesisConfig { /// Local testnet config (multivalidator Alice + Bob). pub fn local_testnet_config() -> ChainSpec { - ChainSpec::from_genesis( - "Local Testnet", - "local_testnet", - ChainType::Local, - local_testnet_genesis, - vec![], - None, - None, - None, - None, - Default::default(), - ) + ChainSpec::builder() + .with_name("Local Testnet") + .with_id("local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(local_testnet_genesis()) + .with_extensions(Default::default()) + .with_code(wasm_binary_unwrap()) + .build() } #[cfg(test)] @@ -427,45 +422,33 @@ pub(crate) mod tests { use sc_service_test; use sp_runtime::BuildStorage; - fn local_testnet_genesis_instant_single() -> RuntimeGenesisConfig { - testnet_genesis( - vec![authority_keys_from_seed("Alice")], - vec![], - get_account_id_from_seed::("Alice"), - None, - ) - } - /// Local testnet config (single validator - Alice). pub fn integration_test_config_with_single_authority() -> ChainSpec { - ChainSpec::from_genesis( - "Integration Test", - "test", - ChainType::Development, - local_testnet_genesis_instant_single, - vec![], - None, - None, - None, - None, - Default::default(), - ) + ChainSpec::builder() + .with_name("Integration Test") + .with_id("test") + .with_chain_type(ChainType::Development) + .with_genesis_config_patch(testnet_genesis( + vec![authority_keys_from_seed("Alice")], + vec![], + get_account_id_from_seed::("Alice"), + None, + )) + .with_extensions(Default::default()) + .with_code(wasm_binary_unwrap()) + .build() } /// Local testnet config (multivalidator Alice + Bob). pub fn integration_test_config_with_two_authorities() -> ChainSpec { - ChainSpec::from_genesis( - "Integration Test", - "test", - ChainType::Development, - local_testnet_genesis, - vec![], - None, - None, - None, - None, - Default::default(), - ) + ChainSpec::builder() + .with_name("Integration Test") + .with_id("test") + .with_chain_type(ChainType::Development) + .with_genesis_config_patch(local_testnet_genesis()) + .with_extensions(Default::default()) + .with_code(wasm_binary_unwrap()) + .build() } #[test] @@ -500,4 +483,301 @@ pub(crate) mod tests { fn test_staging_test_net_chain_spec() { staging_testnet_config().build_storage().unwrap(); } + + // This compares the output of RuntimeGenesisConfig-based ChainSpec building against JSON-based + // ChainSpec building. Once RuntimeGenesisConfig is removed from client-side, entire mod can be + // removed. + mod json_vs_legacy { + use crate::chain_spec::*; + use kitchensink_runtime::{ + wasm_binary_unwrap, BabeConfig, BalancesConfig, CouncilConfig, DemocracyConfig, + ElectionsConfig, ImOnlineConfig, IndicesConfig, NominationPoolsConfig, SessionConfig, + SocietyConfig, StakingConfig, SudoConfig, TechnicalCommitteeConfig, + }; + use sp_runtime::BuildStorage; + /// Helper function to create RuntimeGenesisConfig for testing. + pub(super) fn testnet_genesis_legacy( + initial_authorities: Vec<( + AccountId, + AccountId, + GrandpaId, + BabeId, + ImOnlineId, + AuthorityDiscoveryId, + )>, + initial_nominators: Vec, + root_key: AccountId, + endowed_accounts: Option>, + ) -> RuntimeGenesisConfig { + let (initial_authorities, endowed_accounts, num_endowed_accounts, stakers) = + configure_accounts( + initial_authorities, + initial_nominators, + endowed_accounts, + STASH, + ); + + RuntimeGenesisConfig { + system: Default::default(), + balances: BalancesConfig { + balances: endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect(), + }, + indices: IndicesConfig { indices: vec![] }, + session: SessionConfig { + keys: initial_authorities + .iter() + .map(|x| { + ( + x.0.clone(), + x.0.clone(), + session_keys(x.2.clone(), x.3.clone(), x.4.clone(), x.5.clone()), + ) + }) + .collect::>(), + }, + staking: StakingConfig { + validator_count: initial_authorities.len() as u32, + minimum_validator_count: initial_authorities.len() as u32, + invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(), + slash_reward_fraction: Perbill::from_percent(10), + stakers, + ..Default::default() + }, + democracy: DemocracyConfig::default(), + elections: ElectionsConfig { + members: endowed_accounts + .iter() + .take((num_endowed_accounts + 1) / 2) + .cloned() + .map(|member| (member, STASH)) + .collect(), + }, + council: CouncilConfig::default(), + technical_committee: TechnicalCommitteeConfig { + members: endowed_accounts + .iter() + .take((num_endowed_accounts + 1) / 2) + .cloned() + .collect(), + phantom: Default::default(), + }, + sudo: SudoConfig { key: Some(root_key) }, + babe: BabeConfig { + epoch_config: Some(kitchensink_runtime::BABE_GENESIS_EPOCH_CONFIG), + ..Default::default() + }, + im_online: ImOnlineConfig { keys: vec![] }, + authority_discovery: Default::default(), + grandpa: Default::default(), + technical_membership: Default::default(), + treasury: Default::default(), + society: SocietyConfig { pot: 0 }, + vesting: Default::default(), + assets: pallet_assets::GenesisConfig { + // This asset is used by the NIS pallet as counterpart currency. + assets: vec![( + 9, + get_account_id_from_seed::("Alice"), + true, + 1, + )], + ..Default::default() + }, + pool_assets: Default::default(), + transaction_storage: Default::default(), + transaction_payment: Default::default(), + alliance: Default::default(), + safe_mode: Default::default(), + tx_pause: Default::default(), + alliance_motion: Default::default(), + nomination_pools: NominationPoolsConfig { + min_create_bond: 10 * DOLLARS, + min_join_bond: 1 * DOLLARS, + ..Default::default() + }, + glutton: Default::default(), + } + } + + fn development_config_genesis_legacy() -> RuntimeGenesisConfig { + testnet_genesis_legacy( + vec![authority_keys_from_seed("Alice")], + vec![], + get_account_id_from_seed::("Alice"), + None, + ) + } + + /// Development config (single validator Alice). Legacy building method, for testing. + fn development_config_legacy() -> ChainSpec { + #[allow(deprecated)] + ChainSpec::from_genesis( + "Development", + "dev", + ChainType::Development, + development_config_genesis_legacy, + vec![], + None, + None, + None, + None, + Default::default(), + wasm_binary_unwrap(), + ) + } + + #[test] + fn development_config_building_test() { + sp_tracing::try_init_simple(); + let j1 = development_config().as_json(true).unwrap(); + let j2 = development_config_legacy().as_json(true).unwrap(); + assert_eq!(j1, j2); + } + + pub(super) fn local_testnet_genesis_legacy() -> RuntimeGenesisConfig { + testnet_genesis_legacy( + vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")], + vec![], + get_account_id_from_seed::("Alice"), + None, + ) + } + /// Local testnet config (multivalidator Alice + Bob). Legacy building method, for testing. + fn local_testnet_config_legacy() -> ChainSpec { + #[allow(deprecated)] + ChainSpec::from_genesis( + "Local Testnet", + "local_testnet", + ChainType::Local, + local_testnet_genesis_legacy, + vec![], + None, + None, + None, + None, + Default::default(), + wasm_binary_unwrap(), + ) + } + + #[test] + fn local_testnet_config_building_test() { + sp_tracing::try_init_simple(); + let j1 = local_testnet_config().as_json(true).unwrap(); + let j2 = local_testnet_config_legacy().as_json(true).unwrap(); + assert_eq!(j1, j2); + } + + fn staging_testnet_config_genesis_legacy() -> RuntimeGenesisConfig { + let (initial_authorities, root_key, endowed_accounts) = + configure_accounts_for_staging_testnet(); + testnet_genesis_legacy(initial_authorities, vec![], root_key, Some(endowed_accounts)) + } + + /// Staging testnet config. Legacy building method, for testing. + fn staging_testnet_config_legacy() -> ChainSpec { + let boot_nodes = vec![]; + #[allow(deprecated)] + ChainSpec::from_genesis( + "Staging Testnet", + "staging_testnet", + ChainType::Live, + staging_testnet_config_genesis_legacy, + boot_nodes, + Some( + TelemetryEndpoints::new(vec![(STAGING_TELEMETRY_URL.to_string(), 0)]) + .expect("Staging telemetry url is valid; qed"), + ), + None, + None, + None, + Default::default(), + wasm_binary_unwrap(), + ) + } + + fn hex(x: T) -> String + where + T: array_bytes::Hex, + { + x.hex(Default::default()) + } + + #[test] + fn staging_testnet_config_building_test() { + sp_tracing::try_init_simple(); + + let chain_spec = staging_testnet_config(); + let storage = chain_spec.build_storage().unwrap(); + let mut keys = storage.top.keys().cloned().map(hex).collect::>(); + keys.sort(); + + let chain_spec = staging_testnet_config_legacy(); + let storage = chain_spec.build_storage().unwrap(); + let mut keys_expected = storage.top.keys().cloned().map(hex).collect::>(); + keys_expected.sort(); + assert_eq!(keys, keys_expected); + } + + fn local_testnet_genesis_instant_single_legacy() -> RuntimeGenesisConfig { + testnet_genesis_legacy( + vec![authority_keys_from_seed("Alice")], + vec![], + get_account_id_from_seed::("Alice"), + None, + ) + } + + /// Local testnet config (single validator - Alice) + pub(super) fn integration_test_config_with_single_authority_legacy() -> ChainSpec { + #[allow(deprecated)] + ChainSpec::from_genesis( + "Integration Test", + "test", + ChainType::Development, + local_testnet_genesis_instant_single_legacy, + vec![], + None, + None, + None, + None, + Default::default(), + wasm_binary_unwrap(), + ) + } + + #[test] + fn integration_test_config_with_single_authority_legacy_compare_test() { + sp_tracing::try_init_simple(); + let j1 = integration_test_config_with_single_authority_legacy().as_json(true).unwrap(); + let j2 = super::integration_test_config_with_single_authority().as_json(true).unwrap(); + assert_eq!(j1, j2); + } + + /// Local testnet config (multivalidator Alice + Bob) + pub fn integration_test_config_with_two_authorities_legacy() -> ChainSpec { + #[allow(deprecated)] + ChainSpec::from_genesis( + "Integration Test", + "test", + ChainType::Development, + local_testnet_genesis_legacy, + vec![], + None, + None, + None, + None, + Default::default(), + wasm_binary_unwrap(), + ) + } + + #[test] + fn integration_test_config_with_with_two_authorities_compare_test() { + sp_tracing::try_init_simple(); + let j1 = integration_test_config_with_two_authorities_legacy().as_json(true).unwrap(); + let j2 = super::integration_test_config_with_two_authorities().as_json(true).unwrap(); + assert_eq!(j1, j2); + } + } } diff --git a/substrate/bin/node/executor/Cargo.toml b/substrate/bin/node/executor/Cargo.toml index e98d6fa36c15..2cda0426b25b 100644 --- a/substrate/bin/node/executor/Cargo.toml +++ b/substrate/bin/node/executor/Cargo.toml @@ -14,17 +14,18 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "3.6.1" } -scale-info = { version = "2.5.0", features = ["derive"] } +log = { version = "0.4.17", default-features = false } +scale-info = { version = "2.5.0", features = ["derive", "serde"] } frame-benchmarking = { path = "../../../frame/benchmarking" } node-primitives = { path = "../primitives" } kitchensink-runtime = { path = "../runtime" } sc-executor = { path = "../../../client/executor" } -sp-core = { path = "../../../primitives/core" } +sp-core = { path = "../../../primitives/core", features=["serde"] } sp-keystore = { path = "../../../primitives/keystore" } sp-state-machine = { path = "../../../primitives/state-machine" } sp-tracing = { path = "../../../primitives/tracing" } sp-trie = { path = "../../../primitives/trie" } -sp-statement-store = { path = "../../../primitives/statement-store" } +sp-statement-store = { path = "../../../primitives/statement-store", features=["serde"] } [dev-dependencies] criterion = "0.4.0" diff --git a/substrate/bin/node/executor/benches/bench.rs b/substrate/bin/node/executor/benches/bench.rs index 1c9c002492cf..75cd041ffed0 100644 --- a/substrate/bin/node/executor/benches/bench.rs +++ b/substrate/bin/node/executor/benches/bench.rs @@ -189,7 +189,7 @@ fn bench_execute_block(c: &mut Criterion) { for strategy in execution_methods { group.bench_function(format!("{:?}", strategy), |b| { - let genesis_config = node_testing::genesis::config(Some(compact_code_unwrap())); + let genesis_config = node_testing::genesis::config(); let use_native = match strategy { ExecutionMethod::Native => true, ExecutionMethod::Wasm(..) => false, diff --git a/substrate/bin/node/executor/tests/basic.rs b/substrate/bin/node/executor/tests/basic.rs index a2f46e9fdbe9..ea298ce29454 100644 --- a/substrate/bin/node/executor/tests/basic.rs +++ b/substrate/bin/node/executor/tests/basic.rs @@ -857,3 +857,17 @@ fn should_import_block_with_test_client() { futures::executor::block_on(client.import(BlockOrigin::Own, block)).unwrap(); } + +#[test] +fn default_config_as_json_works() { + sp_tracing::try_init_simple(); + let mut t = new_test_ext(compact_code_unwrap()); + let r = executor_call(&mut t, "GenesisBuilder_create_default_config", &vec![], false) + .0 + .unwrap(); + let r = Vec::::decode(&mut &r[..]).unwrap(); + let json = String::from_utf8(r.into()).expect("returned value is json. qed."); + let expected = include_str!("res/default_genesis_config.json").to_string(); + + assert_eq!(expected, json); +} diff --git a/substrate/bin/node/executor/tests/common.rs b/substrate/bin/node/executor/tests/common.rs index 6ce9ea3a0109..c487f16f2634 100644 --- a/substrate/bin/node/executor/tests/common.rs +++ b/substrate/bin/node/executor/tests/common.rs @@ -123,7 +123,7 @@ pub fn executor_call( pub fn new_test_ext(code: &[u8]) -> TestExternalities { let ext = TestExternalities::new_with_code( code, - node_testing::genesis::config(Some(code)).build_storage().unwrap(), + node_testing::genesis::config().build_storage().unwrap(), ); ext } diff --git a/substrate/bin/node/executor/tests/res/default_genesis_config.json b/substrate/bin/node/executor/tests/res/default_genesis_config.json new file mode 100644 index 000000000000..1732f4f77c6b --- /dev/null +++ b/substrate/bin/node/executor/tests/res/default_genesis_config.json @@ -0,0 +1 @@ +{"system":{},"babe":{"authorities":[],"epochConfig":null},"indices":{"indices":[]},"balances":{"balances":[]},"transactionPayment":{"multiplier":"1000000000000000000"},"staking":{"validatorCount":0,"minimumValidatorCount":0,"invulnerables":[],"forceEra":"NotForcing","slashRewardFraction":0,"canceledPayout":0,"stakers":[],"minNominatorBond":0,"minValidatorBond":0,"maxValidatorCount":null,"maxNominatorCount":null},"session":{"keys":[]},"democracy":{},"council":{"members":[]},"technicalCommittee":{"members":[]},"elections":{"members":[]},"technicalMembership":{"members":[]},"grandpa":{"authorities":[]},"treasury":{},"sudo":{"key":null},"imOnline":{"keys":[]},"authorityDiscovery":{"keys":[]},"society":{"pot":0},"vesting":{"vesting":[]},"glutton":{"compute":"0","storage":"0","trashDataCount":0},"assets":{"assets":[],"metadata":[],"accounts":[]},"poolAssets":{"assets":[],"metadata":[],"accounts":[]},"transactionStorage":{"byteFee":10,"entryFee":1000,"storagePeriod":100800},"allianceMotion":{"members":[]},"alliance":{"fellows":[],"allies":[]},"nominationPools":{"minJoinBond":0,"minCreateBond":0,"maxPools":16,"maxMembersPerPool":32,"maxMembers":512,"globalMaxCommission":null},"txPause":{"paused":[]},"safeMode":{"enteredUntil":null}} \ No newline at end of file diff --git a/substrate/bin/node/runtime/Cargo.toml b/substrate/bin/node/runtime/Cargo.toml index f4a6f6b9c46f..1b9a6ca84022 100644 --- a/substrate/bin/node/runtime/Cargo.toml +++ b/substrate/bin/node/runtime/Cargo.toml @@ -20,31 +20,33 @@ codec = { package = "parity-scale-codec", version = "3.6.1", default-features = "derive", "max-encoded-len", ] } -scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } +scale-info = { version = "2.5.0", default-features = false, features = ["derive", "serde"] } static_assertions = "1.1.0" log = { version = "0.4.17", default-features = false } +serde_json = { version = "1.0.85", default-features = false, features = ["alloc", "arbitrary_precision"] } # pallet-asset-conversion: turn on "num-traits" feature primitive-types = { version = "0.12.0", default-features = false, features = ["codec", "scale-info", "num-traits"] } # primitives -sp-authority-discovery = { path = "../../../primitives/authority-discovery", default-features = false} -sp-consensus-babe = { path = "../../../primitives/consensus/babe", default-features = false} -sp-consensus-grandpa = { path = "../../../primitives/consensus/grandpa", default-features = false} +sp-authority-discovery = { path = "../../../primitives/authority-discovery", default-features = false, features=["serde"] } +sp-consensus-babe = { path = "../../../primitives/consensus/babe", default-features = false, features=["serde"] } +sp-consensus-grandpa = { path = "../../../primitives/consensus/grandpa", default-features = false, features=["serde"] } sp-block-builder = { path = "../../../primitives/block-builder", default-features = false} +sp-genesis-builder = { version = "0.1.0-dev", default-features = false, path = "../../../primitives/genesis-builder" } sp-inherents = { path = "../../../primitives/inherents", default-features = false} node-primitives = { path = "../primitives", default-features = false} sp-offchain = { path = "../../../primitives/offchain", default-features = false} -sp-core = { path = "../../../primitives/core", default-features = false} +sp-core = { path = "../../../primitives/core", default-features = false, features=["serde"] } sp-std = { path = "../../../primitives/std", default-features = false} sp-api = { path = "../../../primitives/api", default-features = false} -sp-runtime = { path = "../../../primitives/runtime", default-features = false} -sp-staking = { path = "../../../primitives/staking", default-features = false} +sp-runtime = { path = "../../../primitives/runtime", default-features = false, features=["serde"] } +sp-staking = { path = "../../../primitives/staking", default-features = false, features=["serde"] } sp-storage = { path = "../../../primitives/storage", default-features = false} sp-session = { path = "../../../primitives/session", default-features = false} sp-transaction-pool = { path = "../../../primitives/transaction-pool", default-features = false} -sp-statement-store = { path = "../../../primitives/statement-store", default-features = false} -sp-version = { path = "../../../primitives/version", default-features = false} +sp-statement-store = { path = "../../../primitives/statement-store", default-features = false, features=["serde"] } +sp-version = { path = "../../../primitives/version", default-features = false, features=["serde"] } sp-io = { path = "../../../primitives/io", default-features = false} # frame dependencies @@ -243,6 +245,8 @@ std = [ "sp-transaction-pool/std", "sp-version/std", "substrate-wasm-builder", + "sp-genesis-builder/std", + "serde_json/std", ] runtime-benchmarks = [ "frame-benchmarking-pallet-pov/runtime-benchmarks", diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 4f34e4ecd812..1fd1f42ed62c 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -30,6 +30,7 @@ use frame_election_provider_support::{ use frame_support::{ construct_runtime, dispatch::DispatchClass, + genesis_builder_helper::{build_config, create_default_config}, instances::{Instance1, Instance2}, ord_parameter_types, pallet_prelude::Get, @@ -2743,6 +2744,16 @@ impl_runtime_apis! { Ok(batches) } } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } } #[cfg(test)] diff --git a/substrate/bin/node/testing/src/bench.rs b/substrate/bin/node/testing/src/bench.rs index f1ab2212239b..eef6abff61e9 100644 --- a/substrate/bin/node/testing/src/bench.rs +++ b/substrate/bin/node/testing/src/bench.rs @@ -398,7 +398,7 @@ impl BenchDb { let client_config = sc_service::ClientConfig::default(); let genesis_block_builder = sc_service::GenesisBlockBuilder::new( - &keyring.generate_genesis(), + keyring.as_storage_builder(), !client_config.no_genesis, backend.clone(), executor.clone(), @@ -585,12 +585,20 @@ impl BenchKeyring { } } - /// Generate genesis with accounts from this keyring endowed with some balance. - pub fn generate_genesis(&self) -> kitchensink_runtime::RuntimeGenesisConfig { - crate::genesis::config_endowed( - Some(kitchensink_runtime::wasm_binary_unwrap()), - self.collect_account_ids(), - ) + /// Generate genesis with accounts from this keyring endowed with some balance and + /// kitchensink_runtime code blob. + pub fn as_storage_builder(&self) -> &dyn sp_runtime::BuildStorage { + self + } +} + +impl sp_runtime::BuildStorage for BenchKeyring { + fn assimilate_storage(&self, storage: &mut sp_core::storage::Storage) -> Result<(), String> { + storage.top.insert( + sp_core::storage::well_known_keys::CODE.to_vec(), + kitchensink_runtime::wasm_binary_unwrap().into(), + ); + crate::genesis::config_endowed(self.collect_account_ids()).assimilate_storage(storage) } } diff --git a/substrate/bin/node/testing/src/client.rs b/substrate/bin/node/testing/src/client.rs index c55867360bd6..22276833fb66 100644 --- a/substrate/bin/node/testing/src/client.rs +++ b/substrate/bin/node/testing/src/client.rs @@ -42,7 +42,12 @@ pub struct GenesisParameters; impl substrate_test_client::GenesisInit for GenesisParameters { fn genesis_storage(&self) -> Storage { - crate::genesis::config(None).build_storage().unwrap() + let mut storage = crate::genesis::config().build_storage().unwrap(); + storage.top.insert( + sp_core::storage::well_known_keys::CODE.to_vec(), + kitchensink_runtime::wasm_binary_unwrap().into(), + ); + storage } } diff --git a/substrate/bin/node/testing/src/genesis.rs b/substrate/bin/node/testing/src/genesis.rs index 6e7bcebfc00d..153eb422457f 100644 --- a/substrate/bin/node/testing/src/genesis.rs +++ b/substrate/bin/node/testing/src/genesis.rs @@ -20,22 +20,21 @@ use crate::keyring::*; use kitchensink_runtime::{ - constants::currency::*, wasm_binary_unwrap, AccountId, AssetsConfig, BabeConfig, - BalancesConfig, GluttonConfig, GrandpaConfig, IndicesConfig, RuntimeGenesisConfig, - SessionConfig, SocietyConfig, StakerStatus, StakingConfig, SystemConfig, - BABE_GENESIS_EPOCH_CONFIG, + constants::currency::*, AccountId, AssetsConfig, BabeConfig, BalancesConfig, GluttonConfig, + GrandpaConfig, IndicesConfig, RuntimeGenesisConfig, SessionConfig, SocietyConfig, StakerStatus, + StakingConfig, BABE_GENESIS_EPOCH_CONFIG, }; use sp_keyring::{Ed25519Keyring, Sr25519Keyring}; use sp_runtime::Perbill; /// Create genesis runtime configuration for tests. -pub fn config(code: Option<&[u8]>) -> RuntimeGenesisConfig { - config_endowed(code, Default::default()) +pub fn config() -> RuntimeGenesisConfig { + config_endowed(Default::default()) } /// Create genesis runtime configuration for tests with some extra /// endowed accounts. -pub fn config_endowed(code: Option<&[u8]>, extra_endowed: Vec) -> RuntimeGenesisConfig { +pub fn config_endowed(extra_endowed: Vec) -> RuntimeGenesisConfig { let mut endowed = vec![ (alice(), 111 * DOLLARS), (bob(), 100 * DOLLARS), @@ -48,10 +47,7 @@ pub fn config_endowed(code: Option<&[u8]>, extra_endowed: Vec) -> Run endowed.extend(extra_endowed.into_iter().map(|endowed| (endowed, 100 * DOLLARS))); RuntimeGenesisConfig { - system: SystemConfig { - code: code.map(|x| x.to_vec()).unwrap_or_else(|| wasm_binary_unwrap().to_vec()), - ..Default::default() - }, + system: Default::default(), indices: IndicesConfig { indices: vec![] }, balances: BalancesConfig { balances: endowed }, session: SessionConfig { diff --git a/substrate/bin/utils/chain-spec-builder/Cargo.toml b/substrate/bin/utils/chain-spec-builder/Cargo.toml index 4baa403e1b2e..afefbafd41c3 100644 --- a/substrate/bin/utils/chain-spec-builder/Cargo.toml +++ b/substrate/bin/utils/chain-spec-builder/Cargo.toml @@ -24,8 +24,12 @@ crate-type = ["rlib"] ansi_term = "0.12.1" clap = { version = "4.2.5", features = ["derive"] } rand = "0.8" +kitchensink-runtime = { version = "3.0.0-dev", path = "../../node/runtime" } +log = "0.4.17" node-cli = { path = "../../node/cli" } sc-chain-spec = { path = "../../../client/chain-spec" } sc-keystore = { path = "../../../client/keystore" } +serde_json = "1.0.100" sp-core = { path = "../../../primitives/core" } sp-keystore = { path = "../../../primitives/keystore" } +sp-tracing = { version = "10.0.0", path = "../../../primitives/tracing" } diff --git a/substrate/bin/utils/chain-spec-builder/bin/main.rs b/substrate/bin/utils/chain-spec-builder/bin/main.rs index 53e11abbf628..24ad1dc1e925 100644 --- a/substrate/bin/utils/chain-spec-builder/bin/main.rs +++ b/substrate/bin/utils/chain-spec-builder/bin/main.rs @@ -17,27 +17,39 @@ // along with this program. If not, see . use chain_spec_builder::{ - generate_authority_keys_and_store, generate_chain_spec, print_seeds, ChainSpecBuilder, + generate_authority_keys_and_store, generate_chain_spec, generate_chain_spec_for_runtime, + print_seeds, ChainSpecBuilder, ChainSpecBuilderCmd, EditCmd, GenerateCmd, NewCmd, VerifyCmd, }; use clap::Parser; use node_cli::chain_spec; use rand::{distributions::Alphanumeric, rngs::OsRng, Rng}; +use sc_chain_spec::GenericChainSpec; use sp_core::{crypto::Ss58Codec, sr25519}; use std::fs; fn main() -> Result<(), String> { + sp_tracing::try_init_simple(); + + let builder = ChainSpecBuilder::parse(); #[cfg(build_type = "debug")] - println!( - "The chain spec builder builds a chain specification that includes a Substrate runtime \ + if matches!(builder.command, ChainSpecBuilderCmd::Generate(_) | ChainSpecBuilderCmd::New(_)) { + println!( + "The chain spec builder builds a chain specification that includes a Substrate runtime \ compiled as WASM. To ensure proper functioning of the included runtime compile (or run) \ the chain spec builder binary in `--release` mode.\n", - ); - - let builder = ChainSpecBuilder::parse(); - let chain_spec_path = builder.chain_spec_path().to_path_buf(); - - let (authority_seeds, nominator_accounts, endowed_accounts, sudo_account) = match builder { - ChainSpecBuilder::Generate { authorities, nominators, endowed, keystore_path, .. } => { + ); + } + + let chain_spec_path = builder.chain_spec_path.to_path_buf(); + let mut write_chain_spec = true; + + let chain_spec_json = match builder.command { + ChainSpecBuilderCmd::Generate(GenerateCmd { + authorities, + nominators, + endowed, + keystore_path, + }) => { let authorities = authorities.max(1); let rand_str = || -> String { OsRng.sample_iter(&Alphanumeric).take(32).map(char::from).collect() @@ -71,19 +83,45 @@ fn main() -> Result<(), String> { let sudo_account = chain_spec::get_account_id_from_seed::(&sudo_seed).to_ss58check(); - (authority_seeds, nominator_accounts, endowed_accounts, sudo_account) + generate_chain_spec(authority_seeds, nominator_accounts, endowed_accounts, sudo_account) }, - ChainSpecBuilder::New { + ChainSpecBuilderCmd::New(NewCmd { authority_seeds, nominator_accounts, endowed_accounts, sudo_account, - .. - } => (authority_seeds, nominator_accounts, endowed_accounts, sudo_account), - }; - - let json = - generate_chain_spec(authority_seeds, nominator_accounts, endowed_accounts, sudo_account)?; + }) => + generate_chain_spec(authority_seeds, nominator_accounts, endowed_accounts, sudo_account), + ChainSpecBuilderCmd::Runtime(cmd) => generate_chain_spec_for_runtime(&cmd), + ChainSpecBuilderCmd::Edit(EditCmd { + ref input_chain_spec, + ref runtime_wasm_path, + convert_to_raw, + }) => { + let mut chain_spec = GenericChainSpec::<()>::from_json_file(input_chain_spec.clone())?; + runtime_wasm_path.clone().and_then(|path| { + chain_spec + .set_code(&fs::read(path.as_path()).expect("wasm blob file is readable")[..]) + .into() + }); + + chain_spec.as_json(convert_to_raw) + }, + ChainSpecBuilderCmd::Verify(VerifyCmd { ref input_chain_spec, ref runtime_wasm_path }) => { + write_chain_spec = false; + let mut chain_spec = GenericChainSpec::<()>::from_json_file(input_chain_spec.clone())?; + runtime_wasm_path.clone().and_then(|path| { + chain_spec + .set_code(&fs::read(path.as_path()).expect("wasm blob file is readable")[..]) + .into() + }); + chain_spec.as_json(true) + }, + }?; - fs::write(chain_spec_path, json).map_err(|err| err.to_string()) + if write_chain_spec { + fs::write(chain_spec_path, chain_spec_json).map_err(|err| err.to_string()) + } else { + Ok(()) + } } diff --git a/substrate/bin/utils/chain-spec-builder/src/lib.rs b/substrate/bin/utils/chain-spec-builder/src/lib.rs index 528b6b70115a..2f180d72f26f 100644 --- a/substrate/bin/utils/chain-spec-builder/src/lib.rs +++ b/substrate/bin/utils/chain-spec-builder/src/lib.rs @@ -29,96 +29,169 @@ //! [`sc-chain-spec`]: ../sc_chain_spec/index.html //! [`node-cli`]: ../node_cli/index.html -use std::path::{Path, PathBuf}; +use std::{ + fs, + path::{Path, PathBuf}, +}; use ansi_term::Style; -use clap::Parser; +use clap::{Parser, Subcommand}; +use sc_chain_spec::GenesisConfigBuilderRuntimeCaller; use node_cli::chain_spec::{self, AccountId}; use sc_keystore::LocalKeystore; +use serde_json::Value; use sp_core::crypto::{ByteArray, Ss58Codec}; use sp_keystore::KeystorePtr; /// A utility to easily create a testnet chain spec definition with a given set /// of authorities and endowed accounts and/or generate random accounts. -#[derive(Parser)] +#[derive(Debug, Parser)] #[command(rename_all = "kebab-case")] -pub enum ChainSpecBuilder { - /// Create a new chain spec with the given authorities, endowed and sudo - /// accounts. - New { - /// Authority key seed. - #[arg(long, short, required = true)] - authority_seeds: Vec, - /// Active nominators (SS58 format), each backing a random subset of the aforementioned - /// authorities. - #[arg(long, short, default_value = "0")] - nominator_accounts: Vec, - /// Endowed account address (SS58 format). - #[arg(long, short)] - endowed_accounts: Vec, - /// Sudo account address (SS58 format). - #[arg(long, short)] - sudo_account: String, - /// The path where the chain spec should be saved. - #[arg(long, short, default_value = "./chain_spec.json")] - chain_spec_path: PathBuf, - }, - /// Create a new chain spec with the given number of authorities and endowed - /// accounts. Random keys will be generated as required. - Generate { - /// The number of authorities. - #[arg(long, short)] - authorities: usize, - /// The number of nominators backing the aforementioned authorities. - /// - /// Will nominate a random subset of `authorities`. - #[arg(long, short, default_value_t = 0)] - nominators: usize, - /// The number of endowed accounts. - #[arg(long, short, default_value_t = 0)] - endowed: usize, - /// The path where the chain spec should be saved. - #[arg(long, short, default_value = "./chain_spec.json")] - chain_spec_path: PathBuf, - /// Path to use when saving generated keystores for each authority. - /// - /// At this path, a new folder will be created for each authority's - /// keystore named `auth-$i` where `i` is the authority index, i.e. - /// `auth-0`, `auth-1`, etc. - #[arg(long, short)] - keystore_path: Option, - }, +pub struct ChainSpecBuilder { + #[command(subcommand)] + pub command: ChainSpecBuilderCmd, + /// The path where the chain spec should be saved. + #[arg(long, short, default_value = "./chain_spec.json")] + pub chain_spec_path: PathBuf, } -impl ChainSpecBuilder { - /// Returns the path where the chain spec should be saved. - pub fn chain_spec_path(&self) -> &Path { - match self { - ChainSpecBuilder::New { chain_spec_path, .. } => chain_spec_path.as_path(), - ChainSpecBuilder::Generate { chain_spec_path, .. } => chain_spec_path.as_path(), - } - } +#[derive(Debug, Subcommand)] +#[command(rename_all = "kebab-case")] +pub enum ChainSpecBuilderCmd { + New(NewCmd), + Generate(GenerateCmd), + Runtime(RuntimeCmd), + Edit(EditCmd), + Verify(VerifyCmd), } -fn genesis_constructor( - authority_seeds: &[String], - nominator_accounts: &[AccountId], - endowed_accounts: &[AccountId], - sudo_account: &AccountId, -) -> chain_spec::RuntimeGenesisConfig { - let authorities = authority_seeds - .iter() - .map(AsRef::as_ref) - .map(chain_spec::authority_keys_from_seed) - .collect::>(); +/// Create a new chain spec with the given authorities, endowed and sudo +/// accounts. Only works for kitchen-sink runtime +#[derive(Parser, Debug)] +#[command(rename_all = "kebab-case")] +pub struct NewCmd { + /// Authority key seed. + #[arg(long, short, required = true)] + pub authority_seeds: Vec, + /// Active nominators (SS58 format), each backing a random subset of the aforementioned + /// authorities. + #[arg(long, short, default_value = "0")] + pub nominator_accounts: Vec, + /// Endowed account address (SS58 format). + #[arg(long, short)] + pub endowed_accounts: Vec, + /// Sudo account address (SS58 format). + #[arg(long, short)] + pub sudo_account: String, +} + +/// Create a new chain spec with the given number of authorities and endowed +/// accounts. Random keys will be generated as required. +#[derive(Parser, Debug)] +pub struct GenerateCmd { + /// The number of authorities. + #[arg(long, short)] + pub authorities: usize, + /// The number of nominators backing the aforementioned authorities. + /// + /// Will nominate a random subset of `authorities`. + #[arg(long, short, default_value_t = 0)] + pub nominators: usize, + /// The number of endowed accounts. + #[arg(long, short, default_value_t = 0)] + pub endowed: usize, + /// Path to use when saving generated keystores for each authority. + /// + /// At this path, a new folder will be created for each authority's + /// keystore named `auth-$i` where `i` is the authority index, i.e. + /// `auth-0`, `auth-1`, etc. + #[arg(long, short)] + pub keystore_path: Option, +} + +/// Create a new chain spec by interacting with the provided runtime wasm blob. +#[derive(Parser, Debug)] +pub struct RuntimeCmd { + /// The name of chain + #[arg(long, short = 'n', default_value = "Custom")] + chain_name: String, + /// The chain id + #[arg(long, short = 'i', default_value = "custom")] + chain_id: String, + /// The path to runtime wasm blob + #[arg(long, short)] + runtime_wasm_path: PathBuf, + /// Export chainspec as raw storage + #[arg(long, short = 's')] + raw_storage: bool, + /// Verify the genesis config. This silently generates the raw storage from genesis config. Any + /// errors will be reported. + #[arg(long, short = 'v')] + verify: bool, + #[command(subcommand)] + action: GenesisBuildAction, +} + +#[derive(Subcommand, Debug, Clone)] +enum GenesisBuildAction { + Patch(PatchCmd), + Full(FullCmd), + Default(DefaultCmd), +} + +/// Patches the runtime's default genesis config with provided patch. +#[derive(Parser, Debug, Clone)] +struct PatchCmd { + /// The path to the runtime genesis config patch. + #[arg(long, short)] + patch_path: PathBuf, +} + +/// Build the genesis config for runtime using provided json file. No defaults will be used. +#[derive(Parser, Debug, Clone)] +struct FullCmd { + /// The path to the full runtime genesis config json file. + #[arg(long, short)] + config_path: PathBuf, +} - chain_spec::testnet_genesis( - authorities, - nominator_accounts.to_vec(), - sudo_account.clone(), - Some(endowed_accounts.to_vec()), - ) +/// Gets the default genesis config for the runtime and uses it in ChainSpec. Please note that +/// default genesis config may not be valid. For some runtimes initial values should be added there +/// (e.g. session keys, babe epoch). +#[derive(Parser, Debug, Clone)] +struct DefaultCmd { + #[arg(long, short)] + /// If provided stores the default genesis config json file at given path (in addition to + /// chain-spec). + default_config_path: Option, +} + +/// Edits provided input chain spec. Input can be converted into raw storage chain-spec. The code +/// can be updated with the runtime provided in the command line. +#[derive(Parser, Debug, Clone)] +pub struct EditCmd { + #[arg(long, short)] + /// Chain spec to be edited + pub input_chain_spec: PathBuf, + /// The path to new runtime wasm blob to be stored into chain-spec + #[arg(long, short = 'r')] + pub runtime_wasm_path: Option, + /// Convert genesis spec to raw format + #[arg(long, short = 's')] + pub convert_to_raw: bool, +} + +/// Verifies provided input chain spec. If the runtime is provided verification is performed against +/// new runtime. +#[derive(Parser, Debug, Clone)] +pub struct VerifyCmd { + #[arg(long, short)] + /// Chain spec to be edited + pub input_chain_spec: PathBuf, + /// The path to new runtime wasm blob to be stored into chain-spec + #[arg(long, short = 'r')] + pub runtime_wasm_path: Option, } /// Generate the chain spec using the given seeds and accounts. @@ -145,27 +218,26 @@ pub fn generate_chain_spec( let sudo_account = parse_account(sudo_account)?; - let chain_spec = chain_spec::ChainSpec::from_genesis( - "Custom", - "custom", - sc_chain_spec::ChainType::Live, - move || { - genesis_constructor( - &authority_seeds, - &nominator_accounts, - &endowed_accounts, - &sudo_account, - ) - }, - vec![], - None, - None, - None, - None, - Default::default(), - ); - - chain_spec.as_json(false) + let authorities = authority_seeds + .iter() + .map(AsRef::as_ref) + .map(chain_spec::authority_keys_from_seed) + .collect::>(); + + chain_spec::ChainSpec::builder() + .with_name("Custom") + .with_id("custom") + .with_chain_type(sc_chain_spec::ChainType::Live) + .with_genesis_config_patch(chain_spec::testnet_genesis( + authorities, + nominator_accounts, + sudo_account, + Some(endowed_accounts), + )) + .with_extensions(Default::default()) + .with_code(kitchensink_runtime::wasm_binary_unwrap()) + .build() + .as_json(false) } /// Generate the authority keys and store them in the given `keystore_path`. @@ -239,3 +311,55 @@ pub fn print_seeds( println!("{}", header.paint("Sudo seed")); println!("//{}", sudo_seed); } + +/// Processes `RuntimeCmd` and returns JSON version of `ChainSpec` +pub fn generate_chain_spec_for_runtime(cmd: &RuntimeCmd) -> Result { + let code = fs::read(cmd.runtime_wasm_path.as_path()).expect("wasm blob file is readable"); + + let builder = chain_spec::ChainSpec::builder() + .with_name(&cmd.chain_name[..]) + .with_id(&cmd.chain_id[..]) + .with_chain_type(sc_chain_spec::ChainType::Live) + .with_extensions(Default::default()) + .with_code(&code[..]); + + let builder = match cmd.action { + GenesisBuildAction::Patch(PatchCmd { ref patch_path }) => { + let patch = fs::read(patch_path.as_path()) + .map_err(|e| format!("patch file {patch_path:?} shall be readable: {e}"))?; + builder.with_genesis_config_patch(serde_json::from_slice::(&patch[..]).map_err( + |e| format!("patch file {patch_path:?} shall contain a valid json: {e}"), + )?) + }, + GenesisBuildAction::Full(FullCmd { ref config_path }) => { + let config = fs::read(config_path.as_path()) + .map_err(|e| format!("config file {config_path:?} shall be readable: {e}"))?; + builder.with_genesis_config(serde_json::from_slice::(&config[..]).map_err( + |e| format!("config file {config_path:?} shall contain a valid json: {e}"), + )?) + }, + GenesisBuildAction::Default(DefaultCmd { ref default_config_path }) => { + let caller = GenesisConfigBuilderRuntimeCaller::new(&code[..]); + let default_config = caller + .get_default_config() + .expect("getting default config from runtime should work"); + default_config_path.clone().map(|path| { + fs::write(path.as_path(), serde_json::to_string_pretty(&default_config).unwrap()) + .map_err(|err| err.to_string()) + }); + builder.with_genesis_config(default_config) + }, + }; + + let chain_spec = builder.build(); + + match (cmd.verify, cmd.raw_storage) { + (_, true) => chain_spec.as_json(true), + (true, false) => { + chain_spec.as_json(true)?; + println!("Genesis config verification: OK"); + chain_spec.as_json(false) + }, + (false, false) => chain_spec.as_json(false), + } +} diff --git a/substrate/client/chain-spec/Cargo.toml b/substrate/client/chain-spec/Cargo.toml index 32f74f13ab50..b305c8808170 100644 --- a/substrate/client/chain-spec/Cargo.toml +++ b/substrate/client/chain-spec/Cargo.toml @@ -13,15 +13,28 @@ readme = "README.md" targets = ["x86_64-unknown-linux-gnu"] [dependencies] +codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] } +json-patch = { version = "1.0.0", default-features = false } memmap2 = "0.5.0" serde = { version = "1.0.163", features = ["derive"] } serde_json = "1.0.85" sc-client-api = { path = "../api" } sc-chain-spec-derive = { path = "derive" } sc-executor = { path = "../executor" } +sc-executor-common = { path = "../../client/executor/common" } +sp-io = { default-features = false, path = "../../primitives/io" } sc-network = { path = "../network" } sc-telemetry = { path = "../telemetry" } sp-blockchain = { path = "../../primitives/blockchain" } sp-core = { path = "../../primitives/core" } +sp-genesis-builder = { path = "../../primitives/genesis-builder" } sp-runtime = { path = "../../primitives/runtime" } sp-state-machine = { path = "../../primitives/state-machine" } +log = { version = "0.4.17", default-features = false } +array-bytes = { version = "6.1" } + +[dev-dependencies] +substrate-test-runtime = { path = "../../test-utils/runtime" } +sp-keyring = { path = "../../primitives/keyring" } +sp-application-crypto = { default-features = false, path = "../../primitives/application-crypto", features = ["serde"] } +sp-consensus-babe = { default-features = false, path = "../../primitives/consensus/babe", features = ["serde"] } diff --git a/substrate/client/chain-spec/res/raw_no_code.json b/substrate/client/chain-spec/res/raw_no_code.json new file mode 100644 index 000000000000..bac7c25582f9 --- /dev/null +++ b/substrate/client/chain-spec/res/raw_no_code.json @@ -0,0 +1,18 @@ +{ + "name": "TestName", + "id": "test_id", + "chainType": "Local", + "bootNodes": [], + "telemetryEndpoints": null, + "protocolId": null, + "properties": null, + "codeSubstitutes": {}, + "genesis": { + "raw": { + "top": { + "0x3a636f6465": "0x010101" + }, + "childrenDefault": {} + } + } +} diff --git a/substrate/client/chain-spec/res/raw_with_code.json b/substrate/client/chain-spec/res/raw_with_code.json new file mode 100644 index 000000000000..c12cec57ba7a --- /dev/null +++ b/substrate/client/chain-spec/res/raw_with_code.json @@ -0,0 +1,19 @@ +{ + "name": "TestName", + "id": "test_id", + "chainType": "Local", + "bootNodes": [], + "telemetryEndpoints": null, + "protocolId": null, + "properties": null, + "codeSubstitutes": {}, + "genesis": { + "raw": { + "top": { + "0x3a636f6465": "0x010101" + }, + "childrenDefault": {} + } + }, + "code": "0x060708" +} diff --git a/substrate/client/chain-spec/res/raw_with_code_no_encoded.json b/substrate/client/chain-spec/res/raw_with_code_no_encoded.json new file mode 100644 index 000000000000..dc82ae6904b9 --- /dev/null +++ b/substrate/client/chain-spec/res/raw_with_code_no_encoded.json @@ -0,0 +1,19 @@ +{ + "name": "TestName", + "id": "test_id", + "chainType": "Local", + "bootNodes": [], + "telemetryEndpoints": null, + "protocolId": null, + "properties": null, + "codeSubstitutes": {}, + "genesis": { + "raw": { + "top": { + "0x3a65787472696e7369635f696e646578": "0x00000000" + }, + "childrenDefault": {} + } + }, + "code": "0x060708" +} diff --git a/substrate/client/chain-spec/res/substrate_test_runtime_from_config.json b/substrate/client/chain-spec/res/substrate_test_runtime_from_config.json new file mode 100644 index 000000000000..cb55d763512d --- /dev/null +++ b/substrate/client/chain-spec/res/substrate_test_runtime_from_config.json @@ -0,0 +1,126 @@ +{ + "name": "TestName", + "id": "test_id", + "chainType": "Local", + "bootNodes": [], + "telemetryEndpoints": null, + "protocolId": null, + "properties": null, + "codeSubstitutes": {}, + "genesis": { + "runtimeGenesisConfig": { + "babe": { + "authorities": [ + [ + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + 1 + ], + [ + "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", + 1 + ], + [ + "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y", + 1 + ] + ], + "epochConfig": { + "allowed_slots": "PrimaryAndSecondaryPlainSlots", + "c": [ + 3, + 10 + ] + } + }, + "balances": { + "balances": [ + [ + "5D34dL5prEUaGNQtPPZ3yN5Y6BnkfXunKXXz6fo7ZJbLwRRH", + 100000000000000000 + ], + [ + "5GBNeWRhZc2jXu7D55rBimKYDk8PGk8itRYFTPfC8RJLKG5o", + 100000000000000000 + ], + [ + "5Dfis6XL8J2P6JHUnUtArnFWndn62SydeP8ee8sG2ky9nfm9", + 100000000000000000 + ], + [ + "5F4H97f7nQovyrbiq4ZetaaviNwThSVcFobcA5aGab6167dK", + 100000000000000000 + ], + [ + "5DiDShBWa1fQx6gLzpf3SFBhMinCoyvHM1BWjPNsmXS8hkrW", + 100000000000000000 + ], + [ + "5EFb84yH9tpcFuiKUcsmdoF7xeeY3ajG1ZLQimxQoFt9HMKR", + 100000000000000000 + ], + [ + "5DZLHESsfGrJ5YzT3HuRPXsSNb589xQ4Unubh1mYLodzKdVY", + 100000000000000000 + ], + [ + "5GHJzqvG6tXnngCpG7B12qjUvbo5e4e9z8Xjidk3CQZHxTPZ", + 100000000000000000 + ], + [ + "5CUnSsgAyLND3bxxnfNhgWXSe9Wn676JzLpGLgyJv858qhoX", + 100000000000000000 + ], + [ + "5CVKn7HAZW1Ky4r7Vkgsr7VEW88C2sHgUNDiwHY9Ct2hjU8q", + 100000000000000000 + ], + [ + "5H673aukQ4PeDe1U2nuv1bi32xDEziimh3PZz7hDdYUB7TNz", + 100000000000000000 + ], + [ + "5HTe9L15LJryjUAt1jZXZCBPnzbbGnpvFwbjE3NwCWaAqovf", + 100000000000000000 + ], + [ + "5D7LFzGpMwHPyDBavkRbWSKWTtJhCaPPZ379wWLT23bJwXJz", + 100000000000000000 + ], + [ + "5CLepMARnEgtVR1EkUuJVUvKh97gzergpSxUU3yKGx1v6EwC", + 100000000000000000 + ], + [ + "5Chb2UhfvZpmjjEziHbFbotM4quX32ZscRV6QJBt1rUKzz51", + 100000000000000000 + ], + [ + "5HmRp3i3ZZk7xsAvbi8hyXVP6whSMnBJGebVC4FsiZVhx52e", + 100000000000000000 + ], + [ + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + 100000000000000000 + ], + [ + "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", + 100000000000000000 + ], + [ + "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y", + 100000000000000000 + ] + ] + }, + "substrateTest": { + "authorities": [ + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", + "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y" + ] + }, + "system": {} + } + }, + "code": "0x0" +} diff --git a/substrate/client/chain-spec/res/substrate_test_runtime_from_config__raw.json b/substrate/client/chain-spec/res/substrate_test_runtime_from_config__raw.json new file mode 100644 index 000000000000..f033163ab19b --- /dev/null +++ b/substrate/client/chain-spec/res/substrate_test_runtime_from_config__raw.json @@ -0,0 +1,53 @@ +{ + "name": "TestName", + "id": "test_id", + "chainType": "Local", + "bootNodes": [], + "telemetryEndpoints": null, + "protocolId": null, + "properties": null, + "codeSubstitutes": {}, + "genesis": { + "raw": { + "top": { + "0x00771836bebdd29870ff246d305c578c4e7b9012096b41c4eb3aaf947f6ea429": "0x0000", + "0x00771836bebdd29870ff246d305c578c5e0621c4869aa60c02be9adcc98a0d1d": "0x0cd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a4890b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22", + "0x1cb6f36e027abb2091cfb5110ab5087f4e7b9012096b41c4eb3aaf947f6ea429": "0x0000", + "0x1cb6f36e027abb2091cfb5110ab5087f5e0621c4869aa60c02be9adcc98a0d1d": "0x0cd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d01000000000000008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48010000000000000090b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe220100000000000000", + "0x1cb6f36e027abb2091cfb5110ab5087f66e8f035c8adbe7f1547b43c51e6f8a4": "0x00000000", + "0x1cb6f36e027abb2091cfb5110ab5087faacf00b9b41fda7a9268821c2a2b3e4c": "0x0cd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d01000000000000008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48010000000000000090b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe220100000000000000", + "0x1cb6f36e027abb2091cfb5110ab5087fdc6b171b77304263c292cc3ea5ed31ef": "0x03000000000000000a0000000000000001", + "0x26aa394eea5630e07c48ae0c9558cef74e7b9012096b41c4eb3aaf947f6ea429": "0x0000", + "0x26aa394eea5630e07c48ae0c9558cef75684a022a34dd8bfa2baaf44f172b710": "0x01", + "0x26aa394eea5630e07c48ae0c9558cef78a42f33323cb5ced3b44dd825fda9fcc": "0x4545454545454545454545454545454545454545454545454545454545454545", + "0x26aa394eea5630e07c48ae0c9558cef7a44704b568d21667356a5a050c118746bb1bdbcacd6ac9340000000000000000": "0x4545454545454545454545454545454545454545454545454545454545454545", + "0x26aa394eea5630e07c48ae0c9558cef7a7fd6c28836b9a28522dc924110cf439": "0x01", + "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da901cae4e3edfbb32c91ed3f01ab964f4eeeab50338d8e5176d3141802d7b010a55dadcd5f23cf8aaafa724627e967e90e": "0x000000000000000000000000010000000000000000008a5d784563010000000000000000000000000000000000000000000000000000000000000080", + "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da91b614bd4a126f2d5d294e9a8af9da25248d7e931307afb4b68d8d565d4c66e00d856c6d65f5fed6bb82dcfb60e936c67": "0x000000000000000000000000010000000000000000008a5d784563010000000000000000000000000000000000000000000000000000000000000080", + "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da94b21aff9fe1e8b2fc4b0775b8cbeff28ba8e2c7594dd74730f3ca835e95455d199261897edc9735d602ea29615e2b10b": "0x000000000000000000000000010000000000000000008a5d784563010000000000000000000000000000000000000000000000000000000000000080", + "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da94f9aea1afa791265fae359272badc1cf8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48": "0x000000000000000000000000010000000000000000008a5d784563010000000000000000000000000000000000000000000000000000000000000080", + "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da95786a2916fcb81e1bd5dcd81e0d2452884617f575372edb5a36d85c04cdf2e4699f96fe33eb5f94a28c041b88e398d0c": "0x000000000000000000000000010000000000000000008a5d784563010000000000000000000000000000000000000000000000000000000000000080", + "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da95b8542d9672c7b7e779cc7c1e6b605691c2115d06120ea2bee32dd601d02f36367564e7ddf84ae2717ca3f097459652e": "0x000000000000000000000000010000000000000000008a5d784563010000000000000000000000000000000000000000000000000000000000000080", + "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da996c30bdbfab640838e6b6d3c33ab4adb4211b79e34ee8072eab506edd4b93a7b85a14c9a05e5cdd056d98e7dbca87730": "0x000000000000000000000000010000000000000000008a5d784563010000000000000000000000000000000000000000000000000000000000000080", + "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da99dc65b1339ec388fbf2ca0cdef51253512c6cfd663203ea16968594f24690338befd906856c4d2f4ef32dad578dba20c": "0x000000000000000000000000010000000000000000008a5d784563010000000000000000000000000000000000000000000000000000000000000080", + "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da99e6eb5abd62f5fd54793da91a47e6af6125d57171ff9241f07acaa1bb6a6103517965cf2cd00e643b27e7599ebccba70": "0x000000000000000000000000010000000000000000008a5d784563010000000000000000000000000000000000000000000000000000000000000080", + "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9b0edae20838083f2cde1c4080db8cf8090b5ab205c6974c9ea841be688864633dc9ca8a357843eeacf2314649965fe22": "0x000000000000000000000000010000000000000000008a5d784563010000000000000000000000000000000000000000000000000000000000000080", + "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9d0052993b6f3bd0544fd1f5e4125b9fbde3e789ecd53431fe5c06c12b72137153496dace35c695b5f4d7b41f7ed5763b": "0x000000000000000000000000010000000000000000008a5d784563010000000000000000000000000000000000000000000000000000000000000080", + "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9d6b7e9a5f12bc571053265dade10d3b4b606fc73f57f03cdb4c932d475ab426043e429cecc2ffff0d2672b0df8398c48": "0x000000000000000000000000010000000000000000008a5d784563010000000000000000000000000000000000000000000000000000000000000080", + "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9de1e86a9a8c739864cf3cc5ec2bea59fd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d": "0x000000000000000000000000010000000000000000008a5d784563010000000000000000000000000000000000000000000000000000000000000080", + "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9e1a35f56ee295d39287cbffcfc60c4b346f136b564e1fad55031404dd84e5cd3fa76bfe7cc7599b39d38fd06663bbc0a": "0x000000000000000000000000010000000000000000008a5d784563010000000000000000000000000000000000000000000000000000000000000080", + "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9e2c1dc507e2035edbbd8776c440d870460c57f0008067cc01c5ff9eb2e2f9b3a94299a915a91198bd1021a6c55596f57": "0x000000000000000000000000010000000000000000008a5d784563010000000000000000000000000000000000000000000000000000000000000080", + "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9eca0e653a94f4080f6311b4e7b6934eb2afba9278e30ccf6a6ceb3a8b6e336b70068f045c666f2e7f4f9cc5f47db8972": "0x000000000000000000000000010000000000000000008a5d784563010000000000000000000000000000000000000000000000000000000000000080", + "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9ee8bf7ef90fc56a8aa3b90b344c599550c29b161e27ff8ba45bf6bad4711f326fc506a8803453a4d7e3158e993495f10": "0x000000000000000000000000010000000000000000008a5d784563010000000000000000000000000000000000000000000000000000000000000080", + "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9f5d6f1c082fe63eec7a71fcad00f4a892e3d43b7b0d04e776e69e7be35247cecdac65504c579195731eaf64b7940966e": "0x000000000000000000000000010000000000000000008a5d784563010000000000000000000000000000000000000000000000000000000000000080", + "0x26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da9fbf0818841edf110e05228a6379763c4fc3c37459d9bdc61f58a5ebc01e9e2305a19d390c0543dc733861ec3cf1de01f": "0x000000000000000000000000010000000000000000008a5d784563010000000000000000000000000000000000000000000000000000000000000080", + "0x26aa394eea5630e07c48ae0c9558cef7f9cce9c888469bb1a0dceaa129672ef8": "0x0000", + "0x3a636f6465": "0x0", + "0x3a65787472696e7369635f696e646578": "0x00000000", + "0xc2261276cc9d1f8598ea4b6a74b15c2f4e7b9012096b41c4eb3aaf947f6ea429": "0x0100", + "0xc2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80": "0x00003ef1ee275e1a" + }, + "childrenDefault": {} + } + } +} diff --git a/substrate/client/chain-spec/res/substrate_test_runtime_from_patch.json b/substrate/client/chain-spec/res/substrate_test_runtime_from_patch.json new file mode 100644 index 000000000000..4b90844d6f5b --- /dev/null +++ b/substrate/client/chain-spec/res/substrate_test_runtime_from_patch.json @@ -0,0 +1,30 @@ +{ + "name": "TestName", + "id": "test_id", + "chainType": "Local", + "bootNodes": [], + "telemetryEndpoints": null, + "protocolId": null, + "properties": null, + "codeSubstitutes": {}, + "genesis": { + "runtimeGenesisConfigPatch": { + "babe": { + "epochConfig": { + "allowed_slots": "PrimaryAndSecondaryPlainSlots", + "c": [ + 7, + 10 + ] + } + }, + "substrateTest": { + "authorities": [ + "5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL", + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" + ] + } + } + }, + "code": "0x0" +} diff --git a/substrate/client/chain-spec/res/substrate_test_runtime_from_patch__raw.json b/substrate/client/chain-spec/res/substrate_test_runtime_from_patch__raw.json new file mode 100644 index 000000000000..9f4b2731649f --- /dev/null +++ b/substrate/client/chain-spec/res/substrate_test_runtime_from_patch__raw.json @@ -0,0 +1,32 @@ +{ + "name": "TestName", + "id": "test_id", + "chainType": "Local", + "bootNodes": [], + "telemetryEndpoints": null, + "protocolId": null, + "properties": null, + "codeSubstitutes": {}, + "genesis": { + "raw": { + "top": { + "0x00771836bebdd29870ff246d305c578c4e7b9012096b41c4eb3aaf947f6ea429": "0x0000", + "0x00771836bebdd29870ff246d305c578c5e0621c4869aa60c02be9adcc98a0d1d": "0x081cbd2d43530a44705ad088af313e18f80b53ef16b36177cd4b77b846f2a5f07cd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d", + "0x1cb6f36e027abb2091cfb5110ab5087f4e7b9012096b41c4eb3aaf947f6ea429": "0x0000", + "0x1cb6f36e027abb2091cfb5110ab5087f66e8f035c8adbe7f1547b43c51e6f8a4": "0x00000000", + "0x1cb6f36e027abb2091cfb5110ab5087fdc6b171b77304263c292cc3ea5ed31ef": "0x07000000000000000a0000000000000001", + "0x26aa394eea5630e07c48ae0c9558cef74e7b9012096b41c4eb3aaf947f6ea429": "0x0000", + "0x26aa394eea5630e07c48ae0c9558cef75684a022a34dd8bfa2baaf44f172b710": "0x01", + "0x26aa394eea5630e07c48ae0c9558cef78a42f33323cb5ced3b44dd825fda9fcc": "0x4545454545454545454545454545454545454545454545454545454545454545", + "0x26aa394eea5630e07c48ae0c9558cef7a44704b568d21667356a5a050c118746bb1bdbcacd6ac9340000000000000000": "0x4545454545454545454545454545454545454545454545454545454545454545", + "0x26aa394eea5630e07c48ae0c9558cef7a7fd6c28836b9a28522dc924110cf439": "0x01", + "0x26aa394eea5630e07c48ae0c9558cef7f9cce9c888469bb1a0dceaa129672ef8": "0x0000", + "0x3a636f6465": "0x0", + "0x3a65787472696e7369635f696e646578": "0x00000000", + "0xc2261276cc9d1f8598ea4b6a74b15c2f4e7b9012096b41c4eb3aaf947f6ea429": "0x0100", + "0xc2261276cc9d1f8598ea4b6a74b15c2f57c875e4cff74148e4628f264b974c80": "0x0000000000000000" + }, + "childrenDefault": {} + } + } +} diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index 96e36d8399ed..c4287e53b370 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -19,7 +19,10 @@ //! Substrate chain configurations. #![warn(missing_docs)] -use crate::{extension::GetExtension, ChainType, Properties, RuntimeGenesis}; +use crate::{ + extension::GetExtension, ChainType, GenesisConfigBuilderRuntimeCaller as RuntimeCaller, + Properties, RuntimeGenesis, +}; use sc_network::config::MultiaddrWithPeerId; use sc_telemetry::TelemetryEndpoints; use serde::{Deserialize, Serialize}; @@ -29,13 +32,27 @@ use sp_core::{ Bytes, }; use sp_runtime::BuildStorage; -use std::{borrow::Cow, collections::BTreeMap, fs::File, path::PathBuf, sync::Arc}; +use std::{ + borrow::Cow, collections::BTreeMap, fs::File, marker::PhantomData, path::PathBuf, sync::Arc, +}; + +#[derive(Serialize, Deserialize, Clone)] +#[serde(rename_all = "camelCase")] +enum GenesisBuildAction { + Patch(json::Value), + Full(json::Value), +} +#[allow(deprecated)] enum GenesisSource { File(PathBuf), Binary(Cow<'static, [u8]>), + #[deprecated( + note = "Factory and G type parameter are planned to be removed in December 2023. Use `GenesisBuilderApi` instead." + )] Factory(Arc G + Send + Sync>), Storage(Storage), + GenesisBuilderApi(GenesisBuildAction), } impl Clone for GenesisSource { @@ -43,14 +60,18 @@ impl Clone for GenesisSource { match *self { Self::File(ref path) => Self::File(path.clone()), Self::Binary(ref d) => Self::Binary(d.clone()), + #[allow(deprecated)] Self::Factory(ref f) => Self::Factory(f.clone()), Self::Storage(ref s) => Self::Storage(s.clone()), + Self::GenesisBuilderApi(ref s) => Self::GenesisBuilderApi(s.clone()), } } } impl GenesisSource { fn resolve(&self) -> Result, String> { + /// helper container for deserializing genesis from the JSON file (ChainSpec JSON file is + /// also supported here) #[derive(Serialize, Deserialize)] struct GenesisContainer { genesis: Genesis, @@ -79,31 +100,13 @@ impl GenesisSource { .map_err(|e| format!("Error parsing embedded file: {}", e))?; Ok(genesis.genesis) }, + #[allow(deprecated)] Self::Factory(f) => Ok(Genesis::Runtime(f())), - Self::Storage(storage) => { - let top = storage - .top - .iter() - .map(|(k, v)| (StorageKey(k.clone()), StorageData(v.clone()))) - .collect(); - - let children_default = storage - .children_default - .iter() - .map(|(k, child)| { - ( - StorageKey(k.clone()), - child - .data - .iter() - .map(|(k, v)| (StorageKey(k.clone()), StorageData(v.clone()))) - .collect(), - ) - }) - .collect(); - - Ok(Genesis::Raw(RawGenesis { top, children_default })) - }, + Self::Storage(storage) => Ok(Genesis::Raw(RawGenesis::from(storage.clone()))), + Self::GenesisBuilderApi(GenesisBuildAction::Full(config)) => + Ok(Genesis::RuntimeGenesisConfig(config.clone())), + Self::GenesisBuilderApi(GenesisBuildAction::Patch(patch)) => + Ok(Genesis::RuntimeGenesisConfigPatch(patch.clone())), } } } @@ -111,6 +114,7 @@ impl GenesisSource { impl BuildStorage for ChainSpec { fn assimilate_storage(&self, storage: &mut Storage) -> Result<(), String> { match self.genesis.resolve()? { + #[allow(deprecated)] Genesis::Runtime(gc) => gc.assimilate_storage(storage), Genesis::Raw(RawGenesis { top: map, children_default: children_map }) => { storage.top.extend(map.into_iter().map(|(k, v)| (k.0, v.0))); @@ -129,7 +133,21 @@ impl BuildStorage for ChainSpec { // it, but Substrate itself isn't capable of loading chain specs with just a hash at the // moment. Genesis::StateRootHash(_) => Err("Genesis storage in hash format not supported".into()), + Genesis::RuntimeGenesisConfig(config) => RuntimeCaller::new(&self.code[..]) + .get_storage_for_config(config)? + .assimilate_storage(storage), + Genesis::RuntimeGenesisConfigPatch(patch) => RuntimeCaller::new(&self.code[..]) + .get_storage_for_patch(patch)? + .assimilate_storage(storage), + }?; + + if !self.code.is_empty() { + storage + .top + .insert(sp_core::storage::well_known_keys::CODE.to_vec(), self.code.clone()); } + + Ok(()) } } @@ -144,20 +162,54 @@ pub struct RawGenesis { pub children_default: BTreeMap, } +impl From for RawGenesis { + fn from(value: sp_core::storage::Storage) -> Self { + Self { + top: value.top.into_iter().map(|(k, v)| (StorageKey(k), StorageData(v))).collect(), + children_default: value + .children_default + .into_iter() + .map(|(sk, child)| { + ( + StorageKey(sk), + child + .data + .into_iter() + .map(|(k, v)| (StorageKey(k), StorageData(v))) + .collect(), + ) + }) + .collect(), + } + } +} + +/// Represents different options for the GenesisConfig configuration. #[derive(Serialize, Deserialize)] #[serde(rename_all = "camelCase")] #[serde(deny_unknown_fields)] enum Genesis { + /// [Deprecated] Contains the JSON representation of G (the native type representing the + /// runtime GenesisConfig struct) (will be removed with `ChainSpec::from_genesis`). Runtime(G), + /// The genesis storage as raw data. Raw(RawGenesis), /// State root hash of the genesis storage. StateRootHash(StorageData), + /// Represents the full runtime genesis config in JSON format. + /// The contained object is a JSON blob that can be parsed by a compatible runtime. + RuntimeGenesisConfig(json::Value), + /// Represents a patch for the default runtime genesis config in JSON format. + /// The contained value is a JSON object that can be parsed by a compatible runtime. + RuntimeGenesisConfigPatch(json::Value), } /// A configuration of a client. Does not include runtime storage initialization. +/// Note: `genesis` and `code` are ignored due to way how the chain specification is serialized into +/// JSON file. Refer to [`ChainSpecJsonContainer`], which flattens [`ClientSpec`] and denies uknown +/// fields. #[derive(Serialize, Deserialize, Clone, Debug)] #[serde(rename_all = "camelCase")] -#[serde(deny_unknown_fields)] struct ClientSpec { name: String, id: String, @@ -181,6 +233,9 @@ struct ClientSpec { #[serde(skip_serializing)] #[allow(unused)] genesis: serde::de::IgnoredAny, + #[serde(skip)] + #[allow(unused)] + code: serde::de::IgnoredAny, /// Mapping from `block_number` to `wasm_code`. /// /// The given `wasm_code` will be used to substitute the on-chain wasm code starting with the @@ -194,15 +249,156 @@ struct ClientSpec { /// We use `Option` here since `()` is not flattenable by serde. pub type NoExtension = Option<()>; +/// Builder for creating [`ChainSpec`] instances. +pub struct ChainSpecBuilder { + name: Option, + id: Option, + chain_type: Option, + boot_nodes: Option>, + telemetry_endpoints: Option, + protocol_id: Option, + fork_id: Option, + properties: Option, + extensions: Option, + code: Option>, + genesis_build_action: Option, + _genesis: PhantomData, +} + +impl ChainSpecBuilder { + /// Creates a new builder instance with no defaults. + pub fn new() -> Self { + Self { + name: None, + id: None, + chain_type: None, + boot_nodes: None, + telemetry_endpoints: None, + protocol_id: None, + fork_id: None, + properties: None, + extensions: None, + code: None, + genesis_build_action: None, + _genesis: Default::default(), + } + } + + /// Sets the spec name. This method must be called. + pub fn with_name(mut self, name: &str) -> Self { + self.name = Some(name.into()); + self + } + + /// Sets the spec ID. This method must be called. + pub fn with_id(mut self, id: &str) -> Self { + self.id = Some(id.into()); + self + } + + /// Sets the type of the chain. This method must be called. + pub fn with_chain_type(mut self, chain_type: ChainType) -> Self { + self.chain_type = Some(chain_type); + self + } + + /// Sets a list of bootnode addresses. + pub fn with_boot_nodes(mut self, boot_nodes: Vec) -> Self { + self.boot_nodes = Some(boot_nodes); + self + } + + /// Sets telemetry endpoints. + pub fn with_telemetry_endpoints(mut self, telemetry_endpoints: TelemetryEndpoints) -> Self { + self.telemetry_endpoints = Some(telemetry_endpoints); + self + } + + /// Sets the network protocol ID. + pub fn with_protocol_id(mut self, protocol_id: &str) -> Self { + self.protocol_id = Some(protocol_id.into()); + self + } + + /// Sets an optional network fork identifier. + pub fn with_fork_id(mut self, fork_id: &str) -> Self { + self.fork_id = Some(fork_id.into()); + self + } + + /// Sets additional loosely-typed properties of the chain. + pub fn with_properties(mut self, properties: Properties) -> Self { + self.properties = Some(properties); + self + } + + /// Sets chain spec extensions. This method must be called. + pub fn with_extensions(mut self, extensions: E) -> Self { + self.extensions = Some(extensions); + self + } + + /// Sets the code. This method must be called. + pub fn with_code(mut self, code: &[u8]) -> Self { + self.code = Some(code.into()); + self + } + + /// Sets the JSON patch for runtime's GenesisConfig. + pub fn with_genesis_config_patch(mut self, patch: json::Value) -> Self { + self.genesis_build_action = Some(GenesisBuildAction::Patch(patch)); + self + } + + /// Sets the full runtime's GenesisConfig JSON. + pub fn with_genesis_config(mut self, config: json::Value) -> Self { + self.genesis_build_action = Some(GenesisBuildAction::Full(config)); + self + } + + /// Builds a [`ChainSpec`] instance using the provided settings. + pub fn build(self) -> ChainSpec { + let client_spec = ClientSpec { + name: self.name.expect("with_name must be called."), + id: self.id.expect("with_id must be called."), + chain_type: self.chain_type.expect("with_chain_type must be called."), + boot_nodes: self.boot_nodes.unwrap_or(Default::default()), + telemetry_endpoints: self.telemetry_endpoints, + protocol_id: self.protocol_id, + fork_id: self.fork_id, + properties: self.properties, + extensions: self.extensions.expect("with_extensions must be called"), + consensus_engine: (), + genesis: Default::default(), + code: Default::default(), + code_substitutes: BTreeMap::new(), + }; + + ChainSpec { + client_spec, + genesis: GenesisSource::GenesisBuilderApi( + self.genesis_build_action + .expect("with_genesis_config_patch or with_genesis_config must be called."), + ), + code: self.code.expect("with code must be called.").into(), + } + } +} + /// A configuration of a chain. Can be used to build a genesis block. pub struct ChainSpec { client_spec: ClientSpec, genesis: GenesisSource, + code: Vec, } impl Clone for ChainSpec { fn clone(&self) -> Self { - ChainSpec { client_spec: self.client_spec.clone(), genesis: self.genesis.clone() } + ChainSpec { + client_spec: self.client_spec.clone(), + genesis: self.genesis.clone(), + code: self.code.clone(), + } } } @@ -260,6 +456,10 @@ impl ChainSpec { } /// Create hardcoded spec. + #[deprecated( + note = "`from_genesis` is planned to be removed in December 2023. Use `builder()` instead." + )] + // deprecated note: Genesis::Runtime + GenesisSource::Factory shall also be removed pub fn from_genesis G + 'static + Send + Sync>( name: &str, id: &str, @@ -271,6 +471,7 @@ impl ChainSpec { fork_id: Option<&str>, properties: Option, extensions: E, + code: &[u8], ) -> Self { let client_spec = ClientSpec { name: name.to_owned(), @@ -284,25 +485,52 @@ impl ChainSpec { extensions, consensus_engine: (), genesis: Default::default(), + code: Default::default(), code_substitutes: BTreeMap::new(), }; - ChainSpec { client_spec, genesis: GenesisSource::Factory(Arc::new(constructor)) } + #[allow(deprecated)] + ChainSpec { + client_spec, + genesis: GenesisSource::Factory(Arc::new(constructor)), + code: code.into(), + } } /// Type of the chain. fn chain_type(&self) -> ChainType { self.client_spec.chain_type.clone() } + + /// Sets the code. + pub fn set_code(&mut self, code: &[u8]) { + self.code = code.into(); + } + + /// Provides a `ChainSpec` builder. + pub fn builder() -> ChainSpecBuilder { + ChainSpecBuilder::new() + } +} + +/// Helper structure for deserializing optional `code` attribute from JSON file. +#[derive(Serialize, Deserialize)] +struct CodeContainer { + #[serde(default, with = "sp_core::bytes")] + code: Vec, } -impl ChainSpec { +impl ChainSpec { /// Parse json content into a `ChainSpec` pub fn from_json_bytes(json: impl Into>) -> Result { let json = json.into(); let client_spec = json::from_slice(json.as_ref()) .map_err(|e| format!("Error parsing spec file: {}", e))?; - Ok(ChainSpec { client_spec, genesis: GenesisSource::Binary(json) }) + + let code: CodeContainer = json::from_slice(json.as_ref()) + .map_err(|e| format!("Error parsing spec file: {}", e))?; + + Ok(ChainSpec { client_spec, genesis: GenesisSource::Binary(json), code: code.code }) } /// Parse json file into a `ChainSpec` @@ -321,47 +549,73 @@ impl ChainSpec { let client_spec = json::from_slice(&bytes).map_err(|e| format!("Error parsing spec file: {}", e))?; - Ok(ChainSpec { client_spec, genesis: GenesisSource::File(path) }) + + let code: CodeContainer = + json::from_slice(&bytes).map_err(|e| format!("Error parsing spec file: {}", e))?; + + Ok(ChainSpec { client_spec, genesis: GenesisSource::File(path), code: code.code }) } } +/// Helper structure for serializing (and only serializing) the ChainSpec into JSON file. It +/// represents the layout of `ChainSpec` JSON file. #[derive(Serialize, Deserialize)] -struct JsonContainer { +#[serde(deny_unknown_fields)] +struct ChainSpecJsonContainer { #[serde(flatten)] client_spec: ClientSpec, genesis: Genesis, + #[serde(with = "sp_core::bytes", skip_serializing_if = "Vec::is_empty")] + code: Vec, } impl ChainSpec { - fn json_container(&self, raw: bool) -> Result, String> { - let genesis = match (raw, self.genesis.resolve()?) { + fn json_container(&self, raw: bool) -> Result, String> { + let mut raw_genesis = match (raw, self.genesis.resolve()?) { + (true, Genesis::RuntimeGenesisConfigPatch(patch)) => { + let storage = RuntimeCaller::new(&self.code[..]).get_storage_for_patch(patch)?; + RawGenesis::from(storage) + }, + (true, Genesis::RuntimeGenesisConfig(config)) => { + let storage = RuntimeCaller::new(&self.code[..]).get_storage_for_config(config)?; + RawGenesis::from(storage) + }, + #[allow(deprecated)] (true, Genesis::Runtime(g)) => { let storage = g.build_storage()?; - let top = - storage.top.into_iter().map(|(k, v)| (StorageKey(k), StorageData(v))).collect(); - let children_default = storage - .children_default - .into_iter() - .map(|(sk, child)| { - ( - StorageKey(sk), - child - .data - .into_iter() - .map(|(k, v)| (StorageKey(k), StorageData(v))) - .collect(), - ) - }) - .collect(); - - Genesis::Raw(RawGenesis { top, children_default }) + RawGenesis::from(storage) }, - (_, genesis) => genesis, + (true, Genesis::Raw(raw)) => raw, + + (_, genesis) => + return Ok(ChainSpecJsonContainer { + client_spec: self.client_spec.clone(), + genesis, + code: self.code.clone(), + }), }; - Ok(JsonContainer { client_spec: self.client_spec.clone(), genesis }) + + if !self.code.is_empty() { + raw_genesis.top.insert( + StorageKey(sp_core::storage::well_known_keys::CODE.to_vec()), + StorageData(self.code.clone()), + ); + } + + Ok(ChainSpecJsonContainer { + client_spec: self.client_spec.clone(), + genesis: Genesis::Raw(raw_genesis), + code: vec![], + }) } - /// Dump to json string. + /// Dump the chain specification to JSON string. + /// + /// During conversion to `raw` format, the `ChainSpec::code` field will be removed and placed + /// into `RawGenesis` as `genesis::top::raw::0x3a636f6465` (which is + /// [`sp_core::storage::well_known_keys::CODE`]). If the spec is already in `raw` format, and + /// contains `genesis::top::raw::0x3a636f6465` field it will be updated with content of `code` + /// field (if present). pub fn as_json(&self, raw: bool) -> Result { let container = self.json_container(raw)?; json::to_string_pretty(&container).map_err(|e| format!("Error generating spec json: {}", e)) @@ -445,6 +699,11 @@ where #[cfg(test)] mod tests { use super::*; + use serde_json::{from_str, json, Value}; + use sp_application_crypto::Ss58Codec; + use sp_core::storage::well_known_keys; + use sp_keyring::AccountKeyring; + use std::collections::VecDeque; #[derive(Debug, Serialize, Deserialize)] struct Genesis(BTreeMap); @@ -536,4 +795,292 @@ mod tests { ); } } + + macro_rules! json_path { + [ $($x:expr),+ ] => { + VecDeque::::from([$($x),+].map(String::from)) + }; + } + + /// The `fun` will be called with the value at `path`. + /// + /// If exists, the value at given `path` will be passed to the `fun` and the result of `fun` + /// call will be returned. Otherwise false is returned. + /// `path` will be modified. + /// + /// # Examples + /// ``` + /// use serde_json::{from_str, json, Value}; + /// let doc = json!({"a":{"b":{"c":"5"}}}); + /// let mut path = ["a", "b", "c"].map(String::from).into(); + /// assert!(json_eval_value_at_key(&doc, &mut path, &|v| { assert_eq!(v,"5"); true })); + /// ``` + pub fn json_eval_value_at_key( + doc: &Value, + path: &mut VecDeque, + fun: &dyn Fn(&Value) -> bool, + ) -> bool { + if path.len() == 1 { + doc.as_object().map_or(false, |o| o.get(&path[0]).map_or(false, |v| fun(v))) + } else { + let key = path.pop_front().unwrap(); + doc.as_object().map_or(false, |o| { + o.get(&key).map_or(false, |v| json_eval_value_at_key(v, path, fun)) + }) + } + } + + fn json_contains_path(doc: &Value, path: &mut VecDeque) -> bool { + json_eval_value_at_key(doc, path, &|_| true) + } + + #[test] + // some tests for json path utils + fn test_json_eval_value_at_key() { + let doc = json!({"a":{"b1":"20","b":{"c":{"d":"10"}}}}); + + assert!(json_eval_value_at_key(&doc, &mut json_path!["a", "b1"], &|v| { *v == "20" })); + assert!(json_eval_value_at_key(&doc, &mut json_path!["a", "b", "c", "d"], &|v| { + *v == "10" + })); + assert!(!json_eval_value_at_key(&doc, &mut json_path!["a", "c", "d"], &|_| { true })); + assert!(!json_eval_value_at_key(&doc, &mut json_path!["d"], &|_| { true })); + + assert!(json_contains_path(&doc, &mut json_path!["a", "b1"])); + assert!(json_contains_path(&doc, &mut json_path!["a", "b"])); + assert!(json_contains_path(&doc, &mut json_path!["a", "b", "c"])); + assert!(json_contains_path(&doc, &mut json_path!["a", "b", "c", "d"])); + assert!(!json_contains_path(&doc, &mut json_path!["a", "b", "c", "d", "e"])); + assert!(!json_contains_path(&doc, &mut json_path!["a", "b", "b1"])); + assert!(!json_contains_path(&doc, &mut json_path!["d"])); + } + + fn zeroize_code_key_in_json(encoded: bool, json: &str) -> Value { + let mut json = from_str::(json).unwrap(); + let (zeroing_patch, mut path) = if encoded { + ( + json!({"genesis":{"raw":{"top":{"0x3a636f6465":"0x0"}}}}), + json_path!["genesis", "raw", "top", "0x3a636f6465"], + ) + } else { + (json!({"code":"0x0"}), json_path!["code"]) + }; + assert!(json_contains_path(&json, &mut path)); + json_patch::merge(&mut json, &zeroing_patch); + json + } + + #[test] + fn generate_chain_spec_with_patch_works() { + let output: ChainSpec<()> = ChainSpecBuilder::new() + .with_name("TestName") + .with_id("test_id") + .with_extensions(Default::default()) + .with_chain_type(ChainType::Local) + .with_code(substrate_test_runtime::wasm_binary_unwrap().into()) + .with_genesis_config_patch(json!({ + "babe": { + "epochConfig": { + "c": [ + 7, + 10 + ], + "allowed_slots": "PrimaryAndSecondaryPlainSlots" + } + }, + "substrateTest": { + "authorities": [ + AccountKeyring::Ferdie.public().to_ss58check(), + AccountKeyring::Alice.public().to_ss58check() + ], + } + })) + .build(); + + let actual = output.as_json(false).unwrap(); + let actual_raw = output.as_json(true).unwrap(); + + let expected = + from_str::(include_str!("../res/substrate_test_runtime_from_patch.json")) + .unwrap(); + let expected_raw = + from_str::(include_str!("../res/substrate_test_runtime_from_patch__raw.json")) + .unwrap(); + + //wasm blob may change overtime so let's zero it. Also ensure it is there: + let actual = zeroize_code_key_in_json(false, actual.as_str()); + let actual_raw = zeroize_code_key_in_json(true, actual_raw.as_str()); + + assert_eq!(actual, expected); + assert_eq!(actual_raw, expected_raw); + } + + #[test] + fn generate_chain_spec_with_full_config_works() { + let j = include_str!("../../../test-utils/runtime/res/default_genesis_config.json"); + let output: ChainSpec<()> = ChainSpecBuilder::new() + .with_name("TestName") + .with_id("test_id") + .with_extensions(Default::default()) + .with_chain_type(ChainType::Local) + .with_code(substrate_test_runtime::wasm_binary_unwrap().into()) + .with_genesis_config(from_str(j).unwrap()) + .build(); + + let actual = output.as_json(false).unwrap(); + let actual_raw = output.as_json(true).unwrap(); + + let expected = + from_str::(include_str!("../res/substrate_test_runtime_from_config.json")) + .unwrap(); + let expected_raw = + from_str::(include_str!("../res/substrate_test_runtime_from_config__raw.json")) + .unwrap(); + + //wasm blob may change overtime so let's zero it. Also ensure it is there: + let actual = zeroize_code_key_in_json(false, actual.as_str()); + let actual_raw = zeroize_code_key_in_json(true, actual_raw.as_str()); + + assert_eq!(actual, expected); + assert_eq!(actual_raw, expected_raw); + } + + #[test] + fn chain_spec_as_json_fails_with_invalid_config() { + let j = + include_str!("../../../test-utils/runtime/res/default_genesis_config_invalid_2.json"); + let output: ChainSpec<()> = ChainSpecBuilder::new() + .with_name("TestName") + .with_id("test_id") + .with_extensions(Default::default()) + .with_chain_type(ChainType::Local) + .with_code(substrate_test_runtime::wasm_binary_unwrap().into()) + .with_genesis_config(from_str(j).unwrap()) + .build(); + + assert_eq!( + output.as_json(true), + Err("Invalid JSON blob: unknown field `babex`, expected one of `system`, `babe`, `substrateTest`, `balances` at line 1 column 8".to_string()) + ); + } + + #[test] + fn chain_spec_as_json_fails_with_invalid_patch() { + let output: ChainSpec<()> = ChainSpecBuilder::new() + .with_name("TestName") + .with_id("test_id") + .with_extensions(Default::default()) + .with_chain_type(ChainType::Local) + .with_code(substrate_test_runtime::wasm_binary_unwrap().into()) + .with_genesis_config_patch(json!({ + "invalid_pallet": {}, + "substrateTest": { + "authorities": [ + AccountKeyring::Ferdie.public().to_ss58check(), + AccountKeyring::Alice.public().to_ss58check() + ], + } + })) + .build(); + + assert!(output.as_json(true).unwrap_err().contains("Invalid JSON blob: unknown field `invalid_pallet`, expected one of `system`, `babe`, `substrateTest`, `balances`")); + } + + #[test] + fn check_if_code_is_valid_for_raw_without_code() { + let spec = ChainSpec::<()>::from_json_bytes(Cow::Owned( + include_bytes!("../res/raw_no_code.json").to_vec(), + )) + .unwrap(); + + let j = from_str::(&spec.as_json(true).unwrap()).unwrap(); + + assert!(json_eval_value_at_key( + &j, + &mut json_path!["genesis", "raw", "top", "0x3a636f6465"], + &|v| { *v == "0x010101" } + )); + assert!(!json_contains_path(&j, &mut json_path!["code"])); + } + + #[test] + fn check_if_code_is_removed_from_raw_with_encoded() { + let spec = ChainSpec::<()>::from_json_bytes(Cow::Owned( + include_bytes!("../res/raw_with_code.json").to_vec(), + )) + .unwrap(); + + let j = from_str::(&spec.as_json(true).unwrap()).unwrap(); + + assert!(json_eval_value_at_key( + &j, + &mut json_path!["genesis", "raw", "top", "0x3a636f6465"], + &|v| { *v == "0x060708" } + )); + + assert!(!json_contains_path(&j, &mut json_path!["code"])); + } + + #[test] + fn check_if_code_is_removed_from_raw_without_encoded() { + let spec = ChainSpec::<()>::from_json_bytes(Cow::Owned( + include_bytes!("../res/raw_with_code_no_encoded.json").to_vec(), + )) + .unwrap(); + + let j = from_str::(&spec.as_json(true).unwrap()).unwrap(); + + assert!(json_eval_value_at_key( + &j, + &mut json_path!["genesis", "raw", "top", "0x3a636f6465"], + &|v| { *v == "0x060708" } + )); + + assert!(!json_contains_path(&j, &mut json_path!["code"])); + } + + #[test] + fn check_code_in_assimilated_storage_for_raw_with_encoded() { + let spec = ChainSpec::<()>::from_json_bytes(Cow::Owned( + include_bytes!("../res/raw_with_code.json").to_vec(), + )) + .unwrap(); + + let storage = spec.build_storage().unwrap(); + assert!(storage + .top + .get(&well_known_keys::CODE.to_vec()) + .map(|v| *v == vec![6, 7, 8]) + .unwrap()) + } + + #[test] + fn check_code_in_assimilated_storage_for_raw_without_encoded() { + let spec = ChainSpec::<()>::from_json_bytes(Cow::Owned( + include_bytes!("../res/raw_with_code_no_encoded.json").to_vec(), + )) + .unwrap(); + + let storage = spec.build_storage().unwrap(); + assert!(storage + .top + .get(&well_known_keys::CODE.to_vec()) + .map(|v| *v == vec![6, 7, 8]) + .unwrap()) + } + + #[test] + fn check_code_in_assimilated_storage_for_raw_without_code() { + let spec = ChainSpec::<()>::from_json_bytes(Cow::Owned( + include_bytes!("../res/raw_no_code.json").to_vec(), + )) + .unwrap(); + + let storage = spec.build_storage().unwrap(); + assert!(storage + .top + .get(&well_known_keys::CODE.to_vec()) + .map(|v| *v == vec![1, 1, 1]) + .unwrap()) + } } diff --git a/substrate/client/chain-spec/src/genesis.rs b/substrate/client/chain-spec/src/genesis_block.rs similarity index 100% rename from substrate/client/chain-spec/src/genesis.rs rename to substrate/client/chain-spec/src/genesis_block.rs diff --git a/substrate/client/chain-spec/src/genesis_config_builder.rs b/substrate/client/chain-spec/src/genesis_config_builder.rs new file mode 100644 index 000000000000..ddd9293d4002 --- /dev/null +++ b/substrate/client/chain-spec/src/genesis_config_builder.rs @@ -0,0 +1,178 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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 this program. If not, see . + +//! A helper module for calling the GenesisBuilder API from arbitrary runtime wasm blobs. + +use codec::{Decode, Encode}; +use sc_executor::{error::Result, WasmExecutor}; +use serde_json::{from_slice, Value}; +use sp_core::{ + storage::Storage, + traits::{CallContext, CodeExecutor, Externalities, FetchRuntimeCode, RuntimeCode}, +}; +use sp_genesis_builder::Result as BuildResult; +use sp_state_machine::BasicExternalities; +use std::borrow::Cow; + +/// A utility that facilitates calling the GenesisBuilder API from the runtime wasm code blob. +pub struct GenesisConfigBuilderRuntimeCaller<'a> { + code: Cow<'a, [u8]>, + code_hash: Vec, + executor: WasmExecutor, +} + +impl<'a> FetchRuntimeCode for GenesisConfigBuilderRuntimeCaller<'a> { + fn fetch_runtime_code(&self) -> Option> { + Some(self.code.as_ref().into()) + } +} + +impl<'a> GenesisConfigBuilderRuntimeCaller<'a> { + /// Creates new instance using the provided code blob. + pub fn new(code: &'a [u8]) -> Self { + GenesisConfigBuilderRuntimeCaller { + code: code.into(), + code_hash: sp_core::blake2_256(&code).to_vec(), + executor: WasmExecutor::::builder() + .with_allow_missing_host_functions(true) + .build(), + } + } + + fn call(&self, ext: &mut dyn Externalities, method: &str, data: &[u8]) -> Result> { + self.executor + .call( + ext, + &RuntimeCode { heap_pages: None, code_fetcher: self, hash: self.code_hash.clone() }, + method, + data, + false, + CallContext::Offchain, + ) + .0 + } +} + +impl<'a> GenesisConfigBuilderRuntimeCaller<'a> { + /// Calls [`sp_genesis_builder::GenesisBuilder::create_default_config`] provided by runtime. + pub fn get_default_config(&self) -> core::result::Result { + let mut t = BasicExternalities::new_empty(); + let call_result = self + .call(&mut t, "GenesisBuilder_create_default_config", &vec![]) + .map_err(|e| format!("wasm call error {e}"))?; + let default_config = Vec::::decode(&mut &call_result[..]) + .map_err(|e| format!("scale codec error: {e}"))?; + Ok(from_slice(&default_config[..]).expect("returned value is json. qed.")) + } + + /// Calls [`sp_genesis_builder::GenesisBuilder::build_config`] provided by runtime. + pub fn get_storage_for_config(&self, config: Value) -> core::result::Result { + let mut ext = BasicExternalities::new_empty(); + + let call_result = self + .call(&mut ext, "GenesisBuilder_build_config", &config.to_string().encode()) + .map_err(|e| format!("wasm call error {e}"))?; + + BuildResult::decode(&mut &call_result[..]) + .map_err(|e| format!("scale codec error: {e}"))??; + + Ok(ext.into_storages()) + } + + /// Patch default `GenesisConfig` using given JSON patch and store it in the storage. + /// + /// This function generates the `GenesisConfig` for the runtime by applying a provided JSON + /// patch. The patch modifies the default `GenesisConfig` allowing customization of the specific + /// keys. The resulting `GenesisConfig` is then deserialized from the patched JSON + /// representation and stored in the storage. + /// + /// If the provided JSON patch is incorrect or the deserialization fails the error will be + /// returned. + /// + /// The patching process modifies the default `GenesisConfig` according to the following rules: + /// 1. Existing keys in the default configuration will be overridden by the corresponding values + /// in the patch. + /// 2. If a key exists in the patch but not in the default configuration, it will be added to + /// the resulting `GenesisConfig`. + /// 3. Keys in the default configuration that have null values in the patch will be removed from + /// the resulting `GenesisConfig`. This is helpful for changing enum variant value. + /// + /// Please note that the patch may contain full `GenesisConfig`. + pub fn get_storage_for_patch(&self, patch: Value) -> core::result::Result { + let mut config = self.get_default_config()?; + json_patch::merge(&mut config, &patch); + self.get_storage_for_config(config) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use serde_json::{from_str, json}; + pub use sp_consensus_babe::{AllowedSlots, BabeEpochConfiguration, Slot}; + + #[test] + fn get_default_config_works() { + let config = + GenesisConfigBuilderRuntimeCaller::new(substrate_test_runtime::wasm_binary_unwrap()) + .get_default_config() + .unwrap(); + let expected = r#"{"system":{},"babe":{"authorities":[],"epochConfig":null},"substrateTest":{"authorities":[]},"balances":{"balances":[]}}"#; + assert_eq!(from_str::(expected).unwrap(), config); + } + + #[test] + fn get_storage_for_patch_works() { + let patch = json!({ + "babe": { + "epochConfig": { + "c": [ + 69, + 696 + ], + "allowed_slots": "PrimaryAndSecondaryPlainSlots" + } + }, + }); + + let storage = + GenesisConfigBuilderRuntimeCaller::new(substrate_test_runtime::wasm_binary_unwrap()) + .get_storage_for_patch(patch) + .unwrap(); + + //Babe|Authorities + let value: Vec = storage + .top + .get( + &array_bytes::hex2bytes( + "1cb6f36e027abb2091cfb5110ab5087fdc6b171b77304263c292cc3ea5ed31ef", + ) + .unwrap(), + ) + .unwrap() + .clone(); + + assert_eq!( + BabeEpochConfiguration::decode(&mut &value[..]).unwrap(), + BabeEpochConfiguration { + c: (69, 696), + allowed_slots: AllowedSlots::PrimaryAndSecondaryPlainSlots + } + ); + } +} diff --git a/substrate/client/chain-spec/src/lib.rs b/substrate/client/chain-spec/src/lib.rs index 341c5f28e4a4..5c78f98c2af7 100644 --- a/substrate/client/chain-spec/src/lib.rs +++ b/substrate/client/chain-spec/src/lib.rs @@ -157,16 +157,23 @@ //! //! // The genesis declaration of the chain. //! // -//! // `runtime`, `raw`, `stateRootHash` denote the type of the genesis declaration. +//! // `runtime`, `runtimeGenesisConfig`, `runtimeGenesisConfigPatch`, `raw`, `stateRootHash` denote +//! // the type of the genesis declaration. //! // //! // These declarations are in the following formats: //! // - `runtime` is a `json` object that can be parsed by a compatible `GenesisConfig`. This //! // `GenesisConfig` is declared by a runtime and opaque to the node. +//! // - `runtimeGenesisConfig` is a json object that can be parsed by compatible runtime. It is a +//! // json object the represents full `GenesisConfig` of the runtime. Similar to `runtime`. +//! // - `runtimeGenesisConfigPatch` is a json object that can be parsed by compatible runtime. It +//! // contains a patch to default runtime's `GenesisConfig`. It is opaque to the node. //! // - `raw` is a `json` object with two fields `top` and `children_default`. Each of these //! // fields is a map of `key => value`. These key/value pairs represent the genesis storage. //! // - `stateRootHash` is a single hex encoded hash that represents the genesis hash. The hash //! // type depends on the hash used by the chain. //! // +//! // Runtime must support `GenesisBuilder` API in order to use `runtimeGenesisConfigPatch` or +//! // `runtimeGenesisConfig`. //! "genesis": { "runtime": {} }, //! //! /// Optional map of `block_number` to `wasm_code`. @@ -189,15 +196,17 @@ mod chain_spec; mod extension; -mod genesis; +mod genesis_block; +mod genesis_config_builder; pub use self::{ - chain_spec::{ChainSpec as GenericChainSpec, NoExtension}, + chain_spec::{ChainSpec as GenericChainSpec, ChainSpecBuilder, NoExtension}, extension::{get_extension, get_extension_mut, Extension, Fork, Forks, GetExtension, Group}, - genesis::{ + genesis_block::{ construct_genesis_block, resolve_state_version_from_wasm, BuildGenesisBlock, GenesisBlockBuilder, }, + genesis_config_builder::GenesisConfigBuilderRuntimeCaller, }; pub use sc_chain_spec_derive::{ChainSpecExtension, ChainSpecGroup}; diff --git a/substrate/client/cli/src/commands/insert_key.rs b/substrate/client/cli/src/commands/insert_key.rs index 732d874319a8..3617b52aa6a1 100644 --- a/substrate/client/cli/src/commands/insert_key.rs +++ b/substrate/client/cli/src/commands/insert_key.rs @@ -126,18 +126,16 @@ mod tests { } fn load_spec(&self, _: &str) -> std::result::Result, String> { - Ok(Box::new(GenericChainSpec::from_genesis( - "test", - "test_id", - ChainType::Development, - || unimplemented!("Not required in tests"), - Vec::new(), - None, - None, - None, - None, - NoExtension::None, - ))) + Ok(Box::new( + GenericChainSpec::<()>::builder() + .with_name("test") + .with_id("test_id") + .with_extensions(NoExtension::None) + .with_chain_type(ChainType::Development) + .with_code(Default::default()) + .with_genesis_config_patch(Default::default()) + .build(), + )) } } diff --git a/substrate/client/cli/src/runner.rs b/substrate/client/cli/src/runner.rs index 59f53200a192..e17a7d669fa5 100644 --- a/substrate/client/cli/src/runner.rs +++ b/substrate/client/cli/src/runner.rs @@ -251,18 +251,16 @@ mod tests { trie_cache_maximum_size: None, state_pruning: None, blocks_pruning: sc_client_db::BlocksPruning::KeepAll, - chain_spec: Box::new(GenericChainSpec::from_genesis( - "test", - "test_id", - ChainType::Development, - || unimplemented!("Not required in tests"), - Vec::new(), - None, - None, - None, - None, - NoExtension::None, - )), + chain_spec: Box::new( + GenericChainSpec::<()>::builder() + .with_name("test") + .with_id("test_id") + .with_extensions(NoExtension::None) + .with_chain_type(ChainType::Development) + .with_code(Default::default()) + .with_genesis_config_patch(Default::default()) + .build(), + ), wasm_method: Default::default(), wasm_runtime_overrides: None, rpc_addr: None, diff --git a/substrate/frame/system/src/lib.rs b/substrate/frame/system/src/lib.rs index 84b6dc031457..b673ed2cf673 100644 --- a/substrate/frame/system/src/lib.rs +++ b/substrate/frame/system/src/lib.rs @@ -676,8 +676,6 @@ pub mod pallet { #[derive(frame_support::DefaultNoBound)] #[pallet::genesis_config] pub struct GenesisConfig { - #[serde(with = "sp_core::bytes")] - pub code: Vec, #[serde(skip)] pub _config: sp_std::marker::PhantomData, } @@ -691,7 +689,6 @@ pub mod pallet { >::put(true); >::put(true); - sp_io::storage::set(well_known_keys::CODE, &self.code); sp_io::storage::set(well_known_keys::EXTRINSIC_INDEX, &0u32.encode()); } } diff --git a/substrate/test-utils/runtime/Cargo.toml b/substrate/test-utils/runtime/Cargo.toml index 0a9406e8af91..6802a44b5279 100644 --- a/substrate/test-utils/runtime/Cargo.toml +++ b/substrate/test-utils/runtime/Cargo.toml @@ -48,8 +48,6 @@ sp-externalities = { path = "../../primitives/externalities", default-features = # 3rd party array-bytes = { version = "6.1", optional = true } log = { version = "0.4.17", default-features = false } -serde = { version = "1.0.163", features = ["alloc", "derive"], default-features = false } -serde_json = { version = "1.0.85", default-features = false, features = ["alloc"] } [dev-dependencies] futures = "0.3.21" @@ -60,6 +58,8 @@ sp-consensus = { path = "../../primitives/consensus/common" } substrate-test-runtime-client = { path = "client" } sp-tracing = { path = "../../primitives/tracing" } json-patch = { version = "1.0.0", default-features = false } +serde = { version = "1.0.163", features = ["alloc", "derive"], default-features = false } +serde_json = { version = "1.0.85", default-features = false, features = ["alloc"] } [build-dependencies] substrate-wasm-builder = { path = "../../utils/wasm-builder", optional = true } diff --git a/substrate/test-utils/runtime/src/test_json/README.md b/substrate/test-utils/runtime/res/README.md similarity index 100% rename from substrate/test-utils/runtime/src/test_json/README.md rename to substrate/test-utils/runtime/res/README.md diff --git a/substrate/test-utils/runtime/src/test_json/default_genesis_config.json b/substrate/test-utils/runtime/res/default_genesis_config.json similarity index 98% rename from substrate/test-utils/runtime/src/test_json/default_genesis_config.json rename to substrate/test-utils/runtime/res/default_genesis_config.json index b0218d417daa..95c7799a033d 100644 --- a/substrate/test-utils/runtime/src/test_json/default_genesis_config.json +++ b/substrate/test-utils/runtime/res/default_genesis_config.json @@ -1,7 +1,5 @@ { - "system": { - "code": "0x52" - }, + "system": {}, "babe": { "authorities": [ [ diff --git a/substrate/test-utils/runtime/src/test_json/default_genesis_config_incomplete.json b/substrate/test-utils/runtime/res/default_genesis_config_incomplete.json similarity index 98% rename from substrate/test-utils/runtime/src/test_json/default_genesis_config_incomplete.json rename to substrate/test-utils/runtime/res/default_genesis_config_incomplete.json index e25730ee11cf..510ed87c93c5 100644 --- a/substrate/test-utils/runtime/src/test_json/default_genesis_config_incomplete.json +++ b/substrate/test-utils/runtime/res/default_genesis_config_incomplete.json @@ -1,7 +1,5 @@ { - "system": { - "code": "0x52" - }, + "system": {}, "babe": { "epochConfig": { "c": [ diff --git a/substrate/test-utils/runtime/src/test_json/default_genesis_config_invalid.json b/substrate/test-utils/runtime/res/default_genesis_config_invalid.json similarity index 98% rename from substrate/test-utils/runtime/src/test_json/default_genesis_config_invalid.json rename to substrate/test-utils/runtime/res/default_genesis_config_invalid.json index 00550efaeec9..f8e06f91d665 100644 --- a/substrate/test-utils/runtime/src/test_json/default_genesis_config_invalid.json +++ b/substrate/test-utils/runtime/res/default_genesis_config_invalid.json @@ -1,7 +1,5 @@ { - "system": { - "code": "0x52" - }, + "system": {}, "babe": { "renamed_authorities": [ [ diff --git a/substrate/test-utils/runtime/res/default_genesis_config_invalid_2.json b/substrate/test-utils/runtime/res/default_genesis_config_invalid_2.json new file mode 100644 index 000000000000..a1345542bcda --- /dev/null +++ b/substrate/test-utils/runtime/res/default_genesis_config_invalid_2.json @@ -0,0 +1,113 @@ +{ + "system": {}, + "babex": { + "authorities": [ + [ + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + 1 + ], + [ + "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", + 1 + ], + [ + "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y", + 1 + ] + ], + "epochConfig": { + "c": [ + 3, + 10 + ], + "allowed_slots": "PrimaryAndSecondaryPlainSlots" + } + }, + "substrateTest": { + "authorities": [ + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", + "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y" + ] + }, + "balances": { + "balances": [ + [ + "5D34dL5prEUaGNQtPPZ3yN5Y6BnkfXunKXXz6fo7ZJbLwRRH", + 100000000000000000 + ], + [ + "5GBNeWRhZc2jXu7D55rBimKYDk8PGk8itRYFTPfC8RJLKG5o", + 100000000000000000 + ], + [ + "5Dfis6XL8J2P6JHUnUtArnFWndn62SydeP8ee8sG2ky9nfm9", + 100000000000000000 + ], + [ + "5F4H97f7nQovyrbiq4ZetaaviNwThSVcFobcA5aGab6167dK", + 100000000000000000 + ], + [ + "5DiDShBWa1fQx6gLzpf3SFBhMinCoyvHM1BWjPNsmXS8hkrW", + 100000000000000000 + ], + [ + "5EFb84yH9tpcFuiKUcsmdoF7xeeY3ajG1ZLQimxQoFt9HMKR", + 100000000000000000 + ], + [ + "5DZLHESsfGrJ5YzT3HuRPXsSNb589xQ4Unubh1mYLodzKdVY", + 100000000000000000 + ], + [ + "5GHJzqvG6tXnngCpG7B12qjUvbo5e4e9z8Xjidk3CQZHxTPZ", + 100000000000000000 + ], + [ + "5CUnSsgAyLND3bxxnfNhgWXSe9Wn676JzLpGLgyJv858qhoX", + 100000000000000000 + ], + [ + "5CVKn7HAZW1Ky4r7Vkgsr7VEW88C2sHgUNDiwHY9Ct2hjU8q", + 100000000000000000 + ], + [ + "5H673aukQ4PeDe1U2nuv1bi32xDEziimh3PZz7hDdYUB7TNz", + 100000000000000000 + ], + [ + "5HTe9L15LJryjUAt1jZXZCBPnzbbGnpvFwbjE3NwCWaAqovf", + 100000000000000000 + ], + [ + "5D7LFzGpMwHPyDBavkRbWSKWTtJhCaPPZ379wWLT23bJwXJz", + 100000000000000000 + ], + [ + "5CLepMARnEgtVR1EkUuJVUvKh97gzergpSxUU3yKGx1v6EwC", + 100000000000000000 + ], + [ + "5Chb2UhfvZpmjjEziHbFbotM4quX32ZscRV6QJBt1rUKzz51", + 100000000000000000 + ], + [ + "5HmRp3i3ZZk7xsAvbi8hyXVP6whSMnBJGebVC4FsiZVhx52e", + 100000000000000000 + ], + [ + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + 100000000000000000 + ], + [ + "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", + 100000000000000000 + ], + [ + "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y", + 100000000000000000 + ] + ] + } +} diff --git a/substrate/test-utils/runtime/src/genesismap.rs b/substrate/test-utils/runtime/src/genesismap.rs index 8a4d6dbe4a71..5ed9c8a64588 100644 --- a/substrate/test-utils/runtime/src/genesismap.rs +++ b/substrate/test-utils/runtime/src/genesismap.rs @@ -117,10 +117,7 @@ impl GenesisStorageBuilder { .collect(); RuntimeGenesisConfig { - system: frame_system::GenesisConfig { - code: self.wasm_code.clone().unwrap_or(wasm_binary_unwrap().to_vec()), - ..Default::default() - }, + system: Default::default(), babe: pallet_babe::GenesisConfig { authorities: authorities_sr25519 .clone() @@ -149,6 +146,11 @@ impl GenesisStorageBuilder { storage.top.insert(well_known_keys::HEAP_PAGES.into(), heap_pages.encode()); } + storage.top.insert( + well_known_keys::CODE.into(), + self.wasm_code.clone().unwrap_or(wasm_binary_unwrap().to_vec()), + ); + storage.top.extend(self.extra_storage.top.clone()); storage.children_default.extend(self.extra_storage.children_default.clone()); diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index b116c8556815..9ad3ec08f0b6 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -1235,7 +1235,7 @@ mod tests { #[test] fn build_minimal_genesis_config_works() { sp_tracing::try_init_simple(); - let default_minimal_json = r#"{"system":{"code":"0x"},"babe":{"authorities":[],"epochConfig":{"c": [ 3, 10 ],"allowed_slots":"PrimaryAndSecondaryPlainSlots"}},"substrateTest":{"authorities":[]},"balances":{"balances":[]}}"#; + let default_minimal_json = r#"{"system":{},"babe":{"authorities":[],"epochConfig":{"c": [ 3, 10 ],"allowed_slots":"PrimaryAndSecondaryPlainSlots"}},"substrateTest":{"authorities":[]},"balances":{"balances":[]}}"#; let mut t = BasicExternalities::new_empty(); executor_call(&mut t, "GenesisBuilder_build_config", &default_minimal_json.encode()) @@ -1262,8 +1262,6 @@ mod tests { // System|LastRuntimeUpgrade "26aa394eea5630e07c48ae0c9558cef7f9cce9c888469bb1a0dceaa129672ef8", - // :code - "3a636f6465", // :extrinsic_index "3a65787472696e7369635f696e646578", // Balances|TotalIssuance @@ -1292,35 +1290,55 @@ mod tests { let r = Vec::::decode(&mut &r[..]).unwrap(); let json = String::from_utf8(r.into()).expect("returned value is json. qed."); - let expected = r#"{"system":{"code":"0x"},"babe":{"authorities":[],"epochConfig":null},"substrateTest":{"authorities":[]},"balances":{"balances":[]}}"#; + let expected = r#"{"system":{},"babe":{"authorities":[],"epochConfig":null},"substrateTest":{"authorities":[]},"balances":{"balances":[]}}"#; assert_eq!(expected.to_string(), json); } #[test] fn build_config_from_json_works() { sp_tracing::try_init_simple(); - let j = include_str!("test_json/default_genesis_config.json"); + let j = include_str!("../res/default_genesis_config.json"); let mut t = BasicExternalities::new_empty(); let r = executor_call(&mut t, "GenesisBuilder_build_config", &j.encode()).unwrap(); let r = BuildResult::decode(&mut &r[..]); assert!(r.is_ok()); - let keys = t.into_storages().top.keys().cloned().map(hex).collect::>(); + let mut keys = t.into_storages().top.keys().cloned().map(hex).collect::>(); + + // following keys are not placed during `::build` + // process, add them `keys` to assert against known keys. + keys.push(hex(b":code")); + keys.sort(); + assert_eq!(keys, storage_key_generator::get_expected_storage_hashed_keys(false)); } #[test] fn build_config_from_invalid_json_fails() { sp_tracing::try_init_simple(); - let j = include_str!("test_json/default_genesis_config_invalid.json"); + let j = include_str!("../res/default_genesis_config_invalid.json"); let mut t = BasicExternalities::new_empty(); let r = executor_call(&mut t, "GenesisBuilder_build_config", &j.encode()).unwrap(); let r = BuildResult::decode(&mut &r[..]).unwrap(); log::info!("result: {:#?}", r); assert_eq!(r, Err( sp_runtime::RuntimeString::Owned( - "Invalid JSON blob: unknown field `renamed_authorities`, expected `authorities` or `epochConfig` at line 6 column 25".to_string(), + "Invalid JSON blob: unknown field `renamed_authorities`, expected `authorities` or `epochConfig` at line 4 column 25".to_string(), + )) + ); + } + + #[test] + fn build_config_from_invalid_json_fails_2() { + sp_tracing::try_init_simple(); + let j = include_str!("../res/default_genesis_config_invalid_2.json"); + let mut t = BasicExternalities::new_empty(); + let r = executor_call(&mut t, "GenesisBuilder_build_config", &j.encode()).unwrap(); + let r = BuildResult::decode(&mut &r[..]).unwrap(); + assert_eq!(r, Err( + sp_runtime::RuntimeString::Owned( + "Invalid JSON blob: unknown field `babex`, expected one of `system`, `babe`, `substrateTest`, `balances` at line 3 column 9".to_string(), )) ); } @@ -1328,7 +1346,7 @@ mod tests { #[test] fn build_config_from_incomplete_json_fails() { sp_tracing::try_init_simple(); - let j = include_str!("test_json/default_genesis_config_incomplete.json"); + let j = include_str!("../res/default_genesis_config_incomplete.json"); let mut t = BasicExternalities::new_empty(); let r = executor_call(&mut t, "GenesisBuilder_build_config", &j.encode()).unwrap(); @@ -1337,7 +1355,7 @@ mod tests { assert_eq!( r, Err(sp_runtime::RuntimeString::Owned( - "Invalid JSON blob: missing field `authorities` at line 13 column 3" + "Invalid JSON blob: missing field `authorities` at line 11 column 3" .to_string() )) ); @@ -1436,10 +1454,6 @@ mod tests { ); assert_eq!(u64::decode(&mut &value[..]).unwrap(), 0); - // :code - let value: Vec = get_from_storage("3a636f6465"); - assert!(Vec::::decode(&mut &value[..]).is_err()); - //System|ParentHash let value: Vec = get_from_storage( "26aa394eea5630e07c48ae0c9558cef78a42f33323cb5ced3b44dd825fda9fcc", From 037c5ae0863a8efa5ade7f72eecca5f8abd046fa Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 28 Aug 2023 18:14:37 +0200 Subject: [PATCH 02/98] polkadot: chain-specs getting ready for non-native world - all references to `RuntimeGenesisConfig` in node/service are removed, - `RococoGenesisExt` is removed. It was the hack to allow overwriting `EpochDurationInBlocks`. Removal of `RococGenesisExt` prevents from manipulating the state to change the runtime constants, what allows to keep metadata const. - all `(kusama|polkadot|versi|rococo|wococo)_(staging|dev)_genesis_config` functions now return the JSON patch for default runtime `GenesisConfig`, - `ChainSpecBuilder` is used, ChainSpec::from_genesis is removed, - rococo-runtime changes: -- Explicit building of fast-runtime version of rococo-runtime is no longer done. -- Environment variables which control the time::EpochDurationInBlocks value were added: `ROCOCO_FAST_RUNTIME` - enables the fast runtime version of runtime with default value of EpochDurationInBlocks set to 10. Value of env does not matter. `ROCOCO_EPOCH_DURATION` - enables the fast runtime version with provided value of EpochDurationInBlocks (epoch duration will be set to the value of env). Examples: - to build runtime for `versi_staging_testnet_config which had EpochDurationInBlocks set to 100: ``` ROCOCO_EPOCH_DURATION=100 cargo build -p rococo ``` - to build runtime for `versi_staging_testnet_config which had EpochDurationInBlocks set to 100: ``` ROCOCO_EPOCH_DURATION=100 cargo build -p rococo-runtime ``` - to build runtime for `wococo_development` ``` ROCOCO_EPOCH_DURATION=10 cargo build -p rococo-runtime or ROCOCO_FAST_RUNTIME=1 cargo build -p rococo-runtime ``` - ChainSpec: tests against legacy added --- polkadot/node/service/src/chain_spec.rs | 1109 +++++----- .../src/chain_spec/legacy_chain_spec.rs | 1907 +++++++++++++++++ polkadot/node/test/client/src/lib.rs | 2 +- polkadot/node/test/service/Cargo.toml | 2 +- polkadot/node/test/service/src/chain_spec.rs | 109 +- polkadot/runtime/common/src/lib.rs | 5 +- polkadot/runtime/kusama/Cargo.toml | 11 +- polkadot/runtime/kusama/build.rs | 15 +- polkadot/runtime/kusama/src/lib.rs | 14 + polkadot/runtime/polkadot/Cargo.toml | 11 +- polkadot/runtime/polkadot/build.rs | 15 +- polkadot/runtime/polkadot/src/lib.rs | 14 + polkadot/runtime/rococo/Cargo.toml | 4 +- polkadot/runtime/rococo/build.rs | 24 +- polkadot/runtime/rococo/constants/Cargo.toml | 3 + polkadot/runtime/rococo/constants/src/lib.rs | 4 +- polkadot/runtime/rococo/src/lib.rs | 14 +- polkadot/runtime/test-runtime/Cargo.toml | 2 + polkadot/runtime/test-runtime/src/lib.rs | 14 +- polkadot/runtime/westend/Cargo.toml | 2 + polkadot/runtime/westend/src/lib.rs | 14 +- 21 files changed, 2599 insertions(+), 696 deletions(-) create mode 100644 polkadot/node/service/src/chain_spec/legacy_chain_spec.rs diff --git a/polkadot/node/service/src/chain_spec.rs b/polkadot/node/service/src/chain_spec.rs index 1e5aaa807b81..44f8bc3a38df 100644 --- a/polkadot/node/service/src/chain_spec.rs +++ b/polkadot/node/service/src/chain_spec.rs @@ -105,7 +105,7 @@ pub struct Extensions { /// The `ChainSpec` parameterized for the polkadot runtime. #[cfg(feature = "polkadot-native")] -pub type PolkadotChainSpec = service::GenericChainSpec; +pub type PolkadotChainSpec = service::GenericChainSpec<(), Extensions>; // Dummy chain spec, in case when we don't have the native runtime. pub type DummyChainSpec = service::GenericChainSpec<(), Extensions>; @@ -116,7 +116,7 @@ pub type PolkadotChainSpec = DummyChainSpec; /// The `ChainSpec` parameterized for the kusama runtime. #[cfg(feature = "kusama-native")] -pub type KusamaChainSpec = service::GenericChainSpec; +pub type KusamaChainSpec = service::GenericChainSpec<(), Extensions>; /// The `ChainSpec` parameterized for the kusama runtime. // Dummy chain spec, but that is fine when we don't have the native runtime. @@ -125,7 +125,7 @@ pub type KusamaChainSpec = DummyChainSpec; /// The `ChainSpec` parameterized for the westend runtime. #[cfg(feature = "westend-native")] -pub type WestendChainSpec = service::GenericChainSpec; +pub type WestendChainSpec = service::GenericChainSpec<(), Extensions>; /// The `ChainSpec` parameterized for the westend runtime. // Dummy chain spec, but that is fine when we don't have the native runtime. @@ -134,42 +134,13 @@ pub type WestendChainSpec = DummyChainSpec; /// The `ChainSpec` parameterized for the rococo runtime. #[cfg(feature = "rococo-native")] -pub type RococoChainSpec = service::GenericChainSpec; - -/// The `ChainSpec` parameterized for the `versi` runtime. -/// -/// As of now `Versi` will just be a clone of `Rococo`, until we need it to differ. -pub type VersiChainSpec = RococoChainSpec; +pub type RococoChainSpec = service::GenericChainSpec<(), Extensions>; /// The `ChainSpec` parameterized for the rococo runtime. // Dummy chain spec, but that is fine when we don't have the native runtime. #[cfg(not(feature = "rococo-native"))] pub type RococoChainSpec = DummyChainSpec; -/// Extension for the Rococo genesis config to support a custom changes to the genesis state. -#[derive(serde::Serialize, serde::Deserialize)] -#[cfg(feature = "rococo-native")] -pub struct RococoGenesisExt { - /// The runtime genesis config. - runtime_genesis_config: rococo::RuntimeGenesisConfig, - /// The session length in blocks. - /// - /// If `None` is supplied, the default value is used. - session_length_in_blocks: Option, -} - -#[cfg(feature = "rococo-native")] -impl sp_runtime::BuildStorage for RococoGenesisExt { - fn assimilate_storage(&self, storage: &mut sp_core::storage::Storage) -> Result<(), String> { - sp_state_machine::BasicExternalities::execute_with_storage(storage, || { - if let Some(length) = self.session_length_in_blocks.as_ref() { - rococo_runtime_constants::time::EpochDurationInBlocks::set(length); - } - }); - self.runtime_genesis_config.assimilate_storage(storage) - } -} - pub fn polkadot_config() -> Result { PolkadotChainSpec::from_json_bytes(&include_bytes!("../chain-specs/polkadot.json")[..]) } @@ -330,7 +301,7 @@ fn rococo_session_keys( } #[cfg(feature = "westend-native")] -fn westend_staging_testnet_config_genesis(wasm_binary: &[u8]) -> westend::RuntimeGenesisConfig { +fn westend_staging_testnet_config_genesis() -> serde_json::Value { use hex_literal::hex; use sp_core::crypto::UncheckedInto; @@ -468,19 +439,16 @@ fn westend_staging_testnet_config_genesis(wasm_binary: &[u8]) -> westend::Runtim const ENDOWMENT: u128 = 1_000_000 * WND; const STASH: u128 = 100 * WND; - westend::RuntimeGenesisConfig { - system: westend::SystemConfig { code: wasm_binary.to_vec(), ..Default::default() }, - balances: westend::BalancesConfig { - balances: endowed_accounts + serde_json::json!({ + "balances": { + "balances": endowed_accounts .iter() .map(|k: &AccountId| (k.clone(), ENDOWMENT)) .chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH))) - .collect(), + .collect::>(), }, - beefy: Default::default(), - indices: westend::IndicesConfig { indices: vec![] }, - session: westend::SessionConfig { - keys: initial_authorities + "session": { + "keys": initial_authorities .iter() .map(|x| { ( @@ -499,48 +467,32 @@ fn westend_staging_testnet_config_genesis(wasm_binary: &[u8]) -> westend::Runtim }) .collect::>(), }, - staking: westend::StakingConfig { - validator_count: 50, - minimum_validator_count: 4, - stakers: initial_authorities + "staking": { + "validatorCount": 50, + "minimumValidatorCount": 4, + "stakers": initial_authorities .iter() - .map(|x| (x.0.clone(), x.0.clone(), STASH, westend::StakerStatus::Validator)) - .collect(), - invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(), - force_era: Forcing::ForceNone, - slash_reward_fraction: Perbill::from_percent(10), - ..Default::default() - }, - babe: westend::BabeConfig { - authorities: Default::default(), - epoch_config: Some(westend::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() + .map(|x| (x.0.clone(), x.0.clone(), STASH, westend::StakerStatus::::Validator)) + .collect::>(), + "invulnerables": initial_authorities.iter().map(|x| x.0.clone()).collect::>(), + "forceEra": Forcing::ForceNone, + "slashRewardFraction": Perbill::from_percent(10), }, - grandpa: Default::default(), - im_online: Default::default(), - authority_discovery: westend::AuthorityDiscoveryConfig { - keys: vec![], - ..Default::default() + "babe": { + "epochConfig": Some(westend::BABE_GENESIS_EPOCH_CONFIG), }, - vesting: westend::VestingConfig { vesting: vec![] }, - sudo: westend::SudoConfig { key: Some(endowed_accounts[0].clone()) }, - hrmp: Default::default(), - configuration: westend::ConfigurationConfig { - config: default_parachains_host_configuration(), + "sudo": { "key": Some(endowed_accounts[0].clone()) }, + "configuration": { + "config": default_parachains_host_configuration(), }, - paras: Default::default(), - registrar: westend_runtime::RegistrarConfig { - next_free_para_id: polkadot_primitives::LOWEST_PUBLIC_ID, - ..Default::default() + "registrar": { + "nextFreeParaId": polkadot_primitives::LOWEST_PUBLIC_ID, }, - xcm_pallet: Default::default(), - nomination_pools: Default::default(), - assigned_slots: Default::default(), - } + }) } #[cfg(feature = "kusama-native")] -fn kusama_staging_testnet_config_genesis(wasm_binary: &[u8]) -> kusama::RuntimeGenesisConfig { +fn kusama_staging_testnet_config_genesis() -> serde_json::Value { use hex_literal::hex; use sp_core::crypto::UncheckedInto; @@ -679,19 +631,16 @@ fn kusama_staging_testnet_config_genesis(wasm_binary: &[u8]) -> kusama::RuntimeG const ENDOWMENT: u128 = 1_000_000 * KSM; const STASH: u128 = 100 * KSM; - kusama::RuntimeGenesisConfig { - system: kusama::SystemConfig { code: wasm_binary.to_vec(), ..Default::default() }, - balances: kusama::BalancesConfig { - balances: endowed_accounts + serde_json::json!({ + "balances": { + "balances": endowed_accounts .iter() .map(|k: &AccountId| (k.clone(), ENDOWMENT)) .chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH))) - .collect(), + .collect::>(), }, - beefy: Default::default(), - indices: kusama::IndicesConfig { indices: vec![] }, - session: kusama::SessionConfig { - keys: initial_authorities + "session": { + "keys": initial_authorities .iter() .map(|x| { ( @@ -710,47 +659,28 @@ fn kusama_staging_testnet_config_genesis(wasm_binary: &[u8]) -> kusama::RuntimeG }) .collect::>(), }, - staking: kusama::StakingConfig { - validator_count: 50, - minimum_validator_count: 4, - stakers: initial_authorities + "staking": { + "validatorCount": 50, + "minimumValidatorCount": 4, + "stakers": initial_authorities .iter() - .map(|x| (x.0.clone(), x.0.clone(), STASH, kusama::StakerStatus::Validator)) - .collect(), - invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(), - force_era: Forcing::ForceNone, - slash_reward_fraction: Perbill::from_percent(10), - ..Default::default() - }, - babe: kusama::BabeConfig { - authorities: Default::default(), - epoch_config: Some(kusama::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() + .map(|x| (x.0.clone(), x.0.clone(), STASH, kusama::StakerStatus::::Validator)) + .collect::>(), + "invulnerables": initial_authorities.iter().map(|x| x.0.clone()).collect::>(), + "forceEra": Forcing::ForceNone, + "slashRewardFraction": Perbill::from_percent(10), }, - grandpa: Default::default(), - im_online: Default::default(), - authority_discovery: kusama::AuthorityDiscoveryConfig { - keys: vec![], - ..Default::default() + "babe": { + "epochConfig": Some(kusama::BABE_GENESIS_EPOCH_CONFIG), }, - claims: kusama::ClaimsConfig { claims: vec![], vesting: vec![] }, - vesting: kusama::VestingConfig { vesting: vec![] }, - treasury: Default::default(), - hrmp: Default::default(), - configuration: kusama::ConfigurationConfig { - config: default_parachains_host_configuration(), + "configuration": { + "config": default_parachains_host_configuration(), }, - paras: Default::default(), - xcm_pallet: Default::default(), - nomination_pools: Default::default(), - nis_counterpart_balances: Default::default(), - } + }) } #[cfg(feature = "rococo-native")] -fn rococo_staging_testnet_config_genesis( - wasm_binary: &[u8], -) -> rococo_runtime::RuntimeGenesisConfig { +fn rococo_staging_testnet_config_genesis() -> serde_json::Value { use hex_literal::hex; use sp_core::crypto::UncheckedInto; @@ -993,19 +923,16 @@ fn rococo_staging_testnet_config_genesis( const ENDOWMENT: u128 = 1_000_000 * ROC; const STASH: u128 = 100 * ROC; - rococo_runtime::RuntimeGenesisConfig { - system: rococo_runtime::SystemConfig { code: wasm_binary.to_vec(), ..Default::default() }, - balances: rococo_runtime::BalancesConfig { - balances: endowed_accounts + serde_json::json!({ + "balances": { + "balances": endowed_accounts .iter() .map(|k: &AccountId| (k.clone(), ENDOWMENT)) .chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH))) - .collect(), + .collect::>(), }, - beefy: Default::default(), - indices: rococo_runtime::IndicesConfig { indices: vec![] }, - session: rococo_runtime::SessionConfig { - keys: initial_authorities + "session": { + "keys": initial_authorities .iter() .map(|x| { ( @@ -1024,42 +951,17 @@ fn rococo_staging_testnet_config_genesis( }) .collect::>(), }, - phragmen_election: Default::default(), - babe: rococo_runtime::BabeConfig { - authorities: Default::default(), - epoch_config: Some(rococo_runtime::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() + "babe": { + "epochConfig": Some(rococo_runtime::BABE_GENESIS_EPOCH_CONFIG), }, - grandpa: Default::default(), - im_online: Default::default(), - democracy: rococo_runtime::DemocracyConfig::default(), - council: rococo::CouncilConfig { members: vec![], phantom: Default::default() }, - technical_committee: rococo::TechnicalCommitteeConfig { - members: vec![], - phantom: Default::default(), + "sudo": { "key": Some(endowed_accounts[0].clone()) }, + "configuration": { + "config": default_parachains_host_configuration(), }, - technical_membership: Default::default(), - treasury: Default::default(), - authority_discovery: rococo_runtime::AuthorityDiscoveryConfig { - keys: vec![], - ..Default::default() + "registrar": { + "nextFreeParaId": polkadot_primitives::LOWEST_PUBLIC_ID, }, - claims: rococo::ClaimsConfig { claims: vec![], vesting: vec![] }, - vesting: rococo::VestingConfig { vesting: vec![] }, - sudo: rococo_runtime::SudoConfig { key: Some(endowed_accounts[0].clone()) }, - paras: rococo_runtime::ParasConfig { paras: vec![], ..Default::default() }, - hrmp: Default::default(), - configuration: rococo_runtime::ConfigurationConfig { - config: default_parachains_host_configuration(), - }, - registrar: rococo_runtime::RegistrarConfig { - next_free_para_id: polkadot_primitives::LOWEST_PUBLIC_ID, - ..Default::default() - }, - xcm_pallet: Default::default(), - nis_counterpart_balances: Default::default(), - assigned_slots: Default::default(), - } + }) } /// Returns the properties for the [`PolkadotChainSpec`]. @@ -1075,73 +977,55 @@ pub fn polkadot_chain_spec_properties() -> serde_json::map::Map Result { - let wasm_binary = kusama::WASM_BINARY.ok_or("Kusama development wasm not available")?; - let boot_nodes = vec![]; - - Ok(KusamaChainSpec::from_genesis( - "Kusama Staging Testnet", - "kusama_staging_testnet", - ChainType::Live, - move || kusama_staging_testnet_config_genesis(wasm_binary), - boot_nodes, - Some( + Ok(KusamaChainSpec::builder() + .with_name("Kusama Staging Testnet") + .with_id("kusama_staging_testnet") + .with_chain_type(ChainType::Live) + .with_genesis_config_patch(kusama_staging_testnet_config_genesis()) + .with_telemetry_endpoints( TelemetryEndpoints::new(vec![(KUSAMA_STAGING_TELEMETRY_URL.to_string(), 0)]) .expect("Kusama Staging telemetry url is valid; qed"), - ), - Some(DEFAULT_PROTOCOL_ID), - None, - None, - Default::default(), - )) + ) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .with_extensions(Default::default()) + .with_code(kusama::WASM_BINARY.ok_or("Kusama development wasm not available")?) + .build()) } /// Westend staging testnet config. #[cfg(feature = "westend-native")] pub fn westend_staging_testnet_config() -> Result { - let wasm_binary = westend::WASM_BINARY.ok_or("Westend development wasm not available")?; - let boot_nodes = vec![]; - - Ok(WestendChainSpec::from_genesis( - "Westend Staging Testnet", - "westend_staging_testnet", - ChainType::Live, - move || westend_staging_testnet_config_genesis(wasm_binary), - boot_nodes, - Some( + Ok(WestendChainSpec::builder() + .with_name("Westend Staging Testnet") + .with_id("westend_staging_testnet") + .with_chain_type(ChainType::Live) + .with_genesis_config_patch(westend_staging_testnet_config_genesis()) + .with_telemetry_endpoints( TelemetryEndpoints::new(vec![(WESTEND_STAGING_TELEMETRY_URL.to_string(), 0)]) .expect("Westend Staging telemetry url is valid; qed"), - ), - Some(DEFAULT_PROTOCOL_ID), - None, - None, - Default::default(), - )) + ) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .with_extensions(Default::default()) + .with_code(westend::WASM_BINARY.ok_or("Westend development wasm not available")?) + .build()) } /// Rococo staging testnet config. #[cfg(feature = "rococo-native")] pub fn rococo_staging_testnet_config() -> Result { - let wasm_binary = rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?; - let boot_nodes = vec![]; - - Ok(RococoChainSpec::from_genesis( - "Rococo Staging Testnet", - "rococo_staging_testnet", - ChainType::Live, - move || RococoGenesisExt { - runtime_genesis_config: rococo_staging_testnet_config_genesis(wasm_binary), - session_length_in_blocks: None, - }, - boot_nodes, - Some( + Ok(RococoChainSpec::builder() + .with_name("Rococo Staging Testnet") + .with_id("rococo_staging_testnet") + .with_chain_type(ChainType::Live) + .with_genesis_config_patch(rococo_staging_testnet_config_genesis()) + .with_telemetry_endpoints( TelemetryEndpoints::new(vec![(ROCOCO_STAGING_TELEMETRY_URL.to_string(), 0)]) .expect("Rococo Staging telemetry url is valid; qed"), - ), - Some(DEFAULT_PROTOCOL_ID), - None, - None, - Default::default(), - )) + ) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .with_extensions(Default::default()) + .with_code(rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?) + .build()) } pub fn versi_chain_spec_properties() -> serde_json::map::Map { @@ -1158,27 +1042,20 @@ pub fn versi_chain_spec_properties() -> serde_json::map::Map Result { - let wasm_binary = rococo::WASM_BINARY.ok_or("Versi development wasm not available")?; - let boot_nodes = vec![]; - - Ok(RococoChainSpec::from_genesis( - "Versi Staging Testnet", - "versi_staging_testnet", - ChainType::Live, - move || RococoGenesisExt { - runtime_genesis_config: rococo_staging_testnet_config_genesis(wasm_binary), - session_length_in_blocks: Some(100), - }, - boot_nodes, - Some( + Ok(RococoChainSpec::builder() + .with_name("Versi Staging Testnet") + .with_id("versi_staging_testnet") + .with_chain_type(ChainType::Live) + .with_genesis_config_patch(rococo_staging_testnet_config_genesis()) + .with_telemetry_endpoints( TelemetryEndpoints::new(vec![(VERSI_STAGING_TELEMETRY_URL.to_string(), 0)]) .expect("Versi Staging telemetry url is valid; qed"), - ), - Some("versi"), - None, - Some(versi_chain_spec_properties()), - Default::default(), - )) + ) + .with_protocol_id("versi") + .with_properties(versi_chain_spec_properties()) + .with_extensions(Default::default()) + .with_code(rococo::WASM_BINARY.ok_or("Versi development wasm not available")?) + .build()) } /// Helper function to generate a crypto pair from seed @@ -1262,10 +1139,9 @@ fn testnet_accounts() -> Vec { ] } -/// Helper function to create polkadot `RuntimeGenesisConfig` for testing +/// Helper function to create polkadot runtime `GenesisConfig` patch for testing #[cfg(feature = "polkadot-native")] pub fn polkadot_testnet_genesis( - wasm_binary: &[u8], initial_authorities: Vec<( AccountId, AccountId, @@ -1278,20 +1154,18 @@ pub fn polkadot_testnet_genesis( )>, _root_key: AccountId, endowed_accounts: Option>, -) -> polkadot::RuntimeGenesisConfig { +) -> 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; - polkadot::RuntimeGenesisConfig { - system: polkadot::SystemConfig { code: wasm_binary.to_vec(), ..Default::default() }, - indices: polkadot::IndicesConfig { indices: vec![] }, - balances: polkadot::BalancesConfig { - balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(), + serde_json::json!({ + "balances": { + "balances": endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect::>(), }, - session: polkadot::SessionConfig { - keys: initial_authorities + "session": { + "keys": initial_authorities .iter() .map(|x| { ( @@ -1309,46 +1183,29 @@ pub fn polkadot_testnet_genesis( }) .collect::>(), }, - staking: polkadot::StakingConfig { - minimum_validator_count: 1, - validator_count: initial_authorities.len() as u32, - stakers: initial_authorities + "staking": { + "minimumValidatorCount": 1, + "validatorCount": initial_authorities.len() as u32, + "stakers": initial_authorities .iter() - .map(|x| (x.0.clone(), x.0.clone(), STASH, polkadot::StakerStatus::Validator)) - .collect(), - invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(), - force_era: Forcing::NotForcing, - slash_reward_fraction: Perbill::from_percent(10), - ..Default::default() - }, - babe: polkadot::BabeConfig { - authorities: Default::default(), - epoch_config: Some(polkadot::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() + .map(|x| (x.0.clone(), x.0.clone(), STASH, polkadot::StakerStatus::::Validator)) + .collect::>(), + "invulnerables": initial_authorities.iter().map(|x| x.0.clone()).collect::>(), + "forceEra": Forcing::NotForcing, + "slashRewardFraction": Perbill::from_percent(10), }, - grandpa: Default::default(), - im_online: Default::default(), - authority_discovery: polkadot::AuthorityDiscoveryConfig { - keys: vec![], - ..Default::default() + "babe": { + "epochConfig": Some(polkadot::BABE_GENESIS_EPOCH_CONFIG), }, - claims: polkadot::ClaimsConfig { claims: vec![], vesting: vec![] }, - vesting: polkadot::VestingConfig { vesting: vec![] }, - treasury: Default::default(), - hrmp: Default::default(), - configuration: polkadot::ConfigurationConfig { - config: default_parachains_host_configuration(), + "configuration": { + "config": default_parachains_host_configuration(), }, - paras: Default::default(), - xcm_pallet: Default::default(), - nomination_pools: Default::default(), - } + }) } -/// Helper function to create kusama `RuntimeGenesisConfig` for testing +/// Helper function to create kusama runtime `GenesisConfig` patch for testing #[cfg(feature = "kusama-native")] pub fn kusama_testnet_genesis( - wasm_binary: &[u8], initial_authorities: Vec<( AccountId, AccountId, @@ -1362,21 +1219,18 @@ pub fn kusama_testnet_genesis( )>, _root_key: AccountId, endowed_accounts: Option>, -) -> kusama::RuntimeGenesisConfig { +) -> 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; - kusama::RuntimeGenesisConfig { - system: kusama::SystemConfig { code: wasm_binary.to_vec(), ..Default::default() }, - indices: kusama::IndicesConfig { indices: vec![] }, - balances: kusama::BalancesConfig { - balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(), + serde_json::json!({ + "balances": { + "balances": endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect::>(), }, - beefy: Default::default(), - session: kusama::SessionConfig { - keys: initial_authorities + "session": { + "keys": initial_authorities .iter() .map(|x| { ( @@ -1395,47 +1249,29 @@ pub fn kusama_testnet_genesis( }) .collect::>(), }, - staking: kusama::StakingConfig { - minimum_validator_count: 1, - validator_count: initial_authorities.len() as u32, - stakers: initial_authorities + "staking": { + "minimumValidatorCount": 1, + "validatorCount": initial_authorities.len() as u32, + "stakers": initial_authorities .iter() - .map(|x| (x.0.clone(), x.0.clone(), STASH, kusama::StakerStatus::Validator)) - .collect(), - invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(), - force_era: Forcing::NotForcing, - slash_reward_fraction: Perbill::from_percent(10), - ..Default::default() - }, - babe: kusama::BabeConfig { - authorities: Default::default(), - epoch_config: Some(kusama::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() + .map(|x| (x.0.clone(), x.0.clone(), STASH, kusama::StakerStatus::::Validator)) + .collect::>(), + "invulnerables": initial_authorities.iter().map(|x| x.0.clone()).collect::>(), + "forceEra": Forcing::NotForcing, + "slashRewardFraction": Perbill::from_percent(10), }, - grandpa: Default::default(), - im_online: Default::default(), - authority_discovery: kusama::AuthorityDiscoveryConfig { - keys: vec![], - ..Default::default() + "babe": { + "epochConfig": Some(kusama::BABE_GENESIS_EPOCH_CONFIG), }, - claims: kusama::ClaimsConfig { claims: vec![], vesting: vec![] }, - vesting: kusama::VestingConfig { vesting: vec![] }, - treasury: Default::default(), - hrmp: Default::default(), - configuration: kusama::ConfigurationConfig { - config: default_parachains_host_configuration(), + "configuration": { + "config": default_parachains_host_configuration(), }, - paras: Default::default(), - xcm_pallet: Default::default(), - nomination_pools: Default::default(), - nis_counterpart_balances: Default::default(), - } + }) } -/// Helper function to create westend `RuntimeGenesisConfig` for testing +/// Helper function to create westend runtime `GenesisConfig` patch for testing #[cfg(feature = "westend-native")] pub fn westend_testnet_genesis( - wasm_binary: &[u8], initial_authorities: Vec<( AccountId, AccountId, @@ -1449,21 +1285,18 @@ pub fn westend_testnet_genesis( )>, root_key: AccountId, endowed_accounts: Option>, -) -> westend::RuntimeGenesisConfig { +) -> serde_json::Value { let endowed_accounts: Vec = endowed_accounts.unwrap_or_else(testnet_accounts); const ENDOWMENT: u128 = 1_000_000 * WND; const STASH: u128 = 100 * WND; - westend::RuntimeGenesisConfig { - system: westend::SystemConfig { code: wasm_binary.to_vec(), ..Default::default() }, - indices: westend::IndicesConfig { indices: vec![] }, - balances: westend::BalancesConfig { - balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(), + serde_json::json!({ + "balances": { + "balances": endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect::>(), }, - beefy: Default::default(), - session: westend::SessionConfig { - keys: initial_authorities + "session": { + "keys": initial_authorities .iter() .map(|x| { ( @@ -1482,50 +1315,33 @@ pub fn westend_testnet_genesis( }) .collect::>(), }, - staking: westend::StakingConfig { - minimum_validator_count: 1, - validator_count: initial_authorities.len() as u32, - stakers: initial_authorities + "staking": { + "minimumValidatorCount": 1, + "validatorCount": initial_authorities.len() as u32, + "stakers": initial_authorities .iter() - .map(|x| (x.0.clone(), x.0.clone(), STASH, westend::StakerStatus::Validator)) - .collect(), - invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(), - force_era: Forcing::NotForcing, - slash_reward_fraction: Perbill::from_percent(10), - ..Default::default() - }, - babe: westend::BabeConfig { - authorities: Default::default(), - epoch_config: Some(westend::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() + .map(|x| (x.0.clone(), x.0.clone(), STASH, westend::StakerStatus::::Validator)) + .collect::>(), + "invulnerables": initial_authorities.iter().map(|x| x.0.clone()).collect::>(), + "forceEra": Forcing::NotForcing, + "slashRewardFraction": Perbill::from_percent(10), }, - grandpa: Default::default(), - im_online: Default::default(), - authority_discovery: westend::AuthorityDiscoveryConfig { - keys: vec![], - ..Default::default() + "babe": { + "epochConfig": Some(westend::BABE_GENESIS_EPOCH_CONFIG), }, - vesting: westend::VestingConfig { vesting: vec![] }, - sudo: westend::SudoConfig { key: Some(root_key) }, - hrmp: Default::default(), - configuration: westend::ConfigurationConfig { - config: default_parachains_host_configuration(), + "sudo": { "key": Some(root_key) }, + "configuration": { + "config": default_parachains_host_configuration(), }, - paras: Default::default(), - registrar: westend_runtime::RegistrarConfig { - next_free_para_id: polkadot_primitives::LOWEST_PUBLIC_ID, - ..Default::default() + "registrar": { + "nextFreeParaId": polkadot_primitives::LOWEST_PUBLIC_ID, }, - xcm_pallet: Default::default(), - nomination_pools: Default::default(), - assigned_slots: Default::default(), - } + }) } -/// Helper function to create rococo `RuntimeGenesisConfig` for testing +/// Helper function to create rococo runtime `GenesisConfig` patch for testing #[cfg(feature = "rococo-native")] pub fn rococo_testnet_genesis( - wasm_binary: &[u8], initial_authorities: Vec<( AccountId, AccountId, @@ -1539,20 +1355,17 @@ pub fn rococo_testnet_genesis( )>, root_key: AccountId, endowed_accounts: Option>, -) -> rococo_runtime::RuntimeGenesisConfig { +) -> serde_json::Value { let endowed_accounts: Vec = endowed_accounts.unwrap_or_else(testnet_accounts); const ENDOWMENT: u128 = 1_000_000 * ROC; - rococo_runtime::RuntimeGenesisConfig { - system: rococo_runtime::SystemConfig { code: wasm_binary.to_vec(), ..Default::default() }, - beefy: Default::default(), - indices: rococo_runtime::IndicesConfig { indices: vec![] }, - balances: rococo_runtime::BalancesConfig { - balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(), + serde_json::json!({ + "balances": { + "balances": endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect::>(), }, - session: rococo_runtime::SessionConfig { - keys: initial_authorities + "session": { + "keys": initial_authorities .iter() .map(|x| { ( @@ -1571,51 +1384,25 @@ pub fn rococo_testnet_genesis( }) .collect::>(), }, - babe: rococo_runtime::BabeConfig { - authorities: Default::default(), - epoch_config: Some(rococo_runtime::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() + "babe": { + "epochConfig": Some(rococo_runtime::BABE_GENESIS_EPOCH_CONFIG), }, - grandpa: Default::default(), - im_online: Default::default(), - phragmen_election: Default::default(), - democracy: rococo::DemocracyConfig::default(), - council: rococo::CouncilConfig { members: vec![], phantom: Default::default() }, - technical_committee: rococo::TechnicalCommitteeConfig { - members: vec![], - phantom: Default::default(), - }, - technical_membership: Default::default(), - treasury: Default::default(), - claims: rococo::ClaimsConfig { claims: vec![], vesting: vec![] }, - vesting: rococo::VestingConfig { vesting: vec![] }, - authority_discovery: rococo_runtime::AuthorityDiscoveryConfig { - keys: vec![], - ..Default::default() - }, - sudo: rococo_runtime::SudoConfig { key: Some(root_key.clone()) }, - hrmp: Default::default(), - configuration: rococo_runtime::ConfigurationConfig { - config: polkadot_runtime_parachains::configuration::HostConfiguration { + "sudo": { "key": Some(root_key.clone()) }, + "configuration": { + "config": polkadot_runtime_parachains::configuration::HostConfiguration { max_validators_per_core: Some(1), ..default_parachains_host_configuration() }, }, - paras: rococo_runtime::ParasConfig { paras: vec![], ..Default::default() }, - registrar: rococo_runtime::RegistrarConfig { - next_free_para_id: polkadot_primitives::LOWEST_PUBLIC_ID, - ..Default::default() - }, - xcm_pallet: Default::default(), - nis_counterpart_balances: Default::default(), - assigned_slots: Default::default(), - } + "registrar": { + "nextFreeParaId": polkadot_primitives::LOWEST_PUBLIC_ID, + } + }) } #[cfg(feature = "polkadot-native")] -fn polkadot_development_config_genesis(wasm_binary: &[u8]) -> polkadot::RuntimeGenesisConfig { +fn polkadot_development_config_genesis() -> serde_json::Value { polkadot_testnet_genesis( - wasm_binary, vec![get_authority_keys_from_seed_no_beefy("Alice")], get_account_id_from_seed::("Alice"), None, @@ -1623,9 +1410,8 @@ fn polkadot_development_config_genesis(wasm_binary: &[u8]) -> polkadot::RuntimeG } #[cfg(feature = "kusama-native")] -fn kusama_development_config_genesis(wasm_binary: &[u8]) -> kusama::RuntimeGenesisConfig { +fn kusama_development_config_genesis() -> serde_json::Value { kusama_testnet_genesis( - wasm_binary, vec![get_authority_keys_from_seed("Alice")], get_account_id_from_seed::("Alice"), None, @@ -1633,9 +1419,8 @@ fn kusama_development_config_genesis(wasm_binary: &[u8]) -> kusama::RuntimeGenes } #[cfg(feature = "westend-native")] -fn westend_development_config_genesis(wasm_binary: &[u8]) -> westend::RuntimeGenesisConfig { +fn westend_development_config_genesis() -> serde_json::Value { westend_testnet_genesis( - wasm_binary, vec![get_authority_keys_from_seed("Alice")], get_account_id_from_seed::("Alice"), None, @@ -1643,9 +1428,8 @@ fn westend_development_config_genesis(wasm_binary: &[u8]) -> westend::RuntimeGen } #[cfg(feature = "rococo-native")] -fn rococo_development_config_genesis(wasm_binary: &[u8]) -> rococo_runtime::RuntimeGenesisConfig { +fn rococo_development_config_genesis() -> serde_json::Value { rococo_testnet_genesis( - wasm_binary, vec![get_authority_keys_from_seed("Alice")], get_account_id_from_seed::("Alice"), None, @@ -1655,134 +1439,92 @@ fn rococo_development_config_genesis(wasm_binary: &[u8]) -> rococo_runtime::Runt /// Polkadot development config (single validator Alice) #[cfg(feature = "polkadot-native")] pub fn polkadot_development_config() -> Result { - let wasm_binary = polkadot::WASM_BINARY.ok_or("Polkadot development wasm not available")?; - - Ok(PolkadotChainSpec::from_genesis( - "Development", - "polkadot_dev", - ChainType::Development, - move || polkadot_development_config_genesis(wasm_binary), - vec![], - None, - Some(DEFAULT_PROTOCOL_ID), - None, - Some(polkadot_chain_spec_properties()), - Default::default(), - )) + Ok(PolkadotChainSpec::builder() + .with_name("Development") + .with_id("polkadot_dev") + .with_chain_type(ChainType::Development) + .with_genesis_config_patch(polkadot_development_config_genesis()) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .with_properties(polkadot_chain_spec_properties()) + .with_extensions(Default::default()) + .with_code(polkadot::WASM_BINARY.ok_or("Polkadot development wasm not available")?) + .build()) } /// Kusama development config (single validator Alice) #[cfg(feature = "kusama-native")] pub fn kusama_development_config() -> Result { - let wasm_binary = kusama::WASM_BINARY.ok_or("Kusama development wasm not available")?; - - Ok(KusamaChainSpec::from_genesis( - "Development", - "kusama_dev", - ChainType::Development, - move || kusama_development_config_genesis(wasm_binary), - vec![], - None, - Some(DEFAULT_PROTOCOL_ID), - None, - None, - Default::default(), - )) + Ok(KusamaChainSpec::builder() + .with_name("Development") + .with_id("kusama_dev") + .with_chain_type(ChainType::Development) + .with_genesis_config_patch(kusama_development_config_genesis()) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .with_extensions(Default::default()) + .with_code(kusama::WASM_BINARY.ok_or("Kusama development wasm not available")?) + .build()) } /// Westend development config (single validator Alice) #[cfg(feature = "westend-native")] pub fn westend_development_config() -> Result { - let wasm_binary = westend::WASM_BINARY.ok_or("Westend development wasm not available")?; - - Ok(WestendChainSpec::from_genesis( - "Development", - "westend_dev", - ChainType::Development, - move || westend_development_config_genesis(wasm_binary), - vec![], - None, - Some(DEFAULT_PROTOCOL_ID), - None, - None, - Default::default(), - )) + Ok(WestendChainSpec::builder() + .with_name("Development") + .with_id("westend_dev") + .with_chain_type(ChainType::Development) + .with_genesis_config_patch(westend_development_config_genesis()) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .with_extensions(Default::default()) + .with_code(westend::WASM_BINARY.ok_or("Westend development wasm not available")?) + .build()) } /// Rococo development config (single validator Alice) #[cfg(feature = "rococo-native")] pub fn rococo_development_config() -> Result { - let wasm_binary = rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?; - - Ok(RococoChainSpec::from_genesis( - "Development", - "rococo_dev", - ChainType::Development, - move || RococoGenesisExt { - runtime_genesis_config: rococo_development_config_genesis(wasm_binary), - // Use 1 minute session length. - session_length_in_blocks: Some(10), - }, - vec![], - None, - Some(DEFAULT_PROTOCOL_ID), - None, - None, - Default::default(), - )) + Ok(RococoChainSpec::builder() + .with_name("Development") + .with_id("rococo_dev") + .with_chain_type(ChainType::Development) + .with_genesis_config_patch(rococo_development_config_genesis()) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .with_extensions(Default::default()) + .with_code(rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?) + .build()) } /// `Versi` development config (single validator Alice) #[cfg(feature = "rococo-native")] pub fn versi_development_config() -> Result { - let wasm_binary = rococo::WASM_BINARY.ok_or("Versi development wasm not available")?; - - Ok(RococoChainSpec::from_genesis( - "Development", - "versi_dev", - ChainType::Development, - move || RococoGenesisExt { - runtime_genesis_config: rococo_development_config_genesis(wasm_binary), - // Use 1 minute session length. - session_length_in_blocks: Some(10), - }, - vec![], - None, - Some("versi"), - None, - None, - Default::default(), - )) + Ok(RococoChainSpec::builder() + .with_name("Development") + .with_id("versi_dev") + .with_chain_type(ChainType::Development) + .with_genesis_config_patch(rococo_development_config_genesis()) + .with_protocol_id("versi") + .with_extensions(Default::default()) + .with_code(rococo::WASM_BINARY.ok_or("Versi development wasm not available")?) + .build()) } /// Wococo development config (single validator Alice) #[cfg(feature = "rococo-native")] pub fn wococo_development_config() -> Result { const WOCOCO_DEV_PROTOCOL_ID: &str = "woco"; - let wasm_binary = rococo::WASM_BINARY.ok_or("Wococo development wasm not available")?; - - Ok(RococoChainSpec::from_genesis( - "Development", - "wococo_dev", - ChainType::Development, - move || RococoGenesisExt { - runtime_genesis_config: rococo_development_config_genesis(wasm_binary), - // Use 1 minute session length. - session_length_in_blocks: Some(10), - }, - vec![], - None, - Some(WOCOCO_DEV_PROTOCOL_ID), - None, - None, - Default::default(), - )) + Ok(RococoChainSpec::builder() + .with_name("Development") + .with_id("wococo_dev") + .with_chain_type(ChainType::Development) + .with_genesis_config_patch(rococo_development_config_genesis()) + .with_protocol_id(WOCOCO_DEV_PROTOCOL_ID) + .with_extensions(Default::default()) + .with_code(rococo::WASM_BINARY.ok_or("Wococo development wasm not available")?) + .build()) } #[cfg(feature = "polkadot-native")] -fn polkadot_local_testnet_genesis(wasm_binary: &[u8]) -> polkadot::RuntimeGenesisConfig { +fn polkadot_local_testnet_genesis() -> serde_json::Value { polkadot_testnet_genesis( - wasm_binary, vec![ get_authority_keys_from_seed_no_beefy("Alice"), get_authority_keys_from_seed_no_beefy("Bob"), @@ -1795,26 +1537,21 @@ fn polkadot_local_testnet_genesis(wasm_binary: &[u8]) -> polkadot::RuntimeGenesi /// Polkadot local testnet config (multivalidator Alice + Bob) #[cfg(feature = "polkadot-native")] pub fn polkadot_local_testnet_config() -> Result { - let wasm_binary = polkadot::WASM_BINARY.ok_or("Polkadot development wasm not available")?; - - Ok(PolkadotChainSpec::from_genesis( - "Local Testnet", - "local_testnet", - ChainType::Local, - move || polkadot_local_testnet_genesis(wasm_binary), - vec![], - None, - Some(DEFAULT_PROTOCOL_ID), - None, - Some(polkadot_chain_spec_properties()), - Default::default(), - )) + Ok(PolkadotChainSpec::builder() + .with_name("Local Testnet") + .with_id("local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(polkadot_local_testnet_genesis()) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .with_properties(polkadot_chain_spec_properties()) + .with_extensions(Default::default()) + .with_code(polkadot::WASM_BINARY.ok_or("Polkadot development wasm not available")?) + .build()) } #[cfg(feature = "kusama-native")] -fn kusama_local_testnet_genesis(wasm_binary: &[u8]) -> kusama::RuntimeGenesisConfig { +fn kusama_local_testnet_genesis() -> serde_json::Value { kusama_testnet_genesis( - wasm_binary, vec![get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob")], get_account_id_from_seed::("Alice"), None, @@ -1824,26 +1561,20 @@ fn kusama_local_testnet_genesis(wasm_binary: &[u8]) -> kusama::RuntimeGenesisCon /// Kusama local testnet config (multivalidator Alice + Bob) #[cfg(feature = "kusama-native")] pub fn kusama_local_testnet_config() -> Result { - let wasm_binary = kusama::WASM_BINARY.ok_or("Kusama development wasm not available")?; - - Ok(KusamaChainSpec::from_genesis( - "Kusama Local Testnet", - "kusama_local_testnet", - ChainType::Local, - move || kusama_local_testnet_genesis(wasm_binary), - vec![], - None, - Some(DEFAULT_PROTOCOL_ID), - None, - None, - Default::default(), - )) + Ok(KusamaChainSpec::builder() + .with_name("Kusama Local Testnet") + .with_id("kusama_local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(kusama_local_testnet_genesis()) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .with_extensions(Default::default()) + .with_code(kusama::WASM_BINARY.ok_or("Kusama development wasm not available")?) + .build()) } #[cfg(feature = "westend-native")] -fn westend_local_testnet_genesis(wasm_binary: &[u8]) -> westend::RuntimeGenesisConfig { +fn westend_local_testnet_genesis() -> serde_json::Value { westend_testnet_genesis( - wasm_binary, vec![get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob")], get_account_id_from_seed::("Alice"), None, @@ -1853,26 +1584,20 @@ fn westend_local_testnet_genesis(wasm_binary: &[u8]) -> westend::RuntimeGenesisC /// Westend local testnet config (multivalidator Alice + Bob) #[cfg(feature = "westend-native")] pub fn westend_local_testnet_config() -> Result { - let wasm_binary = westend::WASM_BINARY.ok_or("Westend development wasm not available")?; - - Ok(WestendChainSpec::from_genesis( - "Westend Local Testnet", - "westend_local_testnet", - ChainType::Local, - move || westend_local_testnet_genesis(wasm_binary), - vec![], - None, - Some(DEFAULT_PROTOCOL_ID), - None, - None, - Default::default(), - )) + Ok(WestendChainSpec::builder() + .with_name("Westend Local Testnet") + .with_id("westend_local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(westend_local_testnet_genesis()) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .with_extensions(Default::default()) + .with_code(westend::WASM_BINARY.ok_or("Westend development wasm not available")?) + .build()) } #[cfg(feature = "rococo-native")] -fn rococo_local_testnet_genesis(wasm_binary: &[u8]) -> rococo_runtime::RuntimeGenesisConfig { +fn rococo_local_testnet_genesis() -> serde_json::Value { rococo_testnet_genesis( - wasm_binary, vec![get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob")], get_account_id_from_seed::("Alice"), None, @@ -1882,31 +1607,21 @@ fn rococo_local_testnet_genesis(wasm_binary: &[u8]) -> rococo_runtime::RuntimeGe /// Rococo local testnet config (multivalidator Alice + Bob) #[cfg(feature = "rococo-native")] pub fn rococo_local_testnet_config() -> Result { - let wasm_binary = rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?; - - Ok(RococoChainSpec::from_genesis( - "Rococo Local Testnet", - "rococo_local_testnet", - ChainType::Local, - move || RococoGenesisExt { - runtime_genesis_config: rococo_local_testnet_genesis(wasm_binary), - // Use 1 minute session length. - session_length_in_blocks: Some(10), - }, - vec![], - None, - Some(DEFAULT_PROTOCOL_ID), - None, - None, - Default::default(), - )) + Ok(RococoChainSpec::builder() + .with_name("Rococo Local Testnet") + .with_id("rococo_local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(rococo_local_testnet_genesis()) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .with_extensions(Default::default()) + .with_code(rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?) + .build()) } /// Wococo is a temporary testnet that uses almost the same runtime as rococo. #[cfg(feature = "rococo-native")] -fn wococo_local_testnet_genesis(wasm_binary: &[u8]) -> rococo_runtime::RuntimeGenesisConfig { +fn wococo_local_testnet_genesis() -> serde_json::Value { rococo_testnet_genesis( - wasm_binary, vec![ get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob"), @@ -1921,31 +1636,21 @@ fn wococo_local_testnet_genesis(wasm_binary: &[u8]) -> rococo_runtime::RuntimeGe /// Wococo local testnet config (multivalidator Alice + Bob + Charlie + Dave) #[cfg(feature = "rococo-native")] pub fn wococo_local_testnet_config() -> Result { - let wasm_binary = rococo::WASM_BINARY.ok_or("Wococo development wasm not available")?; - - Ok(RococoChainSpec::from_genesis( - "Wococo Local Testnet", - "wococo_local_testnet", - ChainType::Local, - move || RococoGenesisExt { - runtime_genesis_config: wococo_local_testnet_genesis(wasm_binary), - // Use 1 minute session length. - session_length_in_blocks: Some(10), - }, - vec![], - None, - Some(DEFAULT_PROTOCOL_ID), - None, - None, - Default::default(), - )) + Ok(RococoChainSpec::builder() + .with_name("Wococo Local Testnet") + .with_id("wococo_local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(wococo_local_testnet_genesis()) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .with_extensions(Default::default()) + .with_code(rococo::WASM_BINARY.ok_or("Wococo development wasm not available")?) + .build()) } /// `Versi` is a temporary testnet that uses the same runtime as rococo. #[cfg(feature = "rococo-native")] -fn versi_local_testnet_genesis(wasm_binary: &[u8]) -> rococo_runtime::RuntimeGenesisConfig { +fn versi_local_testnet_genesis() -> serde_json::Value { rococo_testnet_genesis( - wasm_binary, vec![ get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob"), @@ -1960,22 +1665,196 @@ fn versi_local_testnet_genesis(wasm_binary: &[u8]) -> rococo_runtime::RuntimeGen /// `Versi` local testnet config (multivalidator Alice + Bob + Charlie + Dave) #[cfg(feature = "rococo-native")] pub fn versi_local_testnet_config() -> Result { - let wasm_binary = rococo::WASM_BINARY.ok_or("Versi development wasm not available")?; - - Ok(RococoChainSpec::from_genesis( - "Versi Local Testnet", - "versi_local_testnet", - ChainType::Local, - move || RococoGenesisExt { - runtime_genesis_config: versi_local_testnet_genesis(wasm_binary), - // Use 1 minute session length. - session_length_in_blocks: Some(10), - }, - vec![], - None, - Some("versi"), - None, - None, - Default::default(), - )) + Ok(RococoChainSpec::builder() + .with_name("Versi Local Testnet") + .with_id("versi_local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(versi_local_testnet_genesis()) + .with_protocol_id("versi") + .with_extensions(Default::default()) + .with_code(rococo::WASM_BINARY.ok_or("Versi development wasm not available")?) + .build()) +} + +#[cfg(any( + feature = "polkadot-native", + feature = "kusama-native", + feature = "westend-native", + feature = "rococo-native" +))] +#[cfg(test)] +mod legacy_chain_spec; + +// Tests RuntimeGenesisConfig-based ChainSpecs (old) against the JSON-genesis-config-based (new) +// ChainSpecs. Shall be removed once native runtime is removed. +#[cfg(any( + feature = "polkadot-native", + feature = "kusama-native", + feature = "westend-native", + feature = "rococo-native" +))] +#[cfg(test)] +mod json_vs_legacy_tests { + #[cfg(any( + feature = "polkadot-native", + feature = "kusama-native", + feature = "westend-native", + feature = "rococo-native" + ))] + use super::{legacy_chain_spec as legacy, *}; + + #[test] + #[cfg(feature = "polkadot-native")] + fn polkadot_development_config_compare_test() { + let j1 = polkadot_development_config().unwrap().as_json(true).unwrap(); + let j2 = legacy::polkadot_development_config().unwrap().as_json(true).unwrap(); + assert_eq!(j1, j2); + } + + #[test] + #[cfg(feature = "polkadot-native")] + fn polkadot_local_testnet_config_compare_test() { + let j1 = polkadot_local_testnet_config().unwrap().as_json(true).unwrap(); + let j2 = legacy::polkadot_local_testnet_config().unwrap().as_json(true).unwrap(); + assert_eq!(j1, j2); + } + + #[test] + #[cfg(feature = "kusama-native")] + fn kusama_staging_testnet_config_compare_test() { + let j1 = kusama_staging_testnet_config().unwrap().as_json(true).unwrap(); + let j2 = legacy::kusama_staging_testnet_config().unwrap().as_json(true).unwrap(); + assert_eq!(j1, j2); + } + + #[test] + #[cfg(feature = "kusama-native")] + fn kusama_development_config_compare_test() { + let j1 = kusama_development_config().unwrap().as_json(true).unwrap(); + let j2 = legacy::kusama_development_config().unwrap().as_json(true).unwrap(); + assert_eq!(j1, j2); + } + + #[test] + #[cfg(feature = "kusama-native")] + fn kusama_local_testnet_config_compare_test() { + let j1 = kusama_local_testnet_config().unwrap().as_json(true).unwrap(); + let j2 = legacy::kusama_local_testnet_config().unwrap().as_json(true).unwrap(); + assert_eq!(j1, j2); + } + + #[test] + #[cfg(feature = "westend-native")] + fn westend_staging_testnet_config_compare_test() { + let j1 = westend_staging_testnet_config().unwrap().as_json(true).unwrap(); + let j2 = legacy::westend_staging_testnet_config().unwrap().as_json(true).unwrap(); + assert_eq!(j1, j2); + } + + #[test] + #[cfg(feature = "westend-native")] + fn westend_development_config_compare_test() { + let j1 = westend_development_config().unwrap().as_json(true).unwrap(); + let j2 = legacy::westend_development_config().unwrap().as_json(true).unwrap(); + assert_eq!(j1, j2); + } + + #[test] + #[cfg(feature = "westend-native")] + fn westend_local_testnet_config_compare_test() { + let j1 = westend_local_testnet_config().unwrap().as_json(true).unwrap(); + let j2 = legacy::westend_local_testnet_config().unwrap().as_json(true).unwrap(); + assert_eq!(j1, j2); + } + + #[test] + #[cfg(feature = "rococo-native")] + fn rococo_staging_testnet_config_compare_test() { + let mut j1 = rococo_staging_testnet_config().unwrap().as_json(true).unwrap(); + let mut j2 = legacy::rococo_staging_testnet_config().unwrap().as_json(true).unwrap(); + (j1, j2) = adjust_rococo_output(j1, j2); + assert_eq!(j1, j2); + } + + #[test] + #[cfg(feature = "rococo-native")] + fn rococo_development_config_compare_test() { + let mut j1 = rococo_development_config().unwrap().as_json(true).unwrap(); + let mut j2 = legacy::rococo_development_config().unwrap().as_json(true).unwrap(); + (j1, j2) = adjust_rococo_output(j1, j2); + assert_eq!(j1, j2); + } + + #[test] + #[cfg(feature = "rococo-native")] + fn rococo_local_testnet_config_compare_test() { + let mut j1 = rococo_local_testnet_config().unwrap().as_json(true).unwrap(); + let mut j2 = legacy::rococo_local_testnet_config().unwrap().as_json(true).unwrap(); + (j1, j2) = adjust_rococo_output(j1, j2); + assert_eq!(j1, j2); + } + + #[test] + #[cfg(feature = "rococo-native")] + fn wococo_development_config_compare_test() { + let mut j1 = wococo_development_config().unwrap().as_json(true).unwrap(); + let mut j2 = legacy::wococo_development_config().unwrap().as_json(true).unwrap(); + (j1, j2) = adjust_rococo_output(j1, j2); + assert_eq!(j1, j2); + } + + #[test] + #[cfg(feature = "rococo-native")] + fn wococo_local_testnet_config_compare_test() { + let mut j1 = wococo_local_testnet_config().unwrap().as_json(true).unwrap(); + let mut j2 = legacy::wococo_local_testnet_config().unwrap().as_json(true).unwrap(); + (j1, j2) = adjust_rococo_output(j1, j2); + assert_eq!(j1, j2); + } + + // since we changed how EpochDurationInBlocks is handleded (legacy: in state storage vs new: feature-based const), + // and since we have 3 versions of code, we need to do some adjustments. + fn adjust_rococo_output(input1: String, input2: String) -> (String, String) { + let mut json1 = serde_json::from_str::>(&input1).unwrap(); + let mut json2 = serde_json::from_str::>(&input2).unwrap(); + + let _ = json1.remove("code"); + let _ = json2.remove("code"); + let _ = json2.get_mut("genesis").map(|g| { + g.as_object_mut().unwrap().get_mut("raw").map(|r| { + r.as_object_mut().unwrap().get_mut("top").map(|t| { + let _ = t.as_object_mut().unwrap().remove("0x39e295d143ed41353167609a3d816584"); + }) + }) + }); + + (serde_json::to_string(&json1).unwrap(), serde_json::to_string(&json2).unwrap()) + } + + #[test] + #[cfg(feature = "rococo-native")] + fn versi_staging_testnet_config_compare_test() { + let mut j1 = versi_staging_testnet_config().unwrap().as_json(true).unwrap(); + let mut j2 = legacy::versi_staging_testnet_config().unwrap().as_json(true).unwrap(); + (j1, j2) = adjust_rococo_output(j1, j2); + assert_eq!(j1, j2); + } + + #[test] + #[cfg(feature = "rococo-native")] + fn versi_development_config_compare_test() { + let mut j1 = versi_development_config().unwrap().as_json(true).unwrap(); + let mut j2 = legacy::versi_development_config().unwrap().as_json(true).unwrap(); + (j1, j2) = adjust_rococo_output(j1, j2); + assert_eq!(j1, j2); + } + + #[test] + #[cfg(feature = "rococo-native")] + fn versi_local_testnet_config_compare_test() { + let mut j1 = versi_local_testnet_config().unwrap().as_json(true).unwrap(); + let mut j2 = legacy::versi_local_testnet_config().unwrap().as_json(true).unwrap(); + (j1, j2) = adjust_rococo_output(j1, j2); + assert_eq!(j1, j2); + } } diff --git a/polkadot/node/service/src/chain_spec/legacy_chain_spec.rs b/polkadot/node/service/src/chain_spec/legacy_chain_spec.rs new file mode 100644 index 000000000000..41b8a917bf8d --- /dev/null +++ b/polkadot/node/service/src/chain_spec/legacy_chain_spec.rs @@ -0,0 +1,1907 @@ +// 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 . + +//! RuntimeGenesisConfig-based (legacy) Polkadot chain configurations. Used for testing ChainSpecs against the JSON-based +//! genesis configs. Entire file shall be removed once native runtime is removed. + +use beefy_primitives::ecdsa_crypto::AuthorityId as BeefyId; +use grandpa::AuthorityId as GrandpaId; +#[cfg(feature = "kusama-native")] +use kusama_runtime as kusama; +#[cfg(feature = "kusama-native")] +use kusama_runtime_constants::currency::UNITS as KSM; +use pallet_im_online::sr25519::AuthorityId as ImOnlineId; +#[cfg(any( + feature = "polkadot-native", + feature = "kusama-native", + feature = "westend-native", +))] +use pallet_staking::Forcing; +use polkadot_primitives::{AccountId, AccountPublic, AssignmentId, ValidatorId}; +#[cfg(feature = "polkadot-native")] +use polkadot_runtime as polkadot; +#[cfg(feature = "polkadot-native")] +use polkadot_runtime_constants::currency::UNITS as DOT; +use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; +use sp_consensus_babe::AuthorityId as BabeId; + +#[cfg(feature = "rococo-native")] +use rococo_runtime as rococo; +#[cfg(feature = "rococo-native")] +use rococo_runtime_constants::currency::UNITS as ROC; +use sc_chain_spec::ChainSpecExtension; +#[cfg(any( + feature = "polkadot-native", + feature = "kusama-native", + feature = "westend-native", + feature = "rococo-native" +))] +use sc_chain_spec::ChainType; +use serde::{Deserialize, Serialize}; +use sp_core::{sr25519, Pair, Public}; +use sp_runtime::traits::IdentifyAccount; +#[cfg(any( + feature = "polkadot-native", + feature = "kusama-native", + feature = "westend-native", +))] +use sp_runtime::Perbill; +#[cfg(any( + feature = "polkadot-native", + feature = "kusama-native", + feature = "westend-native", + feature = "rococo-native" +))] +use telemetry::TelemetryEndpoints; +#[cfg(feature = "westend-native")] +use westend_runtime as westend; +#[cfg(feature = "westend-native")] +use westend_runtime_constants::currency::UNITS as WND; + +#[cfg(feature = "kusama-native")] +const KUSAMA_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; +#[cfg(feature = "westend-native")] +const WESTEND_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; +#[cfg(feature = "rococo-native")] +const ROCOCO_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; +#[cfg(feature = "rococo-native")] +const VERSI_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; +#[cfg(any( + feature = "polkadot-native", + feature = "kusama-native", + feature = "westend-native", + feature = "rococo-native" +))] +const DEFAULT_PROTOCOL_ID: &str = "dot"; + +/// Node `ChainSpec` extensions. +/// +/// Additional parameters for some Substrate core modules, +/// customizable from the chain spec. +#[derive(Default, Clone, Serialize, Deserialize, ChainSpecExtension)] +#[serde(rename_all = "camelCase")] +pub struct Extensions { + /// Block numbers with known hashes. + pub fork_blocks: sc_client_api::ForkBlocks, + /// Known bad block hashes. + pub bad_blocks: sc_client_api::BadBlocks, + /// The light sync state. + /// + /// This value will be set by the `sync-state rpc` implementation. + pub light_sync_state: sc_sync_state_rpc::LightSyncStateExtension, +} + +/// The `ChainSpec` parameterized for the polkadot runtime. +#[cfg(feature = "polkadot-native")] +pub type PolkadotChainSpec = service::GenericChainSpec; + +/// The `ChainSpec` parameterized for the kusama runtime. +#[cfg(feature = "kusama-native")] +pub type KusamaChainSpec = service::GenericChainSpec; + +/// The `ChainSpec` parameterized for the kusama runtime. +// Dummy chain spec, but that is fine when we don't have the native runtime. +#[cfg(not(feature = "kusama-native"))] +pub type KusamaChainSpec = DummyChainSpec; + +/// The `ChainSpec` parameterized for the westend runtime. +#[cfg(feature = "westend-native")] +pub type WestendChainSpec = service::GenericChainSpec; + +/// The `ChainSpec` parameterized for the westend runtime. +// Dummy chain spec, but that is fine when we don't have the native runtime. +#[cfg(not(feature = "westend-native"))] +pub type WestendChainSpec = DummyChainSpec; + +/// The `ChainSpec` parameterized for the rococo runtime. +#[cfg(feature = "rococo-native")] +pub type RococoChainSpec = service::GenericChainSpec; + +/// The `ChainSpec` parameterized for the rococo runtime. +// Dummy chain spec, but that is fine when we don't have the native runtime. +#[cfg(not(feature = "rococo-native"))] +pub type RococoChainSpec = DummyChainSpec; + +/// Extension for the Rococo genesis config to support a custom changes to the genesis state. +#[derive(serde::Serialize, serde::Deserialize)] +#[cfg(feature = "rococo-native")] +pub struct RococoGenesisExt { + /// The runtime genesis config. + runtime_genesis_config: rococo::RuntimeGenesisConfig, + /// The session length in blocks. + /// + /// If `None` is supplied, the default value is used. + session_length_in_blocks: Option, +} + +#[cfg(feature = "rococo-native")] +impl sp_runtime::BuildStorage for RococoGenesisExt { + fn assimilate_storage(&self, storage: &mut sp_core::storage::Storage) -> Result<(), String> { + sp_state_machine::BasicExternalities::execute_with_storage(storage, || { + if let Some(length) = self.session_length_in_blocks.as_ref() { + rococo_runtime_constants::time::EpochDurationInBlocks::set(length); + } + }); + self.runtime_genesis_config.assimilate_storage(storage) + } +} + +/// The default parachains host configuration. +#[cfg(any( + feature = "rococo-native", + feature = "kusama-native", + feature = "westend-native", + feature = "polkadot-native" +))] +fn default_parachains_host_configuration( +) -> polkadot_runtime_parachains::configuration::HostConfiguration +{ + use polkadot_primitives::{MAX_CODE_SIZE, MAX_POV_SIZE}; + + polkadot_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, + group_rotation_frequency: 20, + chain_availability_period: 4, + thread_availability_period: 4, + 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_max_parathread_inbound_channels: 4, + hrmp_channel_max_message_size: 1024 * 1024, + hrmp_max_parachain_outbound_channels: 4, + hrmp_max_parathread_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, + ..Default::default() + } +} + +#[cfg(any( + feature = "rococo-native", + feature = "kusama-native", + feature = "westend-native", + feature = "polkadot-native" +))] +#[test] +fn default_parachains_host_configuration_is_consistent() { + default_parachains_host_configuration().panic_if_not_consistent(); +} + +#[cfg(feature = "polkadot-native")] +fn polkadot_session_keys( + babe: BabeId, + grandpa: GrandpaId, + im_online: ImOnlineId, + para_validator: ValidatorId, + para_assignment: AssignmentId, + authority_discovery: AuthorityDiscoveryId, +) -> polkadot::SessionKeys { + polkadot::SessionKeys { + babe, + grandpa, + im_online, + para_validator, + para_assignment, + authority_discovery, + } +} + +#[cfg(feature = "kusama-native")] +fn kusama_session_keys( + babe: BabeId, + grandpa: GrandpaId, + im_online: ImOnlineId, + para_validator: ValidatorId, + para_assignment: AssignmentId, + authority_discovery: AuthorityDiscoveryId, +) -> kusama::SessionKeys { + kusama::SessionKeys { + babe, + grandpa, + im_online, + para_validator, + para_assignment, + authority_discovery, + } +} + +#[cfg(feature = "westend-native")] +fn westend_session_keys( + babe: BabeId, + grandpa: GrandpaId, + im_online: ImOnlineId, + para_validator: ValidatorId, + para_assignment: AssignmentId, + authority_discovery: AuthorityDiscoveryId, +) -> westend::SessionKeys { + westend::SessionKeys { + babe, + grandpa, + im_online, + para_validator, + para_assignment, + authority_discovery, + } +} + +#[cfg(feature = "rococo-native")] +fn rococo_session_keys( + babe: BabeId, + grandpa: GrandpaId, + im_online: ImOnlineId, + para_validator: ValidatorId, + para_assignment: AssignmentId, + authority_discovery: AuthorityDiscoveryId, + beefy: BeefyId, +) -> rococo_runtime::SessionKeys { + rococo_runtime::SessionKeys { + babe, + grandpa, + im_online, + para_validator, + para_assignment, + authority_discovery, + beefy, + } +} + +#[cfg(feature = "westend-native")] +fn westend_staging_testnet_config_genesis() -> westend::RuntimeGenesisConfig { + use hex_literal::hex; + use sp_core::crypto::UncheckedInto; + + // subkey inspect "$SECRET" + let endowed_accounts = vec![ + // 5DaVh5WRfazkGaKhx1jUu6hjz7EmRe4dtW6PKeVLim84KLe8 + hex!["42f4a4b3e0a89c835ee696205caa90dd85c8ea1d7364b646328ee919a6b2fc1e"].into(), + ]; + // SECRET='...' ./scripts/prepare-test-net.sh 4 + let initial_authorities: Vec<( + AccountId, + AccountId, + BabeId, + GrandpaId, + ImOnlineId, + ValidatorId, + AssignmentId, + AuthorityDiscoveryId, + )> = vec![ + ( + //5ERCqy118nnXDai8g4t3MjdX7ZC5PrQzQpe9vwex5cELWqbt + hex!["681af4f93073484e1acd6b27395d0d258f1a6b158c808846c8fd05ee2435056e"].into(), + //5GTS114cfQNBgpQULhMaNCPXGds6NokegCnikxDe1vqANhtn + hex!["c2463372598ebabd21ee5bc33e1d7e77f391d2df29ce2fbe6bed0d13be629a45"].into(), + //5FhGbceKeH7fuGogcBwd28ZCkAwDGYBADCTeHiYrvx2ztyRd + hex!["a097bfc6a33499ed843b711f52f523f8a7174f798a9f98620e52f4170dbe2948"] + .unchecked_into(), + //5Es7nDkJt2by5qVCCD7PZJdp76KJw1LdRCiNst5S5f4eecnz + hex!["7bde49dda82c2c9f082b807ef3ceebff96437d67b3e630c584db7a220ecafacf"] + .unchecked_into(), + //5D4e8zRjaYzFamqChGPPtu26PcKbKgUrhb7WqcNbKa2RDFUR + hex!["2c2fb730a7d9138e6d62fcf516f9ecc2d712af3f2f03ca330c9564b8c0c1bb33"] + .unchecked_into(), + //5DD3JY5ENkjcgVFbVSgUbZv7WmrnyJ8bxxu56ee6hZFiRdnh + hex!["3297a8622988cc23dd9c131e3fb8746d49e007f6e58a81d43420cd539e250e4c"] + .unchecked_into(), + //5Gpodowhud8FG9xENXR5YwTFbUAWyoEtw7sYFytFsG4z7SU6 + hex!["d2932edf775088bd088dc5a112ad867c24cc95858f77f8a1ab014de8d4f96a3f"] + .unchecked_into(), + //5GUMj8tnjL3PJZgXoiWtgLCaMVNHBNeSeTqDsvcxmaVAjKn9 + hex!["c2fb0f74591a00555a292bc4882d3158bafc4c632124cb60681f164ef81bcf72"] + .unchecked_into(), + ), + ( + //5HgDCznTkHKUjzPkQoTZGWbvbyqB7sqHDBPDKdF1FyVYM7Er + hex!["f8418f189f84814fd40cc1b2e90873e72ea789487f3b98ed42811ba76d10fc37"].into(), + //5GQTryeFwuvgmZ2tH5ZeAKZHRM9ch5WGVGo6ND9P8f9uMsNY + hex!["c002bb4af4a1bd2f33d104aef8a41878fe1ac94ba007029c4dfdefa8b698d043"].into(), + //5C7YkWSVH1zrpsE5KwW1ua1qatyphzYxiZrL24mjkxz7mUbn + hex!["022b14fbcf65a93b81f453105b9892c3fc4aa74c22c53b4abab019e1d58fbd41"] + .unchecked_into(), + //5GwFC6Tmg4fhj4PxSqHycgJxi3PDfnC9RGDsNHoRwAvXvpnZ + hex!["d77cafd3b32c8b52b0e2780a586a6e527c94f1bdec117c4e4acb0a491461ffa3"] + .unchecked_into(), + //5DSVrGURuDuh8Luzo8FYq7o2NWiUSLSN6QAVNrj9BtswWH6R + hex!["3cdb36a5a14715999faffd06c5b9e5dcdc24d4b46bc3e4df1aaad266112a7b49"] + .unchecked_into(), + //5DLEG2AupawCXGwhJtrzBRc3zAhuP8V662dDrUTzAsCiB9Ec + hex!["38134245c9919ecb20bf2eedbe943b69ba92ceb9eb5477b92b0afd3cb6ce2858"] + .unchecked_into(), + //5D83o9fDgnHxaKPkSx59hk8zYzqcgzN2mrf7cp8fiVEi7V4E + hex!["2ec917690dc1d676002e3504c530b2595490aa5a4603d9cc579b9485b8d0d854"] + .unchecked_into(), + //5DwBJquZgncRWXFxj2ydbF8LBUPPUbiq86sXWXgm8Z38m8L2 + hex!["52bae9b8dedb8058dda93ec6f57d7e5a517c4c9f002a4636fada70fed0acf376"] + .unchecked_into(), + ), + ( + //5DMHpkRpQV7NWJFfn2zQxCLiAKv7R12PWFRPHKKk5X3JkYfP + hex!["38e280b35d08db46019a210a944e4b7177665232ab679df12d6a8bbb317a2276"].into(), + //5FbJpSHmFDe5FN3DVGe1R345ZePL9nhcC9V2Cczxo7q8q6rN + hex!["9c0bc0e2469924d718ae683737f818a47c46b0612376ecca06a2ac059fe1f870"].into(), + //5E5Pm3Udzxy26KGkLE5pc8JPfQrvkYHiaXWtuEfmQsBSgep9 + hex!["58fecadc2df8182a27e999e7e1fd7c99f8ec18f2a81f9a0db38b3653613f3f4d"] + .unchecked_into(), + //5FxcystSLHtaWoy2HEgRNerj9PrUs452B6AvHVnQZm5ZQmqE + hex!["ac4d0c5e8f8486de05135c10a707f58aa29126d5eb28fdaaba00f9a505f5249d"] + .unchecked_into(), + //5E7KqVXaVGuAqiqMigpuH8oXHLVh4tmijmpJABLYANpjMkem + hex!["5a781385a0235fe8594dd101ec55ef9ba01883f8563a0cdd37b89e0303f6a578"] + .unchecked_into(), + //5H9AybjkpyZ79yN5nHuBqs6RKuZPgM7aAVVvTQsDFovgXb2A + hex!["e09570f62a062450d4406b4eb43e7f775ff954e37606646cd590d1818189501f"] + .unchecked_into(), + //5Ccgs7VwJKBawMbwMENDmj2eFAxhFdGksVHdk8aTAf4w7xox + hex!["1864832dae34df30846d5cc65973f58a2d01b337d094b1284ec3466ecc90251d"] + .unchecked_into(), + //5EsSaZZ7niJs7hmAtp4QeK19AcAuTp7WXB7N7gRipVooerq4 + hex!["7c1d92535e6d94e21cffea6633a855a7e3c9684cd2f209e5ddbdeaf5111e395b"] + .unchecked_into(), + ), + ( + //5Ea11qhmGRntQ7pyEkEydbwxvfrYwGMKW6rPERU4UiSBB6rd + hex!["6ed057d2c833c45629de2f14b9f6ce6df1edbf9421b7a638e1fb4828c2bd2651"].into(), + //5CZomCZwPB78BZMZsCiy7WSpkpHhdrN8QTSyjcK3FFEZHBor + hex!["1631ff446b3534d031adfc37b7f7aed26d2a6b3938d10496aab3345c54707429"].into(), + //5CSM6vppouFHzAVPkVFWN76DPRUG7B9qwJe892ccfSfJ8M5f + hex!["108188c43a7521e1abe737b343341c2179a3a89626c7b017c09a5b10df6f1c42"] + .unchecked_into(), + //5GwkG4std9KcjYi3ThSC7QWfhqokmYVvWEqTU9h7iswjhLnr + hex!["d7de8a43f7ee49fa3b3aaf32fb12617ec9ff7b246a46ab14e9c9d259261117fa"] + .unchecked_into(), + //5CoUk3wrCGJAWbiJEcsVjYhnd2JAHvR59jBRbSw77YrBtRL1 + hex!["209f680bc501f9b59358efe3636c51fd61238a8659bac146db909aea2595284b"] + .unchecked_into(), + //5EcSu96wprFM7G2HfJTjYu8kMParnYGznSUNTsoEKXywEsgG + hex!["70adf80395b3f59e4cab5d9da66d5a286a0b6e138652a06f72542e46912df922"] + .unchecked_into(), + //5Ge3sjpD43Cuy7rNoJQmE9WctgCn6Faw89Pe7xPs3i55eHwJ + hex!["ca5f6b970b373b303f64801a0c2cadc4fc05272c6047a2560a27d0c65589ca1d"] + .unchecked_into(), + //5EFcjHLvB2z5vd5g63n4gABmhzP5iPsKvTwd8sjfvTehNNrk + hex!["60cae7fa5a079d9fc8061d715fbcc35ef57c3b00005694c2badce22dcc5a9f1b"] + .unchecked_into(), + ), + ]; + + const ENDOWMENT: u128 = 1_000_000 * WND; + const STASH: u128 = 100 * WND; + + westend::RuntimeGenesisConfig { + system: westend::SystemConfig::default(), + balances: westend::BalancesConfig { + balances: endowed_accounts + .iter() + .map(|k: &AccountId| (k.clone(), ENDOWMENT)) + .chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH))) + .collect(), + }, + indices: westend::IndicesConfig { indices: vec![] }, + session: westend::SessionConfig { + keys: initial_authorities + .iter() + .map(|x| { + ( + x.0.clone(), + x.0.clone(), + westend_session_keys( + x.2.clone(), + x.3.clone(), + x.4.clone(), + x.5.clone(), + x.6.clone(), + x.7.clone(), + ), + ) + }) + .collect::>(), + }, + staking: westend::StakingConfig { + validator_count: 50, + minimum_validator_count: 4, + stakers: initial_authorities + .iter() + .map(|x| (x.0.clone(), x.0.clone(), STASH, westend::StakerStatus::Validator)) + .collect(), + invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(), + force_era: Forcing::ForceNone, + slash_reward_fraction: Perbill::from_percent(10), + ..Default::default() + }, + babe: westend::BabeConfig { + authorities: Default::default(), + epoch_config: Some(westend::BABE_GENESIS_EPOCH_CONFIG), + ..Default::default() + }, + grandpa: Default::default(), + im_online: Default::default(), + authority_discovery: westend::AuthorityDiscoveryConfig { + keys: vec![], + ..Default::default() + }, + vesting: westend::VestingConfig { vesting: vec![] }, + sudo: westend::SudoConfig { key: Some(endowed_accounts[0].clone()) }, + hrmp: Default::default(), + configuration: westend::ConfigurationConfig { + config: default_parachains_host_configuration(), + }, + paras: Default::default(), + registrar: westend_runtime::RegistrarConfig { + next_free_para_id: polkadot_primitives::LOWEST_PUBLIC_ID, + ..Default::default() + }, + xcm_pallet: Default::default(), + nomination_pools: Default::default(), + } +} + +#[cfg(feature = "kusama-native")] +fn kusama_staging_testnet_config_genesis() -> kusama::RuntimeGenesisConfig { + use hex_literal::hex; + use sp_core::crypto::UncheckedInto; + + // subkey inspect "$SECRET" + let endowed_accounts = vec![ + // 5CVFESwfkk7NmhQ6FwHCM9roBvr9BGa4vJHFYU8DnGQxrXvz + hex!["12b782529c22032ed4694e0f6e7d486be7daa6d12088f6bc74d593b3900b8438"].into(), + ]; + + // for i in 1 2 3 4; do for j in stash controller; do subkey inspect "$SECRET//$i//$j"; done; done + // for i in 1 2 3 4; do for j in babe; do subkey --sr25519 inspect "$SECRET//$i//$j"; done; done + // for i in 1 2 3 4; do for j in grandpa; do subkey --ed25519 inspect "$SECRET//$i//$j"; done; done + // for i in 1 2 3 4; do for j in im_online; do subkey --sr25519 inspect "$SECRET//$i//$j"; done; done + // for i in 1 2 3 4; do for j in para_validator para_assignment; do subkey --sr25519 inspect "$SECRET//$i//$j"; done; done + let initial_authorities: Vec<( + AccountId, + AccountId, + BabeId, + GrandpaId, + ImOnlineId, + ValidatorId, + AssignmentId, + AuthorityDiscoveryId, + )> = vec![ + ( + // 5DD7Q4VEfPTLEdn11CnThoHT5f9xKCrnofWJL5SsvpTghaAT + hex!["32a5718e87d16071756d4b1370c411bbbb947eb62f0e6e0b937d5cbfc0ea633b"].into(), + // 5GNzaEqhrZAtUQhbMe2gn9jBuNWfamWFZHULryFwBUXyd1cG + hex!["bee39fe862c85c91aaf343e130d30b643c6ea0b4406a980206f1df8331f7093b"].into(), + // 5FpewyS2VY8Cj3tKgSckq8ECkjd1HKHvBRnWhiHqRQsWfFC1 + hex!["a639b507ee1585e0b6498ff141d6153960794523226866d1b44eba3f25f36356"] + .unchecked_into(), + // 5EjvdwATjyFFikdZibVvx1q5uBHhphS2Mnsq5c7yfaYK25vm + hex!["76620f7c98bce8619979c2b58cf2b0aff71824126d2b039358729dad993223db"] + .unchecked_into(), + // 5FpewyS2VY8Cj3tKgSckq8ECkjd1HKHvBRnWhiHqRQsWfFC1 + hex!["a639b507ee1585e0b6498ff141d6153960794523226866d1b44eba3f25f36356"] + .unchecked_into(), + // 5FpewyS2VY8Cj3tKgSckq8ECkjd1HKHvBRnWhiHqRQsWfFC1 + hex!["a639b507ee1585e0b6498ff141d6153960794523226866d1b44eba3f25f36356"] + .unchecked_into(), + // 5FpewyS2VY8Cj3tKgSckq8ECkjd1HKHvBRnWhiHqRQsWfFC1 + hex!["a639b507ee1585e0b6498ff141d6153960794523226866d1b44eba3f25f36356"] + .unchecked_into(), + // 5FpewyS2VY8Cj3tKgSckq8ECkjd1HKHvBRnWhiHqRQsWfFC1 + hex!["a639b507ee1585e0b6498ff141d6153960794523226866d1b44eba3f25f36356"] + .unchecked_into(), + ), + ( + // 5G9VGb8ESBeS8Ca4or43RfhShzk9y7T5iTmxHk5RJsjZwsRx + hex!["b496c98a405ceab59b9e970e59ef61acd7765a19b704e02ab06c1cdfe171e40f"].into(), + // 5F7V9Y5FcxKXe1aroqvPeRiUmmeQwTFcL3u9rrPXcMuMiCNx + hex!["86d3a7571dd60139d297e55d8238d0c977b2e208c5af088f7f0136b565b0c103"].into(), + // 5GvuM53k1Z4nAB5zXJFgkRSHv4Bqo4BsvgbQWNWkiWZTMwWY + hex!["765e46067adac4d1fe6c783aa2070dfa64a19f84376659e12705d1734b3eae01"] + .unchecked_into(), + // 5HBDAaybNqjmY7ww8ZcZZY1L5LHxvpnyfqJwoB7HhR6raTmG + hex!["e2234d661bee4a04c38392c75d1566200aa9e6ae44dd98ee8765e4cc9af63cb7"] + .unchecked_into(), + // 5GvuM53k1Z4nAB5zXJFgkRSHv4Bqo4BsvgbQWNWkiWZTMwWY + hex!["765e46067adac4d1fe6c783aa2070dfa64a19f84376659e12705d1734b3eae01"] + .unchecked_into(), + // 5GvuM53k1Z4nAB5zXJFgkRSHv4Bqo4BsvgbQWNWkiWZTMwWY + hex!["765e46067adac4d1fe6c783aa2070dfa64a19f84376659e12705d1734b3eae01"] + .unchecked_into(), + // 5GvuM53k1Z4nAB5zXJFgkRSHv4Bqo4BsvgbQWNWkiWZTMwWY + hex!["765e46067adac4d1fe6c783aa2070dfa64a19f84376659e12705d1734b3eae01"] + .unchecked_into(), + // 5GvuM53k1Z4nAB5zXJFgkRSHv4Bqo4BsvgbQWNWkiWZTMwWY + hex!["765e46067adac4d1fe6c783aa2070dfa64a19f84376659e12705d1734b3eae01"] + .unchecked_into(), + ), + ( + // 5FzwpgGvk2kk9agow6KsywLYcPzjYc8suKej2bne5G5b9YU3 + hex!["ae12f70078a22882bf5135d134468f77301927aa67c376e8c55b7ff127ace115"].into(), + // 5EqoZhVC2BcsM4WjvZNidu2muKAbu5THQTBKe3EjvxXkdP7A + hex!["7addb914ec8486bbc60643d2647685dcc06373401fa80e09813b630c5831d54b"].into(), + // 5CXNq1mSKJT4Sc2CbyBBdANeSkbUvdWvE4czJjKXfBHi9sX5 + hex!["664eae1ca4713dd6abf8c15e6c041820cda3c60df97dc476c2cbf7cb82cb2d2e"] + .unchecked_into(), + // 5E8ULLQrDAtWhfnVfZmX41Yux86zNAwVJYguWJZVWrJvdhBe + hex!["5b57ed1443c8967f461db1f6eb2ada24794d163a668f1cf9d9ce3235dfad8799"] + .unchecked_into(), + // 5CXNq1mSKJT4Sc2CbyBBdANeSkbUvdWvE4czJjKXfBHi9sX5 + hex!["664eae1ca4713dd6abf8c15e6c041820cda3c60df97dc476c2cbf7cb82cb2d2e"] + .unchecked_into(), + // 5CXNq1mSKJT4Sc2CbyBBdANeSkbUvdWvE4czJjKXfBHi9sX5 + hex!["664eae1ca4713dd6abf8c15e6c041820cda3c60df97dc476c2cbf7cb82cb2d2e"] + .unchecked_into(), + // 5CXNq1mSKJT4Sc2CbyBBdANeSkbUvdWvE4czJjKXfBHi9sX5 + hex!["664eae1ca4713dd6abf8c15e6c041820cda3c60df97dc476c2cbf7cb82cb2d2e"] + .unchecked_into(), + // 5CXNq1mSKJT4Sc2CbyBBdANeSkbUvdWvE4czJjKXfBHi9sX5 + hex!["664eae1ca4713dd6abf8c15e6c041820cda3c60df97dc476c2cbf7cb82cb2d2e"] + .unchecked_into(), + ), + ( + // 5CFj6Kg9rmVn1vrqpyjau2ztyBzKeVdRKwNPiA3tqhB5HPqq + hex!["0867dbb49721126df589db100dda728dc3b475cbf414dad8f72a1d5e84897252"].into(), + // 5CwQXP6nvWzigFqNhh2jvCaW9zWVzkdveCJY3tz2MhXMjTon + hex!["26ab2b4b2eba2263b1e55ceb48f687bb0018130a88df0712fbdaf6a347d50e2a"].into(), + // 5FCd9Y7RLNyxz5wnCAErfsLbXGG34L2BaZRHzhiJcMUMd5zd + hex!["2adb17a5cafbddc7c3e00ec45b6951a8b12ce2264235b4def342513a767e5d3d"] + .unchecked_into(), + // 5HGLmrZsiTFTPp3QoS1W8w9NxByt8PVq79reqvdxNcQkByqK + hex!["e60d23f49e93c1c1f2d7c115957df5bbd7faf5ebf138d1e9d02e8b39a1f63df0"] + .unchecked_into(), + // 5FCd9Y7RLNyxz5wnCAErfsLbXGG34L2BaZRHzhiJcMUMd5zd + hex!["2adb17a5cafbddc7c3e00ec45b6951a8b12ce2264235b4def342513a767e5d3d"] + .unchecked_into(), + // 5FCd9Y7RLNyxz5wnCAErfsLbXGG34L2BaZRHzhiJcMUMd5zd + hex!["2adb17a5cafbddc7c3e00ec45b6951a8b12ce2264235b4def342513a767e5d3d"] + .unchecked_into(), + // 5FCd9Y7RLNyxz5wnCAErfsLbXGG34L2BaZRHzhiJcMUMd5zd + hex!["2adb17a5cafbddc7c3e00ec45b6951a8b12ce2264235b4def342513a767e5d3d"] + .unchecked_into(), + // 5FCd9Y7RLNyxz5wnCAErfsLbXGG34L2BaZRHzhiJcMUMd5zd + hex!["2adb17a5cafbddc7c3e00ec45b6951a8b12ce2264235b4def342513a767e5d3d"] + .unchecked_into(), + ), + ]; + + const ENDOWMENT: u128 = 1_000_000 * KSM; + const STASH: u128 = 100 * KSM; + + kusama::RuntimeGenesisConfig { + system: kusama::SystemConfig::default(), + balances: kusama::BalancesConfig { + balances: endowed_accounts + .iter() + .map(|k: &AccountId| (k.clone(), ENDOWMENT)) + .chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH))) + .collect(), + }, + indices: kusama::IndicesConfig { indices: vec![] }, + session: kusama::SessionConfig { + 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: kusama::StakingConfig { + validator_count: 50, + minimum_validator_count: 4, + stakers: initial_authorities + .iter() + .map(|x| (x.0.clone(), x.0.clone(), STASH, kusama::StakerStatus::Validator)) + .collect(), + invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(), + force_era: Forcing::ForceNone, + slash_reward_fraction: Perbill::from_percent(10), + ..Default::default() + }, + babe: kusama::BabeConfig { + authorities: Default::default(), + epoch_config: Some(kusama::BABE_GENESIS_EPOCH_CONFIG), + ..Default::default() + }, + grandpa: Default::default(), + im_online: Default::default(), + authority_discovery: kusama::AuthorityDiscoveryConfig { + keys: vec![], + ..Default::default() + }, + claims: kusama::ClaimsConfig { claims: vec![], vesting: vec![] }, + vesting: kusama::VestingConfig { vesting: vec![] }, + treasury: Default::default(), + hrmp: Default::default(), + configuration: kusama::ConfigurationConfig { + config: default_parachains_host_configuration(), + }, + paras: Default::default(), + xcm_pallet: Default::default(), + nomination_pools: Default::default(), + nis_counterpart_balances: Default::default(), + } +} + +#[cfg(feature = "rococo-native")] +fn rococo_staging_testnet_config_genesis() -> rococo_runtime::RuntimeGenesisConfig { + use hex_literal::hex; + use sp_core::crypto::UncheckedInto; + + // subkey inspect "$SECRET" + let endowed_accounts = vec![ + // 5DwBmEFPXRESyEam5SsQF1zbWSCn2kCjyLW51hJHXe9vW4xs + hex!["52bc71c1eca5353749542dfdf0af97bf764f9c2f44e860cd485f1cd86400f649"].into(), + ]; + + // ./scripts/prepare-test-net.sh 8 + let initial_authorities: Vec<( + AccountId, + AccountId, + BabeId, + GrandpaId, + ImOnlineId, + ValidatorId, + AssignmentId, + AuthorityDiscoveryId, + BeefyId, + )> = vec![ + ( + //5EHZkbp22djdbuMFH9qt1DVzSCvqi3zWpj6DAYfANa828oei + hex!["62475fe5406a7cb6a64c51d0af9d3ab5c2151bcae982fb812f7a76b706914d6a"].into(), + //5FeSEpi9UYYaWwXXb3tV88qtZkmSdB3mvgj3pXkxKyYLGhcd + hex!["9e6e781a76810fe93187af44c79272c290c2b9e2b8b92ee11466cd79d8023f50"].into(), + //5Fh6rDpMDhM363o1Z3Y9twtaCPfizGQWCi55BSykTQjGbP7H + hex!["a076ef1280d768051f21d060623da3ab5b56944d681d303ed2d4bf658c5bed35"] + .unchecked_into(), + //5CPd3zoV9Aaah4xWucuDivMHJ2nEEmpdi864nPTiyRZp4t87 + hex!["0e6d7d1afbcc6547b92995a394ba0daed07a2420be08220a5a1336c6731f0bfa"] + .unchecked_into(), + //5F7BEa1LGFksUihyatf3dCDYneB8pWzVyavnByCsm5nBgezi + hex!["86975a37211f8704e947a365b720f7a3e2757988eaa7d0f197e83dba355ef743"] + .unchecked_into(), + //5CP6oGfwqbEfML8efqm1tCZsUgRsJztp9L8ZkEUxA16W8PPz + hex!["0e07a51d3213842f8e9363ce8e444255990a225f87e80a3d651db7841e1a0205"] + .unchecked_into(), + //5HQdwiDh8Qtd5dSNWajNYpwDvoyNWWA16Y43aEkCNactFc2b + hex!["ec60e71fe4a567ef9fef99d4bbf37ffae70564b41aa6f94ef0317c13e0a5477b"] + .unchecked_into(), + //5HbSgM72xVuscsopsdeG3sCSCYdAeM1Tay9p79N6ky6vwDGq + hex!["f49eae66a0ac9f610316906ec8f1a0928e20d7059d76a5ca53cbcb5a9b50dd3c"] + .unchecked_into(), + //5DPSWdgw38Spu315r6LSvYCggeeieBAJtP5A1qzuzKhqmjVu + hex!["034f68c5661a41930c82f26a662276bf89f33467e1c850f2fb8ef687fe43d62276"] + .unchecked_into(), + ), + ( + //5DvH8oEjQPYhzCoQVo7WDU91qmQfLZvxe9wJcrojmJKebCmG + hex!["520b48452969f6ddf263b664de0adb0c729d0e0ad3b0e5f3cb636c541bc9022a"].into(), + //5ENZvCRzyXJJYup8bM6yEzb2kQHEb1NDpY2ZEyVGBkCfRdj3 + hex!["6618289af7ae8621981ffab34591e7a6486e12745dfa3fd3b0f7e6a3994c7b5b"].into(), + //5DLjSUfqZVNAADbwYLgRvHvdzXypiV1DAEaDMjcESKTcqMoM + hex!["38757d0de00a0c739e7d7984ef4bc01161bd61e198b7c01b618425c16bb5bd5f"] + .unchecked_into(), + //5HnDVBN9mD6mXyx8oryhDbJtezwNSj1VRXgLoYCBA6uEkiao + hex!["fcd5f87a6fd5707a25122a01b4dac0a8482259df7d42a9a096606df1320df08d"] + .unchecked_into(), + //5DhyXZiuB1LvqYKFgT5tRpgGsN3is2cM9QxgW7FikvakbAZP + hex!["48a910c0af90898f11bd57d37ceaea53c78994f8e1833a7ade483c9a84bde055"] + .unchecked_into(), + //5EPEWRecy2ApL5n18n3aHyU1956zXTRqaJpzDa9DoqiggNwF + hex!["669a10892119453e9feb4e3f1ee8e028916cc3240022920ad643846fbdbee816"] + .unchecked_into(), + //5ES3fw5X4bndSgLNmtPfSbM2J1kLqApVB2CCLS4CBpM1UxUZ + hex!["68bf52c482630a8d1511f2edd14f34127a7d7082219cccf7fd4c6ecdb535f80d"] + .unchecked_into(), + //5HeXbwb5PxtcRoopPZTp5CQun38atn2UudQ8p2AxR5BzoaXw + hex!["f6f8fe475130d21165446a02fb1dbce3a7bf36412e5d98f4f0473aed9252f349"] + .unchecked_into(), + //5F7nTtN8MyJV4UsXpjg7tHSnfANXZ5KRPJmkASc1ZSH2Xoa5 + hex!["03a90c2bb6d3b7000020f6152fe2e5002fa970fd1f42aafb6c8edda8dacc2ea77e"] + .unchecked_into(), + ), + ( + //5FPMzsezo1PRxYbVpJMWK7HNbR2kUxidsAAxH4BosHa4wd6S + hex!["92ef83665b39d7a565e11bf8d18d41d45a8011601c339e57a8ea88c8ff7bba6f"].into(), + //5G6NQidFG7YiXsvV7hQTLGArir9tsYqD4JDxByhgxKvSKwRx + hex!["b235f57244230589523271c27b8a490922ffd7dccc83b044feaf22273c1dc735"].into(), + //5GpZhzAVg7SAtzLvaAC777pjquPEcNy1FbNUAG2nZvhmd6eY + hex!["d2644c1ab2c63a3ad8d40ad70d4b260969e3abfe6d7e6665f50dc9f6365c9d2a"] + .unchecked_into(), + //5HAes2RQYPbYKbLBfKb88f4zoXv6pPA6Ke8CjN7dob3GpmSP + hex!["e1b68fbd84333e31486c08e6153d9a1415b2e7e71b413702b7d64e9b631184a1"] + .unchecked_into(), + //5HTXBf36LXmkFWJLokNUK6fPxVpkr2ToUnB1pvaagdGu4c1T + hex!["ee93e26259decb89afcf17ef2aa0fa2db2e1042fb8f56ecfb24d19eae8629878"] + .unchecked_into(), + //5FtAGDZYJKXkhVhAxCQrXmaP7EE2mGbBMfmKDHjfYDgq2BiU + hex!["a8e61ffacafaf546283dc92d14d7cc70ea0151a5dd81fdf73ff5a2951f2b6037"] + .unchecked_into(), + //5CtK7JHv3h6UQZ44y54skxdwSVBRtuxwPE1FYm7UZVhg8rJV + hex!["244f3421b310c68646e99cdbf4963e02067601f57756b072a4b19431448c186e"] + .unchecked_into(), + //5D4r6YaB6F7A7nvMRHNFNF6zrR9g39bqDJFenrcaFmTCRwfa + hex!["2c57f81fd311c1ab53813c6817fe67f8947f8d39258252663b3384ab4195494d"] + .unchecked_into(), + //5EPoHj8uV4fFKQHYThc6Z9fDkU7B6ih2ncVzQuDdNFb8UyhF + hex!["039d065fe4f9234f0a4f13cc3ae585f2691e9c25afa469618abb6645111f607a53"] + .unchecked_into(), + ), + ( + //5DMNx7RoX6d7JQ38NEM7DWRcW2THu92LBYZEWvBRhJeqcWgR + hex!["38f3c2f38f6d47f161e98c697bbe3ca0e47c033460afda0dda314ab4222a0404"].into(), + //5GGdKNDr9P47dpVnmtq3m8Tvowwf1ot1abw6tPsTYYFoKm2v + hex!["ba0898c1964196474c0be08d364cdf4e9e1d47088287f5235f70b0590dfe1704"].into(), + //5EjkyPCzR2SjhDZq8f7ufsw6TfkvgNRepjCRQFc4TcdXdaB1 + hex!["764186bc30fd5a02477f19948dc723d6d57ab174debd4f80ed6038ec960bfe21"] + .unchecked_into(), + //5DJV3zCBTJBLGNDCcdWrYxWDacSz84goGTa4pFeKVvehEBte + hex!["36be9069cdb4a8a07ecd51f257875150f0a8a1be44a10d9d98dabf10a030aef4"] + .unchecked_into(), + //5FHf8kpK4fPjEJeYcYon2gAPwEBubRvtwpzkUbhMWSweKPUY + hex!["8e95b9b5b4dc69790b67b566567ca8bf8cdef3a3a8bb65393c0d1d1c87cd2d2c"] + .unchecked_into(), + //5F9FsRjpecP9GonktmtFL3kjqNAMKjHVFjyjRdTPa4hbQRZA + hex!["882d72965e642677583b333b2d173ac94b5fd6c405c76184bb14293be748a13b"] + .unchecked_into(), + //5F1FZWZSj3JyTLs8sRBxU6QWyGLSL9BMRtmSKDmVEoiKFxSP + hex!["821271c99c958b9220f1771d9f5e29af969edfa865631dba31e1ab7bc0582b75"] + .unchecked_into(), + //5CtgRR74VypK4h154s369abs78hDUxZSJqcbWsfXvsjcHJNA + hex!["2496f28d887d84705c6dae98aee8bf90fc5ad10bb5545eca1de6b68425b70f7c"] + .unchecked_into(), + //5CPx6dsr11SCJHKFkcAQ9jpparS7FwXQBrrMznRo4Hqv1PXz + hex!["0307d29bbf6a5c4061c2157b44fda33b7bb4ec52a5a0305668c74688cedf288d58"] + .unchecked_into(), + ), + ( + //5C8AL1Zb4bVazgT3EgDxFgcow1L4SJjVu44XcLC9CrYqFN4N + hex!["02a2d8cfcf75dda85fafc04ace3bcb73160034ed1964c43098fb1fe831de1b16"].into(), + //5FLYy3YKsAnooqE4hCudttAsoGKbVG3hYYBtVzwMjJQrevPa + hex!["90cab33f0bb501727faa8319f0845faef7d31008f178b65054b6629fe531b772"].into(), + //5Et3tfbVf1ByFThNAuUq5pBssdaPPskip5yob5GNyUFojXC7 + hex!["7c94715e5dd8ab54221b1b6b2bfa5666f593f28a92a18e28052531de1bd80813"] + .unchecked_into(), + //5EX1JBghGbQqWohTPU6msR9qZ2nYPhK9r3RTQ2oD1K8TCxaG + hex!["6c878e33b83c20324238d22240f735457b6fba544b383e70bb62a27b57380c81"] + .unchecked_into(), + //5GqL8RbVAuNXpDhjQi1KrS1MyNuKhvus2AbmQwRGjpuGZmFu + hex!["d2f9d537ffa59919a4028afdb627c14c14c97a1547e13e8e82203d2049b15b1a"] + .unchecked_into(), + //5EUNaBpX9mJgcmLQHyG5Pkms6tbDiKuLbeTEJS924Js9cA1N + hex!["6a8570b9c6408e54bacf123cc2bb1b0f087f9c149147d0005badba63a5a4ac01"] + .unchecked_into(), + //5CaZuueRVpMATZG4hkcrgDoF4WGixuz7zu83jeBdY3bgWGaG + hex!["16c69ea8d595e80b6736f44be1eaeeef2ac9c04a803cc4fd944364cb0d617a33"] + .unchecked_into(), + //5DABsdQCDUGuhzVGWe5xXzYQ9rtrVxRygW7RXf9Tsjsw1aGJ + hex!["306ac5c772fe858942f92b6e28bd82fb7dd8cdd25f9a4626c1b0eee075fcb531"] + .unchecked_into(), + //5H91T5mHhoCw9JJG4NjghDdQyhC6L7XcSuBWKD3q3TAhEVvQ + hex!["02fb0330356e63a35dd930bc74525edf28b3bf5eb44aab9e9e4962c8309aaba6a6"] + .unchecked_into(), + ), + ( + //5C8XbDXdMNKJrZSrQURwVCxdNdk8AzG6xgLggbzuA399bBBF + hex!["02ea6bfa8b23b92fe4b5db1063a1f9475e3acd0ab61e6b4f454ed6ba00b5f864"].into(), + //5GsyzFP8qtF8tXPSsjhjxAeU1v7D1PZofuQKN9TdCc7Dp1JM + hex!["d4ffc4c05b47d1115ad200f7f86e307b20b46c50e1b72a912ec4f6f7db46b616"].into(), + //5GHWB8ZDzegLcMW7Gdd1BS6WHVwDdStfkkE4G7KjPjZNJBtD + hex!["bab3cccdcc34401e9b3971b96a662686cf755aa869a5c4b762199ce531b12c5b"] + .unchecked_into(), + //5GzDPGbUM9uH52ZEwydasTj8edokGUJ7vEpoFWp9FE1YNuFB + hex!["d9c056c98ca0e6b4eb7f5c58c007c1db7be0fe1f3776108f797dd4990d1ccc33"] + .unchecked_into(), + //5GWZbVkJEfWZ7fRca39YAQeqri2Z7pkeHyd7rUctUHyQifLp + hex!["c4a980da30939d5bb9e4a734d12bf81259ae286aa21fa4b65405347fa40eff35"] + .unchecked_into(), + //5CmLCFeSurRXXtwMmLcVo7sdJ9EqDguvJbuCYDcHkr3cpqyE + hex!["1efc23c0b51ad609ab670ecf45807e31acbd8e7e5cb7c07cf49ee42992d2867c"] + .unchecked_into(), + //5DnsSy8a8pfE2aFjKBDtKw7WM1V4nfE5sLzP15MNTka53GqS + hex!["4c64d3f06d28adeb36a892fdaccecace150bec891f04694448a60b74fa469c22"] + .unchecked_into(), + //5CZdFnyzZvKetZTeUwj5APAYskVJe4QFiTezo5dQNsrnehGd + hex!["160ea09c5717270e958a3da42673fa011613a9539b2e4ebcad8626bc117ca04a"] + .unchecked_into(), + //5HgoR9JJkdBusxKrrs3zgd3ToppgNoGj1rDyAJp4e7eZiYyT + hex!["020019a8bb188f8145d02fa855e9c36e9914457d37c500e03634b5223aa5702474"] + .unchecked_into(), + ), + ( + //5HinEonzr8MywkqedcpsmwpxKje2jqr9miEwuzyFXEBCvVXM + hex!["fa373e25a1c4fe19c7148acde13bc3db1811cf656dc086820f3dda736b9c4a00"].into(), + //5EHJbj6Td6ks5HDnyfN4ttTSi57osxcQsQexm7XpazdeqtV7 + hex!["62145d721967bd88622d08625f0f5681463c0f1b8bcd97eb3c2c53f7660fd513"].into(), + //5EeCsC58XgJ1DFaoYA1WktEpP27jvwGpKdxPMFjicpLeYu96 + hex!["720537e2c1c554654d73b3889c3ef4c3c2f95a65dd3f7c185ebe4afebed78372"] + .unchecked_into(), + //5DnEySxbnppWEyN8cCLqvGjAorGdLRg2VmkY96dbJ1LHFK8N + hex!["4bea0b37e0cce9bddd80835fa2bfd5606f5dcfb8388bbb10b10c483f0856cf14"] + .unchecked_into(), + //5E1Y1FJ7dVP7qtE3wm241pTm72rTMcDT5Jd8Czv7Pwp7N3AH + hex!["560d90ca51e9c9481b8a9810060e04d0708d246714960439f804e5c6f40ca651"] + .unchecked_into(), + //5CAC278tFCHAeHYqE51FTWYxHmeLcENSS1RG77EFRTvPZMJT + hex!["042f07fc5268f13c026bbe199d63e6ac77a0c2a780f71cda05cee5a6f1b3f11f"] + .unchecked_into(), + //5HjRTLWcQjZzN3JDvaj1UzjNSayg5ZD9ZGWMstaL7Ab2jjAa + hex!["fab485e87ed1537d089df521edf983a777c57065a702d7ed2b6a2926f31da74f"] + .unchecked_into(), + //5ELv74v7QcsS6FdzvG4vL2NnYDGWmRnJUSMKYwdyJD7Xcdi7 + hex!["64d59feddb3d00316a55906953fb3db8985797472bd2e6c7ea1ab730cc339d7f"] + .unchecked_into(), + //5FaUcPt4fPz93vBhcrCJqmDkjYZ7jCbzAF56QJoCmvPaKrmx + hex!["033f1a6d47fe86f88934e4b83b9fae903b92b5dcf4fec97d5e3e8bf4f39df03685"] + .unchecked_into(), + ), + ( + //5Ey3NQ3dfabaDc16NUv7wRLsFCMDFJSqZFzKVycAsWuUC6Di + hex!["8062e9c21f1d92926103119f7e8153cebdb1e5ab3e52d6f395be80bb193eab47"].into(), + //5HiWsuSBqt8nS9pnggexXuHageUifVPKPHDE2arTKqhTp1dV + hex!["fa0388fa88f3f0cb43d583e2571fbc0edad57dff3a6fd89775451dd2c2b8ea00"].into(), + //5H168nKX2Yrfo3bxj7rkcg25326Uv3CCCnKUGK6uHdKMdPt8 + hex!["da6b2df18f0f9001a6dcf1d301b92534fe9b1f3ccfa10c49449fee93adaa8349"] + .unchecked_into(), + //5DrA2fZdzmNqT5j6DXNwVxPBjDV9jhkAqvjt6Us3bQHKy3cF + hex!["4ee66173993dd0db5d628c4c9cb61a27b76611ad3c3925947f0d0011ee2c5dcc"] + .unchecked_into(), + //5FNFDUGNLUtqg5LgrwYLNmBiGoP8KRxsvQpBkc7GQP6qaBUG + hex!["92156f54a114ee191415898f2da013d9db6a5362d6b36330d5fc23e27360ab66"] + .unchecked_into(), + //5Gx6YeNhynqn8qkda9QKpc9S7oDr4sBrfAu516d3sPpEt26F + hex!["d822d4088b20dca29a580a577a97d6f024bb24c9550bebdfd7d2d18e946a1c7d"] + .unchecked_into(), + //5DhDcHqwxoes5s89AyudGMjtZXx1nEgrk5P45X88oSTR3iyx + hex!["481538f8c2c011a76d7d57db11c2789a5e83b0f9680dc6d26211d2f9c021ae4c"] + .unchecked_into(), + //5DqAvikdpfRdk5rR35ZobZhqaC5bJXZcEuvzGtexAZP1hU3T + hex!["4e262811acdfe94528bfc3c65036080426a0e1301b9ada8d687a70ffcae99c26"] + .unchecked_into(), + //5E41Znrr2YtZu8bZp3nvRuLVHg3jFksfQ3tXuviLku4wsao7 + hex!["025e84e95ed043e387ddb8668176b42f8e2773ddd84f7f58a6d9bf436a4b527986"] + .unchecked_into(), + ), + ]; + + const ENDOWMENT: u128 = 1_000_000 * ROC; + const STASH: u128 = 100 * ROC; + + rococo_runtime::RuntimeGenesisConfig { + system: rococo_runtime::SystemConfig::default(), + balances: rococo_runtime::BalancesConfig { + balances: endowed_accounts + .iter() + .map(|k: &AccountId| (k.clone(), ENDOWMENT)) + .chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH))) + .collect(), + }, + beefy: Default::default(), + indices: rococo_runtime::IndicesConfig { indices: vec![] }, + session: rococo_runtime::SessionConfig { + keys: initial_authorities + .iter() + .map(|x| { + ( + x.0.clone(), + x.0.clone(), + rococo_session_keys( + x.2.clone(), + x.3.clone(), + x.4.clone(), + x.5.clone(), + x.6.clone(), + x.7.clone(), + x.8.clone(), + ), + ) + }) + .collect::>(), + }, + phragmen_election: Default::default(), + babe: rococo_runtime::BabeConfig { + authorities: Default::default(), + epoch_config: Some(rococo_runtime::BABE_GENESIS_EPOCH_CONFIG), + ..Default::default() + }, + grandpa: Default::default(), + im_online: Default::default(), + democracy: rococo_runtime::DemocracyConfig::default(), + council: rococo::CouncilConfig { members: vec![], phantom: Default::default() }, + technical_committee: rococo::TechnicalCommitteeConfig { + members: vec![], + phantom: Default::default(), + }, + technical_membership: Default::default(), + treasury: Default::default(), + authority_discovery: rococo_runtime::AuthorityDiscoveryConfig { + keys: vec![], + ..Default::default() + }, + claims: rococo::ClaimsConfig { claims: vec![], vesting: vec![] }, + vesting: rococo::VestingConfig { vesting: vec![] }, + sudo: rococo_runtime::SudoConfig { key: Some(endowed_accounts[0].clone()) }, + paras: rococo_runtime::ParasConfig { paras: vec![], ..Default::default() }, + hrmp: Default::default(), + configuration: rococo_runtime::ConfigurationConfig { + config: default_parachains_host_configuration(), + }, + registrar: rococo_runtime::RegistrarConfig { + next_free_para_id: polkadot_primitives::LOWEST_PUBLIC_ID, + ..Default::default() + }, + xcm_pallet: Default::default(), + nis_counterpart_balances: Default::default(), + } +} + +/// Returns the properties for the [`PolkadotChainSpec`]. +pub fn polkadot_chain_spec_properties() -> serde_json::map::Map { + serde_json::json!({ + "tokenDecimals": 10, + }) + .as_object() + .expect("Map given; qed") + .clone() +} + +/// Staging testnet config. +#[cfg(feature = "kusama-native")] +pub fn kusama_staging_testnet_config() -> Result { + let boot_nodes = vec![]; + + #[allow(deprecated)] + Ok(KusamaChainSpec::from_genesis( + "Kusama Staging Testnet", + "kusama_staging_testnet", + ChainType::Live, + move || kusama_staging_testnet_config_genesis(), + boot_nodes, + Some( + TelemetryEndpoints::new(vec![(KUSAMA_STAGING_TELEMETRY_URL.to_string(), 0)]) + .expect("Kusama Staging telemetry url is valid; qed"), + ), + Some(DEFAULT_PROTOCOL_ID), + None, + None, + Default::default(), + kusama::WASM_BINARY.ok_or("Kusama development wasm not available")?, + )) +} + +/// Westend staging testnet config. +#[cfg(feature = "westend-native")] +pub fn westend_staging_testnet_config() -> Result { + let boot_nodes = vec![]; + + #[allow(deprecated)] + Ok(WestendChainSpec::from_genesis( + "Westend Staging Testnet", + "westend_staging_testnet", + ChainType::Live, + move || westend_staging_testnet_config_genesis(), + boot_nodes, + Some( + TelemetryEndpoints::new(vec![(WESTEND_STAGING_TELEMETRY_URL.to_string(), 0)]) + .expect("Westend Staging telemetry url is valid; qed"), + ), + Some(DEFAULT_PROTOCOL_ID), + None, + None, + Default::default(), + westend::WASM_BINARY.ok_or("Westend development wasm not available")?, + )) +} + +/// Rococo staging testnet config. +#[cfg(feature = "rococo-native")] +pub fn rococo_staging_testnet_config() -> Result { + let boot_nodes = vec![]; + + #[allow(deprecated)] + Ok(RococoChainSpec::from_genesis( + "Rococo Staging Testnet", + "rococo_staging_testnet", + ChainType::Live, + move || RococoGenesisExt { + runtime_genesis_config: rococo_staging_testnet_config_genesis(), + session_length_in_blocks: None, + }, + boot_nodes, + Some( + TelemetryEndpoints::new(vec![(ROCOCO_STAGING_TELEMETRY_URL.to_string(), 0)]) + .expect("Rococo Staging telemetry url is valid; qed"), + ), + Some(DEFAULT_PROTOCOL_ID), + None, + None, + Default::default(), + rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?, + )) +} + +pub fn versi_chain_spec_properties() -> serde_json::map::Map { + serde_json::json!({ + "ss58Format": 42, + "tokenDecimals": 12, + "tokenSymbol": "VRS", + }) + .as_object() + .expect("Map given; qed") + .clone() +} + +/// Versi staging testnet config. +#[cfg(feature = "rococo-native")] +pub fn versi_staging_testnet_config() -> Result { + let boot_nodes = vec![]; + + #[allow(deprecated)] + Ok(RococoChainSpec::from_genesis( + "Versi Staging Testnet", + "versi_staging_testnet", + ChainType::Live, + move || RococoGenesisExt { + runtime_genesis_config: rococo_staging_testnet_config_genesis(), + session_length_in_blocks: Some(100), + }, + boot_nodes, + Some( + TelemetryEndpoints::new(vec![(VERSI_STAGING_TELEMETRY_URL.to_string(), 0)]) + .expect("Versi Staging telemetry url is valid; qed"), + ), + Some("versi"), + None, + Some(versi_chain_spec_properties()), + Default::default(), + rococo::WASM_BINARY.ok_or("Versi development wasm not available")?, + )) +} + +/// 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, + ImOnlineId, + 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, keys.7, 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, + ImOnlineId, + 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), + get_from_seed::(seed), + ) +} + +#[cfg(any( + feature = "polkadot-native", + feature = "kusama-native", + feature = "westend-native", + feature = "rococo-native" +))] +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 create polkadot `RuntimeGenesisConfig` for testing +#[cfg(feature = "polkadot-native")] +pub fn polkadot_testnet_genesis( + initial_authorities: Vec<( + AccountId, + AccountId, + BabeId, + GrandpaId, + ImOnlineId, + ValidatorId, + AssignmentId, + AuthorityDiscoveryId, + )>, + _root_key: AccountId, + endowed_accounts: Option>, +) -> polkadot::RuntimeGenesisConfig { + let endowed_accounts: Vec = endowed_accounts.unwrap_or_else(testnet_accounts); + + const ENDOWMENT: u128 = 1_000_000 * DOT; + const STASH: u128 = 100 * DOT; + + polkadot::RuntimeGenesisConfig { + system: polkadot::SystemConfig::default(), + indices: polkadot::IndicesConfig { indices: vec![] }, + balances: polkadot::BalancesConfig { + balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(), + }, + session: polkadot::SessionConfig { + 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: polkadot::StakingConfig { + minimum_validator_count: 1, + validator_count: initial_authorities.len() as u32, + stakers: initial_authorities + .iter() + .map(|x| (x.0.clone(), x.0.clone(), STASH, polkadot::StakerStatus::Validator)) + .collect(), + invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(), + force_era: Forcing::NotForcing, + slash_reward_fraction: Perbill::from_percent(10), + ..Default::default() + }, + phragmen_election: Default::default(), + democracy: polkadot::DemocracyConfig::default(), + council: polkadot::CouncilConfig { members: vec![], phantom: Default::default() }, + technical_committee: polkadot::TechnicalCommitteeConfig { + members: vec![], + phantom: Default::default(), + }, + technical_membership: Default::default(), + babe: polkadot::BabeConfig { + authorities: Default::default(), + epoch_config: Some(polkadot::BABE_GENESIS_EPOCH_CONFIG), + ..Default::default() + }, + grandpa: Default::default(), + im_online: Default::default(), + authority_discovery: polkadot::AuthorityDiscoveryConfig { + keys: vec![], + ..Default::default() + }, + claims: polkadot::ClaimsConfig { claims: vec![], vesting: vec![] }, + vesting: polkadot::VestingConfig { vesting: vec![] }, + treasury: Default::default(), + hrmp: Default::default(), + configuration: polkadot::ConfigurationConfig { + config: default_parachains_host_configuration(), + }, + paras: Default::default(), + xcm_pallet: Default::default(), + nomination_pools: Default::default(), + } +} + +/// Helper function to create kusama `RuntimeGenesisConfig` for testing +#[cfg(feature = "kusama-native")] +pub fn kusama_testnet_genesis( + initial_authorities: Vec<( + AccountId, + AccountId, + BabeId, + GrandpaId, + ImOnlineId, + ValidatorId, + AssignmentId, + AuthorityDiscoveryId, + )>, + _root_key: AccountId, + endowed_accounts: Option>, +) -> kusama::RuntimeGenesisConfig { + let endowed_accounts: Vec = endowed_accounts.unwrap_or_else(testnet_accounts); + + const ENDOWMENT: u128 = 1_000_000 * KSM; + const STASH: u128 = 100 * KSM; + + kusama::RuntimeGenesisConfig { + system: kusama::SystemConfig::default(), + indices: kusama::IndicesConfig { indices: vec![] }, + balances: kusama::BalancesConfig { + balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(), + }, + session: kusama::SessionConfig { + 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: kusama::StakingConfig { + minimum_validator_count: 1, + validator_count: initial_authorities.len() as u32, + stakers: initial_authorities + .iter() + .map(|x| (x.0.clone(), x.0.clone(), STASH, kusama::StakerStatus::Validator)) + .collect(), + invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(), + force_era: Forcing::NotForcing, + slash_reward_fraction: Perbill::from_percent(10), + ..Default::default() + }, + babe: kusama::BabeConfig { + authorities: Default::default(), + epoch_config: Some(kusama::BABE_GENESIS_EPOCH_CONFIG), + ..Default::default() + }, + grandpa: Default::default(), + im_online: Default::default(), + authority_discovery: kusama::AuthorityDiscoveryConfig { + keys: vec![], + ..Default::default() + }, + claims: kusama::ClaimsConfig { claims: vec![], vesting: vec![] }, + vesting: kusama::VestingConfig { vesting: vec![] }, + treasury: Default::default(), + hrmp: Default::default(), + configuration: kusama::ConfigurationConfig { + config: default_parachains_host_configuration(), + }, + paras: Default::default(), + xcm_pallet: Default::default(), + nomination_pools: Default::default(), + nis_counterpart_balances: Default::default(), + } +} + +/// Helper function to create westend `RuntimeGenesisConfig` for testing +#[cfg(feature = "westend-native")] +pub fn westend_testnet_genesis( + initial_authorities: Vec<( + AccountId, + AccountId, + BabeId, + GrandpaId, + ImOnlineId, + ValidatorId, + AssignmentId, + AuthorityDiscoveryId, + )>, + root_key: AccountId, + endowed_accounts: Option>, +) -> westend::RuntimeGenesisConfig { + let endowed_accounts: Vec = endowed_accounts.unwrap_or_else(testnet_accounts); + + const ENDOWMENT: u128 = 1_000_000 * WND; + const STASH: u128 = 100 * WND; + + westend::RuntimeGenesisConfig { + system: westend::SystemConfig::default(), + indices: westend::IndicesConfig { indices: vec![] }, + balances: westend::BalancesConfig { + balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(), + }, + session: westend::SessionConfig { + keys: initial_authorities + .iter() + .map(|x| { + ( + x.0.clone(), + x.0.clone(), + westend_session_keys( + x.2.clone(), + x.3.clone(), + x.4.clone(), + x.5.clone(), + x.6.clone(), + x.7.clone(), + ), + ) + }) + .collect::>(), + }, + staking: westend::StakingConfig { + minimum_validator_count: 1, + validator_count: initial_authorities.len() as u32, + stakers: initial_authorities + .iter() + .map(|x| (x.0.clone(), x.0.clone(), STASH, westend::StakerStatus::Validator)) + .collect(), + invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(), + force_era: Forcing::NotForcing, + slash_reward_fraction: Perbill::from_percent(10), + ..Default::default() + }, + babe: westend::BabeConfig { + authorities: Default::default(), + epoch_config: Some(westend::BABE_GENESIS_EPOCH_CONFIG), + ..Default::default() + }, + grandpa: Default::default(), + im_online: Default::default(), + authority_discovery: westend::AuthorityDiscoveryConfig { + keys: vec![], + ..Default::default() + }, + vesting: westend::VestingConfig { vesting: vec![] }, + sudo: westend::SudoConfig { key: Some(root_key) }, + hrmp: Default::default(), + configuration: westend::ConfigurationConfig { + config: default_parachains_host_configuration(), + }, + paras: Default::default(), + registrar: westend_runtime::RegistrarConfig { + next_free_para_id: polkadot_primitives::LOWEST_PUBLIC_ID, + ..Default::default() + }, + xcm_pallet: Default::default(), + nomination_pools: Default::default(), + } +} + +/// Helper function to create rococo `RuntimeGenesisConfig` for testing +#[cfg(feature = "rococo-native")] +pub fn rococo_testnet_genesis( + initial_authorities: Vec<( + AccountId, + AccountId, + BabeId, + GrandpaId, + ImOnlineId, + ValidatorId, + AssignmentId, + AuthorityDiscoveryId, + BeefyId, + )>, + root_key: AccountId, + endowed_accounts: Option>, +) -> rococo_runtime::RuntimeGenesisConfig { + let endowed_accounts: Vec = endowed_accounts.unwrap_or_else(testnet_accounts); + + const ENDOWMENT: u128 = 1_000_000 * ROC; + + rococo_runtime::RuntimeGenesisConfig { + system: rococo_runtime::SystemConfig::default(), + beefy: Default::default(), + indices: rococo_runtime::IndicesConfig { indices: vec![] }, + balances: rococo_runtime::BalancesConfig { + balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(), + }, + session: rococo_runtime::SessionConfig { + keys: initial_authorities + .iter() + .map(|x| { + ( + x.0.clone(), + x.0.clone(), + rococo_session_keys( + x.2.clone(), + x.3.clone(), + x.4.clone(), + x.5.clone(), + x.6.clone(), + x.7.clone(), + x.8.clone(), + ), + ) + }) + .collect::>(), + }, + babe: rococo_runtime::BabeConfig { + authorities: Default::default(), + epoch_config: Some(rococo_runtime::BABE_GENESIS_EPOCH_CONFIG), + ..Default::default() + }, + grandpa: Default::default(), + im_online: Default::default(), + phragmen_election: Default::default(), + democracy: rococo::DemocracyConfig::default(), + council: rococo::CouncilConfig { members: vec![], phantom: Default::default() }, + technical_committee: rococo::TechnicalCommitteeConfig { + members: vec![], + phantom: Default::default(), + }, + technical_membership: Default::default(), + treasury: Default::default(), + claims: rococo::ClaimsConfig { claims: vec![], vesting: vec![] }, + vesting: rococo::VestingConfig { vesting: vec![] }, + authority_discovery: rococo_runtime::AuthorityDiscoveryConfig { + keys: vec![], + ..Default::default() + }, + sudo: rococo_runtime::SudoConfig { key: Some(root_key.clone()) }, + hrmp: Default::default(), + configuration: rococo_runtime::ConfigurationConfig { + config: polkadot_runtime_parachains::configuration::HostConfiguration { + max_validators_per_core: Some(1), + ..default_parachains_host_configuration() + }, + }, + paras: rococo_runtime::ParasConfig { paras: vec![], ..Default::default() }, + registrar: rococo_runtime::RegistrarConfig { + next_free_para_id: polkadot_primitives::LOWEST_PUBLIC_ID, + ..Default::default() + }, + xcm_pallet: Default::default(), + nis_counterpart_balances: Default::default(), + } +} + +#[cfg(feature = "polkadot-native")] +fn polkadot_development_config_genesis() -> polkadot::RuntimeGenesisConfig { + polkadot_testnet_genesis( + vec![get_authority_keys_from_seed_no_beefy("Alice")], + get_account_id_from_seed::("Alice"), + None, + ) +} + +#[cfg(feature = "kusama-native")] +fn kusama_development_config_genesis() -> kusama::RuntimeGenesisConfig { + kusama_testnet_genesis( + vec![get_authority_keys_from_seed_no_beefy("Alice")], + get_account_id_from_seed::("Alice"), + None, + ) +} + +#[cfg(feature = "westend-native")] +fn westend_development_config_genesis() -> westend::RuntimeGenesisConfig { + westend_testnet_genesis( + vec![get_authority_keys_from_seed_no_beefy("Alice")], + get_account_id_from_seed::("Alice"), + None, + ) +} + +#[cfg(feature = "rococo-native")] +fn rococo_development_config_genesis() -> rococo_runtime::RuntimeGenesisConfig { + rococo_testnet_genesis( + vec![get_authority_keys_from_seed("Alice")], + get_account_id_from_seed::("Alice"), + None, + ) +} + +/// Polkadot development config (single validator Alice) +#[cfg(feature = "polkadot-native")] +pub fn polkadot_development_config() -> Result { + #[allow(deprecated)] + Ok(PolkadotChainSpec::from_genesis( + "Development", + "polkadot_dev", + ChainType::Development, + move || polkadot_development_config_genesis(), + vec![], + None, + Some(DEFAULT_PROTOCOL_ID), + None, + Some(polkadot_chain_spec_properties()), + Default::default(), + polkadot::WASM_BINARY.ok_or("Polkadot development wasm not available")?, + )) +} + +/// Kusama development config (single validator Alice) +#[cfg(feature = "kusama-native")] +pub fn kusama_development_config() -> Result { + #[allow(deprecated)] + Ok(KusamaChainSpec::from_genesis( + "Development", + "kusama_dev", + ChainType::Development, + move || kusama_development_config_genesis(), + vec![], + None, + Some(DEFAULT_PROTOCOL_ID), + None, + None, + Default::default(), + kusama::WASM_BINARY.ok_or("Kusama development wasm not available")?, + )) +} + +/// Westend development config (single validator Alice) +#[cfg(feature = "westend-native")] +pub fn westend_development_config() -> Result { + #[allow(deprecated)] + Ok(WestendChainSpec::from_genesis( + "Development", + "westend_dev", + ChainType::Development, + move || westend_development_config_genesis(), + vec![], + None, + Some(DEFAULT_PROTOCOL_ID), + None, + None, + Default::default(), + westend::WASM_BINARY.ok_or("Westend development wasm not available")?, + )) +} + +/// Rococo development config (single validator Alice) +#[cfg(feature = "rococo-native")] +pub fn rococo_development_config() -> Result { + #[allow(deprecated)] + Ok(RococoChainSpec::from_genesis( + "Development", + "rococo_dev", + ChainType::Development, + move || RococoGenesisExt { + runtime_genesis_config: rococo_development_config_genesis(), + // Use 1 minute session length. + session_length_in_blocks: Some(10), + }, + vec![], + None, + Some(DEFAULT_PROTOCOL_ID), + None, + None, + Default::default(), + rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?, + )) +} + +/// `Versi` development config (single validator Alice) +#[cfg(feature = "rococo-native")] +pub fn versi_development_config() -> Result { + #[allow(deprecated)] + Ok(RococoChainSpec::from_genesis( + "Development", + "versi_dev", + ChainType::Development, + move || RococoGenesisExt { + runtime_genesis_config: rococo_development_config_genesis(), + // Use 1 minute session length. + session_length_in_blocks: Some(10), + }, + vec![], + None, + Some("versi"), + None, + None, + Default::default(), + rococo::WASM_BINARY.ok_or("Versi development wasm not available")?, + )) +} + +/// Wococo development config (single validator Alice) +#[cfg(feature = "rococo-native")] +pub fn wococo_development_config() -> Result { + const WOCOCO_DEV_PROTOCOL_ID: &str = "woco"; + + #[allow(deprecated)] + Ok(RococoChainSpec::from_genesis( + "Development", + "wococo_dev", + ChainType::Development, + move || RococoGenesisExt { + runtime_genesis_config: rococo_development_config_genesis(), + // Use 1 minute session length. + session_length_in_blocks: Some(10), + }, + vec![], + None, + Some(WOCOCO_DEV_PROTOCOL_ID), + None, + None, + Default::default(), + rococo::WASM_BINARY.ok_or("Wococo development wasm not available")?, + )) +} + +#[cfg(feature = "polkadot-native")] +fn polkadot_local_testnet_genesis() -> polkadot::RuntimeGenesisConfig { + polkadot_testnet_genesis( + vec![ + get_authority_keys_from_seed_no_beefy("Alice"), + get_authority_keys_from_seed_no_beefy("Bob"), + ], + get_account_id_from_seed::("Alice"), + None, + ) +} + +/// Polkadot local testnet config (multivalidator Alice + Bob) +#[cfg(feature = "polkadot-native")] +pub fn polkadot_local_testnet_config() -> Result { + #[allow(deprecated)] + Ok(PolkadotChainSpec::from_genesis( + "Local Testnet", + "local_testnet", + ChainType::Local, + move || polkadot_local_testnet_genesis(), + vec![], + None, + Some(DEFAULT_PROTOCOL_ID), + None, + Some(polkadot_chain_spec_properties()), + Default::default(), + polkadot::WASM_BINARY.ok_or("Polkadot development wasm not available")?, + )) +} + +#[cfg(feature = "kusama-native")] +fn kusama_local_testnet_genesis() -> kusama::RuntimeGenesisConfig { + kusama_testnet_genesis( + vec![ + get_authority_keys_from_seed_no_beefy("Alice"), + get_authority_keys_from_seed_no_beefy("Bob"), + ], + get_account_id_from_seed::("Alice"), + None, + ) +} + +/// Kusama local testnet config (multivalidator Alice + Bob) +#[cfg(feature = "kusama-native")] +pub fn kusama_local_testnet_config() -> Result { + #[allow(deprecated)] + Ok(KusamaChainSpec::from_genesis( + "Kusama Local Testnet", + "kusama_local_testnet", + ChainType::Local, + move || kusama_local_testnet_genesis(), + vec![], + None, + Some(DEFAULT_PROTOCOL_ID), + None, + None, + Default::default(), + kusama::WASM_BINARY.ok_or("Kusama development wasm not available")?, + )) +} + +#[cfg(feature = "westend-native")] +fn westend_local_testnet_genesis() -> westend::RuntimeGenesisConfig { + westend_testnet_genesis( + vec![ + get_authority_keys_from_seed_no_beefy("Alice"), + get_authority_keys_from_seed_no_beefy("Bob"), + ], + get_account_id_from_seed::("Alice"), + None, + ) +} + +/// Westend local testnet config (multivalidator Alice + Bob) +#[cfg(feature = "westend-native")] +pub fn westend_local_testnet_config() -> Result { + #[allow(deprecated)] + Ok(WestendChainSpec::from_genesis( + "Westend Local Testnet", + "westend_local_testnet", + ChainType::Local, + move || westend_local_testnet_genesis(), + vec![], + None, + Some(DEFAULT_PROTOCOL_ID), + None, + None, + Default::default(), + westend::WASM_BINARY.ok_or("Westend development wasm not available")?, + )) +} + +#[cfg(feature = "rococo-native")] +fn rococo_local_testnet_genesis() -> rococo_runtime::RuntimeGenesisConfig { + rococo_testnet_genesis( + vec![get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob")], + get_account_id_from_seed::("Alice"), + None, + ) +} + +/// Rococo local testnet config (multivalidator Alice + Bob) +#[cfg(feature = "rococo-native")] +pub fn rococo_local_testnet_config() -> Result { + #[allow(deprecated)] + Ok(RococoChainSpec::from_genesis( + "Rococo Local Testnet", + "rococo_local_testnet", + ChainType::Local, + move || RococoGenesisExt { + runtime_genesis_config: rococo_local_testnet_genesis(), + // Use 1 minute session length. + session_length_in_blocks: Some(10), + }, + vec![], + None, + Some(DEFAULT_PROTOCOL_ID), + None, + None, + Default::default(), + rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?, + )) +} + +/// Wococo is a temporary testnet that uses almost the same runtime as rococo. +#[cfg(feature = "rococo-native")] +fn wococo_local_testnet_genesis() -> rococo_runtime::RuntimeGenesisConfig { + rococo_testnet_genesis( + vec![ + get_authority_keys_from_seed("Alice"), + get_authority_keys_from_seed("Bob"), + get_authority_keys_from_seed("Charlie"), + get_authority_keys_from_seed("Dave"), + ], + get_account_id_from_seed::("Alice"), + None, + ) +} + +/// Wococo local testnet config (multivalidator Alice + Bob + Charlie + Dave) +#[cfg(feature = "rococo-native")] +pub fn wococo_local_testnet_config() -> Result { + #[allow(deprecated)] + Ok(RococoChainSpec::from_genesis( + "Wococo Local Testnet", + "wococo_local_testnet", + ChainType::Local, + move || RococoGenesisExt { + runtime_genesis_config: wococo_local_testnet_genesis(), + // Use 1 minute session length. + session_length_in_blocks: Some(10), + }, + vec![], + None, + Some(DEFAULT_PROTOCOL_ID), + None, + None, + Default::default(), + rococo::WASM_BINARY.ok_or("Wococo development wasm not available")?, + )) +} + +/// `Versi` is a temporary testnet that uses the same runtime as rococo. +#[cfg(feature = "rococo-native")] +fn versi_local_testnet_genesis() -> rococo_runtime::RuntimeGenesisConfig { + rococo_testnet_genesis( + vec![ + get_authority_keys_from_seed("Alice"), + get_authority_keys_from_seed("Bob"), + get_authority_keys_from_seed("Charlie"), + get_authority_keys_from_seed("Dave"), + ], + get_account_id_from_seed::("Alice"), + None, + ) +} + +/// `Versi` local testnet config (multivalidator Alice + Bob + Charlie + Dave) +#[cfg(feature = "rococo-native")] +pub fn versi_local_testnet_config() -> Result { + #[allow(deprecated)] + Ok(RococoChainSpec::from_genesis( + "Versi Local Testnet", + "versi_local_testnet", + ChainType::Local, + move || RococoGenesisExt { + runtime_genesis_config: versi_local_testnet_genesis(), + // Use 1 minute session length. + session_length_in_blocks: Some(10), + }, + vec![], + None, + Some("versi"), + None, + None, + Default::default(), + rococo::WASM_BINARY.ok_or("Versi development wasm not available")?, + )) +} diff --git a/polkadot/node/test/client/src/lib.rs b/polkadot/node/test/client/src/lib.rs index 5d97ffcdf1da..6b205c09f2f3 100644 --- a/polkadot/node/test/client/src/lib.rs +++ b/polkadot/node/test/client/src/lib.rs @@ -51,7 +51,7 @@ pub struct GenesisParameters; impl substrate_test_client::GenesisInit for GenesisParameters { fn genesis_storage(&self) -> Storage { - polkadot_test_service::chain_spec::polkadot_local_testnet_genesis() + polkadot_test_service::chain_spec::polkadot_local_testnet_config() .build_storage() .expect("Builds test runtime genesis storage") } diff --git a/polkadot/node/test/service/Cargo.toml b/polkadot/node/test/service/Cargo.toml index c9cb599d2fa0..f10a8240a889 100644 --- a/polkadot/node/test/service/Cargo.toml +++ b/polkadot/node/test/service/Cargo.toml @@ -11,6 +11,7 @@ futures = "0.3.21" hex = "0.4.3" gum = { package = "tracing-gum", path = "../../gum" } rand = "0.8.5" +serde_json = "1.0.96" tempfile = "3.2.0" tokio = "1.24.2" @@ -58,7 +59,6 @@ substrate-test-client = { path = "../../../../substrate/test-utils/client" } [dev-dependencies] pallet-balances = { path = "../../../../substrate/frame/balances", default-features = false } -serde_json = "1.0.96" substrate-test-utils = { path = "../../../../substrate/test-utils" } tokio = { version = "1.24.2", features = ["macros"] } diff --git a/polkadot/node/test/service/src/chain_spec.rs b/polkadot/node/test/service/src/chain_spec.rs index 9aadd7d203c0..d199581bcc46 100644 --- a/polkadot/node/test/service/src/chain_spec.rs +++ b/polkadot/node/test/service/src/chain_spec.rs @@ -33,27 +33,26 @@ use test_runtime_constants::currency::DOTS; const DEFAULT_PROTOCOL_ID: &str = "dot"; /// The `ChainSpec` parameterized for polkadot test runtime. -pub type PolkadotChainSpec = - sc_service::GenericChainSpec; +pub type PolkadotChainSpec = sc_service::GenericChainSpec<(), Extensions>; /// Local testnet config (multivalidator Alice + Bob) pub fn polkadot_local_testnet_config() -> PolkadotChainSpec { - PolkadotChainSpec::from_genesis( - "Local Testnet", - "local_testnet", - ChainType::Local, - || polkadot_local_testnet_genesis(), - vec![], - None, - Some(DEFAULT_PROTOCOL_ID), - None, - Some(polkadot_chain_spec_properties()), - Default::default(), - ) + PolkadotChainSpec::builder() + .with_name("Local Testnet") + .with_id("local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(polkadot_local_testnet_genesis()) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .with_extensions(Default::default()) + .with_properties(polkadot_chain_spec_properties()) + .with_code( + polkadot_test_runtime::WASM_BINARY.expect("Wasm binary must be built for testing"), + ) + .build() } /// Local testnet genesis config (multivalidator Alice + Bob) -pub fn polkadot_local_testnet_genesis() -> polkadot_test_runtime::RuntimeGenesisConfig { +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"), @@ -106,7 +105,7 @@ fn polkadot_testnet_genesis( )>, root_key: AccountId, endowed_accounts: Option>, -) -> polkadot_test_runtime::RuntimeGenesisConfig { +) -> serde_json::Value { use polkadot_test_runtime as runtime; let endowed_accounts: Vec = endowed_accounts.unwrap_or_else(testnet_accounts); @@ -114,17 +113,12 @@ fn polkadot_testnet_genesis( const ENDOWMENT: u128 = 1_000_000 * DOTS; const STASH: u128 = 100 * DOTS; - runtime::RuntimeGenesisConfig { - system: runtime::SystemConfig { - code: runtime::WASM_BINARY.expect("Wasm binary must be built for testing").to_vec(), - ..Default::default() - }, - indices: runtime::IndicesConfig { indices: vec![] }, - balances: runtime::BalancesConfig { - balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(), + serde_json::json!({ + "balances": { + "balances": endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect::>(), }, - session: runtime::SessionConfig { - keys: initial_authorities + "session": { + "keys": initial_authorities .iter() .map(|x| { ( @@ -141,47 +135,36 @@ fn polkadot_testnet_genesis( }) .collect::>(), }, - staking: runtime::StakingConfig { - minimum_validator_count: 1, - validator_count: 2, - stakers: initial_authorities + "staking": { + "minimumValidatorCount": 1, + "validatorCount": 2, + "stakers": initial_authorities .iter() - .map(|x| (x.0.clone(), x.0.clone(), STASH, runtime::StakerStatus::Validator)) - .collect(), - invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(), - force_era: Forcing::NotForcing, - slash_reward_fraction: Perbill::from_percent(10), - ..Default::default() - }, - babe: runtime::BabeConfig { - authorities: vec![], - epoch_config: Some(BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() + .map(|x| (x.0.clone(), x.0.clone(), STASH, runtime::StakerStatus::::Validator)) + .collect::>(), + "invulnerables": initial_authorities.iter().map(|x| x.0.clone()).collect::>(), + "forceEra": Forcing::NotForcing, + "slashRewardFraction": Perbill::from_percent(10), }, - grandpa: Default::default(), - authority_discovery: runtime::AuthorityDiscoveryConfig { - keys: vec![], - ..Default::default() + "babe": { + "epochConfig": Some(BABE_GENESIS_EPOCH_CONFIG), }, - claims: runtime::ClaimsConfig { claims: vec![], vesting: vec![] }, - vesting: runtime::VestingConfig { vesting: vec![] }, - sudo: runtime::SudoConfig { key: Some(root_key) }, - configuration: runtime::ConfigurationConfig { - config: polkadot_runtime_parachains::configuration::HostConfiguration { - validation_upgrade_cooldown: 10u32, - validation_upgrade_delay: 5, - code_retention_period: 1200, - max_code_size: MAX_CODE_SIZE, - max_pov_size: MAX_POV_SIZE, - max_head_data_size: 32 * 1024, - group_rotation_frequency: 20, - paras_availability_period: 4, - no_show_slots: 10, - minimum_validation_upgrade_delay: 5, - ..Default::default() + "sudo": { "key": Some(root_key) }, + "configuration": { + "config": { + "validationUpgradeCooldown": 10u32, + "validationUpgradeDelay": 5, + "codeRetentionPeriod": 1200, + "maxCodeSize": MAX_CODE_SIZE, + "maxPovSize": MAX_POV_SIZE, + "maxHeadDataSize": 32 * 1024, + "groupRotationFrequency": 20, + "parasAvailabilityPeriod": 4, + "noShowSlots": 10, + "minimumValidationUpgradeDelay": 5, }, - }, - } + } + }) } /// Can be called for a `Configuration` to check if it is a configuration for the `Test` network. diff --git a/polkadot/runtime/common/src/lib.rs b/polkadot/runtime/common/src/lib.rs index 61968e48832c..5a73a76d0472 100644 --- a/polkadot/runtime/common/src/lib.rs +++ b/polkadot/runtime/common/src/lib.rs @@ -246,7 +246,8 @@ impl sp_runtime::traits::Convert for U256ToBalance { } /// Macro to set a value (e.g. when using the `parameter_types` macro) to either a production value -/// or to an environment variable or testing value (in case the `fast-runtime` feature is selected). +/// or to an environment variable or testing value (in case the `fast-runtime` feature is selected) +/// or one of two testing values depending on feature. /// Note that the environment variable is evaluated _at compile time_. /// /// Usage: @@ -255,6 +256,8 @@ impl sp_runtime::traits::Convert for U256ToBalance { /// // Note that the env variable version parameter cannot be const. /// pub LaunchPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 1, "KSM_LAUNCH_PERIOD"); /// pub const VotingPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 1 * MINUTES); +/// pub const EpochDuration: BlockNumber = +/// prod_or_fast!(1 * HOURS, "fast-runtime", 1 * MINUTES, "fast-runtime-10m", 10 * MINUTES); /// } /// ``` #[macro_export] diff --git a/polkadot/runtime/kusama/Cargo.toml b/polkadot/runtime/kusama/Cargo.toml index d04f67eda2bb..db59fab96752 100644 --- a/polkadot/runtime/kusama/Cargo.toml +++ b/polkadot/runtime/kusama/Cargo.toml @@ -28,6 +28,7 @@ offchain-primitives = { package = "sp-offchain", path = "../../../substrate/prim sp-std = { package = "sp-std", path = "../../../substrate/primitives/std", default-features = false } sp-application-crypto = { path = "../../../substrate/primitives/application-crypto", default-features = false } sp-arithmetic = { path = "../../../substrate/primitives/arithmetic", default-features = false } +sp-genesis-builder = { path = "../../../substrate/primitives/genesis-builder", default-features = false } sp-io = { path = "../../../substrate/primitives/io", default-features = false } sp-mmr-primitives = { path = "../../../substrate/primitives/merkle-mountain-range", default-features = false } sp-runtime = { path = "../../../substrate/primitives/runtime", default-features = false } @@ -203,6 +204,7 @@ std = [ "sp-application-crypto/std", "sp-arithmetic/std", "sp-core/std", + "sp-genesis-builder/std", "sp-io/std", "sp-mmr-primitives/std", "sp-npos-elections/std", @@ -327,9 +329,16 @@ disable-runtime-api = [] # A feature that should be enabled when the runtime should be build 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" ] +on-chain-release-build = [ + "sp-api/disable-logging", + "disable-genesis-builder", +] # Set timing constants (e.g. session period) to faster versions to speed up testing. fast-runtime = [] runtime-metrics = [ "runtime-parachains/runtime-metrics", "sp-io/with-tracing" ] + +# When enabled, the GenesisBuilder API will not be supprted, GenesisConfig shall be +# stripped from the final binary +disable-genesis-builder = [] diff --git a/polkadot/runtime/kusama/build.rs b/polkadot/runtime/kusama/build.rs index 404ba3f2fdbd..c076fa43523f 100644 --- a/polkadot/runtime/kusama/build.rs +++ b/polkadot/runtime/kusama/build.rs @@ -16,10 +16,23 @@ use substrate_wasm_builder::WasmBuilder; +const NO_GENESIS_BUILDER_ENV: &str = "BUILD_NO_GENESIS_BUILDER_SUPPORT"; + fn main() { WasmBuilder::new() .with_current_project() .import_memory() .export_heap_base() - .build() + .build(); + + if std::env::var(NO_GENESIS_BUILDER_ENV).is_ok() { + WasmBuilder::new() + .with_current_project() + .import_memory() + .export_heap_base() + .enable_feature("disable-genesis-builder") + .set_file_name("kusama_runtime_no_genesis_builder") + .build(); + }; + println!("cargo:rerun-if-env-changed={}", NO_GENESIS_BUILDER_ENV); } diff --git a/polkadot/runtime/kusama/src/lib.rs b/polkadot/runtime/kusama/src/lib.rs index e9e3fb2d2026..aea69c433508 100644 --- a/polkadot/runtime/kusama/src/lib.rs +++ b/polkadot/runtime/kusama/src/lib.rs @@ -60,6 +60,9 @@ use frame_election_provider_support::{ bounds::ElectionBoundsBuilder, generate_solution_type, onchain, NposSolution, SequentialPhragmen, }; + +#[cfg(not(feature = "disable-genesis-builder"))] +use frame_support::genesis_builder_helper::{build_config, create_default_config}; use frame_support::{ construct_runtime, parameter_types, traits::{ @@ -2452,6 +2455,17 @@ sp_api::impl_runtime_apis! { Ok(batches) } } + + #[cfg(not(feature = "disable-genesis-builder"))] + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } } #[cfg(test)] diff --git a/polkadot/runtime/polkadot/Cargo.toml b/polkadot/runtime/polkadot/Cargo.toml index 1d2ce803910e..366620a627bf 100644 --- a/polkadot/runtime/polkadot/Cargo.toml +++ b/polkadot/runtime/polkadot/Cargo.toml @@ -26,6 +26,7 @@ offchain-primitives = { package = "sp-offchain", path = "../../../substrate/prim tx-pool-api = { package = "sp-transaction-pool", path = "../../../substrate/primitives/transaction-pool", default-features = false } sp-arithmetic = { path = "../../../substrate/primitives/arithmetic", default-features = false } sp-api = { path = "../../../substrate/primitives/api", default-features = false } +sp-genesis-builder = { path = "../../../substrate/primitives/genesis-builder", default-features = false } sp-std = { path = "../../../substrate/primitives/std", default-features = false } sp-io = { path = "../../../substrate/primitives/io", default-features = false } sp-mmr-primitives = { path = "../../../substrate/primitives/merkle-mountain-range", default-features = false } @@ -186,6 +187,7 @@ std = [ "sp-arithmetic/std", "sp-arithmetic/std", "sp-core/std", + "sp-genesis-builder/std", "sp-mmr-primitives/std", "sp-npos-elections/std", "sp-runtime/std", @@ -298,9 +300,16 @@ disable-runtime-api = [] # A feature that should be enabled when the runtime should be build 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" ] +on-chain-release-build = [ + "sp-api/disable-logging", + "disable-genesis-builder", +] # Set timing constants (e.g. session period) to faster versions to speed up testing. fast-runtime = [] runtime-metrics = [ "runtime-parachains/runtime-metrics", "sp-io/with-tracing" ] + +# When enabled, the GenesisBuilder API will not be supprted, GenesisConfig shall be +# stripped from the final binary +disable-genesis-builder = [] diff --git a/polkadot/runtime/polkadot/build.rs b/polkadot/runtime/polkadot/build.rs index 428c971bc132..5460ef4bf6ce 100644 --- a/polkadot/runtime/polkadot/build.rs +++ b/polkadot/runtime/polkadot/build.rs @@ -16,10 +16,23 @@ use substrate_wasm_builder::WasmBuilder; +const NO_GENESIS_BUILDER_ENV: &str = "BUILD_NO_GENESIS_BUILDER_SUPPORT"; + fn main() { WasmBuilder::new() .with_current_project() .import_memory() .export_heap_base() - .build() + .build(); + + if std::env::var(NO_GENESIS_BUILDER_ENV).is_ok() { + WasmBuilder::new() + .with_current_project() + .import_memory() + .export_heap_base() + .enable_feature("disable-genesis-builder") + .set_file_name("polkadot_runtime_no_genesis_builder") + .build(); + }; + println!("cargo:rerun-if-env-changed={}", NO_GENESIS_BUILDER_ENV); } diff --git a/polkadot/runtime/polkadot/src/lib.rs b/polkadot/runtime/polkadot/src/lib.rs index c4458076cb3d..32a7d22871da 100644 --- a/polkadot/runtime/polkadot/src/lib.rs +++ b/polkadot/runtime/polkadot/src/lib.rs @@ -44,6 +44,8 @@ use beefy_primitives::ecdsa_crypto::{AuthorityId as BeefyId, Signature as BeefyS use frame_election_provider_support::{ bounds::ElectionBoundsBuilder, generate_solution_type, onchain, SequentialPhragmen, }; +#[cfg(not(feature = "disable-genesis-builder"))] +use frame_support::genesis_builder_helper::{build_config, create_default_config}; use frame_support::{ construct_runtime, parameter_types, traits::{ @@ -2194,6 +2196,18 @@ sp_api::impl_runtime_apis! { Ok(batches) } } + + #[cfg(not(feature = "disable-genesis-builder"))] + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } + } #[cfg(test)] diff --git a/polkadot/runtime/rococo/Cargo.toml b/polkadot/runtime/rococo/Cargo.toml index ebb7cd9c5ef6..678f833bb138 100644 --- a/polkadot/runtime/rococo/Cargo.toml +++ b/polkadot/runtime/rococo/Cargo.toml @@ -21,6 +21,7 @@ beefy-primitives = { package = "sp-consensus-beefy", path = "../../../substrate/ binary-merkle-tree = { path = "../../../substrate/utils/binary-merkle-tree", default-features = false } rococo-runtime-constants = { package = "rococo-runtime-constants", path = "constants", default-features = false } sp-api = { path = "../../../substrate/primitives/api", default-features = false } +sp-genesis-builder = { path = "../../../substrate/primitives/genesis-builder", default-features = false } inherents = { package = "sp-inherents", path = "../../../substrate/primitives/inherents", default-features = false } offchain-primitives = { package = "sp-offchain", path = "../../../substrate/primitives/offchain", default-features = false } sp-std = { package = "sp-std", path = "../../../substrate/primitives/std", default-features = false } @@ -171,6 +172,7 @@ std = [ "serde_derive", "sp-api/std", "sp-core/std", + "sp-genesis-builder/std", "sp-io/std", "sp-mmr-primitives/std", "sp-runtime/std", @@ -275,6 +277,6 @@ try-runtime = [ disable-runtime-api = [] # Set timing constants (e.g. session period) to faster versions to speed up testing. -fast-runtime = [] +fast-runtime = [ "rococo-runtime-constants/fast-runtime" ] runtime-metrics = [ "runtime-parachains/runtime-metrics", "sp-io/with-tracing" ] diff --git a/polkadot/runtime/rococo/build.rs b/polkadot/runtime/rococo/build.rs index e7134e0ef723..f960a21b4200 100644 --- a/polkadot/runtime/rococo/build.rs +++ b/polkadot/runtime/rococo/build.rs @@ -14,12 +14,26 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . +use std::env; use substrate_wasm_builder::WasmBuilder; +// note: needs to be synced with rococo-runtime-constants::time hard-coded string literal in prod_or_fast macro. +const ROCOCO_EPOCH_DURATION_ENV: &str = "ROCOCO_EPOCH_DURATION"; +const ROCOCO_FAST_RUNTIME_ENV: &str = "ROCOCO_FAST_RUNTIME"; + fn main() { - WasmBuilder::new() - .with_current_project() - .import_memory() - .export_heap_base() - .build() + #[cfg(feature = "std")] + { + let mut builder = + WasmBuilder::new().with_current_project().import_memory().export_heap_base(); + + if env::var(ROCOCO_EPOCH_DURATION_ENV).is_ok() | env::var(ROCOCO_FAST_RUNTIME_ENV).is_ok() { + builder = builder.enable_feature("fast-runtime") + }; + + builder.build(); + + println!("cargo:rerun-if-env-changed={}", ROCOCO_EPOCH_DURATION_ENV); + println!("cargo:rerun-if-env-changed={}", ROCOCO_FAST_RUNTIME_ENV); + } } diff --git a/polkadot/runtime/rococo/constants/Cargo.toml b/polkadot/runtime/rococo/constants/Cargo.toml index 174e4e83a5e3..b7553e0f9d62 100644 --- a/polkadot/runtime/rococo/constants/Cargo.toml +++ b/polkadot/runtime/rococo/constants/Cargo.toml @@ -25,3 +25,6 @@ std = [ "sp-runtime/std", "sp-weights/std", ] + +# Set timing constants (e.g. session period) to faster versions to speed up testing. +fast-runtime = [] diff --git a/polkadot/runtime/rococo/constants/src/lib.rs b/polkadot/runtime/rococo/constants/src/lib.rs index 214e2f3fa980..3b2ff696f185 100644 --- a/polkadot/runtime/rococo/constants/src/lib.rs +++ b/polkadot/runtime/rococo/constants/src/lib.rs @@ -41,9 +41,9 @@ pub mod time { use runtime_common::prod_or_fast; pub const MILLISECS_PER_BLOCK: Moment = 6000; pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; - pub const DEFAULT_EPOCH_DURATION: BlockNumber = prod_or_fast!(1 * HOURS, 1 * MINUTES); + frame_support::parameter_types! { - pub storage EpochDurationInBlocks: BlockNumber = DEFAULT_EPOCH_DURATION; + pub storage EpochDurationInBlocks: BlockNumber = prod_or_fast!(1 * HOURS, 1 * MINUTES, "ROCOCO_EPOCH_DURATION"); } // These time units are defined in number of blocks. diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 6894bd7bbf44..9eba2851b1ea 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -58,7 +58,9 @@ use beefy_primitives::{ }; use frame_support::{ - construct_runtime, parameter_types, + construct_runtime, + genesis_builder_helper::{build_config, create_default_config}, + parameter_types, traits::{ Contains, EitherOfDiverse, InstanceFilter, KeyOwnerProofSystem, LockIdentifier, PrivilegeCmp, ProcessMessage, ProcessMessageError, StorageMapShim, WithdrawReasons, @@ -2224,6 +2226,16 @@ sp_api::impl_runtime_apis! { Ok(batches) } } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } } #[cfg(test)] diff --git a/polkadot/runtime/test-runtime/Cargo.toml b/polkadot/runtime/test-runtime/Cargo.toml index e5d04a0dff38..4d3364193afb 100644 --- a/polkadot/runtime/test-runtime/Cargo.toml +++ b/polkadot/runtime/test-runtime/Cargo.toml @@ -28,6 +28,7 @@ sp-io = { path = "../../../substrate/primitives/io", default-features = false } sp-runtime = { path = "../../../substrate/primitives/runtime", default-features = false } sp-staking = { path = "../../../substrate/primitives/staking", default-features = false } sp-core = { path = "../../../substrate/primitives/core", default-features = false } +sp-genesis-builder = { path = "../../../substrate/primitives/genesis-builder", default-features = false } sp-mmr-primitives = { path = "../../../substrate/primitives/merkle-mountain-range", default-features = false } sp-session = { path = "../../../substrate/primitives/session", default-features = false } sp-version = { path = "../../../substrate/primitives/version", default-features = false } @@ -123,6 +124,7 @@ std = [ "serde_derive", "sp-api/std", "sp-core/std", + "sp-genesis-builder/std", "sp-io/std", "sp-runtime/std", "sp-session/std", diff --git a/polkadot/runtime/test-runtime/src/lib.rs b/polkadot/runtime/test-runtime/src/lib.rs index b2397299430d..bd2e0fd095f9 100644 --- a/polkadot/runtime/test-runtime/src/lib.rs +++ b/polkadot/runtime/test-runtime/src/lib.rs @@ -42,7 +42,9 @@ use frame_election_provider_support::{ onchain, SequentialPhragmen, }; use frame_support::{ - construct_runtime, parameter_types, + construct_runtime, + genesis_builder_helper::{build_config, create_default_config}, + parameter_types, traits::{Everything, KeyOwnerProofSystem, WithdrawReasons}, }; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; @@ -1136,4 +1138,14 @@ sp_api::impl_runtime_apis! { Timestamp::now() } } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } } diff --git a/polkadot/runtime/westend/Cargo.toml b/polkadot/runtime/westend/Cargo.toml index 40664e33a3ad..88b65105632c 100644 --- a/polkadot/runtime/westend/Cargo.toml +++ b/polkadot/runtime/westend/Cargo.toml @@ -25,6 +25,7 @@ offchain-primitives = { package = "sp-offchain", path = "../../../substrate/prim sp-api = { path = "../../../substrate/primitives/api", default-features = false } sp-application-crypto = { path = "../../../substrate/primitives/application-crypto", default-features = false } sp-std = { package = "sp-std", path = "../../../substrate/primitives/std", default-features = false } +sp-genesis-builder = { path = "../../../substrate/primitives/genesis-builder", default-features = false } sp-io = { path = "../../../substrate/primitives/io", default-features = false } sp-mmr-primitives = { path = "../../../substrate/primitives/merkle-mountain-range", default-features = false } sp-runtime = { path = "../../../substrate/primitives/runtime", default-features = false } @@ -187,6 +188,7 @@ std = [ "sp-api/std", "sp-application-crypto/std", "sp-core/std", + "sp-genesis-builder/std", "sp-io/std", "sp-mmr-primitives/std", "sp-npos-elections/std", diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 9ae30c376010..d87e62160f64 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -27,7 +27,9 @@ use beefy_primitives::{ }; use frame_election_provider_support::{bounds::ElectionBoundsBuilder, onchain, SequentialPhragmen}; use frame_support::{ - construct_runtime, parameter_types, + construct_runtime, + genesis_builder_helper::{build_config, create_default_config}, + parameter_types, traits::{ ConstU32, InstanceFilter, KeyOwnerProofSystem, ProcessMessage, ProcessMessageError, WithdrawReasons, @@ -2129,6 +2131,16 @@ sp_api::impl_runtime_apis! { Ok(batches) } } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } } #[cfg(all(test, feature = "try-runtime"))] From 3eb57684d0f4d280383c3bff1ee6c108c0f3bba5 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 28 Aug 2023 19:04:34 +0200 Subject: [PATCH 03/98] cumulus: chain-specs getting ready for non-native world - integration-tests: storages building migrated to GenesisConfig JSON patches - parachain-template: GenesisBuilder implemented + JSON patch in ChainSpec - parachains/runtimes: GenesisBuilder API implemented - chain-specs: RuntimeGenesisConfig removed, JSON patches added - json_vs_legacy_tests: tests for json-based ChainSpecs added Copy of current chain_spec files (using deprecated from_genesis) was created in order to test json-patching vs old from_genesis version. - chain-specs: code moved from pallet_system to ChainSpec --- cumulus/parachain-template/node/Cargo.toml | 1 + .../parachain-template/node/src/chain_spec.rs | 415 +++-- cumulus/parachain-template/runtime/Cargo.toml | 2 + cumulus/parachain-template/runtime/src/lib.rs | 11 + .../emulated/common/Cargo.toml | 2 + .../emulated/common/src/constants.rs | 1525 +++++++++++++---- .../assets/asset-hub-kusama/Cargo.toml | 2 + .../assets/asset-hub-kusama/src/lib.rs | 11 + .../assets/asset-hub-polkadot/Cargo.toml | 2 + .../assets/asset-hub-polkadot/src/lib.rs | 11 + .../assets/asset-hub-westend/Cargo.toml | 2 + .../assets/asset-hub-westend/src/lib.rs | 10 + .../bridge-hubs/bridge-hub-kusama/Cargo.toml | 2 + .../bridge-hubs/bridge-hub-kusama/src/lib.rs | 11 + .../bridge-hub-polkadot/Cargo.toml | 2 + .../bridge-hub-polkadot/src/lib.rs | 11 + .../bridge-hubs/bridge-hub-rococo/Cargo.toml | 2 + .../bridge-hubs/bridge-hub-rococo/src/lib.rs | 11 + .../collectives-polkadot/Cargo.toml | 2 + .../collectives-polkadot/src/lib.rs | 11 + .../contracts/contracts-rococo/Cargo.toml | 2 + .../contracts/contracts-rococo/src/lib.rs | 11 + .../glutton/glutton-kusama/Cargo.toml | 2 + .../glutton/glutton-kusama/src/lib.rs | 11 + .../runtimes/starters/seedling/Cargo.toml | 2 + .../runtimes/starters/seedling/src/lib.rs | 11 + .../runtimes/starters/shell/Cargo.toml | 2 + .../runtimes/starters/shell/src/lib.rs | 11 + .../runtimes/testing/penpal/Cargo.toml | 2 + .../runtimes/testing/penpal/src/lib.rs | 11 + .../testing/rococo-parachain/Cargo.toml | 2 + .../testing/rococo-parachain/src/lib.rs | 10 + .../src/chain_spec/asset_hubs.rs | 813 ++++----- .../src/chain_spec/bridge_hubs.rs | 414 ++--- .../src/chain_spec/collectives.rs | 187 +- .../src/chain_spec/contracts.rs | 353 ++-- .../src/chain_spec/glutton.rs | 107 +- .../src/chain_spec/penpal.rs | 131 +- .../src/chain_spec/rococo_parachain.rs | 147 +- .../src/chain_spec/seedling.rs | 57 +- .../src/chain_spec/shell.rs | 39 +- cumulus/polkadot-parachain/src/command.rs | 44 +- .../src/legacy_chain_spec/asset_hubs.rs | 653 +++++++ .../src/legacy_chain_spec/bridge_hubs.rs | 621 +++++++ .../src/legacy_chain_spec/collectives.rs | 184 ++ .../src/legacy_chain_spec/contracts.rs | 287 ++++ .../src/legacy_chain_spec/glutton.rs | 102 ++ .../legacy_chain_spec/json_vs_legacy_tests.rs | 88 + .../src/legacy_chain_spec/mod.rs | 84 + .../src/legacy_chain_spec/penpal.rs | 140 ++ .../src/legacy_chain_spec/rococo_parachain.rs | 125 ++ .../src/legacy_chain_spec/seedling.rs | 62 + .../src/legacy_chain_spec/shell.rs | 48 + cumulus/polkadot-parachain/src/main.rs | 5 + cumulus/test/service/src/chain_spec.rs | 9 +- 55 files changed, 5053 insertions(+), 1770 deletions(-) create mode 100644 cumulus/polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs create mode 100644 cumulus/polkadot-parachain/src/legacy_chain_spec/bridge_hubs.rs create mode 100644 cumulus/polkadot-parachain/src/legacy_chain_spec/collectives.rs create mode 100644 cumulus/polkadot-parachain/src/legacy_chain_spec/contracts.rs create mode 100644 cumulus/polkadot-parachain/src/legacy_chain_spec/glutton.rs create mode 100644 cumulus/polkadot-parachain/src/legacy_chain_spec/json_vs_legacy_tests.rs create mode 100644 cumulus/polkadot-parachain/src/legacy_chain_spec/mod.rs create mode 100644 cumulus/polkadot-parachain/src/legacy_chain_spec/penpal.rs create mode 100644 cumulus/polkadot-parachain/src/legacy_chain_spec/rococo_parachain.rs create mode 100644 cumulus/polkadot-parachain/src/legacy_chain_spec/seedling.rs create mode 100644 cumulus/polkadot-parachain/src/legacy_chain_spec/shell.rs diff --git a/cumulus/parachain-template/node/Cargo.toml b/cumulus/parachain-template/node/Cargo.toml index f110e98aacb4..a81dcac899a4 100644 --- a/cumulus/parachain-template/node/Cargo.toml +++ b/cumulus/parachain-template/node/Cargo.toml @@ -16,6 +16,7 @@ codec = { package = "parity-scale-codec", version = "3.0.0" } serde = { version = "1.0.183", features = ["derive"] } jsonrpsee = { version = "0.16.2", features = ["server"] } futures = "0.3.28" +serde_json = "1.0.104" # Local parachain-template-runtime = { path = "../runtime" } diff --git a/cumulus/parachain-template/node/src/chain_spec.rs b/cumulus/parachain-template/node/src/chain_spec.rs index 0ca3c51900f2..7141f3dd11ba 100644 --- a/cumulus/parachain-template/node/src/chain_spec.rs +++ b/cumulus/parachain-template/node/src/chain_spec.rs @@ -7,8 +7,7 @@ use sp_core::{sr25519, Pair, Public}; use sp_runtime::traits::{IdentifyAccount, Verify}; /// Specialized `ChainSpec` for the normal parachain runtime. -pub type ChainSpec = - sc_service::GenericChainSpec; +pub type ChainSpec = sc_service::GenericChainSpec<(), Extensions>; /// The default XCM version to set in genesis config. const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; @@ -68,53 +67,49 @@ pub fn development_config() -> ChainSpec { properties.insert("tokenDecimals".into(), 12.into()); properties.insert("ss58Format".into(), 42.into()); - ChainSpec::from_genesis( - // Name - "Development", - // ID - "dev", - ChainType::Development, - move || { - testnet_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed("Bob"), - ), - ], - vec![ + ChainSpec::builder() + .with_name("Development") + .with_id("dev") + .with_chain_type(ChainType::Development) + .with_genesis_config_patch(testnet_genesis( + // initial collators. + vec![ + ( get_account_id_from_seed::("Alice"), + get_collator_keys_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"), - ], + get_collator_keys_from_seed("Bob"), + ), + ], + vec![ get_account_id_from_seed::("Alice"), - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - None, - Extensions { - relay_chain: "rococo-local".into(), // You MUST set this to the correct network! + 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"), + ], + get_account_id_from_seed::("Alice"), + 1000.into(), + )) + .with_extensions(Extensions { + relay_chain: "rococo-local".into(), + // You MUST set this to the correct network! para_id: 1000, - }, - ) + }) + .with_code( + parachain_template_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + .build() } pub fn local_testnet_config() -> ChainSpec { @@ -124,59 +119,52 @@ pub fn local_testnet_config() -> ChainSpec { properties.insert("tokenDecimals".into(), 12.into()); properties.insert("ss58Format".into(), 42.into()); - ChainSpec::from_genesis( - // Name - "Local Testnet", - // ID - "local_testnet", - ChainType::Local, - move || { - testnet_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed("Bob"), - ), - ], - vec![ + #[allow(deprecated)] + ChainSpec::builder() + .with_name("Local Testnet") + .with_id("local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(testnet_genesis( + // initial collators. + vec![ + ( get_account_id_from_seed::("Alice"), + get_collator_keys_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"), - ], + get_collator_keys_from_seed("Bob"), + ), + ], + vec![ get_account_id_from_seed::("Alice"), - 1000.into(), - ) - }, - // Bootnodes - Vec::new(), - // Telemetry - None, - // Protocol ID - Some("template-local"), - // Fork ID - None, - // Properties - Some(properties), - // Extensions - Extensions { - relay_chain: "rococo-local".into(), // You MUST set this to the correct network! + 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"), + ], + get_account_id_from_seed::("Alice"), + 1000.into(), + )) + .with_protocol_id("template-local") + .with_properties(properties) + .with_extensions(Extensions { + relay_chain: "rococo-local".into(), + // You MUST set this to the correct network! para_id: 1000, - }, - ) + }) + .with_code( + parachain_template_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + .build() } fn testnet_genesis( @@ -184,28 +172,20 @@ fn testnet_genesis( endowed_accounts: Vec, root: AccountId, id: ParaId, -) -> parachain_template_runtime::RuntimeGenesisConfig { - parachain_template_runtime::RuntimeGenesisConfig { - system: parachain_template_runtime::SystemConfig { - code: parachain_template_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() +) -> serde_json::Value { + serde_json::json!({ + "balances": { + "balances": endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::>(), }, - balances: parachain_template_runtime::BalancesConfig { - balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), + "parachainInfo": { + "parachainId": id, }, - parachain_info: parachain_template_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() + "collatorSelection": { + "invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::>(), + "candidacyBond": EXISTENTIAL_DEPOSIT * 16, }, - collator_selection: parachain_template_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: EXISTENTIAL_DEPOSIT * 16, - ..Default::default() - }, - session: parachain_template_runtime::SessionConfig { - keys: invulnerables + "session": { + "keys": invulnerables .into_iter() .map(|(acc, aura)| { ( @@ -214,18 +194,205 @@ fn testnet_genesis( template_session_keys(aura), // session keys ) }) - .collect(), + .collect::>(), }, - // no need to pass anything to aura, in fact it will panic if we do. Session will take care - // of this. - aura: Default::default(), - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: parachain_template_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() + "polkadotXcm": { + "safeXcmVersion": Some(SAFE_XCM_VERSION), }, - transaction_payment: Default::default(), - sudo: parachain_template_runtime::SudoConfig { key: Some(root) }, + "sudo": { "key": Some(root) } + }) +} + +#[cfg(test)] +/// RuntimeGenesisConfig-based (legacy) parachain-template configurations. Used for testing ChainSpecs against the JSON-based +/// genesis configs. Entire file shall be removed once native runtime is removed. +mod legacy { + use super::*; + + /// Specialized `ChainSpec` for the normal parachain runtime. + pub type ChainSpec = + sc_service::GenericChainSpec; + + pub fn development_config() -> ChainSpec { + // Give your base currency a unit name and decimal places + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("tokenSymbol".into(), "UNIT".into()); + properties.insert("tokenDecimals".into(), 12.into()); + properties.insert("ss58Format".into(), 42.into()); + + #[allow(deprecated)] + ChainSpec::from_genesis( + // Name + "Development", + // ID + "dev", + ChainType::Development, + move || { + testnet_genesis( + // initial collators. + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + get_account_id_from_seed::("Alice"), + 1000.into(), + ) + }, + Vec::new(), + None, + None, + None, + None, + Extensions { + relay_chain: "rococo-local".into(), // You MUST set this to the correct network! + para_id: 1000, + }, + parachain_template_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + } + + pub fn local_testnet_config() -> ChainSpec { + // Give your base currency a unit name and decimal places + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("tokenSymbol".into(), "UNIT".into()); + properties.insert("tokenDecimals".into(), 12.into()); + properties.insert("ss58Format".into(), 42.into()); + + #[allow(deprecated)] + ChainSpec::from_genesis( + // Name + "Local Testnet", + // ID + "local_testnet", + ChainType::Local, + move || { + testnet_genesis( + // initial collators. + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + get_account_id_from_seed::("Alice"), + 1000.into(), + ) + }, + // Bootnodes + Vec::new(), + // Telemetry + None, + // Protocol ID + Some("template-local"), + // Fork ID + None, + // Properties + Some(properties), + // Extensions + Extensions { + relay_chain: "rococo-local".into(), // You MUST set this to the correct network! + para_id: 1000, + }, + parachain_template_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + } + + fn testnet_genesis( + invulnerables: Vec<(AccountId, AuraId)>, + endowed_accounts: Vec, + root: AccountId, + id: ParaId, + ) -> parachain_template_runtime::RuntimeGenesisConfig { + parachain_template_runtime::RuntimeGenesisConfig { + system: parachain_template_runtime::SystemConfig::default(), + balances: parachain_template_runtime::BalancesConfig { + balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), + }, + parachain_info: parachain_template_runtime::ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + collator_selection: parachain_template_runtime::CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: EXISTENTIAL_DEPOSIT * 16, + ..Default::default() + }, + session: parachain_template_runtime::SessionConfig { + keys: invulnerables + .into_iter() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc, // validator id + template_session_keys(aura), // session keys + ) + }) + .collect(), + }, + // no need to pass anything to aura, in fact it will panic if we do. Session will take care + // of this. + aura: Default::default(), + aura_ext: Default::default(), + parachain_system: Default::default(), + polkadot_xcm: parachain_template_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + transaction_payment: Default::default(), + sudo: parachain_template_runtime::SudoConfig { key: Some(root) }, + } + } + + #[test] + fn test_development_config() { + let j1 = development_config().as_json(true); + let j2 = legacy::development_config().as_json(true); + assert_eq!(j1, j2); + } + #[test] + fn test_local_testnet_config() { + let j1 = local_testnet_config().as_json(true); + let j2 = legacy::local_testnet_config().as_json(true); + assert_eq!(j1, j2); } } diff --git a/cumulus/parachain-template/runtime/Cargo.toml b/cumulus/parachain-template/runtime/Cargo.toml index c61df9dbc8ae..78876a9fefa1 100644 --- a/cumulus/parachain-template/runtime/Cargo.toml +++ b/cumulus/parachain-template/runtime/Cargo.toml @@ -44,6 +44,7 @@ sp-api = { path = "../../../substrate/primitives/api", default-features = false} sp-block-builder = { path = "../../../substrate/primitives/block-builder", default-features = false} sp-consensus-aura = { path = "../../../substrate/primitives/consensus/aura", default-features = false} sp-core = { path = "../../../substrate/primitives/core", default-features = false} +sp-genesis-builder = { path = "../../../substrate/primitives/genesis-builder", default-features = false } sp-inherents = { path = "../../../substrate/primitives/inherents", default-features = false} sp-offchain = { path = "../../../substrate/primitives/offchain", default-features = false} sp-runtime = { path = "../../../substrate/primitives/runtime", default-features = false} @@ -107,6 +108,7 @@ std = [ "sp-block-builder/std", "sp-consensus-aura/std", "sp-core/std", + "sp-genesis-builder/std", "sp-inherents/std", "sp-offchain/std", "sp-runtime/std", diff --git a/cumulus/parachain-template/runtime/src/lib.rs b/cumulus/parachain-template/runtime/src/lib.rs index 038597096f6a..b9bf97d7786f 100644 --- a/cumulus/parachain-template/runtime/src/lib.rs +++ b/cumulus/parachain-template/runtime/src/lib.rs @@ -28,6 +28,7 @@ use sp_version::RuntimeVersion; use frame_support::{ construct_runtime, dispatch::DispatchClass, + genesis_builder_helper::{build_config, create_default_config}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything}, weights::{ @@ -742,6 +743,16 @@ impl_runtime_apis! { Ok(batches) } } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } } cumulus_pallet_parachain_system::register_validate_block! { diff --git a/cumulus/parachains/integration-tests/emulated/common/Cargo.toml b/cumulus/parachains/integration-tests/emulated/common/Cargo.toml index 0122379b7d83..575b3be6aa66 100644 --- a/cumulus/parachains/integration-tests/emulated/common/Cargo.toml +++ b/cumulus/parachains/integration-tests/emulated/common/Cargo.toml @@ -9,6 +9,7 @@ description = "Common resources for integration testing with xcm-emulator" codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false } lazy_static = "1.4.0" paste = "1.0.14" +serde_json = "1.0.104" # Substrate grandpa = { package = "sc-consensus-grandpa", path = "../../../../../substrate/client/consensus/grandpa" } @@ -26,6 +27,7 @@ pallet-staking = { path = "../../../../../substrate/frame/staking", default-feat pallet-message-queue = { path = "../../../../../substrate/frame/message-queue", default-features = false} pallet-im-online = { path = "../../../../../substrate/frame/im-online", default-features = false} beefy-primitives = { package = "sp-consensus-beefy", path = "../../../../../substrate/primitives/consensus/beefy" } +sc-chain-spec = { path = "../../../../../substrate/client/chain-spec", default-features = false } # Polkadot polkadot-core-primitives = { path = "../../../../../polkadot/core-primitives", default-features = false} diff --git a/cumulus/parachains/integration-tests/emulated/common/src/constants.rs b/cumulus/parachains/integration-tests/emulated/common/src/constants.rs index 3eb65fa26c16..9d0f2750dc0d 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/constants.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/constants.rs @@ -9,12 +9,15 @@ use polkadot_runtime_parachains::{ paras::{ParaGenesisArgs, ParaKind}, }; use polkadot_service::chain_spec::get_authority_keys_from_seed_no_beefy; +use sc_chain_spec::GenesisConfigBuilderRuntimeCaller; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; use sp_consensus_babe::AuthorityId as BabeId; use sp_core::{sr25519, storage::Storage, Pair, Public}; +#[cfg(test)] +use sp_runtime::BuildStorage; use sp_runtime::{ traits::{IdentifyAccount, Verify}, - BuildStorage, MultiSignature, Perbill, + MultiSignature, Perbill, }; use xcm; @@ -40,6 +43,29 @@ where AccountPublic::from(get_from_seed::(seed)).into_account() } +/// Helper function to build the genesis storage using given json patch and code +fn build_genesis_storage(patch: serde_json::Value, code: &[u8]) -> Storage { + let mut storage = GenesisConfigBuilderRuntimeCaller::new(code) + .get_storage_for_patch(patch) + .unwrap(); + storage + .top + .insert(sp_core::storage::well_known_keys::CODE.to_vec(), code.into()); + storage +} + +#[cfg(test)] +/// Helper function used in tests to build the genesis storage using given RuntimeGenesisConfig and +/// code Used in `legacy_vs_json_check` submods to verify storage building with JSON patch against +/// building with RuntimeGenesisConfig struct. +fn build_genesis_storage_legacy(builder: &dyn BuildStorage, code: &[u8]) -> Storage { + let mut storage = builder.build_storage().unwrap(); + storage + .top + .insert(sp_core::storage::well_known_keys::CODE.to_vec(), code.into()); + storage +} + pub mod accounts { use super::*; pub const ALICE: &str = "Alice"; @@ -163,20 +189,16 @@ pub mod polkadot { } pub fn genesis() -> Storage { - let genesis_config = polkadot_runtime::RuntimeGenesisConfig { - system: polkadot_runtime::SystemConfig { - code: polkadot_runtime::WASM_BINARY.unwrap().to_vec(), - ..Default::default() - }, - balances: polkadot_runtime::BalancesConfig { - balances: accounts::init_balances() + let genesis_config = serde_json::json!({ + "balances": { + "balances": accounts::init_balances() .iter() .cloned() .map(|k| (k, ED * 4096)) - .collect(), + .collect::>(), }, - session: polkadot_runtime::SessionConfig { - keys: validators::initial_authorities() + "session": { + "keys": validators::initial_authorities() .iter() .map(|x| { ( @@ -194,33 +216,30 @@ pub mod polkadot { }) .collect::>(), }, - staking: polkadot_runtime::StakingConfig { - validator_count: validators::initial_authorities().len() as u32, - minimum_validator_count: 1, - stakers: validators::initial_authorities() + "staking": { + "validatorCount": validators::initial_authorities().len() as u32, + "minimumValidatorCount": 1, + "stakers": validators::initial_authorities() .iter() .map(|x| { - (x.0.clone(), x.1.clone(), STASH, polkadot_runtime::StakerStatus::Validator) + (x.0.clone(), x.1.clone(), STASH, polkadot_runtime::StakerStatus::::Validator) }) - .collect(), - invulnerables: validators::initial_authorities() + .collect::>(), + "invulnerables": validators::initial_authorities() .iter() .map(|x| x.0.clone()) - .collect(), - force_era: pallet_staking::Forcing::ForceNone, - slash_reward_fraction: Perbill::from_percent(10), - ..Default::default() + .collect::>(), + "forceEra": pallet_staking::Forcing::ForceNone, + "slashRewardFraction": Perbill::from_percent(10), }, - babe: polkadot_runtime::BabeConfig { - authorities: Default::default(), - epoch_config: Some(polkadot_runtime::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() + "babe": { + "epochConfig": Some(polkadot_runtime::BABE_GENESIS_EPOCH_CONFIG), }, - configuration: polkadot_runtime::ConfigurationConfig { config: get_host_config() }, - paras: polkadot_runtime::ParasConfig { - paras: vec![ + "configuration": { "config": get_host_config() }, + "paras": { + "paras": vec![ ( - asset_hub_polkadot::PARA_ID.into(), + cumulus_primitives_core::ParaId::from(asset_hub_polkadot::PARA_ID), ParaGenesisArgs { genesis_head: HeadData::default(), validation_code: ValidationCode( @@ -230,7 +249,7 @@ pub mod polkadot { }, ), ( - penpal::PARA_ID_A.into(), + cumulus_primitives_core::ParaId::from(penpal::PARA_ID_A), ParaGenesisArgs { genesis_head: HeadData::default(), validation_code: ValidationCode( @@ -240,7 +259,7 @@ pub mod polkadot { }, ), ( - penpal::PARA_ID_B.into(), + cumulus_primitives_core::ParaId::from(penpal::PARA_ID_B), ParaGenesisArgs { genesis_head: HeadData::default(), validation_code: ValidationCode( @@ -250,12 +269,121 @@ pub mod polkadot { }, ), ], - ..Default::default() }, - ..Default::default() - }; + }); + + build_genesis_storage(genesis_config, polkadot_runtime::WASM_BINARY.unwrap()) + } + + #[cfg(test)] + mod legacy_vs_json_check { + use super::*; + fn genesis() -> Storage { + let genesis_config = polkadot_runtime::RuntimeGenesisConfig { + system: polkadot_runtime::SystemConfig::default(), + balances: polkadot_runtime::BalancesConfig { + balances: accounts::init_balances() + .iter() + .cloned() + .map(|k| (k, ED * 4096)) + .collect(), + }, + session: polkadot_runtime::SessionConfig { + keys: validators::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: polkadot_runtime::StakingConfig { + validator_count: validators::initial_authorities().len() as u32, + minimum_validator_count: 1, + stakers: validators::initial_authorities() + .iter() + .map(|x| { + ( + x.0.clone(), + x.1.clone(), + STASH, + polkadot_runtime::StakerStatus::Validator, + ) + }) + .collect(), + invulnerables: validators::initial_authorities() + .iter() + .map(|x| x.0.clone()) + .collect(), + force_era: pallet_staking::Forcing::ForceNone, + slash_reward_fraction: Perbill::from_percent(10), + ..Default::default() + }, + babe: polkadot_runtime::BabeConfig { + authorities: Default::default(), + epoch_config: Some(polkadot_runtime::BABE_GENESIS_EPOCH_CONFIG), + ..Default::default() + }, + configuration: polkadot_runtime::ConfigurationConfig { config: get_host_config() }, + paras: polkadot_runtime::ParasConfig { + paras: vec![ + ( + asset_hub_polkadot::PARA_ID.into(), + ParaGenesisArgs { + genesis_head: HeadData::default(), + validation_code: ValidationCode( + asset_hub_polkadot_runtime::WASM_BINARY.unwrap().to_vec(), + ), + para_kind: ParaKind::Parachain, + }, + ), + ( + penpal::PARA_ID_A.into(), + ParaGenesisArgs { + genesis_head: HeadData::default(), + validation_code: ValidationCode( + penpal_runtime::WASM_BINARY.unwrap().to_vec(), + ), + para_kind: ParaKind::Parachain, + }, + ), + ( + penpal::PARA_ID_B.into(), + ParaGenesisArgs { + genesis_head: HeadData::default(), + validation_code: ValidationCode( + penpal_runtime::WASM_BINARY.unwrap().to_vec(), + ), + para_kind: ParaKind::Parachain, + }, + ), + ], + ..Default::default() + }, + ..Default::default() + }; + + build_genesis_storage_legacy(&genesis_config, polkadot_runtime::WASM_BINARY.unwrap()) + } + + #[test] + fn test_genesis() { + let j1 = super::genesis(); + let j2 = genesis(); - genesis_config.build_storage().unwrap() + assert_eq!(j1.top, j2.top); + assert_eq!(j1.children_default, j2.children_default); + } } } @@ -306,20 +434,16 @@ pub mod westend { } pub fn genesis() -> Storage { - let genesis_config = westend_runtime::RuntimeGenesisConfig { - system: westend_runtime::SystemConfig { - code: westend_runtime::WASM_BINARY.unwrap().to_vec(), - ..Default::default() - }, - balances: westend_runtime::BalancesConfig { - balances: accounts::init_balances() + let genesis_config = serde_json::json!({ + "balances": { + "balances": accounts::init_balances() .iter() .cloned() .map(|k| (k, ENDOWMENT)) - .collect(), + .collect::>(), }, - session: westend_runtime::SessionConfig { - keys: validators::initial_authorities() + "session": { + "keys": validators::initial_authorities() .iter() .map(|x| { ( @@ -338,33 +462,106 @@ pub mod westend { }) .collect::>(), }, - staking: westend_runtime::StakingConfig { - validator_count: validators::initial_authorities().len() as u32, - minimum_validator_count: 1, - stakers: validators::initial_authorities() + "staking": { + "validatorCount": validators::initial_authorities().len() as u32, + "minimumValidatorCount": 1, + "stakers": validators::initial_authorities() .iter() .map(|x| { - (x.0.clone(), x.1.clone(), STASH, westend_runtime::StakerStatus::Validator) + (x.0.clone(), x.1.clone(), STASH, westend_runtime::StakerStatus::::Validator) }) - .collect(), - invulnerables: validators::initial_authorities() + .collect::>(), + "invulnerables": validators::initial_authorities() .iter() .map(|x| x.0.clone()) - .collect(), - force_era: pallet_staking::Forcing::ForceNone, - slash_reward_fraction: Perbill::from_percent(10), - ..Default::default() + .collect::>(), + "forceEra": pallet_staking::Forcing::ForceNone, + "slashRewardFraction": Perbill::from_percent(10), }, - babe: westend_runtime::BabeConfig { - authorities: Default::default(), - epoch_config: Some(westend_runtime::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() + "babe": { + "epochConfig": Some(westend_runtime::BABE_GENESIS_EPOCH_CONFIG), }, - configuration: westend_runtime::ConfigurationConfig { config: get_host_config() }, - ..Default::default() - }; + "configuration": { "config": get_host_config() }, + }); + + build_genesis_storage(genesis_config, westend_runtime::WASM_BINARY.unwrap()) + } + + #[cfg(test)] + mod legacy_vs_json_check { + use super::*; + fn genesis() -> Storage { + let genesis_config = westend_runtime::RuntimeGenesisConfig { + system: westend_runtime::SystemConfig::default(), + balances: westend_runtime::BalancesConfig { + balances: accounts::init_balances() + .iter() + .cloned() + .map(|k| (k, ENDOWMENT)) + .collect(), + }, + session: westend_runtime::SessionConfig { + keys: validators::initial_authorities() + .iter() + .map(|x| { + ( + x.0.clone(), + x.0.clone(), + westend::session_keys( + x.2.clone(), + x.3.clone(), + x.4.clone(), + x.5.clone(), + x.6.clone(), + x.7.clone(), + get_from_seed::("Alice"), + ), + ) + }) + .collect::>(), + }, + staking: westend_runtime::StakingConfig { + validator_count: validators::initial_authorities().len() as u32, + minimum_validator_count: 1, + stakers: validators::initial_authorities() + .iter() + .map(|x| { + ( + x.0.clone(), + x.1.clone(), + STASH, + westend_runtime::StakerStatus::Validator, + ) + }) + .collect(), + invulnerables: validators::initial_authorities() + .iter() + .map(|x| x.0.clone()) + .collect(), + force_era: pallet_staking::Forcing::ForceNone, + slash_reward_fraction: Perbill::from_percent(10), + ..Default::default() + }, + babe: westend_runtime::BabeConfig { + authorities: Default::default(), + epoch_config: Some(westend_runtime::BABE_GENESIS_EPOCH_CONFIG), + ..Default::default() + }, + configuration: westend_runtime::ConfigurationConfig { config: get_host_config() }, + ..Default::default() + }; + + build_genesis_storage_legacy(&genesis_config, westend_runtime::WASM_BINARY.unwrap()) + } + + #[test] + fn test_genesis() { + let j1 = super::genesis(); + let j2 = genesis(); - genesis_config.build_storage().unwrap() + assert_eq!(j1.top, j2.top); + assert_eq!(j1.children_default, j2.children_default); + } } } @@ -415,19 +612,15 @@ pub mod kusama { } pub fn genesis() -> Storage { - let genesis_config = kusama_runtime::RuntimeGenesisConfig { - system: kusama_runtime::SystemConfig { - code: kusama_runtime::WASM_BINARY.unwrap().to_vec(), - ..Default::default() - }, - balances: kusama_runtime::BalancesConfig { - balances: accounts::init_balances() + let genesis_config = serde_json::json!({ + "balances": { + "balances": accounts::init_balances() .iter() .map(|k: &AccountId| (k.clone(), ENDOWMENT)) - .collect(), + .collect::>(), }, - session: kusama_runtime::SessionConfig { - keys: validators::initial_authorities() + "session": { + "keys": validators::initial_authorities() .iter() .map(|x| { ( @@ -446,33 +639,35 @@ pub mod kusama { }) .collect::>(), }, - staking: kusama_runtime::StakingConfig { - validator_count: validators::initial_authorities().len() as u32, - minimum_validator_count: 1, - stakers: validators::initial_authorities() + "staking": { + "validatorCount": validators::initial_authorities().len() as u32, + "minimumValidatorCount": 1, + "stakers": validators::initial_authorities() .iter() .map(|x| { - (x.0.clone(), x.1.clone(), STASH, kusama_runtime::StakerStatus::Validator) + ( + x.0.clone(), + x.1.clone(), + STASH, + kusama_runtime::StakerStatus::::Validator, + ) }) - .collect(), - invulnerables: validators::initial_authorities() + .collect::>(), + "invulnerables": validators::initial_authorities() .iter() .map(|x| x.0.clone()) - .collect(), - force_era: pallet_staking::Forcing::NotForcing, - slash_reward_fraction: Perbill::from_percent(10), - ..Default::default() + .collect::>(), + "forceEra": pallet_staking::Forcing::NotForcing, + "slashRewardFraction": Perbill::from_percent(10), }, - babe: kusama_runtime::BabeConfig { - authorities: Default::default(), - epoch_config: Some(kusama_runtime::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() + "babe": { + "epochConfig": Some(kusama_runtime::BABE_GENESIS_EPOCH_CONFIG), }, - configuration: kusama_runtime::ConfigurationConfig { config: get_host_config() }, - paras: kusama_runtime::ParasConfig { - paras: vec![ + "configuration": { "config": get_host_config() }, + "paras": { + "paras": vec![ ( - asset_hub_kusama::PARA_ID.into(), + cumulus_primitives_core::ParaId::from(asset_hub_kusama::PARA_ID), ParaGenesisArgs { genesis_head: HeadData::default(), validation_code: ValidationCode( @@ -482,7 +677,7 @@ pub mod kusama { }, ), ( - penpal::PARA_ID_A.into(), + cumulus_primitives_core::ParaId::from(penpal::PARA_ID_A), ParaGenesisArgs { genesis_head: HeadData::default(), validation_code: ValidationCode( @@ -492,7 +687,7 @@ pub mod kusama { }, ), ( - penpal::PARA_ID_B.into(), + cumulus_primitives_core::ParaId::from(penpal::PARA_ID_B), ParaGenesisArgs { genesis_head: HeadData::default(), validation_code: ValidationCode( @@ -502,12 +697,121 @@ pub mod kusama { }, ), ], - ..Default::default() }, - ..Default::default() - }; + }); - genesis_config.build_storage().unwrap() + build_genesis_storage(genesis_config, kusama_runtime::WASM_BINARY.unwrap()) + } + + #[cfg(test)] + mod legacy_vs_json_check { + use super::*; + fn genesis() -> Storage { + let genesis_config = kusama_runtime::RuntimeGenesisConfig { + system: kusama_runtime::SystemConfig::default(), + balances: kusama_runtime::BalancesConfig { + balances: accounts::init_balances() + .iter() + .map(|k: &AccountId| (k.clone(), ENDOWMENT)) + .collect(), + }, + session: kusama_runtime::SessionConfig { + keys: validators::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(), + get_from_seed::("Alice"), + ), + ) + }) + .collect::>(), + }, + staking: kusama_runtime::StakingConfig { + validator_count: validators::initial_authorities().len() as u32, + minimum_validator_count: 1, + stakers: validators::initial_authorities() + .iter() + .map(|x| { + ( + x.0.clone(), + x.1.clone(), + STASH, + kusama_runtime::StakerStatus::Validator, + ) + }) + .collect(), + invulnerables: validators::initial_authorities() + .iter() + .map(|x| x.0.clone()) + .collect(), + force_era: pallet_staking::Forcing::NotForcing, + slash_reward_fraction: Perbill::from_percent(10), + ..Default::default() + }, + babe: kusama_runtime::BabeConfig { + authorities: Default::default(), + epoch_config: Some(kusama_runtime::BABE_GENESIS_EPOCH_CONFIG), + ..Default::default() + }, + configuration: kusama_runtime::ConfigurationConfig { config: get_host_config() }, + paras: kusama_runtime::ParasConfig { + paras: vec![ + ( + asset_hub_kusama::PARA_ID.into(), + ParaGenesisArgs { + genesis_head: HeadData::default(), + validation_code: ValidationCode( + asset_hub_kusama_runtime::WASM_BINARY.unwrap().to_vec(), + ), + para_kind: ParaKind::Parachain, + }, + ), + ( + penpal::PARA_ID_A.into(), + ParaGenesisArgs { + genesis_head: HeadData::default(), + validation_code: ValidationCode( + penpal_runtime::WASM_BINARY.unwrap().to_vec(), + ), + para_kind: ParaKind::Parachain, + }, + ), + ( + penpal::PARA_ID_B.into(), + ParaGenesisArgs { + genesis_head: HeadData::default(), + validation_code: ValidationCode( + penpal_runtime::WASM_BINARY.unwrap().to_vec(), + ), + para_kind: ParaKind::Parachain, + }, + ), + ], + ..Default::default() + }, + ..Default::default() + }; + + build_genesis_storage_legacy(&genesis_config, kusama_runtime::WASM_BINARY.unwrap()) + } + + #[test] + fn test_genesis() { + let j1 = super::genesis(); + let j2 = genesis(); + + assert_eq!(j1.top, j2.top); + assert_eq!(j1.children_default, j2.children_default); + } } } @@ -557,20 +861,16 @@ pub mod rococo { } pub fn genesis() -> Storage { - let genesis_config = rococo_runtime::RuntimeGenesisConfig { - system: rococo_runtime::SystemConfig { - code: rococo_runtime::WASM_BINARY.unwrap().to_vec(), - ..Default::default() - }, - balances: rococo_runtime::BalancesConfig { - balances: accounts::init_balances() + let genesis_config = serde_json::json!({ + "balances": { + "balances": accounts::init_balances() .iter() .map(|k| (k.clone(), ENDOWMENT)) - .collect(), + .collect::>(), }, // indices: rococo_runtime::IndicesConfig { indices: vec![] }, - session: rococo_runtime::SessionConfig { - keys: validators::initial_authorities() + "session": { + "keys": validators::initial_authorities() .iter() .map(|x| { ( @@ -589,23 +889,81 @@ pub mod rococo { }) .collect::>(), }, - babe: rococo_runtime::BabeConfig { - authorities: Default::default(), - epoch_config: Some(rococo_runtime::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() + "babe": { + "epochConfig": Some(rococo_runtime::BABE_GENESIS_EPOCH_CONFIG), }, - sudo: rococo_runtime::SudoConfig { - key: Some(get_account_id_from_seed::("Alice")), + "sudo": { + "key": Some(get_account_id_from_seed::("Alice")), }, - configuration: rococo_runtime::ConfigurationConfig { config: get_host_config() }, - registrar: rococo_runtime::RegistrarConfig { - next_free_para_id: polkadot_primitives::LOWEST_PUBLIC_ID, - ..Default::default() + "configuration": { "config": get_host_config() }, + "registrar": { + "nextFreeParaId": polkadot_primitives::LOWEST_PUBLIC_ID, }, - ..Default::default() - }; + }); - genesis_config.build_storage().unwrap() + build_genesis_storage(genesis_config, rococo_runtime::WASM_BINARY.unwrap()) + } + + #[cfg(test)] + mod legacy_vs_json_check { + use super::*; + fn genesis() -> Storage { + let genesis_config = rococo_runtime::RuntimeGenesisConfig { + system: rococo_runtime::SystemConfig::default(), + balances: rococo_runtime::BalancesConfig { + balances: accounts::init_balances() + .iter() + .map(|k| (k.clone(), ENDOWMENT)) + .collect(), + }, + // indices: rococo_runtime::IndicesConfig { indices: vec![] }, + session: rococo_runtime::SessionConfig { + keys: validators::initial_authorities() + .iter() + .map(|x| { + ( + x.0.clone(), + x.0.clone(), + session_keys( + x.2.clone(), + x.3.clone(), + x.4.clone(), + x.5.clone(), + x.6.clone(), + x.7.clone(), + get_from_seed::("Alice"), + ), + ) + }) + .collect::>(), + }, + babe: rococo_runtime::BabeConfig { + authorities: Default::default(), + epoch_config: Some(rococo_runtime::BABE_GENESIS_EPOCH_CONFIG), + ..Default::default() + }, + sudo: rococo_runtime::SudoConfig { + key: Some(get_account_id_from_seed::("Alice")), + }, + configuration: rococo_runtime::ConfigurationConfig { config: get_host_config() }, + registrar: rococo_runtime::RegistrarConfig { + next_free_para_id: polkadot_primitives::LOWEST_PUBLIC_ID, + ..Default::default() + }, + ..Default::default() + }; + + build_genesis_storage_legacy(&genesis_config, rococo_runtime::WASM_BINARY.unwrap()) + } + + #[test] + fn test_genesis() { + let j1 = super::genesis(); + let j2 = genesis(); + + assert_eq!(j1.top, j2.top); + assert_eq!(j1.children_default, j2.children_default); + } } } @@ -616,35 +974,27 @@ pub mod asset_hub_polkadot { pub const ED: Balance = asset_hub_polkadot_runtime::constants::currency::EXISTENTIAL_DEPOSIT; pub fn genesis() -> Storage { - let genesis_config = asset_hub_polkadot_runtime::RuntimeGenesisConfig { - system: asset_hub_polkadot_runtime::SystemConfig { - code: asset_hub_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: asset_hub_polkadot_runtime::BalancesConfig { - balances: accounts::init_balances() + let genesis_config = serde_json::json!({ + "balances": { + "balances": accounts::init_balances() .iter() .cloned() .map(|k| (k, ED * 4096)) - .collect(), + .collect::>(), }, - parachain_info: asset_hub_polkadot_runtime::ParachainInfoConfig { - parachain_id: PARA_ID.into(), - ..Default::default() + "parachainInfo": { + "parachainId": cumulus_primitives_core::ParaId::from(PARA_ID), }, - collator_selection: asset_hub_polkadot_runtime::CollatorSelectionConfig { - invulnerables: collators::invulnerables_asset_hub_polkadot() + "collatorSelection": { + "invulnerables": collators::invulnerables_asset_hub_polkadot() .iter() .cloned() .map(|(acc, _)| acc) - .collect(), - candidacy_bond: ED * 16, - ..Default::default() + .collect::>(), + "candidacyBond": ED * 16, }, - session: asset_hub_polkadot_runtime::SessionConfig { - keys: collators::invulnerables_asset_hub_polkadot() + "session": { + "keys": collators::invulnerables_asset_hub_polkadot() .into_iter() .map(|(acc, aura)| { ( @@ -653,16 +1003,80 @@ pub mod asset_hub_polkadot { asset_hub_polkadot_runtime::SessionKeys { aura }, // session keys ) }) - .collect(), + .collect::>(), }, - polkadot_xcm: asset_hub_polkadot_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() + "polkadotXcm": { + "safeXcmVersion": Some(SAFE_XCM_VERSION), }, - ..Default::default() - }; + }); + + build_genesis_storage( + genesis_config, + asset_hub_polkadot_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + } + + #[cfg(test)] + mod legacy_vs_json_check { + use super::*; + fn genesis() -> Storage { + let genesis_config = asset_hub_polkadot_runtime::RuntimeGenesisConfig { + system: asset_hub_polkadot_runtime::SystemConfig::default(), + balances: asset_hub_polkadot_runtime::BalancesConfig { + balances: accounts::init_balances() + .iter() + .cloned() + .map(|k| (k, ED * 4096)) + .collect(), + }, + parachain_info: asset_hub_polkadot_runtime::ParachainInfoConfig { + parachain_id: PARA_ID.into(), + ..Default::default() + }, + collator_selection: asset_hub_polkadot_runtime::CollatorSelectionConfig { + invulnerables: collators::invulnerables_asset_hub_polkadot() + .iter() + .cloned() + .map(|(acc, _)| acc) + .collect(), + candidacy_bond: ED * 16, + ..Default::default() + }, + session: asset_hub_polkadot_runtime::SessionConfig { + keys: collators::invulnerables_asset_hub_polkadot() + .into_iter() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc, // validator id + asset_hub_polkadot_runtime::SessionKeys { aura }, // session keys + ) + }) + .collect(), + }, + polkadot_xcm: asset_hub_polkadot_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + ..Default::default() + }; + + build_genesis_storage_legacy( + &genesis_config, + asset_hub_polkadot_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + } + + #[test] + fn test_genesis() { + let j1 = super::genesis(); + let j2 = genesis(); - genesis_config.build_storage().unwrap() + assert_eq!(j1.top, j2.top); + assert_eq!(j1.children_default, j2.children_default); + } } } @@ -673,35 +1087,27 @@ pub mod asset_hub_westend { pub const ED: Balance = asset_hub_westend_runtime::constants::currency::EXISTENTIAL_DEPOSIT; pub fn genesis() -> Storage { - let genesis_config = asset_hub_westend_runtime::RuntimeGenesisConfig { - system: asset_hub_westend_runtime::SystemConfig { - code: asset_hub_westend_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: asset_hub_westend_runtime::BalancesConfig { - balances: accounts::init_balances() + let genesis_config = serde_json::json!({ + "balances": { + "balances": accounts::init_balances() .iter() .cloned() .map(|k| (k, ED * 4096)) - .collect(), + .collect::>(), }, - parachain_info: asset_hub_westend_runtime::ParachainInfoConfig { - parachain_id: PARA_ID.into(), - ..Default::default() + "parachainInfo": { + "parachainId": cumulus_primitives_core::ParaId::from(PARA_ID), }, - collator_selection: asset_hub_westend_runtime::CollatorSelectionConfig { - invulnerables: collators::invulnerables() + "collatorSelection": { + "invulnerables": collators::invulnerables() .iter() .cloned() .map(|(acc, _)| acc) - .collect(), - candidacy_bond: ED * 16, - ..Default::default() + .collect::>(), + "candidacyBond": ED * 16, }, - session: asset_hub_westend_runtime::SessionConfig { - keys: collators::invulnerables() + "session": { + "keys": collators::invulnerables() .into_iter() .map(|(acc, aura)| { ( @@ -710,16 +1116,80 @@ pub mod asset_hub_westend { asset_hub_westend_runtime::SessionKeys { aura }, // session keys ) }) - .collect(), + .collect::>(), }, - polkadot_xcm: asset_hub_westend_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() + "polkadotXcm": { + "safeXcmVersion": Some(SAFE_XCM_VERSION), }, - ..Default::default() - }; + }); - genesis_config.build_storage().unwrap() + build_genesis_storage( + genesis_config, + asset_hub_westend_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + } + + #[cfg(test)] + mod legacy_vs_json_check { + use super::*; + fn genesis() -> Storage { + let genesis_config = asset_hub_westend_runtime::RuntimeGenesisConfig { + system: asset_hub_westend_runtime::SystemConfig::default(), + balances: asset_hub_westend_runtime::BalancesConfig { + balances: accounts::init_balances() + .iter() + .cloned() + .map(|k| (k, ED * 4096)) + .collect(), + }, + parachain_info: asset_hub_westend_runtime::ParachainInfoConfig { + parachain_id: PARA_ID.into(), + ..Default::default() + }, + collator_selection: asset_hub_westend_runtime::CollatorSelectionConfig { + invulnerables: collators::invulnerables() + .iter() + .cloned() + .map(|(acc, _)| acc) + .collect(), + candidacy_bond: ED * 16, + ..Default::default() + }, + session: asset_hub_westend_runtime::SessionConfig { + keys: collators::invulnerables() + .into_iter() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc, // validator id + asset_hub_westend_runtime::SessionKeys { aura }, // session keys + ) + }) + .collect(), + }, + polkadot_xcm: asset_hub_westend_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + ..Default::default() + }; + + build_genesis_storage_legacy( + &genesis_config, + asset_hub_westend_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + } + + #[test] + fn test_genesis() { + let j1 = super::genesis(); + let j2 = genesis(); + + assert_eq!(j1.top, j2.top); + assert_eq!(j1.children_default, j2.children_default); + } } } @@ -730,35 +1200,27 @@ pub mod asset_hub_kusama { pub const ED: Balance = asset_hub_kusama_runtime::constants::currency::EXISTENTIAL_DEPOSIT; pub fn genesis() -> Storage { - let genesis_config = asset_hub_kusama_runtime::RuntimeGenesisConfig { - system: asset_hub_kusama_runtime::SystemConfig { - code: asset_hub_kusama_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: asset_hub_kusama_runtime::BalancesConfig { - balances: accounts::init_balances() + let genesis_config = serde_json::json!({ + "balances": { + "balances": accounts::init_balances() .iter() .cloned() .map(|k| (k, ED * 4096)) - .collect(), + .collect::>(), }, - parachain_info: asset_hub_kusama_runtime::ParachainInfoConfig { - parachain_id: PARA_ID.into(), - ..Default::default() + "parachainInfo": { + "parachainId": cumulus_primitives_core::ParaId::from(PARA_ID) }, - collator_selection: asset_hub_kusama_runtime::CollatorSelectionConfig { - invulnerables: collators::invulnerables() + "collatorSelection": { + "invulnerables": collators::invulnerables() .iter() .cloned() .map(|(acc, _)| acc) - .collect(), - candidacy_bond: ED * 16, - ..Default::default() + .collect::>(), + "candidacyBond": ED * 16, }, - session: asset_hub_kusama_runtime::SessionConfig { - keys: collators::invulnerables() + "session": { + "keys": collators::invulnerables() .into_iter() .map(|(acc, aura)| { ( @@ -767,16 +1229,80 @@ pub mod asset_hub_kusama { asset_hub_kusama_runtime::SessionKeys { aura }, // session keys ) }) - .collect(), + .collect::>(), }, - polkadot_xcm: asset_hub_kusama_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() + "polkadotXcm": { + "safeXcmVersion": Some(SAFE_XCM_VERSION), }, - ..Default::default() - }; + }); - genesis_config.build_storage().unwrap() + build_genesis_storage( + genesis_config, + asset_hub_kusama_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + } + + #[cfg(test)] + mod legacy_vs_json_check { + use super::*; + fn genesis() -> Storage { + let genesis_config = asset_hub_kusama_runtime::RuntimeGenesisConfig { + system: asset_hub_kusama_runtime::SystemConfig::default(), + balances: asset_hub_kusama_runtime::BalancesConfig { + balances: accounts::init_balances() + .iter() + .cloned() + .map(|k| (k, ED * 4096)) + .collect(), + }, + parachain_info: asset_hub_kusama_runtime::ParachainInfoConfig { + parachain_id: PARA_ID.into(), + ..Default::default() + }, + collator_selection: asset_hub_kusama_runtime::CollatorSelectionConfig { + invulnerables: collators::invulnerables() + .iter() + .cloned() + .map(|(acc, _)| acc) + .collect(), + candidacy_bond: ED * 16, + ..Default::default() + }, + session: asset_hub_kusama_runtime::SessionConfig { + keys: collators::invulnerables() + .into_iter() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc, // validator id + asset_hub_kusama_runtime::SessionKeys { aura }, // session keys + ) + }) + .collect(), + }, + polkadot_xcm: asset_hub_kusama_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + ..Default::default() + }; + + build_genesis_storage_legacy( + &genesis_config, + asset_hub_kusama_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + } + + #[test] + fn test_genesis() { + let j1 = super::genesis(); + let j2 = genesis(); + + assert_eq!(j1.top, j2.top); + assert_eq!(j1.children_default, j2.children_default); + } } } @@ -788,35 +1314,27 @@ pub mod penpal { pub const ED: Balance = penpal_runtime::EXISTENTIAL_DEPOSIT; pub fn genesis(para_id: u32) -> Storage { - let genesis_config = penpal_runtime::RuntimeGenesisConfig { - system: penpal_runtime::SystemConfig { - code: penpal_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: penpal_runtime::BalancesConfig { - balances: accounts::init_balances() + let genesis_config = serde_json::json!({ + "balances": { + "balances": accounts::init_balances() .iter() .cloned() .map(|k| (k, ED * 4096)) - .collect(), + .collect::>(), }, - parachain_info: penpal_runtime::ParachainInfoConfig { - parachain_id: para_id.into(), - ..Default::default() + "parachainInfo": { + "parachainId": cumulus_primitives_core::ParaId::from(para_id), }, - collator_selection: penpal_runtime::CollatorSelectionConfig { - invulnerables: collators::invulnerables() + "collatorSelection": { + "invulnerables": collators::invulnerables() .iter() .cloned() .map(|(acc, _)| acc) - .collect(), - candidacy_bond: ED * 16, - ..Default::default() + .collect::>(), + "candidacyBond": ED * 16, }, - session: penpal_runtime::SessionConfig { - keys: collators::invulnerables() + "session": { + "keys": collators::invulnerables() .into_iter() .map(|(acc, aura)| { ( @@ -825,19 +1343,84 @@ pub mod penpal { penpal_runtime::SessionKeys { aura }, // session keys ) }) - .collect(), + .collect::>(), }, - polkadot_xcm: penpal_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() + "polkadotXcm": { + "safeXcmVersion": Some(SAFE_XCM_VERSION), }, - sudo: penpal_runtime::SudoConfig { - key: Some(get_account_id_from_seed::("Alice")), + "sudo": { + "key": Some(get_account_id_from_seed::("Alice")), }, - ..Default::default() - }; + }); + + build_genesis_storage( + genesis_config, + penpal_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) + } + + #[cfg(test)] + mod legacy_vs_json_check { + use super::*; + fn genesis(para_id: u32) -> Storage { + let genesis_config = penpal_runtime::RuntimeGenesisConfig { + system: penpal_runtime::SystemConfig::default(), + balances: penpal_runtime::BalancesConfig { + balances: accounts::init_balances() + .iter() + .cloned() + .map(|k| (k, ED * 4096)) + .collect(), + }, + parachain_info: penpal_runtime::ParachainInfoConfig { + parachain_id: para_id.into(), + ..Default::default() + }, + collator_selection: penpal_runtime::CollatorSelectionConfig { + invulnerables: collators::invulnerables() + .iter() + .cloned() + .map(|(acc, _)| acc) + .collect(), + candidacy_bond: ED * 16, + ..Default::default() + }, + session: penpal_runtime::SessionConfig { + keys: collators::invulnerables() + .into_iter() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc, // validator id + penpal_runtime::SessionKeys { aura }, // session keys + ) + }) + .collect(), + }, + polkadot_xcm: penpal_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + sudo: penpal_runtime::SudoConfig { + key: Some(get_account_id_from_seed::("Alice")), + }, + ..Default::default() + }; + + build_genesis_storage_legacy( + &genesis_config, + penpal_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) + } - genesis_config.build_storage().unwrap() + #[test] + fn test_genesis() { + let j1 = super::genesis(101); + let j2 = genesis(101); + + assert_eq!(j1.top, j2.top); + assert_eq!(j1.children_default, j2.children_default); + } } } @@ -848,35 +1431,27 @@ pub mod collectives { pub const ED: Balance = collectives_polkadot_runtime::constants::currency::EXISTENTIAL_DEPOSIT; pub fn genesis() -> Storage { - let genesis_config = collectives_polkadot_runtime::RuntimeGenesisConfig { - system: collectives_polkadot_runtime::SystemConfig { - code: collectives_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: collectives_polkadot_runtime::BalancesConfig { - balances: accounts::init_balances() + let genesis_config = serde_json::json!({ + "balances": { + "balances": accounts::init_balances() .iter() .cloned() .map(|k| (k, ED * 4096)) - .collect(), + .collect::>(), }, - parachain_info: collectives_polkadot_runtime::ParachainInfoConfig { - parachain_id: PARA_ID.into(), - ..Default::default() + "parachainInfo": { + "parachainId": cumulus_primitives_core::ParaId::from(PARA_ID), }, - collator_selection: collectives_polkadot_runtime::CollatorSelectionConfig { - invulnerables: collators::invulnerables() + "collatorSelection": { + "invulnerables": collators::invulnerables() .iter() .cloned() .map(|(acc, _)| acc) - .collect(), - candidacy_bond: ED * 16, - ..Default::default() + .collect::>(), + "candidacyBond": ED * 16, }, - session: collectives_polkadot_runtime::SessionConfig { - keys: collators::invulnerables() + "session": { + "keys": collators::invulnerables() .into_iter() .map(|(acc, aura)| { ( @@ -885,16 +1460,80 @@ pub mod collectives { collectives_polkadot_runtime::SessionKeys { aura }, // session keys ) }) - .collect(), + .collect::>(), }, - polkadot_xcm: collectives_polkadot_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() + "polkadotXcm": { + "safeXcmVersion": Some(SAFE_XCM_VERSION), }, - ..Default::default() - }; + }); - genesis_config.build_storage().unwrap() + build_genesis_storage( + genesis_config, + collectives_polkadot_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + } + + #[cfg(test)] + mod legacy_vs_json_check { + use super::*; + fn genesis() -> Storage { + let genesis_config = collectives_polkadot_runtime::RuntimeGenesisConfig { + system: collectives_polkadot_runtime::SystemConfig::default(), + balances: collectives_polkadot_runtime::BalancesConfig { + balances: accounts::init_balances() + .iter() + .cloned() + .map(|k| (k, ED * 4096)) + .collect(), + }, + parachain_info: collectives_polkadot_runtime::ParachainInfoConfig { + parachain_id: PARA_ID.into(), + ..Default::default() + }, + collator_selection: collectives_polkadot_runtime::CollatorSelectionConfig { + invulnerables: collators::invulnerables() + .iter() + .cloned() + .map(|(acc, _)| acc) + .collect(), + candidacy_bond: ED * 16, + ..Default::default() + }, + session: collectives_polkadot_runtime::SessionConfig { + keys: collators::invulnerables() + .into_iter() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc, // validator id + collectives_polkadot_runtime::SessionKeys { aura }, // session keys + ) + }) + .collect(), + }, + polkadot_xcm: collectives_polkadot_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + ..Default::default() + }; + + build_genesis_storage_legacy( + &genesis_config, + collectives_polkadot_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + } + + #[test] + fn test_genesis() { + let j1 = super::genesis(); + let j2 = genesis(); + + assert_eq!(j1.top, j2.top); + assert_eq!(j1.children_default, j2.children_default); + } } } @@ -905,35 +1544,27 @@ pub mod bridge_hub_kusama { pub const ED: Balance = bridge_hub_kusama_runtime::constants::currency::EXISTENTIAL_DEPOSIT; pub fn genesis() -> Storage { - let genesis_config = bridge_hub_kusama_runtime::RuntimeGenesisConfig { - system: bridge_hub_kusama_runtime::SystemConfig { - code: bridge_hub_kusama_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: bridge_hub_kusama_runtime::BalancesConfig { - balances: accounts::init_balances() + let genesis_config = serde_json::json!({ + "balances": { + "balances": accounts::init_balances() .iter() .cloned() .map(|k| (k, ED * 4096)) - .collect(), + .collect::>(), }, - parachain_info: bridge_hub_kusama_runtime::ParachainInfoConfig { - parachain_id: PARA_ID.into(), - ..Default::default() + "parachainInfo": { + "parachainId": cumulus_primitives_core::ParaId::from(PARA_ID), }, - collator_selection: bridge_hub_kusama_runtime::CollatorSelectionConfig { - invulnerables: collators::invulnerables() + "collatorSelection": { + "invulnerables": collators::invulnerables() .iter() .cloned() .map(|(acc, _)| acc) - .collect(), - candidacy_bond: ED * 16, - ..Default::default() + .collect::>(), + "candidacyBond": ED * 16, }, - session: bridge_hub_kusama_runtime::SessionConfig { - keys: collators::invulnerables() + "session": { + "keys": collators::invulnerables() .into_iter() .map(|(acc, aura)| { ( @@ -942,16 +1573,80 @@ pub mod bridge_hub_kusama { bridge_hub_kusama_runtime::SessionKeys { aura }, // session keys ) }) - .collect(), + .collect::>(), }, - polkadot_xcm: bridge_hub_kusama_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() + "polkadotXcm": { + "safeXcmVersion": Some(SAFE_XCM_VERSION), }, - ..Default::default() - }; + }); - genesis_config.build_storage().unwrap() + build_genesis_storage( + genesis_config, + bridge_hub_kusama_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + } + + #[cfg(test)] + mod legacy_vs_json_check { + use super::*; + fn genesis() -> Storage { + let genesis_config = bridge_hub_kusama_runtime::RuntimeGenesisConfig { + system: bridge_hub_kusama_runtime::SystemConfig::default(), + balances: bridge_hub_kusama_runtime::BalancesConfig { + balances: accounts::init_balances() + .iter() + .cloned() + .map(|k| (k, ED * 4096)) + .collect(), + }, + parachain_info: bridge_hub_kusama_runtime::ParachainInfoConfig { + parachain_id: PARA_ID.into(), + ..Default::default() + }, + collator_selection: bridge_hub_kusama_runtime::CollatorSelectionConfig { + invulnerables: collators::invulnerables() + .iter() + .cloned() + .map(|(acc, _)| acc) + .collect(), + candidacy_bond: ED * 16, + ..Default::default() + }, + session: bridge_hub_kusama_runtime::SessionConfig { + keys: collators::invulnerables() + .into_iter() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc, // validator id + bridge_hub_kusama_runtime::SessionKeys { aura }, // session keys + ) + }) + .collect(), + }, + polkadot_xcm: bridge_hub_kusama_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + ..Default::default() + }; + + build_genesis_storage_legacy( + &genesis_config, + bridge_hub_kusama_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + } + + #[test] + fn test_genesis() { + let j1 = super::genesis(); + let j2 = genesis(); + + assert_eq!(j1.top, j2.top); + assert_eq!(j1.children_default, j2.children_default); + } } } @@ -962,35 +1657,27 @@ pub mod bridge_hub_polkadot { pub const ED: Balance = bridge_hub_polkadot_runtime::constants::currency::EXISTENTIAL_DEPOSIT; pub fn genesis() -> Storage { - let genesis_config = bridge_hub_polkadot_runtime::RuntimeGenesisConfig { - system: bridge_hub_polkadot_runtime::SystemConfig { - code: bridge_hub_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: bridge_hub_polkadot_runtime::BalancesConfig { - balances: accounts::init_balances() + let genesis_config = serde_json::json!({ + "balances": { + "balances": accounts::init_balances() .iter() .cloned() .map(|k| (k, ED * 4096)) - .collect(), + .collect::>(), }, - parachain_info: bridge_hub_polkadot_runtime::ParachainInfoConfig { - parachain_id: PARA_ID.into(), - ..Default::default() + "parachainInfo": { + "parachainId": cumulus_primitives_core::ParaId::from(PARA_ID), }, - collator_selection: bridge_hub_polkadot_runtime::CollatorSelectionConfig { - invulnerables: collators::invulnerables() + "collatorSelection": { + "invulnerables": collators::invulnerables() .iter() .cloned() .map(|(acc, _)| acc) - .collect(), - candidacy_bond: ED * 16, - ..Default::default() + .collect::>(), + "candidacyBond": ED * 16, }, - session: bridge_hub_polkadot_runtime::SessionConfig { - keys: collators::invulnerables() + "session": { + "keys": collators::invulnerables() .into_iter() .map(|(acc, aura)| { ( @@ -999,16 +1686,80 @@ pub mod bridge_hub_polkadot { bridge_hub_polkadot_runtime::SessionKeys { aura }, // session keys ) }) - .collect(), + .collect::>(), }, - polkadot_xcm: bridge_hub_polkadot_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() + "polkadotXcm": { + "safeXcmVersion": Some(SAFE_XCM_VERSION), }, - ..Default::default() - }; + }); + + build_genesis_storage( + genesis_config, + bridge_hub_polkadot_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + } - genesis_config.build_storage().unwrap() + #[cfg(test)] + mod legacy_vs_json_check { + use super::*; + fn genesis() -> Storage { + let genesis_config = bridge_hub_polkadot_runtime::RuntimeGenesisConfig { + system: bridge_hub_polkadot_runtime::SystemConfig::default(), + balances: bridge_hub_polkadot_runtime::BalancesConfig { + balances: accounts::init_balances() + .iter() + .cloned() + .map(|k| (k, ED * 4096)) + .collect(), + }, + parachain_info: bridge_hub_polkadot_runtime::ParachainInfoConfig { + parachain_id: PARA_ID.into(), + ..Default::default() + }, + collator_selection: bridge_hub_polkadot_runtime::CollatorSelectionConfig { + invulnerables: collators::invulnerables() + .iter() + .cloned() + .map(|(acc, _)| acc) + .collect(), + candidacy_bond: ED * 16, + ..Default::default() + }, + session: bridge_hub_polkadot_runtime::SessionConfig { + keys: collators::invulnerables() + .into_iter() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc, // validator id + bridge_hub_polkadot_runtime::SessionKeys { aura }, // session keys + ) + }) + .collect(), + }, + polkadot_xcm: bridge_hub_polkadot_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + ..Default::default() + }; + + build_genesis_storage_legacy( + &genesis_config, + bridge_hub_polkadot_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + } + + #[test] + fn test_genesis() { + let j1 = super::genesis(); + let j2 = genesis(); + + assert_eq!(j1.top, j2.top); + assert_eq!(j1.children_default, j2.children_default); + } } } @@ -1019,35 +1770,27 @@ pub mod bridge_hub_rococo { pub const ED: Balance = bridge_hub_rococo_runtime::constants::currency::EXISTENTIAL_DEPOSIT; pub fn genesis() -> Storage { - let genesis_config = bridge_hub_rococo_runtime::RuntimeGenesisConfig { - system: bridge_hub_rococo_runtime::SystemConfig { - code: bridge_hub_rococo_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: bridge_hub_rococo_runtime::BalancesConfig { - balances: accounts::init_balances() + let genesis_config = serde_json::json!({ + "balances": { + "balances": accounts::init_balances() .iter() .cloned() .map(|k| (k, ED * 4096)) - .collect(), + .collect::>(), }, - parachain_info: bridge_hub_rococo_runtime::ParachainInfoConfig { - parachain_id: PARA_ID.into(), - ..Default::default() + "parachainInfo": { + "parachainId": cumulus_primitives_core::ParaId::from(PARA_ID), }, - collator_selection: bridge_hub_rococo_runtime::CollatorSelectionConfig { - invulnerables: collators::invulnerables() + "collatorSelection": { + "invulnerables": collators::invulnerables() .iter() .cloned() .map(|(acc, _)| acc) - .collect(), - candidacy_bond: ED * 16, - ..Default::default() + .collect::>(), + "candidacyBond": ED * 16, }, - session: bridge_hub_rococo_runtime::SessionConfig { - keys: collators::invulnerables() + "session": { + "keys": collators::invulnerables() .into_iter() .map(|(acc, aura)| { ( @@ -1056,31 +1799,107 @@ pub mod bridge_hub_rococo { bridge_hub_rococo_runtime::SessionKeys { aura }, // session keys ) }) - .collect(), + .collect::>(), }, - polkadot_xcm: bridge_hub_rococo_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() + "polkadotXcm": { + "safeXcmVersion": Some(SAFE_XCM_VERSION), }, - bridge_wococo_grandpa: bridge_hub_rococo_runtime::BridgeWococoGrandpaConfig { - owner: Some(get_account_id_from_seed::(accounts::BOB)), - ..Default::default() + "bridgeWococoGrandpa": { + "owner": Some(get_account_id_from_seed::(accounts::BOB)), }, - bridge_rococo_grandpa: bridge_hub_rococo_runtime::BridgeRococoGrandpaConfig { - owner: Some(get_account_id_from_seed::(accounts::BOB)), - ..Default::default() + "bridgeRococoGrandpa": { + "owner": Some(get_account_id_from_seed::(accounts::BOB)), }, - bridge_rococo_messages: bridge_hub_rococo_runtime::BridgeRococoMessagesConfig { - owner: Some(get_account_id_from_seed::(accounts::BOB)), - ..Default::default() + "bridgeRococoMessages": { + "owner": Some(get_account_id_from_seed::(accounts::BOB)), }, - bridge_wococo_messages: bridge_hub_rococo_runtime::BridgeWococoMessagesConfig { - owner: Some(get_account_id_from_seed::(accounts::BOB)), - ..Default::default() + "bridgeWococoMessages": { + "owner": Some(get_account_id_from_seed::(accounts::BOB)), }, - ..Default::default() - }; + }); + + build_genesis_storage( + genesis_config, + bridge_hub_rococo_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + } - genesis_config.build_storage().unwrap() + #[cfg(test)] + mod legacy_vs_json_check { + use super::*; + fn genesis() -> Storage { + let genesis_config = bridge_hub_rococo_runtime::RuntimeGenesisConfig { + system: bridge_hub_rococo_runtime::SystemConfig::default(), + balances: bridge_hub_rococo_runtime::BalancesConfig { + balances: accounts::init_balances() + .iter() + .cloned() + .map(|k| (k, ED * 4096)) + .collect(), + }, + parachain_info: bridge_hub_rococo_runtime::ParachainInfoConfig { + parachain_id: PARA_ID.into(), + ..Default::default() + }, + collator_selection: bridge_hub_rococo_runtime::CollatorSelectionConfig { + invulnerables: collators::invulnerables() + .iter() + .cloned() + .map(|(acc, _)| acc) + .collect(), + candidacy_bond: ED * 16, + ..Default::default() + }, + session: bridge_hub_rococo_runtime::SessionConfig { + keys: collators::invulnerables() + .into_iter() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc, // validator id + bridge_hub_rococo_runtime::SessionKeys { aura }, // session keys + ) + }) + .collect(), + }, + polkadot_xcm: bridge_hub_rococo_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + bridge_wococo_grandpa: bridge_hub_rococo_runtime::BridgeWococoGrandpaConfig { + owner: Some(get_account_id_from_seed::(accounts::BOB)), + ..Default::default() + }, + bridge_rococo_grandpa: bridge_hub_rococo_runtime::BridgeRococoGrandpaConfig { + owner: Some(get_account_id_from_seed::(accounts::BOB)), + ..Default::default() + }, + bridge_rococo_messages: bridge_hub_rococo_runtime::BridgeRococoMessagesConfig { + owner: Some(get_account_id_from_seed::(accounts::BOB)), + ..Default::default() + }, + bridge_wococo_messages: bridge_hub_rococo_runtime::BridgeWococoMessagesConfig { + owner: Some(get_account_id_from_seed::(accounts::BOB)), + ..Default::default() + }, + ..Default::default() + }; + + build_genesis_storage_legacy( + &genesis_config, + bridge_hub_rococo_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + } + + #[test] + fn test_genesis() { + let j1 = super::genesis(); + let j2 = genesis(); + + assert_eq!(j1.top, j2.top); + assert_eq!(j1.children_default, j2.children_default); + } } } diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-kusama/Cargo.toml index 682581a27b67..77fd1d923d93 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/Cargo.toml @@ -42,6 +42,7 @@ sp-api = { path = "../../../../../substrate/primitives/api", default-features = sp-block-builder = { path = "../../../../../substrate/primitives/block-builder", default-features = false} sp-consensus-aura = { path = "../../../../../substrate/primitives/consensus/aura", default-features = false} sp-core = { path = "../../../../../substrate/primitives/core", default-features = false} +sp-genesis-builder = { path = "../../../../../substrate/primitives/genesis-builder", default-features = false } sp-inherents = { path = "../../../../../substrate/primitives/inherents", default-features = false} sp-offchain = { path = "../../../../../substrate/primitives/offchain", default-features = false} sp-runtime = { path = "../../../../../substrate/primitives/runtime", default-features = false} @@ -196,6 +197,7 @@ std = [ "sp-block-builder/std", "sp-consensus-aura/std", "sp-core/std", + "sp-genesis-builder/std", "sp-inherents/std", "sp-offchain/std", "sp-runtime/std", diff --git a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs index 2130c6502f8e..28bc17c29e46 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs @@ -54,6 +54,7 @@ use constants::{consensus::*, currency::*, fee::WeightToFee}; use frame_support::{ construct_runtime, dispatch::DispatchClass, + genesis_builder_helper::{build_config, create_default_config}, ord_parameter_types, parameter_types, traits::{ AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, EitherOfDiverse, @@ -1340,6 +1341,16 @@ impl_runtime_apis! { Ok(batches) } } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } } cumulus_pallet_parachain_system::register_validate_block! { diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/Cargo.toml index dba374cfa070..1c8db704a045 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/Cargo.toml @@ -39,6 +39,7 @@ sp-api = { path = "../../../../../substrate/primitives/api", default-features = sp-block-builder = { path = "../../../../../substrate/primitives/block-builder", default-features = false} sp-consensus-aura = { path = "../../../../../substrate/primitives/consensus/aura", default-features = false} sp-core = { path = "../../../../../substrate/primitives/core", default-features = false} +sp-genesis-builder = { path = "../../../../../substrate/primitives/genesis-builder", default-features = false } sp-inherents = { path = "../../../../../substrate/primitives/inherents", default-features = false} sp-offchain = { path = "../../../../../substrate/primitives/offchain", default-features = false} sp-runtime = { path = "../../../../../substrate/primitives/runtime", default-features = false} @@ -176,6 +177,7 @@ std = [ "sp-block-builder/std", "sp-consensus-aura/std", "sp-core/std", + "sp-genesis-builder/std", "sp-inherents/std", "sp-offchain/std", "sp-runtime/std", diff --git a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs index 4a81c7fb6e33..e4048ff871e4 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-polkadot/src/lib.rs @@ -86,6 +86,7 @@ use constants::{consensus::*, currency::*, fee::WeightToFee}; use frame_support::{ construct_runtime, dispatch::DispatchClass, + genesis_builder_helper::{build_config, create_default_config}, parameter_types, traits::{ AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, @@ -1219,6 +1220,16 @@ impl_runtime_apis! { Ok(batches) } } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } } cumulus_pallet_parachain_system::register_validate_block! { diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml index 1e9c49cabe45..f1ee264656a0 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/Cargo.toml @@ -41,6 +41,7 @@ sp-api = { path = "../../../../../substrate/primitives/api", default-features = sp-block-builder = { path = "../../../../../substrate/primitives/block-builder", default-features = false} sp-consensus-aura = { path = "../../../../../substrate/primitives/consensus/aura", default-features = false} sp-core = { path = "../../../../../substrate/primitives/core", default-features = false} +sp-genesis-builder = { path = "../../../../../substrate/primitives/genesis-builder", default-features = false } sp-inherents = { path = "../../../../../substrate/primitives/inherents", default-features = false} sp-offchain = { path = "../../../../../substrate/primitives/offchain", default-features = false} sp-runtime = { path = "../../../../../substrate/primitives/runtime", default-features = false} @@ -185,6 +186,7 @@ std = [ "sp-block-builder/std", "sp-consensus-aura/std", "sp-core/std", + "sp-genesis-builder/std", "sp-inherents/std", "sp-offchain/std", "sp-runtime/std", diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 48f2bfa45d80..85ed7e9ebd01 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -41,6 +41,7 @@ use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use frame_support::{ construct_runtime, dispatch::DispatchClass, + genesis_builder_helper::{build_config, create_default_config}, ord_parameter_types, parameter_types, traits::{ tokens::nonfungibles_v2::Inspect, AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU32, @@ -1353,6 +1354,15 @@ impl_runtime_apis! { Ok(batches) } } + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } } cumulus_pallet_parachain_system::register_validate_block! { diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/Cargo.toml index 0dbe3ed9f261..cb8c737144f2 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/Cargo.toml @@ -37,6 +37,7 @@ sp-api = { path = "../../../../../substrate/primitives/api", default-features = sp-block-builder = { path = "../../../../../substrate/primitives/block-builder", default-features = false} sp-consensus-aura = { path = "../../../../../substrate/primitives/consensus/aura", default-features = false} sp-core = { path = "../../../../../substrate/primitives/core", default-features = false} +sp-genesis-builder = { path = "../../../../../substrate/primitives/genesis-builder", default-features = false } sp-inherents = { path = "../../../../../substrate/primitives/inherents", default-features = false} sp-io = { path = "../../../../../substrate/primitives/io", default-features = false} sp-offchain = { path = "../../../../../substrate/primitives/offchain", default-features = false} @@ -113,6 +114,7 @@ std = [ "sp-block-builder/std", "sp-consensus-aura/std", "sp-core/std", + "sp-genesis-builder/std", "sp-inherents/std", "sp-io/std", "sp-offchain/std", diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs index af00e06c7811..0f7b3939b448 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-kusama/src/lib.rs @@ -45,6 +45,7 @@ use constants::{consensus::*, currency::*, fee::WeightToFee}; use frame_support::{ construct_runtime, dispatch::DispatchClass, + genesis_builder_helper::{build_config, create_default_config}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything}, weights::{ConstantMultiplier, Weight}, @@ -779,6 +780,16 @@ impl_runtime_apis! { Ok(batches) } } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } } cumulus_pallet_parachain_system::register_validate_block! { diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/Cargo.toml index 9243f2918dbf..4c22469e54c3 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/Cargo.toml @@ -37,6 +37,7 @@ sp-api = { path = "../../../../../substrate/primitives/api", default-features = sp-block-builder = { path = "../../../../../substrate/primitives/block-builder", default-features = false} sp-consensus-aura = { path = "../../../../../substrate/primitives/consensus/aura", default-features = false} sp-core = { path = "../../../../../substrate/primitives/core", default-features = false} +sp-genesis-builder = { path = "../../../../../substrate/primitives/genesis-builder", default-features = false } sp-inherents = { path = "../../../../../substrate/primitives/inherents", default-features = false} sp-io = { path = "../../../../../substrate/primitives/io", default-features = false} sp-offchain = { path = "../../../../../substrate/primitives/offchain", default-features = false} @@ -113,6 +114,7 @@ std = [ "sp-block-builder/std", "sp-consensus-aura/std", "sp-core/std", + "sp-genesis-builder/std", "sp-inherents/std", "sp-io/std", "sp-offchain/std", diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs index 0a6bddb22571..3213a0919b8e 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-polkadot/src/lib.rs @@ -45,6 +45,7 @@ use constants::{consensus::*, currency::*, fee::WeightToFee}; use frame_support::{ construct_runtime, dispatch::DispatchClass, + genesis_builder_helper::{build_config, create_default_config}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything}, weights::{ConstantMultiplier, Weight}, @@ -779,6 +780,16 @@ impl_runtime_apis! { Ok(batches) } } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } } cumulus_pallet_parachain_system::register_validate_block! { diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml index 5e049dbff108..afcb1f43e537 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/Cargo.toml @@ -37,6 +37,7 @@ sp-api = { path = "../../../../../substrate/primitives/api", default-features = sp-block-builder = { path = "../../../../../substrate/primitives/block-builder", default-features = false} sp-consensus-aura = { path = "../../../../../substrate/primitives/consensus/aura", default-features = false} sp-core = { path = "../../../../../substrate/primitives/core", default-features = false} +sp-genesis-builder = { path = "../../../../../substrate/primitives/genesis-builder", default-features = false } sp-inherents = { path = "../../../../../substrate/primitives/inherents", default-features = false} sp-io = { path = "../../../../../substrate/primitives/io", default-features = false} sp-offchain = { path = "../../../../../substrate/primitives/offchain", default-features = false} @@ -149,6 +150,7 @@ std = [ "sp-block-builder/std", "sp-consensus-aura/std", "sp-core/std", + "sp-genesis-builder/std", "sp-inherents/std", "sp-io/std", "sp-offchain/std", diff --git a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs index a00dd30a870a..13578487d01c 100644 --- a/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/bridge-hubs/bridge-hub-rococo/src/lib.rs @@ -47,6 +47,7 @@ use sp_version::RuntimeVersion; use frame_support::{ construct_runtime, dispatch::DispatchClass, + genesis_builder_helper::{build_config, create_default_config}, parameter_types, traits::{ConstBool, ConstU32, ConstU64, ConstU8, Everything}, weights::{ConstantMultiplier, Weight}, @@ -1230,6 +1231,16 @@ impl_runtime_apis! { Ok(batches) } } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } } cumulus_pallet_parachain_system::register_validate_block! { diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml b/cumulus/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml index 3d2f6e6ee2a1..c0745e705b9c 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml @@ -43,6 +43,7 @@ sp-arithmetic = { path = "../../../../../substrate/primitives/arithmetic", defau sp-block-builder = { path = "../../../../../substrate/primitives/block-builder", default-features = false} sp-consensus-aura = { path = "../../../../../substrate/primitives/consensus/aura", default-features = false} sp-core = { path = "../../../../../substrate/primitives/core", default-features = false} +sp-genesis-builder = { path = "../../../../../substrate/primitives/genesis-builder", default-features = false } sp-inherents = { path = "../../../../../substrate/primitives/inherents", default-features = false} sp-offchain = { path = "../../../../../substrate/primitives/offchain", default-features = false} sp-runtime = { path = "../../../../../substrate/primitives/runtime", default-features = false} @@ -184,6 +185,7 @@ std = [ "sp-block-builder/std", "sp-consensus-aura/std", "sp-core/std", + "sp-genesis-builder/std", "sp-inherents/std", "sp-offchain/std", "sp-runtime/std", diff --git a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs index a9af3b0f29fc..609028e2a5ba 100644 --- a/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs +++ b/cumulus/parachains/runtimes/collectives/collectives-polkadot/src/lib.rs @@ -68,6 +68,7 @@ use constants::{consensus::*, currency::*, fee::WeightToFee}; use frame_support::{ construct_runtime, dispatch::DispatchClass, + genesis_builder_helper::{build_config, create_default_config}, parameter_types, traits::{ConstBool, ConstU16, ConstU32, ConstU64, ConstU8, EitherOfDiverse, InstanceFilter}, weights::{ConstantMultiplier, Weight}, @@ -902,6 +903,16 @@ impl_runtime_apis! { Ok(batches) } } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } } cumulus_pallet_parachain_system::register_validate_block! { diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/Cargo.toml b/cumulus/parachains/runtimes/contracts/contracts-rococo/Cargo.toml index 67885ded6075..726c561eadb5 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/Cargo.toml @@ -22,6 +22,7 @@ sp-api = { path = "../../../../../substrate/primitives/api", default-features = sp-block-builder = { path = "../../../../../substrate/primitives/block-builder", default-features = false} sp-consensus-aura = { path = "../../../../../substrate/primitives/consensus/aura", default-features = false} sp-core = { path = "../../../../../substrate/primitives/core", default-features = false} +sp-genesis-builder = { path = "../../../../../substrate/primitives/genesis-builder", default-features = false } sp-inherents = { path = "../../../../../substrate/primitives/inherents", default-features = false} sp-offchain = { path = "../../../../../substrate/primitives/offchain", default-features = false} sp-runtime = { path = "../../../../../substrate/primitives/runtime", default-features = false} @@ -117,6 +118,7 @@ std = [ "sp-block-builder/std", "sp-consensus-aura/std", "sp-core/std", + "sp-genesis-builder/std", "sp-inherents/std", "sp-offchain/std", "sp-runtime/std", diff --git a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs index 9f381d4417a0..d2fa92a78819 100644 --- a/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/contracts/contracts-rococo/src/lib.rs @@ -49,6 +49,7 @@ use constants::{consensus::*, currency::*, fee::WeightToFee}; use frame_support::{ construct_runtime, dispatch::DispatchClass, + genesis_builder_helper::{build_config, create_default_config}, parameter_types, traits::{ConstBool, ConstU128, ConstU16, ConstU32, ConstU64, ConstU8, Everything}, weights::{ConstantMultiplier, Weight}, @@ -695,6 +696,16 @@ impl_runtime_apis! { Ok(batches) } } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } } cumulus_pallet_parachain_system::register_validate_block! { diff --git a/cumulus/parachains/runtimes/glutton/glutton-kusama/Cargo.toml b/cumulus/parachains/runtimes/glutton/glutton-kusama/Cargo.toml index 43bf468c7954..cf54ce4b567d 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-kusama/Cargo.toml +++ b/cumulus/parachains/runtimes/glutton/glutton-kusama/Cargo.toml @@ -21,6 +21,7 @@ pallet-sudo = { path = "../../../../../substrate/frame/sudo", default-features = sp-api = { path = "../../../../../substrate/primitives/api", default-features = false} sp-block-builder = { path = "../../../../../substrate/primitives/block-builder", default-features = false} sp-core = { path = "../../../../../substrate/primitives/core", default-features = false} +sp-genesis-builder = { path = "../../../../../substrate/primitives/genesis-builder", default-features = false } sp-inherents = { path = "../../../../../substrate/primitives/inherents", default-features = false} sp-offchain = { path = "../../../../../substrate/primitives/offchain", default-features = false} sp-runtime = { path = "../../../../../substrate/primitives/runtime", default-features = false} @@ -73,6 +74,7 @@ std = [ "sp-api/std", "sp-block-builder/std", "sp-core/std", + "sp-genesis-builder/std", "sp-inherents/std", "sp-offchain/std", "sp-runtime/std", diff --git a/cumulus/parachains/runtimes/glutton/glutton-kusama/src/lib.rs b/cumulus/parachains/runtimes/glutton/glutton-kusama/src/lib.rs index cd9d31a4d989..f660e8004067 100644 --- a/cumulus/parachains/runtimes/glutton/glutton-kusama/src/lib.rs +++ b/cumulus/parachains/runtimes/glutton/glutton-kusama/src/lib.rs @@ -63,6 +63,7 @@ use sp_version::RuntimeVersion; pub use frame_support::{ construct_runtime, dispatch::DispatchClass, + genesis_builder_helper::{build_config, create_default_config}, parameter_types, traits::{Everything, IsInVec, Randomness}, weights::{ @@ -398,6 +399,16 @@ impl_runtime_apis! { Ok(batches) } } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } } cumulus_pallet_parachain_system::register_validate_block! { diff --git a/cumulus/parachains/runtimes/starters/seedling/Cargo.toml b/cumulus/parachains/runtimes/starters/seedling/Cargo.toml index 1dfad06616ad..bd7a4e822ba3 100644 --- a/cumulus/parachains/runtimes/starters/seedling/Cargo.toml +++ b/cumulus/parachains/runtimes/starters/seedling/Cargo.toml @@ -17,6 +17,7 @@ pallet-sudo = { path = "../../../../../substrate/frame/sudo", default-features = sp-api = { path = "../../../../../substrate/primitives/api", default-features = false} sp-block-builder = { path = "../../../../../substrate/primitives/block-builder", default-features = false} sp-core = { path = "../../../../../substrate/primitives/core", default-features = false} +sp-genesis-builder = { path = "../../../../../substrate/primitives/genesis-builder", default-features = false } sp-inherents = { path = "../../../../../substrate/primitives/inherents", default-features = false} sp-offchain = { path = "../../../../../substrate/primitives/offchain", default-features = false} sp-runtime = { path = "../../../../../substrate/primitives/runtime", default-features = false} @@ -53,6 +54,7 @@ std = [ "sp-api/std", "sp-block-builder/std", "sp-core/std", + "sp-genesis-builder/std", "sp-inherents/std", "sp-offchain/std", "sp-runtime/std", diff --git a/cumulus/parachains/runtimes/starters/seedling/src/lib.rs b/cumulus/parachains/runtimes/starters/seedling/src/lib.rs index edca2b093948..156207816fb7 100644 --- a/cumulus/parachains/runtimes/starters/seedling/src/lib.rs +++ b/cumulus/parachains/runtimes/starters/seedling/src/lib.rs @@ -45,6 +45,7 @@ use sp_version::RuntimeVersion; pub use frame_support::{ construct_runtime, dispatch::DispatchClass, + genesis_builder_helper::{build_config, create_default_config}, parameter_types, traits::{IsInVec, Randomness}, weights::{ @@ -312,6 +313,16 @@ impl_runtime_apis! { ParachainSystem::collect_collation_info(header) } } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } } cumulus_pallet_parachain_system::register_validate_block! { diff --git a/cumulus/parachains/runtimes/starters/shell/Cargo.toml b/cumulus/parachains/runtimes/starters/shell/Cargo.toml index d15270482096..8843128ab09b 100644 --- a/cumulus/parachains/runtimes/starters/shell/Cargo.toml +++ b/cumulus/parachains/runtimes/starters/shell/Cargo.toml @@ -16,6 +16,7 @@ frame-try-runtime = { path = "../../../../../substrate/frame/try-runtime", defau sp-api = { path = "../../../../../substrate/primitives/api", default-features = false} sp-block-builder = { path = "../../../../../substrate/primitives/block-builder", default-features = false} sp-core = { path = "../../../../../substrate/primitives/core", default-features = false} +sp-genesis-builder = { path = "../../../../../substrate/primitives/genesis-builder", default-features = false } sp-inherents = { path = "../../../../../substrate/primitives/inherents", default-features = false} sp-offchain = { path = "../../../../../substrate/primitives/offchain", default-features = false} sp-runtime = { path = "../../../../../substrate/primitives/runtime", default-features = false} @@ -55,6 +56,7 @@ std = [ "sp-api/std", "sp-block-builder/std", "sp-core/std", + "sp-genesis-builder/std", "sp-inherents/std", "sp-offchain/std", "sp-runtime/std", diff --git a/cumulus/parachains/runtimes/starters/shell/src/lib.rs b/cumulus/parachains/runtimes/starters/shell/src/lib.rs index 205462fac39b..820e2c18ac43 100644 --- a/cumulus/parachains/runtimes/starters/shell/src/lib.rs +++ b/cumulus/parachains/runtimes/starters/shell/src/lib.rs @@ -52,6 +52,7 @@ use sp_version::RuntimeVersion; pub use frame_support::{ construct_runtime, dispatch::DispatchClass, + genesis_builder_helper::{build_config, create_default_config}, parameter_types, traits::{Everything, IsInVec, Randomness}, weights::{ @@ -342,6 +343,16 @@ impl_runtime_apis! { ParachainSystem::collect_collation_info(header) } } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } } cumulus_pallet_parachain_system::register_validate_block! { diff --git a/cumulus/parachains/runtimes/testing/penpal/Cargo.toml b/cumulus/parachains/runtimes/testing/penpal/Cargo.toml index dc945abe79f1..3643de502c91 100644 --- a/cumulus/parachains/runtimes/testing/penpal/Cargo.toml +++ b/cumulus/parachains/runtimes/testing/penpal/Cargo.toml @@ -43,6 +43,7 @@ sp-api = { path = "../../../../../substrate/primitives/api", default-features = sp-block-builder = { path = "../../../../../substrate/primitives/block-builder", default-features = false} sp-consensus-aura = { path = "../../../../../substrate/primitives/consensus/aura", default-features = false} sp-core = { path = "../../../../../substrate/primitives/core", default-features = false} +sp-genesis-builder = { path = "../../../../../substrate/primitives/genesis-builder", default-features = false } sp-inherents = { path = "../../../../../substrate/primitives/inherents", default-features = false} sp-offchain = { path = "../../../../../substrate/primitives/offchain", default-features = false} sp-runtime = { path = "../../../../../substrate/primitives/runtime", default-features = false} @@ -112,6 +113,7 @@ std = [ "sp-block-builder/std", "sp-consensus-aura/std", "sp-core/std", + "sp-genesis-builder/std", "sp-inherents/std", "sp-offchain/std", "sp-runtime/std", diff --git a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs index 4bc7dfacc053..c0c6f65570f1 100644 --- a/cumulus/parachains/runtimes/testing/penpal/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/penpal/src/lib.rs @@ -36,6 +36,7 @@ use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use frame_support::{ construct_runtime, dispatch::DispatchClass, + genesis_builder_helper::{build_config, create_default_config}, pallet_prelude::Weight, parameter_types, traits::{AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, ConstU8, Everything}, @@ -832,6 +833,16 @@ impl_runtime_apis! { Ok(batches) } } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } } cumulus_pallet_parachain_system::register_validate_block! { diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/Cargo.toml b/cumulus/parachains/runtimes/testing/rococo-parachain/Cargo.toml index 9a16d3d9e692..560af570737c 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/Cargo.toml +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/Cargo.toml @@ -26,6 +26,7 @@ sp-api = { path = "../../../../../substrate/primitives/api", default-features = sp-block-builder = { path = "../../../../../substrate/primitives/block-builder", default-features = false} sp-consensus-aura = { path = "../../../../../substrate/primitives/consensus/aura", default-features = false} sp-core = { path = "../../../../../substrate/primitives/core", default-features = false} +sp-genesis-builder = { path = "../../../../../substrate/primitives/genesis-builder", default-features = false } sp-inherents = { path = "../../../../../substrate/primitives/inherents", default-features = false} sp-offchain = { path = "../../../../../substrate/primitives/offchain", default-features = false} sp-runtime = { path = "../../../../../substrate/primitives/runtime", default-features = false} @@ -87,6 +88,7 @@ std = [ "sp-block-builder/std", "sp-consensus-aura/std", "sp-core/std", + "sp-genesis-builder/std", "sp-inherents/std", "sp-offchain/std", "sp-runtime/std", diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs index d01c66e772d7..9b92aaeef729 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -40,6 +40,7 @@ use sp_version::RuntimeVersion; pub use frame_support::{ construct_runtime, dispatch::DispatchClass, + genesis_builder_helper::{build_config, create_default_config}, match_types, parameter_types, traits::{ AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything, @@ -796,6 +797,15 @@ impl_runtime_apis! { ParachainSystem::collect_collation_info(header) } } + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } } cumulus_pallet_parachain_system::register_validate_block! { diff --git a/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs b/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs index 0523c3b7e65f..e3296c61d637 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs @@ -24,12 +24,9 @@ use sc_service::ChainType; use sp_core::{crypto::UncheckedInto, sr25519}; /// Specialized `ChainSpec` for the normal parachain runtime. -pub type AssetHubPolkadotChainSpec = - sc_service::GenericChainSpec; -pub type AssetHubKusamaChainSpec = - sc_service::GenericChainSpec; -pub type AssetHubWestendChainSpec = - sc_service::GenericChainSpec; +pub type AssetHubPolkadotChainSpec = sc_service::GenericChainSpec<(), Extensions>; +pub type AssetHubKusamaChainSpec = sc_service::GenericChainSpec<(), Extensions>; +pub type AssetHubWestendChainSpec = sc_service::GenericChainSpec<(), Extensions>; const ASSET_HUB_POLKADOT_ED: AssetHubBalance = asset_hub_polkadot_runtime::constants::currency::EXISTENTIAL_DEPOSIT; @@ -67,35 +64,32 @@ pub fn asset_hub_polkadot_development_config() -> AssetHubPolkadotChainSpec { properties.insert("tokenSymbol".into(), "DOT".into()); properties.insert("tokenDecimals".into(), 10.into()); - AssetHubPolkadotChainSpec::from_genesis( - // Name - "Polkadot Asset Hub Development", - // ID - "asset-hub-polkadot-dev", - ChainType::Local, - move || { - asset_hub_polkadot_genesis( - // initial collators. - vec![( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - )], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - ], - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: "polkadot-dev".into(), para_id: 1000 }, - ) + AssetHubPolkadotChainSpec::builder() + .with_name("Polkadot Asset Hub Development") + .with_id("asset-hub-polkadot-dev") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(asset_hub_polkadot_genesis( + // initial collators. + vec![( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + )], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + ], + 1000.into(), + )) + .with_boot_nodes(Vec::new()) + .with_properties(properties) + .with_extensions(Extensions { relay_chain: "polkadot-dev".into(), para_id: 1000 }) + .with_code( + asset_hub_polkadot_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + .build() } pub fn asset_hub_polkadot_local_config() -> AssetHubPolkadotChainSpec { @@ -104,49 +98,46 @@ pub fn asset_hub_polkadot_local_config() -> AssetHubPolkadotChainSpec { properties.insert("tokenSymbol".into(), "DOT".into()); properties.insert("tokenDecimals".into(), 10.into()); - AssetHubPolkadotChainSpec::from_genesis( - // Name - "Polkadot Asset Hub Local", - // ID - "asset-hub-polkadot-local", - ChainType::Local, - move || { - asset_hub_polkadot_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ + AssetHubPolkadotChainSpec::builder() + .with_name("Polkadot Asset Hub Local") + .with_id("asset-hub-polkadot-local") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(asset_hub_polkadot_genesis( + // initial collators. + vec![ + ( get_account_id_from_seed::("Alice"), + get_collator_keys_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"), - ], - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: "polkadot-local".into(), para_id: 1000 }, - ) + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + 1000.into(), + )) + .with_boot_nodes(Vec::new()) + .with_properties(properties) + .with_extensions(Extensions { relay_chain: "polkadot-local".into(), para_id: 1000 }) + .with_code( + asset_hub_polkadot_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + .build() } // Not used for syncing, but just to determine the genesis values set for the upgrade from shell. @@ -156,89 +147,79 @@ pub fn asset_hub_polkadot_config() -> AssetHubPolkadotChainSpec { properties.insert("tokenSymbol".into(), "DOT".into()); properties.insert("tokenDecimals".into(), 10.into()); - AssetHubPolkadotChainSpec::from_genesis( - // Name - "Polkadot Asset Hub", - // ID - "asset-hub-polkadot", - ChainType::Live, - move || { - asset_hub_polkadot_genesis( - // initial collators. - vec![ - ( - hex!("4c3d674d2a01060f0ded218e5dcc6f90c1726f43df79885eb3e22d97a20d5421") - .into(), - hex!("4c3d674d2a01060f0ded218e5dcc6f90c1726f43df79885eb3e22d97a20d5421") - .unchecked_into(), - ), - ( - hex!("c7d7d38d16bc23c6321152c50306212dc22c0efc04a2e52b5cccfc31ab3d7811") - .into(), - hex!("c7d7d38d16bc23c6321152c50306212dc22c0efc04a2e52b5cccfc31ab3d7811") - .unchecked_into(), - ), - ( - hex!("c5c07ba203d7375675f5c1ebe70f0a5bb729ae57b48bcc877fcc2ab21309b762") - .into(), - hex!("c5c07ba203d7375675f5c1ebe70f0a5bb729ae57b48bcc877fcc2ab21309b762") - .unchecked_into(), - ), - ( - hex!("0b2d0013fb974794bd7aa452465b567d48ef70373fe231a637c1fb7c547e85b3") - .into(), - hex!("0b2d0013fb974794bd7aa452465b567d48ef70373fe231a637c1fb7c547e85b3") - .unchecked_into(), - ), - ], - vec![], - 1000u32.into(), - ) - }, - vec![ - "/ip4/34.65.251.121/tcp/30334/p2p/12D3KooWG3GrM6XKMM4gp3cvemdwUvu96ziYoJmqmetLZBXE8bSa".parse().unwrap(), - "/ip4/34.65.35.228/tcp/30334/p2p/12D3KooWMRyTLrCEPcAQD6c4EnudL3vVzg9zji3whvsMYPUYevpq".parse().unwrap(), - "/ip4/34.83.247.146/tcp/30334/p2p/12D3KooWE4jFh5FpJDkWVZhnWtFnbSqRhdjvC7Dp9b8b3FTuubQC".parse().unwrap(), - "/ip4/104.199.117.230/tcp/30334/p2p/12D3KooWG9R8pVXKumVo2rdkeVD4j5PVhRTqmYgLHY3a4yPYgLqM".parse().unwrap(), - ], - None, - None, - None, - Some(properties), - Extensions { relay_chain: "polkadot".into(), para_id: 1000 }, - ) + AssetHubPolkadotChainSpec::builder() + .with_name("Polkadot Asset Hub") + .with_id("asset-hub-polkadot") + .with_chain_type(ChainType::Live) + .with_genesis_config_patch( + asset_hub_polkadot_genesis( + // initial collators. + vec![ + ( + hex!("4c3d674d2a01060f0ded218e5dcc6f90c1726f43df79885eb3e22d97a20d5421") + .into(), + hex!("4c3d674d2a01060f0ded218e5dcc6f90c1726f43df79885eb3e22d97a20d5421") + .unchecked_into(), + ), + ( + hex!("c7d7d38d16bc23c6321152c50306212dc22c0efc04a2e52b5cccfc31ab3d7811") + .into(), + hex!("c7d7d38d16bc23c6321152c50306212dc22c0efc04a2e52b5cccfc31ab3d7811") + .unchecked_into(), + ), + ( + hex!("c5c07ba203d7375675f5c1ebe70f0a5bb729ae57b48bcc877fcc2ab21309b762") + .into(), + hex!("c5c07ba203d7375675f5c1ebe70f0a5bb729ae57b48bcc877fcc2ab21309b762") + .unchecked_into(), + ), + ( + hex!("0b2d0013fb974794bd7aa452465b567d48ef70373fe231a637c1fb7c547e85b3") + .into(), + hex!("0b2d0013fb974794bd7aa452465b567d48ef70373fe231a637c1fb7c547e85b3") + .unchecked_into(), + ), + ], + vec![], + 1000u32.into(), + ) + ) + .with_boot_nodes( + vec![ + "/ip4/34.65.251.121/tcp/30334/p2p/12D3KooWG3GrM6XKMM4gp3cvemdwUvu96ziYoJmqmetLZBXE8bSa".parse().unwrap(), + "/ip4/34.65.35.228/tcp/30334/p2p/12D3KooWMRyTLrCEPcAQD6c4EnudL3vVzg9zji3whvsMYPUYevpq".parse().unwrap(), + "/ip4/34.83.247.146/tcp/30334/p2p/12D3KooWE4jFh5FpJDkWVZhnWtFnbSqRhdjvC7Dp9b8b3FTuubQC".parse().unwrap(), + "/ip4/104.199.117.230/tcp/30334/p2p/12D3KooWG9R8pVXKumVo2rdkeVD4j5PVhRTqmYgLHY3a4yPYgLqM".parse().unwrap(), + ] + ) + .with_properties(properties) + .with_extensions(Extensions { relay_chain: "polkadot".into(), para_id: 1000 }) + .with_code(asset_hub_polkadot_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!")) + .build() } fn asset_hub_polkadot_genesis( invulnerables: Vec<(AccountId, AssetHubPolkadotAuraId)>, endowed_accounts: Vec, id: ParaId, -) -> asset_hub_polkadot_runtime::RuntimeGenesisConfig { - asset_hub_polkadot_runtime::RuntimeGenesisConfig { - system: asset_hub_polkadot_runtime::SystemConfig { - code: asset_hub_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: asset_hub_polkadot_runtime::BalancesConfig { - balances: endowed_accounts +) -> serde_json::Value { + serde_json::json!( { + "balances": { + "balances": endowed_accounts .iter() .cloned() .map(|k| (k, ASSET_HUB_POLKADOT_ED * 4096)) - .collect(), + .collect::>(), }, - parachain_info: asset_hub_polkadot_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() + "parachainInfo": { + "parachainId": id, }, - collator_selection: asset_hub_polkadot_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: ASSET_HUB_POLKADOT_ED * 16, - ..Default::default() + "collatorSelection": { + "invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::>(), + "candidacyBond": ASSET_HUB_POLKADOT_ED * 16, }, - session: asset_hub_polkadot_runtime::SessionConfig { - keys: invulnerables + "session": { + "keys": invulnerables .into_iter() .map(|(acc, aura)| { ( @@ -247,18 +228,12 @@ fn asset_hub_polkadot_genesis( asset_hub_polkadot_session_keys(aura), // session keys ) }) - .collect(), + .collect::>(), }, - // no need to pass anything to aura, in fact it will panic if we do. Session will take care - // of this. - aura: Default::default(), - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: asset_hub_polkadot_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, - } + "polkadotXcm": { + "safeXcmVersion": Some(SAFE_XCM_VERSION), + } + }) } pub fn asset_hub_kusama_development_config() -> AssetHubKusamaChainSpec { @@ -267,35 +242,31 @@ pub fn asset_hub_kusama_development_config() -> AssetHubKusamaChainSpec { properties.insert("tokenSymbol".into(), "KSM".into()); properties.insert("tokenDecimals".into(), 12.into()); - AssetHubKusamaChainSpec::from_genesis( - // Name - "Kusama Asset Hub Development", - // ID - "asset-hub-kusama-dev", - ChainType::Local, - move || { - asset_hub_kusama_genesis( - // initial collators. - vec![( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - )], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - ], - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: "kusama-dev".into(), para_id: 1000 }, - ) + AssetHubKusamaChainSpec::builder() + .with_name("Kusama Asset Hub Development") + .with_id("asset-hub-kusama-dev") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(asset_hub_kusama_genesis( + // initial collators. + vec![( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + )], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + ], + 1000.into(), + )) + .with_properties(properties) + .with_extensions(Extensions { relay_chain: "kusama-dev".into(), para_id: 1000 }) + .with_code( + asset_hub_kusama_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + .build() } pub fn asset_hub_kusama_local_config() -> AssetHubKusamaChainSpec { @@ -304,49 +275,45 @@ pub fn asset_hub_kusama_local_config() -> AssetHubKusamaChainSpec { properties.insert("tokenSymbol".into(), "KSM".into()); properties.insert("tokenDecimals".into(), 12.into()); - AssetHubKusamaChainSpec::from_genesis( - // Name - "Kusama Asset Hub Local", - // ID - "asset-hub-kusama-local", - ChainType::Local, - move || { - asset_hub_kusama_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ + AssetHubKusamaChainSpec::builder() + .with_name("Kusama Asset Hub Local") + .with_id("asset-hub-kusama-local") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(asset_hub_kusama_genesis( + // initial collators. + vec![ + ( get_account_id_from_seed::("Alice"), + get_collator_keys_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"), - ], - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: "kusama-local".into(), para_id: 1000 }, - ) + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + 1000.into(), + )) + .with_properties(properties) + .with_extensions(Extensions { relay_chain: "kusama-local".into(), para_id: 1000 }) + .with_code( + asset_hub_kusama_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + .build() } pub fn asset_hub_kusama_config() -> AssetHubKusamaChainSpec { @@ -355,84 +322,68 @@ pub fn asset_hub_kusama_config() -> AssetHubKusamaChainSpec { properties.insert("tokenSymbol".into(), "KSM".into()); properties.insert("tokenDecimals".into(), 12.into()); - AssetHubKusamaChainSpec::from_genesis( - // Name - "Kusama Asset Hub", - // ID - "asset-hub-kusama", - ChainType::Live, - move || { - asset_hub_kusama_genesis( - // initial collators. - vec![ - ( - hex!("50673d59020488a4ffc9d8c6de3062a65977046e6990915617f85fef6d349730") - .into(), - hex!("50673d59020488a4ffc9d8c6de3062a65977046e6990915617f85fef6d349730") - .unchecked_into(), - ), - ( - hex!("fe8102dbc244e7ea2babd9f53236d67403b046154370da5c3ea99def0bd0747a") - .into(), - hex!("fe8102dbc244e7ea2babd9f53236d67403b046154370da5c3ea99def0bd0747a") - .unchecked_into(), - ), - ( - hex!("38144b5398e5d0da5ec936a3af23f5a96e782f676ab19d45f29075ee92eca76a") - .into(), - hex!("38144b5398e5d0da5ec936a3af23f5a96e782f676ab19d45f29075ee92eca76a") - .unchecked_into(), - ), - ( - hex!("3253947640e309120ae70fa458dcacb915e2ddd78f930f52bd3679ec63fc4415") - .into(), - hex!("3253947640e309120ae70fa458dcacb915e2ddd78f930f52bd3679ec63fc4415") - .unchecked_into(), - ), - ], - Vec::new(), - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: "kusama".into(), para_id: 1000 }, - ) + AssetHubKusamaChainSpec::builder() + .with_name("Kusama Asset Hub") + .with_id("asset-hub-kusama") + .with_chain_type(ChainType::Live) + .with_genesis_config_patch(asset_hub_kusama_genesis( + // initial collators. + vec![ + ( + hex!("50673d59020488a4ffc9d8c6de3062a65977046e6990915617f85fef6d349730").into(), + hex!("50673d59020488a4ffc9d8c6de3062a65977046e6990915617f85fef6d349730") + .unchecked_into(), + ), + ( + hex!("fe8102dbc244e7ea2babd9f53236d67403b046154370da5c3ea99def0bd0747a").into(), + hex!("fe8102dbc244e7ea2babd9f53236d67403b046154370da5c3ea99def0bd0747a") + .unchecked_into(), + ), + ( + hex!("38144b5398e5d0da5ec936a3af23f5a96e782f676ab19d45f29075ee92eca76a").into(), + hex!("38144b5398e5d0da5ec936a3af23f5a96e782f676ab19d45f29075ee92eca76a") + .unchecked_into(), + ), + ( + hex!("3253947640e309120ae70fa458dcacb915e2ddd78f930f52bd3679ec63fc4415").into(), + hex!("3253947640e309120ae70fa458dcacb915e2ddd78f930f52bd3679ec63fc4415") + .unchecked_into(), + ), + ], + Vec::new(), + 1000.into(), + )) + .with_properties(properties) + .with_extensions(Extensions { relay_chain: "kusama".into(), para_id: 1000 }) + .with_code( + asset_hub_kusama_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + .build() } fn asset_hub_kusama_genesis( invulnerables: Vec<(AccountId, AuraId)>, endowed_accounts: Vec, id: ParaId, -) -> asset_hub_kusama_runtime::RuntimeGenesisConfig { - asset_hub_kusama_runtime::RuntimeGenesisConfig { - system: asset_hub_kusama_runtime::SystemConfig { - code: asset_hub_kusama_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: asset_hub_kusama_runtime::BalancesConfig { - balances: endowed_accounts +) -> serde_json::Value { + serde_json::json!( { + "balances": { + "balances": endowed_accounts .iter() .cloned() .map(|k| (k, ASSET_HUB_KUSAMA_ED * 524_288)) - .collect(), + .collect::>(), }, - parachain_info: asset_hub_kusama_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() + "parachainInfo": { + "parachainId": id, }, - collator_selection: asset_hub_kusama_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: ASSET_HUB_KUSAMA_ED * 16, - ..Default::default() + "collatorSelection": { + "invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::>(), + "candidacyBond": ASSET_HUB_KUSAMA_ED * 16, }, - session: asset_hub_kusama_runtime::SessionConfig { - keys: invulnerables + "session": { + "keys": invulnerables .into_iter() .map(|(acc, aura)| { ( @@ -441,16 +392,12 @@ fn asset_hub_kusama_genesis( asset_hub_kusama_session_keys(aura), // session keys ) }) - .collect(), + .collect::>(), }, - aura: Default::default(), - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: asset_hub_kusama_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() + "polkadotXcm": { + "safeXcmVersion": Some(SAFE_XCM_VERSION), }, - } + }) } pub fn asset_hub_westend_development_config() -> AssetHubWestendChainSpec { @@ -458,35 +405,31 @@ pub fn asset_hub_westend_development_config() -> AssetHubWestendChainSpec { properties.insert("tokenSymbol".into(), "WND".into()); properties.insert("tokenDecimals".into(), 12.into()); - AssetHubWestendChainSpec::from_genesis( - // Name - "Westend Asset Hub Development", - // ID - "asset-hub-westend-dev", - ChainType::Local, - move || { - asset_hub_westend_genesis( - // initial collators. - vec![( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - )], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - ], - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: "westend".into(), para_id: 1000 }, - ) + AssetHubWestendChainSpec::builder() + .with_name("Westend Asset Hub Development") + .with_id("asset-hub-westend-dev") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(asset_hub_westend_genesis( + // initial collators. + vec![( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + )], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + ], + 1000.into(), + )) + .with_properties(properties) + .with_extensions(Extensions { relay_chain: "westend".into(), para_id: 1000 }) + .with_code( + asset_hub_westend_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + .build() } pub fn asset_hub_westend_local_config() -> AssetHubWestendChainSpec { @@ -494,49 +437,45 @@ pub fn asset_hub_westend_local_config() -> AssetHubWestendChainSpec { properties.insert("tokenSymbol".into(), "WND".into()); properties.insert("tokenDecimals".into(), 12.into()); - AssetHubWestendChainSpec::from_genesis( - // Name - "Westend Asset Hub Local", - // ID - "asset-hub-westend-local", - ChainType::Local, - move || { - asset_hub_westend_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ + AssetHubWestendChainSpec::builder() + .with_name("Westend Asset Hub Local") + .with_id("asset-hub-westend-local") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(asset_hub_westend_genesis( + // initial collators. + vec![ + ( get_account_id_from_seed::("Alice"), + get_collator_keys_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"), - ], - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: "westend-local".into(), para_id: 1000 }, - ) + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + 1000.into(), + )) + .with_properties(properties) + .with_extensions(Extensions { relay_chain: "westend-local".into(), para_id: 1000 }) + .with_code( + asset_hub_westend_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + .build() } pub fn asset_hub_westend_config() -> AssetHubWestendChainSpec { @@ -544,84 +483,68 @@ pub fn asset_hub_westend_config() -> AssetHubWestendChainSpec { properties.insert("tokenSymbol".into(), "WND".into()); properties.insert("tokenDecimals".into(), 12.into()); - AssetHubWestendChainSpec::from_genesis( - // Name - "Westend Asset Hub", - // ID - "asset-hub-westend", - ChainType::Live, - move || { - asset_hub_westend_genesis( - // initial collators. - vec![ - ( - hex!("9cfd429fa002114f33c1d3e211501d62830c9868228eb3b4b8ae15a83de04325") - .into(), - hex!("9cfd429fa002114f33c1d3e211501d62830c9868228eb3b4b8ae15a83de04325") - .unchecked_into(), - ), - ( - hex!("12a03fb4e7bda6c9a07ec0a11d03c24746943e054ff0bb04938970104c783876") - .into(), - hex!("12a03fb4e7bda6c9a07ec0a11d03c24746943e054ff0bb04938970104c783876") - .unchecked_into(), - ), - ( - hex!("1256436307dfde969324e95b8c62cb9101f520a39435e6af0f7ac07b34e1931f") - .into(), - hex!("1256436307dfde969324e95b8c62cb9101f520a39435e6af0f7ac07b34e1931f") - .unchecked_into(), - ), - ( - hex!("98102b7bca3f070f9aa19f58feed2c0a4e107d203396028ec17a47e1ed80e322") - .into(), - hex!("98102b7bca3f070f9aa19f58feed2c0a4e107d203396028ec17a47e1ed80e322") - .unchecked_into(), - ), - ], - Vec::new(), - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: "westend".into(), para_id: 1000 }, - ) + AssetHubWestendChainSpec::builder() + .with_name("Westend Asset Hub") + .with_id("asset-hub-westend") + .with_chain_type(ChainType::Live) + .with_genesis_config_patch(asset_hub_westend_genesis( + // initial collators. + vec![ + ( + hex!("9cfd429fa002114f33c1d3e211501d62830c9868228eb3b4b8ae15a83de04325").into(), + hex!("9cfd429fa002114f33c1d3e211501d62830c9868228eb3b4b8ae15a83de04325") + .unchecked_into(), + ), + ( + hex!("12a03fb4e7bda6c9a07ec0a11d03c24746943e054ff0bb04938970104c783876").into(), + hex!("12a03fb4e7bda6c9a07ec0a11d03c24746943e054ff0bb04938970104c783876") + .unchecked_into(), + ), + ( + hex!("1256436307dfde969324e95b8c62cb9101f520a39435e6af0f7ac07b34e1931f").into(), + hex!("1256436307dfde969324e95b8c62cb9101f520a39435e6af0f7ac07b34e1931f") + .unchecked_into(), + ), + ( + hex!("98102b7bca3f070f9aa19f58feed2c0a4e107d203396028ec17a47e1ed80e322").into(), + hex!("98102b7bca3f070f9aa19f58feed2c0a4e107d203396028ec17a47e1ed80e322") + .unchecked_into(), + ), + ], + Vec::new(), + 1000.into(), + )) + .with_properties(properties) + .with_extensions(Extensions { relay_chain: "westend".into(), para_id: 1000 }) + .with_code( + asset_hub_westend_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + .build() } fn asset_hub_westend_genesis( invulnerables: Vec<(AccountId, AuraId)>, endowed_accounts: Vec, id: ParaId, -) -> asset_hub_westend_runtime::RuntimeGenesisConfig { - asset_hub_westend_runtime::RuntimeGenesisConfig { - system: asset_hub_westend_runtime::SystemConfig { - code: asset_hub_westend_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: asset_hub_westend_runtime::BalancesConfig { - balances: endowed_accounts +) -> serde_json::Value { + serde_json::json!({ + "balances": { + "balances": endowed_accounts .iter() .cloned() .map(|k| (k, ASSET_HUB_WESTEND_ED * 4096)) - .collect(), + .collect::>(), }, - parachain_info: asset_hub_westend_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() + "parachainInfo": { + "parachainId": id, }, - collator_selection: asset_hub_westend_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: ASSET_HUB_WESTEND_ED * 16, - ..Default::default() + "collatorSelection": { + "invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::>(), + "candidacyBond": ASSET_HUB_WESTEND_ED * 16, }, - session: asset_hub_westend_runtime::SessionConfig { - keys: invulnerables + "session": { + "keys": invulnerables .into_iter() .map(|(acc, aura)| { ( @@ -630,16 +553,10 @@ fn asset_hub_westend_genesis( asset_hub_westend_session_keys(aura), // session keys ) }) - .collect(), + .collect::>(), }, - // no need to pass anything to aura, in fact it will panic if we do. Session will take care - // of this. - aura: Default::default(), - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: asset_hub_westend_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() + "polkadotXcm": { + "safeXcmVersion": Some(SAFE_XCM_VERSION), }, - } + }) } diff --git a/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs b/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs index 911368073d59..f564d128be03 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs @@ -195,8 +195,7 @@ pub mod rococo { bridge_hub_rococo_runtime::constants::currency::EXISTENTIAL_DEPOSIT; /// Specialized `ChainSpec` for the normal parachain runtime. - pub type BridgeHubChainSpec = - sc_service::GenericChainSpec; + pub type BridgeHubChainSpec = sc_service::GenericChainSpec<(), Extensions>; pub type RuntimeApi = bridge_hub_rococo_runtime::RuntimeApi; @@ -215,52 +214,51 @@ pub mod rococo { properties.insert("tokenDecimals".into(), 12.into()); modify_props(&mut properties); - BridgeHubChainSpec::from_genesis( - // Name - chain_name, - // ID - super::ensure_id(id).expect("invalid id"), - ChainType::Local, - move || { - genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ + BridgeHubChainSpec::builder() + .with_name(chain_name) + .with_id(super::ensure_id(id).expect("invalid id")) + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(genesis( + // initial collators. + vec![ + ( get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + ), + ( get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - para_id, - bridges_pallet_owner_seed - .as_ref() - .map(|seed| get_account_id_from_seed::(seed)), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, - ) + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + para_id, + bridges_pallet_owner_seed + .as_ref() + .map(|seed| get_account_id_from_seed::(seed)), + )) + .with_properties(properties) + .with_extensions(Extensions { + relay_chain: relay_chain.to_string(), + para_id: para_id.into(), + }) + .with_code( + bridge_hub_rococo_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + .build() } fn genesis( @@ -268,28 +266,20 @@ pub mod rococo { endowed_accounts: Vec, id: ParaId, bridges_pallet_owner: Option, - ) -> bridge_hub_rococo_runtime::RuntimeGenesisConfig { - bridge_hub_rococo_runtime::RuntimeGenesisConfig { - system: bridge_hub_rococo_runtime::SystemConfig { - code: bridge_hub_rococo_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: bridge_hub_rococo_runtime::BalancesConfig { - balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), + ) -> serde_json::Value { + serde_json::json!({ + "balances": { + "balances": endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::>(), }, - parachain_info: bridge_hub_rococo_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() + "parachainInfo": { + "parachainId": id, }, - collator_selection: bridge_hub_rococo_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: BRIDGE_HUB_ROCOCO_ED * 16, - ..Default::default() + "collatorSelection": { + "invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::>(), + "candidacyBond": BRIDGE_HUB_ROCOCO_ED * 16, }, - session: bridge_hub_rococo_runtime::SessionConfig { - keys: invulnerables + "session": { + "keys": invulnerables .into_iter() .map(|(acc, aura)| { ( @@ -298,32 +288,24 @@ pub mod rococo { bridge_hub_rococo_runtime::SessionKeys { aura }, // session keys ) }) - .collect(), + .collect::>(), }, - aura: Default::default(), - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: bridge_hub_rococo_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() + "polkadotXcm": { + "safeXcmVersion": Some(SAFE_XCM_VERSION), }, - bridge_wococo_grandpa: bridge_hub_rococo_runtime::BridgeWococoGrandpaConfig { - owner: bridges_pallet_owner.clone(), - ..Default::default() + "bridgeWococoGrandpa": { + "owner": bridges_pallet_owner.clone(), }, - bridge_rococo_grandpa: bridge_hub_rococo_runtime::BridgeRococoGrandpaConfig { - owner: bridges_pallet_owner.clone(), - ..Default::default() + "bridgeRococoGrandpa": { + "owner": bridges_pallet_owner.clone(), }, - bridge_rococo_messages: bridge_hub_rococo_runtime::BridgeRococoMessagesConfig { - owner: bridges_pallet_owner.clone(), - ..Default::default() + "bridgeRococoMessages": { + "owner": bridges_pallet_owner.clone(), }, - bridge_wococo_messages: bridge_hub_rococo_runtime::BridgeWococoMessagesConfig { - owner: bridges_pallet_owner, - ..Default::default() - }, - } + "bridgeWococoMessages": { + "owner": bridges_pallet_owner, + } + }) } } @@ -375,8 +357,7 @@ pub mod kusama { bridge_hub_kusama_runtime::constants::currency::EXISTENTIAL_DEPOSIT; /// Specialized `ChainSpec` for the normal parachain runtime. - pub type BridgeHubChainSpec = - sc_service::GenericChainSpec; + pub type BridgeHubChainSpec = sc_service::GenericChainSpec<(), Extensions>; pub type RuntimeApi = bridge_hub_kusama_runtime::RuntimeApi; pub fn local_config( @@ -390,81 +371,72 @@ pub mod kusama { properties.insert("tokenSymbol".into(), "KSM".into()); properties.insert("tokenDecimals".into(), 12.into()); - BridgeHubChainSpec::from_genesis( - // Name - chain_name, - // ID - super::ensure_id(id).expect("invalid id"), - ChainType::Local, - move || { - genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ + BridgeHubChainSpec::builder() + .with_name(chain_name) + .with_id(super::ensure_id(id).expect("invalid id")) + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(genesis( + // initial collators. + vec![ + ( get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + ), + ( get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - para_id, - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, - ) + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + para_id, + )) + .with_properties(properties) + .with_extensions(Extensions { + relay_chain: relay_chain.to_string(), + para_id: para_id.into(), + }) + .with_code( + bridge_hub_kusama_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + .build() } fn genesis( invulnerables: Vec<(AccountId, AuraId)>, endowed_accounts: Vec, id: ParaId, - ) -> bridge_hub_kusama_runtime::RuntimeGenesisConfig { - bridge_hub_kusama_runtime::RuntimeGenesisConfig { - system: bridge_hub_kusama_runtime::SystemConfig { - code: bridge_hub_kusama_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: bridge_hub_kusama_runtime::BalancesConfig { - balances: endowed_accounts + ) -> serde_json::Value { + serde_json::json!({ + "balances": { + "balances": endowed_accounts .iter() .cloned() .map(|k| (k, BRIDGE_HUB_KUSAMA_ED * 524_288)) - .collect(), + .collect::>(), }, - parachain_info: bridge_hub_kusama_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() + "parachainInfo": { + "parachainId": id, }, - collator_selection: bridge_hub_kusama_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: BRIDGE_HUB_KUSAMA_ED * 16, - ..Default::default() + "collatorSelection": { + "invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::>(), + "candidacyBond": BRIDGE_HUB_KUSAMA_ED * 16, }, - session: bridge_hub_kusama_runtime::SessionConfig { - keys: invulnerables + "session": { + "keys": invulnerables .into_iter() .map(|(acc, aura)| { ( @@ -473,16 +445,12 @@ pub mod kusama { bridge_hub_kusama_runtime::SessionKeys { aura }, // session keys ) }) - .collect(), - }, - aura: Default::default(), - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: bridge_hub_kusama_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() + .collect::>(), }, - } + "polkadotXcm": { + "safeXcmVersion": Some(SAFE_XCM_VERSION), + } + }) } } @@ -512,8 +480,7 @@ pub mod polkadot { bridge_hub_polkadot_runtime::constants::currency::EXISTENTIAL_DEPOSIT; /// Specialized `ChainSpec` for the normal parachain runtime. - pub type BridgeHubChainSpec = - sc_service::GenericChainSpec; + pub type BridgeHubChainSpec = sc_service::GenericChainSpec<(), Extensions>; pub type RuntimeApi = bridge_hub_polkadot_runtime::RuntimeApi; pub fn local_config( @@ -527,81 +494,72 @@ pub mod polkadot { properties.insert("tokenSymbol".into(), "DOT".into()); properties.insert("tokenDecimals".into(), 10.into()); - BridgeHubChainSpec::from_genesis( - // Name - chain_name, - // ID - super::ensure_id(id).expect("invalid id"), - ChainType::Local, - move || { - genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ + BridgeHubChainSpec::builder() + .with_name(chain_name) + .with_id(super::ensure_id(id).expect("invalid id")) + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(genesis( + // initial collators. + vec![ + ( get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + ), + ( get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - para_id, - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, - ) + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + para_id, + )) + .with_properties(properties) + .with_extensions(Extensions { + relay_chain: relay_chain.to_string(), + para_id: para_id.into(), + }) + .with_code( + bridge_hub_polkadot_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + .build() } fn genesis( invulnerables: Vec<(AccountId, AuraId)>, endowed_accounts: Vec, id: ParaId, - ) -> bridge_hub_polkadot_runtime::RuntimeGenesisConfig { - bridge_hub_polkadot_runtime::RuntimeGenesisConfig { - system: bridge_hub_polkadot_runtime::SystemConfig { - code: bridge_hub_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: bridge_hub_polkadot_runtime::BalancesConfig { - balances: endowed_accounts + ) -> serde_json::Value { + serde_json::json!({ + "balances": { + "balances": endowed_accounts .iter() .cloned() .map(|k| (k, BRIDGE_HUB_POLKADOT_ED * 4096)) - .collect(), + .collect::>(), }, - parachain_info: bridge_hub_polkadot_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() + "parachainInfo": { + "parachainId": id, }, - collator_selection: bridge_hub_polkadot_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: BRIDGE_HUB_POLKADOT_ED * 16, - ..Default::default() + "collatorSelection": { + "invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::>(), + "candidacyBond": BRIDGE_HUB_POLKADOT_ED * 16, }, - session: bridge_hub_polkadot_runtime::SessionConfig { - keys: invulnerables + "session": { + "keys": invulnerables .into_iter() .map(|(acc, aura)| { ( @@ -610,15 +568,11 @@ pub mod polkadot { bridge_hub_polkadot_runtime::SessionKeys { aura }, // session keys ) }) - .collect(), - }, - aura: Default::default(), - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: bridge_hub_polkadot_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() + .collect::>(), }, - } + "polkadotXcm": { + "safeXcmVersion": Some(SAFE_XCM_VERSION), + } + }) } } diff --git a/cumulus/polkadot-parachain/src/chain_spec/collectives.rs b/cumulus/polkadot-parachain/src/chain_spec/collectives.rs index 82c925c5d493..bbc9f570337a 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/collectives.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/collectives.rs @@ -22,8 +22,7 @@ use parachains_common::{AccountId, AuraId, Balance as CollectivesBalance}; use sc_service::ChainType; use sp_core::sr25519; -pub type CollectivesPolkadotChainSpec = - sc_service::GenericChainSpec; +pub type CollectivesPolkadotChainSpec = sc_service::GenericChainSpec<(), Extensions>; const COLLECTIVES_POLKADOT_ED: CollectivesBalance = collectives_polkadot_runtime::constants::currency::EXISTENTIAL_DEPOSIT; @@ -43,37 +42,34 @@ pub fn collectives_polkadot_development_config() -> CollectivesPolkadotChainSpec properties.insert("tokenSymbol".into(), "DOT".into()); properties.insert("tokenDecimals".into(), 10.into()); - CollectivesPolkadotChainSpec::from_genesis( - // Name - "Polkadot Collectives Development", - // ID - "collectives_polkadot_dev", - ChainType::Local, - move || { - collectives_polkadot_genesis( - // initial collators. - vec![( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - )], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - ], - // 1002 avoids a potential collision with Kusama-1001 (Encointer) should there ever - // be a collective para on Kusama. - 1002.into(), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: "polkadot-dev".into(), para_id: 1002 }, - ) + CollectivesPolkadotChainSpec::builder() + .with_name("Polkadot Collectives Development") + .with_id("collectives_polkadot_dev") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(collectives_polkadot_genesis( + // initial collators. + vec![( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + )], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + ], + // 1002 avoids a potential collision with Kusama-1001 (Encointer) should there ever + // be a collective para on Kusama. + 1002.into(), + )) + .with_boot_nodes(Vec::new()) + .with_properties(properties) + .with_extensions(Extensions { relay_chain: "polkadot-dev".into(), para_id: 1002 }) + .with_code( + collectives_polkadot_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + .build() } /// Collectives Polkadot Local Config. @@ -83,81 +79,70 @@ pub fn collectives_polkadot_local_config() -> CollectivesPolkadotChainSpec { properties.insert("tokenSymbol".into(), "DOT".into()); properties.insert("tokenDecimals".into(), 10.into()); - CollectivesPolkadotChainSpec::from_genesis( - // Name - "Polkadot Collectives Local", - // ID - "collectives_polkadot_local", - ChainType::Local, - move || { - collectives_polkadot_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ + CollectivesPolkadotChainSpec::builder() + .with_name("Polkadot Collectives Local") + .with_id("collectives_polkadot_local") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(collectives_polkadot_genesis( + // initial collators. + vec![ + ( get_account_id_from_seed::("Alice"), + get_collator_keys_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"), - ], - 1002.into(), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: "polkadot-local".into(), para_id: 1002 }, - ) + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + 1002.into(), + )) + .with_boot_nodes(Vec::new()) + .with_properties(properties) + .with_extensions(Extensions { relay_chain: "polkadot-local".into(), para_id: 1002 }) + .with_code( + collectives_polkadot_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + .build() } fn collectives_polkadot_genesis( invulnerables: Vec<(AccountId, AuraId)>, endowed_accounts: Vec, id: ParaId, -) -> collectives_polkadot_runtime::RuntimeGenesisConfig { - collectives_polkadot_runtime::RuntimeGenesisConfig { - system: collectives_polkadot_runtime::SystemConfig { - code: collectives_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: collectives_polkadot_runtime::BalancesConfig { - balances: endowed_accounts +) -> serde_json::Value { + serde_json::json!( { + "balances": { + "balances": endowed_accounts .iter() .cloned() .map(|k| (k, COLLECTIVES_POLKADOT_ED * 4096)) - .collect(), + .collect::>(), }, - parachain_info: collectives_polkadot_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() + "parachainInfo": { + "parachainId": id, }, - collator_selection: collectives_polkadot_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: COLLECTIVES_POLKADOT_ED * 16, - ..Default::default() + "collatorSelection": { + "invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::>(), + "candidacyBond": COLLECTIVES_POLKADOT_ED * 16, }, - session: collectives_polkadot_runtime::SessionConfig { - keys: invulnerables + "session": { + "keys": invulnerables .into_iter() .map(|(acc, aura)| { ( @@ -166,18 +151,12 @@ fn collectives_polkadot_genesis( collectives_polkadot_session_keys(aura), // session keys ) }) - .collect(), + .collect::>(), }, // no need to pass anything to aura, in fact it will panic if we do. Session will take care // of this. - aura: Default::default(), - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: collectives_polkadot_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() + "polkadotXcm": { + "safeXcmVersion": Some(SAFE_XCM_VERSION), }, - alliance: Default::default(), - alliance_motion: Default::default(), - } + }) } diff --git a/cumulus/polkadot-parachain/src/chain_spec/contracts.rs b/cumulus/polkadot-parachain/src/chain_spec/contracts.rs index b8af83a0d70e..89590f490e66 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/contracts.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/contracts.rs @@ -23,8 +23,7 @@ use parachains_common::{AccountId, AuraId}; use sc_service::ChainType; use sp_core::{crypto::UncheckedInto, sr25519}; -pub type ContractsRococoChainSpec = - sc_service::GenericChainSpec; +pub type ContractsRococoChainSpec = sc_service::GenericChainSpec<(), Extensions>; /// No relay chain suffix because the id is the same over all relay chains. const CONTRACTS_PARACHAIN_ID: u32 = 1002; @@ -38,52 +37,48 @@ pub fn contracts_rococo_development_config() -> ContractsRococoChainSpec { properties.insert("tokenSymbol".into(), "ROC".into()); properties.insert("tokenDecimals".into(), 12.into()); - ContractsRococoChainSpec::from_genesis( - // Name - "Contracts on Rococo Development", - // ID - "contracts-rococo-dev", - ChainType::Development, - move || { - contracts_rococo_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ + ContractsRococoChainSpec::builder() + .with_name("Contracts on Rococo Development") + .with_id("contracts-rococo-dev") + .with_chain_type(ChainType::Development) + .with_genesis_config_patch(contracts_rococo_genesis( + // initial collators. + vec![ + ( get_account_id_from_seed::("Alice"), + get_collator_keys_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"), - ], - CONTRACTS_PARACHAIN_ID.into(), - ) - }, - Vec::new(), - None, - None, - None, - None, - Extensions { + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + CONTRACTS_PARACHAIN_ID.into(), + )) + .with_boot_nodes(Vec::new()) + .with_extensions(Extensions { relay_chain: "rococo-local".into(), // You MUST set this to the correct network! para_id: CONTRACTS_PARACHAIN_ID, - }, - ) + }) + .with_code( + contracts_rococo_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + .build() } pub fn contracts_rococo_local_config() -> ContractsRococoChainSpec { @@ -91,58 +86,48 @@ pub fn contracts_rococo_local_config() -> ContractsRococoChainSpec { properties.insert("tokenSymbol".into(), "ROC".into()); properties.insert("tokenDecimals".into(), 12.into()); - ContractsRococoChainSpec::from_genesis( - // Name - "Contracts on Rococo", - // ID - "contracts-rococo-local", - ChainType::Local, - move || { - contracts_rococo_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ + ContractsRococoChainSpec::builder() + .with_name("Contracts on Rococo") + .with_id("contracts-rococo-local") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(contracts_rococo_genesis( + // initial collators. + vec![ + ( get_account_id_from_seed::("Alice"), + get_collator_keys_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"), - ], - CONTRACTS_PARACHAIN_ID.into(), - ) - }, - // Bootnodes - Vec::new(), - // Telemetry - None, - // Protocol ID - None, - // Fork ID - None, - // Properties - Some(properties), - // Extensions - Extensions { + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + CONTRACTS_PARACHAIN_ID.into(), + )) + .with_properties(properties) + .with_extensions(Extensions { relay_chain: "rococo-local".into(), // You MUST set this to the correct network! para_id: CONTRACTS_PARACHAIN_ID, - }, - ) + }) + .with_code( + contracts_rococo_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + .build() } pub fn contracts_rococo_config() -> ContractsRococoChainSpec { @@ -151,111 +136,91 @@ pub fn contracts_rococo_config() -> ContractsRococoChainSpec { properties.insert("tokenSymbol".into(), "ROC".into()); properties.insert("tokenDecimals".into(), 12.into()); - ContractsRococoChainSpec::from_genesis( - // Name - "Contracts on Rococo", - // ID - "contracts-rococo", - ChainType::Live, - move || { - contracts_rococo_genesis( - vec![ - // 5GKFbTTgrVS4Vz1UWWHPqMZQNFWZtqo7H2KpCDyYhEL3aS26 - ( - hex!["bc09354c12c054c8f6b3da208485eacec4ac648bad348895273b37bab5a0937c"] - .into(), - hex!["bc09354c12c054c8f6b3da208485eacec4ac648bad348895273b37bab5a0937c"] - .unchecked_into(), - ), - // 5EPRJHm2GpABVWcwnAujcrhnrjFZyDGd5TwKFzkBoGgdRyv2 - ( - hex!["66be63b7bcbfb91040e5248e2d1ceb822cf219c57848c5924ffa3a1f8e67ba72"] - .into(), - hex!["66be63b7bcbfb91040e5248e2d1ceb822cf219c57848c5924ffa3a1f8e67ba72"] - .unchecked_into(), - ), - // 5GH62vrJrVZxLREcHzm2PR5uTLAT5RQMJitoztCGyaP4o3uM - ( - hex!["ba62886472a0a9f66b5e39f1469ce1c5b3d8cad6be39078daf16f111e89d1e44"] - .into(), - hex!["ba62886472a0a9f66b5e39f1469ce1c5b3d8cad6be39078daf16f111e89d1e44"] - .unchecked_into(), - ), - // 5FHfoJDLdjRYX5KXLRqMDYBbWrwHLMtti21uK4QByUoUAbJF - ( - hex!["8e97f65cda001976311df9bed39e8d0c956089093e94a75ef76fe9347a0eda7b"] - .into(), - hex!["8e97f65cda001976311df9bed39e8d0c956089093e94a75ef76fe9347a0eda7b"] - .unchecked_into(), - ), - ], - // Warning: The configuration for a production chain should not contain - // any endowed accounts here, otherwise it'll be minting extra native tokens - // from the relay chain on the parachain. - vec![ - // NOTE: Remove endowed accounts if deployed on other relay chains. - // Endowed accounts - hex!["baa78c7154c7f82d6d377177e20bcab65d327eca0086513f9964f5a0f6bdad56"].into(), - // AccountId of an account which `ink-waterfall` uses for automated testing - hex!["0e47e2344d523c3cc5c34394b0d58b9a4200e813a038e6c5a6163cc07d70b069"].into(), - ], - CONTRACTS_PARACHAIN_ID.into(), - ) - }, - // Bootnodes - vec![ + ContractsRococoChainSpec::builder() + .with_name("Contracts on Rococo") + .with_id("contracts-rococo") + .with_chain_type(ChainType::Live) + .with_genesis_config_patch(contracts_rococo_genesis( + vec![ + // 5GKFbTTgrVS4Vz1UWWHPqMZQNFWZtqo7H2KpCDyYhEL3aS26 + ( + hex!["bc09354c12c054c8f6b3da208485eacec4ac648bad348895273b37bab5a0937c"] + .into(), + hex!["bc09354c12c054c8f6b3da208485eacec4ac648bad348895273b37bab5a0937c"] + .unchecked_into(), + ), + // 5EPRJHm2GpABVWcwnAujcrhnrjFZyDGd5TwKFzkBoGgdRyv2 + ( + hex!["66be63b7bcbfb91040e5248e2d1ceb822cf219c57848c5924ffa3a1f8e67ba72"] + .into(), + hex!["66be63b7bcbfb91040e5248e2d1ceb822cf219c57848c5924ffa3a1f8e67ba72"] + .unchecked_into(), + ), + // 5GH62vrJrVZxLREcHzm2PR5uTLAT5RQMJitoztCGyaP4o3uM + ( + hex!["ba62886472a0a9f66b5e39f1469ce1c5b3d8cad6be39078daf16f111e89d1e44"] + .into(), + hex!["ba62886472a0a9f66b5e39f1469ce1c5b3d8cad6be39078daf16f111e89d1e44"] + .unchecked_into(), + ), + // 5FHfoJDLdjRYX5KXLRqMDYBbWrwHLMtti21uK4QByUoUAbJF + ( + hex!["8e97f65cda001976311df9bed39e8d0c956089093e94a75ef76fe9347a0eda7b"] + .into(), + hex!["8e97f65cda001976311df9bed39e8d0c956089093e94a75ef76fe9347a0eda7b"] + .unchecked_into(), + ), + ], + // Warning: The configuration for a production chain should not contain + // any endowed accounts here, otherwise it'll be minting extra native tokens + // from the relay chain on the parachain. + vec![ + // NOTE: Remove endowed accounts if deployed on other relay chains. + // Endowed accounts + hex!["baa78c7154c7f82d6d377177e20bcab65d327eca0086513f9964f5a0f6bdad56"].into(), + // AccountId of an account which `ink-waterfall` uses for automated testing + hex!["0e47e2344d523c3cc5c34394b0d58b9a4200e813a038e6c5a6163cc07d70b069"].into(), + ], + CONTRACTS_PARACHAIN_ID.into(), + )) + .with_boot_nodes(vec![ "/dns/contracts-collator-0.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWKg3Rpxcr9oJ8n6khoxpGKWztCZydtUZk2cojHqnfLrpj" - .parse() - .expect("MultiaddrWithPeerId"), + .parse() + .expect("MultiaddrWithPeerId"), "/dns/contracts-collator-1.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWPEXYrz8tHU3nDtPoPw4V7ou5dzMEWSTuUj7vaWiYVAVh" - .parse() - .expect("MultiaddrWithPeerId"), + .parse() + .expect("MultiaddrWithPeerId"), "/dns/contracts-collator-2.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWEVU8AFNary4nP4qEnEcwJaRuy59Wefekzdu9pKbnVEhk" - .parse() - .expect("MultiaddrWithPeerId"), + .parse() + .expect("MultiaddrWithPeerId"), "/dns/contracts-collator-3.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWP6pV3ZmcXzGDjv8ZMgA6nZxfAKDxSz4VNiLx6vVCQgJX" - .parse() - .expect("MultiaddrWithPeerId"), - ], - // Telemetry - None, - // Protocol ID - None, - // Fork ID - None, - // Properties - Some(properties), - // Extensions - Extensions { relay_chain: "rococo".into(), para_id: CONTRACTS_PARACHAIN_ID }, - ) + .parse() + .expect("MultiaddrWithPeerId"), + ]) + .with_properties(properties) + .with_extensions(Extensions { relay_chain: "rococo".into(), para_id: CONTRACTS_PARACHAIN_ID }) + .with_code(contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!")) + .build() } fn contracts_rococo_genesis( invulnerables: Vec<(AccountId, AuraId)>, endowed_accounts: Vec, id: ParaId, -) -> contracts_rococo_runtime::RuntimeGenesisConfig { - contracts_rococo_runtime::RuntimeGenesisConfig { - system: contracts_rococo_runtime::SystemConfig { - code: contracts_rococo_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: contracts_rococo_runtime::BalancesConfig { - balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), +) -> serde_json::Value { + serde_json::json!( { + "balances": { + "balances": endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::>(), }, - parachain_info: contracts_rococo_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() + "parachainInfo": { + "parachainId": id, }, - collator_selection: contracts_rococo_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: CONTRACTS_ROCOCO_ED * 16, - ..Default::default() + "collatorSelection": { + "invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::>(), + "candidacyBond": CONTRACTS_ROCOCO_ED * 16, }, - session: contracts_rococo_runtime::SessionConfig { - keys: invulnerables + "session": { + "keys": invulnerables .into_iter() .map(|(acc, aura)| { ( @@ -264,21 +229,17 @@ fn contracts_rococo_genesis( contracts_rococo_runtime::SessionKeys { aura }, // session keys ) }) - .collect(), + .collect::>(), }, // no need to pass anything to aura, in fact it will panic if we do. Session will take care // of this. - aura: Default::default(), - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: contracts_rococo_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() + "polkadotXcm": { + "safeXcmVersion": Some(SAFE_XCM_VERSION), }, - sudo: contracts_rococo_runtime::SudoConfig { - key: Some( - hex!["2681a28014e7d3a5bfb32a003b3571f53c408acbc28d351d6bf58f5028c4ef14"].into(), - ), + "sudo": { + "key": Some(sp_runtime::AccountId32::from(hex![ + "2681a28014e7d3a5bfb32a003b3571f53c408acbc28d351d6bf58f5028c4ef14" + ])), }, - } + }) } diff --git a/cumulus/polkadot-parachain/src/chain_spec/glutton.rs b/cumulus/polkadot-parachain/src/chain_spec/glutton.rs index 5ea51c3a9181..c7964b20102a 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/glutton.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/glutton.rs @@ -20,82 +20,61 @@ use sc_service::ChainType; use sp_core::sr25519; /// Specialized `ChainSpec` for the Glutton parachain runtime. -pub type GluttonChainSpec = - sc_service::GenericChainSpec; +pub type GluttonChainSpec = sc_service::GenericChainSpec<(), Extensions>; pub fn glutton_development_config(para_id: ParaId) -> GluttonChainSpec { - GluttonChainSpec::from_genesis( - // Name - "Glutton Development", - // ID - "glutton_dev", - ChainType::Local, - move || glutton_genesis(para_id), - Vec::new(), - None, - None, - None, - None, - Extensions { relay_chain: "kusama-dev".into(), para_id: para_id.into() }, - ) + #[allow(deprecated)] + GluttonChainSpec::builder() + .with_name("Glutton Development") + .with_id("glutton_dev") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(glutton_genesis(para_id)) + .with_extensions(Extensions { relay_chain: "kusama-dev".into(), para_id: para_id.into() }) + .with_code( + glutton_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) + .build() } pub fn glutton_local_config(para_id: ParaId) -> GluttonChainSpec { - GluttonChainSpec::from_genesis( - // Name - "Glutton Local", - // ID - "glutton_local", - ChainType::Local, - move || glutton_genesis(para_id), - Vec::new(), - None, - None, - None, - None, - Extensions { relay_chain: "kusama-local".into(), para_id: para_id.into() }, - ) + #[allow(deprecated)] + GluttonChainSpec::builder() + .with_name("Glutton Local") + .with_id("glutton_local") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(glutton_genesis(para_id)) + .with_extensions(Extensions { relay_chain: "kusama-local".into(), para_id: para_id.into() }) + .with_code( + glutton_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) + .build() } pub fn glutton_config(para_id: ParaId) -> GluttonChainSpec { let mut properties = sc_chain_spec::Properties::new(); properties.insert("ss58Format".into(), 2.into()); - GluttonChainSpec::from_genesis( - // Name - format!("Glutton {}", para_id).as_str(), - // ID - format!("glutton-kusama-{}", para_id).as_str(), - ChainType::Live, - move || glutton_genesis(para_id), - Vec::new(), - None, - // Protocol ID - Some(format!("glutton-kusama-{}", para_id).as_str()), - None, - Some(properties), - Extensions { relay_chain: "kusama".into(), para_id: para_id.into() }, - ) + GluttonChainSpec::builder() + .with_name(format!("Glutton {}", para_id).as_str()) + .with_id(format!("glutton-kusama-{}", para_id).as_str()) + .with_chain_type(ChainType::Live) + .with_genesis_config_patch(glutton_genesis(para_id)) + .with_protocol_id(format!("glutton-kusama-{}", para_id).as_str()) + .with_properties(properties) + .with_extensions(Extensions { relay_chain: "kusama".into(), para_id: para_id.into() }) + .with_code( + glutton_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) + .build() } -fn glutton_genesis(parachain_id: ParaId) -> glutton_runtime::RuntimeGenesisConfig { - glutton_runtime::RuntimeGenesisConfig { - system: glutton_runtime::SystemConfig { - code: glutton_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() +fn glutton_genesis(parachain_id: ParaId) -> serde_json::Value { + serde_json::json!( { + "parachainInfo": { + "parachainId": parachain_id }, - parachain_info: glutton_runtime::ParachainInfoConfig { parachain_id, ..Default::default() }, - parachain_system: Default::default(), - glutton: glutton_runtime::GluttonConfig { - compute: Default::default(), - storage: Default::default(), - trash_data_count: Default::default(), - ..Default::default() - }, - sudo: glutton_runtime::SudoConfig { - key: Some(get_account_id_from_seed::("Alice")), - }, - } + "sudo": { + "key": Some(get_account_id_from_seed::("Alice")), + } + }) } diff --git a/cumulus/polkadot-parachain/src/chain_spec/penpal.rs b/cumulus/polkadot-parachain/src/chain_spec/penpal.rs index 264898991eb8..19c86037cb06 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/penpal.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/penpal.rs @@ -22,8 +22,7 @@ use parachains_common::{AccountId, AuraId}; use sc_service::ChainType; use sp_core::sr25519; /// Specialized `ChainSpec` for the normal parachain runtime. -pub type PenpalChainSpec = - sc_service::GenericChainSpec; +pub type PenpalChainSpec = sc_service::GenericChainSpec<(), Extensions>; pub fn get_penpal_chain_spec(id: ParaId, relay_chain: &str) -> PenpalChainSpec { // Give your base currency a unit name and decimal places @@ -32,84 +31,70 @@ pub fn get_penpal_chain_spec(id: ParaId, relay_chain: &str) -> PenpalChainSpec { properties.insert("tokenDecimals".into(), 12u32.into()); properties.insert("ss58Format".into(), 42u32.into()); - PenpalChainSpec::from_genesis( - // Name - "Penpal Parachain", - // ID - &format!("penpal-{}", relay_chain.replace("-local", "")), - ChainType::Development, - move || { - penpal_testnet_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ + PenpalChainSpec::builder() + .with_name("Penpal Parachain") + .with_id(&format!("penpal-{}", relay_chain.replace("-local", ""))) + .with_chain_type(ChainType::Development) + .with_genesis_config_patch(penpal_testnet_genesis( + // initial collators. + vec![ + ( get_account_id_from_seed::("Alice"), + get_collator_keys_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"), - ], - id, - ) - }, - Vec::new(), - None, - None, - None, - None, - Extensions { + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + id, + )) + .with_extensions(Extensions { relay_chain: relay_chain.into(), // You MUST set this to the correct network! para_id: id.into(), - }, - ) + }) + .with_code( + penpal_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) + .build() } fn penpal_testnet_genesis( invulnerables: Vec<(AccountId, AuraId)>, endowed_accounts: Vec, id: ParaId, -) -> penpal_runtime::RuntimeGenesisConfig { - penpal_runtime::RuntimeGenesisConfig { - system: penpal_runtime::SystemConfig { - code: penpal_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: penpal_runtime::BalancesConfig { - balances: endowed_accounts +) -> serde_json::Value { + serde_json::json!({ + "balances": { + "balances": endowed_accounts .iter() .cloned() .map(|k| (k, penpal_runtime::EXISTENTIAL_DEPOSIT * 4096)) - .collect(), + .collect::>(), }, - parachain_info: penpal_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() + "parachainInfo": { + "parachainId": id, }, - collator_selection: penpal_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: penpal_runtime::EXISTENTIAL_DEPOSIT * 16, - ..Default::default() + "collatorSelection": { + "invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::>(), + "candidacyBond": penpal_runtime::EXISTENTIAL_DEPOSIT * 16, }, - session: penpal_runtime::SessionConfig { - keys: invulnerables + "session": { + "keys": invulnerables .into_iter() .map(|(acc, aura)| { ( @@ -118,21 +103,15 @@ fn penpal_testnet_genesis( penpal_session_keys(aura), // session keys ) }) - .collect(), + .collect::>(), }, - // no need to pass anything to aura, in fact it will panic if we do. Session will take care - // of this. - aura: Default::default(), - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: penpal_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() + "polkadotXcm": { + "safeXcmVersion": Some(SAFE_XCM_VERSION), }, - sudo: penpal_runtime::SudoConfig { - key: Some(get_account_id_from_seed::("Alice")), + "sudo": { + "key": Some(get_account_id_from_seed::("Alice")), }, - } + }) } /// Generate the session keys from individual elements. diff --git a/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs b/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs index 1ed1a3e35fba..5527521b5624 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs @@ -25,73 +25,66 @@ use rococo_parachain_runtime::AuraId; use sc_chain_spec::ChainType; use sp_core::{crypto::UncheckedInto, sr25519}; -pub type RococoParachainChainSpec = - sc_service::GenericChainSpec; +pub type RococoParachainChainSpec = sc_service::GenericChainSpec<(), Extensions>; pub fn rococo_parachain_local_config() -> RococoParachainChainSpec { - RococoParachainChainSpec::from_genesis( - "Rococo Parachain Local", - "local_testnet", - ChainType::Local, - move || { - testnet_genesis( + #[allow(deprecated)] + RococoParachainChainSpec::builder() + .with_name("Rococo Parachain Local") + .with_id("local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(testnet_genesis( + get_account_id_from_seed::("Alice"), + vec![get_from_seed::("Alice"), get_from_seed::("Bob")], + vec![ get_account_id_from_seed::("Alice"), - vec![get_from_seed::("Alice"), get_from_seed::("Bob")], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - None, - Extensions { relay_chain: "rococo-local".into(), para_id: 1000 }, - ) + 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"), + ], + 1000.into(), + )) + .with_extensions(Extensions { relay_chain: "rococo-local".into(), para_id: 1000 }) + .with_code( + rococo_parachain_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + .build() } pub fn staging_rococo_parachain_local_config() -> RococoParachainChainSpec { - RococoParachainChainSpec::from_genesis( - "Staging Rococo Parachain Local", - "staging_testnet", - ChainType::Live, - move || { - testnet_genesis( - hex!["9ed7705e3c7da027ba0583a22a3212042f7e715d3c168ba14f1424e2bc111d00"].into(), - vec![ - // $secret//one - hex!["aad9fa2249f87a210a0f93400b7f90e47b810c6d65caa0ca3f5af982904c2a33"] - .unchecked_into(), - // $secret//two - hex!["d47753f0cca9dd8da00c70e82ec4fc5501a69c49a5952a643d18802837c88212"] - .unchecked_into(), - ], - vec![ - hex!["9ed7705e3c7da027ba0583a22a3212042f7e715d3c168ba14f1424e2bc111d00"].into() - ], - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - None, - Extensions { relay_chain: "rococo-local".into(), para_id: 1000 }, - ) + #[allow(deprecated)] + RococoParachainChainSpec::builder() + .with_name("Staging Rococo Parachain Local") + .with_id("staging_testnet") + .with_chain_type(ChainType::Live) + .with_genesis_config_patch(testnet_genesis( + hex!["9ed7705e3c7da027ba0583a22a3212042f7e715d3c168ba14f1424e2bc111d00"].into(), + vec![ + // $secret//one + hex!["aad9fa2249f87a210a0f93400b7f90e47b810c6d65caa0ca3f5af982904c2a33"] + .unchecked_into(), + // $secret//two + hex!["d47753f0cca9dd8da00c70e82ec4fc5501a69c49a5952a643d18802837c88212"] + .unchecked_into(), + ], + vec![hex!["9ed7705e3c7da027ba0583a22a3212042f7e715d3c168ba14f1424e2bc111d00"].into()], + 1000.into(), + )) + .with_extensions(Extensions { relay_chain: "rococo-local".into(), para_id: 1000 }) + .with_code( + rococo_parachain_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + .build() } pub(crate) fn testnet_genesis( @@ -99,28 +92,18 @@ pub(crate) fn testnet_genesis( initial_authorities: Vec, endowed_accounts: Vec, id: ParaId, -) -> rococo_parachain_runtime::RuntimeGenesisConfig { - rococo_parachain_runtime::RuntimeGenesisConfig { - system: rococo_parachain_runtime::SystemConfig { - code: rococo_parachain_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: rococo_parachain_runtime::BalancesConfig { - balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), +) -> serde_json::Value { + serde_json::json!({ + "balances": { + "balances": endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::>(), }, - sudo: rococo_parachain_runtime::SudoConfig { key: Some(root_key) }, - parachain_info: rococo_parachain_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() + "sudo": { "key": Some(root_key) }, + "parachainInfo": { + "parachainId": id, }, - aura: rococo_parachain_runtime::AuraConfig { authorities: initial_authorities }, - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: rococo_parachain_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() + "aura": { "authorities": initial_authorities }, + "polkadotXcm": { + "safeXcmVersion": Some(SAFE_XCM_VERSION), }, - } + }) } diff --git a/cumulus/polkadot-parachain/src/chain_spec/seedling.rs b/cumulus/polkadot-parachain/src/chain_spec/seedling.rs index 4a43b4cf4764..49501e5fd713 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/seedling.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/seedling.rs @@ -21,45 +21,30 @@ use sc_service::ChainType; use sp_core::sr25519; /// Specialized `ChainSpec` for the seedling parachain runtime. -pub type SeedlingChainSpec = - sc_service::GenericChainSpec; +pub type SeedlingChainSpec = sc_service::GenericChainSpec<(), Extensions>; pub fn get_seedling_chain_spec() -> SeedlingChainSpec { - SeedlingChainSpec::from_genesis( - "Seedling Local Testnet", - "seedling_local_testnet", - ChainType::Local, - move || { - seedling_testnet_genesis( - get_account_id_from_seed::("Alice"), - 2000.into(), - ) - }, - Vec::new(), - None, - None, - None, - None, - Extensions { relay_chain: "westend".into(), para_id: 2000 }, - ) + SeedlingChainSpec::builder() + .with_name("Seedling Local Testnet") + .with_id("seedling_local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(seedling_testnet_genesis( + get_account_id_from_seed::("Alice"), + 2000.into(), + )) + .with_boot_nodes(Vec::new()) + .with_extensions(Extensions { relay_chain: "westend".into(), para_id: 2000 }) + .with_code( + seedling_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) + .build() } -fn seedling_testnet_genesis( - root_key: AccountId, - parachain_id: ParaId, -) -> seedling_runtime::RuntimeGenesisConfig { - seedling_runtime::RuntimeGenesisConfig { - system: seedling_runtime::SystemConfig { - code: seedling_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - sudo: seedling_runtime::SudoConfig { key: Some(root_key) }, - parachain_info: seedling_runtime::ParachainInfoConfig { - parachain_id, - ..Default::default() +fn seedling_testnet_genesis(root_key: AccountId, parachain_id: ParaId) -> serde_json::Value { + serde_json::json!({ + "sudo": { "key": Some(root_key) }, + "parachainInfo": { + "parachainId": parachain_id, }, - parachain_system: Default::default(), - } + }) } diff --git a/cumulus/polkadot-parachain/src/chain_spec/shell.rs b/cumulus/polkadot-parachain/src/chain_spec/shell.rs index eca605b10df0..1575c0774acd 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/shell.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/shell.rs @@ -19,33 +19,18 @@ use cumulus_primitives_core::ParaId; use sc_service::ChainType; /// Specialized `ChainSpec` for the shell parachain runtime. -pub type ShellChainSpec = - sc_service::GenericChainSpec; +pub type ShellChainSpec = sc_service::GenericChainSpec<(), Extensions>; pub fn get_shell_chain_spec() -> ShellChainSpec { - ShellChainSpec::from_genesis( - "Shell Local Testnet", - "shell_local_testnet", - ChainType::Local, - move || shell_testnet_genesis(1000.into()), - Vec::new(), - None, - None, - None, - None, - Extensions { relay_chain: "westend".into(), para_id: 1000 }, - ) -} - -fn shell_testnet_genesis(parachain_id: ParaId) -> shell_runtime::RuntimeGenesisConfig { - shell_runtime::RuntimeGenesisConfig { - system: shell_runtime::SystemConfig { - code: shell_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - parachain_info: shell_runtime::ParachainInfoConfig { parachain_id, ..Default::default() }, - parachain_system: Default::default(), - } + ShellChainSpec::builder() + .with_name("Shell Local Testnet") + .with_id("shell_local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(serde_json::json!({ + "parachainInfo": { "parachainId": ParaId::from(1000) } + })) + .with_boot_nodes(Vec::new()) + .with_extensions(Extensions { relay_chain: "westend".into(), para_id: 1000 }) + .with_code(shell_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!")) + .build() } diff --git a/cumulus/polkadot-parachain/src/command.rs b/cumulus/polkadot-parachain/src/command.rs index 008e5435f0b1..2320d8f26fbb 100644 --- a/cumulus/polkadot-parachain/src/command.rs +++ b/cumulus/polkadot-parachain/src/command.rs @@ -1096,35 +1096,31 @@ mod tests { cfg_file_path } - pub type DummyChainSpec = - sc_service::GenericChainSpec; + pub type DummyChainSpec = sc_service::GenericChainSpec<(), E>; pub fn create_default_with_extensions( id: &str, extension: E, ) -> DummyChainSpec { - DummyChainSpec::from_genesis( - "Dummy local testnet", - id, - ChainType::Local, - move || { - crate::chain_spec::rococo_parachain::testnet_genesis( - get_account_id_from_seed::("Alice"), - vec![ - get_from_seed::("Alice"), - get_from_seed::("Bob"), - ], - vec![get_account_id_from_seed::("Alice")], - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - None, - extension, - ) + DummyChainSpec::builder() + .with_name("Dummy local testnet") + .with_id(id) + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(crate::chain_spec::rococo_parachain::testnet_genesis( + get_account_id_from_seed::("Alice"), + vec![ + get_from_seed::("Alice"), + get_from_seed::("Bob"), + ], + vec![get_account_id_from_seed::("Alice")], + 1000.into(), + )) + .with_extensions(extension) + .with_code( + rococo_parachain_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + .build() } #[test] diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs new file mode 100644 index 000000000000..1b6ec1c203ae --- /dev/null +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs @@ -0,0 +1,653 @@ +// Copyright 2019-2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus 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. + +// Cumulus 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 Cumulus. If not, see . + +use crate::legacy_chain_spec::{ + get_account_id_from_seed, get_collator_keys_from_seed, Extensions, SAFE_XCM_VERSION, +}; +use cumulus_primitives_core::ParaId; +use hex_literal::hex; +use parachains_common::{AccountId, AssetHubPolkadotAuraId, AuraId, Balance as AssetHubBalance}; +use sc_service::ChainType; +use sp_core::{crypto::UncheckedInto, sr25519}; + +/// Specialized `ChainSpec` for the normal parachain runtime. +pub type AssetHubPolkadotChainSpec = + sc_service::GenericChainSpec; +pub type AssetHubKusamaChainSpec = + sc_service::GenericChainSpec; +pub type AssetHubWestendChainSpec = + sc_service::GenericChainSpec; + +const ASSET_HUB_POLKADOT_ED: AssetHubBalance = + asset_hub_polkadot_runtime::constants::currency::EXISTENTIAL_DEPOSIT; +const ASSET_HUB_KUSAMA_ED: AssetHubBalance = + asset_hub_kusama_runtime::constants::currency::EXISTENTIAL_DEPOSIT; +const ASSET_HUB_WESTEND_ED: AssetHubBalance = + asset_hub_westend_runtime::constants::currency::EXISTENTIAL_DEPOSIT; + +/// 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 asset_hub_westend_session_keys(keys: AuraId) -> asset_hub_westend_runtime::SessionKeys { + asset_hub_westend_runtime::SessionKeys { aura: keys } +} + +pub fn asset_hub_polkadot_development_config() -> AssetHubPolkadotChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 0.into()); + properties.insert("tokenSymbol".into(), "DOT".into()); + properties.insert("tokenDecimals".into(), 10.into()); + + #[allow(deprecated)] + AssetHubPolkadotChainSpec::from_genesis( + // Name + "Polkadot Asset Hub Development", + // ID + "asset-hub-polkadot-dev", + ChainType::Local, + move || { + asset_hub_polkadot_genesis( + // initial collators. + vec![( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + )], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + ], + 1000.into(), + ) + }, + Vec::new(), + None, + None, + None, + Some(properties), + Extensions { relay_chain: "polkadot-dev".into(), para_id: 1000 }, + asset_hub_polkadot_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) +} + +pub fn asset_hub_polkadot_local_config() -> AssetHubPolkadotChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 0.into()); + properties.insert("tokenSymbol".into(), "DOT".into()); + properties.insert("tokenDecimals".into(), 10.into()); + + #[allow(deprecated)] + AssetHubPolkadotChainSpec::from_genesis( + // Name + "Polkadot Asset Hub Local", + // ID + "asset-hub-polkadot-local", + ChainType::Local, + move || { + asset_hub_polkadot_genesis( + // initial collators. + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + 1000.into(), + ) + }, + Vec::new(), + None, + None, + None, + Some(properties), + Extensions { relay_chain: "polkadot-local".into(), para_id: 1000 }, + asset_hub_polkadot_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) +} + +// Not used for syncing, but just to determine the genesis values set for the upgrade from shell. +pub fn asset_hub_polkadot_config() -> AssetHubPolkadotChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 0.into()); + properties.insert("tokenSymbol".into(), "DOT".into()); + properties.insert("tokenDecimals".into(), 10.into()); + + #[allow(deprecated)] + AssetHubPolkadotChainSpec::from_genesis( + // Name + "Polkadot Asset Hub", + // ID + "asset-hub-polkadot", + ChainType::Live, + move || { + asset_hub_polkadot_genesis( + // initial collators. + vec![ + ( + hex!("4c3d674d2a01060f0ded218e5dcc6f90c1726f43df79885eb3e22d97a20d5421") + .into(), + hex!("4c3d674d2a01060f0ded218e5dcc6f90c1726f43df79885eb3e22d97a20d5421") + .unchecked_into(), + ), + ( + hex!("c7d7d38d16bc23c6321152c50306212dc22c0efc04a2e52b5cccfc31ab3d7811") + .into(), + hex!("c7d7d38d16bc23c6321152c50306212dc22c0efc04a2e52b5cccfc31ab3d7811") + .unchecked_into(), + ), + ( + hex!("c5c07ba203d7375675f5c1ebe70f0a5bb729ae57b48bcc877fcc2ab21309b762") + .into(), + hex!("c5c07ba203d7375675f5c1ebe70f0a5bb729ae57b48bcc877fcc2ab21309b762") + .unchecked_into(), + ), + ( + hex!("0b2d0013fb974794bd7aa452465b567d48ef70373fe231a637c1fb7c547e85b3") + .into(), + hex!("0b2d0013fb974794bd7aa452465b567d48ef70373fe231a637c1fb7c547e85b3") + .unchecked_into(), + ), + ], + vec![], + 1000u32.into(), + ) + }, + vec![ + "/ip4/34.65.251.121/tcp/30334/p2p/12D3KooWG3GrM6XKMM4gp3cvemdwUvu96ziYoJmqmetLZBXE8bSa".parse().unwrap(), + "/ip4/34.65.35.228/tcp/30334/p2p/12D3KooWMRyTLrCEPcAQD6c4EnudL3vVzg9zji3whvsMYPUYevpq".parse().unwrap(), + "/ip4/34.83.247.146/tcp/30334/p2p/12D3KooWE4jFh5FpJDkWVZhnWtFnbSqRhdjvC7Dp9b8b3FTuubQC".parse().unwrap(), + "/ip4/104.199.117.230/tcp/30334/p2p/12D3KooWG9R8pVXKumVo2rdkeVD4j5PVhRTqmYgLHY3a4yPYgLqM".parse().unwrap(), + ], + None, + None, + None, + Some(properties), + Extensions { relay_chain: "polkadot".into(), para_id: 1000 }, + asset_hub_polkadot_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) +} + +fn asset_hub_polkadot_genesis( + invulnerables: Vec<(AccountId, AssetHubPolkadotAuraId)>, + endowed_accounts: Vec, + id: ParaId, +) -> asset_hub_polkadot_runtime::RuntimeGenesisConfig { + asset_hub_polkadot_runtime::RuntimeGenesisConfig { + system: asset_hub_polkadot_runtime::SystemConfig::default(), + balances: asset_hub_polkadot_runtime::BalancesConfig { + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, ASSET_HUB_POLKADOT_ED * 4096)) + .collect(), + }, + parachain_info: asset_hub_polkadot_runtime::ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + collator_selection: 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(), + }, + // no need to pass anything to aura, in fact it will panic if we do. Session will take care + // of this. + aura: Default::default(), + aura_ext: Default::default(), + parachain_system: Default::default(), + polkadot_xcm: asset_hub_polkadot_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + } +} + +pub fn asset_hub_kusama_development_config() -> AssetHubKusamaChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 2.into()); + properties.insert("tokenSymbol".into(), "KSM".into()); + properties.insert("tokenDecimals".into(), 12.into()); + + #[allow(deprecated)] + AssetHubKusamaChainSpec::from_genesis( + // Name + "Kusama Asset Hub Development", + // ID + "asset-hub-kusama-dev", + ChainType::Local, + move || { + asset_hub_kusama_genesis( + // initial collators. + vec![( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + )], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + ], + 1000.into(), + ) + }, + Vec::new(), + None, + None, + None, + Some(properties), + Extensions { relay_chain: "kusama-dev".into(), para_id: 1000 }, + asset_hub_kusama_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) +} + +pub fn asset_hub_kusama_local_config() -> AssetHubKusamaChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 2.into()); + properties.insert("tokenSymbol".into(), "KSM".into()); + properties.insert("tokenDecimals".into(), 12.into()); + + #[allow(deprecated)] + AssetHubKusamaChainSpec::from_genesis( + // Name + "Kusama Asset Hub Local", + // ID + "asset-hub-kusama-local", + ChainType::Local, + move || { + asset_hub_kusama_genesis( + // initial collators. + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + 1000.into(), + ) + }, + Vec::new(), + None, + None, + None, + Some(properties), + Extensions { relay_chain: "kusama-local".into(), para_id: 1000 }, + asset_hub_kusama_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) +} + +pub fn asset_hub_kusama_config() -> AssetHubKusamaChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 2.into()); + properties.insert("tokenSymbol".into(), "KSM".into()); + properties.insert("tokenDecimals".into(), 12.into()); + + #[allow(deprecated)] + AssetHubKusamaChainSpec::from_genesis( + // Name + "Kusama Asset Hub", + // ID + "asset-hub-kusama", + ChainType::Live, + move || { + asset_hub_kusama_genesis( + // initial collators. + vec![ + ( + hex!("50673d59020488a4ffc9d8c6de3062a65977046e6990915617f85fef6d349730") + .into(), + hex!("50673d59020488a4ffc9d8c6de3062a65977046e6990915617f85fef6d349730") + .unchecked_into(), + ), + ( + hex!("fe8102dbc244e7ea2babd9f53236d67403b046154370da5c3ea99def0bd0747a") + .into(), + hex!("fe8102dbc244e7ea2babd9f53236d67403b046154370da5c3ea99def0bd0747a") + .unchecked_into(), + ), + ( + hex!("38144b5398e5d0da5ec936a3af23f5a96e782f676ab19d45f29075ee92eca76a") + .into(), + hex!("38144b5398e5d0da5ec936a3af23f5a96e782f676ab19d45f29075ee92eca76a") + .unchecked_into(), + ), + ( + hex!("3253947640e309120ae70fa458dcacb915e2ddd78f930f52bd3679ec63fc4415") + .into(), + hex!("3253947640e309120ae70fa458dcacb915e2ddd78f930f52bd3679ec63fc4415") + .unchecked_into(), + ), + ], + Vec::new(), + 1000.into(), + ) + }, + Vec::new(), + None, + None, + None, + Some(properties), + Extensions { relay_chain: "kusama".into(), para_id: 1000 }, + asset_hub_kusama_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) +} + +fn asset_hub_kusama_genesis( + invulnerables: Vec<(AccountId, AuraId)>, + endowed_accounts: Vec, + id: ParaId, +) -> asset_hub_kusama_runtime::RuntimeGenesisConfig { + asset_hub_kusama_runtime::RuntimeGenesisConfig { + system: asset_hub_kusama_runtime::SystemConfig::default(), + balances: asset_hub_kusama_runtime::BalancesConfig { + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, ASSET_HUB_KUSAMA_ED * 524_288)) + .collect(), + }, + parachain_info: asset_hub_kusama_runtime::ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + collator_selection: 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(), + }, + aura: Default::default(), + aura_ext: Default::default(), + parachain_system: Default::default(), + polkadot_xcm: asset_hub_kusama_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + } +} + +pub fn asset_hub_westend_development_config() -> AssetHubWestendChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("tokenSymbol".into(), "WND".into()); + properties.insert("tokenDecimals".into(), 12.into()); + + #[allow(deprecated)] + AssetHubWestendChainSpec::from_genesis( + // Name + "Westend Asset Hub Development", + // ID + "asset-hub-westend-dev", + ChainType::Local, + move || { + asset_hub_westend_genesis( + // initial collators. + vec![( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + )], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + ], + 1000.into(), + ) + }, + Vec::new(), + None, + None, + None, + Some(properties), + Extensions { relay_chain: "westend".into(), para_id: 1000 }, + asset_hub_westend_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) +} + +pub fn asset_hub_westend_local_config() -> AssetHubWestendChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("tokenSymbol".into(), "WND".into()); + properties.insert("tokenDecimals".into(), 12.into()); + + #[allow(deprecated)] + AssetHubWestendChainSpec::from_genesis( + // Name + "Westend Asset Hub Local", + // ID + "asset-hub-westend-local", + ChainType::Local, + move || { + asset_hub_westend_genesis( + // initial collators. + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + 1000.into(), + ) + }, + Vec::new(), + None, + None, + None, + Some(properties), + Extensions { relay_chain: "westend-local".into(), para_id: 1000 }, + asset_hub_westend_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) +} + +pub fn asset_hub_westend_config() -> AssetHubWestendChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("tokenSymbol".into(), "WND".into()); + properties.insert("tokenDecimals".into(), 12.into()); + + #[allow(deprecated)] + AssetHubWestendChainSpec::from_genesis( + // Name + "Westend Asset Hub", + // ID + "asset-hub-westend", + ChainType::Live, + move || { + asset_hub_westend_genesis( + // initial collators. + vec![ + ( + hex!("9cfd429fa002114f33c1d3e211501d62830c9868228eb3b4b8ae15a83de04325") + .into(), + hex!("9cfd429fa002114f33c1d3e211501d62830c9868228eb3b4b8ae15a83de04325") + .unchecked_into(), + ), + ( + hex!("12a03fb4e7bda6c9a07ec0a11d03c24746943e054ff0bb04938970104c783876") + .into(), + hex!("12a03fb4e7bda6c9a07ec0a11d03c24746943e054ff0bb04938970104c783876") + .unchecked_into(), + ), + ( + hex!("1256436307dfde969324e95b8c62cb9101f520a39435e6af0f7ac07b34e1931f") + .into(), + hex!("1256436307dfde969324e95b8c62cb9101f520a39435e6af0f7ac07b34e1931f") + .unchecked_into(), + ), + ( + hex!("98102b7bca3f070f9aa19f58feed2c0a4e107d203396028ec17a47e1ed80e322") + .into(), + hex!("98102b7bca3f070f9aa19f58feed2c0a4e107d203396028ec17a47e1ed80e322") + .unchecked_into(), + ), + ], + Vec::new(), + 1000.into(), + ) + }, + Vec::new(), + None, + None, + None, + Some(properties), + Extensions { relay_chain: "westend".into(), para_id: 1000 }, + asset_hub_westend_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) +} + +fn asset_hub_westend_genesis( + invulnerables: Vec<(AccountId, AuraId)>, + endowed_accounts: Vec, + id: ParaId, +) -> asset_hub_westend_runtime::RuntimeGenesisConfig { + asset_hub_westend_runtime::RuntimeGenesisConfig { + system: asset_hub_westend_runtime::SystemConfig::default(), + balances: asset_hub_westend_runtime::BalancesConfig { + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, ASSET_HUB_WESTEND_ED * 4096)) + .collect(), + }, + parachain_info: asset_hub_westend_runtime::ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + collator_selection: asset_hub_westend_runtime::CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: ASSET_HUB_WESTEND_ED * 16, + ..Default::default() + }, + session: asset_hub_westend_runtime::SessionConfig { + keys: invulnerables + .into_iter() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc, // validator id + asset_hub_westend_session_keys(aura), // session keys + ) + }) + .collect(), + }, + // no need to pass anything to aura, in fact it will panic if we do. Session will take care + // of this. + aura: Default::default(), + aura_ext: Default::default(), + parachain_system: Default::default(), + polkadot_xcm: asset_hub_westend_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + } +} diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/bridge_hubs.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/bridge_hubs.rs new file mode 100644 index 000000000000..02d5502e290f --- /dev/null +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/bridge_hubs.rs @@ -0,0 +1,621 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus 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. + +// Cumulus 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 Cumulus. If not, see . +// + +#![allow(dead_code)] + +use crate::chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed}; +use cumulus_primitives_core::ParaId; +use parachains_common::Balance as BridgeHubBalance; +use sc_chain_spec::ChainSpec; +use sp_core::sr25519; +use std::{path::PathBuf, str::FromStr}; + +/// Collects all supported BridgeHub configurations +#[derive(Debug, PartialEq)] +pub enum BridgeHubRuntimeType { + Rococo, + RococoLocal, + // used by benchmarks + RococoDevelopment, + + Wococo, + WococoLocal, + + Kusama, + KusamaLocal, + // used by benchmarks + KusamaDevelopment, + + Polkadot, + PolkadotLocal, + // used by benchmarks + PolkadotDevelopment, + + // used with kusama runtime + Westend, +} + +impl FromStr for BridgeHubRuntimeType { + type Err = String; + + fn from_str(value: &str) -> Result { + match value { + polkadot::BRIDGE_HUB_POLKADOT => Ok(BridgeHubRuntimeType::Polkadot), + polkadot::BRIDGE_HUB_POLKADOT_LOCAL => Ok(BridgeHubRuntimeType::PolkadotLocal), + polkadot::BRIDGE_HUB_POLKADOT_DEVELOPMENT => + Ok(BridgeHubRuntimeType::PolkadotDevelopment), + kusama::BRIDGE_HUB_KUSAMA => Ok(BridgeHubRuntimeType::Kusama), + kusama::BRIDGE_HUB_KUSAMA_LOCAL => Ok(BridgeHubRuntimeType::KusamaLocal), + kusama::BRIDGE_HUB_KUSAMA_DEVELOPMENT => Ok(BridgeHubRuntimeType::KusamaDevelopment), + westend::BRIDGE_HUB_WESTEND => Ok(BridgeHubRuntimeType::Westend), + rococo::BRIDGE_HUB_ROCOCO => Ok(BridgeHubRuntimeType::Rococo), + rococo::BRIDGE_HUB_ROCOCO_LOCAL => Ok(BridgeHubRuntimeType::RococoLocal), + rococo::BRIDGE_HUB_ROCOCO_DEVELOPMENT => Ok(BridgeHubRuntimeType::RococoDevelopment), + wococo::BRIDGE_HUB_WOCOCO => Ok(BridgeHubRuntimeType::Wococo), + wococo::BRIDGE_HUB_WOCOCO_LOCAL => Ok(BridgeHubRuntimeType::WococoLocal), + _ => Err(format!("Value '{}' is not configured yet", value)), + } + } +} + +impl BridgeHubRuntimeType { + pub const ID_PREFIX: &'static str = "bridge-hub"; + + pub fn chain_spec_from_json_file(&self, path: PathBuf) -> Result, String> { + match self { + BridgeHubRuntimeType::Polkadot | + BridgeHubRuntimeType::PolkadotLocal | + BridgeHubRuntimeType::PolkadotDevelopment => + Ok(Box::new(polkadot::BridgeHubChainSpec::from_json_file(path)?)), + BridgeHubRuntimeType::Kusama | + BridgeHubRuntimeType::KusamaLocal | + BridgeHubRuntimeType::KusamaDevelopment => + Ok(Box::new(kusama::BridgeHubChainSpec::from_json_file(path)?)), + BridgeHubRuntimeType::Westend => + Ok(Box::new(westend::BridgeHubChainSpec::from_json_file(path)?)), + BridgeHubRuntimeType::Rococo | + BridgeHubRuntimeType::RococoLocal | + BridgeHubRuntimeType::RococoDevelopment => + Ok(Box::new(rococo::BridgeHubChainSpec::from_json_file(path)?)), + BridgeHubRuntimeType::Wococo | BridgeHubRuntimeType::WococoLocal => + Ok(Box::new(wococo::BridgeHubChainSpec::from_json_file(path)?)), + } + } + + pub fn load_config(&self) -> Result, String> { + match self { + BridgeHubRuntimeType::Polkadot => + Ok(Box::new(polkadot::BridgeHubChainSpec::from_json_bytes( + &include_bytes!("../../../parachains/chain-specs/bridge-hub-polkadot.json")[..], + )?)), + BridgeHubRuntimeType::PolkadotLocal => Ok(Box::new(polkadot::local_config( + polkadot::BRIDGE_HUB_POLKADOT_LOCAL, + "Polkadot BridgeHub Local", + "polkadot-local", + ParaId::new(1002), + ))), + BridgeHubRuntimeType::PolkadotDevelopment => Ok(Box::new(polkadot::local_config( + polkadot::BRIDGE_HUB_POLKADOT_DEVELOPMENT, + "Polkadot BridgeHub Development", + "polkadot-dev", + ParaId::new(1002), + ))), + BridgeHubRuntimeType::Kusama => + Ok(Box::new(kusama::BridgeHubChainSpec::from_json_bytes( + &include_bytes!("../../../parachains/chain-specs/bridge-hub-kusama.json")[..], + )?)), + BridgeHubRuntimeType::KusamaLocal => Ok(Box::new(kusama::local_config( + kusama::BRIDGE_HUB_KUSAMA_LOCAL, + "Kusama BridgeHub Local", + "kusama-local", + ParaId::new(1003), + ))), + BridgeHubRuntimeType::KusamaDevelopment => Ok(Box::new(kusama::local_config( + kusama::BRIDGE_HUB_KUSAMA_DEVELOPMENT, + "Kusama BridgeHub Development", + "kusama-dev", + ParaId::new(1003), + ))), + BridgeHubRuntimeType::Westend => + Ok(Box::new(westend::BridgeHubChainSpec::from_json_bytes( + &include_bytes!("../../../parachains/chain-specs/bridge-hub-westend.json")[..], + )?)), + BridgeHubRuntimeType::Rococo => + Ok(Box::new(rococo::BridgeHubChainSpec::from_json_bytes( + &include_bytes!("../../../parachains/chain-specs/bridge-hub-rococo.json")[..], + )?)), + BridgeHubRuntimeType::RococoLocal => Ok(Box::new(rococo::local_config( + rococo::BRIDGE_HUB_ROCOCO_LOCAL, + "Rococo BridgeHub Local", + "rococo-local", + ParaId::new(1013), + Some("Bob".to_string()), + |_| (), + ))), + BridgeHubRuntimeType::RococoDevelopment => Ok(Box::new(rococo::local_config( + rococo::BRIDGE_HUB_ROCOCO_DEVELOPMENT, + "Rococo BridgeHub Development", + "rococo-dev", + ParaId::new(1013), + Some("Bob".to_string()), + |_| (), + ))), + BridgeHubRuntimeType::Wococo => + Ok(Box::new(wococo::BridgeHubChainSpec::from_json_bytes( + &include_bytes!("../../../parachains/chain-specs/bridge-hub-wococo.json")[..], + )?)), + BridgeHubRuntimeType::WococoLocal => Ok(Box::new(wococo::local_config( + wococo::BRIDGE_HUB_WOCOCO_LOCAL, + "Wococo BridgeHub Local", + "wococo-local", + ParaId::new(1014), + Some("Bob".to_string()), + ))), + } + } +} + +/// Check if 'id' satisfy BridgeHub-like format +fn ensure_id(id: &str) -> Result<&str, String> { + if id.starts_with(BridgeHubRuntimeType::ID_PREFIX) { + Ok(id) + } else { + Err(format!( + "Invalid 'id' attribute ({}), should start with prefix: {}", + id, + BridgeHubRuntimeType::ID_PREFIX + )) + } +} + +/// Sub-module for Rococo setup +pub mod rococo { + use super::{get_account_id_from_seed, get_collator_keys_from_seed, sr25519, ParaId}; + use crate::legacy_chain_spec::{Extensions, SAFE_XCM_VERSION}; + use parachains_common::{AccountId, AuraId}; + use sc_chain_spec::ChainType; + + use super::BridgeHubBalance; + + pub(crate) const BRIDGE_HUB_ROCOCO: &str = "bridge-hub-rococo"; + pub(crate) const BRIDGE_HUB_ROCOCO_LOCAL: &str = "bridge-hub-rococo-local"; + pub(crate) const BRIDGE_HUB_ROCOCO_DEVELOPMENT: &str = "bridge-hub-rococo-dev"; + const BRIDGE_HUB_ROCOCO_ED: BridgeHubBalance = + bridge_hub_rococo_runtime::constants::currency::EXISTENTIAL_DEPOSIT; + + /// Specialized `ChainSpec` for the normal parachain runtime. + pub type BridgeHubChainSpec = + sc_service::GenericChainSpec; + + pub type RuntimeApi = bridge_hub_rococo_runtime::RuntimeApi; + + pub fn local_config( + id: &str, + chain_name: &str, + relay_chain: &str, + para_id: ParaId, + bridges_pallet_owner_seed: Option, + modify_props: ModifyProperties, + ) -> BridgeHubChainSpec { + // Rococo defaults + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 42.into()); + properties.insert("tokenSymbol".into(), "ROC".into()); + properties.insert("tokenDecimals".into(), 12.into()); + modify_props(&mut properties); + + #[allow(deprecated)] + BridgeHubChainSpec::from_genesis( + // Name + chain_name, + // ID + super::ensure_id(id).expect("invalid id"), + ChainType::Local, + move || { + genesis( + // initial collators. + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + para_id, + bridges_pallet_owner_seed + .as_ref() + .map(|seed| get_account_id_from_seed::(seed)), + ) + }, + Vec::new(), + None, + None, + None, + Some(properties), + Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, + bridge_hub_rococo_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + } + + fn genesis( + invulnerables: Vec<(AccountId, AuraId)>, + endowed_accounts: Vec, + id: ParaId, + bridges_pallet_owner: Option, + ) -> bridge_hub_rococo_runtime::RuntimeGenesisConfig { + bridge_hub_rococo_runtime::RuntimeGenesisConfig { + system: bridge_hub_rococo_runtime::SystemConfig::default(), + balances: bridge_hub_rococo_runtime::BalancesConfig { + balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), + }, + parachain_info: bridge_hub_rococo_runtime::ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + collator_selection: bridge_hub_rococo_runtime::CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: BRIDGE_HUB_ROCOCO_ED * 16, + ..Default::default() + }, + session: bridge_hub_rococo_runtime::SessionConfig { + keys: invulnerables + .into_iter() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc, // validator id + bridge_hub_rococo_runtime::SessionKeys { aura }, // session keys + ) + }) + .collect(), + }, + aura: Default::default(), + aura_ext: Default::default(), + parachain_system: Default::default(), + polkadot_xcm: bridge_hub_rococo_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + bridge_wococo_grandpa: bridge_hub_rococo_runtime::BridgeWococoGrandpaConfig { + owner: bridges_pallet_owner.clone(), + ..Default::default() + }, + bridge_rococo_grandpa: bridge_hub_rococo_runtime::BridgeRococoGrandpaConfig { + owner: bridges_pallet_owner.clone(), + ..Default::default() + }, + bridge_rococo_messages: bridge_hub_rococo_runtime::BridgeRococoMessagesConfig { + owner: bridges_pallet_owner.clone(), + ..Default::default() + }, + bridge_wococo_messages: bridge_hub_rococo_runtime::BridgeWococoMessagesConfig { + owner: bridges_pallet_owner, + ..Default::default() + }, + } + } +} + +/// Sub-module for Wococo setup (reuses stuff from Rococo) +pub mod wococo { + use super::ParaId; + use crate::chain_spec::bridge_hubs::rococo; + + pub(crate) const BRIDGE_HUB_WOCOCO: &str = "bridge-hub-wococo"; + pub(crate) const BRIDGE_HUB_WOCOCO_LOCAL: &str = "bridge-hub-wococo-local"; + + pub type BridgeHubChainSpec = rococo::BridgeHubChainSpec; + pub type RuntimeApi = rococo::RuntimeApi; + + pub fn local_config( + id: &str, + chain_name: &str, + relay_chain: &str, + para_id: ParaId, + bridges_pallet_owner_seed: Option, + ) -> BridgeHubChainSpec { + rococo::local_config( + id, + chain_name, + relay_chain, + para_id, + bridges_pallet_owner_seed, + |properties| { + properties.insert("tokenSymbol".into(), "WOOK".into()); + }, + ) + } +} + +/// Sub-module for Kusama setup +pub mod kusama { + use super::{BridgeHubBalance, ParaId}; + use crate::legacy_chain_spec::{ + get_account_id_from_seed, get_collator_keys_from_seed, Extensions, SAFE_XCM_VERSION, + }; + use parachains_common::{AccountId, AuraId}; + use sc_chain_spec::ChainType; + use sp_core::sr25519; + + pub(crate) const BRIDGE_HUB_KUSAMA: &str = "bridge-hub-kusama"; + pub(crate) const BRIDGE_HUB_KUSAMA_LOCAL: &str = "bridge-hub-kusama-local"; + pub(crate) const BRIDGE_HUB_KUSAMA_DEVELOPMENT: &str = "bridge-hub-kusama-dev"; + const BRIDGE_HUB_KUSAMA_ED: BridgeHubBalance = + bridge_hub_kusama_runtime::constants::currency::EXISTENTIAL_DEPOSIT; + + /// Specialized `ChainSpec` for the normal parachain runtime. + pub type BridgeHubChainSpec = + sc_service::GenericChainSpec; + pub type RuntimeApi = bridge_hub_kusama_runtime::RuntimeApi; + + pub fn local_config( + id: &str, + chain_name: &str, + relay_chain: &str, + para_id: ParaId, + ) -> BridgeHubChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 2.into()); + properties.insert("tokenSymbol".into(), "KSM".into()); + properties.insert("tokenDecimals".into(), 12.into()); + + #[allow(deprecated)] + BridgeHubChainSpec::from_genesis( + // Name + chain_name, + // ID + super::ensure_id(id).expect("invalid id"), + ChainType::Local, + move || { + genesis( + // initial collators. + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + para_id, + ) + }, + Vec::new(), + None, + None, + None, + Some(properties), + Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, + bridge_hub_kusama_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + } + + fn genesis( + invulnerables: Vec<(AccountId, AuraId)>, + endowed_accounts: Vec, + id: ParaId, + ) -> bridge_hub_kusama_runtime::RuntimeGenesisConfig { + bridge_hub_kusama_runtime::RuntimeGenesisConfig { + system: bridge_hub_kusama_runtime::SystemConfig::default(), + balances: bridge_hub_kusama_runtime::BalancesConfig { + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, BRIDGE_HUB_KUSAMA_ED * 524_288)) + .collect(), + }, + parachain_info: bridge_hub_kusama_runtime::ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + collator_selection: 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_runtime::SessionKeys { aura }, // session keys + ) + }) + .collect(), + }, + aura: Default::default(), + aura_ext: Default::default(), + parachain_system: Default::default(), + polkadot_xcm: bridge_hub_kusama_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + } + } +} + +/// Sub-module for Westend setup (uses Kusama runtime) +pub mod westend { + use crate::chain_spec::bridge_hubs::kusama; + + pub(crate) const BRIDGE_HUB_WESTEND: &str = "bridge-hub-westend"; + pub type BridgeHubChainSpec = kusama::BridgeHubChainSpec; + pub type RuntimeApi = bridge_hub_kusama_runtime::RuntimeApi; +} + +/// Sub-module for Polkadot setup +pub mod polkadot { + use super::{BridgeHubBalance, ParaId}; + use crate::legacy_chain_spec::{ + get_account_id_from_seed, get_collator_keys_from_seed, Extensions, SAFE_XCM_VERSION, + }; + use parachains_common::{AccountId, AuraId}; + use sc_chain_spec::ChainType; + use sp_core::sr25519; + + pub(crate) const BRIDGE_HUB_POLKADOT: &str = "bridge-hub-polkadot"; + pub(crate) const BRIDGE_HUB_POLKADOT_LOCAL: &str = "bridge-hub-polkadot-local"; + pub(crate) const BRIDGE_HUB_POLKADOT_DEVELOPMENT: &str = "bridge-hub-polkadot-dev"; + const BRIDGE_HUB_POLKADOT_ED: BridgeHubBalance = + bridge_hub_polkadot_runtime::constants::currency::EXISTENTIAL_DEPOSIT; + + /// Specialized `ChainSpec` for the normal parachain runtime. + pub type BridgeHubChainSpec = + sc_service::GenericChainSpec; + pub type RuntimeApi = bridge_hub_polkadot_runtime::RuntimeApi; + + pub fn local_config( + id: &str, + chain_name: &str, + relay_chain: &str, + para_id: ParaId, + ) -> BridgeHubChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 0.into()); + properties.insert("tokenSymbol".into(), "DOT".into()); + properties.insert("tokenDecimals".into(), 10.into()); + + #[allow(deprecated)] + BridgeHubChainSpec::from_genesis( + // Name + chain_name, + // ID + super::ensure_id(id).expect("invalid id"), + ChainType::Local, + move || { + genesis( + // initial collators. + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + para_id, + ) + }, + Vec::new(), + None, + None, + None, + Some(properties), + Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, + bridge_hub_polkadot_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) + } + + fn genesis( + invulnerables: Vec<(AccountId, AuraId)>, + endowed_accounts: Vec, + id: ParaId, + ) -> bridge_hub_polkadot_runtime::RuntimeGenesisConfig { + bridge_hub_polkadot_runtime::RuntimeGenesisConfig { + system: bridge_hub_polkadot_runtime::SystemConfig::default(), + balances: bridge_hub_polkadot_runtime::BalancesConfig { + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, BRIDGE_HUB_POLKADOT_ED * 4096)) + .collect(), + }, + parachain_info: bridge_hub_polkadot_runtime::ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + collator_selection: 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_runtime::SessionKeys { aura }, // session keys + ) + }) + .collect(), + }, + aura: Default::default(), + aura_ext: Default::default(), + parachain_system: Default::default(), + polkadot_xcm: bridge_hub_polkadot_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + } + } +} diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/collectives.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/collectives.rs new file mode 100644 index 000000000000..8a89afb78824 --- /dev/null +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/collectives.rs @@ -0,0 +1,184 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus 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. + +// Cumulus 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 Cumulus. If not, see . + +use crate::legacy_chain_spec::{ + get_account_id_from_seed, get_collator_keys_from_seed, Extensions, SAFE_XCM_VERSION, +}; +use cumulus_primitives_core::ParaId; +use parachains_common::{AccountId, AuraId, Balance as CollectivesBalance}; +use sc_service::ChainType; +use sp_core::sr25519; + +pub type CollectivesPolkadotChainSpec = + sc_service::GenericChainSpec; + +const COLLECTIVES_POLKADOT_ED: CollectivesBalance = + collectives_polkadot_runtime::constants::currency::EXISTENTIAL_DEPOSIT; + +/// 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 } +} + +pub fn collectives_polkadot_development_config() -> CollectivesPolkadotChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 0.into()); + properties.insert("tokenSymbol".into(), "DOT".into()); + properties.insert("tokenDecimals".into(), 10.into()); + + #[allow(deprecated)] + CollectivesPolkadotChainSpec::from_genesis( + // Name + "Polkadot Collectives Development", + // ID + "collectives_polkadot_dev", + ChainType::Local, + move || { + collectives_polkadot_genesis( + // initial collators. + vec![( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + )], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + ], + // 1002 avoids a potential collision with Kusama-1001 (Encointer) should there ever + // be a collective para on Kusama. + 1002.into(), + ) + }, + Vec::new(), + None, + None, + None, + Some(properties), + Extensions { relay_chain: "polkadot-dev".into(), para_id: 1002 }, + collectives_polkadot_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) +} + +/// Collectives Polkadot Local Config. +pub fn collectives_polkadot_local_config() -> CollectivesPolkadotChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 0.into()); + properties.insert("tokenSymbol".into(), "DOT".into()); + properties.insert("tokenDecimals".into(), 10.into()); + + #[allow(deprecated)] + CollectivesPolkadotChainSpec::from_genesis( + // Name + "Polkadot Collectives Local", + // ID + "collectives_polkadot_local", + ChainType::Local, + move || { + collectives_polkadot_genesis( + // initial collators. + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + 1002.into(), + ) + }, + Vec::new(), + None, + None, + None, + Some(properties), + Extensions { relay_chain: "polkadot-local".into(), para_id: 1002 }, + collectives_polkadot_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + ) +} + +fn collectives_polkadot_genesis( + invulnerables: Vec<(AccountId, AuraId)>, + endowed_accounts: Vec, + id: ParaId, +) -> collectives_polkadot_runtime::RuntimeGenesisConfig { + collectives_polkadot_runtime::RuntimeGenesisConfig { + system: collectives_polkadot_runtime::SystemConfig::default(), + balances: collectives_polkadot_runtime::BalancesConfig { + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, COLLECTIVES_POLKADOT_ED * 4096)) + .collect(), + }, + parachain_info: collectives_polkadot_runtime::ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + collator_selection: 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(), + }, + // no need to pass anything to aura, in fact it will panic if we do. Session will take care + // of this. + aura: Default::default(), + aura_ext: Default::default(), + parachain_system: Default::default(), + polkadot_xcm: collectives_polkadot_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + alliance: Default::default(), + alliance_motion: Default::default(), + } +} diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/contracts.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/contracts.rs new file mode 100644 index 000000000000..7998f2176774 --- /dev/null +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/contracts.rs @@ -0,0 +1,287 @@ +// Copyright 2019-2021 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus 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. + +// Cumulus 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 Cumulus. If not, see . + +use crate::legacy_chain_spec::{ + get_account_id_from_seed, get_collator_keys_from_seed, Extensions, SAFE_XCM_VERSION, +}; +use cumulus_primitives_core::ParaId; +use hex_literal::hex; +use parachains_common::{AccountId, AuraId}; +use sc_service::ChainType; +use sp_core::{crypto::UncheckedInto, sr25519}; + +pub type ContractsRococoChainSpec = + sc_service::GenericChainSpec; + +/// No relay chain suffix because the id is the same over all relay chains. +const CONTRACTS_PARACHAIN_ID: u32 = 1002; + +/// The existential deposit is determined by the runtime "contracts-rococo". +const CONTRACTS_ROCOCO_ED: contracts_rococo_runtime::Balance = + contracts_rococo_runtime::constants::currency::EXISTENTIAL_DEPOSIT; + +pub fn contracts_rococo_development_config() -> ContractsRococoChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("tokenSymbol".into(), "ROC".into()); + properties.insert("tokenDecimals".into(), 12.into()); + + #[allow(deprecated)] + ContractsRococoChainSpec::from_genesis( + // Name + "Contracts on Rococo Development", + // ID + "contracts-rococo-dev", + ChainType::Development, + move || { + contracts_rococo_genesis( + // initial collators. + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + CONTRACTS_PARACHAIN_ID.into(), + ) + }, + Vec::new(), + None, + None, + None, + None, + Extensions { + relay_chain: "rococo-local".into(), // You MUST set this to the correct network! + para_id: CONTRACTS_PARACHAIN_ID, + }, + contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) +} + +pub fn contracts_rococo_local_config() -> ContractsRococoChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("tokenSymbol".into(), "ROC".into()); + properties.insert("tokenDecimals".into(), 12.into()); + + #[allow(deprecated)] + ContractsRococoChainSpec::from_genesis( + // Name + "Contracts on Rococo", + // ID + "contracts-rococo-local", + ChainType::Local, + move || { + contracts_rococo_genesis( + // initial collators. + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + CONTRACTS_PARACHAIN_ID.into(), + ) + }, + // Bootnodes + Vec::new(), + // Telemetry + None, + // Protocol ID + None, + // Fork ID + None, + // Properties + Some(properties), + // Extensions + Extensions { + relay_chain: "rococo-local".into(), // You MUST set this to the correct network! + para_id: CONTRACTS_PARACHAIN_ID, + }, + // Code + contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) +} + +pub fn contracts_rococo_config() -> ContractsRococoChainSpec { + // Give your base currency a unit name and decimal places + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("tokenSymbol".into(), "ROC".into()); + properties.insert("tokenDecimals".into(), 12.into()); + + #[allow(deprecated)] + ContractsRococoChainSpec::from_genesis( + // Name + "Contracts on Rococo", + // ID + "contracts-rococo", + ChainType::Live, + move || { + contracts_rococo_genesis( + vec![ + // 5GKFbTTgrVS4Vz1UWWHPqMZQNFWZtqo7H2KpCDyYhEL3aS26 + ( + hex!["bc09354c12c054c8f6b3da208485eacec4ac648bad348895273b37bab5a0937c"] + .into(), + hex!["bc09354c12c054c8f6b3da208485eacec4ac648bad348895273b37bab5a0937c"] + .unchecked_into(), + ), + // 5EPRJHm2GpABVWcwnAujcrhnrjFZyDGd5TwKFzkBoGgdRyv2 + ( + hex!["66be63b7bcbfb91040e5248e2d1ceb822cf219c57848c5924ffa3a1f8e67ba72"] + .into(), + hex!["66be63b7bcbfb91040e5248e2d1ceb822cf219c57848c5924ffa3a1f8e67ba72"] + .unchecked_into(), + ), + // 5GH62vrJrVZxLREcHzm2PR5uTLAT5RQMJitoztCGyaP4o3uM + ( + hex!["ba62886472a0a9f66b5e39f1469ce1c5b3d8cad6be39078daf16f111e89d1e44"] + .into(), + hex!["ba62886472a0a9f66b5e39f1469ce1c5b3d8cad6be39078daf16f111e89d1e44"] + .unchecked_into(), + ), + // 5FHfoJDLdjRYX5KXLRqMDYBbWrwHLMtti21uK4QByUoUAbJF + ( + hex!["8e97f65cda001976311df9bed39e8d0c956089093e94a75ef76fe9347a0eda7b"] + .into(), + hex!["8e97f65cda001976311df9bed39e8d0c956089093e94a75ef76fe9347a0eda7b"] + .unchecked_into(), + ), + ], + // Warning: The configuration for a production chain should not contain + // any endowed accounts here, otherwise it'll be minting extra native tokens + // from the relay chain on the parachain. + vec![ + // NOTE: Remove endowed accounts if deployed on other relay chains. + // Endowed accounts + hex!["baa78c7154c7f82d6d377177e20bcab65d327eca0086513f9964f5a0f6bdad56"].into(), + // AccountId of an account which `ink-waterfall` uses for automated testing + hex!["0e47e2344d523c3cc5c34394b0d58b9a4200e813a038e6c5a6163cc07d70b069"].into(), + ], + CONTRACTS_PARACHAIN_ID.into(), + ) + }, + // Bootnodes + vec![ + "/dns/contracts-collator-0.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWKg3Rpxcr9oJ8n6khoxpGKWztCZydtUZk2cojHqnfLrpj" + .parse() + .expect("MultiaddrWithPeerId"), + "/dns/contracts-collator-1.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWPEXYrz8tHU3nDtPoPw4V7ou5dzMEWSTuUj7vaWiYVAVh" + .parse() + .expect("MultiaddrWithPeerId"), + "/dns/contracts-collator-2.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWEVU8AFNary4nP4qEnEcwJaRuy59Wefekzdu9pKbnVEhk" + .parse() + .expect("MultiaddrWithPeerId"), + "/dns/contracts-collator-3.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWP6pV3ZmcXzGDjv8ZMgA6nZxfAKDxSz4VNiLx6vVCQgJX" + .parse() + .expect("MultiaddrWithPeerId"), + ], + // Telemetry + None, + // Protocol ID + None, + // Fork ID + None, + // Properties + Some(properties), + // Extensions + Extensions { relay_chain: "rococo".into(), para_id: CONTRACTS_PARACHAIN_ID }, + // Code + contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) +} + +fn contracts_rococo_genesis( + invulnerables: Vec<(AccountId, AuraId)>, + endowed_accounts: Vec, + id: ParaId, +) -> contracts_rococo_runtime::RuntimeGenesisConfig { + contracts_rococo_runtime::RuntimeGenesisConfig { + system: contracts_rococo_runtime::SystemConfig::default(), + balances: contracts_rococo_runtime::BalancesConfig { + balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), + }, + parachain_info: contracts_rococo_runtime::ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + collator_selection: contracts_rococo_runtime::CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: CONTRACTS_ROCOCO_ED * 16, + ..Default::default() + }, + session: contracts_rococo_runtime::SessionConfig { + keys: invulnerables + .into_iter() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc, // validator id + contracts_rococo_runtime::SessionKeys { aura }, // session keys + ) + }) + .collect(), + }, + // no need to pass anything to aura, in fact it will panic if we do. Session will take care + // of this. + aura: Default::default(), + aura_ext: Default::default(), + parachain_system: Default::default(), + polkadot_xcm: contracts_rococo_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + sudo: contracts_rococo_runtime::SudoConfig { + key: Some( + hex!["2681a28014e7d3a5bfb32a003b3571f53c408acbc28d351d6bf58f5028c4ef14"].into(), + ), + }, + } +} diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/glutton.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/glutton.rs new file mode 100644 index 000000000000..9b5feee29c60 --- /dev/null +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/glutton.rs @@ -0,0 +1,102 @@ +// Copyright Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus 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. + +// Cumulus 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 Cumulus. If not, see . + +use crate::chain_spec::{get_account_id_from_seed, Extensions}; +use cumulus_primitives_core::ParaId; +use sc_service::ChainType; +use sp_core::sr25519; + +/// Specialized `ChainSpec` for the Glutton parachain runtime. +pub type GluttonChainSpec = + sc_service::GenericChainSpec; + +pub fn glutton_development_config(para_id: ParaId) -> GluttonChainSpec { + #[allow(deprecated)] + GluttonChainSpec::from_genesis( + // Name + "Glutton Development", + // ID + "glutton_dev", + ChainType::Local, + move || glutton_genesis(para_id), + Vec::new(), + None, + None, + None, + None, + Extensions { relay_chain: "kusama-dev".into(), para_id: para_id.into() }, + glutton_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) +} + +pub fn glutton_local_config(para_id: ParaId) -> GluttonChainSpec { + #[allow(deprecated)] + GluttonChainSpec::from_genesis( + // Name + "Glutton Local", + // ID + "glutton_local", + ChainType::Local, + move || glutton_genesis(para_id), + Vec::new(), + None, + None, + None, + None, + Extensions { relay_chain: "kusama-local".into(), para_id: para_id.into() }, + glutton_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) +} + +pub fn glutton_config(para_id: ParaId) -> GluttonChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 2.into()); + + #[allow(deprecated)] + GluttonChainSpec::from_genesis( + // Name + format!("Glutton {}", para_id).as_str(), + // ID + format!("glutton-kusama-{}", para_id).as_str(), + ChainType::Live, + move || glutton_genesis(para_id), + Vec::new(), + None, + // Protocol ID + Some(format!("glutton-kusama-{}", para_id).as_str()), + None, + Some(properties), + Extensions { relay_chain: "kusama".into(), para_id: para_id.into() }, + glutton_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) +} + +fn glutton_genesis(parachain_id: ParaId) -> glutton_runtime::RuntimeGenesisConfig { + glutton_runtime::RuntimeGenesisConfig { + system: glutton_runtime::SystemConfig::default(), + parachain_info: glutton_runtime::ParachainInfoConfig { parachain_id, ..Default::default() }, + parachain_system: Default::default(), + glutton: glutton_runtime::GluttonConfig { + compute: Default::default(), + storage: Default::default(), + trash_data_count: Default::default(), + ..Default::default() + }, + sudo: glutton_runtime::SudoConfig { + key: Some(get_account_id_from_seed::("Alice")), + }, + } +} diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/json_vs_legacy_tests.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/json_vs_legacy_tests.rs new file mode 100644 index 000000000000..15710c109634 --- /dev/null +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/json_vs_legacy_tests.rs @@ -0,0 +1,88 @@ +// Copyright 2023 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus 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. + +// Cumulus 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 Cumulus. If not, see . + +//! Tests for verifying if raw ChainSpecs generated using legacy RuntimeGenesisConfig based approach +//! are identical to ChainSpec generated using JSON approach. +//! Entire file shall be removed once native runtime is removed. + +macro_rules! test { + ($test_name:ident, $tested_fn:expr) => { + #[test] + fn $test_name() { + let j1 = { + use crate::chain_spec::*; + $tested_fn.as_json(true).unwrap() + }; + let j2 = { + use crate::legacy_chain_spec::*; + $tested_fn.as_json(true).unwrap() + }; + assert_eq!(j1, j2); + } + }; +} + +test!(test00, asset_hubs::asset_hub_polkadot_development_config()); +test!(test01, asset_hubs::asset_hub_polkadot_local_config()); +test!(test02, asset_hubs::asset_hub_polkadot_config()); +test!(test03, asset_hubs::asset_hub_kusama_development_config()); +test!(test04, asset_hubs::asset_hub_kusama_local_config()); +test!(test05, asset_hubs::asset_hub_kusama_config()); +test!(test06, asset_hubs::asset_hub_westend_development_config()); +test!(test07, asset_hubs::asset_hub_westend_local_config()); +test!(test08, asset_hubs::asset_hub_westend_config()); +test!(test09, collectives::collectives_polkadot_development_config()); +test!(test10, collectives::collectives_polkadot_local_config()); +test!(test11, contracts::contracts_rococo_development_config()); +test!(test12, contracts::contracts_rococo_local_config()); +test!(test13, contracts::contracts_rococo_config()); +test!(test14, glutton::glutton_development_config(667.into())); +test!(test15, glutton::glutton_local_config(667.into())); +test!(test16, glutton::glutton_config(667.into())); +test!(test17, penpal::get_penpal_chain_spec(667.into(), "test")); +test!(test18, rococo_parachain::rococo_parachain_local_config()); +test!(test19, rococo_parachain::staging_rococo_parachain_local_config()); +test!(test20, seedling::get_seedling_chain_spec()); +test!(test21, shell::get_shell_chain_spec()); +test!( + test22, + bridge_hubs::rococo::local_config( + "bridge-hub-rococo-local", + "Test", + "test", + 667.into(), + Some("Bob".to_string()), + |_| {} + ) +); +test!( + test23, + bridge_hubs::wococo::local_config( + "bridge-hub-wococo-local", + "Test", + "test", + 667.into(), + Some("Bob".to_string()) + ) +); +test!( + test24, + bridge_hubs::kusama::local_config("bridge-hub-kusama-local", "Test", "test", 667.into()) +); +test!( + test25, + bridge_hubs::polkadot::local_config("bridge-hub-polkadot-local", "Test", "test", 667.into()) +); diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/mod.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/mod.rs new file mode 100644 index 000000000000..14d55663ad20 --- /dev/null +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/mod.rs @@ -0,0 +1,84 @@ +// Copyright 2019-2021 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus 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. + +// Cumulus 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 Cumulus. If not, see . + +//! RuntimeGenesisConfig-based (legacy) polkadot-parachain ChainSpec configurations. Used for +//! testing ChainSpecs against the JSON-based genesis configs. Entire file shall be removed once +//! native runtime is removed. This is just a verbatim copy of chain_spec mod. + +#![allow(dead_code)] + +use parachains_common::{AccountId, Signature}; +use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup}; +use serde::{Deserialize, Serialize}; +use sp_core::{Pair, Public}; +use sp_runtime::traits::{IdentifyAccount, Verify}; + +pub mod asset_hubs; +pub mod bridge_hubs; +pub mod collectives; +pub mod contracts; +pub mod glutton; +pub mod penpal; +pub mod rococo_parachain; +pub mod seedling; +pub mod shell; + +#[cfg(test)] +mod json_vs_legacy_tests; + +/// The default XCM version to set in genesis config. +const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; + +/// Generic extensions for Parachain ChainSpecs. +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)] +#[serde(deny_unknown_fields)] +pub struct Extensions { + /// The relay chain of the Parachain. + pub relay_chain: String, + /// The id of the Parachain. + pub para_id: u32, +} + +impl Extensions { + /// Try to get the extension from the given `ChainSpec`. + pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> { + sc_chain_spec::get_extension(chain_spec.extensions()) + } +} + +/// Helper function to generate a crypto pair from seed +pub fn get_from_seed(seed: &str) -> ::Public { + TPublic::Pair::from_string(&format!("//{}", seed), None) + .expect("static values are valid; qed") + .public() +} + +type AccountPublic = ::Signer; + +/// Helper function to generate an account ID from seed +pub fn get_account_id_from_seed(seed: &str) -> AccountId +where + AccountPublic: From<::Public>, +{ + AccountPublic::from(get_from_seed::(seed)).into_account() +} + +/// Generate collator keys from seed. +/// +/// This function's return type must always match the session keys of the chain in tuple format. +pub fn get_collator_keys_from_seed(seed: &str) -> ::Public { + get_from_seed::(seed) +} diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/penpal.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/penpal.rs new file mode 100644 index 000000000000..960d4d69cb88 --- /dev/null +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/penpal.rs @@ -0,0 +1,140 @@ +// Copyright 2019-2021 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus 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. + +// Cumulus 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 Cumulus. If not, see . + +use crate::legacy_chain_spec::{ + get_account_id_from_seed, get_collator_keys_from_seed, Extensions, SAFE_XCM_VERSION, +}; +use cumulus_primitives_core::ParaId; +use parachains_common::{AccountId, AuraId}; +use sc_service::ChainType; +use sp_core::sr25519; +/// Specialized `ChainSpec` for the normal parachain runtime. +pub type PenpalChainSpec = + sc_service::GenericChainSpec; + +pub fn get_penpal_chain_spec(id: ParaId, relay_chain: &str) -> PenpalChainSpec { + // Give your base currency a unit name and decimal places + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("tokenSymbol".into(), "UNIT".into()); + properties.insert("tokenDecimals".into(), 12u32.into()); + properties.insert("ss58Format".into(), 42u32.into()); + + #[allow(deprecated)] + PenpalChainSpec::from_genesis( + // Name + "Penpal Parachain", + // ID + &format!("penpal-{}", relay_chain.replace("-local", "")), + ChainType::Development, + move || { + penpal_testnet_genesis( + // initial collators. + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + id, + ) + }, + Vec::new(), + None, + None, + None, + None, + Extensions { + relay_chain: relay_chain.into(), // You MUST set this to the correct network! + para_id: id.into(), + }, + penpal_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) +} + +fn penpal_testnet_genesis( + invulnerables: Vec<(AccountId, AuraId)>, + endowed_accounts: Vec, + id: ParaId, +) -> penpal_runtime::RuntimeGenesisConfig { + penpal_runtime::RuntimeGenesisConfig { + system: penpal_runtime::SystemConfig::default(), + balances: penpal_runtime::BalancesConfig { + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, penpal_runtime::EXISTENTIAL_DEPOSIT * 4096)) + .collect(), + }, + parachain_info: penpal_runtime::ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + collator_selection: penpal_runtime::CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: penpal_runtime::EXISTENTIAL_DEPOSIT * 16, + ..Default::default() + }, + session: penpal_runtime::SessionConfig { + keys: invulnerables + .into_iter() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc, // validator id + penpal_session_keys(aura), // session keys + ) + }) + .collect(), + }, + // no need to pass anything to aura, in fact it will panic if we do. Session will take care + // of this. + aura: Default::default(), + aura_ext: Default::default(), + parachain_system: Default::default(), + polkadot_xcm: penpal_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + sudo: penpal_runtime::SudoConfig { + key: Some(get_account_id_from_seed::("Alice")), + }, + } +} + +/// 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 penpal_session_keys(keys: AuraId) -> penpal_runtime::SessionKeys { + penpal_runtime::SessionKeys { aura: keys } +} diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/rococo_parachain.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/rococo_parachain.rs new file mode 100644 index 000000000000..6f1f13800c64 --- /dev/null +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/rococo_parachain.rs @@ -0,0 +1,125 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus 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. + +// Cumulus 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 Cumulus. If not, see . + +//! ChainSpecs dedicated to Rococo parachain setups (for testing and example purposes) + +use crate::legacy_chain_spec::{get_from_seed, Extensions, SAFE_XCM_VERSION}; +use cumulus_primitives_core::ParaId; +use hex_literal::hex; +use parachains_common::AccountId; +use polkadot_service::chain_spec::get_account_id_from_seed; +use rococo_parachain_runtime::AuraId; +use sc_chain_spec::ChainType; +use sp_core::{crypto::UncheckedInto, sr25519}; + +pub type RococoParachainChainSpec = + sc_service::GenericChainSpec; + +pub fn rococo_parachain_local_config() -> RococoParachainChainSpec { + #[allow(deprecated)] + RococoParachainChainSpec::from_genesis( + "Rococo Parachain Local", + "local_testnet", + ChainType::Local, + move || { + testnet_genesis( + get_account_id_from_seed::("Alice"), + vec![get_from_seed::("Alice"), get_from_seed::("Bob")], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + 1000.into(), + ) + }, + Vec::new(), + None, + None, + None, + None, + Extensions { relay_chain: "rococo-local".into(), para_id: 1000 }, + rococo_parachain_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) +} + +pub fn staging_rococo_parachain_local_config() -> RococoParachainChainSpec { + #[allow(deprecated)] + RococoParachainChainSpec::from_genesis( + "Staging Rococo Parachain Local", + "staging_testnet", + ChainType::Live, + move || { + testnet_genesis( + hex!["9ed7705e3c7da027ba0583a22a3212042f7e715d3c168ba14f1424e2bc111d00"].into(), + vec![ + // $secret//one + hex!["aad9fa2249f87a210a0f93400b7f90e47b810c6d65caa0ca3f5af982904c2a33"] + .unchecked_into(), + // $secret//two + hex!["d47753f0cca9dd8da00c70e82ec4fc5501a69c49a5952a643d18802837c88212"] + .unchecked_into(), + ], + vec![ + hex!["9ed7705e3c7da027ba0583a22a3212042f7e715d3c168ba14f1424e2bc111d00"].into() + ], + 1000.into(), + ) + }, + Vec::new(), + None, + None, + None, + None, + Extensions { relay_chain: "rococo-local".into(), para_id: 1000 }, + rococo_parachain_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) +} + +pub(crate) fn testnet_genesis( + root_key: AccountId, + initial_authorities: Vec, + endowed_accounts: Vec, + id: ParaId, +) -> rococo_parachain_runtime::RuntimeGenesisConfig { + rococo_parachain_runtime::RuntimeGenesisConfig { + system: rococo_parachain_runtime::SystemConfig::default(), + balances: rococo_parachain_runtime::BalancesConfig { + balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), + }, + sudo: rococo_parachain_runtime::SudoConfig { key: Some(root_key) }, + parachain_info: rococo_parachain_runtime::ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + aura: rococo_parachain_runtime::AuraConfig { authorities: initial_authorities }, + aura_ext: Default::default(), + parachain_system: Default::default(), + polkadot_xcm: rococo_parachain_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + } +} diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/seedling.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/seedling.rs new file mode 100644 index 000000000000..652ebb4050b7 --- /dev/null +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/seedling.rs @@ -0,0 +1,62 @@ +// Copyright 2019-2021 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus 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. + +// Cumulus 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 Cumulus. If not, see . + +use crate::chain_spec::{get_account_id_from_seed, Extensions}; +use cumulus_primitives_core::ParaId; +use parachains_common::AccountId; +use sc_service::ChainType; +use sp_core::sr25519; + +/// Specialized `ChainSpec` for the seedling parachain runtime. +pub type SeedlingChainSpec = + sc_service::GenericChainSpec; + +pub fn get_seedling_chain_spec() -> SeedlingChainSpec { + #[allow(deprecated)] + SeedlingChainSpec::from_genesis( + "Seedling Local Testnet", + "seedling_local_testnet", + ChainType::Local, + move || { + seedling_testnet_genesis( + get_account_id_from_seed::("Alice"), + 2000.into(), + ) + }, + Vec::new(), + None, + None, + None, + None, + Extensions { relay_chain: "westend".into(), para_id: 2000 }, + seedling_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) +} + +fn seedling_testnet_genesis( + root_key: AccountId, + parachain_id: ParaId, +) -> seedling_runtime::RuntimeGenesisConfig { + seedling_runtime::RuntimeGenesisConfig { + system: seedling_runtime::SystemConfig::default(), + sudo: seedling_runtime::SudoConfig { key: Some(root_key) }, + parachain_info: seedling_runtime::ParachainInfoConfig { + parachain_id, + ..Default::default() + }, + parachain_system: Default::default(), + } +} diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/shell.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/shell.rs new file mode 100644 index 000000000000..45a665c9f8b2 --- /dev/null +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/shell.rs @@ -0,0 +1,48 @@ +// Copyright 2019-2021 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus 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. + +// Cumulus 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 Cumulus. If not, see . + +use crate::chain_spec::Extensions; +use cumulus_primitives_core::ParaId; +use sc_service::ChainType; + +/// Specialized `ChainSpec` for the shell parachain runtime. +pub type ShellChainSpec = + sc_service::GenericChainSpec; + +pub fn get_shell_chain_spec() -> ShellChainSpec { + #[allow(deprecated)] + ShellChainSpec::from_genesis( + "Shell Local Testnet", + "shell_local_testnet", + ChainType::Local, + move || shell_testnet_genesis(1000.into()), + Vec::new(), + None, + None, + None, + None, + Extensions { relay_chain: "westend".into(), para_id: 1000 }, + shell_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) +} + +fn shell_testnet_genesis(parachain_id: ParaId) -> shell_runtime::RuntimeGenesisConfig { + shell_runtime::RuntimeGenesisConfig { + system: shell_runtime::SystemConfig::default(), + parachain_info: shell_runtime::ParachainInfoConfig { parachain_id, ..Default::default() }, + parachain_system: Default::default(), + } +} diff --git a/cumulus/polkadot-parachain/src/main.rs b/cumulus/polkadot-parachain/src/main.rs index d114d2f5f2c8..0f9ab398510e 100644 --- a/cumulus/polkadot-parachain/src/main.rs +++ b/cumulus/polkadot-parachain/src/main.rs @@ -26,6 +26,11 @@ mod cli; mod command; mod rpc; +#[cfg(test)] +// Tests for verifying if raw ChainSpecs generated using legacy RuntimeGenesisConfig based approach +// are identical to ChainSpec generated using JSON approach. +mod legacy_chain_spec; + fn main() -> sc_cli::Result<()> { command::run() } diff --git a/cumulus/test/service/src/chain_spec.rs b/cumulus/test/service/src/chain_spec.rs index 3d72d0db3ab5..156e06f79452 100644 --- a/cumulus/test/service/src/chain_spec.rs +++ b/cumulus/test/service/src/chain_spec.rs @@ -86,6 +86,7 @@ pub fn get_chain_spec_with_extra_endowed( id: ParaId, extra_endowed_accounts: Vec, ) -> ChainSpec { + #[allow(deprecated)] ChainSpec::from_genesis( "Local Testnet", "local_testnet", @@ -102,6 +103,7 @@ pub fn get_chain_spec_with_extra_endowed( None, None, Extensions { para_id: id.into() }, + cumulus_test_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), ) } @@ -139,12 +141,7 @@ pub fn testnet_genesis( endowed_accounts: Vec, ) -> cumulus_test_runtime::RuntimeGenesisConfig { cumulus_test_runtime::RuntimeGenesisConfig { - system: cumulus_test_runtime::SystemConfig { - code: cumulus_test_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, + system: cumulus_test_runtime::SystemConfig::default(), glutton: Default::default(), parachain_system: Default::default(), balances: cumulus_test_runtime::BalancesConfig { From a2d2152738d7a87df75419cd67fa6536bae33ae9 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 29 Aug 2023 13:37:59 +0200 Subject: [PATCH 04/98] Cargo.lock updated --- Cargo.lock | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index c755be63042b..fdc98a0f83cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -779,6 +779,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -875,6 +876,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -976,6 +978,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-offchain", @@ -1874,6 +1877,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-offchain", @@ -1937,6 +1941,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-offchain", @@ -2043,6 +2048,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keyring", @@ -2356,12 +2362,16 @@ version = "2.0.0" dependencies = [ "ansi_term", "clap 4.4.0", + "kitchensink-runtime", + "log", "node-cli", "rand 0.8.5", "sc-chain-spec", "sc-keystore", + "serde_json", "sp-core", "sp-keystore", + "sp-tracing", ] [[package]] @@ -2663,6 +2673,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-offchain", @@ -2872,6 +2883,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -5884,6 +5896,7 @@ dependencies = [ "sp-api", "sp-block-builder", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -6471,7 +6484,9 @@ dependencies = [ "polkadot-service", "rococo-runtime", "rococo-runtime-constants", + "sc-chain-spec", "sc-consensus-grandpa", + "serde_json", "sp-authority-discovery", "sp-consensus-babe", "sp-consensus-beefy", @@ -6894,12 +6909,14 @@ dependencies = [ "parity-scale-codec", "primitive-types", "scale-info", + "serde_json", "sp-api", "sp-authority-discovery", "sp-block-builder", "sp-consensus-babe", "sp-consensus-grandpa", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-offchain", @@ -7004,6 +7021,7 @@ dependencies = [ "sp-consensus-babe", "sp-consensus-beefy", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keyring", @@ -8479,6 +8497,7 @@ dependencies = [ "frame-system", "futures", "kitchensink-runtime", + "log", "node-primitives", "node-testing", "pallet-balances", @@ -8597,6 +8616,7 @@ dependencies = [ "sc-telemetry", "sc-transaction-pool", "sc-transaction-pool-api", + "serde_json", "sp-api", "sp-block-builder", "sp-blockchain", @@ -8648,11 +8668,13 @@ dependencies = [ "pallet-transaction-payment-rpc-runtime-api", "parity-scale-codec", "scale-info", + "serde_json", "sp-api", "sp-block-builder", "sp-consensus-aura", "sp-consensus-grandpa", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -11057,6 +11079,7 @@ dependencies = [ "sc-transaction-pool", "sc-transaction-pool-api", "serde", + "serde_json", "sp-api", "sp-block-builder", "sp-blockchain", @@ -11114,6 +11137,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -11440,6 +11464,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -12818,6 +12843,7 @@ dependencies = [ "sp-consensus-babe", "sp-consensus-beefy", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keyring", @@ -13249,6 +13275,7 @@ dependencies = [ "sp-consensus-babe", "sp-consensus-beefy", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keyring", @@ -14262,6 +14289,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -14347,6 +14375,7 @@ dependencies = [ "sp-consensus-babe", "sp-consensus-beefy", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keyring", @@ -14765,18 +14794,29 @@ dependencies = [ name = "sc-chain-spec" version = "4.0.0-dev" dependencies = [ + "array-bytes", + "json-patch", + "log", "memmap2", + "parity-scale-codec", "sc-chain-spec-derive", "sc-client-api", "sc-executor", + "sc-executor-common", "sc-network", "sc-telemetry", "serde", "serde_json", + "sp-application-crypto", "sp-blockchain", + "sp-consensus-babe", "sp-core", + "sp-genesis-builder", + "sp-io", + "sp-keyring", "sp-runtime", "sp-state-machine", + "substrate-test-runtime", ] [[package]] @@ -16287,6 +16327,7 @@ dependencies = [ "sp-api", "sp-block-builder", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -16530,6 +16571,7 @@ dependencies = [ "sp-api", "sp-block-builder", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -20422,6 +20464,7 @@ dependencies = [ "sp-consensus-babe", "sp-consensus-beefy", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keyring", From b2bdc5541beede2fc16a6a74f834d19d8b1b550a Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 29 Aug 2023 15:39:37 +0200 Subject: [PATCH 05/98] fixing some missed rebase-relating issues --- .../src/chain_spec/legacy_chain_spec.rs | 355 ++++++++++-------- 1 file changed, 193 insertions(+), 162 deletions(-) diff --git a/polkadot/node/service/src/chain_spec/legacy_chain_spec.rs b/polkadot/node/service/src/chain_spec/legacy_chain_spec.rs index 41b8a917bf8d..6afdc376214a 100644 --- a/polkadot/node/service/src/chain_spec/legacy_chain_spec.rs +++ b/polkadot/node/service/src/chain_spec/legacy_chain_spec.rs @@ -179,8 +179,7 @@ fn default_parachains_host_configuration( max_pov_size: MAX_POV_SIZE, max_head_data_size: 32 * 1024, group_rotation_frequency: 20, - chain_availability_period: 4, - thread_availability_period: 4, + paras_availability_period: 4, max_upward_queue_count: 8, max_upward_queue_size: 1024 * 1024, max_downward_message_size: 1024 * 1024, @@ -191,10 +190,8 @@ fn default_parachains_host_configuration( hrmp_channel_max_capacity: 8, hrmp_channel_max_total_size: 8 * 1024, hrmp_max_parachain_inbound_channels: 4, - hrmp_max_parathread_inbound_channels: 4, hrmp_channel_max_message_size: 1024 * 1024, hrmp_max_parachain_outbound_channels: 4, - hrmp_max_parathread_outbound_channels: 4, hrmp_max_message_num_per_candidate: 5, dispute_period: 6, no_show_slots: 2, @@ -245,6 +242,7 @@ fn kusama_session_keys( para_validator: ValidatorId, para_assignment: AssignmentId, authority_discovery: AuthorityDiscoveryId, + beefy: BeefyId, ) -> kusama::SessionKeys { kusama::SessionKeys { babe, @@ -253,6 +251,7 @@ fn kusama_session_keys( para_validator, para_assignment, authority_discovery, + beefy, } } @@ -264,6 +263,7 @@ fn westend_session_keys( para_validator: ValidatorId, para_assignment: AssignmentId, authority_discovery: AuthorityDiscoveryId, + beefy: BeefyId, ) -> westend::SessionKeys { westend::SessionKeys { babe, @@ -272,6 +272,7 @@ fn westend_session_keys( para_validator, para_assignment, authority_discovery, + beefy, } } @@ -301,12 +302,16 @@ fn westend_staging_testnet_config_genesis() -> westend::RuntimeGenesisConfig { use hex_literal::hex; use sp_core::crypto::UncheckedInto; - // subkey inspect "$SECRET" + // Following keys are used in genesis config for development chains. + // DO NOT use them in production chains as the secret seed is public. + // + // SECRET_SEED="slow awkward present example safe bundle science ocean cradle word tennis earn" + // subkey inspect -n polkadot "$SECRET_SEED" let endowed_accounts = vec![ - // 5DaVh5WRfazkGaKhx1jUu6hjz7EmRe4dtW6PKeVLim84KLe8 - hex!["42f4a4b3e0a89c835ee696205caa90dd85c8ea1d7364b646328ee919a6b2fc1e"].into(), + // 15S75FkhCWEowEGfxWwVfrW3LQuy8w8PNhVmrzfsVhCMjUh1 + hex!["c416837e232d9603e83162ef4bda08e61580eeefe60fe92fc044aa508559ae42"].into(), ]; - // SECRET='...' ./scripts/prepare-test-net.sh 4 + // SECRET=$SECRET_SEED ./scripts/prepare-test-net.sh 4 let initial_authorities: Vec<( AccountId, AccountId, @@ -316,101 +321,114 @@ fn westend_staging_testnet_config_genesis() -> westend::RuntimeGenesisConfig { ValidatorId, AssignmentId, AuthorityDiscoveryId, + BeefyId, )> = vec![ ( - //5ERCqy118nnXDai8g4t3MjdX7ZC5PrQzQpe9vwex5cELWqbt - hex!["681af4f93073484e1acd6b27395d0d258f1a6b158c808846c8fd05ee2435056e"].into(), - //5GTS114cfQNBgpQULhMaNCPXGds6NokegCnikxDe1vqANhtn - hex!["c2463372598ebabd21ee5bc33e1d7e77f391d2df29ce2fbe6bed0d13be629a45"].into(), - //5FhGbceKeH7fuGogcBwd28ZCkAwDGYBADCTeHiYrvx2ztyRd - hex!["a097bfc6a33499ed843b711f52f523f8a7174f798a9f98620e52f4170dbe2948"] + //5EvydUTtHvt39Khac3mMxNPgzcfu49uPDzUs3TL7KEzyrwbw + hex!["7ecfd50629cdd246649959d88d490b31508db511487e111a52a392e6e458f518"].into(), + //5HQyX5gyy77m9QLXguAhiwjTArHYjYspeY98dYDu1JDetfZg + hex!["eca2cca09bdc66a7e6d8c3d9499a0be2ad4690061be8a9834972e17d13d2fe7e"].into(), + //5G13qYRudTyttwTJvHvnwp8StFtcfigyPnwfD4v7LNopsnX4 + hex!["ae27367cb77850fb195fe1f9c60b73210409e68c5ad953088070f7d8513d464c"] .unchecked_into(), - //5Es7nDkJt2by5qVCCD7PZJdp76KJw1LdRCiNst5S5f4eecnz - hex!["7bde49dda82c2c9f082b807ef3ceebff96437d67b3e630c584db7a220ecafacf"] + //5Eb7wM65PNgtY6e33FEAzYtU5cRTXt6WQvZTnzaKQwkVcABk + hex!["6faae44b21c6f2681a7f60df708e9f79d340f7d441d28bd987fab8d05c6487e8"] .unchecked_into(), - //5D4e8zRjaYzFamqChGPPtu26PcKbKgUrhb7WqcNbKa2RDFUR - hex!["2c2fb730a7d9138e6d62fcf516f9ecc2d712af3f2f03ca330c9564b8c0c1bb33"] + //5CdS2wGo4qdTQceVfEnbZH8vULeBrnGYCxSCxDna4tQSMV6y + hex!["18f5d55f138bfa8e0ea26ed6fa56817b247de3c2e2030a908c63fb37c146473f"] .unchecked_into(), - //5DD3JY5ENkjcgVFbVSgUbZv7WmrnyJ8bxxu56ee6hZFiRdnh - hex!["3297a8622988cc23dd9c131e3fb8746d49e007f6e58a81d43420cd539e250e4c"] + //5FqMLAgygdX9UqzukDp15Uid9PAKdFAR621U7xtp5ut2NfrW + hex!["a6c1a5b501985a83cb1c37630c5b41e6b0a15b3675b2fd94694758e6cfa6794d"] .unchecked_into(), - //5Gpodowhud8FG9xENXR5YwTFbUAWyoEtw7sYFytFsG4z7SU6 - hex!["d2932edf775088bd088dc5a112ad867c24cc95858f77f8a1ab014de8d4f96a3f"] + //5DhXAV75BKvF9o447ikWqLttyL2wHtLMFSX7GrsKF9Ny61Ta + hex!["485051748ab9c15732f19f3fbcf1fd00a6d9709635f084505107fbb059c33d2f"] .unchecked_into(), - //5GUMj8tnjL3PJZgXoiWtgLCaMVNHBNeSeTqDsvcxmaVAjKn9 - hex!["c2fb0f74591a00555a292bc4882d3158bafc4c632124cb60681f164ef81bcf72"] + //5GNHfmrtWLTawnGCmc39rjAEiW97vKvE7DGePYe4am5JtE4i + hex!["be59ed75a72f7b47221ce081ba4262cf2e1ea7867e30e0b3781822f942b97677"] + .unchecked_into(), + //5DA6Z8RUF626stn94aTRBCeobDCYcFbU7Pdk4Tz1R9vA8B8F + hex!["0207e43990799e1d02b0507451e342a1240ff836ea769c57297589a5fd072ad8f4"] .unchecked_into(), ), ( - //5HgDCznTkHKUjzPkQoTZGWbvbyqB7sqHDBPDKdF1FyVYM7Er - hex!["f8418f189f84814fd40cc1b2e90873e72ea789487f3b98ed42811ba76d10fc37"].into(), - //5GQTryeFwuvgmZ2tH5ZeAKZHRM9ch5WGVGo6ND9P8f9uMsNY - hex!["c002bb4af4a1bd2f33d104aef8a41878fe1ac94ba007029c4dfdefa8b698d043"].into(), - //5C7YkWSVH1zrpsE5KwW1ua1qatyphzYxiZrL24mjkxz7mUbn - hex!["022b14fbcf65a93b81f453105b9892c3fc4aa74c22c53b4abab019e1d58fbd41"] + //5DFpvDUdCgw54E3E357GR1PyJe3Ft9s7Qyp7wbELAoJH9RQa + hex!["34b7b3efd35fcc3c1926ca065381682b1af29b57dabbcd091042c6de1d541b7d"].into(), + //5DZSSsND5wCjngvyXv27qvF3yPzt3MCU8rWnqNy4imqZmjT8 + hex!["4226796fa792ac78875e023ff2e30e3c2cf79f0b7b3431254cd0f14a3007bc0e"].into(), + //5CPrgfRNDQvQSnLRdeCphP3ibj5PJW9ESbqj2fw29vBMNQNn + hex!["0e9b60f04be3bffe362eb2212ea99d2b909b052f4bff7c714e13c2416a797f5d"] + .unchecked_into(), + //5FXFsPReTUEYPRNKhbTdUathcWBsxTNsLbk2mTpYdKCJewjA + hex!["98f4d81cb383898c2c3d54dab28698c0f717c81b509cb32dc6905af3cc697b18"] .unchecked_into(), - //5GwFC6Tmg4fhj4PxSqHycgJxi3PDfnC9RGDsNHoRwAvXvpnZ - hex!["d77cafd3b32c8b52b0e2780a586a6e527c94f1bdec117c4e4acb0a491461ffa3"] + //5CDYSCJK91r8y2r1V4Ddrit4PFMEkwZXJe8mNBqGXJ4xWCWq + hex!["06bd7dd4ab4c808c7d09d9cb6bd27fbcd99ad8400e99212b335056c475c24031"] .unchecked_into(), - //5DSVrGURuDuh8Luzo8FYq7o2NWiUSLSN6QAVNrj9BtswWH6R - hex!["3cdb36a5a14715999faffd06c5b9e5dcdc24d4b46bc3e4df1aaad266112a7b49"] + //5CZjurB78XbSHf6SLkLhCdkqw52Zm7aBYUDdfkLqEDWJ9Zhj + hex!["162508accd470e379b04cb0c7c60b35a7d5357e84407a89ed2dd48db4b726960"] .unchecked_into(), - //5DLEG2AupawCXGwhJtrzBRc3zAhuP8V662dDrUTzAsCiB9Ec - hex!["38134245c9919ecb20bf2eedbe943b69ba92ceb9eb5477b92b0afd3cb6ce2858"] + //5DkAqCtSjUMVoJFauuGoAbSEgn2aFCRGziKJiLGpPwYgE1pS + hex!["4a559c028b69a7f784ce553393e547bec0aa530352157603396d515f9c83463b"] .unchecked_into(), - //5D83o9fDgnHxaKPkSx59hk8zYzqcgzN2mrf7cp8fiVEi7V4E - hex!["2ec917690dc1d676002e3504c530b2595490aa5a4603d9cc579b9485b8d0d854"] + //5GsBt9MhGwkg8Jfb1F9LAy2kcr88WNyNy4L5ezwbCr8NWKQU + hex!["d464908266c878acbf181bf8fda398b3aa3fd2d05508013e414aaece4cf0d702"] .unchecked_into(), - //5DwBJquZgncRWXFxj2ydbF8LBUPPUbiq86sXWXgm8Z38m8L2 - hex!["52bae9b8dedb8058dda93ec6f57d7e5a517c4c9f002a4636fada70fed0acf376"] + //5DtJVkz8AHevEnpszy3X4dUcPvACW6x1qBMQZtFxjexLr5bq + hex!["02fdf30222d2cb88f2376d558d3de9cb83f9fde3aa4b2dd40c93e3104e3488bcd2"] .unchecked_into(), ), ( - //5DMHpkRpQV7NWJFfn2zQxCLiAKv7R12PWFRPHKKk5X3JkYfP - hex!["38e280b35d08db46019a210a944e4b7177665232ab679df12d6a8bbb317a2276"].into(), - //5FbJpSHmFDe5FN3DVGe1R345ZePL9nhcC9V2Cczxo7q8q6rN - hex!["9c0bc0e2469924d718ae683737f818a47c46b0612376ecca06a2ac059fe1f870"].into(), - //5E5Pm3Udzxy26KGkLE5pc8JPfQrvkYHiaXWtuEfmQsBSgep9 - hex!["58fecadc2df8182a27e999e7e1fd7c99f8ec18f2a81f9a0db38b3653613f3f4d"] + //5E2cob2jrXsBkTih56pizwSqENjE4siaVdXhaD6akLdDyVq7 + hex!["56e0f73c563d49ee4a3971c393e17c44eaa313dabad7fcf297dc3271d803f303"].into(), + //5D4rNYgP9uFNi5GMyDEXTfiaFLjXyDEEX2VvuqBVi3f1qgCh + hex!["2c58e5e1d5aef77774480cead4f6876b1a1a6261170166995184d7f86140572b"].into(), + //5Ea2D65KXqe625sz4uV1jjhSfuigVnkezC8VgEj9LXN7ERAk + hex!["6ed45cb7af613be5d88a2622921e18d147225165f24538af03b93f2a03ce6e13"] + .unchecked_into(), + //5G4kCbgqUhEyrRHCyFwFEkgBZXoYA8sbgsRxT9rY8Tp5Jj5F + hex!["b0f8d2b9e4e1eafd4dab6358e0b9d5380d78af27c094e69ae9d6d30ca300fd86"] .unchecked_into(), - //5FxcystSLHtaWoy2HEgRNerj9PrUs452B6AvHVnQZm5ZQmqE - hex!["ac4d0c5e8f8486de05135c10a707f58aa29126d5eb28fdaaba00f9a505f5249d"] + //5HVhFBLFTKSZK9fX6RktckWDTgYNoSd33fgonsEC8zfr4ddm + hex!["f03c3e184b2883eec9beaeb97f54321587e7476b228831ea0b5fc6da847ea975"] .unchecked_into(), - //5E7KqVXaVGuAqiqMigpuH8oXHLVh4tmijmpJABLYANpjMkem - hex!["5a781385a0235fe8594dd101ec55ef9ba01883f8563a0cdd37b89e0303f6a578"] + //5CS7thd2n54WfqeKU3cjvZzK4z5p7zku1Zw97mSzXgPioAAs + hex!["1055100a283968271a0781450b389b9093231be809be1e48a305ebad2a90497e"] .unchecked_into(), - //5H9AybjkpyZ79yN5nHuBqs6RKuZPgM7aAVVvTQsDFovgXb2A - hex!["e09570f62a062450d4406b4eb43e7f775ff954e37606646cd590d1818189501f"] + //5DSaL4ZmSYarZSazhL5NQh7LT6pWhNRDcefk2QS9RxEXfsJe + hex!["3cea4ab74bab4adf176cf05a6e18c1599a7bc217d4c6c217275bfbe3b037a527"] .unchecked_into(), - //5Ccgs7VwJKBawMbwMENDmj2eFAxhFdGksVHdk8aTAf4w7xox - hex!["1864832dae34df30846d5cc65973f58a2d01b337d094b1284ec3466ecc90251d"] + //5CaNLkYEbFYXZodXhd3UjV6RNLjFGNLiYafc8X5NooMkZiAq + hex!["169faa81aebfe74533518bda28567f2e2664014c8905aa07ea003336afda5a58"] .unchecked_into(), - //5EsSaZZ7niJs7hmAtp4QeK19AcAuTp7WXB7N7gRipVooerq4 - hex!["7c1d92535e6d94e21cffea6633a855a7e3c9684cd2f209e5ddbdeaf5111e395b"] + //5ERwhKiePayukzZStMuzGzRJGxGRFpwxYUXVarQpMSMrXzDS + hex!["03429d0d20f6ac5ca8b349f04d014f7b5b864acf382a744104d5d9a51108156c0f"] .unchecked_into(), ), ( - //5Ea11qhmGRntQ7pyEkEydbwxvfrYwGMKW6rPERU4UiSBB6rd - hex!["6ed057d2c833c45629de2f14b9f6ce6df1edbf9421b7a638e1fb4828c2bd2651"].into(), - //5CZomCZwPB78BZMZsCiy7WSpkpHhdrN8QTSyjcK3FFEZHBor - hex!["1631ff446b3534d031adfc37b7f7aed26d2a6b3938d10496aab3345c54707429"].into(), - //5CSM6vppouFHzAVPkVFWN76DPRUG7B9qwJe892ccfSfJ8M5f - hex!["108188c43a7521e1abe737b343341c2179a3a89626c7b017c09a5b10df6f1c42"] + //5H6j9ovzYk9opckVjvM9SvVfaK37ASTtPTzWeRfqk1tgLJUN + hex!["deb804ed2ed2bb696a3dd4ed7de4cd5c496528a2b204051c6ace385bacd66a3a"].into(), + //5DJ51tMW916mGwjMpfS1o9skcNt6Sb28YnZQXaKVg4h89agE + hex!["366da6a748afedb31f07902f2de36ab265beccee37762d3ae1f237de234d9c36"].into(), + //5CSPYDYoCDGSoSLgSp4EHkJ52YasZLHG2woqhPZkdbtNQpke + hex!["1089bc0cd60237d061872925e81d36c9d9205d250d5d8b542c8e08a8ecf1b911"] .unchecked_into(), - //5GwkG4std9KcjYi3ThSC7QWfhqokmYVvWEqTU9h7iswjhLnr - hex!["d7de8a43f7ee49fa3b3aaf32fb12617ec9ff7b246a46ab14e9c9d259261117fa"] + //5ChfdrAqmLjCeDJvynbMjcxYLHYzPe8UWXd3HnX9JDThUMbn + hex!["1c309a70b4e274314b84c9a0a1f973c9c4fc084df5479ef686c54b1ae4950424"] .unchecked_into(), - //5CoUk3wrCGJAWbiJEcsVjYhnd2JAHvR59jBRbSw77YrBtRL1 - hex!["209f680bc501f9b59358efe3636c51fd61238a8659bac146db909aea2595284b"] + //5DnsMm24575xK2b2aGfmafiDxwCet6Mr4iiZQeDdWvi8CzuF + hex!["4c64868ba6d8ace235d3efb4c10d745a67cf3bdfeae23b264d7ea2f3439dec42"] .unchecked_into(), - //5EcSu96wprFM7G2HfJTjYu8kMParnYGznSUNTsoEKXywEsgG - hex!["70adf80395b3f59e4cab5d9da66d5a286a0b6e138652a06f72542e46912df922"] + //5D8C3HHEp5E8fJsXRD56494F413CdRSR9QKGXe7v5ZEfymdj + hex!["2ee4d78f328db178c54f205ac809da12e291a33bcbd4f29f081ce7e74bdc5044"] .unchecked_into(), - //5Ge3sjpD43Cuy7rNoJQmE9WctgCn6Faw89Pe7xPs3i55eHwJ - hex!["ca5f6b970b373b303f64801a0c2cadc4fc05272c6047a2560a27d0c65589ca1d"] + //5GxeTYCGmp1C3ZRLDkRWqJc6gB2GYmuqnygweuH3vsivMQq6 + hex!["d88e40e3c2c7a7c5abf96ffdd8f7b7bec8798cc277bc97e255881871ab73b529"] .unchecked_into(), - //5EFcjHLvB2z5vd5g63n4gABmhzP5iPsKvTwd8sjfvTehNNrk - hex!["60cae7fa5a079d9fc8061d715fbcc35ef57c3b00005694c2badce22dcc5a9f1b"] + //5DoGpsgSLcJsHa9B8V4PKjxegWAqDZttWfxicAd68prUX654 + hex!["4cb3863271b70daa38612acd5dae4f5afcb7c165fa277629e5150d2214df322a"] + .unchecked_into(), + //5G1KLjqFyMsPAodnjSRkwRFJztTTEzmZWxow2Q3ZSRCPdthM + hex!["03be5ec86d10a94db89c9b7a396d3c7742e3bec5f85159d4cf308cef505966ddf5"] .unchecked_into(), ), ]; @@ -427,6 +445,7 @@ fn westend_staging_testnet_config_genesis() -> westend::RuntimeGenesisConfig { .chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH))) .collect(), }, + beefy: Default::default(), indices: westend::IndicesConfig { indices: vec![] }, session: westend::SessionConfig { keys: initial_authorities @@ -442,6 +461,7 @@ fn westend_staging_testnet_config_genesis() -> westend::RuntimeGenesisConfig { x.5.clone(), x.6.clone(), x.7.clone(), + x.8.clone(), ), ) }) @@ -483,6 +503,7 @@ fn westend_staging_testnet_config_genesis() -> westend::RuntimeGenesisConfig { }, xcm_pallet: Default::default(), nomination_pools: Default::default(), + assigned_slots: Default::default(), } } @@ -491,17 +512,17 @@ fn kusama_staging_testnet_config_genesis() -> kusama::RuntimeGenesisConfig { use hex_literal::hex; use sp_core::crypto::UncheckedInto; - // subkey inspect "$SECRET" + // Following keys are used in genesis config for development chains. + // DO NOT use them in production chains as the secret seed is public. + // + // SECRET_SEED="explain impose opinion genius bar parrot erupt panther surround best expire + // album" subkey inspect -n kusama "$SECRET_SEED" let endowed_accounts = vec![ - // 5CVFESwfkk7NmhQ6FwHCM9roBvr9BGa4vJHFYU8DnGQxrXvz - hex!["12b782529c22032ed4694e0f6e7d486be7daa6d12088f6bc74d593b3900b8438"].into(), + // FLN5cfhF7VCGJYefjPQJR2V6WwbfRmb9ozTwLAzBNeQQG6y + hex!["7a0fe424217ed176da7abf12e08198db0d0949298e1372c80a1930cb6dc21d3e"].into(), ]; - // for i in 1 2 3 4; do for j in stash controller; do subkey inspect "$SECRET//$i//$j"; done; done - // for i in 1 2 3 4; do for j in babe; do subkey --sr25519 inspect "$SECRET//$i//$j"; done; done - // for i in 1 2 3 4; do for j in grandpa; do subkey --ed25519 inspect "$SECRET//$i//$j"; done; done - // for i in 1 2 3 4; do for j in im_online; do subkey --sr25519 inspect "$SECRET//$i//$j"; done; done - // for i in 1 2 3 4; do for j in para_validator para_assignment; do subkey --sr25519 inspect "$SECRET//$i//$j"; done; done + // SECRET=$SECRET_SEED ./scripts/prepare-test-net.sh 4 let initial_authorities: Vec<( AccountId, AccountId, @@ -511,101 +532,114 @@ fn kusama_staging_testnet_config_genesis() -> kusama::RuntimeGenesisConfig { ValidatorId, AssignmentId, AuthorityDiscoveryId, + BeefyId, )> = vec![ ( - // 5DD7Q4VEfPTLEdn11CnThoHT5f9xKCrnofWJL5SsvpTghaAT - hex!["32a5718e87d16071756d4b1370c411bbbb947eb62f0e6e0b937d5cbfc0ea633b"].into(), - // 5GNzaEqhrZAtUQhbMe2gn9jBuNWfamWFZHULryFwBUXyd1cG - hex!["bee39fe862c85c91aaf343e130d30b643c6ea0b4406a980206f1df8331f7093b"].into(), - // 5FpewyS2VY8Cj3tKgSckq8ECkjd1HKHvBRnWhiHqRQsWfFC1 - hex!["a639b507ee1585e0b6498ff141d6153960794523226866d1b44eba3f25f36356"] + //5D5EsvSJf3KR3WHeZNG8rETdW6homig1cGHezspFt1P4o7sL + hex!["2ca4a9582244a3356a0d96e59d71f7e4d12aa88bca6d46f360ef11f6487cab1f"].into(), + //5Ev6RixvmK62UQE2PW19MPdLsYT4Nomwj85HKPdbnRECbDYh + hex!["7e237806f642b7f45f70ec45fbc41034516c8e5561bae2a62cd287129e1d0712"].into(), + //5GbjzK1uYVo6v1SaYhTeK3dbYy2GN9X4K5iwRkHEQ9eLS3We + hex!["c89cb7afc47ec0b5aac5824e5338a62959c92978167d3f841491836746e70b3d"] .unchecked_into(), - // 5EjvdwATjyFFikdZibVvx1q5uBHhphS2Mnsq5c7yfaYK25vm - hex!["76620f7c98bce8619979c2b58cf2b0aff71824126d2b039358729dad993223db"] + //5GFz3YFW8QzEUsWhRjJzvDP7e5X5tPf5U12vUw32R8oJVgqb + hex!["b98b200021a608148f9817aeb553596b6968a5aa61b6d320c522f520ecc9cf9c"] .unchecked_into(), - // 5FpewyS2VY8Cj3tKgSckq8ECkjd1HKHvBRnWhiHqRQsWfFC1 - hex!["a639b507ee1585e0b6498ff141d6153960794523226866d1b44eba3f25f36356"] + //5GzaFD8YsqnP5FYe5ijA9M4LQvzU9TPJmnBGdpuoqEvR1gQC + hex!["da0690438c0dd7a9aa26e03c9f1deaa58ba2b88d0bec0954b06478632164a401"] .unchecked_into(), - // 5FpewyS2VY8Cj3tKgSckq8ECkjd1HKHvBRnWhiHqRQsWfFC1 - hex!["a639b507ee1585e0b6498ff141d6153960794523226866d1b44eba3f25f36356"] + //5CkZPtNy61PtbJpLqnjNFmbi1qukGkFdqFr5GKduSEthJ1cd + hex!["1e6554d35f6f17a37176c71801426204d6df400a1869114e4f00564b35d31150"] .unchecked_into(), - // 5FpewyS2VY8Cj3tKgSckq8ECkjd1HKHvBRnWhiHqRQsWfFC1 - hex!["a639b507ee1585e0b6498ff141d6153960794523226866d1b44eba3f25f36356"] + //5CodnwweaYA1zB4QhdP4YVYFWnuZHY6W7zkN1NCRqJ9wZhap + hex!["20bddf09b1d0a2d93bafeb87fe19eb5bd59950c174f23a141a6d99736a5e700d"] .unchecked_into(), - // 5FpewyS2VY8Cj3tKgSckq8ECkjd1HKHvBRnWhiHqRQsWfFC1 - hex!["a639b507ee1585e0b6498ff141d6153960794523226866d1b44eba3f25f36356"] + //5E7TSvNAP6QeJNeckdvYvADpHsx7v6aHXtGoQv5R2N1V3hEB + hex!["5a91b2546f1aac1c388eb0739c83e42d9972884d74360200ce32b7595bc65a04"] + .unchecked_into(), + //5GsoKeoM2HmjXPsdCua4oPu3Ms1Jgu4HbSnB81Lisa2tBFZp + hex!["02fd1e7e8455ab888ad054bbec7bc19409e6b1a5bb0300feefc6b58e60efae7e85"] .unchecked_into(), ), ( - // 5G9VGb8ESBeS8Ca4or43RfhShzk9y7T5iTmxHk5RJsjZwsRx - hex!["b496c98a405ceab59b9e970e59ef61acd7765a19b704e02ab06c1cdfe171e40f"].into(), - // 5F7V9Y5FcxKXe1aroqvPeRiUmmeQwTFcL3u9rrPXcMuMiCNx - hex!["86d3a7571dd60139d297e55d8238d0c977b2e208c5af088f7f0136b565b0c103"].into(), - // 5GvuM53k1Z4nAB5zXJFgkRSHv4Bqo4BsvgbQWNWkiWZTMwWY - hex!["765e46067adac4d1fe6c783aa2070dfa64a19f84376659e12705d1734b3eae01"] + //5HMtKQuL2GQ7YvLBTh3vqFJEpkZW19sQh2X2mcUzAwBAe885 + hex!["ea478deab0ebfbeab7342febc236a9f1af5129ca0083fa25e6b0cf6a998d8354"].into(), + //5EFD5pLC3w5NFEcmQ6rGw9dUZ6fTSjWJemsvJZuaj7Qmq2WT + hex!["607b4e88129804eca8cd6fa26cbe2dd36667130e2a061050b08d9015871f4263"].into(), + //5DFztsnvC9hN85j5AP116atcnzFhAxnbzPodEp1AsYq1LYXu + hex!["34d949c39fae5801ba328ac6d0ddc76e469b7d5a4372a4a0d94f6aad6f9c1600"] + .unchecked_into(), + //5EZJNJ4j1eEEwCWusg7nYsZxTYBwoTH2drszxRqgMBTgNxMW + hex!["6e47830dcfc1f2b53a1b5db3f76702fc2760c1cc119119aceb00a57ec6658465"] .unchecked_into(), - // 5HBDAaybNqjmY7ww8ZcZZY1L5LHxvpnyfqJwoB7HhR6raTmG - hex!["e2234d661bee4a04c38392c75d1566200aa9e6ae44dd98ee8765e4cc9af63cb7"] + //5Dts3SrgDQMY9XCzKeQrxYSTh5MphPek994qkDCDk5c4neeF + hex!["50f6ef6326cd61ac500f167493e435f1204ce1d66ad18024bc5810d09673785e"] .unchecked_into(), - // 5GvuM53k1Z4nAB5zXJFgkRSHv4Bqo4BsvgbQWNWkiWZTMwWY - hex!["765e46067adac4d1fe6c783aa2070dfa64a19f84376659e12705d1734b3eae01"] + //5DMKT99825TvA8F1yCQvE1ZcKTqg8T8Ad1KEjN6EuVpz4E6w + hex!["38e7fb2f6a1dcec73d93b07a0dc7cff1f9a9cc32cde8eb1e6ea1782f5316b431"] .unchecked_into(), - // 5GvuM53k1Z4nAB5zXJFgkRSHv4Bqo4BsvgbQWNWkiWZTMwWY - hex!["765e46067adac4d1fe6c783aa2070dfa64a19f84376659e12705d1734b3eae01"] + //5EestuSehdMsWsBZ1hXCVo5YQiYiTPJwtV281x5fjUVtaqtP + hex!["72889a7b6ada28c3bd05a5a7298437f01d6d3270559768d16275efaf11864c0a"] .unchecked_into(), - // 5GvuM53k1Z4nAB5zXJFgkRSHv4Bqo4BsvgbQWNWkiWZTMwWY - hex!["765e46067adac4d1fe6c783aa2070dfa64a19f84376659e12705d1734b3eae01"] + //5FNd5EabUbcReXEPwY9aASJMwSqyiic9w1Qt23YxNXj3dzbi + hex!["925f03f6211c68377987b0f78cd02aa882ad1fa9cc00c01fe6ce68e14c23340d"] .unchecked_into(), - // 5GvuM53k1Z4nAB5zXJFgkRSHv4Bqo4BsvgbQWNWkiWZTMwWY - hex!["765e46067adac4d1fe6c783aa2070dfa64a19f84376659e12705d1734b3eae01"] + //5DxhuqfovpooTn8yH7WJGFjYw3pQxSEN9y9kvYUiGguHAj9D + hex!["030e77039e470ccdec7fe23dbc41c66f1c187ec8345e8919d3dc1250d975c3ce82"] .unchecked_into(), ), ( - // 5FzwpgGvk2kk9agow6KsywLYcPzjYc8suKej2bne5G5b9YU3 - hex!["ae12f70078a22882bf5135d134468f77301927aa67c376e8c55b7ff127ace115"].into(), - // 5EqoZhVC2BcsM4WjvZNidu2muKAbu5THQTBKe3EjvxXkdP7A - hex!["7addb914ec8486bbc60643d2647685dcc06373401fa80e09813b630c5831d54b"].into(), - // 5CXNq1mSKJT4Sc2CbyBBdANeSkbUvdWvE4czJjKXfBHi9sX5 - hex!["664eae1ca4713dd6abf8c15e6c041820cda3c60df97dc476c2cbf7cb82cb2d2e"] + //5DAiYTKQ5KxwLncfNoTAH58dXBk2oDcQxtAXyDwMdKGLpGeY + hex!["30d203d942c1d056245b51e466a50b684f172a37c1cdde678f5346a0b3dbcd52"].into(), + //5Dq778qqNiAsjdF4qLVdkSBR8SftJKU35nyeBnkztRgniVhV + hex!["4e194bbafeec45647b2679e6b615b2a879d2e74fe706921930509ab3c9dbb22d"].into(), + //5E6iENoE1tXJUd7PkopQ8uqejg6xhPpqAnsVjS3hAQHWK1tm + hex!["5a0037b6bfc5e879ba5ef480ac29c59a12873854159686899082f41950ffd472"] + .unchecked_into(), + //5F8Dtgoc5dCaLAGYtaDqQUDg91fPQUynd497Fvhor8SYMdXp + hex!["87638aef8ab75db093150a6677c0919292ff66fc17f9f006a71fd0618415e164"] .unchecked_into(), - // 5E8ULLQrDAtWhfnVfZmX41Yux86zNAwVJYguWJZVWrJvdhBe - hex!["5b57ed1443c8967f461db1f6eb2ada24794d163a668f1cf9d9ce3235dfad8799"] + //5EKsYx6Wj1Qg7LLc12U2YRjRUFmHa4Q3rNSoGZaP1ofS54km + hex!["6409c85a1125fa456b9dc6e85408a6d931aa8e04f48511c87fc147d1c103e902"] .unchecked_into(), - // 5CXNq1mSKJT4Sc2CbyBBdANeSkbUvdWvE4czJjKXfBHi9sX5 - hex!["664eae1ca4713dd6abf8c15e6c041820cda3c60df97dc476c2cbf7cb82cb2d2e"] + //5H3UQy1NhCUUq3getmSEG8R1capY7Uy8JtKJz68UABmD9UxS + hex!["dc3cab0f94fa974cba826984f23dd4dc77ade20f25d935af5f07b85518da8044"] .unchecked_into(), - // 5CXNq1mSKJT4Sc2CbyBBdANeSkbUvdWvE4czJjKXfBHi9sX5 - hex!["664eae1ca4713dd6abf8c15e6c041820cda3c60df97dc476c2cbf7cb82cb2d2e"] + //5DstCjokShCt9NppNnAcjg2nS4M5PKY3etn2BoFkZzMhQJ3w + hex!["50379866eb62e5c8aac31133efc4a1723e964a8e30c93c3ce2e7758bd03eb776"] .unchecked_into(), - // 5CXNq1mSKJT4Sc2CbyBBdANeSkbUvdWvE4czJjKXfBHi9sX5 - hex!["664eae1ca4713dd6abf8c15e6c041820cda3c60df97dc476c2cbf7cb82cb2d2e"] + //5E4SCbSqUWKC4NVRCkMkJEnXCaVRiNQbSHL4upRB1ffd1Mk1 + hex!["5843c339c39d2c308bfb1841cd10beecfa157580492db05b66db8553e8d6512c"] .unchecked_into(), - // 5CXNq1mSKJT4Sc2CbyBBdANeSkbUvdWvE4czJjKXfBHi9sX5 - hex!["664eae1ca4713dd6abf8c15e6c041820cda3c60df97dc476c2cbf7cb82cb2d2e"] + //5HNoMQ1PL3m7eBhp24FZxZUBtz4eh3AiwWq8i8jXLCRpJHsu + hex!["03c81d4e72cbdb96a7e6aad76830ae783b0b4650dc19703dde96866d8894dc921f"] .unchecked_into(), ), ( - // 5CFj6Kg9rmVn1vrqpyjau2ztyBzKeVdRKwNPiA3tqhB5HPqq - hex!["0867dbb49721126df589db100dda728dc3b475cbf414dad8f72a1d5e84897252"].into(), - // 5CwQXP6nvWzigFqNhh2jvCaW9zWVzkdveCJY3tz2MhXMjTon - hex!["26ab2b4b2eba2263b1e55ceb48f687bb0018130a88df0712fbdaf6a347d50e2a"].into(), - // 5FCd9Y7RLNyxz5wnCAErfsLbXGG34L2BaZRHzhiJcMUMd5zd - hex!["2adb17a5cafbddc7c3e00ec45b6951a8b12ce2264235b4def342513a767e5d3d"] + //5FNnjg8hXcPVLKASA69bPbooatacxcWNqkQAyXZfFiXi7T8r + hex!["927f8b12a0fa7185077353d9f6b4fe6bc6cd9682bd498642fa3801280909711a"].into(), + //5GipjBdL3rbex9qyxMinZpJYQbobbwk1ctbZp6B2mh3H25c6 + hex!["ce03638cd1e8496793b0540ba23370034511ea5d08837deb17f6c4d905b8d017"].into(), + //5GByn4uRpwmPe4i4MA4PjTQ8HXuycdue8HMWDhZ7vbU4WR9R + hex!["b67d3ed42ab1fcf3fcd7dee99bd6963bc22058ee22bcfddddb776492e85bd76e"] .unchecked_into(), - // 5HGLmrZsiTFTPp3QoS1W8w9NxByt8PVq79reqvdxNcQkByqK - hex!["e60d23f49e93c1c1f2d7c115957df5bbd7faf5ebf138d1e9d02e8b39a1f63df0"] + //5GnZZ1rs7RE1jwPiyw1kts4JqaxnML5SdsWMuHV9TqCcuPWj + hex!["d0dd492b1a33d2f06a9aa7213e1aaa41d8820a6b56e95cd2462129b446574014"] .unchecked_into(), - // 5FCd9Y7RLNyxz5wnCAErfsLbXGG34L2BaZRHzhiJcMUMd5zd - hex!["2adb17a5cafbddc7c3e00ec45b6951a8b12ce2264235b4def342513a767e5d3d"] + //5GKEKSAa3gbitHhvu5gm4f7q942azCVGDNhrw3hnsGPEMzyg + hex!["bc04e9764e23330b9f4e6922aa6437f87f3dd17b8590825e824724ae89d4ac51"] .unchecked_into(), - // 5FCd9Y7RLNyxz5wnCAErfsLbXGG34L2BaZRHzhiJcMUMd5zd - hex!["2adb17a5cafbddc7c3e00ec45b6951a8b12ce2264235b4def342513a767e5d3d"] + //5H6QLnsfU7sAQ5ZACs9bPivsn9CXrqqwxhq4KKyoquZb5mVW + hex!["de78b26966c08357d66f7f56e7dcac7e4beb16aa0b74939290a42b3f5949bc36"] .unchecked_into(), - // 5FCd9Y7RLNyxz5wnCAErfsLbXGG34L2BaZRHzhiJcMUMd5zd - hex!["2adb17a5cafbddc7c3e00ec45b6951a8b12ce2264235b4def342513a767e5d3d"] + //5FUUeYiAvFfXfB5yZLNkis2ZDy9T3CBLBPC6SwXFriGEjH5f + hex!["96d61fe92a50a79944ea93e3afc0a95a328773878e774cf8c8fbe8eba81cd95c"] .unchecked_into(), - // 5FCd9Y7RLNyxz5wnCAErfsLbXGG34L2BaZRHzhiJcMUMd5zd - hex!["2adb17a5cafbddc7c3e00ec45b6951a8b12ce2264235b4def342513a767e5d3d"] + //5DLkWtgJahWG99cMcQxtftW9W14oduySyQi6hdhav7w3BiKq + hex!["38791c68ee472b94105c66cf150387979c49175062a687d1a1509119cfdc9e0c"] + .unchecked_into(), + //5Cjm1c3Jwt5jp6AaN2XfnncgZcswAmyfJn1buHEUaPauXAKK + hex!["025185a88886008267d27797fc74e34241e3aa8da767fafc9dd3ae5a59546802bb"] .unchecked_into(), ), ]; @@ -622,6 +656,7 @@ fn kusama_staging_testnet_config_genesis() -> kusama::RuntimeGenesisConfig { .chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH))) .collect(), }, + beefy: Default::default(), indices: kusama::IndicesConfig { indices: vec![] }, session: kusama::SessionConfig { keys: initial_authorities @@ -637,6 +672,7 @@ fn kusama_staging_testnet_config_genesis() -> kusama::RuntimeGenesisConfig { x.5.clone(), x.6.clone(), x.7.clone(), + x.8.clone(), ), ) }) @@ -988,6 +1024,7 @@ fn rococo_staging_testnet_config_genesis() -> rococo_runtime::RuntimeGenesisConf }, xcm_pallet: Default::default(), nis_counterpart_balances: Default::default(), + assigned_slots: Default::default(), } } @@ -1253,14 +1290,6 @@ pub fn polkadot_testnet_genesis( slash_reward_fraction: Perbill::from_percent(10), ..Default::default() }, - phragmen_election: Default::default(), - democracy: polkadot::DemocracyConfig::default(), - council: polkadot::CouncilConfig { members: vec![], phantom: Default::default() }, - technical_committee: polkadot::TechnicalCommitteeConfig { - members: vec![], - phantom: Default::default(), - }, - technical_membership: Default::default(), babe: polkadot::BabeConfig { authorities: Default::default(), epoch_config: Some(polkadot::BABE_GENESIS_EPOCH_CONFIG), @@ -1297,6 +1326,7 @@ pub fn kusama_testnet_genesis( ValidatorId, AssignmentId, AuthorityDiscoveryId, + BeefyId, )>, _root_key: AccountId, endowed_accounts: Option>, @@ -1312,6 +1342,7 @@ pub fn kusama_testnet_genesis( balances: kusama::BalancesConfig { balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(), }, + beefy: Default::default(), session: kusama::SessionConfig { keys: initial_authorities .iter() @@ -1326,6 +1357,7 @@ pub fn kusama_testnet_genesis( x.5.clone(), x.6.clone(), x.7.clone(), + x.8.clone(), ), ) }) @@ -1380,6 +1412,7 @@ pub fn westend_testnet_genesis( ValidatorId, AssignmentId, AuthorityDiscoveryId, + BeefyId, )>, root_key: AccountId, endowed_accounts: Option>, @@ -1395,6 +1428,7 @@ pub fn westend_testnet_genesis( balances: westend::BalancesConfig { balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(), }, + beefy: Default::default(), session: westend::SessionConfig { keys: initial_authorities .iter() @@ -1409,6 +1443,7 @@ pub fn westend_testnet_genesis( x.5.clone(), x.6.clone(), x.7.clone(), + x.8.clone(), ), ) }) @@ -1450,6 +1485,7 @@ pub fn westend_testnet_genesis( }, xcm_pallet: Default::default(), nomination_pools: Default::default(), + assigned_slots: Default::default(), } } @@ -1538,6 +1574,7 @@ pub fn rococo_testnet_genesis( }, xcm_pallet: Default::default(), nis_counterpart_balances: Default::default(), + assigned_slots: Default::default(), } } @@ -1553,7 +1590,7 @@ fn polkadot_development_config_genesis() -> polkadot::RuntimeGenesisConfig { #[cfg(feature = "kusama-native")] fn kusama_development_config_genesis() -> kusama::RuntimeGenesisConfig { kusama_testnet_genesis( - vec![get_authority_keys_from_seed_no_beefy("Alice")], + vec![get_authority_keys_from_seed("Alice")], get_account_id_from_seed::("Alice"), None, ) @@ -1562,7 +1599,7 @@ fn kusama_development_config_genesis() -> kusama::RuntimeGenesisConfig { #[cfg(feature = "westend-native")] fn westend_development_config_genesis() -> westend::RuntimeGenesisConfig { westend_testnet_genesis( - vec![get_authority_keys_from_seed_no_beefy("Alice")], + vec![get_authority_keys_from_seed("Alice")], get_account_id_from_seed::("Alice"), None, ) @@ -1739,10 +1776,7 @@ pub fn polkadot_local_testnet_config() -> Result { #[cfg(feature = "kusama-native")] fn kusama_local_testnet_genesis() -> kusama::RuntimeGenesisConfig { kusama_testnet_genesis( - vec![ - get_authority_keys_from_seed_no_beefy("Alice"), - get_authority_keys_from_seed_no_beefy("Bob"), - ], + vec![get_authority_keys_from_seed("Alice"),get_authority_keys_from_seed("Bob")], get_account_id_from_seed::("Alice"), None, ) @@ -1770,10 +1804,7 @@ pub fn kusama_local_testnet_config() -> Result { #[cfg(feature = "westend-native")] fn westend_local_testnet_genesis() -> westend::RuntimeGenesisConfig { westend_testnet_genesis( - vec![ - get_authority_keys_from_seed_no_beefy("Alice"), - get_authority_keys_from_seed_no_beefy("Bob"), - ], + vec![get_authority_keys_from_seed("Alice"),get_authority_keys_from_seed("Bob")], get_account_id_from_seed::("Alice"), None, ) From 8f468277d50fdcafdab6ed9330faac0bf8507017 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 29 Aug 2023 15:42:32 +0200 Subject: [PATCH 06/98] fmt --- .../node/service/src/chain_spec/legacy_chain_spec.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/polkadot/node/service/src/chain_spec/legacy_chain_spec.rs b/polkadot/node/service/src/chain_spec/legacy_chain_spec.rs index 6afdc376214a..8eea8a5ad662 100644 --- a/polkadot/node/service/src/chain_spec/legacy_chain_spec.rs +++ b/polkadot/node/service/src/chain_spec/legacy_chain_spec.rs @@ -14,8 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Polkadot. If not, see . -//! RuntimeGenesisConfig-based (legacy) Polkadot chain configurations. Used for testing ChainSpecs against the JSON-based -//! genesis configs. Entire file shall be removed once native runtime is removed. +//! RuntimeGenesisConfig-based (legacy) Polkadot chain configurations. Used for testing ChainSpecs +//! against the JSON-based genesis configs. Entire file shall be removed once native runtime is +//! removed. use beefy_primitives::ecdsa_crypto::AuthorityId as BeefyId; use grandpa::AuthorityId as GrandpaId; @@ -1776,7 +1777,7 @@ pub fn polkadot_local_testnet_config() -> Result { #[cfg(feature = "kusama-native")] fn kusama_local_testnet_genesis() -> kusama::RuntimeGenesisConfig { kusama_testnet_genesis( - vec![get_authority_keys_from_seed("Alice"),get_authority_keys_from_seed("Bob")], + vec![get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob")], get_account_id_from_seed::("Alice"), None, ) @@ -1804,7 +1805,7 @@ pub fn kusama_local_testnet_config() -> Result { #[cfg(feature = "westend-native")] fn westend_local_testnet_genesis() -> westend::RuntimeGenesisConfig { westend_testnet_genesis( - vec![get_authority_keys_from_seed("Alice"),get_authority_keys_from_seed("Bob")], + vec![get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob")], get_account_id_from_seed::("Alice"), None, ) From bf9bbafe1f1c697df25807aa7b29890ead7e4950 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 29 Aug 2023 13:48:41 +0000 Subject: [PATCH 07/98] ".git/.scripts/commands/fmt/fmt.sh" --- cumulus/parachain-template/node/src/chain_spec.rs | 9 +++++---- polkadot/node/service/src/chain_spec.rs | 4 ++-- polkadot/runtime/rococo/build.rs | 3 ++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cumulus/parachain-template/node/src/chain_spec.rs b/cumulus/parachain-template/node/src/chain_spec.rs index 7141f3dd11ba..5edccefe9f3c 100644 --- a/cumulus/parachain-template/node/src/chain_spec.rs +++ b/cumulus/parachain-template/node/src/chain_spec.rs @@ -204,8 +204,9 @@ fn testnet_genesis( } #[cfg(test)] -/// RuntimeGenesisConfig-based (legacy) parachain-template configurations. Used for testing ChainSpecs against the JSON-based -/// genesis configs. Entire file shall be removed once native runtime is removed. +/// RuntimeGenesisConfig-based (legacy) parachain-template configurations. Used for testing +/// ChainSpecs against the JSON-based genesis configs. Entire file shall be removed once native +/// runtime is removed. mod legacy { use super::*; @@ -369,8 +370,8 @@ mod legacy { }) .collect(), }, - // no need to pass anything to aura, in fact it will panic if we do. Session will take care - // of this. + // no need to pass anything to aura, in fact it will panic if we do. Session will take + // care of this. aura: Default::default(), aura_ext: Default::default(), parachain_system: Default::default(), diff --git a/polkadot/node/service/src/chain_spec.rs b/polkadot/node/service/src/chain_spec.rs index 44f8bc3a38df..0ea01be636b6 100644 --- a/polkadot/node/service/src/chain_spec.rs +++ b/polkadot/node/service/src/chain_spec.rs @@ -1812,8 +1812,8 @@ mod json_vs_legacy_tests { assert_eq!(j1, j2); } - // since we changed how EpochDurationInBlocks is handleded (legacy: in state storage vs new: feature-based const), - // and since we have 3 versions of code, we need to do some adjustments. + // since we changed how EpochDurationInBlocks is handleded (legacy: in state storage vs new: + // feature-based const), and since we have 3 versions of code, we need to do some adjustments. fn adjust_rococo_output(input1: String, input2: String) -> (String, String) { let mut json1 = serde_json::from_str::>(&input1).unwrap(); let mut json2 = serde_json::from_str::>(&input2).unwrap(); diff --git a/polkadot/runtime/rococo/build.rs b/polkadot/runtime/rococo/build.rs index f960a21b4200..b28f3266f03e 100644 --- a/polkadot/runtime/rococo/build.rs +++ b/polkadot/runtime/rococo/build.rs @@ -17,7 +17,8 @@ use std::env; use substrate_wasm_builder::WasmBuilder; -// note: needs to be synced with rococo-runtime-constants::time hard-coded string literal in prod_or_fast macro. +// note: needs to be synced with rococo-runtime-constants::time hard-coded string literal in +// prod_or_fast macro. const ROCOCO_EPOCH_DURATION_ENV: &str = "ROCOCO_EPOCH_DURATION"; const ROCOCO_FAST_RUNTIME_ENV: &str = "ROCOCO_FAST_RUNTIME"; From 21a4fa0b437f877ee4e99abe87b071225dcbe55d Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 29 Aug 2023 16:03:03 +0200 Subject: [PATCH 08/98] zepter fmt --- polkadot/runtime/kusama/Cargo.toml | 5 +---- polkadot/runtime/polkadot/Cargo.toml | 5 +---- substrate/bin/node-template/runtime/Cargo.toml | 4 ++-- substrate/bin/node/runtime/Cargo.toml | 4 ++-- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/polkadot/runtime/kusama/Cargo.toml b/polkadot/runtime/kusama/Cargo.toml index 0c99e0055aab..0f392bf6efb7 100644 --- a/polkadot/runtime/kusama/Cargo.toml +++ b/polkadot/runtime/kusama/Cargo.toml @@ -350,10 +350,7 @@ disable-runtime-api = [] # A feature that should be enabled when the runtime should be build 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", - "disable-genesis-builder", -] +on-chain-release-build = [ "disable-genesis-builder", "sp-api/disable-logging" ] # Set timing constants (e.g. session period) to faster versions to speed up testing. fast-runtime = [] diff --git a/polkadot/runtime/polkadot/Cargo.toml b/polkadot/runtime/polkadot/Cargo.toml index c142bda6d14a..fb4049671caa 100644 --- a/polkadot/runtime/polkadot/Cargo.toml +++ b/polkadot/runtime/polkadot/Cargo.toml @@ -319,10 +319,7 @@ disable-runtime-api = [] # A feature that should be enabled when the runtime should be build 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", - "disable-genesis-builder", -] +on-chain-release-build = [ "disable-genesis-builder", "sp-api/disable-logging" ] # Set timing constants (e.g. session period) to faster versions to speed up testing. fast-runtime = [] diff --git a/substrate/bin/node-template/runtime/Cargo.toml b/substrate/bin/node-template/runtime/Cargo.toml index 6fd47b26b89d..b99ae4ef849f 100644 --- a/substrate/bin/node-template/runtime/Cargo.toml +++ b/substrate/bin/node-template/runtime/Cargo.toml @@ -76,11 +76,13 @@ std = [ "pallet-transaction-payment-rpc-runtime-api/std", "pallet-transaction-payment/std", "scale-info/std", + "serde_json/std", "sp-api/std", "sp-block-builder/std", "sp-consensus-aura/std", "sp-consensus-grandpa/std", "sp-core/std", + "sp-genesis-builder/std", "sp-inherents/std", "sp-offchain/std", "sp-runtime/std", @@ -90,8 +92,6 @@ std = [ "sp-transaction-pool/std", "sp-version/std", "substrate-wasm-builder", - "serde_json/std", - "sp-genesis-builder/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", diff --git a/substrate/bin/node/runtime/Cargo.toml b/substrate/bin/node/runtime/Cargo.toml index 756f4e642498..1c45de20f81c 100644 --- a/substrate/bin/node/runtime/Cargo.toml +++ b/substrate/bin/node/runtime/Cargo.toml @@ -227,12 +227,14 @@ std = [ "pallet-vesting/std", "pallet-whitelist/std", "scale-info/std", + "serde_json/std", "sp-api/std", "sp-authority-discovery/std", "sp-block-builder/std", "sp-consensus-babe/std", "sp-consensus-grandpa/std", "sp-core/std", + "sp-genesis-builder/std", "sp-inherents/std", "sp-io/std", "sp-offchain/std", @@ -245,8 +247,6 @@ std = [ "sp-transaction-pool/std", "sp-version/std", "substrate-wasm-builder", - "sp-genesis-builder/std", - "serde_json/std", ] runtime-benchmarks = [ "frame-benchmarking-pallet-pov/runtime-benchmarks", From 141f7cc6821a4e2332f6d8a0d2ad07750d269341 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 29 Aug 2023 17:22:54 +0200 Subject: [PATCH 09/98] cumulus: TestClientBuilder genesis_storage fix --- cumulus/test/client/src/lib.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cumulus/test/client/src/lib.rs b/cumulus/test/client/src/lib.rs index 9660a99c3594..0b21842864dd 100644 --- a/cumulus/test/client/src/lib.rs +++ b/cumulus/test/client/src/lib.rs @@ -82,7 +82,7 @@ pub struct GenesisParameters { impl substrate_test_client::GenesisInit for GenesisParameters { fn genesis_storage(&self) -> Storage { - if self.endowed_accounts.is_empty() { + let mut storage = if self.endowed_accounts.is_empty() { genesis_config().build_storage().unwrap() } else { cumulus_test_service::testnet_genesis( @@ -91,7 +91,16 @@ impl substrate_test_client::GenesisInit for GenesisParameters { ) .build_storage() .unwrap() - } + }; + + storage.top.insert( + sp_core::storage::well_known_keys::CODE.to_vec(), + cumulus_test_runtime::WASM_BINARY + .expect("cumulus_test_runtime WASM binary was not built, please build it!") + .into(), + ); + + storage } } From e499a0b1b7d50f2528cd675555a94687e7a77ce1 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 30 Aug 2023 15:29:04 +0200 Subject: [PATCH 10/98] polkadot: parachains::HostConfiguration fix --- polkadot/node/test/service/src/chain_spec.rs | 23 ++++++++++--------- .../runtime/parachains/src/configuration.rs | 1 + 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/polkadot/node/test/service/src/chain_spec.rs b/polkadot/node/test/service/src/chain_spec.rs index d199581bcc46..0dd06822c41c 100644 --- a/polkadot/node/test/service/src/chain_spec.rs +++ b/polkadot/node/test/service/src/chain_spec.rs @@ -151,17 +151,18 @@ fn polkadot_testnet_genesis( }, "sudo": { "key": Some(root_key) }, "configuration": { - "config": { - "validationUpgradeCooldown": 10u32, - "validationUpgradeDelay": 5, - "codeRetentionPeriod": 1200, - "maxCodeSize": MAX_CODE_SIZE, - "maxPovSize": MAX_POV_SIZE, - "maxHeadDataSize": 32 * 1024, - "groupRotationFrequency": 20, - "parasAvailabilityPeriod": 4, - "noShowSlots": 10, - "minimumValidationUpgradeDelay": 5, + "config": polkadot_runtime_parachains::configuration::HostConfiguration { + validation_upgrade_cooldown: 10u32, + validation_upgrade_delay: 5, + code_retention_period: 1200, + max_code_size: MAX_CODE_SIZE, + max_pov_size: MAX_POV_SIZE, + max_head_data_size: 32 * 1024, + group_rotation_frequency: 20, + paras_availability_period: 4, + no_show_slots: 10, + minimum_validation_upgrade_delay: 5, + ..Default::default() }, } }) diff --git a/polkadot/runtime/parachains/src/configuration.rs b/polkadot/runtime/parachains/src/configuration.rs index accc01a2b180..88e8c5efac68 100644 --- a/polkadot/runtime/parachains/src/configuration.rs +++ b/polkadot/runtime/parachains/src/configuration.rs @@ -53,6 +53,7 @@ const LOG_TARGET: &str = "runtime::configuration"; serde::Serialize, serde::Deserialize, )] +#[serde(deny_unknown_fields)] pub struct HostConfiguration { // NOTE: This structure is used by parachains via merkle proofs. Therefore, this struct // requires special treatment. From 125de59b7b7cfc77cbd935aa59ae339149e6a7cc Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 30 Aug 2023 15:44:28 +0200 Subject: [PATCH 11/98] Cargo.lock updated --- Cargo.lock | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 6f54299b7a2a..7981c21a3b3b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -779,6 +779,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -875,6 +876,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -976,6 +978,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-offchain", @@ -1874,6 +1877,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-offchain", @@ -1937,6 +1941,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-offchain", @@ -2043,6 +2048,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keyring", @@ -2356,12 +2362,16 @@ version = "2.0.0" dependencies = [ "ansi_term", "clap 4.4.1", + "kitchensink-runtime", + "log", "node-cli", "rand 0.8.5", "sc-chain-spec", "sc-keystore", + "serde_json", "sp-core", "sp-keystore", + "sp-tracing", ] [[package]] @@ -2663,6 +2673,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-offchain", @@ -2872,6 +2883,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -5884,6 +5896,7 @@ dependencies = [ "sp-api", "sp-block-builder", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -6471,7 +6484,9 @@ dependencies = [ "polkadot-service", "rococo-runtime", "rococo-runtime-constants", + "sc-chain-spec", "sc-consensus-grandpa", + "serde_json", "sp-authority-discovery", "sp-consensus-babe", "sp-consensus-beefy", @@ -6894,12 +6909,14 @@ dependencies = [ "parity-scale-codec", "primitive-types", "scale-info", + "serde_json", "sp-api", "sp-authority-discovery", "sp-block-builder", "sp-consensus-babe", "sp-consensus-grandpa", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-offchain", @@ -7004,6 +7021,7 @@ dependencies = [ "sp-consensus-babe", "sp-consensus-beefy", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keyring", @@ -8476,6 +8494,7 @@ dependencies = [ "frame-system", "futures", "kitchensink-runtime", + "log", "node-primitives", "node-testing", "pallet-balances", @@ -8594,6 +8613,7 @@ dependencies = [ "sc-telemetry", "sc-transaction-pool", "sc-transaction-pool-api", + "serde_json", "sp-api", "sp-block-builder", "sp-blockchain", @@ -8645,11 +8665,13 @@ dependencies = [ "pallet-transaction-payment-rpc-runtime-api", "parity-scale-codec", "scale-info", + "serde_json", "sp-api", "sp-block-builder", "sp-consensus-aura", "sp-consensus-grandpa", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -11054,6 +11076,7 @@ dependencies = [ "sc-transaction-pool", "sc-transaction-pool-api", "serde", + "serde_json", "sp-api", "sp-block-builder", "sp-blockchain", @@ -11111,6 +11134,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -11437,6 +11461,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -12815,6 +12840,7 @@ dependencies = [ "sp-consensus-babe", "sp-consensus-beefy", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keyring", @@ -13246,6 +13272,7 @@ dependencies = [ "sp-consensus-babe", "sp-consensus-beefy", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keyring", @@ -14259,6 +14286,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -14344,6 +14372,7 @@ dependencies = [ "sp-consensus-babe", "sp-consensus-beefy", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keyring", @@ -14762,18 +14791,29 @@ dependencies = [ name = "sc-chain-spec" version = "4.0.0-dev" dependencies = [ + "array-bytes", + "json-patch", + "log", "memmap2", + "parity-scale-codec", "sc-chain-spec-derive", "sc-client-api", "sc-executor", + "sc-executor-common", "sc-network", "sc-telemetry", "serde", "serde_json", + "sp-application-crypto", "sp-blockchain", + "sp-consensus-babe", "sp-core", + "sp-genesis-builder", + "sp-io", + "sp-keyring", "sp-runtime", "sp-state-machine", + "substrate-test-runtime", ] [[package]] @@ -16284,6 +16324,7 @@ dependencies = [ "sp-api", "sp-block-builder", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -16527,6 +16568,7 @@ dependencies = [ "sp-api", "sp-block-builder", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -20419,6 +20461,7 @@ dependencies = [ "sp-consensus-babe", "sp-consensus-beefy", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keyring", From a247f5889bdeb5d8bf432e41a277f34caa89bbf4 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 30 Aug 2023 17:25:12 +0200 Subject: [PATCH 12/98] gitlab: enabled fact-runtime for rococo runtime --- .gitlab/pipeline/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab/pipeline/build.yml b/.gitlab/pipeline/build.yml index 0364c3607606..95ccc13024ac 100644 --- a/.gitlab/pipeline/build.yml +++ b/.gitlab/pipeline/build.yml @@ -17,6 +17,8 @@ build-linux-stable: RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings" # Ensure we run the UI tests. RUN_UI_TESTS: 1 + # Ensure rococo runtime has fast-runtime feature enabled + ROCOCO_FAST_RUNTIME: 1 script: - time cargo build --locked --profile testnet --features pyroscope,fast-runtime --bin polkadot --bin polkadot-prepare-worker --bin polkadot-execute-worker # pack artifacts From 3de595a83f9e44ef3c5fd178ec2d0f374a0246bc Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 31 Aug 2023 12:23:21 +0200 Subject: [PATCH 13/98] Revert "gitlab: enabled fact-runtime for rococo runtime" This reverts commit a247f5889bdeb5d8bf432e41a277f34caa89bbf4. --- .gitlab/pipeline/build.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitlab/pipeline/build.yml b/.gitlab/pipeline/build.yml index 95ccc13024ac..0364c3607606 100644 --- a/.gitlab/pipeline/build.yml +++ b/.gitlab/pipeline/build.yml @@ -17,8 +17,6 @@ build-linux-stable: RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings" # Ensure we run the UI tests. RUN_UI_TESTS: 1 - # Ensure rococo runtime has fast-runtime feature enabled - ROCOCO_FAST_RUNTIME: 1 script: - time cargo build --locked --profile testnet --features pyroscope,fast-runtime --bin polkadot --bin polkadot-prepare-worker --bin polkadot-execute-worker # pack artifacts From 6bfc04d547998155179add037fb4efcef8a80783 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 31 Aug 2023 13:55:25 +0200 Subject: [PATCH 14/98] chain-spec: always output backward compatible spec (tests check) --- substrate/client/chain-spec/src/chain_spec.rs | 16 ++++++++-- .../chain-spec/src/genesis_config_builder.rs | 31 ++++++++++++------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index c4287e53b370..119066628a7d 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -198,6 +198,7 @@ enum Genesis { StateRootHash(StorageData), /// Represents the full runtime genesis config in JSON format. /// The contained object is a JSON blob that can be parsed by a compatible runtime. + #[serde(rename(serialize = "runtime"))] RuntimeGenesisConfig(json::Value), /// Represents a patch for the default runtime genesis config in JSON format. /// The contained value is a JSON object that can be parsed by a compatible runtime. @@ -374,13 +375,24 @@ impl ChainSpecBuilder { code_substitutes: BTreeMap::new(), }; + let code = self.code.expect("with code must be called."); + + let genesis_build_action = match self.genesis_build_action { + Some(GenesisBuildAction::Patch(patch)) => Some(GenesisBuildAction::Full( + RuntimeCaller::new(&code[..]) + .get_config_for_patch(patch) + .expect("patch should be correct"), + )), + _ => self.genesis_build_action, + }; + ChainSpec { client_spec, genesis: GenesisSource::GenesisBuilderApi( - self.genesis_build_action + genesis_build_action .expect("with_genesis_config_patch or with_genesis_config must be called."), ), - code: self.code.expect("with code must be called.").into(), + code: code.into(), } } } diff --git a/substrate/client/chain-spec/src/genesis_config_builder.rs b/substrate/client/chain-spec/src/genesis_config_builder.rs index ddd9293d4002..f89d7fd18e8a 100644 --- a/substrate/client/chain-spec/src/genesis_config_builder.rs +++ b/substrate/client/chain-spec/src/genesis_config_builder.rs @@ -94,29 +94,38 @@ impl<'a> GenesisConfigBuilderRuntimeCaller<'a> { Ok(ext.into_storages()) } - /// Patch default `GenesisConfig` using given JSON patch and store it in the storage. + /// Patch default `RuntimeGenesisConfig` using given JSON patch and store it in the storage. /// - /// This function generates the `GenesisConfig` for the runtime by applying a provided JSON - /// patch. The patch modifies the default `GenesisConfig` allowing customization of the specific - /// keys. The resulting `GenesisConfig` is then deserialized from the patched JSON - /// representation and stored in the storage. + /// Refer to [get_storage_for_patch] for info how patch is applied. + pub fn get_storage_for_patch(&self, patch: Value) -> core::result::Result { + let config = self.get_config_for_patch(patch)?; + self.get_storage_for_config(config) + } + + /// Creates a `RuntimeGenesisConfig`, by applying given `patch` to default + /// `RuntimeGenesisConfig`. + /// + /// This function generates the `RuntimeGenesisConfig` for the runtime by applying a provided + /// JSON patch. The patch modifies the default `RuntimeGenesisConfig` allowing customization of + /// the specific keys. The resulting `RuntimeGenesisConfig` is then returned. /// /// If the provided JSON patch is incorrect or the deserialization fails the error will be /// returned. /// - /// The patching process modifies the default `GenesisConfig` according to the following rules: + /// The patching process modifies the default `RuntimeGenesisConfig` according to the following + /// rules: /// 1. Existing keys in the default configuration will be overridden by the corresponding values /// in the patch. /// 2. If a key exists in the patch but not in the default configuration, it will be added to - /// the resulting `GenesisConfig`. + /// the resulting `RuntimeGenesisConfig`. /// 3. Keys in the default configuration that have null values in the patch will be removed from - /// the resulting `GenesisConfig`. This is helpful for changing enum variant value. + /// the resulting `RuntimeGenesisConfig`. This is helpful for changing enum variant value. /// - /// Please note that the patch may contain full `GenesisConfig`. - pub fn get_storage_for_patch(&self, patch: Value) -> core::result::Result { + /// Please note that the patch may contain full `RuntimeGenesisConfig`. + pub fn get_config_for_patch(&self, patch: Value) -> core::result::Result { let mut config = self.get_default_config()?; json_patch::merge(&mut config, &patch); - self.get_storage_for_config(config) + Ok(config) } } From fb433fb417ae79df6e0e18a4cc66d54c52d51ad5 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 1 Sep 2023 12:02:22 +0200 Subject: [PATCH 15/98] Revert "chain-spec: always output backward compatible spec (tests check)" This reverts commit 6bfc04d547998155179add037fb4efcef8a80783. --- substrate/client/chain-spec/src/chain_spec.rs | 16 ++-------- .../chain-spec/src/genesis_config_builder.rs | 31 +++++++------------ 2 files changed, 13 insertions(+), 34 deletions(-) diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index 119066628a7d..c4287e53b370 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -198,7 +198,6 @@ enum Genesis { StateRootHash(StorageData), /// Represents the full runtime genesis config in JSON format. /// The contained object is a JSON blob that can be parsed by a compatible runtime. - #[serde(rename(serialize = "runtime"))] RuntimeGenesisConfig(json::Value), /// Represents a patch for the default runtime genesis config in JSON format. /// The contained value is a JSON object that can be parsed by a compatible runtime. @@ -375,24 +374,13 @@ impl ChainSpecBuilder { code_substitutes: BTreeMap::new(), }; - let code = self.code.expect("with code must be called."); - - let genesis_build_action = match self.genesis_build_action { - Some(GenesisBuildAction::Patch(patch)) => Some(GenesisBuildAction::Full( - RuntimeCaller::new(&code[..]) - .get_config_for_patch(patch) - .expect("patch should be correct"), - )), - _ => self.genesis_build_action, - }; - ChainSpec { client_spec, genesis: GenesisSource::GenesisBuilderApi( - genesis_build_action + self.genesis_build_action .expect("with_genesis_config_patch or with_genesis_config must be called."), ), - code: code.into(), + code: self.code.expect("with code must be called.").into(), } } } diff --git a/substrate/client/chain-spec/src/genesis_config_builder.rs b/substrate/client/chain-spec/src/genesis_config_builder.rs index f89d7fd18e8a..ddd9293d4002 100644 --- a/substrate/client/chain-spec/src/genesis_config_builder.rs +++ b/substrate/client/chain-spec/src/genesis_config_builder.rs @@ -94,38 +94,29 @@ impl<'a> GenesisConfigBuilderRuntimeCaller<'a> { Ok(ext.into_storages()) } - /// Patch default `RuntimeGenesisConfig` using given JSON patch and store it in the storage. + /// Patch default `GenesisConfig` using given JSON patch and store it in the storage. /// - /// Refer to [get_storage_for_patch] for info how patch is applied. - pub fn get_storage_for_patch(&self, patch: Value) -> core::result::Result { - let config = self.get_config_for_patch(patch)?; - self.get_storage_for_config(config) - } - - /// Creates a `RuntimeGenesisConfig`, by applying given `patch` to default - /// `RuntimeGenesisConfig`. - /// - /// This function generates the `RuntimeGenesisConfig` for the runtime by applying a provided - /// JSON patch. The patch modifies the default `RuntimeGenesisConfig` allowing customization of - /// the specific keys. The resulting `RuntimeGenesisConfig` is then returned. + /// This function generates the `GenesisConfig` for the runtime by applying a provided JSON + /// patch. The patch modifies the default `GenesisConfig` allowing customization of the specific + /// keys. The resulting `GenesisConfig` is then deserialized from the patched JSON + /// representation and stored in the storage. /// /// If the provided JSON patch is incorrect or the deserialization fails the error will be /// returned. /// - /// The patching process modifies the default `RuntimeGenesisConfig` according to the following - /// rules: + /// The patching process modifies the default `GenesisConfig` according to the following rules: /// 1. Existing keys in the default configuration will be overridden by the corresponding values /// in the patch. /// 2. If a key exists in the patch but not in the default configuration, it will be added to - /// the resulting `RuntimeGenesisConfig`. + /// the resulting `GenesisConfig`. /// 3. Keys in the default configuration that have null values in the patch will be removed from - /// the resulting `RuntimeGenesisConfig`. This is helpful for changing enum variant value. + /// the resulting `GenesisConfig`. This is helpful for changing enum variant value. /// - /// Please note that the patch may contain full `RuntimeGenesisConfig`. - pub fn get_config_for_patch(&self, patch: Value) -> core::result::Result { + /// Please note that the patch may contain full `GenesisConfig`. + pub fn get_storage_for_patch(&self, patch: Value) -> core::result::Result { let mut config = self.get_default_config()?; json_patch::merge(&mut config, &patch); - Ok(config) + self.get_storage_for_config(config) } } From a9ab958ecd5062e967982d9d464ac2871e54f1c8 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 1 Sep 2023 17:28:39 +0200 Subject: [PATCH 16/98] trying to make zombienet tests work --- .../zombienet_tests/functional/0002-parachains-disputes.toml | 4 ++-- .../functional/0003-parachains-garbage-candidate.toml | 4 ++-- .../functional/0004-parachains-disputes-past-session.toml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/polkadot/zombienet_tests/functional/0002-parachains-disputes.toml b/polkadot/zombienet_tests/functional/0002-parachains-disputes.toml index a0a87d60d4e3..6055e9a4b65b 100644 --- a/polkadot/zombienet_tests/functional/0002-parachains-disputes.toml +++ b/polkadot/zombienet_tests/functional/0002-parachains-disputes.toml @@ -1,12 +1,12 @@ [settings] timeout = 1000 -[relaychain.genesis.runtime.runtime_genesis_config.configuration.config] +[relaychain.genesis.runtimeGenesisConfigPatch.configuration.config] max_validators_per_core = 5 needed_approvals = 8 [relaychain] -default_image = "{{ZOMBIENET_INTEGRATION_TEST_IMAGE}}" +default_image = "docker.io/paritypr/zombienet:8c572276" chain = "rococo-local" chain_spec_command = "polkadot build-spec --chain rococo-local --disable-default-bootnode" default_command = "polkadot" diff --git a/polkadot/zombienet_tests/functional/0003-parachains-garbage-candidate.toml b/polkadot/zombienet_tests/functional/0003-parachains-garbage-candidate.toml index 7c4f5a9f1bca..ca44abae34ae 100644 --- a/polkadot/zombienet_tests/functional/0003-parachains-garbage-candidate.toml +++ b/polkadot/zombienet_tests/functional/0003-parachains-garbage-candidate.toml @@ -2,12 +2,12 @@ timeout = 1000 bootnode = true -[relaychain.genesis.runtime.runtime_genesis_config.configuration.config] +[relaychain.genesis.runtimeGenesisConfigPatch.configuration.config] max_validators_per_core = 1 needed_approvals = 2 [relaychain] -default_image = "{{ZOMBIENET_INTEGRATION_TEST_IMAGE}}" +default_image = "docker.io/paritypr/zombienet:8c572276" chain = "rococo-local" chain_spec_command = "polkadot build-spec --chain rococo-local --disable-default-bootnode" default_command = "polkadot" diff --git a/polkadot/zombienet_tests/functional/0004-parachains-disputes-past-session.toml b/polkadot/zombienet_tests/functional/0004-parachains-disputes-past-session.toml index 50c465950f72..d867b3e5e997 100644 --- a/polkadot/zombienet_tests/functional/0004-parachains-disputes-past-session.toml +++ b/polkadot/zombienet_tests/functional/0004-parachains-disputes-past-session.toml @@ -2,13 +2,13 @@ timeout = 1000 bootnode = true -[relaychain.genesis.runtime.configuration.config] +[relaychain.genesis.runtimeGenesisConfigPatch.configuration.config] max_validators_per_core = 1 needed_approvals = 2 group_rotation_frequency = 3 [relaychain] -default_image = "{{ZOMBIENET_INTEGRATION_TEST_IMAGE}}" +default_image = "docker.io/paritypr/zombienet:8c572276" chain = "westend-local" # using westend-local to enable slashing default_command = "polkadot" From c121b80174e2ed084484626b3726e9afcfb5ec15 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 1 Sep 2023 18:15:19 +0200 Subject: [PATCH 17/98] fix --- .../zombienet_tests/functional/0002-parachains-disputes.toml | 2 +- .../functional/0003-parachains-garbage-candidate.toml | 2 +- .../functional/0004-parachains-disputes-past-session.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/polkadot/zombienet_tests/functional/0002-parachains-disputes.toml b/polkadot/zombienet_tests/functional/0002-parachains-disputes.toml index 6055e9a4b65b..f51df45fa4be 100644 --- a/polkadot/zombienet_tests/functional/0002-parachains-disputes.toml +++ b/polkadot/zombienet_tests/functional/0002-parachains-disputes.toml @@ -6,7 +6,7 @@ timeout = 1000 needed_approvals = 8 [relaychain] -default_image = "docker.io/paritypr/zombienet:8c572276" +default_image = "{{ZOMBIENET_INTEGRATION_TEST_IMAGE}}" chain = "rococo-local" chain_spec_command = "polkadot build-spec --chain rococo-local --disable-default-bootnode" default_command = "polkadot" diff --git a/polkadot/zombienet_tests/functional/0003-parachains-garbage-candidate.toml b/polkadot/zombienet_tests/functional/0003-parachains-garbage-candidate.toml index ca44abae34ae..7b1234eabc00 100644 --- a/polkadot/zombienet_tests/functional/0003-parachains-garbage-candidate.toml +++ b/polkadot/zombienet_tests/functional/0003-parachains-garbage-candidate.toml @@ -7,7 +7,7 @@ bootnode = true needed_approvals = 2 [relaychain] -default_image = "docker.io/paritypr/zombienet:8c572276" +default_image = "{{ZOMBIENET_INTEGRATION_TEST_IMAGE}}" chain = "rococo-local" chain_spec_command = "polkadot build-spec --chain rococo-local --disable-default-bootnode" default_command = "polkadot" diff --git a/polkadot/zombienet_tests/functional/0004-parachains-disputes-past-session.toml b/polkadot/zombienet_tests/functional/0004-parachains-disputes-past-session.toml index d867b3e5e997..9333d65ffd64 100644 --- a/polkadot/zombienet_tests/functional/0004-parachains-disputes-past-session.toml +++ b/polkadot/zombienet_tests/functional/0004-parachains-disputes-past-session.toml @@ -8,7 +8,7 @@ bootnode = true group_rotation_frequency = 3 [relaychain] -default_image = "docker.io/paritypr/zombienet:8c572276" +default_image = "{{ZOMBIENET_INTEGRATION_TEST_IMAGE}}" chain = "westend-local" # using westend-local to enable slashing default_command = "polkadot" From cb7197719f650f8607c0c3f241bd2a29515efc3a Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 1 Sep 2023 18:23:01 +0200 Subject: [PATCH 18/98] zombienet test fix --- polkadot/zombienet_tests/misc/0001-paritydb.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/zombienet_tests/misc/0001-paritydb.toml b/polkadot/zombienet_tests/misc/0001-paritydb.toml index 38fa56898196..af039768b76f 100644 --- a/polkadot/zombienet_tests/misc/0001-paritydb.toml +++ b/polkadot/zombienet_tests/misc/0001-paritydb.toml @@ -2,7 +2,7 @@ timeout = 1000 bootnode = true -[relaychain.genesis.runtime.runtime_genesis_config.configuration.config] +[relaychain.genesis.runtimeGenesisConfigPatch.configuration.config] max_validators_per_core = 1 needed_approvals = 3 From 86bacb1e8b1d3d35b8f31144bb3f6218aa17195d Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 1 Sep 2023 18:23:21 +0200 Subject: [PATCH 19/98] zombienet dev version used --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9e7346601ba3..6d0e9b9342cc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,7 +30,7 @@ variables: RUSTY_CACHIER_COMPRESSION_METHOD: zstd NEXTEST_FAILURE_OUTPUT: immediate-final NEXTEST_SUCCESS_OUTPUT: final - ZOMBIENET_IMAGE: "docker.io/paritytech/zombienet:v1.3.65" + ZOMBIENET_IMAGE: "docker.io/paritypr/zombienet:8c57227" DOCKER_IMAGES_VERSION: "${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}" default: From dcfd2f7136190f7d8da72c9bb0399f149d1f1bc2 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 1 Sep 2023 18:49:26 +0200 Subject: [PATCH 20/98] ... --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6d0e9b9342cc..4080ac5c5969 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,7 +30,7 @@ variables: RUSTY_CACHIER_COMPRESSION_METHOD: zstd NEXTEST_FAILURE_OUTPUT: immediate-final NEXTEST_SUCCESS_OUTPUT: final - ZOMBIENET_IMAGE: "docker.io/paritypr/zombienet:8c57227" + ZOMBIENET_IMAGE: "docker.io/paritypr/zombienet:8c572276" DOCKER_IMAGES_VERSION: "${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}" default: From 72d0c5a82e0a7a53874b0cf14dc6c5c6590281d5 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Sat, 2 Sep 2023 10:34:03 +0200 Subject: [PATCH 21/98] experimenting with chain-spec path --- substrate/zombienet/0001-basic-warp-sync/test-warp-sync.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/zombienet/0001-basic-warp-sync/test-warp-sync.toml b/substrate/zombienet/0001-basic-warp-sync/test-warp-sync.toml index d14d77cfe621..773f5020bc3a 100644 --- a/substrate/zombienet/0001-basic-warp-sync/test-warp-sync.toml +++ b/substrate/zombienet/0001-basic-warp-sync/test-warp-sync.toml @@ -6,7 +6,7 @@ default_image = "{{ZOMBIENET_INTEGRATION_TEST_IMAGE}}" default_command = "substrate" chain = "gen-db" -chain_spec_path = "substrate/zombienet/0001-basic-warp-sync/chain-spec.json" +chain_spec_path = "chain-spec.json" [[relaychain.nodes]] name = "alice" From dc458e94802d3e849ae151ca4336384a503e25d9 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 4 Sep 2023 10:54:13 +0200 Subject: [PATCH 22/98] chain-spec: removed optional fields from ChainSpecBuilder --- .../parachain-template/node/src/chain_spec.rs | 162 +++-- .../src/chain_spec/asset_hubs.rs | 617 +++++++++--------- .../src/chain_spec/bridge_hubs.rs | 234 ++++--- .../src/chain_spec/collectives.rs | 130 ++-- .../src/chain_spec/contracts.rs | 163 +++-- .../src/chain_spec/glutton.rs | 61 +- .../src/chain_spec/penpal.rs | 75 ++- .../src/chain_spec/rococo_parachain.rs | 99 ++- .../src/chain_spec/seedling.rs | 27 +- .../src/chain_spec/shell.rs | 23 +- cumulus/polkadot-parachain/src/command.rs | 37 +- polkadot/node/service/src/chain_spec.rs | 342 +++++----- polkadot/node/test/service/src/chain_spec.rs | 23 +- .../bin/node-template/node/src/chain_spec.rs | 98 +-- substrate/bin/node/cli/src/chain_spec.rs | 20 +- .../bin/utils/chain-spec-builder/src/lib.rs | 10 +- substrate/client/chain-spec/src/chain_spec.rs | 171 ++--- .../client/cli/src/commands/insert_key.rs | 4 +- substrate/client/cli/src/runner.rs | 4 +- substrate/client/network/src/service.rs | 14 +- .../rpc-spec-v2/src/chain_head/chain_head.rs | 6 +- .../src/chain_head/chain_head_storage.rs | 4 +- .../frame/broker/src/dispatchable_impls.rs | 8 +- substrate/frame/broker/src/tick_impls.rs | 8 +- substrate/frame/safe-mode/src/lib.rs | 2 +- 25 files changed, 1149 insertions(+), 1193 deletions(-) diff --git a/cumulus/parachain-template/node/src/chain_spec.rs b/cumulus/parachain-template/node/src/chain_spec.rs index 5edccefe9f3c..d20aadc0f3c3 100644 --- a/cumulus/parachain-template/node/src/chain_spec.rs +++ b/cumulus/parachain-template/node/src/chain_spec.rs @@ -67,49 +67,48 @@ pub fn development_config() -> ChainSpec { properties.insert("tokenDecimals".into(), 12.into()); properties.insert("ss58Format".into(), 42.into()); - ChainSpec::builder() - .with_name("Development") - .with_id("dev") - .with_chain_type(ChainType::Development) - .with_genesis_config_patch(testnet_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed("Bob"), - ), - ], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - get_account_id_from_seed::("Alice"), - 1000.into(), - )) - .with_extensions(Extensions { + ChainSpec::builder( + parachain_template_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: "rococo-local".into(), // You MUST set this to the correct network! para_id: 1000, - }) - .with_code( - parachain_template_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), - ) - .build() + }, + ) + .with_name("Development") + .with_id("dev") + .with_chain_type(ChainType::Development) + .with_genesis_config_patch(testnet_genesis( + // initial collators. + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + get_account_id_from_seed::("Alice"), + 1000.into(), + )) + .build() } pub fn local_testnet_config() -> ChainSpec { @@ -120,51 +119,50 @@ pub fn local_testnet_config() -> ChainSpec { properties.insert("ss58Format".into(), 42.into()); #[allow(deprecated)] - ChainSpec::builder() - .with_name("Local Testnet") - .with_id("local_testnet") - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(testnet_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed("Bob"), - ), - ], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - get_account_id_from_seed::("Alice"), - 1000.into(), - )) - .with_protocol_id("template-local") - .with_properties(properties) - .with_extensions(Extensions { + ChainSpec::builder( + parachain_template_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: "rococo-local".into(), // You MUST set this to the correct network! para_id: 1000, - }) - .with_code( - parachain_template_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), - ) - .build() + }, + ) + .with_name("Local Testnet") + .with_id("local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(testnet_genesis( + // initial collators. + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + get_account_id_from_seed::("Alice"), + 1000.into(), + )) + .with_protocol_id("template-local") + .with_properties(properties) + .build() } fn testnet_genesis( diff --git a/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs b/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs index 72aaa54e094c..ba2453b27718 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs @@ -64,32 +64,31 @@ pub fn asset_hub_polkadot_development_config() -> AssetHubPolkadotChainSpec { properties.insert("tokenSymbol".into(), "DOT".into()); properties.insert("tokenDecimals".into(), 10.into()); - AssetHubPolkadotChainSpec::builder() - .with_name("Polkadot Asset Hub Development") - .with_id("asset-hub-polkadot-dev") - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(asset_hub_polkadot_genesis( - // initial collators. - vec![( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - )], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - ], - 1000.into(), - )) - .with_boot_nodes(Vec::new()) - .with_properties(properties) - .with_extensions(Extensions { relay_chain: "polkadot-dev".into(), para_id: 1000 }) - .with_code( - asset_hub_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), - ) - .build() + AssetHubPolkadotChainSpec::builder( + asset_hub_polkadot_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: "polkadot-dev".into(), para_id: 1000 }, + ) + .with_name("Polkadot Asset Hub Development") + .with_id("asset-hub-polkadot-dev") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(asset_hub_polkadot_genesis( + // initial collators. + vec![( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + )], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + ], + 1000.into(), + )) + .with_boot_nodes(Vec::new()) + .with_properties(properties) + .build() } pub fn asset_hub_polkadot_local_config() -> AssetHubPolkadotChainSpec { @@ -98,46 +97,45 @@ pub fn asset_hub_polkadot_local_config() -> AssetHubPolkadotChainSpec { properties.insert("tokenSymbol".into(), "DOT".into()); properties.insert("tokenDecimals".into(), 10.into()); - AssetHubPolkadotChainSpec::builder() - .with_name("Polkadot Asset Hub Local") - .with_id("asset-hub-polkadot-local") - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(asset_hub_polkadot_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ + AssetHubPolkadotChainSpec::builder( + asset_hub_polkadot_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: "polkadot-local".into(), para_id: 1000 }, + ) + .with_name("Polkadot Asset Hub Local") + .with_id("asset-hub-polkadot-local") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(asset_hub_polkadot_genesis( + // initial collators. + vec![ + ( get_account_id_from_seed::("Alice"), + get_collator_keys_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"), - ], - 1000.into(), - )) - .with_boot_nodes(Vec::new()) - .with_properties(properties) - .with_extensions(Extensions { relay_chain: "polkadot-local".into(), para_id: 1000 }) - .with_code( - asset_hub_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), - ) - .build() + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + 1000.into(), + )) + .with_boot_nodes(Vec::new()) + .with_properties(properties) + .build() } // Not used for syncing, but just to determine the genesis values set for the upgrade from shell. @@ -147,55 +145,57 @@ pub fn asset_hub_polkadot_config() -> AssetHubPolkadotChainSpec { properties.insert("tokenSymbol".into(), "DOT".into()); properties.insert("tokenDecimals".into(), 10.into()); - AssetHubPolkadotChainSpec::builder() - .with_name("Polkadot Asset Hub") - .with_id("asset-hub-polkadot") - .with_chain_type(ChainType::Live) - .with_genesis_config_patch( - asset_hub_polkadot_genesis( - // initial collators. - vec![ - ( - hex!("4c3d674d2a01060f0ded218e5dcc6f90c1726f43df79885eb3e22d97a20d5421") - .into(), - hex!("4c3d674d2a01060f0ded218e5dcc6f90c1726f43df79885eb3e22d97a20d5421") - .unchecked_into(), - ), - ( - hex!("c7d7d38d16bc23c6321152c50306212dc22c0efc04a2e52b5cccfc31ab3d7811") - .into(), - hex!("c7d7d38d16bc23c6321152c50306212dc22c0efc04a2e52b5cccfc31ab3d7811") - .unchecked_into(), - ), - ( - hex!("c5c07ba203d7375675f5c1ebe70f0a5bb729ae57b48bcc877fcc2ab21309b762") - .into(), - hex!("c5c07ba203d7375675f5c1ebe70f0a5bb729ae57b48bcc877fcc2ab21309b762") - .unchecked_into(), - ), - ( - hex!("0b2d0013fb974794bd7aa452465b567d48ef70373fe231a637c1fb7c547e85b3") - .into(), - hex!("0b2d0013fb974794bd7aa452465b567d48ef70373fe231a637c1fb7c547e85b3") - .unchecked_into(), - ), - ], - vec![], - 1000u32.into(), - ) - ) - .with_boot_nodes( - vec![ - "/ip4/34.65.251.121/tcp/30334/p2p/12D3KooWG3GrM6XKMM4gp3cvemdwUvu96ziYoJmqmetLZBXE8bSa".parse().unwrap(), - "/ip4/34.65.35.228/tcp/30334/p2p/12D3KooWMRyTLrCEPcAQD6c4EnudL3vVzg9zji3whvsMYPUYevpq".parse().unwrap(), - "/ip4/34.83.247.146/tcp/30334/p2p/12D3KooWE4jFh5FpJDkWVZhnWtFnbSqRhdjvC7Dp9b8b3FTuubQC".parse().unwrap(), - "/ip4/104.199.117.230/tcp/30334/p2p/12D3KooWG9R8pVXKumVo2rdkeVD4j5PVhRTqmYgLHY3a4yPYgLqM".parse().unwrap(), - ] - ) - .with_properties(properties) - .with_extensions(Extensions { relay_chain: "polkadot".into(), para_id: 1000 }) - .with_code(asset_hub_polkadot_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!")) - .build() + AssetHubPolkadotChainSpec::builder( + asset_hub_polkadot_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: "polkadot".into(), para_id: 1000 }, + ) + .with_name("Polkadot Asset Hub") + .with_id("asset-hub-polkadot") + .with_chain_type(ChainType::Live) + .with_genesis_config_patch(asset_hub_polkadot_genesis( + // initial collators. + vec![ + ( + hex!("4c3d674d2a01060f0ded218e5dcc6f90c1726f43df79885eb3e22d97a20d5421").into(), + hex!("4c3d674d2a01060f0ded218e5dcc6f90c1726f43df79885eb3e22d97a20d5421") + .unchecked_into(), + ), + ( + hex!("c7d7d38d16bc23c6321152c50306212dc22c0efc04a2e52b5cccfc31ab3d7811").into(), + hex!("c7d7d38d16bc23c6321152c50306212dc22c0efc04a2e52b5cccfc31ab3d7811") + .unchecked_into(), + ), + ( + hex!("c5c07ba203d7375675f5c1ebe70f0a5bb729ae57b48bcc877fcc2ab21309b762").into(), + hex!("c5c07ba203d7375675f5c1ebe70f0a5bb729ae57b48bcc877fcc2ab21309b762") + .unchecked_into(), + ), + ( + hex!("0b2d0013fb974794bd7aa452465b567d48ef70373fe231a637c1fb7c547e85b3").into(), + hex!("0b2d0013fb974794bd7aa452465b567d48ef70373fe231a637c1fb7c547e85b3") + .unchecked_into(), + ), + ], + vec![], + 1000u32.into(), + )) + .with_boot_nodes(vec![ + "/ip4/34.65.251.121/tcp/30334/p2p/12D3KooWG3GrM6XKMM4gp3cvemdwUvu96ziYoJmqmetLZBXE8bSa" + .parse() + .unwrap(), + "/ip4/34.65.35.228/tcp/30334/p2p/12D3KooWMRyTLrCEPcAQD6c4EnudL3vVzg9zji3whvsMYPUYevpq" + .parse() + .unwrap(), + "/ip4/34.83.247.146/tcp/30334/p2p/12D3KooWE4jFh5FpJDkWVZhnWtFnbSqRhdjvC7Dp9b8b3FTuubQC" + .parse() + .unwrap(), + "/ip4/104.199.117.230/tcp/30334/p2p/12D3KooWG9R8pVXKumVo2rdkeVD4j5PVhRTqmYgLHY3a4yPYgLqM" + .parse() + .unwrap(), + ]) + .with_properties(properties) + .build() } fn asset_hub_polkadot_genesis( @@ -242,31 +242,29 @@ pub fn asset_hub_kusama_development_config() -> AssetHubKusamaChainSpec { properties.insert("tokenSymbol".into(), "KSM".into()); properties.insert("tokenDecimals".into(), 12.into()); - AssetHubKusamaChainSpec::builder() - .with_name("Kusama Asset Hub Development") - .with_id("asset-hub-kusama-dev") - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(asset_hub_kusama_genesis( - // initial collators. - vec![( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - )], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - ], - 1000.into(), - )) - .with_properties(properties) - .with_extensions(Extensions { relay_chain: "kusama-dev".into(), para_id: 1000 }) - .with_code( - asset_hub_kusama_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), - ) - .build() + AssetHubKusamaChainSpec::builder( + asset_hub_kusama_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: "kusama-dev".into(), para_id: 1000 }, + ) + .with_name("Kusama Asset Hub Development") + .with_id("asset-hub-kusama-dev") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(asset_hub_kusama_genesis( + // initial collators. + vec![( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + )], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + ], + 1000.into(), + )) + .with_properties(properties) + .build() } pub fn asset_hub_kusama_local_config() -> AssetHubKusamaChainSpec { @@ -275,45 +273,43 @@ pub fn asset_hub_kusama_local_config() -> AssetHubKusamaChainSpec { properties.insert("tokenSymbol".into(), "KSM".into()); properties.insert("tokenDecimals".into(), 12.into()); - AssetHubKusamaChainSpec::builder() - .with_name("Kusama Asset Hub Local") - .with_id("asset-hub-kusama-local") - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(asset_hub_kusama_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ + AssetHubKusamaChainSpec::builder( + asset_hub_kusama_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: "kusama-local".into(), para_id: 1000 }, + ) + .with_name("Kusama Asset Hub Local") + .with_id("asset-hub-kusama-local") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(asset_hub_kusama_genesis( + // initial collators. + vec![ + ( get_account_id_from_seed::("Alice"), + get_collator_keys_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"), - ], - 1000.into(), - )) - .with_properties(properties) - .with_extensions(Extensions { relay_chain: "kusama-local".into(), para_id: 1000 }) - .with_code( - asset_hub_kusama_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), - ) - .build() + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + 1000.into(), + )) + .with_properties(properties) + .build() } pub fn asset_hub_kusama_config() -> AssetHubKusamaChainSpec { @@ -322,44 +318,42 @@ pub fn asset_hub_kusama_config() -> AssetHubKusamaChainSpec { properties.insert("tokenSymbol".into(), "KSM".into()); properties.insert("tokenDecimals".into(), 12.into()); - AssetHubKusamaChainSpec::builder() - .with_name("Kusama Asset Hub") - .with_id("asset-hub-kusama") - .with_chain_type(ChainType::Live) - .with_genesis_config_patch(asset_hub_kusama_genesis( - // initial collators. - vec![ - ( - hex!("50673d59020488a4ffc9d8c6de3062a65977046e6990915617f85fef6d349730").into(), - hex!("50673d59020488a4ffc9d8c6de3062a65977046e6990915617f85fef6d349730") - .unchecked_into(), - ), - ( - hex!("fe8102dbc244e7ea2babd9f53236d67403b046154370da5c3ea99def0bd0747a").into(), - hex!("fe8102dbc244e7ea2babd9f53236d67403b046154370da5c3ea99def0bd0747a") - .unchecked_into(), - ), - ( - hex!("38144b5398e5d0da5ec936a3af23f5a96e782f676ab19d45f29075ee92eca76a").into(), - hex!("38144b5398e5d0da5ec936a3af23f5a96e782f676ab19d45f29075ee92eca76a") - .unchecked_into(), - ), - ( - hex!("3253947640e309120ae70fa458dcacb915e2ddd78f930f52bd3679ec63fc4415").into(), - hex!("3253947640e309120ae70fa458dcacb915e2ddd78f930f52bd3679ec63fc4415") - .unchecked_into(), - ), - ], - Vec::new(), - 1000.into(), - )) - .with_properties(properties) - .with_extensions(Extensions { relay_chain: "kusama".into(), para_id: 1000 }) - .with_code( - asset_hub_kusama_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), - ) - .build() + AssetHubKusamaChainSpec::builder( + asset_hub_kusama_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: "kusama".into(), para_id: 1000 }, + ) + .with_name("Kusama Asset Hub") + .with_id("asset-hub-kusama") + .with_chain_type(ChainType::Live) + .with_genesis_config_patch(asset_hub_kusama_genesis( + // initial collators. + vec![ + ( + hex!("50673d59020488a4ffc9d8c6de3062a65977046e6990915617f85fef6d349730").into(), + hex!("50673d59020488a4ffc9d8c6de3062a65977046e6990915617f85fef6d349730") + .unchecked_into(), + ), + ( + hex!("fe8102dbc244e7ea2babd9f53236d67403b046154370da5c3ea99def0bd0747a").into(), + hex!("fe8102dbc244e7ea2babd9f53236d67403b046154370da5c3ea99def0bd0747a") + .unchecked_into(), + ), + ( + hex!("38144b5398e5d0da5ec936a3af23f5a96e782f676ab19d45f29075ee92eca76a").into(), + hex!("38144b5398e5d0da5ec936a3af23f5a96e782f676ab19d45f29075ee92eca76a") + .unchecked_into(), + ), + ( + hex!("3253947640e309120ae70fa458dcacb915e2ddd78f930f52bd3679ec63fc4415").into(), + hex!("3253947640e309120ae70fa458dcacb915e2ddd78f930f52bd3679ec63fc4415") + .unchecked_into(), + ), + ], + Vec::new(), + 1000.into(), + )) + .with_properties(properties) + .build() } fn asset_hub_kusama_genesis( @@ -405,31 +399,30 @@ pub fn asset_hub_westend_development_config() -> AssetHubWestendChainSpec { properties.insert("tokenSymbol".into(), "WND".into()); properties.insert("tokenDecimals".into(), 12.into()); - AssetHubWestendChainSpec::builder() - .with_name("Westend Asset Hub Development") - .with_id("asset-hub-westend-dev") - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(asset_hub_westend_genesis( - // initial collators. - vec![( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - )], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - ], - 1000.into(), - )) - .with_properties(properties) - .with_extensions(Extensions { relay_chain: "westend".into(), para_id: 1000 }) - .with_code( - asset_hub_westend_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), - ) - .build() + AssetHubWestendChainSpec::builder( + asset_hub_westend_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: "westend".into(), para_id: 1000 }, + ) + .with_name("Westend Asset Hub Development") + .with_id("asset-hub-westend-dev") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(asset_hub_westend_genesis( + // initial collators. + vec![( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + )], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + ], + 1000.into(), + )) + .with_properties(properties) + .build() } pub fn asset_hub_westend_local_config() -> AssetHubWestendChainSpec { @@ -437,45 +430,44 @@ pub fn asset_hub_westend_local_config() -> AssetHubWestendChainSpec { properties.insert("tokenSymbol".into(), "WND".into()); properties.insert("tokenDecimals".into(), 12.into()); - AssetHubWestendChainSpec::builder() - .with_name("Westend Asset Hub Local") - .with_id("asset-hub-westend-local") - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(asset_hub_westend_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ + AssetHubWestendChainSpec::builder( + asset_hub_westend_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: "westend-local".into(), para_id: 1000 }, + ) + .with_name("Westend Asset Hub Local") + .with_id("asset-hub-westend-local") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(asset_hub_westend_genesis( + // initial collators. + vec![ + ( get_account_id_from_seed::("Alice"), + get_collator_keys_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"), - ], - 1000.into(), - )) - .with_properties(properties) - .with_extensions(Extensions { relay_chain: "westend-local".into(), para_id: 1000 }) - .with_code( - asset_hub_westend_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), - ) - .build() + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + 1000.into(), + )) + .with_properties(properties) + .build() } pub fn asset_hub_westend_config() -> AssetHubWestendChainSpec { @@ -483,44 +475,43 @@ pub fn asset_hub_westend_config() -> AssetHubWestendChainSpec { properties.insert("tokenSymbol".into(), "WND".into()); properties.insert("tokenDecimals".into(), 12.into()); - AssetHubWestendChainSpec::builder() - .with_name("Westend Asset Hub") - .with_id("asset-hub-westend") - .with_chain_type(ChainType::Live) - .with_genesis_config_patch(asset_hub_westend_genesis( - // initial collators. - vec![ - ( - hex!("9cfd429fa002114f33c1d3e211501d62830c9868228eb3b4b8ae15a83de04325").into(), - hex!("9cfd429fa002114f33c1d3e211501d62830c9868228eb3b4b8ae15a83de04325") - .unchecked_into(), - ), - ( - hex!("12a03fb4e7bda6c9a07ec0a11d03c24746943e054ff0bb04938970104c783876").into(), - hex!("12a03fb4e7bda6c9a07ec0a11d03c24746943e054ff0bb04938970104c783876") - .unchecked_into(), - ), - ( - hex!("1256436307dfde969324e95b8c62cb9101f520a39435e6af0f7ac07b34e1931f").into(), - hex!("1256436307dfde969324e95b8c62cb9101f520a39435e6af0f7ac07b34e1931f") - .unchecked_into(), - ), - ( - hex!("98102b7bca3f070f9aa19f58feed2c0a4e107d203396028ec17a47e1ed80e322").into(), - hex!("98102b7bca3f070f9aa19f58feed2c0a4e107d203396028ec17a47e1ed80e322") - .unchecked_into(), - ), - ], - Vec::new(), - 1000.into(), - )) - .with_properties(properties) - .with_extensions(Extensions { relay_chain: "westend".into(), para_id: 1000 }) - .with_code( - asset_hub_westend_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), - ) - .build() + AssetHubWestendChainSpec::builder( + asset_hub_westend_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: "westend".into(), para_id: 1000 }, + ) + .with_name("Westend Asset Hub") + .with_id("asset-hub-westend") + .with_chain_type(ChainType::Live) + .with_genesis_config_patch(asset_hub_westend_genesis( + // initial collators. + vec![ + ( + hex!("9cfd429fa002114f33c1d3e211501d62830c9868228eb3b4b8ae15a83de04325").into(), + hex!("9cfd429fa002114f33c1d3e211501d62830c9868228eb3b4b8ae15a83de04325") + .unchecked_into(), + ), + ( + hex!("12a03fb4e7bda6c9a07ec0a11d03c24746943e054ff0bb04938970104c783876").into(), + hex!("12a03fb4e7bda6c9a07ec0a11d03c24746943e054ff0bb04938970104c783876") + .unchecked_into(), + ), + ( + hex!("1256436307dfde969324e95b8c62cb9101f520a39435e6af0f7ac07b34e1931f").into(), + hex!("1256436307dfde969324e95b8c62cb9101f520a39435e6af0f7ac07b34e1931f") + .unchecked_into(), + ), + ( + hex!("98102b7bca3f070f9aa19f58feed2c0a4e107d203396028ec17a47e1ed80e322").into(), + hex!("98102b7bca3f070f9aa19f58feed2c0a4e107d203396028ec17a47e1ed80e322") + .unchecked_into(), + ), + ], + Vec::new(), + 1000.into(), + )) + .with_properties(properties) + .build() } fn asset_hub_westend_genesis( diff --git a/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs b/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs index 2a4a70e5c436..3a52121b94ca 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs @@ -214,51 +214,47 @@ pub mod rococo { properties.insert("tokenDecimals".into(), 12.into()); modify_props(&mut properties); - BridgeHubChainSpec::builder() - .with_name(chain_name) - .with_id(super::ensure_id(id).expect("invalid id")) - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ + BridgeHubChainSpec::builder( + bridge_hub_rococo_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, + ) + .with_name(chain_name) + .with_id(super::ensure_id(id).expect("invalid id")) + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(genesis( + // initial collators. + vec![ + ( get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + ), + ( get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - para_id, - bridges_pallet_owner_seed - .as_ref() - .map(|seed| get_account_id_from_seed::(seed)), - )) - .with_properties(properties) - .with_extensions(Extensions { - relay_chain: relay_chain.to_string(), - para_id: para_id.into(), - }) - .with_code( - bridge_hub_rococo_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), - ) - .build() + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + para_id, + bridges_pallet_owner_seed + .as_ref() + .map(|seed| get_account_id_from_seed::(seed)), + )) + .with_properties(properties) + .build() } fn genesis( @@ -371,48 +367,44 @@ pub mod kusama { properties.insert("tokenSymbol".into(), "KSM".into()); properties.insert("tokenDecimals".into(), 12.into()); - BridgeHubChainSpec::builder() - .with_name(chain_name) - .with_id(super::ensure_id(id).expect("invalid id")) - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ + BridgeHubChainSpec::builder( + bridge_hub_kusama_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, + ) + .with_name(chain_name) + .with_id(super::ensure_id(id).expect("invalid id")) + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(genesis( + // initial collators. + vec![ + ( get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + ), + ( get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - para_id, - )) - .with_properties(properties) - .with_extensions(Extensions { - relay_chain: relay_chain.to_string(), - para_id: para_id.into(), - }) - .with_code( - bridge_hub_kusama_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), - ) - .build() + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + para_id, + )) + .with_properties(properties) + .build() } fn genesis( @@ -494,48 +486,44 @@ pub mod polkadot { properties.insert("tokenSymbol".into(), "DOT".into()); properties.insert("tokenDecimals".into(), 10.into()); - BridgeHubChainSpec::builder() - .with_name(chain_name) - .with_id(super::ensure_id(id).expect("invalid id")) - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ + BridgeHubChainSpec::builder( + bridge_hub_polkadot_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, + ) + .with_name(chain_name) + .with_id(super::ensure_id(id).expect("invalid id")) + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(genesis( + // initial collators. + vec![ + ( get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + ), + ( get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - para_id, - )) - .with_properties(properties) - .with_extensions(Extensions { - relay_chain: relay_chain.to_string(), - para_id: para_id.into(), - }) - .with_code( - bridge_hub_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), - ) - .build() + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + para_id, + )) + .with_properties(properties) + .build() } fn genesis( diff --git a/cumulus/polkadot-parachain/src/chain_spec/collectives.rs b/cumulus/polkadot-parachain/src/chain_spec/collectives.rs index bd4481fb0143..c901e4e829fa 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/collectives.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/collectives.rs @@ -42,34 +42,33 @@ pub fn collectives_polkadot_development_config() -> CollectivesPolkadotChainSpec properties.insert("tokenSymbol".into(), "DOT".into()); properties.insert("tokenDecimals".into(), 10.into()); - CollectivesPolkadotChainSpec::builder() - .with_name("Polkadot Collectives Development") - .with_id("collectives_polkadot_dev") - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(collectives_polkadot_genesis( - // initial collators. - vec![( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - )], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - ], - // 1002 avoids a potential collision with Kusama-1001 (Encointer) should there ever - // be a collective para on Kusama. - 1002.into(), - )) - .with_boot_nodes(Vec::new()) - .with_properties(properties) - .with_extensions(Extensions { relay_chain: "polkadot-dev".into(), para_id: 1002 }) - .with_code( - collectives_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), - ) - .build() + CollectivesPolkadotChainSpec::builder( + collectives_polkadot_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: "polkadot-dev".into(), para_id: 1002 }, + ) + .with_name("Polkadot Collectives Development") + .with_id("collectives_polkadot_dev") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(collectives_polkadot_genesis( + // initial collators. + vec![( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + )], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + ], + // 1002 avoids a potential collision with Kusama-1001 (Encointer) should there ever + // be a collective para on Kusama. + 1002.into(), + )) + .with_boot_nodes(Vec::new()) + .with_properties(properties) + .build() } /// Collectives Polkadot Local Config. @@ -79,46 +78,45 @@ pub fn collectives_polkadot_local_config() -> CollectivesPolkadotChainSpec { properties.insert("tokenSymbol".into(), "DOT".into()); properties.insert("tokenDecimals".into(), 10.into()); - CollectivesPolkadotChainSpec::builder() - .with_name("Polkadot Collectives Local") - .with_id("collectives_polkadot_local") - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(collectives_polkadot_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ + CollectivesPolkadotChainSpec::builder( + collectives_polkadot_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: "polkadot-local".into(), para_id: 1002 }, + ) + .with_name("Polkadot Collectives Local") + .with_id("collectives_polkadot_local") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(collectives_polkadot_genesis( + // initial collators. + vec![ + ( get_account_id_from_seed::("Alice"), + get_collator_keys_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"), - ], - 1002.into(), - )) - .with_boot_nodes(Vec::new()) - .with_properties(properties) - .with_extensions(Extensions { relay_chain: "polkadot-local".into(), para_id: 1002 }) - .with_code( - collectives_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), - ) - .build() + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + 1002.into(), + )) + .with_boot_nodes(Vec::new()) + .with_properties(properties) + .build() } fn collectives_polkadot_genesis( diff --git a/cumulus/polkadot-parachain/src/chain_spec/contracts.rs b/cumulus/polkadot-parachain/src/chain_spec/contracts.rs index 86e3a782ece2..95e806b9becb 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/contracts.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/contracts.rs @@ -37,48 +37,46 @@ pub fn contracts_rococo_development_config() -> ContractsRococoChainSpec { properties.insert("tokenSymbol".into(), "ROC".into()); properties.insert("tokenDecimals".into(), 12.into()); - ContractsRococoChainSpec::builder() - .with_name("Contracts on Rococo Development") - .with_id("contracts-rococo-dev") - .with_chain_type(ChainType::Development) - .with_genesis_config_patch(contracts_rococo_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - CONTRACTS_PARACHAIN_ID.into(), - )) - .with_boot_nodes(Vec::new()) - .with_extensions(Extensions { + ContractsRococoChainSpec::builder( + contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: "rococo-local".into(), // You MUST set this to the correct network! para_id: CONTRACTS_PARACHAIN_ID, - }) - .with_code( - contracts_rococo_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), - ) - .build() + }, + ) + .with_name("Contracts on Rococo Development") + .with_id("contracts-rococo-dev") + .with_chain_type(ChainType::Development) + .with_genesis_config_patch(contracts_rococo_genesis( + // initial collators. + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + CONTRACTS_PARACHAIN_ID.into(), + )) + .with_boot_nodes(Vec::new()) + .build() } pub fn contracts_rococo_local_config() -> ContractsRococoChainSpec { @@ -86,48 +84,46 @@ pub fn contracts_rococo_local_config() -> ContractsRococoChainSpec { properties.insert("tokenSymbol".into(), "ROC".into()); properties.insert("tokenDecimals".into(), 12.into()); - ContractsRococoChainSpec::builder() - .with_name("Contracts on Rococo") - .with_id("contracts-rococo-local") - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(contracts_rococo_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - CONTRACTS_PARACHAIN_ID.into(), - )) - .with_properties(properties) - .with_extensions(Extensions { + ContractsRococoChainSpec::builder( + contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: "rococo-local".into(), // You MUST set this to the correct network! para_id: CONTRACTS_PARACHAIN_ID, - }) - .with_code( - contracts_rococo_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), - ) - .build() + }, + ) + .with_name("Contracts on Rococo") + .with_id("contracts-rococo-local") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(contracts_rococo_genesis( + // initial collators. + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + CONTRACTS_PARACHAIN_ID.into(), + )) + .with_properties(properties) + .build() } pub fn contracts_rococo_config() -> ContractsRococoChainSpec { @@ -136,7 +132,10 @@ pub fn contracts_rococo_config() -> ContractsRococoChainSpec { properties.insert("tokenSymbol".into(), "ROC".into()); properties.insert("tokenDecimals".into(), 12.into()); - ContractsRococoChainSpec::builder() + ContractsRococoChainSpec::builder( + contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: "rococo".into(), para_id: CONTRACTS_PARACHAIN_ID } + ) .with_name("Contracts on Rococo") .with_id("contracts-rococo") .with_chain_type(ChainType::Live) @@ -198,8 +197,6 @@ pub fn contracts_rococo_config() -> ContractsRococoChainSpec { .expect("MultiaddrWithPeerId"), ]) .with_properties(properties) - .with_extensions(Extensions { relay_chain: "rococo".into(), para_id: CONTRACTS_PARACHAIN_ID }) - .with_code(contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!")) .build() } diff --git a/cumulus/polkadot-parachain/src/chain_spec/glutton.rs b/cumulus/polkadot-parachain/src/chain_spec/glutton.rs index 76dc2823b9f7..8bdc21717be5 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/glutton.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/glutton.rs @@ -24,48 +24,45 @@ pub type GluttonChainSpec = sc_service::GenericChainSpec<(), Extensions>; pub fn glutton_development_config(para_id: ParaId) -> GluttonChainSpec { #[allow(deprecated)] - GluttonChainSpec::builder() - .with_name("Glutton Development") - .with_id("glutton_dev") - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(glutton_genesis(para_id)) - .with_extensions(Extensions { relay_chain: "kusama-dev".into(), para_id: para_id.into() }) - .with_code( - glutton_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), - ) - .build() + GluttonChainSpec::builder( + glutton_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: "kusama-dev".into(), para_id: para_id.into() }, + ) + .with_name("Glutton Development") + .with_id("glutton_dev") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(glutton_genesis(para_id)) + .build() } pub fn glutton_local_config(para_id: ParaId) -> GluttonChainSpec { #[allow(deprecated)] - GluttonChainSpec::builder() - .with_name("Glutton Local") - .with_id("glutton_local") - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(glutton_genesis(para_id)) - .with_extensions(Extensions { relay_chain: "kusama-local".into(), para_id: para_id.into() }) - .with_code( - glutton_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), - ) - .build() + GluttonChainSpec::builder( + glutton_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: "kusama-local".into(), para_id: para_id.into() }, + ) + .with_name("Glutton Local") + .with_id("glutton_local") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(glutton_genesis(para_id)) + .build() } pub fn glutton_config(para_id: ParaId) -> GluttonChainSpec { let mut properties = sc_chain_spec::Properties::new(); properties.insert("ss58Format".into(), 2.into()); - GluttonChainSpec::builder() - .with_name(format!("Glutton {}", para_id).as_str()) - .with_id(format!("glutton-kusama-{}", para_id).as_str()) - .with_chain_type(ChainType::Live) - .with_genesis_config_patch(glutton_genesis(para_id)) - .with_protocol_id(format!("glutton-kusama-{}", para_id).as_str()) - .with_properties(properties) - .with_extensions(Extensions { relay_chain: "kusama".into(), para_id: para_id.into() }) - .with_code( - glutton_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), - ) - .build() + GluttonChainSpec::builder( + glutton_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: "kusama".into(), para_id: para_id.into() }, + ) + .with_name(format!("Glutton {}", para_id).as_str()) + .with_id(format!("glutton-kusama-{}", para_id).as_str()) + .with_chain_type(ChainType::Live) + .with_genesis_config_patch(glutton_genesis(para_id)) + .with_protocol_id(format!("glutton-kusama-{}", para_id).as_str()) + .with_properties(properties) + .build() } fn glutton_genesis(parachain_id: ParaId) -> serde_json::Value { diff --git a/cumulus/polkadot-parachain/src/chain_spec/penpal.rs b/cumulus/polkadot-parachain/src/chain_spec/penpal.rs index b5831a147a0e..355beea56033 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/penpal.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/penpal.rs @@ -31,46 +31,45 @@ pub fn get_penpal_chain_spec(id: ParaId, relay_chain: &str) -> PenpalChainSpec { properties.insert("tokenDecimals".into(), 12u32.into()); properties.insert("ss58Format".into(), 42u32.into()); - PenpalChainSpec::builder() - .with_name("Penpal Parachain") - .with_id(&format!("penpal-{}", relay_chain.replace("-local", ""))) - .with_chain_type(ChainType::Development) - .with_genesis_config_patch(penpal_testnet_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - id, - )) - .with_extensions(Extensions { + PenpalChainSpec::builder( + penpal_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: relay_chain.into(), // You MUST set this to the correct network! para_id: id.into(), - }) - .with_code( - penpal_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), - ) - .build() + }, + ) + .with_name("Penpal Parachain") + .with_id(&format!("penpal-{}", relay_chain.replace("-local", ""))) + .with_chain_type(ChainType::Development) + .with_genesis_config_patch(penpal_testnet_genesis( + // initial collators. + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + id, + )) + .build() } fn penpal_testnet_genesis( diff --git a/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs b/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs index 0947a8416b75..1031b48ea4ec 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs @@ -28,63 +28,58 @@ use sp_core::{crypto::UncheckedInto, sr25519}; pub type RococoParachainChainSpec = sc_service::GenericChainSpec<(), Extensions>; pub fn rococo_parachain_local_config() -> RococoParachainChainSpec { - #[allow(deprecated)] - RococoParachainChainSpec::builder() - .with_name("Rococo Parachain Local") - .with_id("local_testnet") - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(testnet_genesis( + RococoParachainChainSpec::builder( + rococo_parachain_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: "rococo-local".into(), para_id: 1000 }, + ) + .with_name("Rococo Parachain Local") + .with_id("local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(testnet_genesis( + get_account_id_from_seed::("Alice"), + vec![get_from_seed::("Alice"), get_from_seed::("Bob")], + vec![ get_account_id_from_seed::("Alice"), - vec![get_from_seed::("Alice"), get_from_seed::("Bob")], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - 1000.into(), - )) - .with_extensions(Extensions { relay_chain: "rococo-local".into(), para_id: 1000 }) - .with_code( - rococo_parachain_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), - ) - .build() + 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"), + ], + 1000.into(), + )) + .build() } pub fn staging_rococo_parachain_local_config() -> RococoParachainChainSpec { #[allow(deprecated)] - RococoParachainChainSpec::builder() - .with_name("Staging Rococo Parachain Local") - .with_id("staging_testnet") - .with_chain_type(ChainType::Live) - .with_genesis_config_patch(testnet_genesis( - hex!["9ed7705e3c7da027ba0583a22a3212042f7e715d3c168ba14f1424e2bc111d00"].into(), - vec![ - // $secret//one - hex!["aad9fa2249f87a210a0f93400b7f90e47b810c6d65caa0ca3f5af982904c2a33"] - .unchecked_into(), - // $secret//two - hex!["d47753f0cca9dd8da00c70e82ec4fc5501a69c49a5952a643d18802837c88212"] - .unchecked_into(), - ], - vec![hex!["9ed7705e3c7da027ba0583a22a3212042f7e715d3c168ba14f1424e2bc111d00"].into()], - 1000.into(), - )) - .with_extensions(Extensions { relay_chain: "rococo-local".into(), para_id: 1000 }) - .with_code( - rococo_parachain_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), - ) - .build() + RococoParachainChainSpec::builder( + rococo_parachain_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: "rococo-local".into(), para_id: 1000 }, + ) + .with_name("Staging Rococo Parachain Local") + .with_id("staging_testnet") + .with_chain_type(ChainType::Live) + .with_genesis_config_patch(testnet_genesis( + hex!["9ed7705e3c7da027ba0583a22a3212042f7e715d3c168ba14f1424e2bc111d00"].into(), + vec![ + // $secret//one + hex!["aad9fa2249f87a210a0f93400b7f90e47b810c6d65caa0ca3f5af982904c2a33"] + .unchecked_into(), + // $secret//two + hex!["d47753f0cca9dd8da00c70e82ec4fc5501a69c49a5952a643d18802837c88212"] + .unchecked_into(), + ], + vec![hex!["9ed7705e3c7da027ba0583a22a3212042f7e715d3c168ba14f1424e2bc111d00"].into()], + 1000.into(), + )) + .build() } pub(crate) fn testnet_genesis( diff --git a/cumulus/polkadot-parachain/src/chain_spec/seedling.rs b/cumulus/polkadot-parachain/src/chain_spec/seedling.rs index 4f6e87bb7a80..0d949a2cd7c5 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/seedling.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/seedling.rs @@ -24,20 +24,19 @@ use sp_core::sr25519; pub type SeedlingChainSpec = sc_service::GenericChainSpec<(), Extensions>; pub fn get_seedling_chain_spec() -> SeedlingChainSpec { - SeedlingChainSpec::builder() - .with_name("Seedling Local Testnet") - .with_id("seedling_local_testnet") - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(seedling_testnet_genesis( - get_account_id_from_seed::("Alice"), - 2000.into(), - )) - .with_boot_nodes(Vec::new()) - .with_extensions(Extensions { relay_chain: "westend".into(), para_id: 2000 }) - .with_code( - seedling_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), - ) - .build() + SeedlingChainSpec::builder( + seedling_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: "westend".into(), para_id: 2000 }, + ) + .with_name("Seedling Local Testnet") + .with_id("seedling_local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(seedling_testnet_genesis( + get_account_id_from_seed::("Alice"), + 2000.into(), + )) + .with_boot_nodes(Vec::new()) + .build() } fn seedling_testnet_genesis(root_key: AccountId, parachain_id: ParaId) -> serde_json::Value { diff --git a/cumulus/polkadot-parachain/src/chain_spec/shell.rs b/cumulus/polkadot-parachain/src/chain_spec/shell.rs index 355e44841408..027858cb9747 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/shell.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/shell.rs @@ -22,15 +22,16 @@ use sc_service::ChainType; pub type ShellChainSpec = sc_service::GenericChainSpec<(), Extensions>; pub fn get_shell_chain_spec() -> ShellChainSpec { - ShellChainSpec::builder() - .with_name("Shell Local Testnet") - .with_id("shell_local_testnet") - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(serde_json::json!({ - "parachainInfo": { "parachainId": ParaId::from(1000) } - })) - .with_boot_nodes(Vec::new()) - .with_extensions(Extensions { relay_chain: "westend".into(), para_id: 1000 }) - .with_code(shell_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!")) - .build() + ShellChainSpec::builder( + shell_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + Extensions { relay_chain: "westend".into(), para_id: 1000 }, + ) + .with_name("Shell Local Testnet") + .with_id("shell_local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(serde_json::json!({ + "parachainInfo": { "parachainId": ParaId::from(1000) } + })) + .with_boot_nodes(Vec::new()) + .build() } diff --git a/cumulus/polkadot-parachain/src/command.rs b/cumulus/polkadot-parachain/src/command.rs index a0cbd6f93f61..b1a744ce7663 100644 --- a/cumulus/polkadot-parachain/src/command.rs +++ b/cumulus/polkadot-parachain/src/command.rs @@ -1102,25 +1102,24 @@ mod tests { id: &str, extension: E, ) -> DummyChainSpec { - DummyChainSpec::builder() - .with_name("Dummy local testnet") - .with_id(id) - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(crate::chain_spec::rococo_parachain::testnet_genesis( - get_account_id_from_seed::("Alice"), - vec![ - get_from_seed::("Alice"), - get_from_seed::("Bob"), - ], - vec![get_account_id_from_seed::("Alice")], - 1000.into(), - )) - .with_extensions(extension) - .with_code( - rococo_parachain_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), - ) - .build() + DummyChainSpec::builder( + rococo_parachain_runtime::WASM_BINARY + .expect("WASM binary was not build, please build it!"), + extension, + ) + .with_name("Dummy local testnet") + .with_id(id) + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(crate::chain_spec::rococo_parachain::testnet_genesis( + get_account_id_from_seed::("Alice"), + vec![ + get_from_seed::("Alice"), + get_from_seed::("Bob"), + ], + vec![get_account_id_from_seed::("Alice")], + 1000.into(), + )) + .build() } #[test] diff --git a/polkadot/node/service/src/chain_spec.rs b/polkadot/node/service/src/chain_spec.rs index 0ea01be636b6..e4f2eccbf1b1 100644 --- a/polkadot/node/service/src/chain_spec.rs +++ b/polkadot/node/service/src/chain_spec.rs @@ -977,55 +977,58 @@ pub fn polkadot_chain_spec_properties() -> serde_json::map::Map Result { - Ok(KusamaChainSpec::builder() - .with_name("Kusama Staging Testnet") - .with_id("kusama_staging_testnet") - .with_chain_type(ChainType::Live) - .with_genesis_config_patch(kusama_staging_testnet_config_genesis()) - .with_telemetry_endpoints( - TelemetryEndpoints::new(vec![(KUSAMA_STAGING_TELEMETRY_URL.to_string(), 0)]) - .expect("Kusama Staging telemetry url is valid; qed"), - ) - .with_protocol_id(DEFAULT_PROTOCOL_ID) - .with_extensions(Default::default()) - .with_code(kusama::WASM_BINARY.ok_or("Kusama development wasm not available")?) - .build()) + Ok(KusamaChainSpec::builder( + kusama::WASM_BINARY.ok_or("Kusama development wasm not available")?, + Default::default(), + ) + .with_name("Kusama Staging Testnet") + .with_id("kusama_staging_testnet") + .with_chain_type(ChainType::Live) + .with_genesis_config_patch(kusama_staging_testnet_config_genesis()) + .with_telemetry_endpoints( + TelemetryEndpoints::new(vec![(KUSAMA_STAGING_TELEMETRY_URL.to_string(), 0)]) + .expect("Kusama Staging telemetry url is valid; qed"), + ) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .build()) } /// Westend staging testnet config. #[cfg(feature = "westend-native")] pub fn westend_staging_testnet_config() -> Result { - Ok(WestendChainSpec::builder() - .with_name("Westend Staging Testnet") - .with_id("westend_staging_testnet") - .with_chain_type(ChainType::Live) - .with_genesis_config_patch(westend_staging_testnet_config_genesis()) - .with_telemetry_endpoints( - TelemetryEndpoints::new(vec![(WESTEND_STAGING_TELEMETRY_URL.to_string(), 0)]) - .expect("Westend Staging telemetry url is valid; qed"), - ) - .with_protocol_id(DEFAULT_PROTOCOL_ID) - .with_extensions(Default::default()) - .with_code(westend::WASM_BINARY.ok_or("Westend development wasm not available")?) - .build()) + Ok(WestendChainSpec::builder( + westend::WASM_BINARY.ok_or("Westend development wasm not available")?, + Default::default(), + ) + .with_name("Westend Staging Testnet") + .with_id("westend_staging_testnet") + .with_chain_type(ChainType::Live) + .with_genesis_config_patch(westend_staging_testnet_config_genesis()) + .with_telemetry_endpoints( + TelemetryEndpoints::new(vec![(WESTEND_STAGING_TELEMETRY_URL.to_string(), 0)]) + .expect("Westend Staging telemetry url is valid; qed"), + ) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .build()) } /// Rococo staging testnet config. #[cfg(feature = "rococo-native")] pub fn rococo_staging_testnet_config() -> Result { - Ok(RococoChainSpec::builder() - .with_name("Rococo Staging Testnet") - .with_id("rococo_staging_testnet") - .with_chain_type(ChainType::Live) - .with_genesis_config_patch(rococo_staging_testnet_config_genesis()) - .with_telemetry_endpoints( - TelemetryEndpoints::new(vec![(ROCOCO_STAGING_TELEMETRY_URL.to_string(), 0)]) - .expect("Rococo Staging telemetry url is valid; qed"), - ) - .with_protocol_id(DEFAULT_PROTOCOL_ID) - .with_extensions(Default::default()) - .with_code(rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?) - .build()) + Ok(RococoChainSpec::builder( + rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?, + Default::default(), + ) + .with_name("Rococo Staging Testnet") + .with_id("rococo_staging_testnet") + .with_chain_type(ChainType::Live) + .with_genesis_config_patch(rococo_staging_testnet_config_genesis()) + .with_telemetry_endpoints( + TelemetryEndpoints::new(vec![(ROCOCO_STAGING_TELEMETRY_URL.to_string(), 0)]) + .expect("Rococo Staging telemetry url is valid; qed"), + ) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .build()) } pub fn versi_chain_spec_properties() -> serde_json::map::Map { @@ -1042,20 +1045,21 @@ pub fn versi_chain_spec_properties() -> serde_json::map::Map Result { - Ok(RococoChainSpec::builder() - .with_name("Versi Staging Testnet") - .with_id("versi_staging_testnet") - .with_chain_type(ChainType::Live) - .with_genesis_config_patch(rococo_staging_testnet_config_genesis()) - .with_telemetry_endpoints( - TelemetryEndpoints::new(vec![(VERSI_STAGING_TELEMETRY_URL.to_string(), 0)]) - .expect("Versi Staging telemetry url is valid; qed"), - ) - .with_protocol_id("versi") - .with_properties(versi_chain_spec_properties()) - .with_extensions(Default::default()) - .with_code(rococo::WASM_BINARY.ok_or("Versi development wasm not available")?) - .build()) + Ok(RococoChainSpec::builder( + rococo::WASM_BINARY.ok_or("Versi development wasm not available")?, + Default::default(), + ) + .with_name("Versi Staging Testnet") + .with_id("versi_staging_testnet") + .with_chain_type(ChainType::Live) + .with_genesis_config_patch(rococo_staging_testnet_config_genesis()) + .with_telemetry_endpoints( + TelemetryEndpoints::new(vec![(VERSI_STAGING_TELEMETRY_URL.to_string(), 0)]) + .expect("Versi Staging telemetry url is valid; qed"), + ) + .with_protocol_id("versi") + .with_properties(versi_chain_spec_properties()) + .build()) } /// Helper function to generate a crypto pair from seed @@ -1439,87 +1443,93 @@ fn rococo_development_config_genesis() -> serde_json::Value { /// Polkadot development config (single validator Alice) #[cfg(feature = "polkadot-native")] pub fn polkadot_development_config() -> Result { - Ok(PolkadotChainSpec::builder() - .with_name("Development") - .with_id("polkadot_dev") - .with_chain_type(ChainType::Development) - .with_genesis_config_patch(polkadot_development_config_genesis()) - .with_protocol_id(DEFAULT_PROTOCOL_ID) - .with_properties(polkadot_chain_spec_properties()) - .with_extensions(Default::default()) - .with_code(polkadot::WASM_BINARY.ok_or("Polkadot development wasm not available")?) - .build()) + Ok(PolkadotChainSpec::builder( + polkadot::WASM_BINARY.ok_or("Polkadot development wasm not available")?, + Default::default(), + ) + .with_name("Development") + .with_id("polkadot_dev") + .with_chain_type(ChainType::Development) + .with_genesis_config_patch(polkadot_development_config_genesis()) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .with_properties(polkadot_chain_spec_properties()) + .build()) } /// Kusama development config (single validator Alice) #[cfg(feature = "kusama-native")] pub fn kusama_development_config() -> Result { - Ok(KusamaChainSpec::builder() - .with_name("Development") - .with_id("kusama_dev") - .with_chain_type(ChainType::Development) - .with_genesis_config_patch(kusama_development_config_genesis()) - .with_protocol_id(DEFAULT_PROTOCOL_ID) - .with_extensions(Default::default()) - .with_code(kusama::WASM_BINARY.ok_or("Kusama development wasm not available")?) - .build()) + Ok(KusamaChainSpec::builder( + kusama::WASM_BINARY.ok_or("Kusama development wasm not available")?, + Default::default(), + ) + .with_name("Development") + .with_id("kusama_dev") + .with_chain_type(ChainType::Development) + .with_genesis_config_patch(kusama_development_config_genesis()) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .build()) } /// Westend development config (single validator Alice) #[cfg(feature = "westend-native")] pub fn westend_development_config() -> Result { - Ok(WestendChainSpec::builder() - .with_name("Development") - .with_id("westend_dev") - .with_chain_type(ChainType::Development) - .with_genesis_config_patch(westend_development_config_genesis()) - .with_protocol_id(DEFAULT_PROTOCOL_ID) - .with_extensions(Default::default()) - .with_code(westend::WASM_BINARY.ok_or("Westend development wasm not available")?) - .build()) + Ok(WestendChainSpec::builder( + westend::WASM_BINARY.ok_or("Westend development wasm not available")?, + Default::default(), + ) + .with_name("Development") + .with_id("westend_dev") + .with_chain_type(ChainType::Development) + .with_genesis_config_patch(westend_development_config_genesis()) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .build()) } /// Rococo development config (single validator Alice) #[cfg(feature = "rococo-native")] pub fn rococo_development_config() -> Result { - Ok(RococoChainSpec::builder() - .with_name("Development") - .with_id("rococo_dev") - .with_chain_type(ChainType::Development) - .with_genesis_config_patch(rococo_development_config_genesis()) - .with_protocol_id(DEFAULT_PROTOCOL_ID) - .with_extensions(Default::default()) - .with_code(rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?) - .build()) + Ok(RococoChainSpec::builder( + rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?, + Default::default(), + ) + .with_name("Development") + .with_id("rococo_dev") + .with_chain_type(ChainType::Development) + .with_genesis_config_patch(rococo_development_config_genesis()) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .build()) } /// `Versi` development config (single validator Alice) #[cfg(feature = "rococo-native")] pub fn versi_development_config() -> Result { - Ok(RococoChainSpec::builder() - .with_name("Development") - .with_id("versi_dev") - .with_chain_type(ChainType::Development) - .with_genesis_config_patch(rococo_development_config_genesis()) - .with_protocol_id("versi") - .with_extensions(Default::default()) - .with_code(rococo::WASM_BINARY.ok_or("Versi development wasm not available")?) - .build()) + Ok(RococoChainSpec::builder( + rococo::WASM_BINARY.ok_or("Versi development wasm not available")?, + Default::default(), + ) + .with_name("Development") + .with_id("versi_dev") + .with_chain_type(ChainType::Development) + .with_genesis_config_patch(rococo_development_config_genesis()) + .with_protocol_id("versi") + .build()) } /// Wococo development config (single validator Alice) #[cfg(feature = "rococo-native")] pub fn wococo_development_config() -> Result { const WOCOCO_DEV_PROTOCOL_ID: &str = "woco"; - Ok(RococoChainSpec::builder() - .with_name("Development") - .with_id("wococo_dev") - .with_chain_type(ChainType::Development) - .with_genesis_config_patch(rococo_development_config_genesis()) - .with_protocol_id(WOCOCO_DEV_PROTOCOL_ID) - .with_extensions(Default::default()) - .with_code(rococo::WASM_BINARY.ok_or("Wococo development wasm not available")?) - .build()) + Ok(RococoChainSpec::builder( + rococo::WASM_BINARY.ok_or("Wococo development wasm not available")?, + Default::default(), + ) + .with_name("Development") + .with_id("wococo_dev") + .with_chain_type(ChainType::Development) + .with_genesis_config_patch(rococo_development_config_genesis()) + .with_protocol_id(WOCOCO_DEV_PROTOCOL_ID) + .build()) } #[cfg(feature = "polkadot-native")] @@ -1537,16 +1547,17 @@ fn polkadot_local_testnet_genesis() -> serde_json::Value { /// Polkadot local testnet config (multivalidator Alice + Bob) #[cfg(feature = "polkadot-native")] pub fn polkadot_local_testnet_config() -> Result { - Ok(PolkadotChainSpec::builder() - .with_name("Local Testnet") - .with_id("local_testnet") - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(polkadot_local_testnet_genesis()) - .with_protocol_id(DEFAULT_PROTOCOL_ID) - .with_properties(polkadot_chain_spec_properties()) - .with_extensions(Default::default()) - .with_code(polkadot::WASM_BINARY.ok_or("Polkadot development wasm not available")?) - .build()) + Ok(PolkadotChainSpec::builder( + polkadot::WASM_BINARY.ok_or("Polkadot development wasm not available")?, + Default::default(), + ) + .with_name("Local Testnet") + .with_id("local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(polkadot_local_testnet_genesis()) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .with_properties(polkadot_chain_spec_properties()) + .build()) } #[cfg(feature = "kusama-native")] @@ -1561,15 +1572,16 @@ fn kusama_local_testnet_genesis() -> serde_json::Value { /// Kusama local testnet config (multivalidator Alice + Bob) #[cfg(feature = "kusama-native")] pub fn kusama_local_testnet_config() -> Result { - Ok(KusamaChainSpec::builder() - .with_name("Kusama Local Testnet") - .with_id("kusama_local_testnet") - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(kusama_local_testnet_genesis()) - .with_protocol_id(DEFAULT_PROTOCOL_ID) - .with_extensions(Default::default()) - .with_code(kusama::WASM_BINARY.ok_or("Kusama development wasm not available")?) - .build()) + Ok(KusamaChainSpec::builder( + kusama::WASM_BINARY.ok_or("Kusama development wasm not available")?, + Default::default(), + ) + .with_name("Kusama Local Testnet") + .with_id("kusama_local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(kusama_local_testnet_genesis()) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .build()) } #[cfg(feature = "westend-native")] @@ -1584,15 +1596,16 @@ fn westend_local_testnet_genesis() -> serde_json::Value { /// Westend local testnet config (multivalidator Alice + Bob) #[cfg(feature = "westend-native")] pub fn westend_local_testnet_config() -> Result { - Ok(WestendChainSpec::builder() - .with_name("Westend Local Testnet") - .with_id("westend_local_testnet") - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(westend_local_testnet_genesis()) - .with_protocol_id(DEFAULT_PROTOCOL_ID) - .with_extensions(Default::default()) - .with_code(westend::WASM_BINARY.ok_or("Westend development wasm not available")?) - .build()) + Ok(WestendChainSpec::builder( + westend::WASM_BINARY.ok_or("Westend development wasm not available")?, + Default::default(), + ) + .with_name("Westend Local Testnet") + .with_id("westend_local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(westend_local_testnet_genesis()) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .build()) } #[cfg(feature = "rococo-native")] @@ -1607,15 +1620,16 @@ fn rococo_local_testnet_genesis() -> serde_json::Value { /// Rococo local testnet config (multivalidator Alice + Bob) #[cfg(feature = "rococo-native")] pub fn rococo_local_testnet_config() -> Result { - Ok(RococoChainSpec::builder() - .with_name("Rococo Local Testnet") - .with_id("rococo_local_testnet") - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(rococo_local_testnet_genesis()) - .with_protocol_id(DEFAULT_PROTOCOL_ID) - .with_extensions(Default::default()) - .with_code(rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?) - .build()) + Ok(RococoChainSpec::builder( + rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?, + Default::default(), + ) + .with_name("Rococo Local Testnet") + .with_id("rococo_local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(rococo_local_testnet_genesis()) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .build()) } /// Wococo is a temporary testnet that uses almost the same runtime as rococo. @@ -1636,15 +1650,16 @@ fn wococo_local_testnet_genesis() -> serde_json::Value { /// Wococo local testnet config (multivalidator Alice + Bob + Charlie + Dave) #[cfg(feature = "rococo-native")] pub fn wococo_local_testnet_config() -> Result { - Ok(RococoChainSpec::builder() - .with_name("Wococo Local Testnet") - .with_id("wococo_local_testnet") - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(wococo_local_testnet_genesis()) - .with_protocol_id(DEFAULT_PROTOCOL_ID) - .with_extensions(Default::default()) - .with_code(rococo::WASM_BINARY.ok_or("Wococo development wasm not available")?) - .build()) + Ok(RococoChainSpec::builder( + rococo::WASM_BINARY.ok_or("Wococo development wasm not available")?, + Default::default(), + ) + .with_name("Wococo Local Testnet") + .with_id("wococo_local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(wococo_local_testnet_genesis()) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .build()) } /// `Versi` is a temporary testnet that uses the same runtime as rococo. @@ -1665,15 +1680,16 @@ fn versi_local_testnet_genesis() -> serde_json::Value { /// `Versi` local testnet config (multivalidator Alice + Bob + Charlie + Dave) #[cfg(feature = "rococo-native")] pub fn versi_local_testnet_config() -> Result { - Ok(RococoChainSpec::builder() - .with_name("Versi Local Testnet") - .with_id("versi_local_testnet") - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(versi_local_testnet_genesis()) - .with_protocol_id("versi") - .with_extensions(Default::default()) - .with_code(rococo::WASM_BINARY.ok_or("Versi development wasm not available")?) - .build()) + Ok(RococoChainSpec::builder( + rococo::WASM_BINARY.ok_or("Versi development wasm not available")?, + Default::default(), + ) + .with_name("Versi Local Testnet") + .with_id("versi_local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(versi_local_testnet_genesis()) + .with_protocol_id("versi") + .build()) } #[cfg(any( diff --git a/polkadot/node/test/service/src/chain_spec.rs b/polkadot/node/test/service/src/chain_spec.rs index 0dd06822c41c..5592d3e5699d 100644 --- a/polkadot/node/test/service/src/chain_spec.rs +++ b/polkadot/node/test/service/src/chain_spec.rs @@ -37,18 +37,17 @@ pub type PolkadotChainSpec = sc_service::GenericChainSpec<(), Extensions>; /// Local testnet config (multivalidator Alice + Bob) pub fn polkadot_local_testnet_config() -> PolkadotChainSpec { - PolkadotChainSpec::builder() - .with_name("Local Testnet") - .with_id("local_testnet") - .with_chain_type(ChainType::Local) - .with_genesis_config_patch(polkadot_local_testnet_genesis()) - .with_protocol_id(DEFAULT_PROTOCOL_ID) - .with_extensions(Default::default()) - .with_properties(polkadot_chain_spec_properties()) - .with_code( - polkadot_test_runtime::WASM_BINARY.expect("Wasm binary must be built for testing"), - ) - .build() + PolkadotChainSpec::builder( + polkadot_test_runtime::WASM_BINARY.expect("Wasm binary must be built for testing"), + Default::default(), + ) + .with_name("Local Testnet") + .with_id("local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(polkadot_local_testnet_genesis()) + .with_protocol_id(DEFAULT_PROTOCOL_ID) + .with_properties(polkadot_chain_spec_properties()) + .build() } /// Local testnet genesis config (multivalidator Alice + Bob) diff --git a/substrate/bin/node-template/node/src/chain_spec.rs b/substrate/bin/node-template/node/src/chain_spec.rs index ee5a206e3b95..6e0d78f647a5 100644 --- a/substrate/bin/node-template/node/src/chain_spec.rs +++ b/substrate/bin/node-template/node/src/chain_spec.rs @@ -34,59 +34,61 @@ pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) { } pub fn development_config() -> Result { - Ok(ChainSpec::builder() - .with_name("Development") - .with_id("dev") - .with_chain_type(ChainType::Development) - .with_extensions(None) - .with_code(WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?) - .with_genesis_config_patch(testnet_genesis( - // Initial PoA authorities - vec![authority_keys_from_seed("Alice")], - // Sudo account + Ok(ChainSpec::builder( + WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?, + None, + ) + .with_name("Development") + .with_id("dev") + .with_chain_type(ChainType::Development) + .with_genesis_config_patch(testnet_genesis( + // Initial PoA authorities + vec![authority_keys_from_seed("Alice")], + // Sudo account + get_account_id_from_seed::("Alice"), + // Pre-funded accounts + vec![ get_account_id_from_seed::("Alice"), - // Pre-funded accounts - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - ], - true, - )) - .build()) + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + ], + true, + )) + .build()) } pub fn local_testnet_config() -> Result { - Ok(ChainSpec::builder() - .with_name("Local Testnet") - .with_id("local_testnet") - .with_chain_type(ChainType::Local) - .with_extensions(None) - .with_code(WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?) - .with_genesis_config_patch(testnet_genesis( - // Initial PoA authorities - vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")], - // Sudo account + Ok(ChainSpec::builder( + WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?, + None, + ) + .with_name("Local Testnet") + .with_id("local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(testnet_genesis( + // Initial PoA authorities + vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")], + // Sudo account + get_account_id_from_seed::("Alice"), + // Pre-funded accounts + vec![ get_account_id_from_seed::("Alice"), - // Pre-funded accounts - 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"), - ], - true, - )) - .build()) + 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"), + ], + true, + )) + .build()) } /// Configure initial storage state for FRAME modules. diff --git a/substrate/bin/node/cli/src/chain_spec.rs b/substrate/bin/node/cli/src/chain_spec.rs index f7d5a94659a8..e0397c21ddfc 100644 --- a/substrate/bin/node/cli/src/chain_spec.rs +++ b/substrate/bin/node/cli/src/chain_spec.rs @@ -189,7 +189,7 @@ fn staging_testnet_config_genesis() -> serde_json::Value { /// Staging testnet config. pub fn staging_testnet_config() -> ChainSpec { - ChainSpec::builder() + ChainSpec::builder(wasm_binary_unwrap(), Default::default()) .with_name("Staging Testnet") .with_id("staging_testnet") .with_chain_type(ChainType::Live) @@ -198,8 +198,6 @@ pub fn staging_testnet_config() -> ChainSpec { TelemetryEndpoints::new(vec![(STAGING_TELEMETRY_URL.to_string(), 0)]) .expect("Staging telemetry url is valid; qed"), ) - .with_extensions(Default::default()) - .with_code(wasm_binary_unwrap()) .build() } @@ -384,13 +382,11 @@ fn development_config_genesis_json() -> serde_json::Value { /// Development config (single validator Alice). pub fn development_config() -> ChainSpec { - ChainSpec::builder() + ChainSpec::builder(wasm_binary_unwrap(), Default::default()) .with_name("Development") .with_id("dev") .with_chain_type(ChainType::Development) .with_genesis_config_patch(development_config_genesis_json()) - .with_extensions(Default::default()) - .with_code(wasm_binary_unwrap()) .build() } @@ -405,13 +401,11 @@ fn local_testnet_genesis() -> serde_json::Value { /// Local testnet config (multivalidator Alice + Bob). pub fn local_testnet_config() -> ChainSpec { - ChainSpec::builder() + ChainSpec::builder(wasm_binary_unwrap(), Default::default()) .with_name("Local Testnet") .with_id("local_testnet") .with_chain_type(ChainType::Local) .with_genesis_config_patch(local_testnet_genesis()) - .with_extensions(Default::default()) - .with_code(wasm_binary_unwrap()) .build() } @@ -424,7 +418,7 @@ pub(crate) mod tests { /// Local testnet config (single validator - Alice). pub fn integration_test_config_with_single_authority() -> ChainSpec { - ChainSpec::builder() + ChainSpec::builder(wasm_binary_unwrap(), Default::default()) .with_name("Integration Test") .with_id("test") .with_chain_type(ChainType::Development) @@ -434,20 +428,16 @@ pub(crate) mod tests { get_account_id_from_seed::("Alice"), None, )) - .with_extensions(Default::default()) - .with_code(wasm_binary_unwrap()) .build() } /// Local testnet config (multivalidator Alice + Bob). pub fn integration_test_config_with_two_authorities() -> ChainSpec { - ChainSpec::builder() + ChainSpec::builder(wasm_binary_unwrap(), Default::default()) .with_name("Integration Test") .with_id("test") .with_chain_type(ChainType::Development) .with_genesis_config_patch(local_testnet_genesis()) - .with_extensions(Default::default()) - .with_code(wasm_binary_unwrap()) .build() } diff --git a/substrate/bin/utils/chain-spec-builder/src/lib.rs b/substrate/bin/utils/chain-spec-builder/src/lib.rs index 2f180d72f26f..1d402e56f88a 100644 --- a/substrate/bin/utils/chain-spec-builder/src/lib.rs +++ b/substrate/bin/utils/chain-spec-builder/src/lib.rs @@ -224,7 +224,7 @@ pub fn generate_chain_spec( .map(chain_spec::authority_keys_from_seed) .collect::>(); - chain_spec::ChainSpec::builder() + chain_spec::ChainSpec::builder(kitchensink_runtime::wasm_binary_unwrap(), Default::default()) .with_name("Custom") .with_id("custom") .with_chain_type(sc_chain_spec::ChainType::Live) @@ -234,8 +234,6 @@ pub fn generate_chain_spec( sudo_account, Some(endowed_accounts), )) - .with_extensions(Default::default()) - .with_code(kitchensink_runtime::wasm_binary_unwrap()) .build() .as_json(false) } @@ -316,12 +314,10 @@ pub fn print_seeds( pub fn generate_chain_spec_for_runtime(cmd: &RuntimeCmd) -> Result { let code = fs::read(cmd.runtime_wasm_path.as_path()).expect("wasm blob file is readable"); - let builder = chain_spec::ChainSpec::builder() + let builder = chain_spec::ChainSpec::builder(&code[..], Default::default()) .with_name(&cmd.chain_name[..]) .with_id(&cmd.chain_id[..]) - .with_chain_type(sc_chain_spec::ChainType::Live) - .with_extensions(Default::default()) - .with_code(&code[..]); + .with_chain_type(sc_chain_spec::ChainType::Live); let builder = match cmd.action { GenesisBuildAction::Patch(PatchCmd { ref patch_path }) => { diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index c4287e53b370..17a6fe7b14ad 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -251,54 +251,54 @@ pub type NoExtension = Option<()>; /// Builder for creating [`ChainSpec`] instances. pub struct ChainSpecBuilder { - name: Option, - id: Option, - chain_type: Option, + code: Vec, + extensions: E, + name: String, + id: String, + chain_type: ChainType, + genesis_build_action: GenesisBuildAction, boot_nodes: Option>, telemetry_endpoints: Option, protocol_id: Option, fork_id: Option, properties: Option, - extensions: Option, - code: Option>, - genesis_build_action: Option, _genesis: PhantomData, } impl ChainSpecBuilder { /// Creates a new builder instance with no defaults. - pub fn new() -> Self { + pub fn new(code: &[u8], extensions: E) -> Self { Self { - name: None, - id: None, - chain_type: None, + code: code.into(), + extensions, + name: "Development".to_string(), + id: "dev".to_string(), + chain_type: ChainType::Local, + genesis_build_action: GenesisBuildAction::Patch(Default::default()), boot_nodes: None, telemetry_endpoints: None, protocol_id: None, fork_id: None, properties: None, - extensions: None, - code: None, - genesis_build_action: None, _genesis: Default::default(), } } /// Sets the spec name. This method must be called. pub fn with_name(mut self, name: &str) -> Self { - self.name = Some(name.into()); + self.name = name.into(); self } /// Sets the spec ID. This method must be called. pub fn with_id(mut self, id: &str) -> Self { - self.id = Some(id.into()); + self.id = id.into(); self } /// Sets the type of the chain. This method must be called. pub fn with_chain_type(mut self, chain_type: ChainType) -> Self { - self.chain_type = Some(chain_type); + self.chain_type = chain_type; self } @@ -334,40 +334,40 @@ impl ChainSpecBuilder { /// Sets chain spec extensions. This method must be called. pub fn with_extensions(mut self, extensions: E) -> Self { - self.extensions = Some(extensions); + self.extensions = extensions; self } /// Sets the code. This method must be called. pub fn with_code(mut self, code: &[u8]) -> Self { - self.code = Some(code.into()); + self.code = code.into(); self } /// Sets the JSON patch for runtime's GenesisConfig. pub fn with_genesis_config_patch(mut self, patch: json::Value) -> Self { - self.genesis_build_action = Some(GenesisBuildAction::Patch(patch)); + self.genesis_build_action = GenesisBuildAction::Patch(patch); self } /// Sets the full runtime's GenesisConfig JSON. pub fn with_genesis_config(mut self, config: json::Value) -> Self { - self.genesis_build_action = Some(GenesisBuildAction::Full(config)); + self.genesis_build_action = GenesisBuildAction::Full(config); self } /// Builds a [`ChainSpec`] instance using the provided settings. pub fn build(self) -> ChainSpec { let client_spec = ClientSpec { - name: self.name.expect("with_name must be called."), - id: self.id.expect("with_id must be called."), - chain_type: self.chain_type.expect("with_chain_type must be called."), + name: self.name, + id: self.id, + chain_type: self.chain_type, boot_nodes: self.boot_nodes.unwrap_or(Default::default()), telemetry_endpoints: self.telemetry_endpoints, protocol_id: self.protocol_id, fork_id: self.fork_id, properties: self.properties, - extensions: self.extensions.expect("with_extensions must be called"), + extensions: self.extensions, consensus_engine: (), genesis: Default::default(), code: Default::default(), @@ -376,11 +376,8 @@ impl ChainSpecBuilder { ChainSpec { client_spec, - genesis: GenesisSource::GenesisBuilderApi( - self.genesis_build_action - .expect("with_genesis_config_patch or with_genesis_config must be called."), - ), - code: self.code.expect("with code must be called.").into(), + genesis: GenesisSource::GenesisBuilderApi(self.genesis_build_action), + code: self.code, } } } @@ -508,8 +505,8 @@ impl ChainSpec { } /// Provides a `ChainSpec` builder. - pub fn builder() -> ChainSpecBuilder { - ChainSpecBuilder::new() + pub fn builder(code: &[u8], extensions: E) -> ChainSpecBuilder { + ChainSpecBuilder::new(code, extensions) } } @@ -872,30 +869,31 @@ mod tests { #[test] fn generate_chain_spec_with_patch_works() { - let output: ChainSpec<()> = ChainSpecBuilder::new() - .with_name("TestName") - .with_id("test_id") - .with_extensions(Default::default()) - .with_chain_type(ChainType::Local) - .with_code(substrate_test_runtime::wasm_binary_unwrap().into()) - .with_genesis_config_patch(json!({ - "babe": { - "epochConfig": { - "c": [ - 7, - 10 - ], - "allowed_slots": "PrimaryAndSecondaryPlainSlots" - } - }, - "substrateTest": { - "authorities": [ - AccountKeyring::Ferdie.public().to_ss58check(), - AccountKeyring::Alice.public().to_ss58check() + let output: ChainSpec<()> = ChainSpec::builder( + substrate_test_runtime::wasm_binary_unwrap().into(), + Default::default(), + ) + .with_name("TestName") + .with_id("test_id") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(json!({ + "babe": { + "epochConfig": { + "c": [ + 7, + 10 ], + "allowed_slots": "PrimaryAndSecondaryPlainSlots" } - })) - .build(); + }, + "substrateTest": { + "authorities": [ + AccountKeyring::Ferdie.public().to_ss58check(), + AccountKeyring::Alice.public().to_ss58check() + ], + } + })) + .build(); let actual = output.as_json(false).unwrap(); let actual_raw = output.as_json(true).unwrap(); @@ -918,14 +916,15 @@ mod tests { #[test] fn generate_chain_spec_with_full_config_works() { let j = include_str!("../../../test-utils/runtime/res/default_genesis_config.json"); - let output: ChainSpec<()> = ChainSpecBuilder::new() - .with_name("TestName") - .with_id("test_id") - .with_extensions(Default::default()) - .with_chain_type(ChainType::Local) - .with_code(substrate_test_runtime::wasm_binary_unwrap().into()) - .with_genesis_config(from_str(j).unwrap()) - .build(); + let output: ChainSpec<()> = ChainSpec::builder( + substrate_test_runtime::wasm_binary_unwrap().into(), + Default::default(), + ) + .with_name("TestName") + .with_id("test_id") + .with_chain_type(ChainType::Local) + .with_genesis_config(from_str(j).unwrap()) + .build(); let actual = output.as_json(false).unwrap(); let actual_raw = output.as_json(true).unwrap(); @@ -949,14 +948,15 @@ mod tests { fn chain_spec_as_json_fails_with_invalid_config() { let j = include_str!("../../../test-utils/runtime/res/default_genesis_config_invalid_2.json"); - let output: ChainSpec<()> = ChainSpecBuilder::new() - .with_name("TestName") - .with_id("test_id") - .with_extensions(Default::default()) - .with_chain_type(ChainType::Local) - .with_code(substrate_test_runtime::wasm_binary_unwrap().into()) - .with_genesis_config(from_str(j).unwrap()) - .build(); + let output: ChainSpec<()> = ChainSpec::builder( + substrate_test_runtime::wasm_binary_unwrap().into(), + Default::default(), + ) + .with_name("TestName") + .with_id("test_id") + .with_chain_type(ChainType::Local) + .with_genesis_config(from_str(j).unwrap()) + .build(); assert_eq!( output.as_json(true), @@ -966,22 +966,23 @@ mod tests { #[test] fn chain_spec_as_json_fails_with_invalid_patch() { - let output: ChainSpec<()> = ChainSpecBuilder::new() - .with_name("TestName") - .with_id("test_id") - .with_extensions(Default::default()) - .with_chain_type(ChainType::Local) - .with_code(substrate_test_runtime::wasm_binary_unwrap().into()) - .with_genesis_config_patch(json!({ - "invalid_pallet": {}, - "substrateTest": { - "authorities": [ - AccountKeyring::Ferdie.public().to_ss58check(), - AccountKeyring::Alice.public().to_ss58check() - ], - } - })) - .build(); + let output: ChainSpec<()> = ChainSpec::builder( + substrate_test_runtime::wasm_binary_unwrap().into(), + Default::default(), + ) + .with_name("TestName") + .with_id("test_id") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(json!({ + "invalid_pallet": {}, + "substrateTest": { + "authorities": [ + AccountKeyring::Ferdie.public().to_ss58check(), + AccountKeyring::Alice.public().to_ss58check() + ], + } + })) + .build(); assert!(output.as_json(true).unwrap_err().contains("Invalid JSON blob: unknown field `invalid_pallet`, expected one of `system`, `babe`, `substrateTest`, `balances`")); } diff --git a/substrate/client/cli/src/commands/insert_key.rs b/substrate/client/cli/src/commands/insert_key.rs index 3617b52aa6a1..3d89610b28b1 100644 --- a/substrate/client/cli/src/commands/insert_key.rs +++ b/substrate/client/cli/src/commands/insert_key.rs @@ -127,12 +127,10 @@ mod tests { fn load_spec(&self, _: &str) -> std::result::Result, String> { Ok(Box::new( - GenericChainSpec::<()>::builder() + GenericChainSpec::<()>::builder(Default::default(), NoExtension::None) .with_name("test") .with_id("test_id") - .with_extensions(NoExtension::None) .with_chain_type(ChainType::Development) - .with_code(Default::default()) .with_genesis_config_patch(Default::default()) .build(), )) diff --git a/substrate/client/cli/src/runner.rs b/substrate/client/cli/src/runner.rs index e17a7d669fa5..1707a76cbe78 100644 --- a/substrate/client/cli/src/runner.rs +++ b/substrate/client/cli/src/runner.rs @@ -252,12 +252,10 @@ mod tests { state_pruning: None, blocks_pruning: sc_client_db::BlocksPruning::KeepAll, chain_spec: Box::new( - GenericChainSpec::<()>::builder() + GenericChainSpec::<()>::builder(Default::default(), NoExtension::None) .with_name("test") .with_id("test_id") - .with_extensions(NoExtension::None) .with_chain_type(ChainType::Development) - .with_code(Default::default()) .with_genesis_config_patch(Default::default()) .build(), ), diff --git a/substrate/client/network/src/service.rs b/substrate/client/network/src/service.rs index aca0072a31de..c1df48ad7858 100644 --- a/substrate/client/network/src/service.rs +++ b/substrate/client/network/src/service.rs @@ -943,9 +943,10 @@ where peers: HashSet, ) -> Result<(), String> { let Some(set_id) = self.notification_protocol_ids.get(&protocol) else { - return Err( - format!("Cannot add peers to reserved set of unknown protocol: {}", protocol) - ) + return Err(format!( + "Cannot add peers to reserved set of unknown protocol: {}", + protocol + )) }; let peers = self.split_multiaddr_and_peer_id(peers)?; @@ -974,9 +975,10 @@ where peers: Vec, ) -> Result<(), String> { let Some(set_id) = self.notification_protocol_ids.get(&protocol) else { - return Err( - format!("Cannot remove peers from reserved set of unknown protocol: {}", protocol) - ) + return Err(format!( + "Cannot remove peers from reserved set of unknown protocol: {}", + protocol + )) }; for peer_id in peers.into_iter() { diff --git a/substrate/client/rpc-spec-v2/src/chain_head/chain_head.rs b/substrate/client/rpc-spec-v2/src/chain_head/chain_head.rs index bae7c84df0ed..14364c331e6c 100644 --- a/substrate/client/rpc-spec-v2/src/chain_head/chain_head.rs +++ b/substrate/client/rpc-spec-v2/src/chain_head/chain_head.rs @@ -462,7 +462,8 @@ where follow_subscription: String, operation_id: String, ) -> RpcResult<()> { - let Some(operation) = self.subscriptions.get_operation(&follow_subscription, &operation_id) else { + let Some(operation) = self.subscriptions.get_operation(&follow_subscription, &operation_id) + else { return Ok(()) }; @@ -479,7 +480,8 @@ where follow_subscription: String, operation_id: String, ) -> RpcResult<()> { - let Some(operation) = self.subscriptions.get_operation(&follow_subscription, &operation_id) else { + let Some(operation) = self.subscriptions.get_operation(&follow_subscription, &operation_id) + else { return Ok(()) }; diff --git a/substrate/client/rpc-spec-v2/src/chain_head/chain_head_storage.rs b/substrate/client/rpc-spec-v2/src/chain_head/chain_head_storage.rs index 5e1f38f9a997..48a673f47e3b 100644 --- a/substrate/client/rpc-spec-v2/src/chain_head/chain_head_storage.rs +++ b/substrate/client/rpc-spec-v2/src/chain_head/chain_head_storage.rs @@ -166,9 +166,7 @@ where let mut ret = Vec::with_capacity(self.operation_max_storage_items); for _ in 0..self.operation_max_storage_items { - let Some(key) = keys_iter.next() else { - break - }; + let Some(key) = keys_iter.next() else { break }; let result = match ty { IterQueryType::Value => self.query_storage_value(hash, &key, child_key), diff --git a/substrate/frame/broker/src/dispatchable_impls.rs b/substrate/frame/broker/src/dispatchable_impls.rs index 7c1d5a786b7c..54cf5d71dcad 100644 --- a/substrate/frame/broker/src/dispatchable_impls.rs +++ b/substrate/frame/broker/src/dispatchable_impls.rs @@ -333,12 +333,8 @@ impl Pallet { region.begin = r + 1; contribution.length.saturating_dec(); - let Some(mut pool_record) = InstaPoolHistory::::get(r) else { - continue; - }; - let Some(total_payout) = pool_record.maybe_payout else { - break; - }; + let Some(mut pool_record) = InstaPoolHistory::::get(r) else { continue }; + let Some(total_payout) = pool_record.maybe_payout else { break }; let p = total_payout .saturating_mul(contributed_parts.into()) .checked_div(&pool_record.private_contributions.into()) diff --git a/substrate/frame/broker/src/tick_impls.rs b/substrate/frame/broker/src/tick_impls.rs index d65b8968f3cf..a1a50a61908d 100644 --- a/substrate/frame/broker/src/tick_impls.rs +++ b/substrate/frame/broker/src/tick_impls.rs @@ -95,9 +95,7 @@ impl Pallet { } pub(crate) fn process_revenue() -> bool { - let Some((until, amount)) = T::Coretime::check_notify_revenue_info() else { - return false; - }; + let Some((until, amount)) = T::Coretime::check_notify_revenue_info() else { return false }; let when: Timeslice = (until / T::TimeslicePeriod::get()).saturating_sub(One::one()).saturated_into(); let mut revenue = T::ConvertBalance::convert_back(amount); @@ -289,9 +287,7 @@ impl Pallet { rc_begin: RelayBlockNumberOf, core: CoreIndex, ) { - let Some(workplan) = Workplan::::take((timeslice, core)) else { - return; - }; + let Some(workplan) = Workplan::::take((timeslice, core)) else { return }; let workload = Workload::::get(core); let parts_used = workplan.iter().map(|i| i.mask).fold(CoreMask::void(), |a, i| a | i); let mut workplan = workplan.into_inner(); diff --git a/substrate/frame/safe-mode/src/lib.rs b/substrate/frame/safe-mode/src/lib.rs index ff045b964afb..b8e8378fa9e7 100644 --- a/substrate/frame/safe-mode/src/lib.rs +++ b/substrate/frame/safe-mode/src/lib.rs @@ -398,7 +398,7 @@ pub mod pallet { /// [`EnteredUntil`]. fn on_initialize(current: BlockNumberFor) -> Weight { let Some(limit) = EnteredUntil::::get() else { - return T::WeightInfo::on_initialize_noop(); + return T::WeightInfo::on_initialize_noop() }; if current > limit { From 224b0d3e63e6c59ff78526ce783dae04a064b459 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 4 Sep 2023 11:03:10 +0200 Subject: [PATCH 23/98] __raw -> _raw --- ...__raw.json => substrate_test_runtime_from_config_raw.json} | 0 ...h__raw.json => substrate_test_runtime_from_patch_raw.json} | 0 substrate/client/chain-spec/src/chain_spec.rs | 4 ++-- 3 files changed, 2 insertions(+), 2 deletions(-) rename substrate/client/chain-spec/res/{substrate_test_runtime_from_config__raw.json => substrate_test_runtime_from_config_raw.json} (100%) rename substrate/client/chain-spec/res/{substrate_test_runtime_from_patch__raw.json => substrate_test_runtime_from_patch_raw.json} (100%) diff --git a/substrate/client/chain-spec/res/substrate_test_runtime_from_config__raw.json b/substrate/client/chain-spec/res/substrate_test_runtime_from_config_raw.json similarity index 100% rename from substrate/client/chain-spec/res/substrate_test_runtime_from_config__raw.json rename to substrate/client/chain-spec/res/substrate_test_runtime_from_config_raw.json diff --git a/substrate/client/chain-spec/res/substrate_test_runtime_from_patch__raw.json b/substrate/client/chain-spec/res/substrate_test_runtime_from_patch_raw.json similarity index 100% rename from substrate/client/chain-spec/res/substrate_test_runtime_from_patch__raw.json rename to substrate/client/chain-spec/res/substrate_test_runtime_from_patch_raw.json diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index 17a6fe7b14ad..c843fc7ea495 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -902,7 +902,7 @@ mod tests { from_str::(include_str!("../res/substrate_test_runtime_from_patch.json")) .unwrap(); let expected_raw = - from_str::(include_str!("../res/substrate_test_runtime_from_patch__raw.json")) + from_str::(include_str!("../res/substrate_test_runtime_from_patch_raw.json")) .unwrap(); //wasm blob may change overtime so let's zero it. Also ensure it is there: @@ -933,7 +933,7 @@ mod tests { from_str::(include_str!("../res/substrate_test_runtime_from_config.json")) .unwrap(); let expected_raw = - from_str::(include_str!("../res/substrate_test_runtime_from_config__raw.json")) + from_str::(include_str!("../res/substrate_test_runtime_from_config_raw.json")) .unwrap(); //wasm blob may change overtime so let's zero it. Also ensure it is there: From a784a7237dff726af728253bcdb91239134a4606 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 4 Sep 2023 11:27:45 +0200 Subject: [PATCH 24/98] code review suggestions --- Cargo.lock | 1 + substrate/bin/node/cli/src/chain_spec.rs | 5 +- substrate/bin/node/executor/Cargo.toml | 1 + substrate/bin/node/executor/tests/basic.rs | 5 +- .../tests/res/default_genesis_config.json | 106 +++++++++++++++++- .../bin/utils/chain-spec-builder/bin/main.rs | 8 +- .../chain-spec/src/genesis_config_builder.rs | 4 +- substrate/client/chain-spec/src/lib.rs | 2 +- 8 files changed, 120 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 909bf343eae8..fd013f5f9e57 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8355,6 +8355,7 @@ dependencies = [ "parity-scale-codec", "sc-executor", "scale-info", + "serde_json", "sp-application-crypto", "sp-consensus-babe", "sp-core", diff --git a/substrate/bin/node/cli/src/chain_spec.rs b/substrate/bin/node/cli/src/chain_spec.rs index e0397c21ddfc..ee75b7d75aaa 100644 --- a/substrate/bin/node/cli/src/chain_spec.rs +++ b/substrate/bin/node/cli/src/chain_spec.rs @@ -316,7 +316,7 @@ pub fn testnet_genesis( let (initial_authorities, endowed_accounts, num_endowed_accounts, stakers) = configure_accounts(initial_authorities, initial_nominators, endowed_accounts, STASH); - let json = serde_json::json!({ + serde_json::json!({ "balances": { "balances": endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect::>(), }, @@ -367,8 +367,7 @@ pub fn testnet_genesis( "minCreateBond": 10 * DOLLARS, "minJoinBond": 1 * DOLLARS, }, - }); - json + }) } fn development_config_genesis_json() -> serde_json::Value { diff --git a/substrate/bin/node/executor/Cargo.toml b/substrate/bin/node/executor/Cargo.toml index b503447c6abc..e2864cd71312 100644 --- a/substrate/bin/node/executor/Cargo.toml +++ b/substrate/bin/node/executor/Cargo.toml @@ -48,6 +48,7 @@ sp-consensus-babe = { path = "../../../primitives/consensus/babe" } sp-externalities = { path = "../../../primitives/externalities" } sp-keyring = { path = "../../../primitives/keyring" } sp-runtime = { path = "../../../primitives/runtime" } +serde_json = "1.0.85" [features] stress-test = [] diff --git a/substrate/bin/node/executor/tests/basic.rs b/substrate/bin/node/executor/tests/basic.rs index ea298ce29454..6f3696e3754c 100644 --- a/substrate/bin/node/executor/tests/basic.rs +++ b/substrate/bin/node/executor/tests/basic.rs @@ -869,5 +869,8 @@ fn default_config_as_json_works() { let json = String::from_utf8(r.into()).expect("returned value is json. qed."); let expected = include_str!("res/default_genesis_config.json").to_string(); - assert_eq!(expected, json); + assert_eq!( + serde_json::from_str::(&expected).unwrap(), + serde_json::from_str::(&json).unwrap() + ); } diff --git a/substrate/bin/node/executor/tests/res/default_genesis_config.json b/substrate/bin/node/executor/tests/res/default_genesis_config.json index 1732f4f77c6b..3141402e0807 100644 --- a/substrate/bin/node/executor/tests/res/default_genesis_config.json +++ b/substrate/bin/node/executor/tests/res/default_genesis_config.json @@ -1 +1,105 @@ -{"system":{},"babe":{"authorities":[],"epochConfig":null},"indices":{"indices":[]},"balances":{"balances":[]},"transactionPayment":{"multiplier":"1000000000000000000"},"staking":{"validatorCount":0,"minimumValidatorCount":0,"invulnerables":[],"forceEra":"NotForcing","slashRewardFraction":0,"canceledPayout":0,"stakers":[],"minNominatorBond":0,"minValidatorBond":0,"maxValidatorCount":null,"maxNominatorCount":null},"session":{"keys":[]},"democracy":{},"council":{"members":[]},"technicalCommittee":{"members":[]},"elections":{"members":[]},"technicalMembership":{"members":[]},"grandpa":{"authorities":[]},"treasury":{},"sudo":{"key":null},"imOnline":{"keys":[]},"authorityDiscovery":{"keys":[]},"society":{"pot":0},"vesting":{"vesting":[]},"glutton":{"compute":"0","storage":"0","trashDataCount":0},"assets":{"assets":[],"metadata":[],"accounts":[]},"poolAssets":{"assets":[],"metadata":[],"accounts":[]},"transactionStorage":{"byteFee":10,"entryFee":1000,"storagePeriod":100800},"allianceMotion":{"members":[]},"alliance":{"fellows":[],"allies":[]},"nominationPools":{"minJoinBond":0,"minCreateBond":0,"maxPools":16,"maxMembersPerPool":32,"maxMembers":512,"globalMaxCommission":null},"txPause":{"paused":[]},"safeMode":{"enteredUntil":null}} \ No newline at end of file +{ + "system": {}, + "babe": { + "authorities": [], + "epochConfig": null + }, + "indices": { + "indices": [] + }, + "balances": { + "balances": [] + }, + "transactionPayment": { + "multiplier": "1000000000000000000" + }, + "staking": { + "validatorCount": 0, + "minimumValidatorCount": 0, + "invulnerables": [], + "forceEra": "NotForcing", + "slashRewardFraction": 0, + "canceledPayout": 0, + "stakers": [], + "minNominatorBond": 0, + "minValidatorBond": 0, + "maxValidatorCount": null, + "maxNominatorCount": null + }, + "session": { + "keys": [] + }, + "democracy": {}, + "council": { + "members": [] + }, + "technicalCommittee": { + "members": [] + }, + "elections": { + "members": [] + }, + "technicalMembership": { + "members": [] + }, + "grandpa": { + "authorities": [] + }, + "treasury": {}, + "sudo": { + "key": null + }, + "imOnline": { + "keys": [] + }, + "authorityDiscovery": { + "keys": [] + }, + "society": { + "pot": 0 + }, + "vesting": { + "vesting": [] + }, + "glutton": { + "compute": "0", + "storage": "0", + "trashDataCount": 0 + }, + "assets": { + "assets": [], + "metadata": [], + "accounts": [] + }, + "poolAssets": { + "assets": [], + "metadata": [], + "accounts": [] + }, + "transactionStorage": { + "byteFee": 10, + "entryFee": 1000, + "storagePeriod": 100800 + }, + "allianceMotion": { + "members": [] + }, + "alliance": { + "fellows": [], + "allies": [] + }, + "nominationPools": { + "minJoinBond": 0, + "minCreateBond": 0, + "maxPools": 16, + "maxMembersPerPool": 32, + "maxMembers": 512, + "globalMaxCommission": null + }, + "txPause": { + "paused": [] + }, + "safeMode": { + "enteredUntil": null + } +} diff --git a/substrate/bin/utils/chain-spec-builder/bin/main.rs b/substrate/bin/utils/chain-spec-builder/bin/main.rs index 24ad1dc1e925..3abe1e2aca70 100644 --- a/substrate/bin/utils/chain-spec-builder/bin/main.rs +++ b/substrate/bin/utils/chain-spec-builder/bin/main.rs @@ -99,22 +99,22 @@ fn main() -> Result<(), String> { convert_to_raw, }) => { let mut chain_spec = GenericChainSpec::<()>::from_json_file(input_chain_spec.clone())?; - runtime_wasm_path.clone().and_then(|path| { + if let Some(path) = runtime_wasm_path { chain_spec .set_code(&fs::read(path.as_path()).expect("wasm blob file is readable")[..]) .into() - }); + } chain_spec.as_json(convert_to_raw) }, ChainSpecBuilderCmd::Verify(VerifyCmd { ref input_chain_spec, ref runtime_wasm_path }) => { write_chain_spec = false; let mut chain_spec = GenericChainSpec::<()>::from_json_file(input_chain_spec.clone())?; - runtime_wasm_path.clone().and_then(|path| { + if let Some(path) = runtime_wasm_path { chain_spec .set_code(&fs::read(path.as_path()).expect("wasm blob file is readable")[..]) .into() - }); + }; chain_spec.as_json(true) }, }?; diff --git a/substrate/client/chain-spec/src/genesis_config_builder.rs b/substrate/client/chain-spec/src/genesis_config_builder.rs index ddd9293d4002..1e046ed70b27 100644 --- a/substrate/client/chain-spec/src/genesis_config_builder.rs +++ b/substrate/client/chain-spec/src/genesis_config_builder.rs @@ -47,7 +47,7 @@ impl<'a> GenesisConfigBuilderRuntimeCaller<'a> { pub fn new(code: &'a [u8]) -> Self { GenesisConfigBuilderRuntimeCaller { code: code.into(), - code_hash: sp_core::blake2_256(&code).to_vec(), + code_hash: sp_core::blake2_256(code).to_vec(), executor: WasmExecutor::::builder() .with_allow_missing_host_functions(true) .build(), @@ -73,7 +73,7 @@ impl<'a> GenesisConfigBuilderRuntimeCaller<'a> { pub fn get_default_config(&self) -> core::result::Result { let mut t = BasicExternalities::new_empty(); let call_result = self - .call(&mut t, "GenesisBuilder_create_default_config", &vec![]) + .call(&mut t, "GenesisBuilder_create_default_config", &[]) .map_err(|e| format!("wasm call error {e}"))?; let default_config = Vec::::decode(&mut &call_result[..]) .map_err(|e| format!("scale codec error: {e}"))?; diff --git a/substrate/client/chain-spec/src/lib.rs b/substrate/client/chain-spec/src/lib.rs index 5c78f98c2af7..fe940fd3621d 100644 --- a/substrate/client/chain-spec/src/lib.rs +++ b/substrate/client/chain-spec/src/lib.rs @@ -166,7 +166,7 @@ //! // - `runtimeGenesisConfig` is a json object that can be parsed by compatible runtime. It is a //! // json object the represents full `GenesisConfig` of the runtime. Similar to `runtime`. //! // - `runtimeGenesisConfigPatch` is a json object that can be parsed by compatible runtime. It -//! // contains a patch to default runtime's `GenesisConfig`. It is opaque to the node. +//! // contains a patch to default runtime's `GenesisConfig`. It is opaque to the node. //! // - `raw` is a `json` object with two fields `top` and `children_default`. Each of these //! // fields is a map of `key => value`. These key/value pairs represent the genesis storage. //! // - `stateRootHash` is a single hex encoded hash that represents the genesis hash. The hash From a37017797746010285d6be48f4da60b447b11172 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 4 Sep 2023 13:46:35 +0200 Subject: [PATCH 25/98] json-patch: dependency removed, merging implemented in-place --- Cargo.lock | 1 - substrate/client/chain-spec/Cargo.toml | 1 - substrate/client/chain-spec/src/chain_spec.rs | 2 +- .../chain-spec/src/genesis_config_builder.rs | 2 +- substrate/client/chain-spec/src/json_patch.rs | 171 ++++++++++++++++++ substrate/client/chain-spec/src/lib.rs | 1 + 6 files changed, 174 insertions(+), 4 deletions(-) create mode 100644 substrate/client/chain-spec/src/json_patch.rs diff --git a/Cargo.lock b/Cargo.lock index b12eed69a671..e1e1bb9945df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14637,7 +14637,6 @@ name = "sc-chain-spec" version = "4.0.0-dev" dependencies = [ "array-bytes", - "json-patch", "log", "memmap2", "parity-scale-codec", diff --git a/substrate/client/chain-spec/Cargo.toml b/substrate/client/chain-spec/Cargo.toml index fb5fcfdc4ac9..56b97b5b4e0c 100644 --- a/substrate/client/chain-spec/Cargo.toml +++ b/substrate/client/chain-spec/Cargo.toml @@ -14,7 +14,6 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] } -json-patch = { version = "1.0.0", default-features = false } memmap2 = "0.5.0" serde = { version = "1.0.188", features = ["derive"] } serde_json = "1.0.85" diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index c843fc7ea495..1d07b746f158 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -863,7 +863,7 @@ mod tests { (json!({"code":"0x0"}), json_path!["code"]) }; assert!(json_contains_path(&json, &mut path)); - json_patch::merge(&mut json, &zeroing_patch); + crate::json_patch::merge(&mut json, zeroing_patch); json } diff --git a/substrate/client/chain-spec/src/genesis_config_builder.rs b/substrate/client/chain-spec/src/genesis_config_builder.rs index 1e046ed70b27..89ac84cd3057 100644 --- a/substrate/client/chain-spec/src/genesis_config_builder.rs +++ b/substrate/client/chain-spec/src/genesis_config_builder.rs @@ -115,7 +115,7 @@ impl<'a> GenesisConfigBuilderRuntimeCaller<'a> { /// Please note that the patch may contain full `GenesisConfig`. pub fn get_storage_for_patch(&self, patch: Value) -> core::result::Result { let mut config = self.get_default_config()?; - json_patch::merge(&mut config, &patch); + crate::json_patch::merge(&mut config, patch); self.get_storage_for_config(config) } } diff --git a/substrate/client/chain-spec/src/json_patch.rs b/substrate/client/chain-spec/src/json_patch.rs new file mode 100644 index 000000000000..5b7e473ed033 --- /dev/null +++ b/substrate/client/chain-spec/src/json_patch.rs @@ -0,0 +1,171 @@ +use serde_json::Value; + +/// Recursively merges two JSON objects, `a` and `b`, into a single object. +/// +/// If a key exists in both objects, the value from `b` will override the value from `a`. +/// If a key exists in `b` with a `null` value, it will be removed from `a`. +/// If a key exists only in `b` and not in `a`, it will be added to `a`. +/// +/// # Arguments +/// +/// * `a` - A mutable reference to the target JSON object to merge into. +/// * `b` - The JSON object to merge with `a`. +pub fn merge(a: &mut Value, b: Value) { + match (a, b) { + (Value::Object(a), Value::Object(b)) => + for (k, v) in b { + if v.is_null() { + a.remove(&k); + } else { + merge(a.entry(k).or_insert(Value::Null), v); + } + }, + (a, b) => *a = b, + }; +} + +#[cfg(test)] +mod tests { + use super::*; + use serde_json::json; + + #[test] + fn test1_simple_merge() { + let mut j1 = json!({ "a":123 }); + merge(&mut j1, json!({ "b":256 })); + assert_eq!(j1, json!({ "a":123, "b":256 })); + } + + #[test] + fn test2_patch_simple_merge_nested() { + let mut j1 = json!({ + "a": { + "name": "xxx", + "value": 123 + }, + "b": { "c" : { "inner_name": "yyy" } } + }); + + let j2 = json!({ + "a": { + "keys": ["a", "b", "c" ] + } + }); + + merge(&mut j1, j2); + assert_eq!( + j1, + json!({"a":{"keys":["a","b","c"],"name":"xxx","value":123}, "b": { "c" : { "inner_name": "yyy" } }}) + ); + } + + #[test] + fn test3_patch_overrides_existing_keys() { + let mut j1 = json!({ + "a": { + "name": "xxx", + "value": 123, + "keys": ["d"] + + } + }); + + let j2 = json!({ + "a": { + "keys": ["a", "b", "c" ] + } + }); + + merge(&mut j1, j2); + assert_eq!(j1, json!({"a":{"keys":["a","b","c"],"name":"xxx","value":123}})); + } + + #[test] + fn test4_patch_overrides_existing_keys() { + let mut j1 = json!({ + "a": { + "name": "xxx", + "value": 123, + "b" : { + "inner_name": "yyy" + } + } + }); + + let j2 = json!({ + "a": { + "name": "new_name", + "b" : { + "inner_name": "inner_new_name" + } + } + }); + + merge(&mut j1, j2); + assert_eq!( + j1, + json!({ "a": {"name":"new_name", "value":123, "b" : { "inner_name": "inner_new_name" }} }) + ); + } + + #[test] + fn test5_patch_overrides_existing_nested_keys() { + let mut j1 = json!({ + "a": { + "name": "xxx", + "value": 123, + "b": { + "c": { + "d": { + "name": "yyy", + "value": 256 + } + } + } + }, + }); + + let j2 = json!({ + "a": { + "value": 456, + "b": { + "c": { + "d": { + "name": "new_name" + } + } + } + } + }); + + merge(&mut j1, j2); + assert_eq!( + j1, + json!({ "a": {"name":"xxx", "value":456, "b": { "c": { "d": { "name": "new_name", "value": 256 }}}}}) + ); + } + + #[test] + fn test6_patch_removes_keys_if_null() { + let mut j1 = json!({ + "a": { + "name": "xxx", + "value": 123, + "enum_variant_1": { + "name": "yyy", + } + }, + }); + + let j2 = json!({ + "a": { + "value": 456, + "enum_variant_1": null, + "enum_variant_2": 32, + } + }); + + merge(&mut j1, j2); + assert_eq!(j1, json!({ "a": {"name":"xxx", "value":456, "enum_variant_2": 32 }})); + } +} diff --git a/substrate/client/chain-spec/src/lib.rs b/substrate/client/chain-spec/src/lib.rs index fe940fd3621d..dbe1caac24d8 100644 --- a/substrate/client/chain-spec/src/lib.rs +++ b/substrate/client/chain-spec/src/lib.rs @@ -198,6 +198,7 @@ mod chain_spec; mod extension; mod genesis_block; mod genesis_config_builder; +mod json_patch; pub use self::{ chain_spec::{ChainSpec as GenericChainSpec, ChainSpecBuilder, NoExtension}, From 76c55746de62dd2e4bc2a0dd90b848bbdd65a087 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 4 Sep 2023 14:09:11 +0200 Subject: [PATCH 26/98] license added to new file --- substrate/client/chain-spec/src/json_patch.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/substrate/client/chain-spec/src/json_patch.rs b/substrate/client/chain-spec/src/json_patch.rs index 5b7e473ed033..c3930069a60d 100644 --- a/substrate/client/chain-spec/src/json_patch.rs +++ b/substrate/client/chain-spec/src/json_patch.rs @@ -1,3 +1,23 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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 this program. If not, see . + +//! A helper module providing json patching functions. + use serde_json::Value; /// Recursively merges two JSON objects, `a` and `b`, into a single object. From d18a3935d17bf250d58b430d02d743e034691af3 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 5 Sep 2023 16:19:00 +0200 Subject: [PATCH 27/98] Code review suggestions --- Cargo.lock | 2 -- polkadot/runtime/rococo/build.rs | 18 +++++++----------- substrate/bin/node/executor/Cargo.toml | 1 - substrate/bin/node/executor/tests/basic.rs | 1 - substrate/client/chain-spec/Cargo.toml | 1 - .../chain-spec/src/genesis_config_builder.rs | 2 -- 6 files changed, 7 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e1e1bb9945df..471314b5b104 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8340,7 +8340,6 @@ dependencies = [ "frame-system", "futures", "kitchensink-runtime", - "log", "node-primitives", "node-testing", "pallet-balances", @@ -14643,7 +14642,6 @@ dependencies = [ "sc-chain-spec-derive", "sc-client-api", "sc-executor", - "sc-executor-common", "sc-network", "sc-telemetry", "serde", diff --git a/polkadot/runtime/rococo/build.rs b/polkadot/runtime/rococo/build.rs index b28f3266f03e..3f93de39dfcb 100644 --- a/polkadot/runtime/rococo/build.rs +++ b/polkadot/runtime/rococo/build.rs @@ -23,18 +23,14 @@ const ROCOCO_EPOCH_DURATION_ENV: &str = "ROCOCO_EPOCH_DURATION"; const ROCOCO_FAST_RUNTIME_ENV: &str = "ROCOCO_FAST_RUNTIME"; fn main() { - #[cfg(feature = "std")] - { - let mut builder = - WasmBuilder::new().with_current_project().import_memory().export_heap_base(); + let mut builder = WasmBuilder::new().with_current_project().import_memory().export_heap_base(); - if env::var(ROCOCO_EPOCH_DURATION_ENV).is_ok() | env::var(ROCOCO_FAST_RUNTIME_ENV).is_ok() { - builder = builder.enable_feature("fast-runtime") - }; + if env::var(ROCOCO_EPOCH_DURATION_ENV).is_ok() | env::var(ROCOCO_FAST_RUNTIME_ENV).is_ok() { + builder = builder.enable_feature("fast-runtime") + }; - builder.build(); + builder.build(); - println!("cargo:rerun-if-env-changed={}", ROCOCO_EPOCH_DURATION_ENV); - println!("cargo:rerun-if-env-changed={}", ROCOCO_FAST_RUNTIME_ENV); - } + println!("cargo:rerun-if-env-changed={}", ROCOCO_EPOCH_DURATION_ENV); + println!("cargo:rerun-if-env-changed={}", ROCOCO_FAST_RUNTIME_ENV); } diff --git a/substrate/bin/node/executor/Cargo.toml b/substrate/bin/node/executor/Cargo.toml index e2864cd71312..a32d4c26b5eb 100644 --- a/substrate/bin/node/executor/Cargo.toml +++ b/substrate/bin/node/executor/Cargo.toml @@ -14,7 +14,6 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "3.6.1" } -log = { version = "0.4.17", default-features = false } scale-info = { version = "2.5.0", features = ["derive", "serde"] } frame-benchmarking = { path = "../../../frame/benchmarking" } node-primitives = { path = "../primitives" } diff --git a/substrate/bin/node/executor/tests/basic.rs b/substrate/bin/node/executor/tests/basic.rs index 6f3696e3754c..cbceac04e8ea 100644 --- a/substrate/bin/node/executor/tests/basic.rs +++ b/substrate/bin/node/executor/tests/basic.rs @@ -860,7 +860,6 @@ fn should_import_block_with_test_client() { #[test] fn default_config_as_json_works() { - sp_tracing::try_init_simple(); let mut t = new_test_ext(compact_code_unwrap()); let r = executor_call(&mut t, "GenesisBuilder_create_default_config", &vec![], false) .0 diff --git a/substrate/client/chain-spec/Cargo.toml b/substrate/client/chain-spec/Cargo.toml index 56b97b5b4e0c..c28120e58f90 100644 --- a/substrate/client/chain-spec/Cargo.toml +++ b/substrate/client/chain-spec/Cargo.toml @@ -20,7 +20,6 @@ serde_json = "1.0.85" sc-client-api = { path = "../api" } sc-chain-spec-derive = { path = "derive" } sc-executor = { path = "../executor" } -sc-executor-common = { path = "../../client/executor/common" } sp-io = { default-features = false, path = "../../primitives/io" } sc-network = { path = "../network" } sc-telemetry = { path = "../telemetry" } diff --git a/substrate/client/chain-spec/src/genesis_config_builder.rs b/substrate/client/chain-spec/src/genesis_config_builder.rs index 89ac84cd3057..df3f9ffc6e6c 100644 --- a/substrate/client/chain-spec/src/genesis_config_builder.rs +++ b/substrate/client/chain-spec/src/genesis_config_builder.rs @@ -66,9 +66,7 @@ impl<'a> GenesisConfigBuilderRuntimeCaller<'a> { ) .0 } -} -impl<'a> GenesisConfigBuilderRuntimeCaller<'a> { /// Calls [`sp_genesis_builder::GenesisBuilder::create_default_config`] provided by runtime. pub fn get_default_config(&self) -> core::result::Result { let mut t = BasicExternalities::new_empty(); From 88df79c26ca44b0bb22d18aa6902d8b272f5b88b Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 5 Sep 2023 16:21:01 +0200 Subject: [PATCH 28/98] Update .gitlab-ci.yml Co-authored-by: Javier Viola --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b5cb97231ee7..f2877e6ad964 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,7 +30,7 @@ variables: RUSTY_CACHIER_COMPRESSION_METHOD: zstd NEXTEST_FAILURE_OUTPUT: immediate-final NEXTEST_SUCCESS_OUTPUT: final - ZOMBIENET_IMAGE: "docker.io/paritypr/zombienet:8c572276" + ZOMBIENET_IMAGE: "docker.io/paritypr/zombienet:v1.3.66" DOCKER_IMAGES_VERSION: "${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}" default: From 4b0901452283020f673d61791b5f90f196946c83 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 8 Sep 2023 12:39:19 +0200 Subject: [PATCH 29/98] Update substrate/client/chain-spec/src/chain_spec.rs Co-authored-by: Davide Galassi --- substrate/client/chain-spec/src/chain_spec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index 1d07b746f158..28af63d21ac5 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -284,7 +284,7 @@ impl ChainSpecBuilder { } } - /// Sets the spec name. This method must be called. + /// Sets the spec name. pub fn with_name(mut self, name: &str) -> Self { self.name = name.into(); self From 4f6157ed3266f24f4f2a0e2637d70e814b949730 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 8 Sep 2023 16:40:07 +0200 Subject: [PATCH 30/98] doc fixed --- substrate/client/chain-spec/src/chain_spec.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index 28af63d21ac5..2ac7026981d1 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -290,13 +290,13 @@ impl ChainSpecBuilder { self } - /// Sets the spec ID. This method must be called. + /// Sets the spec ID. pub fn with_id(mut self, id: &str) -> Self { self.id = id.into(); self } - /// Sets the type of the chain. This method must be called. + /// Sets the type of the chain. pub fn with_chain_type(mut self, chain_type: ChainType) -> Self { self.chain_type = chain_type; self @@ -332,13 +332,13 @@ impl ChainSpecBuilder { self } - /// Sets chain spec extensions. This method must be called. + /// Sets chain spec extensions. pub fn with_extensions(mut self, extensions: E) -> Self { self.extensions = extensions; self } - /// Sets the code. This method must be called. + /// Sets the code. pub fn with_code(mut self, code: &[u8]) -> Self { self.code = code.into(); self From 4694e89d34ca3b71672bf65c03f861b1889ec089 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 8 Sep 2023 16:42:45 +0200 Subject: [PATCH 31/98] Apply suggestions from code review Co-authored-by: Davide Galassi --- cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs | 1 + cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs index 041341b57171..1a441c21022c 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs @@ -1354,6 +1354,7 @@ impl_runtime_apis! { Ok(batches) } } + impl sp_genesis_builder::GenesisBuilder for Runtime { fn create_default_config() -> Vec { create_default_config::() diff --git a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs index db0a721f9639..50c5a445c25f 100644 --- a/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs +++ b/cumulus/parachains/runtimes/testing/rococo-parachain/src/lib.rs @@ -797,6 +797,7 @@ impl_runtime_apis! { ParachainSystem::collect_collation_info(header) } } + impl sp_genesis_builder::GenesisBuilder for Runtime { fn create_default_config() -> Vec { create_default_config::() From 4a235469fd7ec4c6575862b0f6428f3601a59b3e Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 8 Sep 2023 17:21:16 +0200 Subject: [PATCH 32/98] merge master fixes --- .../polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs | 6 +++--- .../polkadot-parachain/src/legacy_chain_spec/bridge_hubs.rs | 6 +++--- .../polkadot-parachain/src/legacy_chain_spec/collectives.rs | 2 +- .../polkadot-parachain/src/legacy_chain_spec/contracts.rs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs index 1b6ec1c203ae..4bfaf44c95da 100644 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs @@ -32,11 +32,11 @@ pub type AssetHubWestendChainSpec = sc_service::GenericChainSpec; const ASSET_HUB_POLKADOT_ED: AssetHubBalance = - asset_hub_polkadot_runtime::constants::currency::EXISTENTIAL_DEPOSIT; + parachains_common::polkadot::currency::EXISTENTIAL_DEPOSIT; const ASSET_HUB_KUSAMA_ED: AssetHubBalance = - asset_hub_kusama_runtime::constants::currency::EXISTENTIAL_DEPOSIT; + parachains_common::kusama::currency::EXISTENTIAL_DEPOSIT; const ASSET_HUB_WESTEND_ED: AssetHubBalance = - asset_hub_westend_runtime::constants::currency::EXISTENTIAL_DEPOSIT; + parachains_common::westend::currency::EXISTENTIAL_DEPOSIT; /// Generate the session keys from individual elements. /// diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/bridge_hubs.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/bridge_hubs.rs index 02d5502e290f..53411526629a 100644 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/bridge_hubs.rs +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/bridge_hubs.rs @@ -195,7 +195,7 @@ pub mod rococo { pub(crate) const BRIDGE_HUB_ROCOCO_LOCAL: &str = "bridge-hub-rococo-local"; pub(crate) const BRIDGE_HUB_ROCOCO_DEVELOPMENT: &str = "bridge-hub-rococo-dev"; const BRIDGE_HUB_ROCOCO_ED: BridgeHubBalance = - bridge_hub_rococo_runtime::constants::currency::EXISTENTIAL_DEPOSIT; + parachains_common::rococo::currency::EXISTENTIAL_DEPOSIT; /// Specialized `ChainSpec` for the normal parachain runtime. pub type BridgeHubChainSpec = @@ -373,7 +373,7 @@ pub mod kusama { pub(crate) const BRIDGE_HUB_KUSAMA_LOCAL: &str = "bridge-hub-kusama-local"; pub(crate) const BRIDGE_HUB_KUSAMA_DEVELOPMENT: &str = "bridge-hub-kusama-dev"; const BRIDGE_HUB_KUSAMA_ED: BridgeHubBalance = - bridge_hub_kusama_runtime::constants::currency::EXISTENTIAL_DEPOSIT; + parachains_common::kusama::currency::EXISTENTIAL_DEPOSIT; /// Specialized `ChainSpec` for the normal parachain runtime. pub type BridgeHubChainSpec = @@ -508,7 +508,7 @@ pub mod polkadot { pub(crate) const BRIDGE_HUB_POLKADOT_LOCAL: &str = "bridge-hub-polkadot-local"; pub(crate) const BRIDGE_HUB_POLKADOT_DEVELOPMENT: &str = "bridge-hub-polkadot-dev"; const BRIDGE_HUB_POLKADOT_ED: BridgeHubBalance = - bridge_hub_polkadot_runtime::constants::currency::EXISTENTIAL_DEPOSIT; + parachains_common::polkadot::currency::EXISTENTIAL_DEPOSIT; /// Specialized `ChainSpec` for the normal parachain runtime. pub type BridgeHubChainSpec = diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/collectives.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/collectives.rs index 8a89afb78824..dbb2b83ba48d 100644 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/collectives.rs +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/collectives.rs @@ -26,7 +26,7 @@ pub type CollectivesPolkadotChainSpec = sc_service::GenericChainSpec; const COLLECTIVES_POLKADOT_ED: CollectivesBalance = - collectives_polkadot_runtime::constants::currency::EXISTENTIAL_DEPOSIT; + parachains_common::polkadot::currency::EXISTENTIAL_DEPOSIT; /// Generate the session keys from individual elements. /// diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/contracts.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/contracts.rs index 7998f2176774..18a0140d5108 100644 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/contracts.rs +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/contracts.rs @@ -31,7 +31,7 @@ const CONTRACTS_PARACHAIN_ID: u32 = 1002; /// The existential deposit is determined by the runtime "contracts-rococo". const CONTRACTS_ROCOCO_ED: contracts_rococo_runtime::Balance = - contracts_rococo_runtime::constants::currency::EXISTENTIAL_DEPOSIT; + parachains_common::rococo::currency::EXISTENTIAL_DEPOSIT; pub fn contracts_rococo_development_config() -> ContractsRococoChainSpec { let mut properties = sc_chain_spec::Properties::new(); From ef77c7a6385bfc55375d422644736bcc9956c5a3 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 22 Sep 2023 11:57:00 +0200 Subject: [PATCH 33/98] Cargo.lock updated --- Cargo.lock | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index ccf546b16b6b..389d2c4341fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -774,6 +774,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -866,6 +867,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -961,6 +963,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-offchain", @@ -1859,6 +1862,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-offchain", @@ -1922,6 +1926,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-offchain", @@ -2021,6 +2026,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keyring", @@ -2334,12 +2340,16 @@ version = "2.0.0" dependencies = [ "ansi_term", "clap 4.4.4", + "kitchensink-runtime", + "log", "node-cli", "rand 0.8.5", "sc-chain-spec", "sc-keystore", + "serde_json", "sp-core", "sp-keystore", + "sp-tracing", ] [[package]] @@ -2636,6 +2646,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-offchain", @@ -2846,6 +2857,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -5814,6 +5826,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -6389,7 +6402,9 @@ dependencies = [ "polkadot-service", "rococo-runtime", "rococo-runtime-constants", + "sc-chain-spec", "sc-consensus-grandpa", + "serde_json", "sp-authority-discovery", "sp-consensus-babe", "sp-consensus-beefy", @@ -6804,12 +6819,14 @@ dependencies = [ "parity-scale-codec", "primitive-types", "scale-info", + "serde_json", "sp-api", "sp-authority-discovery", "sp-block-builder", "sp-consensus-babe", "sp-consensus-grandpa", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-offchain", @@ -8287,6 +8304,7 @@ dependencies = [ "parity-scale-codec", "sc-executor", "scale-info", + "serde_json", "sp-application-crypto", "sp-consensus-babe", "sp-core", @@ -8391,6 +8409,7 @@ dependencies = [ "sc-telemetry", "sc-transaction-pool", "sc-transaction-pool-api", + "serde_json", "sp-api", "sp-block-builder", "sp-blockchain", @@ -8442,11 +8461,13 @@ dependencies = [ "pallet-transaction-payment-rpc-runtime-api", "parity-scale-codec", "scale-info", + "serde_json", "sp-api", "sp-block-builder", "sp-consensus-aura", "sp-consensus-grandpa", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -10855,6 +10876,7 @@ dependencies = [ "sc-transaction-pool", "sc-transaction-pool-api", "serde", + "serde_json", "sp-api", "sp-block-builder", "sp-blockchain", @@ -10912,6 +10934,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -11244,6 +11267,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -12626,6 +12650,7 @@ dependencies = [ "sp-consensus-babe", "sp-consensus-beefy", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keyring", @@ -13054,6 +13079,7 @@ dependencies = [ "sp-consensus-babe", "sp-consensus-beefy", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keyring", @@ -14068,6 +14094,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -14153,6 +14180,7 @@ dependencies = [ "sp-consensus-babe", "sp-consensus-beefy", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keyring", @@ -14571,7 +14599,10 @@ dependencies = [ name = "sc-chain-spec" version = "4.0.0-dev" dependencies = [ + "array-bytes", + "log", "memmap2", + "parity-scale-codec", "sc-chain-spec-derive", "sc-client-api", "sc-executor", @@ -14579,10 +14610,16 @@ dependencies = [ "sc-telemetry", "serde", "serde_json", + "sp-application-crypto", "sp-blockchain", + "sp-consensus-babe", "sp-core", + "sp-genesis-builder", + "sp-io", + "sp-keyring", "sp-runtime", "sp-state-machine", + "substrate-test-runtime", ] [[package]] @@ -16096,6 +16133,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -16343,6 +16381,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -17757,6 +17796,7 @@ dependencies = [ "sp-consensus-babe", "sp-consensus-beefy", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keyring", @@ -20286,6 +20326,7 @@ dependencies = [ "sp-consensus-babe", "sp-consensus-beefy", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-keyring", From 21d73f5efa3af395d2b84cbc4cb8badffa91e39b Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 22 Sep 2023 13:50:03 +0200 Subject: [PATCH 34/98] fixes --- cumulus/polkadot-parachain/src/chain_spec/shell.rs | 2 +- cumulus/polkadot-parachain/src/legacy_chain_spec/shell.rs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cumulus/polkadot-parachain/src/chain_spec/shell.rs b/cumulus/polkadot-parachain/src/chain_spec/shell.rs index 936d2312aa97..d4bc6a0639d2 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/shell.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/shell.rs @@ -42,7 +42,7 @@ pub fn get_shell_chain_spec() -> ShellChainSpec { fn shell_testnet_genesis(parachain_id: ParaId, collators: Vec) -> serde_json::Value { serde_json::json!({ - "parachainInfo": { "parachainId": ParaId::from(1000) } + "parachainInfo": { "parachainId": ParaId::from(1000) }, "aura": { "authorities": collators }, }) } diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/shell.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/shell.rs index 9d107ed59c6a..7cba707c732c 100644 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/shell.rs +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/shell.rs @@ -44,7 +44,10 @@ pub fn get_shell_chain_spec() -> ShellChainSpec { ) } -fn shell_testnet_genesis(parachain_id: ParaId) -> shell_runtime::RuntimeGenesisConfig { +fn shell_testnet_genesis( + parachain_id: ParaId, + collators: Vec, +) -> shell_runtime::RuntimeGenesisConfig { shell_runtime::RuntimeGenesisConfig { system: shell_runtime::SystemConfig::default(), parachain_info: shell_runtime::ParachainInfoConfig { parachain_id, ..Default::default() }, From 74689637f1ef69282ab8631e8af392f16a492db5 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 22 Sep 2023 14:36:40 +0200 Subject: [PATCH 35/98] more fixes --- .../src/chain_spec/legacy_chain_spec.rs | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/polkadot/node/service/src/chain_spec/legacy_chain_spec.rs b/polkadot/node/service/src/chain_spec/legacy_chain_spec.rs index d43d0e6e5945..3c12dd89b2c5 100644 --- a/polkadot/node/service/src/chain_spec/legacy_chain_spec.rs +++ b/polkadot/node/service/src/chain_spec/legacy_chain_spec.rs @@ -72,32 +72,14 @@ pub struct Extensions { pub light_sync_state: sc_sync_state_rpc::LightSyncStateExtension, } -// Generic chain spec, in case when we don't have the native runtime. -pub type GenericChainSpec = service::GenericChainSpec<(), Extensions>; - /// The `ChainSpec` parameterized for the westend runtime. #[cfg(feature = "westend-native")] pub type WestendChainSpec = service::GenericChainSpec; -/// The `ChainSpec` parameterized for the westend runtime. -// Dummy chain spec, but that is fine when we don't have the native runtime. -#[cfg(not(feature = "westend-native"))] -pub type WestendChainSpec = GenericChainSpec; - /// The `ChainSpec` parameterized for the rococo runtime. #[cfg(feature = "rococo-native")] pub type RococoChainSpec = service::GenericChainSpec; -/// The `ChainSpec` parameterized for the `versi` runtime. -/// -/// As of now `Versi` will just be a clone of `Rococo`, until we need it to differ. -pub type VersiChainSpec = RococoChainSpec; - -/// The `ChainSpec` parameterized for the rococo runtime. -// Dummy chain spec, but that is fine when we don't have the native runtime. -#[cfg(not(feature = "rococo-native"))] -pub type RococoChainSpec = GenericChainSpec; - /// Extension for the Rococo genesis config to support a custom changes to the genesis state. #[derive(serde::Serialize, serde::Deserialize)] #[cfg(feature = "rococo-native")] From 1459e596c7fd7867e30920169df950b5bc5c0479 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 22 Sep 2023 14:55:37 +0200 Subject: [PATCH 36/98] fix --- cumulus/polkadot-parachain/src/chain_spec/shell.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/polkadot-parachain/src/chain_spec/shell.rs b/cumulus/polkadot-parachain/src/chain_spec/shell.rs index d4bc6a0639d2..f3aa377e3126 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/shell.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/shell.rs @@ -42,7 +42,7 @@ pub fn get_shell_chain_spec() -> ShellChainSpec { fn shell_testnet_genesis(parachain_id: ParaId, collators: Vec) -> serde_json::Value { serde_json::json!({ - "parachainInfo": { "parachainId": ParaId::from(1000) }, + "parachainInfo": { "parachainId": parachain_id}, "aura": { "authorities": collators }, }) } From fbc2b9644335a7bb39c2d5c2e2bb650f950d6fb9 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 27 Sep 2023 12:32:16 +0200 Subject: [PATCH 37/98] merge fixes --- polkadot/runtime/kusama/Cargo.toml | 6 +----- polkadot/runtime/kusama/build.rs | 13 ------------- polkadot/runtime/polkadot/Cargo.toml | 6 +----- polkadot/runtime/polkadot/build.rs | 13 ------------- polkadot/runtime/polkadot/src/lib.rs | 2 -- substrate/bin/node-template/runtime/Cargo.toml | 3 --- 6 files changed, 2 insertions(+), 41 deletions(-) diff --git a/polkadot/runtime/kusama/Cargo.toml b/polkadot/runtime/kusama/Cargo.toml index a3fb9c84887c..ebbcfc71e953 100644 --- a/polkadot/runtime/kusama/Cargo.toml +++ b/polkadot/runtime/kusama/Cargo.toml @@ -344,13 +344,9 @@ try-runtime = [ # A feature that should be enabled when the runtime should be build 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 = [ "disable-genesis-builder", "sp-api/disable-logging" ] +on-chain-release-build = [ "sp-api/disable-logging" ] # Set timing constants (e.g. session period) to faster versions to speed up testing. fast-runtime = [] runtime-metrics = [ "runtime-parachains/runtime-metrics", "sp-io/with-tracing" ] - -# When enabled, the GenesisBuilder API will not be supprted, GenesisConfig shall be -# stripped from the final binary -disable-genesis-builder = [] diff --git a/polkadot/runtime/kusama/build.rs b/polkadot/runtime/kusama/build.rs index c076fa43523f..70042179487b 100644 --- a/polkadot/runtime/kusama/build.rs +++ b/polkadot/runtime/kusama/build.rs @@ -16,23 +16,10 @@ use substrate_wasm_builder::WasmBuilder; -const NO_GENESIS_BUILDER_ENV: &str = "BUILD_NO_GENESIS_BUILDER_SUPPORT"; - fn main() { WasmBuilder::new() .with_current_project() .import_memory() .export_heap_base() .build(); - - if std::env::var(NO_GENESIS_BUILDER_ENV).is_ok() { - WasmBuilder::new() - .with_current_project() - .import_memory() - .export_heap_base() - .enable_feature("disable-genesis-builder") - .set_file_name("kusama_runtime_no_genesis_builder") - .build(); - }; - println!("cargo:rerun-if-env-changed={}", NO_GENESIS_BUILDER_ENV); } diff --git a/polkadot/runtime/polkadot/Cargo.toml b/polkadot/runtime/polkadot/Cargo.toml index 7bd3322b6f53..5e283b496697 100644 --- a/polkadot/runtime/polkadot/Cargo.toml +++ b/polkadot/runtime/polkadot/Cargo.toml @@ -313,13 +313,9 @@ try-runtime = [ # A feature that should be enabled when the runtime should be build 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 = [ "disable-genesis-builder", "sp-api/disable-logging" ] +on-chain-release-build = [ "sp-api/disable-logging" ] # Set timing constants (e.g. session period) to faster versions to speed up testing. fast-runtime = [] runtime-metrics = [ "runtime-parachains/runtime-metrics", "sp-io/with-tracing" ] - -# When enabled, the GenesisBuilder API will not be supprted, GenesisConfig shall be -# stripped from the final binary -disable-genesis-builder = [] diff --git a/polkadot/runtime/polkadot/build.rs b/polkadot/runtime/polkadot/build.rs index 5460ef4bf6ce..48dcb53b3cd8 100644 --- a/polkadot/runtime/polkadot/build.rs +++ b/polkadot/runtime/polkadot/build.rs @@ -16,23 +16,10 @@ use substrate_wasm_builder::WasmBuilder; -const NO_GENESIS_BUILDER_ENV: &str = "BUILD_NO_GENESIS_BUILDER_SUPPORT"; - fn main() { WasmBuilder::new() .with_current_project() .import_memory() .export_heap_base() .build(); - - if std::env::var(NO_GENESIS_BUILDER_ENV).is_ok() { - WasmBuilder::new() - .with_current_project() - .import_memory() - .export_heap_base() - .enable_feature("disable-genesis-builder") - .set_file_name("polkadot_runtime_no_genesis_builder") - .build(); - }; - println!("cargo:rerun-if-env-changed={}", NO_GENESIS_BUILDER_ENV); } diff --git a/polkadot/runtime/polkadot/src/lib.rs b/polkadot/runtime/polkadot/src/lib.rs index 12cf3b0f11b1..c9e3ded6dadd 100644 --- a/polkadot/runtime/polkadot/src/lib.rs +++ b/polkadot/runtime/polkadot/src/lib.rs @@ -44,8 +44,6 @@ use beefy_primitives::ecdsa_crypto::{AuthorityId as BeefyId, Signature as BeefyS use frame_election_provider_support::{ bounds::ElectionBoundsBuilder, generate_solution_type, onchain, SequentialPhragmen, }; -#[cfg(not(feature = "disable-genesis-builder"))] -use frame_support::genesis_builder_helper::{build_config, create_default_config}; use frame_support::{ construct_runtime, genesis_builder_helper::{build_config, create_default_config}, diff --git a/substrate/bin/node-template/runtime/Cargo.toml b/substrate/bin/node-template/runtime/Cargo.toml index b99ae4ef849f..5fb88e79bc5d 100644 --- a/substrate/bin/node-template/runtime/Cargo.toml +++ b/substrate/bin/node-template/runtime/Cargo.toml @@ -120,6 +120,3 @@ try-runtime = [ "sp-runtime/try-runtime", ] experimental = [ "pallet-aura/experimental" ] - -#Enabling this flag will disable GenesisBuilder API implementation in runtime. -disable-genesis-builder = [] From 992af8ff1c20d50fd3b696d02523e78953cea780 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 28 Sep 2023 13:38:50 +0200 Subject: [PATCH 38/98] merging fix --- polkadot/node/service/src/chain_spec/legacy_chain_spec.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/polkadot/node/service/src/chain_spec/legacy_chain_spec.rs b/polkadot/node/service/src/chain_spec/legacy_chain_spec.rs index cedb71387815..7375eb934e4a 100644 --- a/polkadot/node/service/src/chain_spec/legacy_chain_spec.rs +++ b/polkadot/node/service/src/chain_spec/legacy_chain_spec.rs @@ -948,6 +948,7 @@ pub fn westend_testnet_genesis( vesting: westend::VestingConfig { vesting: vec![] }, sudo: westend::SudoConfig { key: Some(root_key) }, hrmp: Default::default(), + treasury: Default::default(), configuration: westend::ConfigurationConfig { config: default_parachains_host_configuration(), }, From c038d26887536000b061ea5cf17fb4f5a6bc6033 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 10 Oct 2023 15:51:51 +0200 Subject: [PATCH 39/98] Cargo.lock update --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index c2a9279a076f..cbb79c02a860 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14527,7 +14527,7 @@ dependencies = [ name = "sc-chain-spec" version = "4.0.0-dev" dependencies = [ - "array-bytes", + "array-bytes 6.1.0", "log", "memmap2", "parity-scale-codec", From 37a97013bcd994e7ba41c2936aff4da48794ab06 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 10 Oct 2023 21:07:52 +0200 Subject: [PATCH 40/98] test fixed --- .../bin/node/executor/tests/res/default_genesis_config.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/substrate/bin/node/executor/tests/res/default_genesis_config.json b/substrate/bin/node/executor/tests/res/default_genesis_config.json index 3141402e0807..caf12a443d36 100644 --- a/substrate/bin/node/executor/tests/res/default_genesis_config.json +++ b/substrate/bin/node/executor/tests/res/default_genesis_config.json @@ -88,6 +88,9 @@ "fellows": [], "allies": [] }, + "mixnet": { + "mixnodes": [] + }, "nominationPools": { "minJoinBond": 0, "minCreateBond": 0, From fb9b3d51ec4a63a916ea86ee6b3e9407f96a4983 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 11 Oct 2023 16:52:05 +0200 Subject: [PATCH 41/98] zombienet dev (fixing test) --- .gitlab-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 61451a9c4620..5a150d5f58fc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,7 +30,8 @@ variables: RUSTY_CACHIER_COMPRESSION_METHOD: zstd NEXTEST_FAILURE_OUTPUT: immediate-final NEXTEST_SUCCESS_OUTPUT: final - ZOMBIENET_IMAGE: "docker.io/paritytech/zombienet:v1.3.69" + # ZOMBIENET_IMAGE: "docker.io/paritytech/zombienet:v1.3.69" + ZOMBIENET_IMAGE: "docker.io/paritypr/zombienet:2df6a12b" DOCKER_IMAGES_VERSION: "${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}" default: From 6f8e1258c34998122de52907915515b298bdbbbd Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 17 Oct 2023 10:29:18 +0200 Subject: [PATCH 42/98] chain-spec doc reworked --- Cargo.lock | 1 + substrate/client/chain-spec/Cargo.toml | 1 + substrate/client/chain-spec/src/chain_spec.rs | 50 +++- substrate/client/chain-spec/src/lib.rs | 259 +++++++++++------- 4 files changed, 197 insertions(+), 114 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7746a4d71f9e..b2401685b5a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14484,6 +14484,7 @@ name = "sc-chain-spec" version = "4.0.0-dev" dependencies = [ "array-bytes 6.1.0", + "docify", "log", "memmap2", "parity-scale-codec", diff --git a/substrate/client/chain-spec/Cargo.toml b/substrate/client/chain-spec/Cargo.toml index ca1f5dd40a99..b11088190d16 100644 --- a/substrate/client/chain-spec/Cargo.toml +++ b/substrate/client/chain-spec/Cargo.toml @@ -30,6 +30,7 @@ sp-runtime = { path = "../../primitives/runtime" } sp-state-machine = { path = "../../primitives/state-machine" } log = { version = "0.4.17", default-features = false } array-bytes = { version = "6.1" } +docify = "0.2.0" [dev-dependencies] substrate-test-runtime = { path = "../../test-utils/runtime" } diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index 2ac7026981d1..407d6bd3407e 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -18,7 +18,6 @@ //! Substrate chain configurations. #![warn(missing_docs)] - use crate::{ extension::GetExtension, ChainType, GenesisConfigBuilderRuntimeCaller as RuntimeCaller, Properties, RuntimeGenesis, @@ -184,23 +183,24 @@ impl From for RawGenesis { } } -/// Represents different options for the GenesisConfig configuration. +/// Represents different formats for the GenesisConfig configuration. #[derive(Serialize, Deserialize)] #[serde(rename_all = "camelCase")] #[serde(deny_unknown_fields)] -enum Genesis { - /// [Deprecated] Contains the JSON representation of G (the native type representing the +pub enum Genesis { + /// (Deprecated) Contains the JSON representation of G (the native type representing the /// runtime GenesisConfig struct) (will be removed with `ChainSpec::from_genesis`). Runtime(G), - /// The genesis storage as raw data. + /// The genesis storage as raw data. Typically raw key-value entries in state. Raw(RawGenesis), /// State root hash of the genesis storage. StateRootHash(StorageData), - /// Represents the full runtime genesis config in JSON format. + /// Represents the explicit and comprehensive runtime genesis config in JSON format. /// The contained object is a JSON blob that can be parsed by a compatible runtime. RuntimeGenesisConfig(json::Value), - /// Represents a patch for the default runtime genesis config in JSON format. - /// The contained value is a JSON object that can be parsed by a compatible runtime. + /// Represents a patch for the default runtime genesis config in JSON format which is + /// essentially a list of keys that are to be customized in runtime genesis config. + /// The contained value is a JSON blob that can be parsed by a compatible runtime. RuntimeGenesisConfigPatch(json::Value), } @@ -867,6 +867,40 @@ mod tests { json } + #[docify::export] + #[test] + fn build_chain_spec_with_patch_works() { + let output: ChainSpec<()> = ChainSpec::builder( + substrate_test_runtime::wasm_binary_unwrap().into(), + Default::default(), + ) + .with_name("TestName") + .with_id("test_id") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(json!({ + "babe": { + "epochConfig": { + "c": [ + 7, + 10 + ], + "allowed_slots": "PrimaryAndSecondaryPlainSlots" + } + }, + "substrateTest": { + "authorities": [ + AccountKeyring::Ferdie.public().to_ss58check(), + AccountKeyring::Alice.public().to_ss58check() + ], + } + })) + .build(); + + let raw_chain_spec = output.as_json(true); + assert!(raw_chain_spec.is_ok()); + } + + #[docify::export] #[test] fn generate_chain_spec_with_patch_works() { let output: ChainSpec<()> = ChainSpec::builder( diff --git a/substrate/client/chain-spec/src/lib.rs b/substrate/client/chain-spec/src/lib.rs index dbe1caac24d8..c977b939712b 100644 --- a/substrate/client/chain-spec/src/lib.rs +++ b/substrate/client/chain-spec/src/lib.rs @@ -16,19 +16,155 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -//! Substrate chain configurations. +#![allow(rustdoc::private_intra_doc_links)] + +//! # Substrate chain configurations. +//! This crate includes structs and utilities for defining configuration files (known as chain +//! specification) for both runtime and node. +//! +//! The chain specification is a JSON file that describes the properties and intial state of the +//! chain. +//! +//! In summary, though not restirced to, the main role of the chain spec is to provide a list of +//! well-known boot nodes for the blockchain network and the means for initializing the genesis +//! storage. This initialization is necessary for creating a genesis block upon which subsequent +//! blocks are built. When the node is launched for the first time, it reads the chain spec, +//! initializes the genesis block, and establishes connections with the boot nodes. +//! +//! It is divided into three main logical sections: +//! - one section details general chain properties, +//! - the other explicitly or indirectly defines the genesis storage, which, in turn, +//! determines the genesis hash of the chain, +//! - third deals with the runtime code. +//! +//! The chain specification consits of the following fields: +//! +//! | Chain spec key | descirption | +//! |---------|---------| +//! |`name`|The human readable name of the chain.| +//! |`id`|The id of the chain.| +//! |`chainType`|The chain type of this chain (refer to [`ChainType`]).| +//! |`bootNodes`|A list of multi addresses that belong to boot nodes of the chain.| +//! |`telemetryEndpoints`|Optional list of `multi address, verbosity` of telemetry endpoints. The verbosity goes from `0` to `9`. With `0` being the mode with the lowest verbosity.| +//! |`protocolId`|Optional networking protocol id that identifies the chain.| +//! |`forkId`|Optional fork id. Should most likely be left empty. Can be used to signal a fork on the network level when two chains have the same genesis hash.| +//! |`properties`|Custom properties. Shall be provided in the form of `key`, `value` json object.| +//! |`consensusEngine`|Deprecated field. Should be ignored.| +//! |`codeSubstitutes`|Optional map of `block_number` to `wasm_code`. More details in material to follow.| +//! ||| +//! |`genesis`|Defines the initial state of the runtime. More details in material to follow.| +//! ||| +//! |`code`|The runtime wasm code blob in hex format.| +//! +//! +//! # Initial runtime state aka genesis storage +//! +//! The `genesis` key of the chain specification definition describes the +//! initial state of the runtime. For example it may contain: +//! - initial list of funded accoumts, +//! - the sudo key, +//! - initial authorities set for consensus, etc. +//! +//! The genesis state can be represented in the formats described by [`chain_spec::Genesis`] +//! enum. It includes: +//! +//! - `runtime` - a JSON object that is an explicit and comprehensive representation of the +//! `RuntimeGenesisConfig` struct. The `RuntimeGenesisConfig` struct is declared by the runtime +//! and opaque to the node. +//! - `runtimeGenesisConfig` - an alias for `runtime`, +//! - `runtimeGenesisConfigPatch` - a JSON object that is partial representation of +//! `RuntimeGenesisConfig` provided by runtime. It contains a patch which is essentially a list of +//! keys that are to be customized in the default runtime's `RuntimeGenesisConfig`. It is opaque +//! to the node. +//! - `raw` is a JSON object with two fields `top` and `children_default`. Each of these fields is a +//! map of `key => value`. These key/value pairs represent the entries in a genesis storage trie. +//! - `stateRootHash` is a single hex encoded hash that represents the genesis hash. The hash type +//! depends on the hash used by the chain. +//! +//! For production or long living chain specification `raw` format is recommended. +//! +//! # From initial state to raw genesis. +//! +//! To generate a raw genesis storage from the JSON representation of the runtime genesis config the +//! node needs to interact with the runtime. +//! +//! This interaction involves passing the runtime genesis config JSON blob to the runtime using the +//! [`sp_genesis_builder::GenesisBuilder::build_config`] function. It is a crucial step for +//! computing the storage root hash, which is a key component in determining the genesis hash. +//! +//! Consequently, the runtime must support the [`sp_genesis_builder::GenesisBuilder`] API to +//! utilize either [`chain_spec::Genesis::RuntimeGenesisConfigPatch`] or +//! [`chain_spec::Genesis::RuntimeGenesisConfig`] formats. +//! +//! This whole process is encapsulated within the implementation of the [`BuildStorage`] trait, +//! which can be accessed through the [`ChainSpec::as_storage_builder`] method. +//! +//! In case of `raw` genesis state the node does not interact with the runtime regarding the +//! computation of initial state. +//! +//! # Optional code mapping +//! Optional map of `block_number` to `wasm_code`. +//! +//! The given `wasm_code` will be used to substitute the on-chain wasm code starting with the +//! given block number until the `spec_version` on-chain changes. The given `wasm_code` should +//! be as close as possible to the on-chain wasm code. A substitute should be used to fix a bug +//! that can not be fixed with a runtime upgrade, if for example the runtime is constantly +//! panicking. Introducing new runtime apis isn't supported, because the node +//! will read the runtime version from the on-chain wasm code. Use this functionality only when +//! there is no other way around it and only patch the problematic bug, the rest should be done +//! with a on-chain runtime upgrade. +//! +//! # JSON chain specification example +//! Example of the full default Substrate chain specification is the following: +//! ``` +//! { +//! "name": "Flaming Fir", +//! "id": "flamingfir9", +//! "chainType": "Live", +//! "bootNodes": [ +//! "/dns/0.flamingfir.paritytech.net/tcp/30333/p2p/12D3KooWLK2gMLhWsYJzjW3q35zAs9FDDVqfqVfVuskiGZGRSMvR", +//! ], +//! "telemetryEndpoints": [ +//! [ +//! "/dns/telemetry.polkadot.io/tcp/443/x-parity-wss/%2Fsubmit%2F", +//! 0 +//! ] +//! ], +//! "protocolId": "fir9", +//! "forkId": "random_fork", +//! "properties": { +//! "tokenDecimals": 15, +//! "tokenSymbol": "FIR" +//! }, +//! "genesis": { "runtime": { ... } }, +//! "codeSubstitutes": [], +//! } +//! ``` //! -//! This crate contains structs and utilities to declare -//! a runtime-specific configuration file (a.k.a chain spec). +//! The [`ChainSpec`] trait represents the API to access values defined in JSON chain specification. +//! +//! # Building a chain specification. +//! The [`ChainSpecBuilder`] shall be used to create an instance of chain specification. Its API +//! allows to configure all fields of the chain spec. For details on how to generate a JSON +//! representation of chain specification refer to [`ChainSpec::as_json`]. +//! +//! The sample code to generate a chain spec is as follows: +#![doc = docify::embed!("src/chain_spec.rs", build_chain_spec_with_patch_works)] +//! The following are the `raw` and plain versions of the chain specification JSON files: +//! ``` +#![doc = include_str!("../res/substrate_test_runtime_from_patch.json")] +//! ``` +//! ``` +#![doc = include_str!("../res/substrate_test_runtime_from_patch_raw.json")] +//! ``` //! -//! Basic chain spec type containing all required parameters is -//! [`GenericChainSpec`]. It can be extended with -//! additional options that contain configuration specific to your chain. -//! Usually the extension is going to be an amalgamate of types exposed -//! by Substrate core modules. To allow the core modules to retrieve -//! their configuration from your extension you should use `ChainSpecExtension` -//! macro exposed by this crate. +//! # Custom chain spec extensions +//! Basic chain spec type containing all required parameters is [`GenericChainSpec`]. It can be +//! extended with additional options that contain configuration specific to your chain. Usually the +//! extension is going to be an amalgamate of types exposed by Substrate core modules. //! +//! To allow the core modules to retrieve their configuration from your extension you should use +//! `ChainSpecExtension` macro exposed by this crate. //! ```rust //! use std::collections::HashMap; //! use sc_chain_spec::{GenericChainSpec, ChainSpecExtension}; @@ -41,13 +177,10 @@ //! pub type MyChainSpec = GenericChainSpec; //! ``` //! -//! Some parameters may require different values depending on the -//! current blockchain height (a.k.a. forks). You can use `ChainSpecGroup` -//! macro and provided [`Forks`](./struct.Forks.html) structure to put -//! such parameters to your chain spec. -//! This will allow to override a single parameter starting at specific -//! block number. -//! +//! Some parameters may require different values depending on the current blockchain height (a.k.a. +//! forks). You can use `ChainSpecGroup` macro and provided [`Forks`](./struct.Forks.html) structure +//! to put such parameters to your chain spec. This will allow to override a single parameter +//! starting at specific block number. //! ```rust //! use sc_chain_spec::{Forks, ChainSpecGroup, ChainSpecExtension, GenericChainSpec}; //! @@ -77,11 +210,9 @@ //! pub type MyChainSpec2 = GenericChainSpec>; //! ``` //! -//! It's also possible to have a set of parameters that is allowed to change -//! with block numbers (i.e. is forkable), and another set that is not subject to changes. -//! This is also possible by declaring an extension that contains `Forks` within it. -//! -//! +//! It's also possible to have a set of parameters that is allowed to change with block numbers +//! (i.e. is forkable), and another set that is not subject to changes. This is also possible by +//! declaring an extension that contains `Forks` within it. //! ```rust //! use serde::{Serialize, Deserialize}; //! use sc_chain_spec::{Forks, GenericChainSpec, ChainSpecGroup, ChainSpecExtension}; @@ -107,90 +238,6 @@ //! pub type MyChainSpec = GenericChainSpec; //! ``` //! -//! # Substrate chain specification format -//! -//! The Substrate chain specification is a `json` file that describes the basics of a chain. Most -//! importantly it lays out the genesis storage which leads to the genesis hash. The default -//! Substrate chain specification format is the following: -//! -//! ```json -//! // The human readable name of the chain. -//! "name": "Flaming Fir", -//! -//! // The id of the chain. -//! "id": "flamingfir9", -//! -//! // The chain type of this chain. -//! // Possible values are `Live`, `Development`, `Local`. -//! "chainType": "Live", -//! -//! // A list of multi addresses that belong to boot nodes of the chain. -//! "bootNodes": [ -//! "/dns/0.flamingfir.paritytech.net/tcp/30333/p2p/12D3KooWLK2gMLhWsYJzjW3q35zAs9FDDVqfqVfVuskiGZGRSMvR", -//! ], -//! -//! // Optional list of "multi address, verbosity" of telemetry endpoints. -//! // The verbosity goes from `0` to `9`. With `0` being the mode with the lowest verbosity. -//! "telemetryEndpoints": [ -//! [ -//! "/dns/telemetry.polkadot.io/tcp/443/x-parity-wss/%2Fsubmit%2F", -//! 0 -//! ] -//! ], -//! -//! // Optional networking protocol id that identifies the chain. -//! "protocolId": "fir9", -//! -//! // Optional fork id. Should most likely be left empty. -//! // Can be used to signal a fork on the network level when two chains have the -//! // same genesis hash. -//! "forkId": "random_fork", -//! -//! // Custom properties. -//! "properties": { -//! "tokenDecimals": 15, -//! "tokenSymbol": "FIR" -//! }, -//! -//! // Deprecated field. Should be ignored. -//! "consensusEngine": null, -//! -//! // The genesis declaration of the chain. -//! // -//! // `runtime`, `runtimeGenesisConfig`, `runtimeGenesisConfigPatch`, `raw`, `stateRootHash` denote -//! // the type of the genesis declaration. -//! // -//! // These declarations are in the following formats: -//! // - `runtime` is a `json` object that can be parsed by a compatible `GenesisConfig`. This -//! // `GenesisConfig` is declared by a runtime and opaque to the node. -//! // - `runtimeGenesisConfig` is a json object that can be parsed by compatible runtime. It is a -//! // json object the represents full `GenesisConfig` of the runtime. Similar to `runtime`. -//! // - `runtimeGenesisConfigPatch` is a json object that can be parsed by compatible runtime. It -//! // contains a patch to default runtime's `GenesisConfig`. It is opaque to the node. -//! // - `raw` is a `json` object with two fields `top` and `children_default`. Each of these -//! // fields is a map of `key => value`. These key/value pairs represent the genesis storage. -//! // - `stateRootHash` is a single hex encoded hash that represents the genesis hash. The hash -//! // type depends on the hash used by the chain. -//! // -//! // Runtime must support `GenesisBuilder` API in order to use `runtimeGenesisConfigPatch` or -//! // `runtimeGenesisConfig`. -//! "genesis": { "runtime": {} }, -//! -//! /// Optional map of `block_number` to `wasm_code`. -//! /// -//! /// The given `wasm_code` will be used to substitute the on-chain wasm code starting with the -//! /// given block number until the `spec_version` on-chain changes. The given `wasm_code` should -//! /// be as close as possible to the on-chain wasm code. A substitute should be used to fix a bug -//! /// that can not be fixed with a runtime upgrade, if for example the runtime is constantly -//! /// panicking. Introducing new runtime apis isn't supported, because the node -//! /// will read the runtime version from the on-chain wasm code. Use this functionality only when -//! /// there is no other way around it and only patch the problematic bug, the rest should be done -//! /// with a on-chain runtime upgrade. -//! "codeSubstitutes": [], -//! ``` -//! -//! See [`ChainSpec`] for a trait representation of the above. -//! //! The chain spec can be extended with other fields that are opaque to the default chain spec. //! Specific node implementations will need to be able to deserialize these extensions. From 6da1de6dfbfd81e830f0e8426ead0cbd516134ac Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Tue, 17 Oct 2023 09:50:30 +0000 Subject: [PATCH 43/98] ".git/.scripts/commands/fmt/fmt.sh" --- substrate/client/chain-spec/src/lib.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/substrate/client/chain-spec/src/lib.rs b/substrate/client/chain-spec/src/lib.rs index c977b939712b..f10b802bf1e8 100644 --- a/substrate/client/chain-spec/src/lib.rs +++ b/substrate/client/chain-spec/src/lib.rs @@ -45,13 +45,14 @@ //! |`id`|The id of the chain.| //! |`chainType`|The chain type of this chain (refer to [`ChainType`]).| //! |`bootNodes`|A list of multi addresses that belong to boot nodes of the chain.| -//! |`telemetryEndpoints`|Optional list of `multi address, verbosity` of telemetry endpoints. The verbosity goes from `0` to `9`. With `0` being the mode with the lowest verbosity.| +//! |`telemetryEndpoints`|Optional list of `multi address, verbosity` of telemetry endpoints. The +//! verbosity goes from `0` to `9`. With `0` being the mode with the lowest verbosity.| //! |`protocolId`|Optional networking protocol id that identifies the chain.| -//! |`forkId`|Optional fork id. Should most likely be left empty. Can be used to signal a fork on the network level when two chains have the same genesis hash.| -//! |`properties`|Custom properties. Shall be provided in the form of `key`, `value` json object.| -//! |`consensusEngine`|Deprecated field. Should be ignored.| -//! |`codeSubstitutes`|Optional map of `block_number` to `wasm_code`. More details in material to follow.| -//! ||| +//! |`forkId`|Optional fork id. Should most likely be left empty. Can be used to signal a fork on +//! the network level when two chains have the same genesis hash.| |`properties`|Custom properties. +//! Shall be provided in the form of `key`, `value` json object.| |`consensusEngine`|Deprecated +//! field. Should be ignored.| |`codeSubstitutes`|Optional map of `block_number` to `wasm_code`. +//! More details in material to follow.| ||| //! |`genesis`|Defines the initial state of the runtime. More details in material to follow.| //! ||| //! |`code`|The runtime wasm code blob in hex format.| @@ -157,7 +158,7 @@ //! ``` #![doc = include_str!("../res/substrate_test_runtime_from_patch_raw.json")] //! ``` -//! +//! //! # Custom chain spec extensions //! Basic chain spec type containing all required parameters is [`GenericChainSpec`]. It can be //! extended with additional options that contain configuration specific to your chain. Usually the @@ -176,7 +177,7 @@ //! //! pub type MyChainSpec = GenericChainSpec; //! ``` -//! +//! //! Some parameters may require different values depending on the current blockchain height (a.k.a. //! forks). You can use `ChainSpecGroup` macro and provided [`Forks`](./struct.Forks.html) structure //! to put such parameters to your chain spec. This will allow to override a single parameter @@ -209,7 +210,7 @@ //! /// A chain spec supporting forkable `Extension`. //! pub type MyChainSpec2 = GenericChainSpec>; //! ``` -//! +//! //! It's also possible to have a set of parameters that is allowed to change with block numbers //! (i.e. is forkable), and another set that is not subject to changes. This is also possible by //! declaring an extension that contains `Forks` within it. @@ -237,7 +238,7 @@ //! //! pub type MyChainSpec = GenericChainSpec; //! ``` -//! +//! //! The chain spec can be extended with other fields that are opaque to the default chain spec. //! Specific node implementations will need to be able to deserialize these extensions. From 987a8d1a79673dacd47564c1923fd7e4a5c608ba Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 17 Oct 2023 14:00:19 +0200 Subject: [PATCH 44/98] doc improvements --- substrate/client/chain-spec/src/lib.rs | 127 ++++++++++++++----------- 1 file changed, 74 insertions(+), 53 deletions(-) diff --git a/substrate/client/chain-spec/src/lib.rs b/substrate/client/chain-spec/src/lib.rs index f10b802bf1e8..8a8a9e322fe5 100644 --- a/substrate/client/chain-spec/src/lib.rs +++ b/substrate/client/chain-spec/src/lib.rs @@ -22,7 +22,7 @@ //! This crate includes structs and utilities for defining configuration files (known as chain //! specification) for both runtime and node. //! -//! The chain specification is a JSON file that describes the properties and intial state of the +//! The chain specification is a JSON file that describes the properties and initial state of the //! chain. //! //! In summary, though not restirced to, the main role of the chain spec is to provide a list of @@ -31,7 +31,7 @@ //! blocks are built. When the node is launched for the first time, it reads the chain spec, //! initializes the genesis block, and establishes connections with the boot nodes. //! -//! It is divided into three main logical sections: +//! JSON chain spec is divided into three main logical sections: //! - one section details general chain properties, //! - the other explicitly or indirectly defines the genesis storage, which, in turn, //! determines the genesis hash of the chain, @@ -39,30 +39,80 @@ //! //! The chain specification consits of the following fields: //! -//! | Chain spec key | descirption | -//! |---------|---------| -//! |`name`|The human readable name of the chain.| -//! |`id`|The id of the chain.| -//! |`chainType`|The chain type of this chain (refer to [`ChainType`]).| -//! |`bootNodes`|A list of multi addresses that belong to boot nodes of the chain.| -//! |`telemetryEndpoints`|Optional list of `multi address, verbosity` of telemetry endpoints. The -//! verbosity goes from `0` to `9`. With `0` being the mode with the lowest verbosity.| -//! |`protocolId`|Optional networking protocol id that identifies the chain.| -//! |`forkId`|Optional fork id. Should most likely be left empty. Can be used to signal a fork on -//! the network level when two chains have the same genesis hash.| |`properties`|Custom properties. -//! Shall be provided in the form of `key`, `value` json object.| |`consensusEngine`|Deprecated -//! field. Should be ignored.| |`codeSubstitutes`|Optional map of `block_number` to `wasm_code`. -//! More details in material to follow.| ||| -//! |`genesis`|Defines the initial state of the runtime. More details in material to follow.| -//! ||| -//! |`code`|The runtime wasm code blob in hex format.| -//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//!
Chain spec keyDescription
nameThe human readable name of the chain.
idThe id of the chain.
chainTypeThe chain type of this chain +//! (refer to +//! +//! ChainType +//! ). +//!
bootNodesA list of multi addresses that belong to boot nodes of the chain.
telemetryEndpointsOptional list of multi address, verbosity of telemetry endpoints. The +//! verbosity goes from 0 to 9. With 0 being the mode with the lowest verbosity.
protocolIdOptional networking protocol id that identifies the chain.
forkIdOptional fork id. Should most likely be left empty. Can be used to signal a fork on +//! the network level when two chains have the same genesis hash.
propertiesCustom properties. Shall be provided in the form of +//! key-value json object. +//!
consensusEngineDeprecated field. Should be ignored.
codeSubstitutesOptional map of block_number to wasm_code More details in +//! material to follow.
genesisDefines the initial state of the runtime. More details in material to follow.
codeThe runtime wasm code blob in hex format.
//! //! # Initial runtime state aka genesis storage //! //! The `genesis` key of the chain specification definition describes the //! initial state of the runtime. For example it may contain: -//! - initial list of funded accoumts, +//! - initial list of funded accounts, //! - the sudo key, //! - initial authorities set for consensus, etc. //! @@ -115,33 +165,6 @@ //! there is no other way around it and only patch the problematic bug, the rest should be done //! with a on-chain runtime upgrade. //! -//! # JSON chain specification example -//! Example of the full default Substrate chain specification is the following: -//! ``` -//! { -//! "name": "Flaming Fir", -//! "id": "flamingfir9", -//! "chainType": "Live", -//! "bootNodes": [ -//! "/dns/0.flamingfir.paritytech.net/tcp/30333/p2p/12D3KooWLK2gMLhWsYJzjW3q35zAs9FDDVqfqVfVuskiGZGRSMvR", -//! ], -//! "telemetryEndpoints": [ -//! [ -//! "/dns/telemetry.polkadot.io/tcp/443/x-parity-wss/%2Fsubmit%2F", -//! 0 -//! ] -//! ], -//! "protocolId": "fir9", -//! "forkId": "random_fork", -//! "properties": { -//! "tokenDecimals": 15, -//! "tokenSymbol": "FIR" -//! }, -//! "genesis": { "runtime": { ... } }, -//! "codeSubstitutes": [], -//! } -//! ``` -//! //! The [`ChainSpec`] trait represents the API to access values defined in JSON chain specification. //! //! # Building a chain specification. @@ -151,14 +174,15 @@ //! //! The sample code to generate a chain spec is as follows: #![doc = docify::embed!("src/chain_spec.rs", build_chain_spec_with_patch_works)] -//! The following are the `raw` and plain versions of the chain specification JSON files: +//! # JSON chain specification example +//! The following are the `raw` and plain versions of the chain specification JSON files, resulting +//! from executing above example: //! ``` #![doc = include_str!("../res/substrate_test_runtime_from_patch.json")] //! ``` //! ``` #![doc = include_str!("../res/substrate_test_runtime_from_patch_raw.json")] //! ``` -//! //! # Custom chain spec extensions //! Basic chain spec type containing all required parameters is [`GenericChainSpec`]. It can be //! extended with additional options that contain configuration specific to your chain. Usually the @@ -177,7 +201,6 @@ //! //! pub type MyChainSpec = GenericChainSpec; //! ``` -//! //! Some parameters may require different values depending on the current blockchain height (a.k.a. //! forks). You can use `ChainSpecGroup` macro and provided [`Forks`](./struct.Forks.html) structure //! to put such parameters to your chain spec. This will allow to override a single parameter @@ -210,7 +233,6 @@ //! /// A chain spec supporting forkable `Extension`. //! pub type MyChainSpec2 = GenericChainSpec>; //! ``` -//! //! It's also possible to have a set of parameters that is allowed to change with block numbers //! (i.e. is forkable), and another set that is not subject to changes. This is also possible by //! declaring an extension that contains `Forks` within it. @@ -238,7 +260,6 @@ //! //! pub type MyChainSpec = GenericChainSpec; //! ``` -//! //! The chain spec can be extended with other fields that are opaque to the default chain spec. //! Specific node implementations will need to be able to deserialize these extensions. From 83a3f73f5b518df472338a78b60dccea2a56a8dd Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 17 Oct 2023 23:19:34 +0200 Subject: [PATCH 45/98] polishing doc --- substrate/client/chain-spec/src/lib.rs | 118 ++++++++++++++++++------- 1 file changed, 84 insertions(+), 34 deletions(-) diff --git a/substrate/client/chain-spec/src/lib.rs b/substrate/client/chain-spec/src/lib.rs index 8a8a9e322fe5..6771f743608b 100644 --- a/substrate/client/chain-spec/src/lib.rs +++ b/substrate/client/chain-spec/src/lib.rs @@ -18,14 +18,17 @@ #![allow(rustdoc::private_intra_doc_links)] -//! # Substrate chain configurations. //! This crate includes structs and utilities for defining configuration files (known as chain //! specification) for both runtime and node. //! -//! The chain specification is a JSON file that describes the properties and initial state of the -//! chain. +//! # Intro: chain specification. //! -//! In summary, though not restirced to, the main role of the chain spec is to provide a list of +//! The chain specification is a collection of information that describes the properties and an +//! initial state of a chain. Typically user interacts with the JSON representation of the chain +//! spec. Internally the chain spec is embodied by [`GenericChainSpec`] struct, specific +//! properties can be accessed using the [`ChainSpec`] trait. +//! +//! In summary, though not restirced to, the primary role of the chain spec is to provide a list of //! well-known boot nodes for the blockchain network and the means for initializing the genesis //! storage. This initialization is necessary for creating a genesis block upon which subsequent //! blocks are built. When the node is launched for the first time, it reads the chain spec, @@ -108,31 +111,68 @@ //! //! //! -//! # Initial runtime state aka genesis storage +//! # `genesis`: initial runtime state +//! +//! All nodes in the network must build subsequent blocks upon exactly the same genesis block. +//! +//! The information configured in the `genesis` section of a chain specification is used to build +//! the genesis storage, which is essential for creating the genesis block, since the block header +//! includes the storage root hash. //! //! The `genesis` key of the chain specification definition describes the //! initial state of the runtime. For example it may contain: //! - initial list of funded accounts, -//! - the sudo key, +//! - the administrative account that controls the sudo key //! - initial authorities set for consensus, etc. //! +//! The compiled WASM blob of the runtime code is stored in the state (and therefore on the chain). +//! As a result, the initial runtime must also be provided within the chain specification (under the +//! `code` field). +//! //! The genesis state can be represented in the formats described by [`chain_spec::Genesis`] //! enum. It includes: +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//! +//!
FormatDescription
runtimeA JSON object that provides an explicit and comprehensive representation of the +//! RuntimeGenesisConfig struct. This struct is declared by the runtime and is opaque +//! to the node.
runtimeGenesisConfigAn alias for the runtime format.
runtimeGenesisConfigPatchA JSON object that offers a partial representation of the +//! RuntimeGenesisConfig +//! provided by the runtime. It contains a patch, which is essentially a list of keys to customize +//! in the default runtime's RuntimeGenesisConfig. It is opaque to the node.
rawA JSON object with two fields: top and children_default Each +//! field is a map of key => value pairs representing entries in a genesis storage +//! trie.
stateRootHashA single hex-encoded hash representing the genesis hash. The hash type +//! depends on the hash used by the chain.
//! -//! - `runtime` - a JSON object that is an explicit and comprehensive representation of the -//! `RuntimeGenesisConfig` struct. The `RuntimeGenesisConfig` struct is declared by the runtime -//! and opaque to the node. -//! - `runtimeGenesisConfig` - an alias for `runtime`, -//! - `runtimeGenesisConfigPatch` - a JSON object that is partial representation of -//! `RuntimeGenesisConfig` provided by runtime. It contains a patch which is essentially a list of -//! keys that are to be customized in the default runtime's `RuntimeGenesisConfig`. It is opaque -//! to the node. -//! - `raw` is a JSON object with two fields `top` and `children_default`. Each of these fields is a -//! map of `key => value`. These key/value pairs represent the entries in a genesis storage trie. -//! - `stateRootHash` is a single hex encoded hash that represents the genesis hash. The hash type -//! depends on the hash used by the chain. -//! -//! For production or long living chain specification `raw` format is recommended. +//! For production or long lasting chain specification `raw` format is recommended. +//! +//! JSON examples in the [following section](#json-chain-specification-example) illustrate the `raw` +//! and `runtimeGenesisConfigPatch` genesis fields. //! //! # From initial state to raw genesis. //! @@ -140,19 +180,29 @@ //! node needs to interact with the runtime. //! //! This interaction involves passing the runtime genesis config JSON blob to the runtime using the -//! [`sp_genesis_builder::GenesisBuilder::build_config`] function. It is a crucial step for -//! computing the storage root hash, which is a key component in determining the genesis hash. +//! [`sp_genesis_builder::GenesisBuilder::build_config`] function. During this operation runtime +//! converts the JSON representation of genesis config into [`sp_io::storage`] items. It is a +//! crucial step for computing the storage root hash, which is a key component in determining the +//! genesis hash. //! //! Consequently, the runtime must support the [`sp_genesis_builder::GenesisBuilder`] API to -//! utilize either [`chain_spec::Genesis::RuntimeGenesisConfigPatch`] or -//! [`chain_spec::Genesis::RuntimeGenesisConfig`] formats. +//! utilize either [`RuntimeGenesisConfigPatch`][patch] or [`RuntimeGenesisConfig`][full] formats. +//! +//! [patch]: chain_spec::Genesis::RuntimeGenesisConfigPatch +//! [full]: chain_spec::Genesis::RuntimeGenesisConfig //! -//! This whole process is encapsulated within the implementation of the [`BuildStorage`] trait, -//! which can be accessed through the [`ChainSpec::as_storage_builder`] method. +//! This entire process is encapsulated within the implementation of the [`BuildStorage`] trait, +//! which can be accessed through the [`ChainSpec::as_storage_builder`] method. There is an +//! intermediate internal helper that facilitates this interaction, +//! [`GenesisConfigBuilderRuntimeCaller`], which serves as a straightforward wrapper for +//! [`sc_executor::WasmExecutor`]. //! //! In case of `raw` genesis state the node does not interact with the runtime regarding the //! computation of initial state. //! +//! The plain and `raw` chain specification JSON blobs can be found in +//! [JSON examples](#json-chain-specification-example) section. +//! //! # Optional code mapping //! Optional map of `block_number` to `wasm_code`. //! @@ -165,24 +215,24 @@ //! there is no other way around it and only patch the problematic bug, the rest should be done //! with a on-chain runtime upgrade. //! -//! The [`ChainSpec`] trait represents the API to access values defined in JSON chain specification. -//! //! # Building a chain specification. //! The [`ChainSpecBuilder`] shall be used to create an instance of chain specification. Its API -//! allows to configure all fields of the chain spec. For details on how to generate a JSON -//! representation of chain specification refer to [`ChainSpec::as_json`]. +//! allows to configure all fields of the chain spec. To generate a JSON representation of chain +//! specification, use [`ChainSpec::as_json`]. //! //! The sample code to generate a chain spec is as follows: #![doc = docify::embed!("src/chain_spec.rs", build_chain_spec_with_patch_works)] //! # JSON chain specification example -//! The following are the `raw` and plain versions of the chain specification JSON files, resulting -//! from executing above example: -//! ``` +//! The following are the plain and `raw` ersions of the chain specification JSON files, resulting +//! from executing of the above [example](#building-a-chain-specification): +//! ```ignore #![doc = include_str!("../res/substrate_test_runtime_from_patch.json")] //! ``` -//! ``` +//! ```ignore #![doc = include_str!("../res/substrate_test_runtime_from_patch_raw.json")] //! ``` +//! The [`ChainSpec`] trait represents the API to access values defined in JSON chain specification. +//! //! # Custom chain spec extensions //! Basic chain spec type containing all required parameters is [`GenericChainSpec`]. It can be //! extended with additional options that contain configuration specific to your chain. Usually the From b23e07330b6eec55c0213a9a3c45809f77e62ba5 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 18 Oct 2023 11:30:34 +0200 Subject: [PATCH 46/98] doc improvements --- substrate/client/chain-spec/src/lib.rs | 42 +++++++++++++------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/substrate/client/chain-spec/src/lib.rs b/substrate/client/chain-spec/src/lib.rs index 6771f743608b..78213f31b442 100644 --- a/substrate/client/chain-spec/src/lib.rs +++ b/substrate/client/chain-spec/src/lib.rs @@ -122,15 +122,15 @@ //! The `genesis` key of the chain specification definition describes the //! initial state of the runtime. For example it may contain: //! - initial list of funded accounts, -//! - the administrative account that controls the sudo key +//! - the administrative account that controls the sudo key, //! - initial authorities set for consensus, etc. //! //! The compiled WASM blob of the runtime code is stored in the state (and therefore on the chain). //! As a result, the initial runtime must also be provided within the chain specification (under the //! `code` field). //! -//! The genesis state can be represented in the formats described by [`chain_spec::Genesis`] -//! enum. It includes: +//! The genesis state can be represented in the formats described by [`GenesisFormat`] +//! enum. In essence, tha most important formats are: //! //! //! @@ -140,31 +140,29 @@ //! //! //! -//! +//! //! -//! -//! -//! -//! +//! RuntimeGenesisConfig struct. Must contain all the keys of the genesis config, no +//! defaults will be used. //! //! -//! +//! //! +//! RuntimeGenesisConfig provided by the runtime. It contains a patch, which is +//! essentially a list of keys to customize in the default runtime's +//! RuntimeGenesisConfig. //! //! -//! +//! //! -//! -//! -//! +//! trie. //! //! //!
runtime +//! runtime +//! A JSON object that provides an explicit and comprehensive representation of the -//! RuntimeGenesisConfig struct. This struct is declared by the runtime and is opaque -//! to the node.
runtimeGenesisConfigAn alias for the runtime format.
runtimeGenesisConfigPatch +//! patch +//! A JSON object that offers a partial representation of the -//! RuntimeGenesisConfig -//! provided by the runtime. It contains a patch, which is essentially a list of keys to customize -//! in the default runtime's RuntimeGenesisConfig. It is opaque to the node.
raw +//! raw +//! A JSON object with two fields: top and children_default Each //! field is a map of key => value pairs representing entries in a genesis storage -//! trie.
stateRootHashA single hex-encoded hash representing the genesis hash. The hash type -//! depends on the hash used by the chain.
@@ -320,7 +318,9 @@ mod genesis_config_builder; mod json_patch; pub use self::{ - chain_spec::{ChainSpec as GenericChainSpec, ChainSpecBuilder, NoExtension}, + chain_spec::{ + ChainSpec as GenericChainSpec, ChainSpecBuilder, Genesis as GenesisFormat, NoExtension, + }, extension::{get_extension, get_extension_mut, Extension, Fork, Forks, GetExtension, Group}, genesis_block::{ construct_genesis_block, resolve_state_version_from_wasm, BuildGenesisBlock, From 6f6596ea1685aee86a1aea0b88209307f3c7a755 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 18 Oct 2023 15:29:21 +0200 Subject: [PATCH 47/98] genesis-builder: implemented for asset-hub-rococo runtime --- .../runtimes/assets/asset-hub-rococo/Cargo.toml | 2 ++ .../runtimes/assets/asset-hub-rococo/src/lib.rs | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml index af0ce6d5814e..4bb726dd831e 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/Cargo.toml @@ -43,6 +43,7 @@ sp-block-builder = { path = "../../../../../substrate/primitives/block-builder", sp-consensus-aura = { path = "../../../../../substrate/primitives/consensus/aura", default-features = false} sp-core = { path = "../../../../../substrate/primitives/core", default-features = false} sp-inherents = { path = "../../../../../substrate/primitives/inherents", default-features = false} +sp-genesis-builder = { path = "../../../../../substrate/primitives/genesis-builder", default-features = false } sp-offchain = { path = "../../../../../substrate/primitives/offchain", default-features = false} sp-runtime = { path = "../../../../../substrate/primitives/runtime", default-features = false} sp-session = { path = "../../../../../substrate/primitives/session", default-features = false} @@ -223,6 +224,7 @@ std = [ "sp-block-builder/std", "sp-consensus-aura/std", "sp-core/std", + "sp-genesis-builder/std", "sp-inherents/std", "sp-offchain/std", "sp-runtime/std", diff --git a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs index 3328ff0edaf4..11530895d623 100644 --- a/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs +++ b/cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs @@ -58,6 +58,7 @@ use codec::{Decode, Encode, MaxEncodedLen}; use frame_support::{ construct_runtime, dispatch::DispatchClass, + genesis_builder_helper::{build_config, create_default_config}, ord_parameter_types, parameter_types, traits::{ AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, EitherOfDiverse, @@ -1451,6 +1452,16 @@ impl_runtime_apis! { Ok(batches) } } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } } cumulus_pallet_parachain_system::register_validate_block! { From 56ec31cabbf448cfe331cf8e6445efd65dd9751e Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 18 Oct 2023 15:30:47 +0200 Subject: [PATCH 48/98] merging improvements --- cumulus/polkadot-parachain/Cargo.toml | 1 + .../src/legacy_chain_spec/asset_hubs.rs | 252 +++++++++++++++++- .../legacy_chain_spec/json_vs_legacy_tests.rs | 8 + 3 files changed, 260 insertions(+), 1 deletion(-) diff --git a/cumulus/polkadot-parachain/Cargo.toml b/cumulus/polkadot-parachain/Cargo.toml index 3c2069c81ef4..c29b7cbb9135 100644 --- a/cumulus/polkadot-parachain/Cargo.toml +++ b/cumulus/polkadot-parachain/Cargo.toml @@ -46,6 +46,7 @@ sp-io = { path = "../../substrate/primitives/io" } sp-core = { path = "../../substrate/primitives/core" } sp-session = { path = "../../substrate/primitives/session" } sc-consensus = { path = "../../substrate/client/consensus/common" } +sp-tracing = { path = "../../substrate/primitives/tracing" } sc-cli = { path = "../../substrate/client/cli" } sc-client-api = { path = "../../substrate/client/api" } sc-executor = { path = "../../substrate/client/executor" } diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs index 4bfaf44c95da..9ccb48d3b9c8 100644 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs @@ -1,4 +1,4 @@ -// Copyright 2019-2022 Parity Technologies (UK) Ltd. +// Copyright (C) Parity Technologies (UK) Ltd. // This file is part of Cumulus. // Cumulus is free software: you can redistribute it and/or modify @@ -30,6 +30,9 @@ pub type AssetHubKusamaChainSpec = sc_service::GenericChainSpec; pub type AssetHubWestendChainSpec = sc_service::GenericChainSpec; +pub type AssetHubRococoChainSpec = + sc_service::GenericChainSpec; +pub type AssetHubWococoChainSpec = AssetHubRococoChainSpec; const ASSET_HUB_POLKADOT_ED: AssetHubBalance = parachains_common::polkadot::currency::EXISTENTIAL_DEPOSIT; @@ -37,6 +40,8 @@ const ASSET_HUB_KUSAMA_ED: AssetHubBalance = parachains_common::kusama::currency::EXISTENTIAL_DEPOSIT; const ASSET_HUB_WESTEND_ED: AssetHubBalance = parachains_common::westend::currency::EXISTENTIAL_DEPOSIT; +const ASSET_HUB_ROCOCO_ED: AssetHubBalance = + parachains_common::westend::currency::EXISTENTIAL_DEPOSIT; /// Generate the session keys from individual elements. /// @@ -54,6 +59,13 @@ pub fn asset_hub_kusama_session_keys(keys: AuraId) -> asset_hub_kusama_runtime:: asset_hub_kusama_runtime::SessionKeys { aura: keys } } +/// Generate the session keys from individual elements. +/// +/// The input must be a tuple of individual keys (a single arg for now since we have just one key). +pub fn asset_hub_rococo_session_keys(keys: AuraId) -> asset_hub_rococo_runtime::SessionKeys { + asset_hub_rococo_runtime::SessionKeys { aura: keys } +} + /// Generate the session keys from individual elements. /// /// The input must be a tuple of individual keys (a single arg for now since we have just one key). @@ -651,3 +663,241 @@ fn asset_hub_westend_genesis( }, } } + +pub fn asset_hub_rococo_development_config() -> AssetHubRococoChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 42.into()); + properties.insert("tokenSymbol".into(), "ROC".into()); + properties.insert("tokenDecimals".into(), 12.into()); + asset_hub_rococo_like_development_config( + properties, + "Rococo Asset Hub Development", + "asset-hub-rococo-dev", + 1000, + ) +} + +pub fn asset_hub_wococo_development_config() -> AssetHubWococoChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 42.into()); + properties.insert("tokenSymbol".into(), "WOC".into()); + properties.insert("tokenDecimals".into(), 12.into()); + asset_hub_rococo_like_development_config( + properties, + "Wococo Asset Hub Development", + "asset-hub-wococo-dev", + 1000, + ) +} + +fn asset_hub_rococo_like_development_config( + properties: sc_chain_spec::Properties, + name: &str, + chain_id: &str, + para_id: u32, +) -> AssetHubRococoChainSpec { + #[allow(deprecated)] + AssetHubRococoChainSpec::from_genesis( + // Name + name, + // ID + chain_id, + ChainType::Local, + move || { + asset_hub_rococo_genesis( + // initial collators. + vec![( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + )], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + ], + para_id.into(), + ) + }, + Vec::new(), + None, + None, + None, + Some(properties), + Extensions { relay_chain: "rococo-dev".into(), para_id }, + asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) +} + +pub fn asset_hub_rococo_local_config() -> AssetHubRococoChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 42.into()); + properties.insert("tokenSymbol".into(), "ROC".into()); + properties.insert("tokenDecimals".into(), 12.into()); + asset_hub_rococo_like_local_config( + properties, + "Rococo Asset Hub Local", + "asset-hub-rococo-local", + 1000, + ) +} + +pub fn asset_hub_wococo_local_config() -> AssetHubWococoChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 42.into()); + properties.insert("tokenSymbol".into(), "WOC".into()); + properties.insert("tokenDecimals".into(), 12.into()); + asset_hub_rococo_like_local_config( + properties, + "Wococo Asset Hub Local", + "asset-hub-wococo-local", + 1000, + ) +} + +fn asset_hub_rococo_like_local_config( + properties: sc_chain_spec::Properties, + name: &str, + chain_id: &str, + para_id: u32, +) -> AssetHubRococoChainSpec { + #[allow(deprecated)] + AssetHubRococoChainSpec::from_genesis( + // Name + name, + // ID + chain_id, + ChainType::Local, + move || { + asset_hub_rococo_genesis( + // initial collators. + vec![ + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + ), + ( + get_account_id_from_seed::("Bob"), + get_collator_keys_from_seed::("Bob"), + ), + ], + vec![ + get_account_id_from_seed::("Alice"), + get_account_id_from_seed::("Bob"), + get_account_id_from_seed::("Charlie"), + get_account_id_from_seed::("Dave"), + get_account_id_from_seed::("Eve"), + get_account_id_from_seed::("Ferdie"), + get_account_id_from_seed::("Alice//stash"), + get_account_id_from_seed::("Bob//stash"), + get_account_id_from_seed::("Charlie//stash"), + get_account_id_from_seed::("Dave//stash"), + get_account_id_from_seed::("Eve//stash"), + get_account_id_from_seed::("Ferdie//stash"), + ], + para_id.into(), + ) + }, + Vec::new(), + None, + None, + None, + Some(properties), + Extensions { relay_chain: "rococo-local".into(), para_id }, + asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) +} + +pub fn asset_hub_rococo_config() -> AssetHubRococoChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 42.into()); + properties.insert("tokenSymbol".into(), "ROC".into()); + properties.insert("tokenDecimals".into(), 12.into()); + asset_hub_rococo_like_local_config(properties, "Rococo Asset Hub", "asset-hub-rococo", 1000) +} + +pub fn asset_hub_wococo_config() -> AssetHubWococoChainSpec { + let mut properties = sc_chain_spec::Properties::new(); + properties.insert("ss58Format".into(), 42.into()); + properties.insert("tokenSymbol".into(), "WOC".into()); + properties.insert("tokenDecimals".into(), 12.into()); + asset_hub_rococo_like_config(properties, "Wococo Asset Hub", "asset-hub-wococo", 1000) +} + +fn asset_hub_rococo_like_config( + properties: sc_chain_spec::Properties, + name: &str, + chain_id: &str, + para_id: u32, +) -> AssetHubRococoChainSpec { + #[allow(deprecated)] + AssetHubRococoChainSpec::from_genesis( + // Name + name, + // ID + chain_id, + ChainType::Live, + move || { + asset_hub_rococo_genesis( + // initial collators. + vec![ + // TODO: add invulnerables? from Rockmine? + ], + Vec::new(), + para_id.into(), + ) + }, + Vec::new(), + None, + None, + None, + Some(properties), + Extensions { relay_chain: "rococo".into(), para_id }, + asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + ) +} + +fn asset_hub_rococo_genesis( + invulnerables: Vec<(AccountId, AuraId)>, + endowed_accounts: Vec, + id: ParaId, +) -> asset_hub_rococo_runtime::RuntimeGenesisConfig { + asset_hub_rococo_runtime::RuntimeGenesisConfig { + system: asset_hub_rococo_runtime::SystemConfig::default(), + balances: asset_hub_rococo_runtime::BalancesConfig { + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, ASSET_HUB_ROCOCO_ED * 524_288)) + .collect(), + }, + parachain_info: asset_hub_rococo_runtime::ParachainInfoConfig { + parachain_id: id, + ..Default::default() + }, + collator_selection: asset_hub_rococo_runtime::CollatorSelectionConfig { + invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + candidacy_bond: ASSET_HUB_ROCOCO_ED * 16, + ..Default::default() + }, + session: asset_hub_rococo_runtime::SessionConfig { + keys: invulnerables + .into_iter() + .map(|(acc, aura)| { + ( + acc.clone(), // account id + acc, // validator id + asset_hub_rococo_session_keys(aura), // session keys + ) + }) + .collect(), + }, + aura: Default::default(), + aura_ext: Default::default(), + parachain_system: Default::default(), + polkadot_xcm: asset_hub_rococo_runtime::PolkadotXcmConfig { + safe_xcm_version: Some(SAFE_XCM_VERSION), + ..Default::default() + }, + } +} diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/json_vs_legacy_tests.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/json_vs_legacy_tests.rs index 15710c109634..c863990a7f82 100644 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/json_vs_legacy_tests.rs +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/json_vs_legacy_tests.rs @@ -22,6 +22,7 @@ macro_rules! test { ($test_name:ident, $tested_fn:expr) => { #[test] fn $test_name() { + sp_tracing::try_init_simple(); let j1 = { use crate::chain_spec::*; $tested_fn.as_json(true).unwrap() @@ -86,3 +87,10 @@ test!( test25, bridge_hubs::polkadot::local_config("bridge-hub-polkadot-local", "Test", "test", 667.into()) ); + +test!(test26, asset_hubs::asset_hub_rococo_development_config()); +test!(test27, asset_hubs::asset_hub_wococo_development_config()); +test!(test28, asset_hubs::asset_hub_rococo_local_config()); +test!(test29, asset_hubs::asset_hub_wococo_local_config()); +test!(test30, asset_hubs::asset_hub_rococo_config()); +test!(test31, asset_hubs::asset_hub_wococo_config()); From aee8fd8a87887d4ed76f4e5abe0280dd17947257 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 18 Oct 2023 15:31:46 +0200 Subject: [PATCH 49/98] Cargo.lock udpated --- Cargo.lock | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 69f1e36afd46..47ca56794455 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -878,6 +878,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -12603,6 +12604,7 @@ dependencies = [ "sp-runtime", "sp-session", "sp-timestamp", + "sp-tracing", "sp-transaction-pool", "staging-xcm", "substrate-build-script-utils", From 5a7e2c1e0731ea95c4ac06a8cb39eeea62619fea Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 18 Oct 2023 16:01:57 +0200 Subject: [PATCH 50/98] fix --- .../polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs index 9ccb48d3b9c8..ba5511f365ad 100644 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs @@ -842,6 +842,13 @@ fn asset_hub_rococo_like_config( // initial collators. vec![ // TODO: add invulnerables? from Rockmine? + // This is just a stub to avoid runtime failure: + // ERROR runtime: panicked at 'Empty validator set for session 0 in genesis + // block!' + ( + get_account_id_from_seed::("Alice"), + get_collator_keys_from_seed::("Alice"), + ), ], Vec::new(), para_id.into(), From b40484a2fbd5d99469173eb6b5a3daa164a2fbf4 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 18 Oct 2023 17:37:04 +0200 Subject: [PATCH 51/98] substrate-doc: added chain-spec to umbrella crate --- substrate/Cargo.toml | 1 + substrate/src/lib.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/substrate/Cargo.toml b/substrate/Cargo.toml index d77f02c60603..b53a4ca089a6 100644 --- a/substrate/Cargo.toml +++ b/substrate/Cargo.toml @@ -16,6 +16,7 @@ subkey = { path = "bin/utils/subkey" } chain-spec-builder = { path = "bin/utils/chain-spec-builder" } sc-service = { path = "client/service" } +sc-chain-spec = { path = "client/chain-spec" } sc-cli = { path = "client/cli" } sc-consensus-aura = { path = "client/consensus/aura" } sc-consensus-babe = { path = "client/consensus/babe" } diff --git a/substrate/src/lib.rs b/substrate/src/lib.rs index 409515ea505b..76e688274c62 100644 --- a/substrate/src/lib.rs +++ b/substrate/src/lib.rs @@ -129,8 +129,9 @@ //! side features. The corresponding runtime, called [`kitchensink_runtime`] contains all of the //! modules that are provided with `FRAME`. This node and runtime is only used for testing and //! demonstration. -//! * [`chain-spec-builder`]: Utility to build more detailed chain-specs for the aforementioned -//! node. Other projects typically contain a `build-spec` subcommand that does the same. +//! * [`chain-spec-builder`]: Utility to build more detailed [chain-spec][`sc-chain-spec`] for the +//! aforementioned node. Other projects typically contain a `build-spec` subcommand that does the +//! same. //! * [`node-template`]: a template node that contains a minimal set of features and can act as a //! starting point of a project. //! * [`subkey`]: Substrate's key management utility. @@ -164,6 +165,8 @@ //! //! Additional noteworthy crates within substrate: //! +//! - Chain specification of a Substrate node: +//! - [`sc-chain-spec`] //! - RPC APIs of a Substrate node: [`sc-rpc-api`]/[`sc-rpc`] //! - CLI Options of a Substrate node: [`sc-cli`] //! - All of the consensus related crates provided by Substrate: @@ -203,6 +206,7 @@ //! [`sp-api`]: ../sp_api/index.html //! [`sp-api`]: ../sp_api/index.html //! [`sc-client-db`]: ../sc_client_db/index.html +//! [`sc-chain-spec`]: ../sc_chain_spec/index.html //! [`sc-network`]: ../sc_network/index.html //! [`sc-rpc-api`]: ../sc_rpc_api/index.html //! [`sc-rpc`]: ../sc_rpc/index.html From 3c62e17eabc3a42121bec5656b69ec36927adadd Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 18 Oct 2023 17:38:27 +0200 Subject: [PATCH 52/98] Cargo.lock --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.lock b/Cargo.lock index 47ca56794455..768757e674b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17847,6 +17847,7 @@ dependencies = [ "aquamarine", "chain-spec-builder", "frame-support", + "sc-chain-spec", "sc-cli", "sc-consensus-aura", "sc-consensus-babe", From f57a227ace849e8058016bdf6d8fe95d08fa6f01 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 18 Oct 2023 22:33:44 +0200 Subject: [PATCH 53/98] code review - doc fixes Co-authored-by: Kevin Krone --- substrate/client/chain-spec/src/lib.rs | 84 +++++++++++++------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/substrate/client/chain-spec/src/lib.rs b/substrate/client/chain-spec/src/lib.rs index 78213f31b442..3846a14fbe48 100644 --- a/substrate/client/chain-spec/src/lib.rs +++ b/substrate/client/chain-spec/src/lib.rs @@ -21,26 +21,26 @@ //! This crate includes structs and utilities for defining configuration files (known as chain //! specification) for both runtime and node. //! -//! # Intro: chain specification. +//! # Intro: Chain Specification //! -//! The chain specification is a collection of information that describes the properties and an -//! initial state of a chain. Typically user interacts with the JSON representation of the chain -//! spec. Internally the chain spec is embodied by [`GenericChainSpec`] struct, specific +//! The chain specification comprises parameters and settings that define the properties and an +//! initial state of a chain. Users typically interact with the JSON representation of the chain +//! spec. Internally, the chain spec is embodied by the [`GenericChainSpec`] struct, and specific //! properties can be accessed using the [`ChainSpec`] trait. //! -//! In summary, though not restirced to, the primary role of the chain spec is to provide a list of +//! In summary, although not restricted to, the primary role of the chain spec is to provide a list of //! well-known boot nodes for the blockchain network and the means for initializing the genesis //! storage. This initialization is necessary for creating a genesis block upon which subsequent //! blocks are built. When the node is launched for the first time, it reads the chain spec, //! initializes the genesis block, and establishes connections with the boot nodes. //! -//! JSON chain spec is divided into three main logical sections: +//! The JSON chain spec is divided into three main logical sections: //! - one section details general chain properties, -//! - the other explicitly or indirectly defines the genesis storage, which, in turn, -//! determines the genesis hash of the chain, -//! - third deals with the runtime code. +//! - another explicitly or indirectly defines the genesis storage, which, in turn, +//! determines the genesis hash of the chain, +//! - the third deals with the runtime code. //! -//! The chain specification consits of the following fields: +//! The chain specification consists of the following fields: //! //! //! @@ -111,7 +111,7 @@ //! //!
//! -//! # `genesis`: initial runtime state +//! # `genesis`: Initial Runtime State //! //! All nodes in the network must build subsequent blocks upon exactly the same genesis block. //! @@ -120,17 +120,17 @@ //! includes the storage root hash. //! //! The `genesis` key of the chain specification definition describes the -//! initial state of the runtime. For example it may contain: -//! - initial list of funded accounts, +//! initial state of the runtime. For example, it may contain: +//! - an initial list of funded accounts, //! - the administrative account that controls the sudo key, -//! - initial authorities set for consensus, etc. +//! - an initial authorities set for consensus, etc. //! //! The compiled WASM blob of the runtime code is stored in the state (and therefore on the chain). //! As a result, the initial runtime must also be provided within the chain specification (under the //! `code` field). //! //! The genesis state can be represented in the formats described by [`GenesisFormat`] -//! enum. In essence, tha most important formats are: +//! enum. In essence, the most important formats are: //! //! //! @@ -160,26 +160,26 @@ //! -//! //! //! //!
//! raw //! A JSON object with two fields: top and children_default Each +//! A JSON object with two fields: top and children_default. Each //! field is a map of key => value pairs representing entries in a genesis storage //! trie.
//! -//! For production or long lasting chain specification `raw` format is recommended. +//! For production or long-lasting blockchains, using the `raw` format in the chain specification is recommended. //! //! JSON examples in the [following section](#json-chain-specification-example) illustrate the `raw` //! and `runtimeGenesisConfigPatch` genesis fields. //! -//! # From initial state to raw genesis. +//! # From Initial State to Raw Genesis. //! -//! To generate a raw genesis storage from the JSON representation of the runtime genesis config the +//! To generate a raw genesis storage from the JSON representation of the runtime genesis config, the //! node needs to interact with the runtime. //! //! This interaction involves passing the runtime genesis config JSON blob to the runtime using the -//! [`sp_genesis_builder::GenesisBuilder::build_config`] function. During this operation runtime -//! converts the JSON representation of genesis config into [`sp_io::storage`] items. It is a +//! [`sp_genesis_builder::GenesisBuilder::build_config`] function. During this operation, the runtime +//! converts the JSON representation of the genesis config into [`sp_io::storage`] items. It is a //! crucial step for computing the storage root hash, which is a key component in determining the //! genesis hash. //! @@ -201,27 +201,27 @@ //! The plain and `raw` chain specification JSON blobs can be found in //! [JSON examples](#json-chain-specification-example) section. //! -//! # Optional code mapping +//! # Optional Code Mapping //! Optional map of `block_number` to `wasm_code`. //! //! The given `wasm_code` will be used to substitute the on-chain wasm code starting with the //! given block number until the `spec_version` on-chain changes. The given `wasm_code` should //! be as close as possible to the on-chain wasm code. A substitute should be used to fix a bug -//! that can not be fixed with a runtime upgrade, if for example the runtime is constantly -//! panicking. Introducing new runtime apis isn't supported, because the node +//! that cannot be fixed with a runtime upgrade, if for example the runtime is constantly +//! panicking. Introducing new runtime APIs isn't supported, because the node //! will read the runtime version from the on-chain wasm code. Use this functionality only when -//! there is no other way around it and only patch the problematic bug, the rest should be done -//! with a on-chain runtime upgrade. +//! there is no other way around it, and only patch the problematic bug; the rest should be done +//! with an on-chain runtime upgrade. //! -//! # Building a chain specification. -//! The [`ChainSpecBuilder`] shall be used to create an instance of chain specification. Its API -//! allows to configure all fields of the chain spec. To generate a JSON representation of chain +//! # Building a Chain Specification +//! The [`ChainSpecBuilder`] should be used to create an instance of a chain specification. Its API +//! allows configuration of all fields of the chain spec. To generate a JSON representation of the //! specification, use [`ChainSpec::as_json`]. //! //! The sample code to generate a chain spec is as follows: #![doc = docify::embed!("src/chain_spec.rs", build_chain_spec_with_patch_works)] //! # JSON chain specification example -//! The following are the plain and `raw` ersions of the chain specification JSON files, resulting +//! The following are the plain and `raw` versions of the chain specification JSON files, resulting //! from executing of the above [example](#building-a-chain-specification): //! ```ignore #![doc = include_str!("../res/substrate_test_runtime_from_patch.json")] @@ -229,14 +229,14 @@ //! ```ignore #![doc = include_str!("../res/substrate_test_runtime_from_patch_raw.json")] //! ``` -//! The [`ChainSpec`] trait represents the API to access values defined in JSON chain specification. +//! The [`ChainSpec`] trait represents the API to access values defined in the JSON chain specification. //! -//! # Custom chain spec extensions -//! Basic chain spec type containing all required parameters is [`GenericChainSpec`]. It can be -//! extended with additional options that contain configuration specific to your chain. Usually the -//! extension is going to be an amalgamate of types exposed by Substrate core modules. +//! # Custom Chain Spec Extensions +//! The basic chain spec type containing all required parameters is [`GenericChainSpec`]. It can be +//! extended with additional options containing configuration specific to your chain. Usually, the +//! extension will be a combination of types exposed by Substrate core modules. //! -//! To allow the core modules to retrieve their configuration from your extension you should use +//! To allow the core modules to retrieve their configuration from your extension, you should use //! `ChainSpecExtension` macro exposed by this crate. //! ```rust //! use std::collections::HashMap; @@ -250,9 +250,9 @@ //! pub type MyChainSpec = GenericChainSpec; //! ``` //! Some parameters may require different values depending on the current blockchain height (a.k.a. -//! forks). You can use `ChainSpecGroup` macro and provided [`Forks`](./struct.Forks.html) structure -//! to put such parameters to your chain spec. This will allow to override a single parameter -//! starting at specific block number. +//! forks). You can use the [`ChainSpecGroup`](macro@ChainSpecGroup) macro and the provided [`Forks`] +//! structure to add such parameters to your chain spec. This will allow overriding a single +//! parameter starting at a specific block number. //! ```rust //! use sc_chain_spec::{Forks, ChainSpecGroup, ChainSpecExtension, GenericChainSpec}; //! @@ -281,9 +281,9 @@ //! /// A chain spec supporting forkable `Extension`. //! pub type MyChainSpec2 = GenericChainSpec>; //! ``` -//! It's also possible to have a set of parameters that is allowed to change with block numbers -//! (i.e. is forkable), and another set that is not subject to changes. This is also possible by -//! declaring an extension that contains `Forks` within it. +//! It's also possible to have a set of parameters that are allowed to change with block numbers +//! (i.e., they are forkable), and another set that is not subject to changes. This can also be +//! achieved by declaring an extension that contains [`Forks`] within it. //! ```rust //! use serde::{Serialize, Deserialize}; //! use sc_chain_spec::{Forks, GenericChainSpec, ChainSpecGroup, ChainSpecExtension}; From ddaac44df2def6d8c415e605f0d0555145fd1ec1 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Wed, 18 Oct 2023 20:36:58 +0000 Subject: [PATCH 54/98] ".git/.scripts/commands/fmt/fmt.sh" --- substrate/client/chain-spec/src/lib.rs | 27 +++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/substrate/client/chain-spec/src/lib.rs b/substrate/client/chain-spec/src/lib.rs index 3846a14fbe48..aa289f324cec 100644 --- a/substrate/client/chain-spec/src/lib.rs +++ b/substrate/client/chain-spec/src/lib.rs @@ -28,16 +28,16 @@ //! spec. Internally, the chain spec is embodied by the [`GenericChainSpec`] struct, and specific //! properties can be accessed using the [`ChainSpec`] trait. //! -//! In summary, although not restricted to, the primary role of the chain spec is to provide a list of -//! well-known boot nodes for the blockchain network and the means for initializing the genesis +//! In summary, although not restricted to, the primary role of the chain spec is to provide a list +//! of well-known boot nodes for the blockchain network and the means for initializing the genesis //! storage. This initialization is necessary for creating a genesis block upon which subsequent //! blocks are built. When the node is launched for the first time, it reads the chain spec, //! initializes the genesis block, and establishes connections with the boot nodes. //! //! The JSON chain spec is divided into three main logical sections: //! - one section details general chain properties, -//! - another explicitly or indirectly defines the genesis storage, which, in turn, -//! determines the genesis hash of the chain, +//! - another explicitly or indirectly defines the genesis storage, which, in turn, determines the +//! genesis hash of the chain, //! - the third deals with the runtime code. //! //! The chain specification consists of the following fields: @@ -160,28 +160,29 @@ //! //! raw //! -//! A JSON object with two fields: top and children_default. Each -//! field is a map of key => value pairs representing entries in a genesis storage +//! A JSON object with two fields: top and children_default. +//! Each field is a map of key => value pairs representing entries in a genesis storage //! trie. //! //! //! //! -//! For production or long-lasting blockchains, using the `raw` format in the chain specification is recommended. +//! For production or long-lasting blockchains, using the `raw` format in the chain specification is +//! recommended. //! //! JSON examples in the [following section](#json-chain-specification-example) illustrate the `raw` //! and `runtimeGenesisConfigPatch` genesis fields. //! //! # From Initial State to Raw Genesis. //! -//! To generate a raw genesis storage from the JSON representation of the runtime genesis config, the -//! node needs to interact with the runtime. +//! To generate a raw genesis storage from the JSON representation of the runtime genesis config, +//! the node needs to interact with the runtime. //! //! This interaction involves passing the runtime genesis config JSON blob to the runtime using the -//! [`sp_genesis_builder::GenesisBuilder::build_config`] function. During this operation, the runtime -//! converts the JSON representation of the genesis config into [`sp_io::storage`] items. It is a -//! crucial step for computing the storage root hash, which is a key component in determining the -//! genesis hash. +//! [`sp_genesis_builder::GenesisBuilder::build_config`] function. During this operation, the +//! runtime converts the JSON representation of the genesis config into [`sp_io::storage`] items. It +//! is a crucial step for computing the storage root hash, which is a key component in determining +//! the genesis hash. //! //! Consequently, the runtime must support the [`sp_genesis_builder::GenesisBuilder`] API to //! utilize either [`RuntimeGenesisConfigPatch`][patch] or [`RuntimeGenesisConfig`][full] formats. From 8f83e65c9b58e38b60ab9d808ab6d4fada107f74 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 20 Oct 2023 14:56:09 +0200 Subject: [PATCH 55/98] prdoc added --- prdoc/pr_1256.prdoc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 prdoc/pr_1256.prdoc diff --git a/prdoc/pr_1256.prdoc b/prdoc/pr_1256.prdoc new file mode 100644 index 000000000000..9e8bc569dcec --- /dev/null +++ b/prdoc/pr_1256.prdoc @@ -0,0 +1,23 @@ +# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 +# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json + +title: `chain-spec`: getting ready for native-runtime-free world + +doc: + - audience: Node Dev + description: | + - [`ChainSpec::from_genesis`](https://github.com/paritytech/substrate/blob/3ef576eaeb3f42610e85daecc464961cf1295570/client/chain-spec/src/chain_spec.rs#L263) becomes deprecated in favor of [`ChainSpec::builder()`](https://github.com/paritytech/substrate/blob/20bee680ed098be7239cf7a6b804cd4de267983e/client/chain-spec/src/chain_spec.rs#L507), + - The signature of [`ChainSpec::from_genesis`] method was chagned by extending it with `code` argument. + + - audience: Node Operator + description: | + Change in plain chain specification JSON file. `::genesis::runtime::system::code` key is removed and replaced with `::code` key. Raw version of chain spec remains unchanged. + +migrations: + db: [] + + runtime: [] + +crates: [] + +host_functions: [] From 7c821ca4bf5a82a58b8f05306ed0f2dfd1ad2a1b Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 23 Oct 2023 19:04:29 +0200 Subject: [PATCH 56/98] commented code removed --- .../emulated/common/src/constants.rs | 202 ------------------ 1 file changed, 202 deletions(-) diff --git a/cumulus/parachains/integration-tests/emulated/common/src/constants.rs b/cumulus/parachains/integration-tests/emulated/common/src/constants.rs index 0960ed4e7e3c..51b68d8ef029 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/constants.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/constants.rs @@ -902,208 +902,6 @@ pub mod asset_hub_wococo { } } -// pub mod asset_hub_rococo { -// use super::*; -// pub const PARA_ID: u32 = 1000; -// pub const ED: Balance = parachains_common::rococo::currency::EXISTENTIAL_DEPOSIT; -// -// pub fn genesis() -> Storage { -// <<<<<<< HEAD -// let genesis_config = serde_json::json!({ -// "balances": { -// "balances": accounts::init_balances() -// .iter() -// .cloned() -// .map(|k| (k, ED * 4096)) -// .collect::>(), -// }, -// "parachainInfo": { -// "parachainId": cumulus_primitives_core::ParaId::from(PARA_ID), -// }, -// "collatorSelection": { -// "invulnerables": collators::invulnerables() -// ======= -// let genesis_config = asset_hub_rococo_runtime::RuntimeGenesisConfig { -// system: asset_hub_rococo_runtime::SystemConfig { -// code: asset_hub_rococo_runtime::WASM_BINARY -// .expect("WASM binary was not build, please build it!") -// .to_vec(), -// ..Default::default() -// }, -// balances: asset_hub_rococo_runtime::BalancesConfig { -// balances: accounts::init_balances() -// .iter() -// .cloned() -// .map(|k| (k, ED * 4096 * 4096)) -// .collect(), -// }, -// parachain_info: asset_hub_rococo_runtime::ParachainInfoConfig { -// parachain_id: PARA_ID.into(), -// ..Default::default() -// }, -// collator_selection: asset_hub_rococo_runtime::CollatorSelectionConfig { -// invulnerables: collators::invulnerables() -// >>>>>>> origin/master -// .iter() -// .cloned() -// .map(|(acc, _)| acc) -// .collect::>(), -// "candidacyBond": ED * 16, -// }, -// <<<<<<< HEAD -// "session": { -// "keys": collators::invulnerables() -// ======= -// session: asset_hub_rococo_runtime::SessionConfig { -// keys: collators::invulnerables() -// >>>>>>> origin/master -// .into_iter() -// .map(|(acc, aura)| { -// ( -// acc.clone(), // account id -// acc, // validator id -// asset_hub_rococo_runtime::SessionKeys { aura }, // session keys -// ) -// }) -// .collect::>(), -// }, -// <<<<<<< HEAD -// "polkadotXcm": { -// "safeXcmVersion": Some(SAFE_XCM_VERSION), -// ======= -// polkadot_xcm: asset_hub_rococo_runtime::PolkadotXcmConfig { -// safe_xcm_version: Some(SAFE_XCM_VERSION), -// ..Default::default() -// }, -// ..Default::default() -// }; -// -// genesis_config.build_storage().unwrap() -// } -// } -// -// pub mod asset_hub_wococo { -// use super::*; -// pub const PARA_ID: u32 = 1000; -// pub const ED: Balance = parachains_common::wococo::currency::EXISTENTIAL_DEPOSIT; -// -// pub fn genesis() -> Storage { -// let genesis_config = asset_hub_rococo_runtime::RuntimeGenesisConfig { -// system: asset_hub_rococo_runtime::SystemConfig { -// code: asset_hub_rococo_runtime::WASM_BINARY -// .expect("WASM binary was not build, please build it!") -// .to_vec(), -// ..Default::default() -// }, -// balances: asset_hub_rococo_runtime::BalancesConfig { -// balances: accounts::init_balances() -// .iter() -// .cloned() -// .map(|k| (k, ED * 4096)) -// .collect(), -// }, -// parachain_info: asset_hub_rococo_runtime::ParachainInfoConfig { -// parachain_id: PARA_ID.into(), -// ..Default::default() -// }, -// collator_selection: asset_hub_rococo_runtime::CollatorSelectionConfig { -// invulnerables: collators::invulnerables() -// .iter() -// .cloned() -// .map(|(acc, _)| acc) -// .collect(), -// candidacy_bond: ED * 16, -// ..Default::default() -// }, -// session: asset_hub_rococo_runtime::SessionConfig { -// keys: collators::invulnerables() -// .into_iter() -// .map(|(acc, aura)| { -// ( -// acc.clone(), // account id -// acc, // validator id -// asset_hub_rococo_runtime::SessionKeys { aura }, // session keys -// ) -// }) -// .collect(), -// }, -// polkadot_xcm: asset_hub_rococo_runtime::PolkadotXcmConfig { -// safe_xcm_version: Some(SAFE_XCM_VERSION), -// ..Default::default() -// >>>>>>> origin/master -// }, -// }); -// -// build_genesis_storage( -// genesis_config, -// asset_hub_westend_runtime::WASM_BINARY -// .expect("WASM binary was not build, please build it!"), -// ) -// } -// -// #[cfg(test)] -// mod legacy_vs_json_check { -// use super::*; -// pub fn genesis() -> Storage { -// let genesis_config = asset_hub_westend_runtime::RuntimeGenesisConfig { -// system: asset_hub_westend_runtime::SystemConfig::default(), -// balances: asset_hub_westend_runtime::BalancesConfig { -// balances: accounts::init_balances() -// .iter() -// .cloned() -// .map(|k| (k, ED * 4096)) -// .collect(), -// }, -// parachain_info: asset_hub_westend_runtime::ParachainInfoConfig { -// parachain_id: PARA_ID.into(), -// ..Default::default() -// }, -// collator_selection: asset_hub_westend_runtime::CollatorSelectionConfig { -// invulnerables: collators::invulnerables() -// .iter() -// .cloned() -// .map(|(acc, _)| acc) -// .collect(), -// candidacy_bond: ED * 16, -// ..Default::default() -// }, -// session: asset_hub_westend_runtime::SessionConfig { -// keys: collators::invulnerables() -// .into_iter() -// .map(|(acc, aura)| { -// ( -// acc.clone(), // account id -// acc, // validator id -// asset_hub_westend_runtime::SessionKeys { aura }, // session keys -// ) -// }) -// .collect(), -// }, -// polkadot_xcm: asset_hub_westend_runtime::PolkadotXcmConfig { -// safe_xcm_version: Some(SAFE_XCM_VERSION), -// ..Default::default() -// }, -// ..Default::default() -// }; -// -// build_genesis_storage_legacy( -// &genesis_config, -// asset_hub_westend_runtime::WASM_BINARY -// .expect("WASM binary was not build, please build it!"), -// ) -// } -// -// #[test] -// fn test_genesis() { -// let j1 = super::genesis(); -// let j2 = genesis(); -// -// assert_eq!(j1.top, j2.top); -// assert_eq!(j1.children_default, j2.children_default); -// } -// } -// } - // Penpal pub mod penpal { use super::*; From b9e850d605681f0120c42189fd18cd76b0ad38bb Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Mon, 23 Oct 2023 17:47:04 +0000 Subject: [PATCH 57/98] ".git/.scripts/commands/fmt/fmt.sh" --- .../src/chain_spec/asset_hubs.rs | 127 ++++++++---------- .../legacy_chain_spec/json_vs_legacy_tests.rs | 1 - 2 files changed, 59 insertions(+), 69 deletions(-) diff --git a/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs b/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs index 8d199fafd027..fc709a4fcd9e 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs @@ -707,39 +707,35 @@ pub fn asset_hub_rococo_genesis_config() -> AssetHubRococoChainSpec { .with_id("asset-hub-rococo") .with_chain_type(ChainType::Live) .with_genesis_config_patch(asset_hub_rococo_genesis( - // initial collators. - vec![ - // E8XC6rTJRsioKCp6KMy6zd24ykj4gWsusZ3AkSeyavpVBAG - ( - hex!("44cb62d1d6cdd2fff2a5ef3bb7ef827be5b3e117a394ecaa634d8dd9809d5608") - .into(), - hex!("44cb62d1d6cdd2fff2a5ef3bb7ef827be5b3e117a394ecaa634d8dd9809d5608") - .unchecked_into(), - ), - // G28iWEybndgGRbhfx83t7Q42YhMPByHpyqWDUgeyoGF94ri - ( - hex!("9864b85e23aa4506643db9879c3dbbeabaa94d269693a4447f537dd6b5893944") - .into(), - hex!("9864b85e23aa4506643db9879c3dbbeabaa94d269693a4447f537dd6b5893944") - .unchecked_into(), - ), - // G839e2eMiq7UXbConsY6DS1XDAYG2XnQxAmLuRLGGQ3Px9c - ( - hex!("9ce5741ee2f1ac3bdedbde9f3339048f4da2cb88ddf33a0977fa0b4cf86e2948") - .into(), - hex!("9ce5741ee2f1ac3bdedbde9f3339048f4da2cb88ddf33a0977fa0b4cf86e2948") - .unchecked_into(), - ), - // GLao4ukFUW6qhexuZowdFrKa2NLCfnEjZMftSXXfvGv1vvt - ( - hex!("a676ed15f5a325eab49ed8d5f8c00f3f814b19bb58cda14ad10894c078dd337f") - .into(), - hex!("a676ed15f5a325eab49ed8d5f8c00f3f814b19bb58cda14ad10894c078dd337f") - .unchecked_into(), - ), - ], - Vec::new(), - para_id.into(), + // initial collators. + vec![ + // E8XC6rTJRsioKCp6KMy6zd24ykj4gWsusZ3AkSeyavpVBAG + ( + hex!("44cb62d1d6cdd2fff2a5ef3bb7ef827be5b3e117a394ecaa634d8dd9809d5608").into(), + hex!("44cb62d1d6cdd2fff2a5ef3bb7ef827be5b3e117a394ecaa634d8dd9809d5608") + .unchecked_into(), + ), + // G28iWEybndgGRbhfx83t7Q42YhMPByHpyqWDUgeyoGF94ri + ( + hex!("9864b85e23aa4506643db9879c3dbbeabaa94d269693a4447f537dd6b5893944").into(), + hex!("9864b85e23aa4506643db9879c3dbbeabaa94d269693a4447f537dd6b5893944") + .unchecked_into(), + ), + // G839e2eMiq7UXbConsY6DS1XDAYG2XnQxAmLuRLGGQ3Px9c + ( + hex!("9ce5741ee2f1ac3bdedbde9f3339048f4da2cb88ddf33a0977fa0b4cf86e2948").into(), + hex!("9ce5741ee2f1ac3bdedbde9f3339048f4da2cb88ddf33a0977fa0b4cf86e2948") + .unchecked_into(), + ), + // GLao4ukFUW6qhexuZowdFrKa2NLCfnEjZMftSXXfvGv1vvt + ( + hex!("a676ed15f5a325eab49ed8d5f8c00f3f814b19bb58cda14ad10894c078dd337f").into(), + hex!("a676ed15f5a325eab49ed8d5f8c00f3f814b19bb58cda14ad10894c078dd337f") + .unchecked_into(), + ), + ], + Vec::new(), + para_id.into(), )) .with_properties(properties) .build() @@ -759,45 +755,40 @@ pub fn asset_hub_wococo_genesis_config() -> AssetHubWococoChainSpec { .with_id("asset-hub-wococo") .with_chain_type(ChainType::Live) .with_genesis_config_patch(asset_hub_rococo_genesis( - // initial collators. - vec![ - // 5C8RGkS8t5K93fB2hkgKbvSYs5iG6AknJMuQmbBDeazon9Lj - ( - hex!("02d526f43cf27e94f478f9db785dc86052a77c695e7c855211839d3fde3ce534") - .into(), - hex!("02d526f43cf27e94f478f9db785dc86052a77c695e7c855211839d3fde3ce534") - .unchecked_into(), - ), - // 5GePeDZQeBagXH7kH5QPKnQKi39Z5hoYFB5FmUtEvc4yxKej - ( - hex!("caa1f623ca183296c4521b56cc29c484ca017830f8cb538f30f2d4664d631814") - .into(), - hex!("caa1f623ca183296c4521b56cc29c484ca017830f8cb538f30f2d4664d631814") - .unchecked_into(), - ), - // 5CfnTTb9NMJDNKDntA83mHKoedZ7wjDC8ypLCTDd4NwUx3zv - ( - hex!("1ac112d635db2bd34e79ae2b99486cf7c0b71a928668e4feb3dc4633d368f965") - .into(), - hex!("1ac112d635db2bd34e79ae2b99486cf7c0b71a928668e4feb3dc4633d368f965") - .unchecked_into(), - ), - // 5EqheiwiG22gvGpN7cvrbeaQzhg7rzsYYVkYK4yj5vRrTQRQ - ( - hex!("7ac9d11be07334cd27e9eb849f5fc7677a10ad36b6ab38b377d3c8b2c0b08b66") - .into(), - hex!("7ac9d11be07334cd27e9eb849f5fc7677a10ad36b6ab38b377d3c8b2c0b08b66") - .unchecked_into(), - ), - ], - Vec::new(), - para_id.into(), - )) + // initial collators. + vec![ + // 5C8RGkS8t5K93fB2hkgKbvSYs5iG6AknJMuQmbBDeazon9Lj + ( + hex!("02d526f43cf27e94f478f9db785dc86052a77c695e7c855211839d3fde3ce534").into(), + hex!("02d526f43cf27e94f478f9db785dc86052a77c695e7c855211839d3fde3ce534") + .unchecked_into(), + ), + // 5GePeDZQeBagXH7kH5QPKnQKi39Z5hoYFB5FmUtEvc4yxKej + ( + hex!("caa1f623ca183296c4521b56cc29c484ca017830f8cb538f30f2d4664d631814").into(), + hex!("caa1f623ca183296c4521b56cc29c484ca017830f8cb538f30f2d4664d631814") + .unchecked_into(), + ), + // 5CfnTTb9NMJDNKDntA83mHKoedZ7wjDC8ypLCTDd4NwUx3zv + ( + hex!("1ac112d635db2bd34e79ae2b99486cf7c0b71a928668e4feb3dc4633d368f965").into(), + hex!("1ac112d635db2bd34e79ae2b99486cf7c0b71a928668e4feb3dc4633d368f965") + .unchecked_into(), + ), + // 5EqheiwiG22gvGpN7cvrbeaQzhg7rzsYYVkYK4yj5vRrTQRQ + ( + hex!("7ac9d11be07334cd27e9eb849f5fc7677a10ad36b6ab38b377d3c8b2c0b08b66").into(), + hex!("7ac9d11be07334cd27e9eb849f5fc7677a10ad36b6ab38b377d3c8b2c0b08b66") + .unchecked_into(), + ), + ], + Vec::new(), + para_id.into(), + )) .with_properties(properties) .build() } - fn asset_hub_rococo_genesis( invulnerables: Vec<(AccountId, AuraId)>, endowed_accounts: Vec, diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/json_vs_legacy_tests.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/json_vs_legacy_tests.rs index 72ace5cdb49b..7f8f7a30519f 100644 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/json_vs_legacy_tests.rs +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/json_vs_legacy_tests.rs @@ -93,4 +93,3 @@ test!( test31, bridge_hubs::polkadot::local_config("bridge-hub-polkadot-local", "Test", "test", 667.into()) ); - From dec047a416c122256ddb553233f9cb82b178288a Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 30 Oct 2023 08:39:14 +0100 Subject: [PATCH 58/98] minimal node: genesis builder support --- Cargo.lock | 3 + substrate/bin/minimal/node/Cargo.toml | 1 + substrate/bin/minimal/node/src/chain_spec.rs | 87 ++++++++++++++------ substrate/bin/minimal/runtime/Cargo.toml | 4 + substrate/bin/minimal/runtime/src/lib.rs | 11 +++ 5 files changed, 81 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ea787730dda4..f1c885404874 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7987,6 +7987,7 @@ dependencies = [ "sc-telemetry", "sc-transaction-pool", "sc-transaction-pool-api", + "serde_json", "sp-api", "sp-block-builder", "sp-blockchain", @@ -8003,6 +8004,7 @@ name = "minimal-runtime" version = "0.1.0" dependencies = [ "frame", + "frame-support", "pallet-balances", "pallet-sudo", "pallet-timestamp", @@ -8010,6 +8012,7 @@ dependencies = [ "pallet-transaction-payment-rpc-runtime-api", "parity-scale-codec", "scale-info", + "sp-genesis-builder", "substrate-wasm-builder", ] diff --git a/substrate/bin/minimal/node/Cargo.toml b/substrate/bin/minimal/node/Cargo.toml index 11ce98eec0dd..39d39d7e3122 100644 --- a/substrate/bin/minimal/node/Cargo.toml +++ b/substrate/bin/minimal/node/Cargo.toml @@ -21,6 +21,7 @@ clap = { version = "4.0.9", features = ["derive"] } futures = { version = "0.3.21", features = ["thread-pool"] } futures-timer = "3.0.1" jsonrpsee = { version = "0.16.2", features = ["server"] } +serde_json = "1.0.107" sc-cli = { path = "../../../client/cli" } sc-executor = { path = "../../../client/executor" } diff --git a/substrate/bin/minimal/node/src/chain_spec.rs b/substrate/bin/minimal/node/src/chain_spec.rs index 91fa9ef45202..71468f62bc8f 100644 --- a/substrate/bin/minimal/node/src/chain_spec.rs +++ b/substrate/bin/minimal/node/src/chain_spec.rs @@ -15,12 +15,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -use runtime::{BalancesConfig, RuntimeGenesisConfig, SudoConfig, SystemConfig, WASM_BINARY}; +use runtime::{BalancesConfig, SudoConfig, WASM_BINARY}; use sc_service::{ChainType, Properties}; +use serde_json::{json, Value}; use sp_keyring::AccountKeyring; /// This is a specialization of the general Substrate ChainSpec type. -pub type ChainSpec = sc_service::GenericChainSpec; +pub type ChainSpec = sc_service::GenericChainSpec<()>; fn props() -> Properties { let mut properties = Properties::new(); @@ -30,37 +31,73 @@ fn props() -> Properties { } pub fn development_config() -> Result { - let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?; - Ok(ChainSpec::from_genesis( - "Development", - "dev", - ChainType::Development, - move || testnet_genesis(wasm_binary), - vec![], - None, - None, - None, - Some(props()), - None, - )) + Ok(ChainSpec::builder(WASM_BINARY.expect("Development wasm not available"), Default::default()) + .with_name("Development") + .with_id("dev") + .with_chain_type(ChainType::Development) + .with_genesis_config_patch(testnet_genesis()) + .with_properties(props()) + .build()) } /// Configure initial storage state for FRAME pallets. -fn testnet_genesis(wasm_binary: &[u8]) -> RuntimeGenesisConfig { +fn testnet_genesis() -> Value { use frame::traits::Get; use runtime::interface::{Balance, MinimumBalance}; let endowment = >::get().max(1) * 1000; let balances = AccountKeyring::iter() .map(|a| (a.to_account_id(), endowment)) .collect::>(); - RuntimeGenesisConfig { - system: SystemConfig { - // Add Wasm runtime to storage. - code: wasm_binary.to_vec(), - _config: Default::default(), - }, - balances: BalancesConfig { balances }, - sudo: SudoConfig { key: Some(AccountKeyring::Alice.to_account_id()) }, - ..Default::default() + json!({ + "balances": BalancesConfig { balances }, + "sudo": SudoConfig { key: Some(AccountKeyring::Alice.to_account_id()) }, + }) +} + +#[cfg(test)] +mod test { + use super::*; + use runtime::RuntimeGenesisConfig; + pub type LegacyChainSpec = sc_service::GenericChainSpec; + + fn development_config_legacy() -> Result { + Ok( + #[allow(deprecated)] + LegacyChainSpec::from_genesis( + "Development", + "dev", + ChainType::Development, + move || testnet_genesis_legacy(), + vec![], + None, + None, + None, + Some(props()), + None, + WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?, + ), + ) + } + + /// Configure initial storage state for FRAME pallets (legacy version). + fn testnet_genesis_legacy() -> RuntimeGenesisConfig { + use frame::traits::Get; + use runtime::interface::{Balance, MinimumBalance}; + let endowment = >::get().max(1) * 1000; + let balances = AccountKeyring::iter() + .map(|a| (a.to_account_id(), endowment)) + .collect::>(); + RuntimeGenesisConfig { + balances: BalancesConfig { balances }, + sudo: SudoConfig { key: Some(AccountKeyring::Alice.to_account_id()) }, + ..Default::default() + } + } + + #[test] + fn legacy_vs_json_based_chainspec_check() { + let j1 = development_config().unwrap().as_json(true).unwrap(); + let j2 = development_config_legacy().unwrap().as_json(true).unwrap(); + assert_eq!(j1, j2); } } diff --git a/substrate/bin/minimal/runtime/Cargo.toml b/substrate/bin/minimal/runtime/Cargo.toml index 1f9b49da7bc3..08feb445879f 100644 --- a/substrate/bin/minimal/runtime/Cargo.toml +++ b/substrate/bin/minimal/runtime/Cargo.toml @@ -9,6 +9,7 @@ scale-info = { version = "2.6.0", default-features = false } # this is a frame-based runtime, thus importing `frame` with runtime feature enabled. frame = { path = "../../../frame", default-features = false, features = ["runtime", "experimental"] } +frame-support = { path = "../../../frame/support", default-features = false} # pallets that we want to use pallet-balances = { path = "../../../frame/balances", default-features = false } @@ -17,6 +18,9 @@ pallet-timestamp = { path = "../../../frame/timestamp", default-features = false pallet-transaction-payment = { path = "../../../frame/transaction-payment", default-features = false } pallet-transaction-payment-rpc-runtime-api = { path = "../../../frame/transaction-payment/rpc/runtime-api", default-features = false } +# genesis builder that allows us to interacto with runtime genesis config +sp-genesis-builder = { path = "../../../primitives/genesis-builder", default-features = false} + [build-dependencies] substrate-wasm-builder = { path = "../../../utils/wasm-builder", optional = true } diff --git a/substrate/bin/minimal/runtime/src/lib.rs b/substrate/bin/minimal/runtime/src/lib.rs index 6c59592554c5..efee400c3f59 100644 --- a/substrate/bin/minimal/runtime/src/lib.rs +++ b/substrate/bin/minimal/runtime/src/lib.rs @@ -31,6 +31,7 @@ use frame::{ prelude::*, }, }; +use frame_support::genesis_builder_helper::{build_config, create_default_config}; #[runtime_version] pub const VERSION: RuntimeVersion = RuntimeVersion { @@ -210,6 +211,16 @@ impl_runtime_apis! { TransactionPayment::length_to_fee(length) } } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } } /// Some re-exports that the node side code needs to know. Some are useful in this context as well. From ea2e1f1ee099e397f278ac1a0094a446b9f926af Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 30 Oct 2023 09:35:58 +0100 Subject: [PATCH 59/98] review suggestions for documentation --- substrate/client/chain-spec/README.md | 90 +------------------------- substrate/client/chain-spec/src/lib.rs | 34 ++++++---- 2 files changed, 25 insertions(+), 99 deletions(-) diff --git a/substrate/client/chain-spec/README.md b/substrate/client/chain-spec/README.md index dad1662d3230..9f746d2d4ce7 100644 --- a/substrate/client/chain-spec/README.md +++ b/substrate/client/chain-spec/README.md @@ -1,92 +1,6 @@ Substrate chain configurations. -This crate contains structs and utilities to declare -a runtime-specific configuration file (a.k.a chain spec). - -Basic chain spec type containing all required parameters is -[`ChainSpec`](https://docs.rs/sc-chain-spec/latest/sc_chain_spec/struct.GenericChainSpec.html). It can be extended with -additional options that contain configuration specific to your chain. -Usually the extension is going to be an amalgamate of types exposed -by Substrate core modules. To allow the core modules to retrieve -their configuration from your extension you should use `ChainSpecExtension` -macro exposed by this crate. - -```rust -use std::collections::HashMap; -use sc_chain_spec::{GenericChainSpec, ChainSpecExtension}; - -#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, ChainSpecExtension)] -pub struct MyExtension { - pub known_blocks: HashMap, -} - -pub type MyChainSpec = GenericChainSpec; -``` - -Some parameters may require different values depending on the -current blockchain height (a.k.a. forks). You can use `ChainSpecGroup` -macro and provided [`Forks`](https://docs.rs/sc-chain-spec/latest/sc_chain_spec/struct.Forks.html) structure to put -such parameters to your chain spec. -This will allow to override a single parameter starting at specific -block number. - -```rust -use sc_chain_spec::{Forks, ChainSpecGroup, ChainSpecExtension, GenericChainSpec}; - -#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, ChainSpecGroup)] -pub struct ClientParams { - max_block_size: usize, - max_extrinsic_size: usize, -} - -#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, ChainSpecGroup)] -pub struct PoolParams { - max_transaction_size: usize, -} - -#[derive(Clone, Debug, serde::Serialize, serde::Deserialize, ChainSpecGroup, ChainSpecExtension)] -pub struct Extension { - pub client: ClientParams, - pub pool: PoolParams, -} - -pub type BlockNumber = u64; - -/// A chain spec supporting forkable `ClientParams`. -pub type MyChainSpec1 = GenericChainSpec>; - -/// A chain spec supporting forkable `Extension`. -pub type MyChainSpec2 = GenericChainSpec>; -``` - -It's also possible to have a set of parameters that is allowed to change -with block numbers (i.e. is forkable), and another set that is not subject to changes. -This is also possible by declaring an extension that contains `Forks` within it. - - -```rust -use serde::{Serialize, Deserialize}; -use sc_chain_spec::{Forks, GenericChainSpec, ChainSpecGroup, ChainSpecExtension}; - -#[derive(Clone, Debug, Serialize, Deserialize, ChainSpecGroup)] -pub struct ClientParams { - max_block_size: usize, - max_extrinsic_size: usize, -} - -#[derive(Clone, Debug, Serialize, Deserialize, ChainSpecGroup)] -pub struct PoolParams { - max_transaction_size: usize, -} - -#[derive(Clone, Debug, Serialize, Deserialize, ChainSpecExtension)] -pub struct Extension { - pub client: ClientParams, - #[forks] - pub pool: Forks, -} - -pub type MyChainSpec = GenericChainSpec; -``` +This crate contains structs and utilities to declare a runtime-specific configuration file (a.k.a chain spec). +Refer to crate documentation for details. License: GPL-3.0-or-later WITH Classpath-exception-2.0 diff --git a/substrate/client/chain-spec/src/lib.rs b/substrate/client/chain-spec/src/lib.rs index aa289f324cec..015b02c3d93d 100644 --- a/substrate/client/chain-spec/src/lib.rs +++ b/substrate/client/chain-spec/src/lib.rs @@ -69,7 +69,9 @@ //! //! //! bootNodes -//! A list of multi addresses that belong to boot nodes of the chain. +//! A list of +//! multi addresses +//! that belong to boot nodes of the chain. //! //! //! telemetryEndpoints @@ -97,7 +99,7 @@ //! //! //! codeSubstitutes -//! Optional map of block_number to wasm_code More details in +//! Optional map of block_number to wasm_code. More details in //! material to follow. //! //! @@ -131,6 +133,7 @@ //! //! The genesis state can be represented in the formats described by [`GenesisFormat`] //! enum. In essence, the most important formats are: +//! //! //! //! @@ -144,16 +147,19 @@ //! runtime //! //! -//! +//! RuntimeGenesisConfig struct, which is generated by frame::runtime::prelude::construct_runtime macro (example of generated struct). Must contain all the keys of +//! the genesis config, no defaults will be used. //! //! //! //! //! @@ -168,7 +174,8 @@ //!
A JSON object that provides an explicit and comprehensive representation of the -//! RuntimeGenesisConfig struct. Must contain all the keys of the genesis config, no -//! defaults will be used.
//! patch //! A JSON object that offers a partial representation of the //! RuntimeGenesisConfig provided by the runtime. It contains a patch, which is -//! essentially a list of keys to customize in the default runtime's +//! essentially a list of key-value pairs to customize in the default runtime's //! RuntimeGenesisConfig.
//! //! For production or long-lasting blockchains, using the `raw` format in the chain specification is -//! recommended. +//! recommended. Only the `raw` format guarantees that storage root hash will remain unchanged when +//! the RuntimeGenesisConfig format changes due to software upgrade. //! //! JSON examples in the [following section](#json-chain-specification-example) illustrate the `raw` //! and `runtimeGenesisConfigPatch` genesis fields. @@ -203,6 +210,7 @@ //! [JSON examples](#json-chain-specification-example) section. //! //! # Optional Code Mapping +//! //! Optional map of `block_number` to `wasm_code`. //! //! The given `wasm_code` will be used to substitute the on-chain wasm code starting with the @@ -210,11 +218,13 @@ //! be as close as possible to the on-chain wasm code. A substitute should be used to fix a bug //! that cannot be fixed with a runtime upgrade, if for example the runtime is constantly //! panicking. Introducing new runtime APIs isn't supported, because the node -//! will read the runtime version from the on-chain wasm code. Use this functionality only when -//! there is no other way around it, and only patch the problematic bug; the rest should be done -//! with an on-chain runtime upgrade. +//! will read the runtime version from the on-chain wasm code. +//! +//! Use this functionality only when there is no other way around it, and only patch the problematic +//! bug; the rest should be done with an on-chain runtime upgrade. //! //! # Building a Chain Specification +//! //! The [`ChainSpecBuilder`] should be used to create an instance of a chain specification. Its API //! allows configuration of all fields of the chain spec. To generate a JSON representation of the //! specification, use [`ChainSpec::as_json`]. @@ -222,6 +232,7 @@ //! The sample code to generate a chain spec is as follows: #![doc = docify::embed!("src/chain_spec.rs", build_chain_spec_with_patch_works)] //! # JSON chain specification example +//! //! The following are the plain and `raw` versions of the chain specification JSON files, resulting //! from executing of the above [example](#building-a-chain-specification): //! ```ignore @@ -233,6 +244,7 @@ //! The [`ChainSpec`] trait represents the API to access values defined in the JSON chain specification. //! //! # Custom Chain Spec Extensions +//! //! The basic chain spec type containing all required parameters is [`GenericChainSpec`]. It can be //! extended with additional options containing configuration specific to your chain. Usually, the //! extension will be a combination of types exposed by Substrate core modules. @@ -245,7 +257,7 @@ //! //! #[derive(Clone, Debug, serde::Serialize, serde::Deserialize, ChainSpecExtension)] //! pub struct MyExtension { -//! pub known_blocks: HashMap, +//! pub known_blocks: HashMap, //! } //! //! pub type MyChainSpec = GenericChainSpec; From 69f0aeb509e58cd9e482455d024da41adc828342 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 30 Oct 2023 09:42:02 +0100 Subject: [PATCH 60/98] not build <> not built --- .../parachain-template/node/src/chain_spec.rs | 8 +++--- .../emulated/common/src/constants.rs | 20 +++++++------- .../src/chain_spec/asset_hubs.rs | 26 +++++++++---------- .../src/chain_spec/bridge_hubs.rs | 6 ++--- .../src/chain_spec/collectives.rs | 4 +-- .../src/chain_spec/contracts.rs | 6 ++--- .../src/chain_spec/glutton.rs | 6 ++--- .../src/chain_spec/penpal.rs | 2 +- .../src/chain_spec/rococo_parachain.rs | 4 +-- .../src/chain_spec/seedling.rs | 2 +- .../src/chain_spec/shell.rs | 2 +- cumulus/polkadot-parachain/src/command.rs | 2 +- .../src/legacy_chain_spec/asset_hubs.rs | 26 +++++++++---------- .../src/legacy_chain_spec/bridge_hubs.rs | 6 ++--- .../src/legacy_chain_spec/collectives.rs | 4 +-- .../src/legacy_chain_spec/contracts.rs | 6 ++--- .../src/legacy_chain_spec/glutton.rs | 6 ++--- .../src/legacy_chain_spec/penpal.rs | 2 +- .../src/legacy_chain_spec/rococo_parachain.rs | 4 +-- .../src/legacy_chain_spec/seedling.rs | 2 +- .../src/legacy_chain_spec/shell.rs | 2 +- cumulus/test/service/src/chain_spec.rs | 2 +- 22 files changed, 74 insertions(+), 74 deletions(-) diff --git a/cumulus/parachain-template/node/src/chain_spec.rs b/cumulus/parachain-template/node/src/chain_spec.rs index d20aadc0f3c3..4655a492c50a 100644 --- a/cumulus/parachain-template/node/src/chain_spec.rs +++ b/cumulus/parachain-template/node/src/chain_spec.rs @@ -69,7 +69,7 @@ pub fn development_config() -> ChainSpec { ChainSpec::builder( parachain_template_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "rococo-local".into(), // You MUST set this to the correct network! @@ -121,7 +121,7 @@ pub fn local_testnet_config() -> ChainSpec { #[allow(deprecated)] ChainSpec::builder( parachain_template_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "rococo-local".into(), // You MUST set this to the correct network! @@ -267,7 +267,7 @@ mod legacy { para_id: 1000, }, parachain_template_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), ) } @@ -332,7 +332,7 @@ mod legacy { para_id: 1000, }, parachain_template_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), ) } diff --git a/cumulus/parachains/integration-tests/emulated/common/src/constants.rs b/cumulus/parachains/integration-tests/emulated/common/src/constants.rs index ff5da19b4770..cfbb34971bd8 100644 --- a/cumulus/parachains/integration-tests/emulated/common/src/constants.rs +++ b/cumulus/parachains/integration-tests/emulated/common/src/constants.rs @@ -611,7 +611,7 @@ pub mod asset_hub_westend { build_genesis_storage( genesis_config, asset_hub_westend_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), ) } @@ -663,7 +663,7 @@ pub mod asset_hub_westend { build_genesis_storage_legacy( &genesis_config, asset_hub_westend_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), ) } @@ -723,7 +723,7 @@ pub mod asset_hub_rococo { build_genesis_storage( genesis_config, asset_hub_rococo_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), ) } @@ -775,7 +775,7 @@ pub mod asset_hub_rococo { build_genesis_storage_legacy( &genesis_config, asset_hub_rococo_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), ) } @@ -835,7 +835,7 @@ pub mod asset_hub_wococo { build_genesis_storage( genesis_config, asset_hub_rococo_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), ) } @@ -887,7 +887,7 @@ pub mod asset_hub_wococo { build_genesis_storage_legacy( &genesis_config, asset_hub_rococo_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), ) } @@ -951,7 +951,7 @@ pub mod penpal { build_genesis_storage( genesis_config, - penpal_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + penpal_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), ) } @@ -1005,7 +1005,7 @@ pub mod penpal { build_genesis_storage_legacy( &genesis_config, - penpal_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + penpal_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), ) } @@ -1078,7 +1078,7 @@ pub mod bridge_hub_rococo { build_genesis_storage( genesis_config, bridge_hub_rococo_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), ) } @@ -1148,7 +1148,7 @@ pub mod bridge_hub_rococo { build_genesis_storage_legacy( &genesis_config, bridge_hub_rococo_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), ) } diff --git a/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs b/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs index fc709a4fcd9e..b4a73ff8aaa8 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs @@ -81,7 +81,7 @@ pub fn asset_hub_polkadot_development_config() -> AssetHubPolkadotChainSpec { AssetHubPolkadotChainSpec::builder( asset_hub_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "polkadot-dev".into(), para_id: 1000 }, ) .with_name("Polkadot Asset Hub Development") @@ -113,7 +113,7 @@ pub fn asset_hub_polkadot_local_config() -> AssetHubPolkadotChainSpec { AssetHubPolkadotChainSpec::builder( asset_hub_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "polkadot-local".into(), para_id: 1000 }, ) .with_name("Polkadot Asset Hub Local") @@ -161,7 +161,7 @@ pub fn asset_hub_polkadot_config() -> AssetHubPolkadotChainSpec { AssetHubPolkadotChainSpec::builder( asset_hub_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "polkadot".into(), para_id: 1000 }, ) .with_name("Polkadot Asset Hub") @@ -257,7 +257,7 @@ pub fn asset_hub_kusama_development_config() -> AssetHubKusamaChainSpec { properties.insert("tokenDecimals".into(), 12.into()); AssetHubKusamaChainSpec::builder( - asset_hub_kusama_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + asset_hub_kusama_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "kusama-dev".into(), para_id: 1000 }, ) .with_name("Kusama Asset Hub Development") @@ -288,7 +288,7 @@ pub fn asset_hub_kusama_local_config() -> AssetHubKusamaChainSpec { properties.insert("tokenDecimals".into(), 12.into()); AssetHubKusamaChainSpec::builder( - asset_hub_kusama_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + asset_hub_kusama_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "kusama-local".into(), para_id: 1000 }, ) .with_name("Kusama Asset Hub Local") @@ -333,7 +333,7 @@ pub fn asset_hub_kusama_config() -> AssetHubKusamaChainSpec { properties.insert("tokenDecimals".into(), 12.into()); AssetHubKusamaChainSpec::builder( - asset_hub_kusama_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + asset_hub_kusama_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "kusama".into(), para_id: 1000 }, ) .with_name("Kusama Asset Hub") @@ -415,7 +415,7 @@ pub fn asset_hub_westend_development_config() -> AssetHubWestendChainSpec { AssetHubWestendChainSpec::builder( asset_hub_westend_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "westend".into(), para_id: 1000 }, ) .with_name("Westend Asset Hub Development") @@ -446,7 +446,7 @@ pub fn asset_hub_westend_local_config() -> AssetHubWestendChainSpec { AssetHubWestendChainSpec::builder( asset_hub_westend_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "westend-local".into(), para_id: 1000 }, ) .with_name("Westend Asset Hub Local") @@ -491,7 +491,7 @@ pub fn asset_hub_westend_config() -> AssetHubWestendChainSpec { AssetHubWestendChainSpec::builder( asset_hub_westend_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "westend".into(), para_id: 1000 }, ) .with_name("Westend Asset Hub") @@ -599,7 +599,7 @@ fn asset_hub_rococo_like_development_config( para_id: u32, ) -> AssetHubRococoChainSpec { AssetHubRococoChainSpec::builder( - asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "rococo-dev".into(), para_id }, ) .with_name(name) @@ -656,7 +656,7 @@ fn asset_hub_rococo_like_local_config( para_id: u32, ) -> AssetHubRococoChainSpec { AssetHubRococoChainSpec::builder( - asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "rococo-local".into(), para_id }, ) .with_name(name) @@ -700,7 +700,7 @@ pub fn asset_hub_rococo_genesis_config() -> AssetHubRococoChainSpec { properties.insert("tokenDecimals".into(), 12.into()); let para_id = 1000; AssetHubRococoChainSpec::builder( - asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "rococo".into(), para_id }, ) .with_name("Rococo Asset Hub") @@ -748,7 +748,7 @@ pub fn asset_hub_wococo_genesis_config() -> AssetHubWococoChainSpec { properties.insert("tokenDecimals".into(), 12.into()); let para_id = 1000; AssetHubRococoChainSpec::builder( - asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "wococo".into(), para_id }, ) .with_name("Wococo Asset Hub") diff --git a/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs b/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs index 91664f8ca21a..9e86a492108d 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs @@ -216,7 +216,7 @@ pub mod rococo { BridgeHubChainSpec::builder( bridge_hub_rococo_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, ) .with_name(chain_name) @@ -369,7 +369,7 @@ pub mod kusama { BridgeHubChainSpec::builder( bridge_hub_kusama_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, ) .with_name(chain_name) @@ -488,7 +488,7 @@ pub mod polkadot { BridgeHubChainSpec::builder( bridge_hub_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, ) .with_name(chain_name) diff --git a/cumulus/polkadot-parachain/src/chain_spec/collectives.rs b/cumulus/polkadot-parachain/src/chain_spec/collectives.rs index c6ebf3742249..0a8064f50ca5 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/collectives.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/collectives.rs @@ -44,7 +44,7 @@ pub fn collectives_polkadot_development_config() -> CollectivesPolkadotChainSpec CollectivesPolkadotChainSpec::builder( collectives_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "polkadot-dev".into(), para_id: 1002 }, ) .with_name("Polkadot Collectives Development") @@ -80,7 +80,7 @@ pub fn collectives_polkadot_local_config() -> CollectivesPolkadotChainSpec { CollectivesPolkadotChainSpec::builder( collectives_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "polkadot-local".into(), para_id: 1002 }, ) .with_name("Polkadot Collectives Local") diff --git a/cumulus/polkadot-parachain/src/chain_spec/contracts.rs b/cumulus/polkadot-parachain/src/chain_spec/contracts.rs index 108b09337f99..7ca66354fbfd 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/contracts.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/contracts.rs @@ -38,7 +38,7 @@ pub fn contracts_rococo_development_config() -> ContractsRococoChainSpec { properties.insert("tokenDecimals".into(), 12.into()); ContractsRococoChainSpec::builder( - contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "rococo-local".into(), // You MUST set this to the correct network! para_id: CONTRACTS_PARACHAIN_ID, @@ -85,7 +85,7 @@ pub fn contracts_rococo_local_config() -> ContractsRococoChainSpec { properties.insert("tokenDecimals".into(), 12.into()); ContractsRococoChainSpec::builder( - contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "rococo-local".into(), // You MUST set this to the correct network! para_id: CONTRACTS_PARACHAIN_ID, @@ -133,7 +133,7 @@ pub fn contracts_rococo_config() -> ContractsRococoChainSpec { properties.insert("tokenDecimals".into(), 12.into()); ContractsRococoChainSpec::builder( - contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "rococo".into(), para_id: CONTRACTS_PARACHAIN_ID } ) .with_name("Contracts on Rococo") diff --git a/cumulus/polkadot-parachain/src/chain_spec/glutton.rs b/cumulus/polkadot-parachain/src/chain_spec/glutton.rs index ffc5e42efcc6..1a0a06404c58 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/glutton.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/glutton.rs @@ -27,7 +27,7 @@ pub type GluttonChainSpec = sc_service::GenericChainSpec<(), Extensions>; pub fn glutton_development_config(para_id: ParaId) -> GluttonChainSpec { GluttonChainSpec::builder( - glutton_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + glutton_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "kusama-dev".into(), para_id: para_id.into() }, ) .with_name("Glutton Development") @@ -42,7 +42,7 @@ pub fn glutton_development_config(para_id: ParaId) -> GluttonChainSpec { pub fn glutton_local_config(para_id: ParaId) -> GluttonChainSpec { GluttonChainSpec::builder( - glutton_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + glutton_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "kusama-local".into(), para_id: para_id.into() }, ) .with_name("Glutton Local") @@ -63,7 +63,7 @@ pub fn glutton_config(para_id: ParaId) -> GluttonChainSpec { properties.insert("ss58Format".into(), 2.into()); GluttonChainSpec::builder( - glutton_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + glutton_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "kusama".into(), para_id: para_id.into() }, ) .with_name(format!("Glutton {}", para_id).as_str()) diff --git a/cumulus/polkadot-parachain/src/chain_spec/penpal.rs b/cumulus/polkadot-parachain/src/chain_spec/penpal.rs index 355beea56033..2e35ee231dff 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/penpal.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/penpal.rs @@ -32,7 +32,7 @@ pub fn get_penpal_chain_spec(id: ParaId, relay_chain: &str) -> PenpalChainSpec { properties.insert("ss58Format".into(), 42u32.into()); PenpalChainSpec::builder( - penpal_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + penpal_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), Extensions { relay_chain: relay_chain.into(), // You MUST set this to the correct network! para_id: id.into(), diff --git a/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs b/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs index 1031b48ea4ec..c2ba44314568 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/rococo_parachain.rs @@ -29,7 +29,7 @@ pub type RococoParachainChainSpec = sc_service::GenericChainSpec<(), Extensions> pub fn rococo_parachain_local_config() -> RococoParachainChainSpec { RococoParachainChainSpec::builder( - rococo_parachain_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + rococo_parachain_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "rococo-local".into(), para_id: 1000 }, ) .with_name("Rococo Parachain Local") @@ -60,7 +60,7 @@ pub fn rococo_parachain_local_config() -> RococoParachainChainSpec { pub fn staging_rococo_parachain_local_config() -> RococoParachainChainSpec { #[allow(deprecated)] RococoParachainChainSpec::builder( - rococo_parachain_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + rococo_parachain_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "rococo-local".into(), para_id: 1000 }, ) .with_name("Staging Rococo Parachain Local") diff --git a/cumulus/polkadot-parachain/src/chain_spec/seedling.rs b/cumulus/polkadot-parachain/src/chain_spec/seedling.rs index 4b0faa80553a..b034588e14c0 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/seedling.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/seedling.rs @@ -27,7 +27,7 @@ pub type SeedlingChainSpec = sc_service::GenericChainSpec<(), Extensions>; pub fn get_seedling_chain_spec() -> SeedlingChainSpec { SeedlingChainSpec::builder( - seedling_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + seedling_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "westend".into(), para_id: 2000 }, ) .with_name("Seedling Local Testnet") diff --git a/cumulus/polkadot-parachain/src/chain_spec/shell.rs b/cumulus/polkadot-parachain/src/chain_spec/shell.rs index f3aa377e3126..02c65e809a6c 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/shell.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/shell.rs @@ -26,7 +26,7 @@ pub type ShellChainSpec = sc_service::GenericChainSpec<(), Extensions>; pub fn get_shell_chain_spec() -> ShellChainSpec { ShellChainSpec::builder( - shell_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + shell_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), Extensions { relay_chain: "westend".into(), para_id: 1000 }, ) .with_name("Shell Local Testnet") diff --git a/cumulus/polkadot-parachain/src/command.rs b/cumulus/polkadot-parachain/src/command.rs index 2058f04822fc..1fe6ca2e3b78 100644 --- a/cumulus/polkadot-parachain/src/command.rs +++ b/cumulus/polkadot-parachain/src/command.rs @@ -1202,7 +1202,7 @@ mod tests { ) -> DummyChainSpec { DummyChainSpec::builder( rococo_parachain_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), extension, ) .with_name("Dummy local testnet") diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs index 3f450b40c21b..acbad93c4764 100644 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs @@ -109,7 +109,7 @@ pub fn asset_hub_polkadot_development_config() -> AssetHubPolkadotChainSpec { Some(properties), Extensions { relay_chain: "polkadot-dev".into(), para_id: 1000 }, asset_hub_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), ) } @@ -163,7 +163,7 @@ pub fn asset_hub_polkadot_local_config() -> AssetHubPolkadotChainSpec { Some(properties), Extensions { relay_chain: "polkadot-local".into(), para_id: 1000 }, asset_hub_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), ) } @@ -225,7 +225,7 @@ pub fn asset_hub_polkadot_config() -> AssetHubPolkadotChainSpec { None, Some(properties), Extensions { relay_chain: "polkadot".into(), para_id: 1000 }, - asset_hub_polkadot_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + asset_hub_polkadot_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), ) } @@ -311,7 +311,7 @@ pub fn asset_hub_kusama_development_config() -> AssetHubKusamaChainSpec { None, Some(properties), Extensions { relay_chain: "kusama-dev".into(), para_id: 1000 }, - asset_hub_kusama_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + asset_hub_kusama_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), ) } @@ -364,7 +364,7 @@ pub fn asset_hub_kusama_local_config() -> AssetHubKusamaChainSpec { None, Some(properties), Extensions { relay_chain: "kusama-local".into(), para_id: 1000 }, - asset_hub_kusama_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + asset_hub_kusama_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), ) } @@ -420,7 +420,7 @@ pub fn asset_hub_kusama_config() -> AssetHubKusamaChainSpec { None, Some(properties), Extensions { relay_chain: "kusama".into(), para_id: 1000 }, - asset_hub_kusama_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + asset_hub_kusama_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), ) } @@ -504,7 +504,7 @@ pub fn asset_hub_westend_development_config() -> AssetHubWestendChainSpec { Some(properties), Extensions { relay_chain: "westend".into(), para_id: 1000 }, asset_hub_westend_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), ) } @@ -557,7 +557,7 @@ pub fn asset_hub_westend_local_config() -> AssetHubWestendChainSpec { Some(properties), Extensions { relay_chain: "westend-local".into(), para_id: 1000 }, asset_hub_westend_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), ) } @@ -613,7 +613,7 @@ pub fn asset_hub_westend_config() -> AssetHubWestendChainSpec { Some(properties), Extensions { relay_chain: "westend".into(), para_id: 1000 }, asset_hub_westend_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), ) } @@ -725,7 +725,7 @@ fn asset_hub_rococo_like_development_config( None, Some(properties), Extensions { relay_chain: "rococo-dev".into(), para_id }, - asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), ) } @@ -804,7 +804,7 @@ fn asset_hub_rococo_like_local_config( None, Some(properties), Extensions { relay_chain: "rococo-local".into(), para_id }, - asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), ) } @@ -863,7 +863,7 @@ pub fn asset_hub_rococo_genesis_config() -> AssetHubRococoChainSpec { None, Some(properties), Extensions { relay_chain: "rococo".into(), para_id }, - asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), ) } @@ -923,7 +923,7 @@ pub fn asset_hub_wococo_genesis_config() -> AssetHubWococoChainSpec { None, Some(properties), Extensions { relay_chain: "wococo".into(), para_id }, - asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), ) } diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/bridge_hubs.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/bridge_hubs.rs index 60c4fdcdcf81..d9999dccdc27 100644 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/bridge_hubs.rs +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/bridge_hubs.rs @@ -265,7 +265,7 @@ pub mod rococo { Some(properties), Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, bridge_hub_rococo_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), ) } @@ -437,7 +437,7 @@ pub mod kusama { Some(properties), Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, bridge_hub_kusama_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), ) } @@ -572,7 +572,7 @@ pub mod polkadot { Some(properties), Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, bridge_hub_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), ) } diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/collectives.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/collectives.rs index dbb2b83ba48d..a064a742d208 100644 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/collectives.rs +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/collectives.rs @@ -75,7 +75,7 @@ pub fn collectives_polkadot_development_config() -> CollectivesPolkadotChainSpec Some(properties), Extensions { relay_chain: "polkadot-dev".into(), para_id: 1002 }, collectives_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), ) } @@ -130,7 +130,7 @@ pub fn collectives_polkadot_local_config() -> CollectivesPolkadotChainSpec { Some(properties), Extensions { relay_chain: "polkadot-local".into(), para_id: 1002 }, collectives_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), + .expect("WASM binary was not built, please build it!"), ) } diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/contracts.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/contracts.rs index 18a0140d5108..cbb3b5fe42ed 100644 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/contracts.rs +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/contracts.rs @@ -84,7 +84,7 @@ pub fn contracts_rococo_development_config() -> ContractsRococoChainSpec { relay_chain: "rococo-local".into(), // You MUST set this to the correct network! para_id: CONTRACTS_PARACHAIN_ID, }, - contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), ) } @@ -146,7 +146,7 @@ pub fn contracts_rococo_local_config() -> ContractsRococoChainSpec { para_id: CONTRACTS_PARACHAIN_ID, }, // Code - contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), ) } @@ -234,7 +234,7 @@ pub fn contracts_rococo_config() -> ContractsRococoChainSpec { // Extensions Extensions { relay_chain: "rococo".into(), para_id: CONTRACTS_PARACHAIN_ID }, // Code - contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), ) } diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/glutton.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/glutton.rs index 829a1e1d7cf4..d5379e86e1c0 100644 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/glutton.rs +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/glutton.rs @@ -41,7 +41,7 @@ pub fn glutton_development_config(para_id: ParaId) -> GluttonChainSpec { None, None, Extensions { relay_chain: "kusama-dev".into(), para_id: para_id.into() }, - glutton_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + glutton_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), ) } @@ -68,7 +68,7 @@ pub fn glutton_local_config(para_id: ParaId) -> GluttonChainSpec { None, None, Extensions { relay_chain: "kusama-local".into(), para_id: para_id.into() }, - glutton_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + glutton_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), ) } @@ -99,7 +99,7 @@ pub fn glutton_config(para_id: ParaId) -> GluttonChainSpec { None, Some(properties), Extensions { relay_chain: "kusama".into(), para_id: para_id.into() }, - glutton_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + glutton_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), ) } diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/penpal.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/penpal.rs index 960d4d69cb88..59c0ccf3eecc 100644 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/penpal.rs +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/penpal.rs @@ -78,7 +78,7 @@ pub fn get_penpal_chain_spec(id: ParaId, relay_chain: &str) -> PenpalChainSpec { relay_chain: relay_chain.into(), // You MUST set this to the correct network! para_id: id.into(), }, - penpal_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + penpal_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), ) } diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/rococo_parachain.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/rococo_parachain.rs index 6f1f13800c64..ddf2aa16fe5e 100644 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/rococo_parachain.rs +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/rococo_parachain.rs @@ -61,7 +61,7 @@ pub fn rococo_parachain_local_config() -> RococoParachainChainSpec { None, None, Extensions { relay_chain: "rococo-local".into(), para_id: 1000 }, - rococo_parachain_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + rococo_parachain_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), ) } @@ -94,7 +94,7 @@ pub fn staging_rococo_parachain_local_config() -> RococoParachainChainSpec { None, None, Extensions { relay_chain: "rococo-local".into(), para_id: 1000 }, - rococo_parachain_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + rococo_parachain_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), ) } diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/seedling.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/seedling.rs index 002c7f8b0db1..9be675fbe673 100644 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/seedling.rs +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/seedling.rs @@ -45,7 +45,7 @@ pub fn get_seedling_chain_spec() -> SeedlingChainSpec { None, None, Extensions { relay_chain: "westend".into(), para_id: 2000 }, - seedling_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + seedling_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), ) } diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/shell.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/shell.rs index 7cba707c732c..a9bc0b47497a 100644 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/shell.rs +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/shell.rs @@ -40,7 +40,7 @@ pub fn get_shell_chain_spec() -> ShellChainSpec { None, None, Extensions { relay_chain: "westend".into(), para_id: 1000 }, - shell_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + shell_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), ) } diff --git a/cumulus/test/service/src/chain_spec.rs b/cumulus/test/service/src/chain_spec.rs index 3b4f1818693d..257d4e9a7e2a 100644 --- a/cumulus/test/service/src/chain_spec.rs +++ b/cumulus/test/service/src/chain_spec.rs @@ -103,7 +103,7 @@ pub fn get_chain_spec_with_extra_endowed( None, None, Extensions { para_id: id.into() }, - cumulus_test_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"), + cumulus_test_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), ) } From 8564093219f911e10f3882c106d42149a3caa05e Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 30 Oct 2023 09:45:46 +0100 Subject: [PATCH 61/98] Update substrate/client/chain-spec/src/lib.rs Co-authored-by: Davide Galassi --- substrate/client/chain-spec/src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/substrate/client/chain-spec/src/lib.rs b/substrate/client/chain-spec/src/lib.rs index 015b02c3d93d..597968f1179b 100644 --- a/substrate/client/chain-spec/src/lib.rs +++ b/substrate/client/chain-spec/src/lib.rs @@ -127,9 +127,8 @@ //! - the administrative account that controls the sudo key, //! - an initial authorities set for consensus, etc. //! -//! The compiled WASM blob of the runtime code is stored in the state (and therefore on the chain). -//! As a result, the initial runtime must also be provided within the chain specification (under the -//! `code` field). +//! As the compiled WASM blob of the runtime code is stored in the chain's state, the initial runtime +//! must also be provided within the chain specification under the `code` field. //! //! The genesis state can be represented in the formats described by [`GenesisFormat`] //! enum. In essence, the most important formats are: From 8c7d66f83056dc787bab2efe57047b2b34f7ed91 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Mon, 30 Oct 2023 08:54:37 +0000 Subject: [PATCH 62/98] ".git/.scripts/commands/fmt/fmt.sh" --- substrate/client/chain-spec/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/client/chain-spec/src/lib.rs b/substrate/client/chain-spec/src/lib.rs index 597968f1179b..39baa83498a1 100644 --- a/substrate/client/chain-spec/src/lib.rs +++ b/substrate/client/chain-spec/src/lib.rs @@ -127,8 +127,8 @@ //! - the administrative account that controls the sudo key, //! - an initial authorities set for consensus, etc. //! -//! As the compiled WASM blob of the runtime code is stored in the chain's state, the initial runtime -//! must also be provided within the chain specification under the `code` field. +//! As the compiled WASM blob of the runtime code is stored in the chain's state, the initial +//! runtime must also be provided within the chain specification under the `code` field. //! //! The genesis state can be represented in the formats described by [`GenesisFormat`] //! enum. In essence, the most important formats are: From 3d8347ebc92e04a156a975340ee193c888c3ebfe Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 1 Nov 2023 08:48:01 +0100 Subject: [PATCH 63/98] Update prdoc/pr_1256.prdoc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- prdoc/pr_1256.prdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prdoc/pr_1256.prdoc b/prdoc/pr_1256.prdoc index 9e8bc569dcec..41f145e8dc19 100644 --- a/prdoc/pr_1256.prdoc +++ b/prdoc/pr_1256.prdoc @@ -7,7 +7,7 @@ doc: - audience: Node Dev description: | - [`ChainSpec::from_genesis`](https://github.com/paritytech/substrate/blob/3ef576eaeb3f42610e85daecc464961cf1295570/client/chain-spec/src/chain_spec.rs#L263) becomes deprecated in favor of [`ChainSpec::builder()`](https://github.com/paritytech/substrate/blob/20bee680ed098be7239cf7a6b804cd4de267983e/client/chain-spec/src/chain_spec.rs#L507), - - The signature of [`ChainSpec::from_genesis`] method was chagned by extending it with `code` argument. + - The signature of [`ChainSpec::from_genesis`] method was changed by extending it with `code` argument. - audience: Node Operator description: | From ceb6b16acc380af3640859f53bb9b610bbf2ea54 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 1 Nov 2023 08:49:08 +0100 Subject: [PATCH 64/98] Update substrate/client/chain-spec/src/chain_spec.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- substrate/client/chain-spec/src/chain_spec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index 407d6bd3407e..6180255622dd 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -362,7 +362,7 @@ impl ChainSpecBuilder { name: self.name, id: self.id, chain_type: self.chain_type, - boot_nodes: self.boot_nodes.unwrap_or(Default::default()), + boot_nodes: self.boot_nodes.unwrap_or_default(), telemetry_endpoints: self.telemetry_endpoints, protocol_id: self.protocol_id, fork_id: self.fork_id, From 87e60aca4638ad2211bb3800fad8a05c512e82bb Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 1 Nov 2023 09:47:42 +0100 Subject: [PATCH 65/98] Code review suggestions --- substrate/bin/utils/chain-spec-builder/bin/main.rs | 10 ++++++++-- substrate/bin/utils/chain-spec-builder/src/lib.rs | 11 ++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/substrate/bin/utils/chain-spec-builder/bin/main.rs b/substrate/bin/utils/chain-spec-builder/bin/main.rs index 3abe1e2aca70..ced8cc934d0f 100644 --- a/substrate/bin/utils/chain-spec-builder/bin/main.rs +++ b/substrate/bin/utils/chain-spec-builder/bin/main.rs @@ -101,7 +101,10 @@ fn main() -> Result<(), String> { let mut chain_spec = GenericChainSpec::<()>::from_json_file(input_chain_spec.clone())?; if let Some(path) = runtime_wasm_path { chain_spec - .set_code(&fs::read(path.as_path()).expect("wasm blob file is readable")[..]) + .set_code( + &fs::read(path.as_path()) + .map_err(|e| format!("wasm blob file shall be readable {e}"))?[..], + ) .into() } @@ -112,7 +115,10 @@ fn main() -> Result<(), String> { let mut chain_spec = GenericChainSpec::<()>::from_json_file(input_chain_spec.clone())?; if let Some(path) = runtime_wasm_path { chain_spec - .set_code(&fs::read(path.as_path()).expect("wasm blob file is readable")[..]) + .set_code( + &fs::read(path.as_path()) + .map_err(|e| format!("wasm blob file shall be readable {e}"))?[..], + ) .into() }; chain_spec.as_json(true) diff --git a/substrate/bin/utils/chain-spec-builder/src/lib.rs b/substrate/bin/utils/chain-spec-builder/src/lib.rs index cc8b4368f1ee..e1bb825d52a3 100644 --- a/substrate/bin/utils/chain-spec-builder/src/lib.rs +++ b/substrate/bin/utils/chain-spec-builder/src/lib.rs @@ -161,9 +161,9 @@ struct FullCmd { /// (e.g. session keys, babe epoch). #[derive(Parser, Debug, Clone)] struct DefaultCmd { - #[arg(long, short)] /// If provided stores the default genesis config json file at given path (in addition to /// chain-spec). + #[arg(long, short)] default_config_path: Option, } @@ -171,8 +171,8 @@ struct DefaultCmd { /// can be updated with the runtime provided in the command line. #[derive(Parser, Debug, Clone)] pub struct EditCmd { - #[arg(long, short)] /// Chain spec to be edited + #[arg(long, short)] pub input_chain_spec: PathBuf, /// The path to new runtime wasm blob to be stored into chain-spec #[arg(long, short = 'r')] @@ -186,8 +186,8 @@ pub struct EditCmd { /// new runtime. #[derive(Parser, Debug, Clone)] pub struct VerifyCmd { - #[arg(long, short)] /// Chain spec to be edited + #[arg(long, short)] pub input_chain_spec: PathBuf, /// The path to new runtime wasm blob to be stored into chain-spec #[arg(long, short = 'r')] @@ -314,7 +314,8 @@ pub fn print_seeds( /// Processes `RuntimeCmd` and returns JSON version of `ChainSpec` pub fn generate_chain_spec_for_runtime(cmd: &RuntimeCmd) -> Result { - let code = fs::read(cmd.runtime_wasm_path.as_path()).expect("wasm blob file is readable"); + let code = fs::read(cmd.runtime_wasm_path.as_path()) + .map_err(|e| format!("wasm blob shall be readable {e}"))?; let builder = chain_spec::ChainSpec::builder(&code[..], Default::default()) .with_name(&cmd.chain_name[..]) @@ -340,7 +341,7 @@ pub fn generate_chain_spec_for_runtime(cmd: &RuntimeCmd) -> Result Date: Wed, 1 Nov 2023 10:10:58 +0100 Subject: [PATCH 66/98] fix --- substrate/bin/utils/chain-spec-builder/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/bin/utils/chain-spec-builder/src/lib.rs b/substrate/bin/utils/chain-spec-builder/src/lib.rs index e1bb825d52a3..50a8dd089962 100644 --- a/substrate/bin/utils/chain-spec-builder/src/lib.rs +++ b/substrate/bin/utils/chain-spec-builder/src/lib.rs @@ -341,7 +341,7 @@ pub fn generate_chain_spec_for_runtime(cmd: &RuntimeCmd) -> Result Date: Wed, 1 Nov 2023 12:00:52 +0100 Subject: [PATCH 67/98] doc fix --- substrate/client/chain-spec/src/lib.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/substrate/client/chain-spec/src/lib.rs b/substrate/client/chain-spec/src/lib.rs index 39baa83498a1..5ec27b332576 100644 --- a/substrate/client/chain-spec/src/lib.rs +++ b/substrate/client/chain-spec/src/lib.rs @@ -16,8 +16,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#![allow(rustdoc::private_intra_doc_links)] - //! This crate includes structs and utilities for defining configuration files (known as chain //! specification) for both runtime and node. //! @@ -130,8 +128,7 @@ //! As the compiled WASM blob of the runtime code is stored in the chain's state, the initial //! runtime must also be provided within the chain specification under the `code` field. //! -//! The genesis state can be represented in the formats described by [`GenesisFormat`] -//! enum. In essence, the most important formats are: +//! In essence, the most important formats of genesis initial state are: //! //! //! From c3b99aa01df913f9e08ab4043eb55dc207266b7e Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 1 Nov 2023 18:39:01 +0100 Subject: [PATCH 68/98] chain-spec: code field move to RuntimeGenesis --- .../client/chain-spec/res/raw_with_code.json | 3 +- .../res/raw_with_code_no_encoded.json | 19 -- .../substrate_test_runtime_from_config.json | 228 +++++++-------- .../substrate_test_runtime_from_patch.json | 36 +-- substrate/client/chain-spec/src/chain_spec.rs | 274 ++++++++---------- substrate/client/chain-spec/src/lib.rs | 37 ++- 6 files changed, 272 insertions(+), 325 deletions(-) delete mode 100644 substrate/client/chain-spec/res/raw_with_code_no_encoded.json diff --git a/substrate/client/chain-spec/res/raw_with_code.json b/substrate/client/chain-spec/res/raw_with_code.json index c12cec57ba7a..afd047f8eabc 100644 --- a/substrate/client/chain-spec/res/raw_with_code.json +++ b/substrate/client/chain-spec/res/raw_with_code.json @@ -15,5 +15,6 @@ "childrenDefault": {} } }, - "code": "0x060708" + "code": "0x060708", + "xxx": "xxx" } diff --git a/substrate/client/chain-spec/res/raw_with_code_no_encoded.json b/substrate/client/chain-spec/res/raw_with_code_no_encoded.json deleted file mode 100644 index dc82ae6904b9..000000000000 --- a/substrate/client/chain-spec/res/raw_with_code_no_encoded.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "TestName", - "id": "test_id", - "chainType": "Local", - "bootNodes": [], - "telemetryEndpoints": null, - "protocolId": null, - "properties": null, - "codeSubstitutes": {}, - "genesis": { - "raw": { - "top": { - "0x3a65787472696e7369635f696e646578": "0x00000000" - }, - "childrenDefault": {} - } - }, - "code": "0x060708" -} diff --git a/substrate/client/chain-spec/res/substrate_test_runtime_from_config.json b/substrate/client/chain-spec/res/substrate_test_runtime_from_config.json index cb55d763512d..05421c06f72b 100644 --- a/substrate/client/chain-spec/res/substrate_test_runtime_from_config.json +++ b/substrate/client/chain-spec/res/substrate_test_runtime_from_config.json @@ -8,119 +8,121 @@ "properties": null, "codeSubstitutes": {}, "genesis": { - "runtimeGenesisConfig": { - "babe": { - "authorities": [ - [ - "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", - 1 - ], - [ - "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", - 1 - ], - [ - "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y", - 1 - ] - ], - "epochConfig": { - "allowed_slots": "PrimaryAndSecondaryPlainSlots", - "c": [ - 3, - 10 - ] - } + "runtimeGenesis": { + "config": { + "babe": { + "authorities": [ + [ + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + 1 + ], + [ + "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", + 1 + ], + [ + "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y", + 1 + ] + ], + "epochConfig": { + "allowed_slots": "PrimaryAndSecondaryPlainSlots", + "c": [ + 3, + 10 + ] + } + }, + "balances": { + "balances": [ + [ + "5D34dL5prEUaGNQtPPZ3yN5Y6BnkfXunKXXz6fo7ZJbLwRRH", + 100000000000000000 + ], + [ + "5GBNeWRhZc2jXu7D55rBimKYDk8PGk8itRYFTPfC8RJLKG5o", + 100000000000000000 + ], + [ + "5Dfis6XL8J2P6JHUnUtArnFWndn62SydeP8ee8sG2ky9nfm9", + 100000000000000000 + ], + [ + "5F4H97f7nQovyrbiq4ZetaaviNwThSVcFobcA5aGab6167dK", + 100000000000000000 + ], + [ + "5DiDShBWa1fQx6gLzpf3SFBhMinCoyvHM1BWjPNsmXS8hkrW", + 100000000000000000 + ], + [ + "5EFb84yH9tpcFuiKUcsmdoF7xeeY3ajG1ZLQimxQoFt9HMKR", + 100000000000000000 + ], + [ + "5DZLHESsfGrJ5YzT3HuRPXsSNb589xQ4Unubh1mYLodzKdVY", + 100000000000000000 + ], + [ + "5GHJzqvG6tXnngCpG7B12qjUvbo5e4e9z8Xjidk3CQZHxTPZ", + 100000000000000000 + ], + [ + "5CUnSsgAyLND3bxxnfNhgWXSe9Wn676JzLpGLgyJv858qhoX", + 100000000000000000 + ], + [ + "5CVKn7HAZW1Ky4r7Vkgsr7VEW88C2sHgUNDiwHY9Ct2hjU8q", + 100000000000000000 + ], + [ + "5H673aukQ4PeDe1U2nuv1bi32xDEziimh3PZz7hDdYUB7TNz", + 100000000000000000 + ], + [ + "5HTe9L15LJryjUAt1jZXZCBPnzbbGnpvFwbjE3NwCWaAqovf", + 100000000000000000 + ], + [ + "5D7LFzGpMwHPyDBavkRbWSKWTtJhCaPPZ379wWLT23bJwXJz", + 100000000000000000 + ], + [ + "5CLepMARnEgtVR1EkUuJVUvKh97gzergpSxUU3yKGx1v6EwC", + 100000000000000000 + ], + [ + "5Chb2UhfvZpmjjEziHbFbotM4quX32ZscRV6QJBt1rUKzz51", + 100000000000000000 + ], + [ + "5HmRp3i3ZZk7xsAvbi8hyXVP6whSMnBJGebVC4FsiZVhx52e", + 100000000000000000 + ], + [ + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + 100000000000000000 + ], + [ + "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", + 100000000000000000 + ], + [ + "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y", + 100000000000000000 + ] + ] + }, + "substrateTest": { + "authorities": [ + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", + "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y" + ] + }, + "system": {} }, - "balances": { - "balances": [ - [ - "5D34dL5prEUaGNQtPPZ3yN5Y6BnkfXunKXXz6fo7ZJbLwRRH", - 100000000000000000 - ], - [ - "5GBNeWRhZc2jXu7D55rBimKYDk8PGk8itRYFTPfC8RJLKG5o", - 100000000000000000 - ], - [ - "5Dfis6XL8J2P6JHUnUtArnFWndn62SydeP8ee8sG2ky9nfm9", - 100000000000000000 - ], - [ - "5F4H97f7nQovyrbiq4ZetaaviNwThSVcFobcA5aGab6167dK", - 100000000000000000 - ], - [ - "5DiDShBWa1fQx6gLzpf3SFBhMinCoyvHM1BWjPNsmXS8hkrW", - 100000000000000000 - ], - [ - "5EFb84yH9tpcFuiKUcsmdoF7xeeY3ajG1ZLQimxQoFt9HMKR", - 100000000000000000 - ], - [ - "5DZLHESsfGrJ5YzT3HuRPXsSNb589xQ4Unubh1mYLodzKdVY", - 100000000000000000 - ], - [ - "5GHJzqvG6tXnngCpG7B12qjUvbo5e4e9z8Xjidk3CQZHxTPZ", - 100000000000000000 - ], - [ - "5CUnSsgAyLND3bxxnfNhgWXSe9Wn676JzLpGLgyJv858qhoX", - 100000000000000000 - ], - [ - "5CVKn7HAZW1Ky4r7Vkgsr7VEW88C2sHgUNDiwHY9Ct2hjU8q", - 100000000000000000 - ], - [ - "5H673aukQ4PeDe1U2nuv1bi32xDEziimh3PZz7hDdYUB7TNz", - 100000000000000000 - ], - [ - "5HTe9L15LJryjUAt1jZXZCBPnzbbGnpvFwbjE3NwCWaAqovf", - 100000000000000000 - ], - [ - "5D7LFzGpMwHPyDBavkRbWSKWTtJhCaPPZ379wWLT23bJwXJz", - 100000000000000000 - ], - [ - "5CLepMARnEgtVR1EkUuJVUvKh97gzergpSxUU3yKGx1v6EwC", - 100000000000000000 - ], - [ - "5Chb2UhfvZpmjjEziHbFbotM4quX32ZscRV6QJBt1rUKzz51", - 100000000000000000 - ], - [ - "5HmRp3i3ZZk7xsAvbi8hyXVP6whSMnBJGebVC4FsiZVhx52e", - 100000000000000000 - ], - [ - "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", - 100000000000000000 - ], - [ - "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", - 100000000000000000 - ], - [ - "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y", - 100000000000000000 - ] - ] - }, - "substrateTest": { - "authorities": [ - "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", - "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", - "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y" - ] - }, - "system": {} + "code": "0x0" } - }, - "code": "0x0" + } } diff --git a/substrate/client/chain-spec/res/substrate_test_runtime_from_patch.json b/substrate/client/chain-spec/res/substrate_test_runtime_from_patch.json index 4b90844d6f5b..273bb4f91e94 100644 --- a/substrate/client/chain-spec/res/substrate_test_runtime_from_patch.json +++ b/substrate/client/chain-spec/res/substrate_test_runtime_from_patch.json @@ -8,23 +8,25 @@ "properties": null, "codeSubstitutes": {}, "genesis": { - "runtimeGenesisConfigPatch": { - "babe": { - "epochConfig": { - "allowed_slots": "PrimaryAndSecondaryPlainSlots", - "c": [ - 7, - 10 - ] - } + "runtimeGenesis": { + "patch": { + "babe": { + "epochConfig": { + "allowed_slots": "PrimaryAndSecondaryPlainSlots", + "c": [ + 7, + 10 + ] + } + }, + "substrateTest": { + "authorities": [ + "5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL", + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" + ] + } }, - "substrateTest": { - "authorities": [ - "5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL", - "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" - ] - } + "code": "0x0" } - }, - "code": "0x0" + } } diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index 6180255622dd..0cecffcde474 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -49,9 +49,11 @@ enum GenesisSource { #[deprecated( note = "Factory and G type parameter are planned to be removed in December 2023. Use `GenesisBuilderApi` instead." )] - Factory(Arc G + Send + Sync>), + /// factory function + code + Factory(Arc G + Send + Sync>, Vec), Storage(Storage), - GenesisBuilderApi(GenesisBuildAction), + /// build action + code + GenesisBuilderApi(GenesisBuildAction, Vec), } impl Clone for GenesisSource { @@ -60,9 +62,9 @@ impl Clone for GenesisSource { Self::File(ref path) => Self::File(path.clone()), Self::Binary(ref d) => Self::Binary(d.clone()), #[allow(deprecated)] - Self::Factory(ref f) => Self::Factory(f.clone()), + Self::Factory(ref f, ref c) => Self::Factory(f.clone(), c.clone()), Self::Storage(ref s) => Self::Storage(s.clone()), - Self::GenesisBuilderApi(ref s) => Self::GenesisBuilderApi(s.clone()), + Self::GenesisBuilderApi(ref s, ref c) => Self::GenesisBuilderApi(s.clone(), c.clone()), } } } @@ -100,12 +102,18 @@ impl GenesisSource { Ok(genesis.genesis) }, #[allow(deprecated)] - Self::Factory(f) => Ok(Genesis::Runtime(f())), + Self::Factory(f, code) => Ok(Genesis::Runtime(f(), code.clone())), Self::Storage(storage) => Ok(Genesis::Raw(RawGenesis::from(storage.clone()))), - Self::GenesisBuilderApi(GenesisBuildAction::Full(config)) => - Ok(Genesis::RuntimeGenesisConfig(config.clone())), - Self::GenesisBuilderApi(GenesisBuildAction::Patch(patch)) => - Ok(Genesis::RuntimeGenesisConfigPatch(patch.clone())), + Self::GenesisBuilderApi(GenesisBuildAction::Full(config), code) => + Ok(Genesis::RuntimeGenesis(RuntimeGenesisInner { + json_blob: RuntimeGenesisConfigJson::Config(config.clone()), + code: code.clone(), + })), + Self::GenesisBuilderApi(GenesisBuildAction::Patch(patch), code) => + Ok(Genesis::RuntimeGenesis(RuntimeGenesisInner { + json_blob: RuntimeGenesisConfigJson::Patch(patch.clone()), + code: code.clone(), + })), } } } @@ -114,7 +122,10 @@ impl BuildStorage for ChainSpec { fn assimilate_storage(&self, storage: &mut Storage) -> Result<(), String> { match self.genesis.resolve()? { #[allow(deprecated)] - Genesis::Runtime(gc) => gc.assimilate_storage(storage), + Genesis::Runtime(gc, code) => { + gc.assimilate_storage(storage)?; + storage.top.insert(sp_core::storage::well_known_keys::CODE.to_vec(), code); + }, Genesis::Raw(RawGenesis { top: map, children_default: children_map }) => { storage.top.extend(map.into_iter().map(|(k, v)| (k.0, v.0))); children_map.into_iter().for_each(|(k, v)| { @@ -126,25 +137,37 @@ impl BuildStorage for ChainSpec { .data .extend(v.into_iter().map(|(k, v)| (k.0, v.0))); }); - Ok(()) }, // The `StateRootHash` variant exists as a way to keep note that other clients support // it, but Substrate itself isn't capable of loading chain specs with just a hash at the // moment. - Genesis::StateRootHash(_) => Err("Genesis storage in hash format not supported".into()), - Genesis::RuntimeGenesisConfig(config) => RuntimeCaller::new(&self.code[..]) - .get_storage_for_config(config)? - .assimilate_storage(storage), - Genesis::RuntimeGenesisConfigPatch(patch) => RuntimeCaller::new(&self.code[..]) - .get_storage_for_patch(patch)? - .assimilate_storage(storage), - }?; - - if !self.code.is_empty() { - storage - .top - .insert(sp_core::storage::well_known_keys::CODE.to_vec(), self.code.clone()); - } + Genesis::StateRootHash(_) => + return Err("Genesis storage in hash format not supported".into()), + Genesis::RuntimeGenesis(RuntimeGenesisInner { + json_blob: RuntimeGenesisConfigJson::Config(config), + code, + }) => { + RuntimeCaller::new(&code[..]) + .get_storage_for_config(config)? + .assimilate_storage(storage)?; + + storage + .top + .insert(sp_core::storage::well_known_keys::CODE.to_vec(), code.clone()); + }, + Genesis::RuntimeGenesis(RuntimeGenesisInner { + json_blob: RuntimeGenesisConfigJson::Patch(patch), + code, + }) => { + RuntimeCaller::new(&code[..]) + .get_storage_for_patch(patch)? + .assimilate_storage(storage)?; + + storage + .top + .insert(sp_core::storage::well_known_keys::CODE.to_vec(), code.clone()); + }, + }; Ok(()) } @@ -183,33 +206,55 @@ impl From for RawGenesis { } } -/// Represents different formats for the GenesisConfig configuration. +/// Inner representation of RuntimeGenesis format +#[derive(Serialize, Deserialize, Debug)] +struct RuntimeGenesisInner { + /// runtime wasm code, expected to be hex-encoded + /// The code shall be capable of parsing `json_blob`. + #[serde(default, with = "sp_core::bytes")] + code: Vec, + /// patch or full config, this field will be flattened + #[serde(flatten)] + json_blob: RuntimeGenesisConfigJson, +} + +/// Represents two possible variants of the contained JSON blob for the RuntimeGenesis format. +#[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +enum RuntimeGenesisConfigJson { + /// Represents the explicit and comprehensive runtime genesis config in JSON format. + /// The contained object is a JSON blob that can be parsed by a compatible runtime. + Config(json::Value), + /// Represents a patch for the default runtime genesis config in JSON format which is + /// essentially a list of keys that are to be customized in runtime genesis config. + /// The contained value is a JSON blob that can be parsed by a compatible runtime. + Patch(json::Value), +} + +/// Represents different formats of the GenesisConfig configuration within chain spec JSON blob. #[derive(Serialize, Deserialize)] #[serde(rename_all = "camelCase")] #[serde(deny_unknown_fields)] -pub enum Genesis { +enum Genesis { /// (Deprecated) Contains the JSON representation of G (the native type representing the - /// runtime GenesisConfig struct) (will be removed with `ChainSpec::from_genesis`). - Runtime(G), + /// runtime GenesisConfig struct) (will be removed with `ChainSpec::from_genesis`) and the + /// runtime code. + Runtime(G, Vec), /// The genesis storage as raw data. Typically raw key-value entries in state. Raw(RawGenesis), /// State root hash of the genesis storage. StateRootHash(StorageData), - /// Represents the explicit and comprehensive runtime genesis config in JSON format. - /// The contained object is a JSON blob that can be parsed by a compatible runtime. - RuntimeGenesisConfig(json::Value), - /// Represents a patch for the default runtime genesis config in JSON format which is - /// essentially a list of keys that are to be customized in runtime genesis config. - /// The contained value is a JSON blob that can be parsed by a compatible runtime. - RuntimeGenesisConfigPatch(json::Value), + /// Represents the runtime genesis config in JSON format toghether with runtime code. + RuntimeGenesis(RuntimeGenesisInner), } /// A configuration of a client. Does not include runtime storage initialization. -/// Note: `genesis` and `code` are ignored due to way how the chain specification is serialized into +/// Note: `genesis` field is ignored due to way how the chain specification is serialized into /// JSON file. Refer to [`ChainSpecJsonContainer`], which flattens [`ClientSpec`] and denies uknown /// fields. #[derive(Serialize, Deserialize, Clone, Debug)] #[serde(rename_all = "camelCase")] +#[serde(deny_unknown_fields)] struct ClientSpec { name: String, id: String, @@ -233,9 +278,6 @@ struct ClientSpec { #[serde(skip_serializing)] #[allow(unused)] genesis: serde::de::IgnoredAny, - #[serde(skip)] - #[allow(unused)] - code: serde::de::IgnoredAny, /// Mapping from `block_number` to `wasm_code`. /// /// The given `wasm_code` will be used to substitute the on-chain wasm code starting with the @@ -370,14 +412,12 @@ impl ChainSpecBuilder { extensions: self.extensions, consensus_engine: (), genesis: Default::default(), - code: Default::default(), code_substitutes: BTreeMap::new(), }; ChainSpec { client_spec, - genesis: GenesisSource::GenesisBuilderApi(self.genesis_build_action), - code: self.code, + genesis: GenesisSource::GenesisBuilderApi(self.genesis_build_action, self.code.into()), } } } @@ -386,16 +426,11 @@ impl ChainSpecBuilder { pub struct ChainSpec { client_spec: ClientSpec, genesis: GenesisSource, - code: Vec, } impl Clone for ChainSpec { fn clone(&self) -> Self { - ChainSpec { - client_spec: self.client_spec.clone(), - genesis: self.genesis.clone(), - code: self.code.clone(), - } + ChainSpec { client_spec: self.client_spec.clone(), genesis: self.genesis.clone() } } } @@ -482,15 +517,13 @@ impl ChainSpec { extensions, consensus_engine: (), genesis: Default::default(), - code: Default::default(), code_substitutes: BTreeMap::new(), }; #[allow(deprecated)] ChainSpec { client_spec, - genesis: GenesisSource::Factory(Arc::new(constructor)), - code: code.into(), + genesis: GenesisSource::Factory(Arc::new(constructor), code.into()), } } @@ -499,24 +532,12 @@ impl ChainSpec { self.client_spec.chain_type.clone() } - /// Sets the code. - pub fn set_code(&mut self, code: &[u8]) { - self.code = code.into(); - } - /// Provides a `ChainSpec` builder. pub fn builder(code: &[u8], extensions: E) -> ChainSpecBuilder { ChainSpecBuilder::new(code, extensions) } } -/// Helper structure for deserializing optional `code` attribute from JSON file. -#[derive(Serialize, Deserialize)] -struct CodeContainer { - #[serde(default, with = "sp_core::bytes")] - code: Vec, -} - impl ChainSpec { /// Parse json content into a `ChainSpec` pub fn from_json_bytes(json: impl Into>) -> Result { @@ -524,10 +545,7 @@ impl ChainSpec ChainSpec { #[serde(flatten)] client_spec: ClientSpec, genesis: Genesis, - #[serde(with = "sp_core::bytes", skip_serializing_if = "Vec::is_empty")] - code: Vec, } impl ChainSpec { fn json_container(&self, raw: bool) -> Result, String> { - let mut raw_genesis = match (raw, self.genesis.resolve()?) { - (true, Genesis::RuntimeGenesisConfigPatch(patch)) => { - let storage = RuntimeCaller::new(&self.code[..]).get_storage_for_patch(patch)?; + let raw_genesis = match (raw, self.genesis.resolve()?) { + ( + true, + Genesis::RuntimeGenesis(RuntimeGenesisInner { + json_blob: RuntimeGenesisConfigJson::Config(config), + code, + }), + ) => { + let mut storage = RuntimeCaller::new(&code[..]).get_storage_for_config(config)?; + + storage.top.insert(sp_core::storage::well_known_keys::CODE.to_vec(), code); RawGenesis::from(storage) }, - (true, Genesis::RuntimeGenesisConfig(config)) => { - let storage = RuntimeCaller::new(&self.code[..]).get_storage_for_config(config)?; + ( + true, + Genesis::RuntimeGenesis(RuntimeGenesisInner { + json_blob: RuntimeGenesisConfigJson::Patch(patch), + code, + }), + ) => { + let mut storage = RuntimeCaller::new(&code[..]).get_storage_for_patch(patch)?; + + storage.top.insert(sp_core::storage::well_known_keys::CODE.to_vec(), code); RawGenesis::from(storage) }, + #[allow(deprecated)] - (true, Genesis::Runtime(g)) => { - let storage = g.build_storage()?; + (true, Genesis::Runtime(g, code)) => { + let mut storage = g.build_storage()?; + storage.top.insert(sp_core::storage::well_known_keys::CODE.to_vec(), code); RawGenesis::from(storage) }, (true, Genesis::Raw(raw)) => raw, (_, genesis) => - return Ok(ChainSpecJsonContainer { - client_spec: self.client_spec.clone(), - genesis, - code: self.code.clone(), - }), + return Ok(ChainSpecJsonContainer { client_spec: self.client_spec.clone(), genesis }), }; - if !self.code.is_empty() { - raw_genesis.top.insert( - StorageKey(sp_core::storage::well_known_keys::CODE.to_vec()), - StorageData(self.code.clone()), - ); - } - Ok(ChainSpecJsonContainer { client_spec: self.client_spec.clone(), genesis: Genesis::Raw(raw_genesis), - code: vec![], }) } @@ -860,7 +878,10 @@ mod tests { json_path!["genesis", "raw", "top", "0x3a636f6465"], ) } else { - (json!({"code":"0x0"}), json_path!["code"]) + ( + json!({"genesis":{"runtimeGenesis":{"code":"0x0"}}}), + json_path!["genesis", "runtimeGenesis", "code"], + ) }; assert!(json_contains_path(&json, &mut path)); crate::json_patch::merge(&mut json, zeroing_patch); @@ -1039,69 +1060,12 @@ mod tests { } #[test] - fn check_if_code_is_removed_from_raw_with_encoded() { - let spec = ChainSpec::<()>::from_json_bytes(Cow::Owned( - include_bytes!("../res/raw_with_code.json").to_vec(), - )) - .unwrap(); - - let j = from_str::(&spec.as_json(true).unwrap()).unwrap(); - - assert!(json_eval_value_at_key( - &j, - &mut json_path!["genesis", "raw", "top", "0x3a636f6465"], - &|v| { *v == "0x060708" } - )); - - assert!(!json_contains_path(&j, &mut json_path!["code"])); - } - - #[test] - fn check_if_code_is_removed_from_raw_without_encoded() { - let spec = ChainSpec::<()>::from_json_bytes(Cow::Owned( - include_bytes!("../res/raw_with_code_no_encoded.json").to_vec(), - )) - .unwrap(); - - let j = from_str::(&spec.as_json(true).unwrap()).unwrap(); - - assert!(json_eval_value_at_key( - &j, - &mut json_path!["genesis", "raw", "top", "0x3a636f6465"], - &|v| { *v == "0x060708" } - )); - - assert!(!json_contains_path(&j, &mut json_path!["code"])); - } - - #[test] + #[should_panic(expected = "unknown field `code`")] fn check_code_in_assimilated_storage_for_raw_with_encoded() { - let spec = ChainSpec::<()>::from_json_bytes(Cow::Owned( + let _ = ChainSpec::<()>::from_json_bytes(Cow::Owned( include_bytes!("../res/raw_with_code.json").to_vec(), )) .unwrap(); - - let storage = spec.build_storage().unwrap(); - assert!(storage - .top - .get(&well_known_keys::CODE.to_vec()) - .map(|v| *v == vec![6, 7, 8]) - .unwrap()) - } - - #[test] - fn check_code_in_assimilated_storage_for_raw_without_encoded() { - let spec = ChainSpec::<()>::from_json_bytes(Cow::Owned( - include_bytes!("../res/raw_with_code_no_encoded.json").to_vec(), - )) - .unwrap(); - - let storage = spec.build_storage().unwrap(); - assert!(storage - .top - .get(&well_known_keys::CODE.to_vec()) - .map(|v| *v == vec![6, 7, 8]) - .unwrap()) } #[test] diff --git a/substrate/client/chain-spec/src/lib.rs b/substrate/client/chain-spec/src/lib.rs index 5ec27b332576..a26606072aee 100644 --- a/substrate/client/chain-spec/src/lib.rs +++ b/substrate/client/chain-spec/src/lib.rs @@ -32,11 +32,10 @@ //! blocks are built. When the node is launched for the first time, it reads the chain spec, //! initializes the genesis block, and establishes connections with the boot nodes. //! -//! The JSON chain spec is divided into three main logical sections: +//! The JSON chain spec is divided into two main logical sections: //! - one section details general chain properties, -//! - another explicitly or indirectly defines the genesis storage, which, in turn, determines the +//! - second explicitly or indirectly defines the genesis storage, which, in turn, determines the //! genesis hash of the chain, -//! - the third deals with the runtime code. //! //! The chain specification consists of the following fields: //! @@ -104,10 +103,6 @@ //! //! //! -//! -//! -//! -//! //! //!
genesisDefines the initial state of the runtime. More details in material to follow.
codeThe runtime wasm code blob in hex format.
//! @@ -126,7 +121,7 @@ //! - an initial authorities set for consensus, etc. //! //! As the compiled WASM blob of the runtime code is stored in the chain's state, the initial -//! runtime must also be provided within the chain specification under the `code` field. +//! runtime must also be provided within the chain specification. //! //! In essence, the most important formats of genesis initial state are: //! @@ -140,7 +135,7 @@ //! //! //! -//! runtime +//! runtime //! //! A JSON object that provides an explicit and comprehensive representation of the //! RuntimeGenesisConfig struct, which is generated by frame::runtime::prelude::construct_runtime macro (example of generated struct). Must contain all the keys of -//! the genesis config, no defaults will be used. +//! the genesis config, no defaults will be used. +//! +//! This format explicitly provides the code of the runtime. +//! //! //! -//! patch +//! patch //! //! A JSON object that offers a partial representation of the //! RuntimeGenesisConfig provided by the runtime. It contains a patch, which is //! essentially a list of key-value pairs to customize in the default runtime's //! RuntimeGenesisConfig. +//! +//! This format explicitly provides the code of the runtime. //! //! //! -//! raw +//! raw //! //! A JSON object with two fields: top and children_default. //! Each field is a map of key => value pairs representing entries in a genesis storage //! trie. +//! +//! The runtime code is stored in the state as one of the key-pair entry. //! //! //! //! //! For production or long-lasting blockchains, using the `raw` format in the chain specification is //! recommended. Only the `raw` format guarantees that storage root hash will remain unchanged when -//! the RuntimeGenesisConfig format changes due to software upgrade. +//! the `RuntimeGenesisConfig` format changes due to software upgrade. //! //! JSON examples in the [following section](#json-chain-specification-example) illustrate the `raw` //! and `runtimeGenesisConfigPatch` genesis fields. @@ -188,10 +190,7 @@ //! the genesis hash. //! //! Consequently, the runtime must support the [`sp_genesis_builder::GenesisBuilder`] API to -//! utilize either [`RuntimeGenesisConfigPatch`][patch] or [`RuntimeGenesisConfig`][full] formats. -//! -//! [patch]: chain_spec::Genesis::RuntimeGenesisConfigPatch -//! [full]: chain_spec::Genesis::RuntimeGenesisConfig +//! utilize either `patch` or `full` formats. //! //! This entire process is encapsulated within the implementation of the [`BuildStorage`] trait, //! which can be accessed through the [`ChainSpec::as_storage_builder`] method. There is an @@ -327,9 +326,7 @@ mod genesis_config_builder; mod json_patch; pub use self::{ - chain_spec::{ - ChainSpec as GenericChainSpec, ChainSpecBuilder, Genesis as GenesisFormat, NoExtension, - }, + chain_spec::{ChainSpec as GenericChainSpec, ChainSpecBuilder, NoExtension}, extension::{get_extension, get_extension_mut, Extension, Fork, Forks, GetExtension, Group}, genesis_block::{ construct_genesis_block, resolve_state_version_from_wasm, BuildGenesisBlock, From 2702ef637e390d2e96a8fd48d7741e0bb15c53f1 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 1 Nov 2023 18:55:09 +0100 Subject: [PATCH 69/98] fmt --- .../substrate_test_runtime_from_config.json | 222 +++++++++--------- .../substrate_test_runtime_from_patch.json | 30 +-- 2 files changed, 126 insertions(+), 126 deletions(-) diff --git a/substrate/client/chain-spec/res/substrate_test_runtime_from_config.json b/substrate/client/chain-spec/res/substrate_test_runtime_from_config.json index 05421c06f72b..06a0ec17b43f 100644 --- a/substrate/client/chain-spec/res/substrate_test_runtime_from_config.json +++ b/substrate/client/chain-spec/res/substrate_test_runtime_from_config.json @@ -10,117 +10,117 @@ "genesis": { "runtimeGenesis": { "config": { - "babe": { - "authorities": [ - [ - "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", - 1 - ], - [ - "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", - 1 - ], - [ - "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y", - 1 - ] - ], - "epochConfig": { - "allowed_slots": "PrimaryAndSecondaryPlainSlots", - "c": [ - 3, - 10 - ] - } - }, - "balances": { - "balances": [ - [ - "5D34dL5prEUaGNQtPPZ3yN5Y6BnkfXunKXXz6fo7ZJbLwRRH", - 100000000000000000 - ], - [ - "5GBNeWRhZc2jXu7D55rBimKYDk8PGk8itRYFTPfC8RJLKG5o", - 100000000000000000 - ], - [ - "5Dfis6XL8J2P6JHUnUtArnFWndn62SydeP8ee8sG2ky9nfm9", - 100000000000000000 - ], - [ - "5F4H97f7nQovyrbiq4ZetaaviNwThSVcFobcA5aGab6167dK", - 100000000000000000 - ], - [ - "5DiDShBWa1fQx6gLzpf3SFBhMinCoyvHM1BWjPNsmXS8hkrW", - 100000000000000000 - ], - [ - "5EFb84yH9tpcFuiKUcsmdoF7xeeY3ajG1ZLQimxQoFt9HMKR", - 100000000000000000 - ], - [ - "5DZLHESsfGrJ5YzT3HuRPXsSNb589xQ4Unubh1mYLodzKdVY", - 100000000000000000 - ], - [ - "5GHJzqvG6tXnngCpG7B12qjUvbo5e4e9z8Xjidk3CQZHxTPZ", - 100000000000000000 - ], - [ - "5CUnSsgAyLND3bxxnfNhgWXSe9Wn676JzLpGLgyJv858qhoX", - 100000000000000000 - ], - [ - "5CVKn7HAZW1Ky4r7Vkgsr7VEW88C2sHgUNDiwHY9Ct2hjU8q", - 100000000000000000 - ], - [ - "5H673aukQ4PeDe1U2nuv1bi32xDEziimh3PZz7hDdYUB7TNz", - 100000000000000000 - ], - [ - "5HTe9L15LJryjUAt1jZXZCBPnzbbGnpvFwbjE3NwCWaAqovf", - 100000000000000000 - ], - [ - "5D7LFzGpMwHPyDBavkRbWSKWTtJhCaPPZ379wWLT23bJwXJz", - 100000000000000000 - ], - [ - "5CLepMARnEgtVR1EkUuJVUvKh97gzergpSxUU3yKGx1v6EwC", - 100000000000000000 - ], - [ - "5Chb2UhfvZpmjjEziHbFbotM4quX32ZscRV6QJBt1rUKzz51", - 100000000000000000 - ], - [ - "5HmRp3i3ZZk7xsAvbi8hyXVP6whSMnBJGebVC4FsiZVhx52e", - 100000000000000000 - ], - [ - "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", - 100000000000000000 - ], - [ - "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", - 100000000000000000 - ], - [ - "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y", - 100000000000000000 - ] - ] - }, - "substrateTest": { - "authorities": [ - "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", - "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", - "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y" - ] - }, - "system": {} + "babe": { + "authorities": [ + [ + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + 1 + ], + [ + "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", + 1 + ], + [ + "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y", + 1 + ] + ], + "epochConfig": { + "allowed_slots": "PrimaryAndSecondaryPlainSlots", + "c": [ + 3, + 10 + ] + } + }, + "balances": { + "balances": [ + [ + "5D34dL5prEUaGNQtPPZ3yN5Y6BnkfXunKXXz6fo7ZJbLwRRH", + 1e+17 + ], + [ + "5GBNeWRhZc2jXu7D55rBimKYDk8PGk8itRYFTPfC8RJLKG5o", + 1e+17 + ], + [ + "5Dfis6XL8J2P6JHUnUtArnFWndn62SydeP8ee8sG2ky9nfm9", + 1e+17 + ], + [ + "5F4H97f7nQovyrbiq4ZetaaviNwThSVcFobcA5aGab6167dK", + 1e+17 + ], + [ + "5DiDShBWa1fQx6gLzpf3SFBhMinCoyvHM1BWjPNsmXS8hkrW", + 1e+17 + ], + [ + "5EFb84yH9tpcFuiKUcsmdoF7xeeY3ajG1ZLQimxQoFt9HMKR", + 1e+17 + ], + [ + "5DZLHESsfGrJ5YzT3HuRPXsSNb589xQ4Unubh1mYLodzKdVY", + 1e+17 + ], + [ + "5GHJzqvG6tXnngCpG7B12qjUvbo5e4e9z8Xjidk3CQZHxTPZ", + 1e+17 + ], + [ + "5CUnSsgAyLND3bxxnfNhgWXSe9Wn676JzLpGLgyJv858qhoX", + 1e+17 + ], + [ + "5CVKn7HAZW1Ky4r7Vkgsr7VEW88C2sHgUNDiwHY9Ct2hjU8q", + 1e+17 + ], + [ + "5H673aukQ4PeDe1U2nuv1bi32xDEziimh3PZz7hDdYUB7TNz", + 1e+17 + ], + [ + "5HTe9L15LJryjUAt1jZXZCBPnzbbGnpvFwbjE3NwCWaAqovf", + 1e+17 + ], + [ + "5D7LFzGpMwHPyDBavkRbWSKWTtJhCaPPZ379wWLT23bJwXJz", + 1e+17 + ], + [ + "5CLepMARnEgtVR1EkUuJVUvKh97gzergpSxUU3yKGx1v6EwC", + 1e+17 + ], + [ + "5Chb2UhfvZpmjjEziHbFbotM4quX32ZscRV6QJBt1rUKzz51", + 1e+17 + ], + [ + "5HmRp3i3ZZk7xsAvbi8hyXVP6whSMnBJGebVC4FsiZVhx52e", + 1e+17 + ], + [ + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + 1e+17 + ], + [ + "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", + 1e+17 + ], + [ + "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y", + 1e+17 + ] + ] + }, + "substrateTest": { + "authorities": [ + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", + "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", + "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y" + ] + }, + "system": {} }, "code": "0x0" } diff --git a/substrate/client/chain-spec/res/substrate_test_runtime_from_patch.json b/substrate/client/chain-spec/res/substrate_test_runtime_from_patch.json index 273bb4f91e94..6cef1dac7ac3 100644 --- a/substrate/client/chain-spec/res/substrate_test_runtime_from_patch.json +++ b/substrate/client/chain-spec/res/substrate_test_runtime_from_patch.json @@ -10,21 +10,21 @@ "genesis": { "runtimeGenesis": { "patch": { - "babe": { - "epochConfig": { - "allowed_slots": "PrimaryAndSecondaryPlainSlots", - "c": [ - 7, - 10 - ] - } - }, - "substrateTest": { - "authorities": [ - "5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL", - "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" - ] - } + "babe": { + "epochConfig": { + "allowed_slots": "PrimaryAndSecondaryPlainSlots", + "c": [ + 7, + 10 + ] + } + }, + "substrateTest": { + "authorities": [ + "5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL", + "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" + ] + } }, "code": "0x0" } From 91bc747f30b757061da0698343c583d6e928138b Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 1 Nov 2023 20:30:06 +0100 Subject: [PATCH 70/98] fixes --- .../bin/utils/chain-spec-builder/bin/main.rs | 35 ++-- .../client/chain-spec/res/raw_with_code.json | 3 +- .../substrate_test_runtime_from_config.json | 38 ++-- substrate/client/chain-spec/src/chain_spec.rs | 185 ++++++++++++++---- substrate/client/chain-spec/src/lib.rs | 23 ++- 5 files changed, 199 insertions(+), 85 deletions(-) diff --git a/substrate/bin/utils/chain-spec-builder/bin/main.rs b/substrate/bin/utils/chain-spec-builder/bin/main.rs index ced8cc934d0f..e97df346c71e 100644 --- a/substrate/bin/utils/chain-spec-builder/bin/main.rs +++ b/substrate/bin/utils/chain-spec-builder/bin/main.rs @@ -23,7 +23,7 @@ use chain_spec_builder::{ use clap::Parser; use node_cli::chain_spec; use rand::{distributions::Alphanumeric, rngs::OsRng, Rng}; -use sc_chain_spec::GenericChainSpec; +use sc_chain_spec::{update_code_in_json_chain_spec, GenericChainSpec}; use sp_core::{crypto::Ss58Codec, sr25519}; use std::fs; @@ -98,28 +98,33 @@ fn main() -> Result<(), String> { ref runtime_wasm_path, convert_to_raw, }) => { - let mut chain_spec = GenericChainSpec::<()>::from_json_file(input_chain_spec.clone())?; + let chain_spec = GenericChainSpec::<()>::from_json_file(input_chain_spec.clone())?; + + let mut chain_spec_json = + serde_json::from_str::(&chain_spec.as_json(false)?) + .map_err(|e| format!("Conversion to json failed: {e}"))?; if let Some(path) = runtime_wasm_path { - chain_spec - .set_code( - &fs::read(path.as_path()) - .map_err(|e| format!("wasm blob file shall be readable {e}"))?[..], - ) - .into() + update_code_in_json_chain_spec( + &mut chain_spec_json, + &fs::read(path.as_path()) + .map_err(|e| format!("Wasm blob file could not be read: {e}"))?[..], + ); } chain_spec.as_json(convert_to_raw) }, ChainSpecBuilderCmd::Verify(VerifyCmd { ref input_chain_spec, ref runtime_wasm_path }) => { write_chain_spec = false; - let mut chain_spec = GenericChainSpec::<()>::from_json_file(input_chain_spec.clone())?; + let chain_spec = GenericChainSpec::<()>::from_json_file(input_chain_spec.clone())?; + let mut chain_spec_json = + serde_json::from_str::(&chain_spec.as_json(false)?) + .map_err(|e| format!("Conversion to json failed: {e}"))?; if let Some(path) = runtime_wasm_path { - chain_spec - .set_code( - &fs::read(path.as_path()) - .map_err(|e| format!("wasm blob file shall be readable {e}"))?[..], - ) - .into() + update_code_in_json_chain_spec( + &mut chain_spec_json, + &fs::read(path.as_path()) + .map_err(|e| format!("Wasm blob file could not be read: {e}"))?[..], + ); }; chain_spec.as_json(true) }, diff --git a/substrate/client/chain-spec/res/raw_with_code.json b/substrate/client/chain-spec/res/raw_with_code.json index afd047f8eabc..c12cec57ba7a 100644 --- a/substrate/client/chain-spec/res/raw_with_code.json +++ b/substrate/client/chain-spec/res/raw_with_code.json @@ -15,6 +15,5 @@ "childrenDefault": {} } }, - "code": "0x060708", - "xxx": "xxx" + "code": "0x060708" } diff --git a/substrate/client/chain-spec/res/substrate_test_runtime_from_config.json b/substrate/client/chain-spec/res/substrate_test_runtime_from_config.json index 06a0ec17b43f..d16f26d12540 100644 --- a/substrate/client/chain-spec/res/substrate_test_runtime_from_config.json +++ b/substrate/client/chain-spec/res/substrate_test_runtime_from_config.json @@ -37,79 +37,79 @@ "balances": [ [ "5D34dL5prEUaGNQtPPZ3yN5Y6BnkfXunKXXz6fo7ZJbLwRRH", - 1e+17 + 100000000000000000 ], [ "5GBNeWRhZc2jXu7D55rBimKYDk8PGk8itRYFTPfC8RJLKG5o", - 1e+17 + 100000000000000000 ], [ "5Dfis6XL8J2P6JHUnUtArnFWndn62SydeP8ee8sG2ky9nfm9", - 1e+17 + 100000000000000000 ], [ "5F4H97f7nQovyrbiq4ZetaaviNwThSVcFobcA5aGab6167dK", - 1e+17 + 100000000000000000 ], [ "5DiDShBWa1fQx6gLzpf3SFBhMinCoyvHM1BWjPNsmXS8hkrW", - 1e+17 + 100000000000000000 ], [ "5EFb84yH9tpcFuiKUcsmdoF7xeeY3ajG1ZLQimxQoFt9HMKR", - 1e+17 + 100000000000000000 ], [ "5DZLHESsfGrJ5YzT3HuRPXsSNb589xQ4Unubh1mYLodzKdVY", - 1e+17 + 100000000000000000 ], [ "5GHJzqvG6tXnngCpG7B12qjUvbo5e4e9z8Xjidk3CQZHxTPZ", - 1e+17 + 100000000000000000 ], [ "5CUnSsgAyLND3bxxnfNhgWXSe9Wn676JzLpGLgyJv858qhoX", - 1e+17 + 100000000000000000 ], [ "5CVKn7HAZW1Ky4r7Vkgsr7VEW88C2sHgUNDiwHY9Ct2hjU8q", - 1e+17 + 100000000000000000 ], [ "5H673aukQ4PeDe1U2nuv1bi32xDEziimh3PZz7hDdYUB7TNz", - 1e+17 + 100000000000000000 ], [ "5HTe9L15LJryjUAt1jZXZCBPnzbbGnpvFwbjE3NwCWaAqovf", - 1e+17 + 100000000000000000 ], [ "5D7LFzGpMwHPyDBavkRbWSKWTtJhCaPPZ379wWLT23bJwXJz", - 1e+17 + 100000000000000000 ], [ "5CLepMARnEgtVR1EkUuJVUvKh97gzergpSxUU3yKGx1v6EwC", - 1e+17 + 100000000000000000 ], [ "5Chb2UhfvZpmjjEziHbFbotM4quX32ZscRV6QJBt1rUKzz51", - 1e+17 + 100000000000000000 ], [ "5HmRp3i3ZZk7xsAvbi8hyXVP6whSMnBJGebVC4FsiZVhx52e", - 1e+17 + 100000000000000000 ], [ "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY", - 1e+17 + 100000000000000000 ], [ "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty", - 1e+17 + 100000000000000000 ], [ "5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y", - 1e+17 + 100000000000000000 ] ] }, diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index 0cecffcde474..43ff9748b0b6 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -32,7 +32,12 @@ use sp_core::{ }; use sp_runtime::BuildStorage; use std::{ - borrow::Cow, collections::BTreeMap, fs::File, marker::PhantomData, path::PathBuf, sync::Arc, + borrow::Cow, + collections::{BTreeMap, VecDeque}, + fs::File, + marker::PhantomData, + path::PathBuf, + sync::Arc, }; #[derive(Serialize, Deserialize, Clone)] @@ -711,6 +716,77 @@ where } } +/// The `fun` will be called with the value at `path`. +/// +/// If exists, the value at given `path` will be passed to the `fun` and the result of `fun` +/// call will be returned. Otherwise false is returned. +/// `path` will be modified. +/// +/// # Examples +/// ``` +/// use serde_json::{from_str, json, Value}; +/// let doc = json!({"a":{"b":{"c":"5"}}}); +/// let mut path = ["a", "b", "c"].into(); +/// assert!(json_eval_value_at_key(&doc, &mut path, &|v| { assert_eq!(v,"5"); true })); +/// ``` +fn json_eval_value_at_key( + doc: &json::Value, + path: &mut VecDeque<&str>, + fun: &dyn Fn(&json::Value) -> bool, +) -> bool { + if path.len() == 1 { + doc.as_object().map_or(false, |o| o.get(path[0]).map_or(false, |v| fun(v))) + } else { + let key = path.pop_front().unwrap(); + doc.as_object() + .map_or(false, |o| o.get(key).map_or(false, |v| json_eval_value_at_key(v, path, fun))) + } +} + +macro_rules! json_path { + [ $($x:expr),+ ] => { + VecDeque::<&str>::from([$($x),+]) + }; +} + +fn json_contains_path(doc: &json::Value, path: &mut VecDeque<&str>) -> bool { + json_eval_value_at_key(doc, path, &|_| true) +} + +/// This function updates the code in given chain spec. +/// +/// Function support updating the runtime code in provided JSON chain spec blob. `Genesis::Raw` +/// and `Genesis::RuntimeGenesis` formats are supported. +/// +/// If update was successful `true` is returned, otherwise `false`. Chain spec JSON is modified in +/// place. +pub fn update_code_in_json_chain_spec<'a>(chain_spec: &mut json::Value, code: &'a [u8]) -> bool { + let mut path = json_path!["genesis", "runtimeGenesis", "code"]; + let mut raw_path = json_path!["genesis", "raw", "top", "0x3a636f6465"]; + + if json_contains_path(&chain_spec, &mut path) { + #[derive(Serialize)] + struct Container<'a> { + #[serde(with = "sp_core::bytes")] + code: &'a [u8], + } + let code_patch = json::json!({"genesis":{"runtimeGenesis": Container { code }}}); + crate::json_patch::merge(chain_spec, code_patch); + true + } else if json_contains_path(&chain_spec, &mut raw_path) { + #[derive(Serialize)] + struct Container<'a> { + #[serde(with = "sp_core::bytes", rename = "0x3a636f6465")] + code: &'a [u8], + } + let code_patch = json::json!({"genesis":{"raw":{"top": Container { code }}}}); + crate::json_patch::merge(chain_spec, code_patch); + true + } else { + false + } +} + #[cfg(test)] mod tests { use super::*; @@ -718,7 +794,6 @@ mod tests { use sp_application_crypto::Ss58Codec; use sp_core::storage::well_known_keys; use sp_keyring::AccountKeyring; - use std::collections::VecDeque; #[derive(Debug, Serialize, Deserialize)] struct Genesis(BTreeMap); @@ -811,44 +886,6 @@ mod tests { } } - macro_rules! json_path { - [ $($x:expr),+ ] => { - VecDeque::::from([$($x),+].map(String::from)) - }; - } - - /// The `fun` will be called with the value at `path`. - /// - /// If exists, the value at given `path` will be passed to the `fun` and the result of `fun` - /// call will be returned. Otherwise false is returned. - /// `path` will be modified. - /// - /// # Examples - /// ``` - /// use serde_json::{from_str, json, Value}; - /// let doc = json!({"a":{"b":{"c":"5"}}}); - /// let mut path = ["a", "b", "c"].map(String::from).into(); - /// assert!(json_eval_value_at_key(&doc, &mut path, &|v| { assert_eq!(v,"5"); true })); - /// ``` - pub fn json_eval_value_at_key( - doc: &Value, - path: &mut VecDeque, - fun: &dyn Fn(&Value) -> bool, - ) -> bool { - if path.len() == 1 { - doc.as_object().map_or(false, |o| o.get(&path[0]).map_or(false, |v| fun(v))) - } else { - let key = path.pop_front().unwrap(); - doc.as_object().map_or(false, |o| { - o.get(&key).map_or(false, |v| json_eval_value_at_key(v, path, fun)) - }) - } - } - - fn json_contains_path(doc: &Value, path: &mut VecDeque) -> bool { - json_eval_value_at_key(doc, path, &|_| true) - } - #[test] // some tests for json path utils fn test_json_eval_value_at_key() { @@ -1082,4 +1119,72 @@ mod tests { .map(|v| *v == vec![1, 1, 1]) .unwrap()) } + + #[test] + fn update_code_works_with_runtime_genesis_config() { + let j = include_str!("../../../test-utils/runtime/res/default_genesis_config.json"); + let chain_spec: ChainSpec<()> = ChainSpec::builder( + substrate_test_runtime::wasm_binary_unwrap().into(), + Default::default(), + ) + .with_name("TestName") + .with_id("test_id") + .with_chain_type(ChainType::Local) + .with_genesis_config(from_str(j).unwrap()) + .build(); + + let mut chain_spec_json = from_str::(&chain_spec.as_json(false).unwrap()).unwrap(); + assert!(update_code_in_json_chain_spec(&mut chain_spec_json, &[0, 1, 2, 4, 5, 6])); + + assert!(json_eval_value_at_key( + &chain_spec_json, + &mut json_path!["genesis", "runtimeGenesis", "code"], + &|v| { *v == "0x000102040506" } + )); + } + + #[test] + fn update_code_works_for_raw() { + let j = include_str!("../../../test-utils/runtime/res/default_genesis_config.json"); + let chain_spec: ChainSpec<()> = ChainSpec::builder( + substrate_test_runtime::wasm_binary_unwrap().into(), + Default::default(), + ) + .with_name("TestName") + .with_id("test_id") + .with_chain_type(ChainType::Local) + .with_genesis_config(from_str(j).unwrap()) + .build(); + + let mut chain_spec_json = from_str::(&chain_spec.as_json(true).unwrap()).unwrap(); + assert!(update_code_in_json_chain_spec(&mut chain_spec_json, &[0, 1, 2, 4, 5, 6])); + + assert!(json_eval_value_at_key( + &chain_spec_json, + &mut json_path!["genesis", "raw", "top", "0x3a636f6465"], + &|v| { *v == "0x000102040506" } + )); + } + + #[test] + fn update_code_works_with_runtime_genesis_patch() { + let chain_spec: ChainSpec<()> = ChainSpec::builder( + substrate_test_runtime::wasm_binary_unwrap().into(), + Default::default(), + ) + .with_name("TestName") + .with_id("test_id") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(json!({})) + .build(); + + let mut chain_spec_json = from_str::(&chain_spec.as_json(false).unwrap()).unwrap(); + assert!(update_code_in_json_chain_spec(&mut chain_spec_json, &[0, 1, 2, 4, 5, 6])); + + assert!(json_eval_value_at_key( + &chain_spec_json, + &mut json_path!["genesis", "runtimeGenesis", "code"], + &|v| { *v == "0x000102040506" } + )); + } } diff --git a/substrate/client/chain-spec/src/lib.rs b/substrate/client/chain-spec/src/lib.rs index a26606072aee..6a922e7b40b2 100644 --- a/substrate/client/chain-spec/src/lib.rs +++ b/substrate/client/chain-spec/src/lib.rs @@ -135,7 +135,7 @@ //! //! //! -//! runtime +//! runtime / full config //! //! A JSON object that provides an explicit and comprehensive representation of the //! RuntimeGenesisConfig struct, which is generated by A JSON object that offers a partial representation of the //! RuntimeGenesisConfig provided by the runtime. It contains a patch, which is //! essentially a list of key-value pairs to customize in the default runtime's -//! RuntimeGenesisConfig. -//! +//! RuntimeGenesisConfig. //! This format explicitly provides the code of the runtime. -//! +//! //! //! //! raw //! //! A JSON object with two fields: top and children_default. //! Each field is a map of key => value pairs representing entries in a genesis storage -//! trie. -//! -//! The runtime code is stored in the state as one of the key-pair entry. +//! trie. The runtime code is one of such entries. //! //! //! @@ -176,7 +173,7 @@ //! the `RuntimeGenesisConfig` format changes due to software upgrade. //! //! JSON examples in the [following section](#json-chain-specification-example) illustrate the `raw` -//! and `runtimeGenesisConfigPatch` genesis fields. +//! `patch` and full genesis fields. //! //! # From Initial State to Raw Genesis. //! @@ -236,8 +233,13 @@ //! ```ignore #![doc = include_str!("../res/substrate_test_runtime_from_patch_raw.json")] //! ``` +//! The following example shows the plain full config version of chain spec: +//! ```ignore +#![doc = include_str!("../res/substrate_test_runtime_from_config.json")] +//! ``` //! The [`ChainSpec`] trait represents the API to access values defined in the JSON chain specification. //! +//! //! # Custom Chain Spec Extensions //! //! The basic chain spec type containing all required parameters is [`GenericChainSpec`]. It can be @@ -326,7 +328,10 @@ mod genesis_config_builder; mod json_patch; pub use self::{ - chain_spec::{ChainSpec as GenericChainSpec, ChainSpecBuilder, NoExtension}, + chain_spec::{ + update_code_in_json_chain_spec, ChainSpec as GenericChainSpec, ChainSpecBuilder, + NoExtension, + }, extension::{get_extension, get_extension_mut, Extension, Fork, Forks, GetExtension, Group}, genesis_block::{ construct_genesis_block, resolve_state_version_from_wasm, BuildGenesisBlock, From 60dae23b3b46e1bda2303fe6126ee774433e46c2 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 1 Nov 2023 20:39:58 +0100 Subject: [PATCH 71/98] clippy happy happy me --- substrate/client/chain-spec/src/chain_spec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index 43ff9748b0b6..a6fd5159c2ae 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -760,7 +760,7 @@ fn json_contains_path(doc: &json::Value, path: &mut VecDeque<&str>) -> bool { /// /// If update was successful `true` is returned, otherwise `false`. Chain spec JSON is modified in /// place. -pub fn update_code_in_json_chain_spec<'a>(chain_spec: &mut json::Value, code: &'a [u8]) -> bool { +pub fn update_code_in_json_chain_spec(chain_spec: &mut json::Value, code: &[u8]) -> bool { let mut path = json_path!["genesis", "runtimeGenesis", "code"]; let mut raw_path = json_path!["genesis", "raw", "top", "0x3a636f6465"]; From ffc779e1d245030c4a48eadf406516a887cc0287 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 1 Nov 2023 21:27:37 +0100 Subject: [PATCH 72/98] doc fix --- substrate/client/chain-spec/src/chain_spec.rs | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index a6fd5159c2ae..d3fc750782d0 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -51,10 +51,10 @@ enum GenesisBuildAction { enum GenesisSource { File(PathBuf), Binary(Cow<'static, [u8]>), + /// factory function + code #[deprecated( note = "Factory and G type parameter are planned to be removed in December 2023. Use `GenesisBuilderApi` instead." )] - /// factory function + code Factory(Arc G + Send + Sync>, Vec), Storage(Storage), /// build action + code @@ -155,7 +155,6 @@ impl BuildStorage for ChainSpec { RuntimeCaller::new(&code[..]) .get_storage_for_config(config)? .assimilate_storage(storage)?; - storage .top .insert(sp_core::storage::well_known_keys::CODE.to_vec(), code.clone()); @@ -167,7 +166,6 @@ impl BuildStorage for ChainSpec { RuntimeCaller::new(&code[..]) .get_storage_for_patch(patch)? .assimilate_storage(storage)?; - storage .top .insert(sp_core::storage::well_known_keys::CODE.to_vec(), code.clone()); @@ -211,19 +209,19 @@ impl From for RawGenesis { } } -/// Inner representation of RuntimeGenesis format +/// Inner representation of [`Genesis::RuntimeGenesis`] format #[derive(Serialize, Deserialize, Debug)] struct RuntimeGenesisInner { - /// runtime wasm code, expected to be hex-encoded + /// Runtime wasm code, expected to be hex-encoded in JSON. /// The code shall be capable of parsing `json_blob`. #[serde(default, with = "sp_core::bytes")] code: Vec, - /// patch or full config, this field will be flattened + /// The patch or full representation of runtime's `RuntimeGenesisConfig` struct. #[serde(flatten)] json_blob: RuntimeGenesisConfigJson, } -/// Represents two possible variants of the contained JSON blob for the RuntimeGenesis format. +/// Represents two possible variants of the contained JSON blob for the [`Genesis::RuntimeGenesis`] format. #[derive(Serialize, Deserialize, Debug)] #[serde(rename_all = "camelCase")] enum RuntimeGenesisConfigJson { @@ -236,13 +234,13 @@ enum RuntimeGenesisConfigJson { Patch(json::Value), } -/// Represents different formats of the GenesisConfig configuration within chain spec JSON blob. +/// Represents the different formats of the genesis state within chain spec JSON blob. #[derive(Serialize, Deserialize)] #[serde(rename_all = "camelCase")] #[serde(deny_unknown_fields)] enum Genesis { /// (Deprecated) Contains the JSON representation of G (the native type representing the - /// runtime GenesisConfig struct) (will be removed with `ChainSpec::from_genesis`) and the + /// runtime's `RuntimeGenesisConfig` struct) (will be removed with `ChainSpec::from_genesis`) and the /// runtime code. Runtime(G, Vec), /// The genesis storage as raw data. Typically raw key-value entries in state. @@ -594,7 +592,6 @@ impl ChainSpec { }), ) => { let mut storage = RuntimeCaller::new(&code[..]).get_storage_for_config(config)?; - storage.top.insert(sp_core::storage::well_known_keys::CODE.to_vec(), code); RawGenesis::from(storage) }, @@ -606,7 +603,6 @@ impl ChainSpec { }), ) => { let mut storage = RuntimeCaller::new(&code[..]).get_storage_for_patch(patch)?; - storage.top.insert(sp_core::storage::well_known_keys::CODE.to_vec(), code); RawGenesis::from(storage) }, @@ -723,7 +719,7 @@ where /// `path` will be modified. /// /// # Examples -/// ``` +/// ```ignore /// use serde_json::{from_str, json, Value}; /// let doc = json!({"a":{"b":{"c":"5"}}}); /// let mut path = ["a", "b", "c"].into(); From 8d29febf33737665641f57f9c8f8d23b6abd30d2 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 2 Nov 2023 08:15:47 +0100 Subject: [PATCH 73/98] zombienet image for testing --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 069068369aba..e628bcf43b85 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,7 +30,7 @@ variables: RUSTY_CACHIER_COMPRESSION_METHOD: zstd NEXTEST_FAILURE_OUTPUT: immediate-final NEXTEST_SUCCESS_OUTPUT: final - ZOMBIENET_IMAGE: "docker.io/paritytech/zombienet:v1.3.71" + ZOMBIENET_IMAGE: "docker.io/paritypr/zombienet:6064d9e5" DOCKER_IMAGES_VERSION: "${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}" default: From 14d8e04066abdef9bb596e7d03b05c9f0f692512 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 2 Nov 2023 08:46:34 +0100 Subject: [PATCH 74/98] zombienet version bumped for testing --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e628bcf43b85..8dbd95f89c10 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,7 +30,7 @@ variables: RUSTY_CACHIER_COMPRESSION_METHOD: zstd NEXTEST_FAILURE_OUTPUT: immediate-final NEXTEST_SUCCESS_OUTPUT: final - ZOMBIENET_IMAGE: "docker.io/paritypr/zombienet:6064d9e5" + ZOMBIENET_IMAGE: "docker.io/paritypr/zombienet:df998b63" DOCKER_IMAGES_VERSION: "${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}" default: From 54e6ba80959856628e6b6698c25771e55c73ee13 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 2 Nov 2023 10:41:51 +0100 Subject: [PATCH 75/98] zombienet: path to genesis config patch corrected --- .../zombienet_tests/functional/0002-parachains-disputes.toml | 2 +- .../functional/0004-parachains-garbage-candidate.toml | 2 +- .../functional/0005-parachains-disputes-past-session.toml | 2 +- polkadot/zombienet_tests/misc/0001-paritydb.toml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/polkadot/zombienet_tests/functional/0002-parachains-disputes.toml b/polkadot/zombienet_tests/functional/0002-parachains-disputes.toml index f51df45fa4be..aad195401165 100644 --- a/polkadot/zombienet_tests/functional/0002-parachains-disputes.toml +++ b/polkadot/zombienet_tests/functional/0002-parachains-disputes.toml @@ -1,7 +1,7 @@ [settings] timeout = 1000 -[relaychain.genesis.runtimeGenesisConfigPatch.configuration.config] +[relaychain.genesis.runtimeGenesis.patch.configuration.config] max_validators_per_core = 5 needed_approvals = 8 diff --git a/polkadot/zombienet_tests/functional/0004-parachains-garbage-candidate.toml b/polkadot/zombienet_tests/functional/0004-parachains-garbage-candidate.toml index 7b1234eabc00..49b5553a0c37 100644 --- a/polkadot/zombienet_tests/functional/0004-parachains-garbage-candidate.toml +++ b/polkadot/zombienet_tests/functional/0004-parachains-garbage-candidate.toml @@ -2,7 +2,7 @@ timeout = 1000 bootnode = true -[relaychain.genesis.runtimeGenesisConfigPatch.configuration.config] +[relaychain.genesis.runtimeGenesis.patch.configuration.config] max_validators_per_core = 1 needed_approvals = 2 diff --git a/polkadot/zombienet_tests/functional/0005-parachains-disputes-past-session.toml b/polkadot/zombienet_tests/functional/0005-parachains-disputes-past-session.toml index 6c22c1f01e25..e2fbec079b1a 100644 --- a/polkadot/zombienet_tests/functional/0005-parachains-disputes-past-session.toml +++ b/polkadot/zombienet_tests/functional/0005-parachains-disputes-past-session.toml @@ -2,7 +2,7 @@ timeout = 1000 bootnode = true -[relaychain.genesis.runtimeGenesisConfigPatch.configuration.config] +[relaychain.genesis.runtimeGenesis.patch.configuration.config] max_validators_per_core = 1 needed_approvals = 2 group_rotation_frequency = 2 diff --git a/polkadot/zombienet_tests/misc/0001-paritydb.toml b/polkadot/zombienet_tests/misc/0001-paritydb.toml index af039768b76f..a229a63f792c 100644 --- a/polkadot/zombienet_tests/misc/0001-paritydb.toml +++ b/polkadot/zombienet_tests/misc/0001-paritydb.toml @@ -2,7 +2,7 @@ timeout = 1000 bootnode = true -[relaychain.genesis.runtimeGenesisConfigPatch.configuration.config] +[relaychain.genesis.runtimeGenesis.patch.configuration.config] max_validators_per_core = 1 needed_approvals = 3 From 2e2c74965aaa15d9cdae66d8741d21fc52a1a368 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 2 Nov 2023 16:21:56 +0100 Subject: [PATCH 76/98] fixes --- cumulus/zombienet/tests/0002-pov_recovery.toml | 2 +- cumulus/zombienet/tests/0005-migrate_solo_to_para.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cumulus/zombienet/tests/0002-pov_recovery.toml b/cumulus/zombienet/tests/0002-pov_recovery.toml index 7c74a74a7502..34cacbc2a9ba 100644 --- a/cumulus/zombienet/tests/0002-pov_recovery.toml +++ b/cumulus/zombienet/tests/0002-pov_recovery.toml @@ -4,7 +4,7 @@ default_command = "polkadot" chain = "rococo-local" -[relaychain.genesis.runtime.runtime_genesis_config.configuration.config] +[relaychain.genesis.runtimeGenesis.patch.configuration.config] # set parameters such that collators only connect to 1 validator as a backing group max_validators_per_core = 1 group_rotation_frequency = 100 # 10 mins diff --git a/cumulus/zombienet/tests/0005-migrate_solo_to_para.toml b/cumulus/zombienet/tests/0005-migrate_solo_to_para.toml index f98c0e6f2592..180ed8bf7b99 100644 --- a/cumulus/zombienet/tests/0005-migrate_solo_to_para.toml +++ b/cumulus/zombienet/tests/0005-migrate_solo_to_para.toml @@ -32,7 +32,7 @@ cumulus_based = true add_to_genesis = false register_para = false # Set some random value in the genesis state to create a different genesis hash. -[parachains.genesis.runtime.runtime_genesis_config.sudo] +[parachains.genesis.runtimeGenesis.patch.sudo] key = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" # run the parachain that will be used to return the header of the solo chain. From c82e634d6f94dc130137bb1e3d073bfe159b5335 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 2 Nov 2023 16:49:28 +0100 Subject: [PATCH 77/98] fix reverted --- cumulus/zombienet/tests/0005-migrate_solo_to_para.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cumulus/zombienet/tests/0005-migrate_solo_to_para.toml b/cumulus/zombienet/tests/0005-migrate_solo_to_para.toml index 180ed8bf7b99..f98c0e6f2592 100644 --- a/cumulus/zombienet/tests/0005-migrate_solo_to_para.toml +++ b/cumulus/zombienet/tests/0005-migrate_solo_to_para.toml @@ -32,7 +32,7 @@ cumulus_based = true add_to_genesis = false register_para = false # Set some random value in the genesis state to create a different genesis hash. -[parachains.genesis.runtimeGenesis.patch.sudo] +[parachains.genesis.runtime.runtime_genesis_config.sudo] key = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" # run the parachain that will be used to return the header of the solo chain. From ac41e786cf97b174cd8bb16598c784ddcc02131b Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 2 Nov 2023 18:23:13 +0100 Subject: [PATCH 78/98] fixes --- Cargo.lock | 27 +++++++++++++++++++ .../src/chain_spec/bridge_hubs.rs | 11 ++++---- .../src/legacy_chain_spec/bridge_hubs.rs | 5 ++-- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 808a1976e079..b7af47ec03bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -964,6 +964,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-aura", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", @@ -6736,7 +6737,9 @@ dependencies = [ "polkadot-service", "rococo-runtime", "rococo-runtime-constants", + "sc-chain-spec", "sc-consensus-grandpa", + "serde_json", "sp-authority-discovery", "sp-consensus-babe", "sp-consensus-beefy", @@ -7157,6 +7160,7 @@ dependencies = [ "parity-scale-codec", "primitive-types", "scale-info", + "serde_json", "sp-api", "sp-authority-discovery", "sp-block-builder", @@ -8197,6 +8201,7 @@ dependencies = [ "sc-telemetry", "sc-transaction-pool", "sc-transaction-pool-api", + "serde_json", "sp-api", "sp-block-builder", "sp-blockchain", @@ -8213,6 +8218,7 @@ name = "minimal-runtime" version = "0.1.0" dependencies = [ "frame", + "frame-support", "pallet-balances", "pallet-sudo", "pallet-timestamp", @@ -8220,6 +8226,7 @@ dependencies = [ "pallet-transaction-payment-rpc-runtime-api", "parity-scale-codec", "scale-info", + "sp-genesis-builder", "substrate-wasm-builder", ] @@ -8677,6 +8684,7 @@ dependencies = [ "sc-telemetry", "sc-transaction-pool", "sc-transaction-pool-api", + "serde_json", "sp-api", "sp-block-builder", "sp-blockchain", @@ -8728,6 +8736,7 @@ dependencies = [ "pallet-transaction-payment-rpc-runtime-api", "parity-scale-codec", "scale-info", + "serde_json", "sp-api", "sp-block-builder", "sp-consensus-aura", @@ -11166,6 +11175,7 @@ dependencies = [ "sc-transaction-pool", "sc-transaction-pool-api", "serde", + "serde_json", "sp-api", "sp-block-builder", "sp-blockchain", @@ -12736,6 +12746,7 @@ dependencies = [ "sp-runtime", "sp-session", "sp-timestamp", + "sp-tracing 10.0.0", "sp-transaction-pool", "staging-xcm", "substrate-build-script-utils", @@ -14777,7 +14788,11 @@ dependencies = [ name = "sc-chain-spec" version = "4.0.0-dev" dependencies = [ + "array-bytes 6.1.0", + "docify", + "log", "memmap2", + "parity-scale-codec", "sc-chain-spec-derive", "sc-client-api", "sc-executor", @@ -14785,10 +14800,16 @@ dependencies = [ "sc-telemetry", "serde", "serde_json", + "sp-application-crypto", "sp-blockchain", + "sp-consensus-babe", "sp-core", + "sp-genesis-builder", + "sp-io", + "sp-keyring", "sp-runtime", "sp-state-machine", + "substrate-test-runtime", ] [[package]] @@ -17980,11 +18001,15 @@ version = "2.0.0" dependencies = [ "ansi_term", "clap 4.4.6", + "kitchensink-runtime", + "log", "rand 0.8.5", "sc-chain-spec", "sc-keystore", + "serde_json", "sp-core", "sp-keystore", + "sp-tracing 10.0.0", "staging-node-cli", ] @@ -18104,6 +18129,7 @@ dependencies = [ "parity-scale-codec", "sc-executor", "scale-info", + "serde_json", "sp-application-crypto", "sp-consensus-babe", "sp-core", @@ -18333,6 +18359,7 @@ name = "substrate" version = "1.0.0" dependencies = [ "frame-support", + "sc-chain-spec", "sc-cli", "sc-consensus-aura", "sc-consensus-babe", diff --git a/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs b/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs index 02b108899298..848f85d477e0 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs @@ -504,10 +504,9 @@ pub mod westend { properties.insert("tokenSymbol".into(), "WND".into()); properties.insert("tokenDecimals".into(), 12.into()); - BridgeHubChainSpec::builder( bridge_hub_westend_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") + .expect("WASM binary was not build, please build it!"), Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, ) .with_name(chain_name) @@ -555,14 +554,14 @@ pub mod westend { bridges_pallet_owner: Option, ) -> serde_json::Value { serde_json::json!({ - "balances": bridge_hub_westend_runtime::BalancesConfig { - "balances": endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), + "balances": { + "balances": endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::>(), }, "parachainInfo": { "parachainId": id, }, "collatorSelection": { - "invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), + "invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::>(), "candidacy_bond": BRIDGE_HUB_WESTEND_ED * 16, }, "session": { @@ -575,7 +574,7 @@ pub mod westend { bridge_hub_westend_runtime::SessionKeys { aura }, // session keys ) }) - .collect(), + .collect::>(), }, "polkadotXcm": { "safeXcmVersion": Some(SAFE_XCM_VERSION), diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/bridge_hubs.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/bridge_hubs.rs index e6aee22ee069..05cec27c882a 100644 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/bridge_hubs.rs +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/bridge_hubs.rs @@ -493,11 +493,10 @@ pub mod kusama { } } - /// Sub-module for Westend setup. pub mod westend { use super::{get_account_id_from_seed, get_collator_keys_from_seed, sr25519, ParaId}; - use crate::chain_spec::{Extensions, SAFE_XCM_VERSION}; + use crate::legacy_chain_spec::{Extensions, SAFE_XCM_VERSION}; use parachains_common::{AccountId, AuraId}; use sc_chain_spec::ChainType; @@ -572,7 +571,7 @@ pub mod westend { Some(properties), Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, bridge_hub_westend_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") + .expect("WASM binary was not build, please build it!"), ) } From f68759104fb8ac783153e716a66488fbd64b9b60 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Thu, 2 Nov 2023 17:31:07 +0000 Subject: [PATCH 79/98] ".git/.scripts/commands/fmt/fmt.sh" --- substrate/client/chain-spec/src/chain_spec.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index d3fc750782d0..7792f4257af7 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -221,7 +221,8 @@ struct RuntimeGenesisInner { json_blob: RuntimeGenesisConfigJson, } -/// Represents two possible variants of the contained JSON blob for the [`Genesis::RuntimeGenesis`] format. +/// Represents two possible variants of the contained JSON blob for the +/// [`Genesis::RuntimeGenesis`] format. #[derive(Serialize, Deserialize, Debug)] #[serde(rename_all = "camelCase")] enum RuntimeGenesisConfigJson { @@ -240,8 +241,8 @@ enum RuntimeGenesisConfigJson { #[serde(deny_unknown_fields)] enum Genesis { /// (Deprecated) Contains the JSON representation of G (the native type representing the - /// runtime's `RuntimeGenesisConfig` struct) (will be removed with `ChainSpec::from_genesis`) and the - /// runtime code. + /// runtime's `RuntimeGenesisConfig` struct) (will be removed with `ChainSpec::from_genesis`) + /// and the runtime code. Runtime(G, Vec), /// The genesis storage as raw data. Typically raw key-value entries in state. Raw(RawGenesis), From e6b98665f83a1b35c5b0ddaef163beb4f144d835 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 2 Nov 2023 18:41:55 +0100 Subject: [PATCH 80/98] test + fixes --- .../polkadot-parachain/src/chain_spec/bridge_hubs.rs | 2 +- .../src/legacy_chain_spec/json_vs_legacy_tests.rs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs b/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs index 848f85d477e0..71fb9e5b1404 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/bridge_hubs.rs @@ -562,7 +562,7 @@ pub mod westend { }, "collatorSelection": { "invulnerables": invulnerables.iter().cloned().map(|(acc, _)| acc).collect::>(), - "candidacy_bond": BRIDGE_HUB_WESTEND_ED * 16, + "candidacyBond": BRIDGE_HUB_WESTEND_ED * 16, }, "session": { "keys": invulnerables diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/json_vs_legacy_tests.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/json_vs_legacy_tests.rs index 7f8f7a30519f..d76b6a28979e 100644 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/json_vs_legacy_tests.rs +++ b/cumulus/polkadot-parachain/src/legacy_chain_spec/json_vs_legacy_tests.rs @@ -93,3 +93,14 @@ test!( test31, bridge_hubs::polkadot::local_config("bridge-hub-polkadot-local", "Test", "test", 667.into()) ); + +test!( + test32, + bridge_hubs::westend::local_config( + "bridge-hub-westend-local", + "Test", + "test", + 664.into(), + Some("Alice".to_string()) + ) +); From 98a53d0a2d02f1d459b01c13720a2bc03b65ad2c Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 2 Nov 2023 23:13:11 +0100 Subject: [PATCH 81/98] fix (me wants green ci) --- substrate/client/chain-spec/src/chain_spec.rs | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index 7792f4257af7..388bd2b3691a 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -107,7 +107,8 @@ impl GenesisSource { Ok(genesis.genesis) }, #[allow(deprecated)] - Self::Factory(f, code) => Ok(Genesis::Runtime(f(), code.clone())), + Self::Factory(f, code) => + Ok(Genesis::Runtime(RuntimeInnerWrapper { runtime: f(), code: code.clone() })), Self::Storage(storage) => Ok(Genesis::Raw(RawGenesis::from(storage.clone()))), Self::GenesisBuilderApi(GenesisBuildAction::Full(config), code) => Ok(Genesis::RuntimeGenesis(RuntimeGenesisInner { @@ -127,8 +128,8 @@ impl BuildStorage for ChainSpec { fn assimilate_storage(&self, storage: &mut Storage) -> Result<(), String> { match self.genesis.resolve()? { #[allow(deprecated)] - Genesis::Runtime(gc, code) => { - gc.assimilate_storage(storage)?; + Genesis::Runtime(RuntimeInnerWrapper { runtime: runtime_genesis_config, code }) => { + runtime_genesis_config.assimilate_storage(storage)?; storage.top.insert(sp_core::storage::well_known_keys::CODE.to_vec(), code); }, Genesis::Raw(RawGenesis { top: map, children_default: children_map }) => { @@ -235,6 +236,15 @@ enum RuntimeGenesisConfigJson { Patch(json::Value), } +/// Inner variant wrapper for deprecated runtime. +#[derive(Serialize, Deserialize, Debug)] +struct RuntimeInnerWrapper { + #[serde(flatten)] + runtime: G, + #[serde(skip)] + code: Vec, +} + /// Represents the different formats of the genesis state within chain spec JSON blob. #[derive(Serialize, Deserialize)] #[serde(rename_all = "camelCase")] @@ -243,7 +253,7 @@ enum Genesis { /// (Deprecated) Contains the JSON representation of G (the native type representing the /// runtime's `RuntimeGenesisConfig` struct) (will be removed with `ChainSpec::from_genesis`) /// and the runtime code. - Runtime(G, Vec), + Runtime(RuntimeInnerWrapper), /// The genesis storage as raw data. Typically raw key-value entries in state. Raw(RawGenesis), /// State root hash of the genesis storage. @@ -609,7 +619,7 @@ impl ChainSpec { }, #[allow(deprecated)] - (true, Genesis::Runtime(g, code)) => { + (true, Genesis::Runtime(RuntimeInnerWrapper { runtime: g, code })) => { let mut storage = g.build_storage()?; storage.top.insert(sp_core::storage::well_known_keys::CODE.to_vec(), code); RawGenesis::from(storage) @@ -627,12 +637,6 @@ impl ChainSpec { } /// Dump the chain specification to JSON string. - /// - /// During conversion to `raw` format, the `ChainSpec::code` field will be removed and placed - /// into `RawGenesis` as `genesis::top::raw::0x3a636f6465` (which is - /// [`sp_core::storage::well_known_keys::CODE`]). If the spec is already in `raw` format, and - /// contains `genesis::top::raw::0x3a636f6465` field it will be updated with content of `code` - /// field (if present). pub fn as_json(&self, raw: bool) -> Result { let container = self.json_container(raw)?; json::to_string_pretty(&container).map_err(|e| format!("Error generating spec json: {}", e)) From 8dc196eb661a2a9c8952ce3b4b4221471af2d6bc Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 3 Nov 2023 10:16:48 +0100 Subject: [PATCH 82/98] fixes --- .../bin/utils/chain-spec-builder/bin/main.rs | 10 ++-- substrate/client/chain-spec/src/chain_spec.rs | 49 +++++++++++++++---- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/substrate/bin/utils/chain-spec-builder/bin/main.rs b/substrate/bin/utils/chain-spec-builder/bin/main.rs index 33a7d336d009..83892afd6ace 100644 --- a/substrate/bin/utils/chain-spec-builder/bin/main.rs +++ b/substrate/bin/utils/chain-spec-builder/bin/main.rs @@ -102,7 +102,7 @@ fn main() -> Result<(), String> { let chain_spec = GenericChainSpec::<()>::from_json_file(input_chain_spec.clone())?; let mut chain_spec_json = - serde_json::from_str::(&chain_spec.as_json(false)?) + serde_json::from_str::(&chain_spec.as_json(convert_to_raw)?) .map_err(|e| format!("Conversion to json failed: {e}"))?; if let Some(path) = runtime_wasm_path { update_code_in_json_chain_spec( @@ -112,13 +112,14 @@ fn main() -> Result<(), String> { ); } - chain_spec.as_json(convert_to_raw) + serde_json::to_string_pretty(&chain_spec_json) + .map_err(|e| format!("to pretty failed: {e}")) }, ChainSpecBuilderCmd::Verify(VerifyCmd { ref input_chain_spec, ref runtime_wasm_path }) => { write_chain_spec = false; let chain_spec = GenericChainSpec::<()>::from_json_file(input_chain_spec.clone())?; let mut chain_spec_json = - serde_json::from_str::(&chain_spec.as_json(false)?) + serde_json::from_str::(&chain_spec.as_json(true)?) .map_err(|e| format!("Conversion to json failed: {e}"))?; if let Some(path) = runtime_wasm_path { update_code_in_json_chain_spec( @@ -127,7 +128,8 @@ fn main() -> Result<(), String> { .map_err(|e| format!("Wasm blob file could not be read: {e}"))?[..], ); }; - chain_spec.as_json(true) + serde_json::to_string_pretty(&chain_spec_json) + .map_err(|e| format!("to pretty failed: {e}")) }, }?; diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index 388bd2b3691a..f87fc66aad20 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -107,8 +107,10 @@ impl GenesisSource { Ok(genesis.genesis) }, #[allow(deprecated)] - Self::Factory(f, code) => - Ok(Genesis::Runtime(RuntimeInnerWrapper { runtime: f(), code: code.clone() })), + Self::Factory(f, code) => Ok(Genesis::RuntimeAndCode(RuntimeInnerWrapper { + runtime: f(), + code: code.clone(), + })), Self::Storage(storage) => Ok(Genesis::Raw(RawGenesis::from(storage.clone()))), Self::GenesisBuilderApi(GenesisBuildAction::Full(config), code) => Ok(Genesis::RuntimeGenesis(RuntimeGenesisInner { @@ -128,7 +130,14 @@ impl BuildStorage for ChainSpec { fn assimilate_storage(&self, storage: &mut Storage) -> Result<(), String> { match self.genesis.resolve()? { #[allow(deprecated)] - Genesis::Runtime(RuntimeInnerWrapper { runtime: runtime_genesis_config, code }) => { + Genesis::Runtime(runtime_genesis_config) => { + runtime_genesis_config.assimilate_storage(storage)?; + }, + #[allow(deprecated)] + Genesis::RuntimeAndCode(RuntimeInnerWrapper { + runtime: runtime_genesis_config, + code, + }) => { runtime_genesis_config.assimilate_storage(storage)?; storage.top.insert(sp_core::storage::well_known_keys::CODE.to_vec(), code); }, @@ -239,9 +248,8 @@ enum RuntimeGenesisConfigJson { /// Inner variant wrapper for deprecated runtime. #[derive(Serialize, Deserialize, Debug)] struct RuntimeInnerWrapper { - #[serde(flatten)] runtime: G, - #[serde(skip)] + #[serde(with = "sp_core::bytes")] code: Vec, } @@ -249,11 +257,20 @@ struct RuntimeInnerWrapper { #[derive(Serialize, Deserialize)] #[serde(rename_all = "camelCase")] #[serde(deny_unknown_fields)] +#[allow(deprecated)] enum Genesis { + /// (Deprecated) Contains the JSON representation of G (the native type representing the + /// runtime's `RuntimeGenesisConfig` struct) (will be removed with `ChainSpec::from_genesis`) + /// without the runtime code. + Runtime(G), /// (Deprecated) Contains the JSON representation of G (the native type representing the /// runtime's `RuntimeGenesisConfig` struct) (will be removed with `ChainSpec::from_genesis`) /// and the runtime code. - Runtime(RuntimeInnerWrapper), + // #[serde(skip_deserializing, rename(serialize = "runtime"))] + #[deprecated( + note = "`RuntimeAndCode` is planned to be removed in December 2023. Use `RuntimeGenesis` instead." + )] + RuntimeAndCode(RuntimeInnerWrapper), /// The genesis storage as raw data. Typically raw key-value entries in state. Raw(RawGenesis), /// State root hash of the genesis storage. @@ -268,7 +285,8 @@ enum Genesis { /// fields. #[derive(Serialize, Deserialize, Clone, Debug)] #[serde(rename_all = "camelCase")] -#[serde(deny_unknown_fields)] +// we cannot #[serde(deny_unknown_fields)]. Otherwise chain-spec-builder will fail on any +// non-standard spec struct ClientSpec { name: String, id: String, @@ -585,7 +603,8 @@ impl ChainSpec { #[serde(flatten)] client_spec: ClientSpec, @@ -619,11 +638,16 @@ impl ChainSpec { }, #[allow(deprecated)] - (true, Genesis::Runtime(RuntimeInnerWrapper { runtime: g, code })) => { + (true, Genesis::RuntimeAndCode(RuntimeInnerWrapper { runtime: g, code })) => { let mut storage = g.build_storage()?; storage.top.insert(sp_core::storage::well_known_keys::CODE.to_vec(), code); RawGenesis::from(storage) }, + #[allow(deprecated)] + (true, Genesis::Runtime(g)) => { + let storage = g.build_storage()?; + RawGenesis::from(storage) + }, (true, Genesis::Raw(raw)) => raw, (_, genesis) => @@ -763,9 +787,12 @@ fn json_contains_path(doc: &json::Value, path: &mut VecDeque<&str>) -> bool { /// place. pub fn update_code_in_json_chain_spec(chain_spec: &mut json::Value, code: &[u8]) -> bool { let mut path = json_path!["genesis", "runtimeGenesis", "code"]; - let mut raw_path = json_path!["genesis", "raw", "top", "0x3a636f6465"]; + let mut raw_path = json_path!["genesis", "raw", "top"]; + + println!("xxx"); if json_contains_path(&chain_spec, &mut path) { + println!("xxx1"); #[derive(Serialize)] struct Container<'a> { #[serde(with = "sp_core::bytes")] @@ -775,12 +802,14 @@ pub fn update_code_in_json_chain_spec(chain_spec: &mut json::Value, code: &[u8]) crate::json_patch::merge(chain_spec, code_patch); true } else if json_contains_path(&chain_spec, &mut raw_path) { + println!("xxx2"); #[derive(Serialize)] struct Container<'a> { #[serde(with = "sp_core::bytes", rename = "0x3a636f6465")] code: &'a [u8], } let code_patch = json::json!({"genesis":{"raw":{"top": Container { code }}}}); + println!("xxx2 {:#?}", code_patch); crate::json_patch::merge(chain_spec, code_patch); true } else { From ed7b137de08bb63a767f3faeb97ed233908fd974 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 3 Nov 2023 10:23:16 +0100 Subject: [PATCH 83/98] fix --- substrate/client/chain-spec/src/chain_spec.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index f87fc66aad20..dcce8facc125 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -266,10 +266,9 @@ enum Genesis { /// (Deprecated) Contains the JSON representation of G (the native type representing the /// runtime's `RuntimeGenesisConfig` struct) (will be removed with `ChainSpec::from_genesis`) /// and the runtime code. - // #[serde(skip_deserializing, rename(serialize = "runtime"))] - #[deprecated( - note = "`RuntimeAndCode` is planned to be removed in December 2023. Use `RuntimeGenesis` instead." - )] + // #[deprecated( + // note = "`RuntimeAndCode` is planned to be removed in December 2023. Use `RuntimeGenesis` + // instead." )] RuntimeAndCode(RuntimeInnerWrapper), /// The genesis storage as raw data. Typically raw key-value entries in state. Raw(RawGenesis), From 30ffe7c65a4309ff1cc46e670e97515784563d21 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 3 Nov 2023 14:14:19 +0100 Subject: [PATCH 84/98] cumulus-test-service: GenesisExt removed --- cumulus/test/client/src/lib.rs | 3 ++- cumulus/test/runtime/src/lib.rs | 10 +++---- cumulus/test/runtime/src/test_pallet.rs | 28 +++++++++++++++++++ cumulus/test/service/src/chain_spec.rs | 36 +++++-------------------- 4 files changed, 42 insertions(+), 35 deletions(-) diff --git a/cumulus/test/client/src/lib.rs b/cumulus/test/client/src/lib.rs index 7b941b98e50a..8497437932ca 100644 --- a/cumulus/test/client/src/lib.rs +++ b/cumulus/test/client/src/lib.rs @@ -90,6 +90,7 @@ impl substrate_test_client::GenesisInit for GenesisParameters { cumulus_test_service::testnet_genesis( cumulus_test_service::get_account_id_from_seed::("Alice"), self.endowed_accounts.clone(), + None, ) .build_storage() .unwrap() @@ -136,7 +137,7 @@ impl DefaultTestClientBuilderExt for TestClientBuilder { } fn genesis_config() -> RuntimeGenesisConfig { - cumulus_test_service::testnet_genesis_with_default_endowed(Default::default()) + cumulus_test_service::testnet_genesis_with_default_endowed(Default::default(), None) } /// Create an unsigned extrinsic from a runtime call. diff --git a/cumulus/test/runtime/src/lib.rs b/cumulus/test/runtime/src/lib.rs index 85a1caa0ce35..381cc64cef82 100644 --- a/cumulus/test/runtime/src/lib.rs +++ b/cumulus/test/runtime/src/lib.rs @@ -76,10 +76,6 @@ impl_opaque_keys! { pub struct SessionKeys {} } -/// Some key that we set in genesis and only read in [`TestOnRuntimeUpgrade`] to ensure that -/// [`OnRuntimeUpgrade`] works as expected. -pub const TEST_RUNTIME_UPGRADE_KEY: &[u8] = b"+test_runtime_upgrade_key+"; - /// The para-id used in this runtime. pub const PARACHAIN_ID: u32 = 100; @@ -293,6 +289,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { } parameter_types! { + // will be set by test_pallet during genesis init pub storage ParachainId: cumulus_primitives_core::ParaId = PARACHAIN_ID.into(); } @@ -367,7 +364,10 @@ pub struct TestOnRuntimeUpgrade; impl OnRuntimeUpgrade for TestOnRuntimeUpgrade { fn on_runtime_upgrade() -> frame_support::weights::Weight { - assert_eq!(sp_io::storage::get(TEST_RUNTIME_UPGRADE_KEY), Some(vec![1, 2, 3, 4].into())); + assert_eq!( + sp_io::storage::get(test_pallet::TEST_RUNTIME_UPGRADE_KEY), + Some(vec![1, 2, 3, 4].into()) + ); Weight::from_parts(1, 0) } } diff --git a/cumulus/test/runtime/src/test_pallet.rs b/cumulus/test/runtime/src/test_pallet.rs index 0af23797dad6..e179d591030a 100644 --- a/cumulus/test/runtime/src/test_pallet.rs +++ b/cumulus/test/runtime/src/test_pallet.rs @@ -17,8 +17,15 @@ /// A special pallet that exposes dispatchables that are only useful for testing. pub use pallet::*; +/// Some key that we set in genesis and only read in [`TestOnRuntimeUpgrade`] to ensure that +/// [`OnRuntimeUpgrade`] works as expected. +pub const TEST_RUNTIME_UPGRADE_KEY: &[u8] = b"+test_runtime_upgrade_key+"; +/// Allows to set `runtime::ParachainId` in genesis: +pub const PARACHAIN_ID_RUNTIME_KEY: &[u8] = b":ParachainId:"; + #[frame_support::pallet(dev_mode)] pub mod pallet { + use crate::test_pallet::{PARACHAIN_ID_RUNTIME_KEY, TEST_RUNTIME_UPGRADE_KEY}; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; @@ -45,4 +52,25 @@ pub mod pallet { Ok(()) } } + + #[derive(frame_support::DefaultNoBound)] + #[pallet::genesis_config] + pub struct GenesisConfig { + pub self_para_id: Option, + #[serde(skip)] + pub _config: sp_std::marker::PhantomData, + } + + #[pallet::genesis_build] + impl BuildGenesisConfig for GenesisConfig { + fn build(&self) { + sp_io::storage::set(TEST_RUNTIME_UPGRADE_KEY, &[1, 2, 3, 4].encode()); + self.self_para_id.map(|para_id| { + sp_io::storage::set( + &sp_io::hashing::twox_128(&PARACHAIN_ID_RUNTIME_KEY), + ¶_id.encode(), + ) + }); + } + } } diff --git a/cumulus/test/service/src/chain_spec.rs b/cumulus/test/service/src/chain_spec.rs index 257d4e9a7e2a..8ffa8b0ff7eb 100644 --- a/cumulus/test/service/src/chain_spec.rs +++ b/cumulus/test/service/src/chain_spec.rs @@ -17,7 +17,7 @@ #![allow(missing_docs)] use cumulus_primitives_core::ParaId; -use cumulus_test_runtime::{AccountId, Signature}; +use cumulus_test_runtime::{AccountId, RuntimeGenesisConfig, Signature}; use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup}; use sc_service::ChainType; use serde::{Deserialize, Serialize}; @@ -25,27 +25,7 @@ use sp_core::{sr25519, Pair, Public}; use sp_runtime::traits::{IdentifyAccount, Verify}; /// Specialized `ChainSpec` for the normal parachain runtime. -pub type ChainSpec = sc_service::GenericChainSpec; - -/// Extension for the genesis config to add custom keys easily. -#[derive(serde::Serialize, serde::Deserialize)] -pub struct GenesisExt { - /// The runtime genesis config. - runtime_genesis_config: cumulus_test_runtime::RuntimeGenesisConfig, - /// The parachain id. - para_id: ParaId, -} - -impl sp_runtime::BuildStorage for GenesisExt { - fn assimilate_storage(&self, storage: &mut sp_core::storage::Storage) -> Result<(), String> { - sp_state_machine::BasicExternalities::execute_with_storage(storage, || { - sp_io::storage::set(cumulus_test_runtime::TEST_RUNTIME_UPGRADE_KEY, &[1, 2, 3, 4]); - cumulus_test_runtime::ParachainId::set(&self.para_id); - }); - - self.runtime_genesis_config.assimilate_storage(storage) - } -} +pub type ChainSpec = sc_service::GenericChainSpec; /// Helper function to generate a crypto pair from seed pub fn get_from_seed(seed: &str) -> ::Public { @@ -91,12 +71,7 @@ pub fn get_chain_spec_with_extra_endowed( "Local Testnet", "local_testnet", ChainType::Local, - move || GenesisExt { - runtime_genesis_config: testnet_genesis_with_default_endowed( - extra_endowed_accounts.clone(), - ), - para_id: id, - }, + move || testnet_genesis_with_default_endowed(extra_endowed_accounts.clone(), Some(id)), Vec::new(), None, None, @@ -115,6 +90,7 @@ pub fn get_chain_spec(id: ParaId) -> ChainSpec { /// Local testnet genesis for testing. pub fn testnet_genesis_with_default_endowed( mut extra_endowed_accounts: Vec, + self_para_id: Option, ) -> cumulus_test_runtime::RuntimeGenesisConfig { let mut endowed = vec![ get_account_id_from_seed::("Alice"), @@ -132,13 +108,14 @@ pub fn testnet_genesis_with_default_endowed( ]; endowed.append(&mut extra_endowed_accounts); - testnet_genesis(get_account_id_from_seed::("Alice"), endowed) + testnet_genesis(get_account_id_from_seed::("Alice"), endowed, self_para_id) } /// Creates a local testnet genesis with endowed accounts. pub fn testnet_genesis( root_key: AccountId, endowed_accounts: Vec, + self_para_id: Option, ) -> cumulus_test_runtime::RuntimeGenesisConfig { cumulus_test_runtime::RuntimeGenesisConfig { system: cumulus_test_runtime::SystemConfig::default(), @@ -149,5 +126,6 @@ pub fn testnet_genesis( }, sudo: cumulus_test_runtime::SudoConfig { key: Some(root_key) }, transaction_payment: Default::default(), + test_pallet: cumulus_test_runtime::TestPalletConfig { self_para_id, ..Default::default() }, } } From 253aabe591c820169dd0fee5ec86067dd33e5479 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 3 Nov 2023 15:16:05 +0100 Subject: [PATCH 85/98] cumulus-test: chainspec --- Cargo.lock | 1 + cumulus/test/service/Cargo.toml | 1 + cumulus/test/service/src/chain_spec.rs | 40 ++++++++----------- .../tests/0005-migrate_solo_to_para.toml | 2 +- substrate/client/chain-spec/src/chain_spec.rs | 9 ----- 5 files changed, 20 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b7af47ec03bf..e376644cdd8d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4287,6 +4287,7 @@ dependencies = [ "sc-transaction-pool", "sc-transaction-pool-api", "serde", + "serde_json", "sp-api", "sp-arithmetic", "sp-authority-discovery", diff --git a/cumulus/test/service/Cargo.toml b/cumulus/test/service/Cargo.toml index 14e45a4c7e67..5d73ba83d523 100644 --- a/cumulus/test/service/Cargo.toml +++ b/cumulus/test/service/Cargo.toml @@ -17,6 +17,7 @@ criterion = { version = "0.5.1", features = [ "async_tokio" ] } jsonrpsee = { version = "0.16.2", features = ["server"] } rand = "0.8.5" serde = { version = "1.0.188", features = ["derive"] } +serde_json = "1.0.107" tokio = { version = "1.32.0", features = ["macros"] } tracing = "0.1.37" url = "2.4.0" diff --git a/cumulus/test/service/src/chain_spec.rs b/cumulus/test/service/src/chain_spec.rs index 8ffa8b0ff7eb..574e138724db 100644 --- a/cumulus/test/service/src/chain_spec.rs +++ b/cumulus/test/service/src/chain_spec.rs @@ -66,20 +66,18 @@ pub fn get_chain_spec_with_extra_endowed( id: ParaId, extra_endowed_accounts: Vec, ) -> ChainSpec { - #[allow(deprecated)] - ChainSpec::from_genesis( - "Local Testnet", - "local_testnet", - ChainType::Local, - move || testnet_genesis_with_default_endowed(extra_endowed_accounts.clone(), Some(id)), - Vec::new(), - None, - None, - None, - None, - Extensions { para_id: id.into() }, + ChainSpec::builder( cumulus_test_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), + Extensions { para_id: id.into() }, ) + .with_name("Local Testnet") + .with_id("local_testnet") + .with_chain_type(ChainType::Local) + .with_genesis_config_patch(testnet_genesis_with_default_endowed( + extra_endowed_accounts.clone(), + Some(id), + )) + .build() } /// Get the chain spec for a specific parachain ID. @@ -91,7 +89,7 @@ pub fn get_chain_spec(id: ParaId) -> ChainSpec { pub fn testnet_genesis_with_default_endowed( mut extra_endowed_accounts: Vec, self_para_id: Option, -) -> cumulus_test_runtime::RuntimeGenesisConfig { +) -> serde_json::Value { let mut endowed = vec![ get_account_id_from_seed::("Alice"), get_account_id_from_seed::("Bob"), @@ -116,16 +114,12 @@ pub fn testnet_genesis( root_key: AccountId, endowed_accounts: Vec, self_para_id: Option, -) -> cumulus_test_runtime::RuntimeGenesisConfig { - cumulus_test_runtime::RuntimeGenesisConfig { - system: cumulus_test_runtime::SystemConfig::default(), - glutton: Default::default(), - parachain_system: Default::default(), - balances: cumulus_test_runtime::BalancesConfig { +) -> serde_json::Value { + serde_json::json!({ + "balances": cumulus_test_runtime::BalancesConfig { balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), }, - sudo: cumulus_test_runtime::SudoConfig { key: Some(root_key) }, - transaction_payment: Default::default(), - test_pallet: cumulus_test_runtime::TestPalletConfig { self_para_id, ..Default::default() }, - } + "sudo": cumulus_test_runtime::SudoConfig { key: Some(root_key) }, + "testPallet": cumulus_test_runtime::TestPalletConfig { self_para_id, ..Default::default() } + }) } diff --git a/cumulus/zombienet/tests/0005-migrate_solo_to_para.toml b/cumulus/zombienet/tests/0005-migrate_solo_to_para.toml index f98c0e6f2592..180ed8bf7b99 100644 --- a/cumulus/zombienet/tests/0005-migrate_solo_to_para.toml +++ b/cumulus/zombienet/tests/0005-migrate_solo_to_para.toml @@ -32,7 +32,7 @@ cumulus_based = true add_to_genesis = false register_para = false # Set some random value in the genesis state to create a different genesis hash. -[parachains.genesis.runtime.runtime_genesis_config.sudo] +[parachains.genesis.runtimeGenesis.patch.sudo] key = "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" # run the parachain that will be used to return the header of the solo chain. diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index dcce8facc125..c7c83f341723 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -1125,15 +1125,6 @@ mod tests { assert!(!json_contains_path(&j, &mut json_path!["code"])); } - #[test] - #[should_panic(expected = "unknown field `code`")] - fn check_code_in_assimilated_storage_for_raw_with_encoded() { - let _ = ChainSpec::<()>::from_json_bytes(Cow::Owned( - include_bytes!("../res/raw_with_code.json").to_vec(), - )) - .unwrap(); - } - #[test] fn check_code_in_assimilated_storage_for_raw_without_code() { let spec = ChainSpec::<()>::from_json_bytes(Cow::Owned( From af239cb29be8a95454114f783866e61f797b928d Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 3 Nov 2023 15:44:57 +0100 Subject: [PATCH 86/98] some fixes --- cumulus/test/client/src/lib.rs | 36 +++++++------------------- cumulus/test/service/src/chain_spec.rs | 8 +++--- cumulus/test/service/src/genesis.rs | 2 +- cumulus/test/service/src/lib.rs | 2 +- 4 files changed, 15 insertions(+), 33 deletions(-) diff --git a/cumulus/test/client/src/lib.rs b/cumulus/test/client/src/lib.rs index 8497437932ca..a3c79158f492 100644 --- a/cumulus/test/client/src/lib.rs +++ b/cumulus/test/client/src/lib.rs @@ -19,13 +19,13 @@ mod block_builder; use codec::{Decode, Encode}; use runtime::{ - Balance, Block, BlockHashCount, Runtime, RuntimeCall, RuntimeGenesisConfig, Signature, - SignedExtra, SignedPayload, UncheckedExtrinsic, VERSION, + Balance, Block, BlockHashCount, Runtime, RuntimeCall, Signature, SignedExtra, SignedPayload, + UncheckedExtrinsic, VERSION, }; use sc_executor::HeapAllocStrategy; use sc_executor_common::runtime_blob::RuntimeBlob; use sp_blockchain::HeaderBackend; -use sp_core::{sr25519, Pair}; +use sp_core::Pair; use sp_io::TestExternalities; use sp_runtime::{generic::Era, BuildStorage, SaturatedConversion}; @@ -84,26 +84,12 @@ pub struct GenesisParameters { impl substrate_test_client::GenesisInit for GenesisParameters { fn genesis_storage(&self) -> Storage { - let mut storage = if self.endowed_accounts.is_empty() { - genesis_config().build_storage().unwrap() - } else { - cumulus_test_service::testnet_genesis( - cumulus_test_service::get_account_id_from_seed::("Alice"), - self.endowed_accounts.clone(), - None, - ) - .build_storage() - .unwrap() - }; - - storage.top.insert( - sp_core::storage::well_known_keys::CODE.to_vec(), - cumulus_test_runtime::WASM_BINARY - .expect("cumulus_test_runtime WASM binary was not built, please build it!") - .into(), - ); - - storage + cumulus_test_service::chain_spec::get_chain_spec_with_extra_endowed( + None, + self.endowed_accounts.clone(), + ) + .build_storage() + .expect("Builds test runtime genesis storage") } } @@ -136,10 +122,6 @@ impl DefaultTestClientBuilderExt for TestClientBuilder { } } -fn genesis_config() -> RuntimeGenesisConfig { - cumulus_test_service::testnet_genesis_with_default_endowed(Default::default(), None) -} - /// Create an unsigned extrinsic from a runtime call. pub fn generate_unsigned(function: impl Into) -> UncheckedExtrinsic { UncheckedExtrinsic::new_unsigned(function.into()) diff --git a/cumulus/test/service/src/chain_spec.rs b/cumulus/test/service/src/chain_spec.rs index 574e138724db..61bbf755d890 100644 --- a/cumulus/test/service/src/chain_spec.rs +++ b/cumulus/test/service/src/chain_spec.rs @@ -63,25 +63,25 @@ where /// The given accounts are initialized with funds in addition /// to the default known accounts. pub fn get_chain_spec_with_extra_endowed( - id: ParaId, + id: Option, extra_endowed_accounts: Vec, ) -> ChainSpec { ChainSpec::builder( cumulus_test_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - Extensions { para_id: id.into() }, + Extensions { para_id: id.unwrap_or(cumulus_test_runtime::PARACHAIN_ID.into()).into() }, ) .with_name("Local Testnet") .with_id("local_testnet") .with_chain_type(ChainType::Local) .with_genesis_config_patch(testnet_genesis_with_default_endowed( extra_endowed_accounts.clone(), - Some(id), + id, )) .build() } /// Get the chain spec for a specific parachain ID. -pub fn get_chain_spec(id: ParaId) -> ChainSpec { +pub fn get_chain_spec(id: Option) -> ChainSpec { get_chain_spec_with_extra_endowed(id, Default::default()) } diff --git a/cumulus/test/service/src/genesis.rs b/cumulus/test/service/src/genesis.rs index 9dba57ba9fbc..d4a9a2256264 100644 --- a/cumulus/test/service/src/genesis.rs +++ b/cumulus/test/service/src/genesis.rs @@ -23,7 +23,7 @@ use sp_runtime::traits::Block as BlockT; /// Returns the initial head data for a parachain ID. pub fn initial_head_data(para_id: ParaId) -> HeadData { - let spec = crate::chain_spec::get_chain_spec(para_id); + let spec = crate::chain_spec::get_chain_spec(Some(para_id)); let block: Block = generate_genesis_block(&spec, sp_runtime::StateVersion::V1).unwrap(); let genesis_state = block.header().encode(); genesis_state.into() diff --git a/cumulus/test/service/src/lib.rs b/cumulus/test/service/src/lib.rs index a721645546af..6fd3e4d43d75 100644 --- a/cumulus/test/service/src/lib.rs +++ b/cumulus/test/service/src/lib.rs @@ -719,7 +719,7 @@ pub fn node_config( let role = if is_collator { Role::Authority } else { Role::Full }; let key_seed = key.to_seed(); let mut spec = - Box::new(chain_spec::get_chain_spec_with_extra_endowed(para_id, endowed_accounts)); + Box::new(chain_spec::get_chain_spec_with_extra_endowed(Some(para_id), endowed_accounts)); let mut storage = spec.as_storage_builder().build_storage().expect("could not build storage"); From cbb493efe5f69b93c4c45672de0c34d6c76fddfa Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 3 Nov 2023 17:12:20 +0100 Subject: [PATCH 87/98] fixes --- cumulus/test/service/src/cli.rs | 5 +++-- cumulus/test/service/src/main.rs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cumulus/test/service/src/cli.rs b/cumulus/test/service/src/cli.rs index 9235a0c45c58..ef1159a3c1f8 100644 --- a/cumulus/test/service/src/cli.rs +++ b/cumulus/test/service/src/cli.rs @@ -287,8 +287,9 @@ impl SubstrateCli for TestCollatorCli { fn load_spec(&self, id: &str) -> std::result::Result, String> { Ok(match id { - "" => Box::new(cumulus_test_service::get_chain_spec(ParaId::from(self.parachain_id))) - as Box<_>, + "" => Box::new(cumulus_test_service::get_chain_spec(Some(ParaId::from( + self.parachain_id, + )))) as Box<_>, path => { let chain_spec = cumulus_test_service::chain_spec::ChainSpec::from_json_file(path.into())?; diff --git a/cumulus/test/service/src/main.rs b/cumulus/test/service/src/main.rs index 5946e9cc3506..16b68796bd39 100644 --- a/cumulus/test/service/src/main.rs +++ b/cumulus/test/service/src/main.rs @@ -73,7 +73,7 @@ fn main() -> Result<(), sc_cli::Error> { let runner = cli.create_runner(cmd)?; runner.sync_run(|_config| { let parachain_id = ParaId::from(cmd.parachain_id); - let spec = cumulus_test_service::get_chain_spec(parachain_id); + let spec = cumulus_test_service::get_chain_spec(Some(parachain_id)); cmd.base.run(&spec) }) }, From e94b4768e59987af99d53dfe37f7044dc369738b Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Sat, 4 Nov 2023 09:08:45 +0100 Subject: [PATCH 88/98] genesis-builder implemented for cumulus-test-runtime --- Cargo.lock | 1 + cumulus/test/runtime/Cargo.toml | 2 ++ cumulus/test/runtime/src/lib.rs | 11 +++++++++++ 3 files changed, 14 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index e376644cdd8d..3ddd8f29c114 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4221,6 +4221,7 @@ dependencies = [ "sp-api", "sp-block-builder", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-io", "sp-offchain", diff --git a/cumulus/test/runtime/Cargo.toml b/cumulus/test/runtime/Cargo.toml index e1e723449ea1..3ea51c1973f4 100644 --- a/cumulus/test/runtime/Cargo.toml +++ b/cumulus/test/runtime/Cargo.toml @@ -23,6 +23,7 @@ pallet-transaction-payment = { path = "../../../substrate/frame/transaction-paym sp-api = { path = "../../../substrate/primitives/api", default-features = false} sp-block-builder = { path = "../../../substrate/primitives/block-builder", default-features = false} sp-core = { path = "../../../substrate/primitives/core", default-features = false} +sp-genesis-builder = { path = "../../../substrate/primitives/genesis-builder", default-features = false} sp-inherents = { path = "../../../substrate/primitives/inherents", default-features = false} sp-io = { path = "../../../substrate/primitives/io", default-features = false} sp-offchain = { path = "../../../substrate/primitives/offchain", default-features = false} @@ -59,6 +60,7 @@ std = [ "sp-api/std", "sp-block-builder/std", "sp-core/std", + "sp-genesis-builder/std", "sp-inherents/std", "sp-io/std", "sp-offchain/std", diff --git a/cumulus/test/runtime/src/lib.rs b/cumulus/test/runtime/src/lib.rs index 381cc64cef82..19fd6d5f02db 100644 --- a/cumulus/test/runtime/src/lib.rs +++ b/cumulus/test/runtime/src/lib.rs @@ -47,6 +47,7 @@ use sp_version::RuntimeVersion; pub use frame_support::{ construct_runtime, dispatch::DispatchClass, + genesis_builder_helper::{build_config, create_default_config}, parameter_types, traits::{ConstU8, Randomness}, weights::{ @@ -473,6 +474,16 @@ impl_runtime_apis! { ParachainSystem::collect_collation_info(header) } } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } } cumulus_pallet_parachain_system::register_validate_block! { From 8e85faffa5d9a5997dbec266ac5a252044bb160a Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Sat, 4 Nov 2023 12:24:59 +0100 Subject: [PATCH 89/98] test and doc for legacy --- substrate/client/chain-spec/src/chain_spec.rs | 50 +++++++++++++++++-- substrate/test-utils/runtime/src/lib.rs | 9 ++-- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index c7c83f341723..7888bfed53e5 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -248,7 +248,9 @@ enum RuntimeGenesisConfigJson { /// Inner variant wrapper for deprecated runtime. #[derive(Serialize, Deserialize, Debug)] struct RuntimeInnerWrapper { + /// The native `RuntimeGenesisConfig` struct. runtime: G, + /// Runtime code. #[serde(with = "sp_core::bytes")] code: Vec, } @@ -261,14 +263,13 @@ struct RuntimeInnerWrapper { enum Genesis { /// (Deprecated) Contains the JSON representation of G (the native type representing the /// runtime's `RuntimeGenesisConfig` struct) (will be removed with `ChainSpec::from_genesis`) - /// without the runtime code. + /// without the runtime code. It is required to deserialize the legacy chainspecs genereted + /// with `ChainsSpec::from_genesis` method. Runtime(G), /// (Deprecated) Contains the JSON representation of G (the native type representing the /// runtime's `RuntimeGenesisConfig` struct) (will be removed with `ChainSpec::from_genesis`) - /// and the runtime code. - // #[deprecated( - // note = "`RuntimeAndCode` is planned to be removed in December 2023. Use `RuntimeGenesis` - // instead." )] + /// and the runtime code. It is required to create and deserializa JSON chainspecs created with + /// deprecated `ChainSpec::from_genesis` method. RuntimeAndCode(RuntimeInnerWrapper), /// The genesis storage as raw data. Typically raw key-value entries in state. Raw(RawGenesis), @@ -1207,4 +1208,43 @@ mod tests { &|v| { *v == "0x000102040506" } )); } + + #[test] + fn generate_from_genesis_is_still_supported() { + let chain_spec: ChainSpec = + ChainSpec::from_genesis( + "TestName", + "test", + ChainType::Local, + move || substrate_test_runtime::RuntimeGenesisConfig { + babe: substrate_test_runtime::BabeConfig { + epoch_config: Some( + substrate_test_runtime::TEST_RUNTIME_BABE_EPOCH_CONFIGURATION, + ), + ..Default::default() + }, + ..Default::default() + }, + Vec::new(), + None, + None, + None, + None, + Default::default(), + &vec![0, 1, 2, 4, 5, 6], + ); + + let chain_spec_json = from_str::(&chain_spec.as_json(false).unwrap()).unwrap(); + assert!(json_eval_value_at_key( + &chain_spec_json, + &mut json_path!["genesis", "runtimeAndCode", "code"], + &|v| { *v == "0x000102040506" } + )); + let chain_spec_json = from_str::(&chain_spec.as_json(true).unwrap()).unwrap(); + assert!(json_eval_value_at_key( + &chain_spec_json, + &mut json_path!["genesis", "raw", "top", "0x3a636f6465"], + &|v| { *v == "0x000102040506" } + )); + } } diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index 949ffaa950e3..1a4e9fd04667 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -464,11 +464,10 @@ impl_opaque_keys! { } } -pub(crate) const TEST_RUNTIME_BABE_EPOCH_CONFIGURATION: BabeEpochConfiguration = - BabeEpochConfiguration { - c: (3, 10), - allowed_slots: AllowedSlots::PrimaryAndSecondaryPlainSlots, - }; +pub const TEST_RUNTIME_BABE_EPOCH_CONFIGURATION: BabeEpochConfiguration = BabeEpochConfiguration { + c: (3, 10), + allowed_slots: AllowedSlots::PrimaryAndSecondaryPlainSlots, +}; impl_runtime_apis! { impl sp_api::Core for Runtime { From 00ca55d0c57cc839c0510d0b3ffbd6ccc2253d88 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Sat, 4 Nov 2023 15:12:37 +0100 Subject: [PATCH 90/98] fix --- substrate/client/chain-spec/src/chain_spec.rs | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index 7888bfed53e5..92b9f559fc2a 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -1211,28 +1211,28 @@ mod tests { #[test] fn generate_from_genesis_is_still_supported() { - let chain_spec: ChainSpec = - ChainSpec::from_genesis( - "TestName", - "test", - ChainType::Local, - move || substrate_test_runtime::RuntimeGenesisConfig { - babe: substrate_test_runtime::BabeConfig { - epoch_config: Some( - substrate_test_runtime::TEST_RUNTIME_BABE_EPOCH_CONFIGURATION, - ), - ..Default::default() - }, + #[allow(deprecated)] + let chain_spec: ChainSpec = ChainSpec::from_genesis( + "TestName", + "test", + ChainType::Local, + move || substrate_test_runtime::RuntimeGenesisConfig { + babe: substrate_test_runtime::BabeConfig { + epoch_config: Some( + substrate_test_runtime::TEST_RUNTIME_BABE_EPOCH_CONFIGURATION, + ), ..Default::default() }, - Vec::new(), - None, - None, - None, - None, - Default::default(), - &vec![0, 1, 2, 4, 5, 6], - ); + ..Default::default() + }, + Vec::new(), + None, + None, + None, + None, + Default::default(), + &vec![0, 1, 2, 4, 5, 6], + ); let chain_spec_json = from_str::(&chain_spec.as_json(false).unwrap()).unwrap(); assert!(json_eval_value_at_key( From 670e837711258aa633ac2f5758decf0b25af3812 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Sun, 5 Nov 2023 08:54:42 +0100 Subject: [PATCH 91/98] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- substrate/client/chain-spec/src/chain_spec.rs | 9 +++------ .../client/chain-spec/src/genesis_config_builder.rs | 12 +++++++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index 92b9f559fc2a..3144d4f5d1dc 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -238,6 +238,8 @@ struct RuntimeGenesisInner { enum RuntimeGenesisConfigJson { /// Represents the explicit and comprehensive runtime genesis config in JSON format. /// The contained object is a JSON blob that can be parsed by a compatible runtime. + /// + /// Using a full config is useful for when someone wants to ensure that a change in the runtime makes the deserialization fail and not silently add some default values. Config(json::Value), /// Represents a patch for the default runtime genesis config in JSON format which is /// essentially a list of keys that are to be customized in runtime genesis config. @@ -268,7 +270,7 @@ enum Genesis { Runtime(G), /// (Deprecated) Contains the JSON representation of G (the native type representing the /// runtime's `RuntimeGenesisConfig` struct) (will be removed with `ChainSpec::from_genesis`) - /// and the runtime code. It is required to create and deserializa JSON chainspecs created with + /// and the runtime code. It is required to create and deserialize JSON chainspecs created with /// deprecated `ChainSpec::from_genesis` method. RuntimeAndCode(RuntimeInnerWrapper), /// The genesis storage as raw data. Typically raw key-value entries in state. @@ -789,10 +791,7 @@ pub fn update_code_in_json_chain_spec(chain_spec: &mut json::Value, code: &[u8]) let mut path = json_path!["genesis", "runtimeGenesis", "code"]; let mut raw_path = json_path!["genesis", "raw", "top"]; - println!("xxx"); - if json_contains_path(&chain_spec, &mut path) { - println!("xxx1"); #[derive(Serialize)] struct Container<'a> { #[serde(with = "sp_core::bytes")] @@ -802,14 +801,12 @@ pub fn update_code_in_json_chain_spec(chain_spec: &mut json::Value, code: &[u8]) crate::json_patch::merge(chain_spec, code_patch); true } else if json_contains_path(&chain_spec, &mut raw_path) { - println!("xxx2"); #[derive(Serialize)] struct Container<'a> { #[serde(with = "sp_core::bytes", rename = "0x3a636f6465")] code: &'a [u8], } let code_patch = json::json!({"genesis":{"raw":{"top": Container { code }}}}); - println!("xxx2 {:#?}", code_patch); crate::json_patch::merge(chain_spec, code_patch); true } else { diff --git a/substrate/client/chain-spec/src/genesis_config_builder.rs b/substrate/client/chain-spec/src/genesis_config_builder.rs index df3f9ffc6e6c..158d2e44042a 100644 --- a/substrate/client/chain-spec/src/genesis_config_builder.rs +++ b/substrate/client/chain-spec/src/genesis_config_builder.rs @@ -44,6 +44,8 @@ impl<'a> FetchRuntimeCode for GenesisConfigBuilderRuntimeCaller<'a> { impl<'a> GenesisConfigBuilderRuntimeCaller<'a> { /// Creates new instance using the provided code blob. + /// + /// This code is later referred to as `runtime`. pub fn new(code: &'a [u8]) -> Self { GenesisConfigBuilderRuntimeCaller { code: code.into(), @@ -67,7 +69,9 @@ impl<'a> GenesisConfigBuilderRuntimeCaller<'a> { .0 } - /// Calls [`sp_genesis_builder::GenesisBuilder::create_default_config`] provided by runtime. + /// Returns the default `GenesisConfig` provided by the `runtime`. + /// + /// Calls [`GenesisBuilder::create_default_config`](sp_genesis_builder::GenesisBuilder::create_default_config) in the `runtime`. pub fn get_default_config(&self) -> core::result::Result { let mut t = BasicExternalities::new_empty(); let call_result = self @@ -78,7 +82,9 @@ impl<'a> GenesisConfigBuilderRuntimeCaller<'a> { Ok(from_slice(&default_config[..]).expect("returned value is json. qed.")) } - /// Calls [`sp_genesis_builder::GenesisBuilder::build_config`] provided by runtime. + /// Build the given `GenesisConfig` and returns the genesis state. + /// + /// Calls [`GenesisBuilder::build_config`](sp_genesis_builder::GenesisBuilder::build_config) provided by the `runtime`. pub fn get_storage_for_config(&self, config: Value) -> core::result::Result { let mut ext = BasicExternalities::new_empty(); @@ -92,7 +98,7 @@ impl<'a> GenesisConfigBuilderRuntimeCaller<'a> { Ok(ext.into_storages()) } - /// Patch default `GenesisConfig` using given JSON patch and store it in the storage. + /// Creates the genesis state by patching the default `GenesisConfig` and applying it. /// /// This function generates the `GenesisConfig` for the runtime by applying a provided JSON /// patch. The patch modifies the default `GenesisConfig` allowing customization of the specific From 393ce9d68da581aa5664adbd6b201b0ac80e6060 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Sun, 5 Nov 2023 08:58:12 +0100 Subject: [PATCH 92/98] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bastian Köcher --- substrate/client/chain-spec/src/chain_spec.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index 3144d4f5d1dc..d43fa448a5e9 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -761,10 +761,11 @@ fn json_eval_value_at_key( path: &mut VecDeque<&str>, fun: &dyn Fn(&json::Value) -> bool, ) -> bool { - if path.len() == 1 { - doc.as_object().map_or(false, |o| o.get(path[0]).map_or(false, |v| fun(v))) + let Some(key) = path.pop() else { return false; } + + if path.is_empty() { + doc.as_object().map_or(false, |o| o.get(key).map_or(false, |v| fun(v))) } else { - let key = path.pop_front().unwrap(); doc.as_object() .map_or(false, |o| o.get(key).map_or(false, |v| json_eval_value_at_key(v, path, fun))) } From 3df6b4d00eb310900de6f4858114baf68239412c Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Sun, 5 Nov 2023 09:06:08 +0100 Subject: [PATCH 93/98] review suggestions + fixes --- substrate/client/chain-spec/src/chain_spec.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index d43fa448a5e9..51b935b37168 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -52,9 +52,7 @@ enum GenesisSource { File(PathBuf), Binary(Cow<'static, [u8]>), /// factory function + code - #[deprecated( - note = "Factory and G type parameter are planned to be removed in December 2023. Use `GenesisBuilderApi` instead." - )] + //Factory and G type parameter shall be removed togheter with `ChainSpec::from_genesis` Factory(Arc G + Send + Sync>, Vec), Storage(Storage), /// build action + code @@ -66,7 +64,6 @@ impl Clone for GenesisSource { match *self { Self::File(ref path) => Self::File(path.clone()), Self::Binary(ref d) => Self::Binary(d.clone()), - #[allow(deprecated)] Self::Factory(ref f, ref c) => Self::Factory(f.clone(), c.clone()), Self::Storage(ref s) => Self::Storage(s.clone()), Self::GenesisBuilderApi(ref s, ref c) => Self::GenesisBuilderApi(s.clone(), c.clone()), @@ -106,7 +103,6 @@ impl GenesisSource { .map_err(|e| format!("Error parsing embedded file: {}", e))?; Ok(genesis.genesis) }, - #[allow(deprecated)] Self::Factory(f, code) => Ok(Genesis::RuntimeAndCode(RuntimeInnerWrapper { runtime: f(), code: code.clone(), @@ -239,7 +235,8 @@ enum RuntimeGenesisConfigJson { /// Represents the explicit and comprehensive runtime genesis config in JSON format. /// The contained object is a JSON blob that can be parsed by a compatible runtime. /// - /// Using a full config is useful for when someone wants to ensure that a change in the runtime makes the deserialization fail and not silently add some default values. + /// Using a full config is useful for when someone wants to ensure that a change in the runtime + /// makes the deserialization fail and not silently add some default values. Config(json::Value), /// Represents a patch for the default runtime genesis config in JSON format which is /// essentially a list of keys that are to be customized in runtime genesis config. @@ -261,7 +258,6 @@ struct RuntimeInnerWrapper { #[derive(Serialize, Deserialize)] #[serde(rename_all = "camelCase")] #[serde(deny_unknown_fields)] -#[allow(deprecated)] enum Genesis { /// (Deprecated) Contains the JSON representation of G (the native type representing the /// runtime's `RuntimeGenesisConfig` struct) (will be removed with `ChainSpec::from_genesis`) @@ -554,7 +550,6 @@ impl ChainSpec { code_substitutes: BTreeMap::new(), }; - #[allow(deprecated)] ChainSpec { client_spec, genesis: GenesisSource::Factory(Arc::new(constructor), code.into()), @@ -761,8 +756,10 @@ fn json_eval_value_at_key( path: &mut VecDeque<&str>, fun: &dyn Fn(&json::Value) -> bool, ) -> bool { - let Some(key) = path.pop() else { return false; } - + let Some(key) = path.pop_front() else { + return false; + }; + if path.is_empty() { doc.as_object().map_or(false, |o| o.get(key).map_or(false, |v| fun(v))) } else { From cf70573251f0d3857026d92400f94103e504d934 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Sun, 5 Nov 2023 09:48:51 +0100 Subject: [PATCH 94/98] fmt --- substrate/client/chain-spec/src/genesis_config_builder.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/substrate/client/chain-spec/src/genesis_config_builder.rs b/substrate/client/chain-spec/src/genesis_config_builder.rs index 158d2e44042a..c2c6249563f0 100644 --- a/substrate/client/chain-spec/src/genesis_config_builder.rs +++ b/substrate/client/chain-spec/src/genesis_config_builder.rs @@ -84,7 +84,8 @@ impl<'a> GenesisConfigBuilderRuntimeCaller<'a> { /// Build the given `GenesisConfig` and returns the genesis state. /// - /// Calls [`GenesisBuilder::build_config`](sp_genesis_builder::GenesisBuilder::build_config) provided by the `runtime`. + /// Calls [`GenesisBuilder::build_config`](sp_genesis_builder::GenesisBuilder::build_config) + /// provided by the `runtime`. pub fn get_storage_for_config(&self, config: Value) -> core::result::Result { let mut ext = BasicExternalities::new_empty(); From 1393fcbefde53e8a2f71479e4cf6b0b63d0c6efc Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Sun, 5 Nov 2023 09:13:02 +0100 Subject: [PATCH 95/98] deprecation date updated to 05.24 --- substrate/client/chain-spec/src/chain_spec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/client/chain-spec/src/chain_spec.rs b/substrate/client/chain-spec/src/chain_spec.rs index 51b935b37168..a44a3b4fbd97 100644 --- a/substrate/client/chain-spec/src/chain_spec.rs +++ b/substrate/client/chain-spec/src/chain_spec.rs @@ -519,7 +519,7 @@ impl ChainSpec { /// Create hardcoded spec. #[deprecated( - note = "`from_genesis` is planned to be removed in December 2023. Use `builder()` instead." + note = "`from_genesis` is planned to be removed in May 2024. Use `builder()` instead." )] // deprecated note: Genesis::Runtime + GenesisSource::Factory shall also be removed pub fn from_genesis G + 'static + Send + Sync>( From 03ae1bc9dfcca18392dbf3dba67a7cc6c98181fd Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Sun, 5 Nov 2023 09:39:49 +0100 Subject: [PATCH 96/98] prdoc: updated --- prdoc/pr_1256.prdoc | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/prdoc/pr_1256.prdoc b/prdoc/pr_1256.prdoc index 41f145e8dc19..f486786fec35 100644 --- a/prdoc/pr_1256.prdoc +++ b/prdoc/pr_1256.prdoc @@ -1,18 +1,14 @@ # Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0 # See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json -title: `chain-spec`: getting ready for native-runtime-free world +title: "`chain-spec`: getting ready for native-runtime-free world" doc: - audience: Node Dev description: | - - [`ChainSpec::from_genesis`](https://github.com/paritytech/substrate/blob/3ef576eaeb3f42610e85daecc464961cf1295570/client/chain-spec/src/chain_spec.rs#L263) becomes deprecated in favor of [`ChainSpec::builder()`](https://github.com/paritytech/substrate/blob/20bee680ed098be7239cf7a6b804cd4de267983e/client/chain-spec/src/chain_spec.rs#L507), + - [`ChainSpec::from_genesis`](https://github.com/paritytech/polkadot-sdk/blob/3df6b4d00eb310900de6f4858114baf68239412c/substrate/client/chain-spec/src/chain_spec.rs#L525) becomes deprecated in favor of [`ChainSpec::builder()`](https://github.com/paritytech/polkadot-sdk/blob/3df6b4d00eb310900de6f4858114baf68239412c/substrate/client/chain-spec/src/chain_spec.rs#L432), - The signature of [`ChainSpec::from_genesis`] method was changed by extending it with `code` argument. - - audience: Node Operator - description: | - Change in plain chain specification JSON file. `::genesis::runtime::system::code` key is removed and replaced with `::code` key. Raw version of chain spec remains unchanged. - migrations: db: [] From f4d3f32cb8c974a3b6b06ca8248daa99f3d0266e Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Sun, 5 Nov 2023 09:40:33 +0100 Subject: [PATCH 97/98] json vs legacy tests removed --- .../parachain-template/node/src/chain_spec.rs | 195 --- .../src/legacy_chain_spec/asset_hubs.rs | 973 ------------- .../src/legacy_chain_spec/bridge_hubs.rs | 753 ---------- .../src/legacy_chain_spec/collectives.rs | 184 --- .../src/legacy_chain_spec/contracts.rs | 287 ---- .../src/legacy_chain_spec/glutton.rs | 126 -- .../legacy_chain_spec/json_vs_legacy_tests.rs | 106 -- .../src/legacy_chain_spec/mod.rs | 84 -- .../src/legacy_chain_spec/penpal.rs | 140 -- .../src/legacy_chain_spec/rococo_parachain.rs | 125 -- .../src/legacy_chain_spec/seedling.rs | 68 - .../src/legacy_chain_spec/shell.rs | 58 - cumulus/polkadot-parachain/src/main.rs | 5 - polkadot/node/service/src/chain_spec.rs | 143 -- .../src/chain_spec/legacy_chain_spec.rs | 1289 ----------------- substrate/bin/minimal/node/src/chain_spec.rs | 48 - substrate/bin/node/cli/src/chain_spec.rs | 305 ---- 17 files changed, 4889 deletions(-) delete mode 100644 cumulus/polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs delete mode 100644 cumulus/polkadot-parachain/src/legacy_chain_spec/bridge_hubs.rs delete mode 100644 cumulus/polkadot-parachain/src/legacy_chain_spec/collectives.rs delete mode 100644 cumulus/polkadot-parachain/src/legacy_chain_spec/contracts.rs delete mode 100644 cumulus/polkadot-parachain/src/legacy_chain_spec/glutton.rs delete mode 100644 cumulus/polkadot-parachain/src/legacy_chain_spec/json_vs_legacy_tests.rs delete mode 100644 cumulus/polkadot-parachain/src/legacy_chain_spec/mod.rs delete mode 100644 cumulus/polkadot-parachain/src/legacy_chain_spec/penpal.rs delete mode 100644 cumulus/polkadot-parachain/src/legacy_chain_spec/rococo_parachain.rs delete mode 100644 cumulus/polkadot-parachain/src/legacy_chain_spec/seedling.rs delete mode 100644 cumulus/polkadot-parachain/src/legacy_chain_spec/shell.rs delete mode 100644 polkadot/node/service/src/chain_spec/legacy_chain_spec.rs diff --git a/cumulus/parachain-template/node/src/chain_spec.rs b/cumulus/parachain-template/node/src/chain_spec.rs index 4655a492c50a..a79c78699c07 100644 --- a/cumulus/parachain-template/node/src/chain_spec.rs +++ b/cumulus/parachain-template/node/src/chain_spec.rs @@ -200,198 +200,3 @@ fn testnet_genesis( "sudo": { "key": Some(root) } }) } - -#[cfg(test)] -/// RuntimeGenesisConfig-based (legacy) parachain-template configurations. Used for testing -/// ChainSpecs against the JSON-based genesis configs. Entire file shall be removed once native -/// runtime is removed. -mod legacy { - use super::*; - - /// Specialized `ChainSpec` for the normal parachain runtime. - pub type ChainSpec = - sc_service::GenericChainSpec; - - pub fn development_config() -> ChainSpec { - // Give your base currency a unit name and decimal places - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("tokenSymbol".into(), "UNIT".into()); - properties.insert("tokenDecimals".into(), 12.into()); - properties.insert("ss58Format".into(), 42.into()); - - #[allow(deprecated)] - ChainSpec::from_genesis( - // Name - "Development", - // ID - "dev", - ChainType::Development, - move || { - testnet_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed("Bob"), - ), - ], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - get_account_id_from_seed::("Alice"), - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - None, - Extensions { - relay_chain: "rococo-local".into(), // You MUST set this to the correct network! - para_id: 1000, - }, - parachain_template_runtime::WASM_BINARY - .expect("WASM binary was not built, please build it!"), - ) - } - - pub fn local_testnet_config() -> ChainSpec { - // Give your base currency a unit name and decimal places - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("tokenSymbol".into(), "UNIT".into()); - properties.insert("tokenDecimals".into(), 12.into()); - properties.insert("ss58Format".into(), 42.into()); - - #[allow(deprecated)] - ChainSpec::from_genesis( - // Name - "Local Testnet", - // ID - "local_testnet", - ChainType::Local, - move || { - testnet_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed("Bob"), - ), - ], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - get_account_id_from_seed::("Alice"), - 1000.into(), - ) - }, - // Bootnodes - Vec::new(), - // Telemetry - None, - // Protocol ID - Some("template-local"), - // Fork ID - None, - // Properties - Some(properties), - // Extensions - Extensions { - relay_chain: "rococo-local".into(), // You MUST set this to the correct network! - para_id: 1000, - }, - parachain_template_runtime::WASM_BINARY - .expect("WASM binary was not built, please build it!"), - ) - } - - fn testnet_genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - root: AccountId, - id: ParaId, - ) -> parachain_template_runtime::RuntimeGenesisConfig { - parachain_template_runtime::RuntimeGenesisConfig { - system: parachain_template_runtime::SystemConfig::default(), - balances: parachain_template_runtime::BalancesConfig { - balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), - }, - parachain_info: parachain_template_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() - }, - collator_selection: parachain_template_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: EXISTENTIAL_DEPOSIT * 16, - ..Default::default() - }, - session: parachain_template_runtime::SessionConfig { - keys: invulnerables - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - template_session_keys(aura), // session keys - ) - }) - .collect(), - }, - // no need to pass anything to aura, in fact it will panic if we do. Session will take - // care of this. - aura: Default::default(), - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: parachain_template_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, - transaction_payment: Default::default(), - sudo: parachain_template_runtime::SudoConfig { key: Some(root) }, - } - } - - #[test] - fn test_development_config() { - let j1 = development_config().as_json(true); - let j2 = legacy::development_config().as_json(true); - assert_eq!(j1, j2); - } - #[test] - fn test_local_testnet_config() { - let j1 = local_testnet_config().as_json(true); - let j2 = legacy::local_testnet_config().as_json(true); - assert_eq!(j1, j2); - } -} diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs deleted file mode 100644 index acbad93c4764..000000000000 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/asset_hubs.rs +++ /dev/null @@ -1,973 +0,0 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Cumulus. - -// Cumulus 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. - -// Cumulus 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 Cumulus. If not, see . - -use crate::legacy_chain_spec::{ - get_account_id_from_seed, get_collator_keys_from_seed, Extensions, SAFE_XCM_VERSION, -}; -use cumulus_primitives_core::ParaId; -use hex_literal::hex; -use parachains_common::{AccountId, AssetHubPolkadotAuraId, AuraId, Balance as AssetHubBalance}; -use sc_service::ChainType; -use sp_core::{crypto::UncheckedInto, sr25519}; - -/// Specialized `ChainSpec` for the normal parachain runtime. -pub type AssetHubPolkadotChainSpec = - sc_service::GenericChainSpec; -pub type AssetHubKusamaChainSpec = - sc_service::GenericChainSpec; -pub type AssetHubWestendChainSpec = - sc_service::GenericChainSpec; -pub type AssetHubRococoChainSpec = - sc_service::GenericChainSpec; -pub type AssetHubWococoChainSpec = AssetHubRococoChainSpec; - -const ASSET_HUB_POLKADOT_ED: AssetHubBalance = - parachains_common::polkadot::currency::EXISTENTIAL_DEPOSIT; -const ASSET_HUB_KUSAMA_ED: AssetHubBalance = - parachains_common::kusama::currency::EXISTENTIAL_DEPOSIT; -const ASSET_HUB_WESTEND_ED: AssetHubBalance = - parachains_common::westend::currency::EXISTENTIAL_DEPOSIT; -const ASSET_HUB_ROCOCO_ED: AssetHubBalance = - parachains_common::westend::currency::EXISTENTIAL_DEPOSIT; - -/// 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 asset_hub_rococo_session_keys(keys: AuraId) -> asset_hub_rococo_runtime::SessionKeys { - asset_hub_rococo_runtime::SessionKeys { aura: keys } -} - -/// Generate the session keys from individual elements. -/// -/// The input must be a tuple of individual keys (a single arg for now since we have just one key). -pub fn asset_hub_westend_session_keys(keys: AuraId) -> asset_hub_westend_runtime::SessionKeys { - asset_hub_westend_runtime::SessionKeys { aura: keys } -} - -pub fn asset_hub_polkadot_development_config() -> AssetHubPolkadotChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("ss58Format".into(), 0.into()); - properties.insert("tokenSymbol".into(), "DOT".into()); - properties.insert("tokenDecimals".into(), 10.into()); - - #[allow(deprecated)] - AssetHubPolkadotChainSpec::from_genesis( - // Name - "Polkadot Asset Hub Development", - // ID - "asset-hub-polkadot-dev", - ChainType::Local, - move || { - asset_hub_polkadot_genesis( - // initial collators. - vec![( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - )], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - ], - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: "polkadot-dev".into(), para_id: 1000 }, - asset_hub_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not built, please build it!"), - ) -} - -pub fn asset_hub_polkadot_local_config() -> AssetHubPolkadotChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("ss58Format".into(), 0.into()); - properties.insert("tokenSymbol".into(), "DOT".into()); - properties.insert("tokenDecimals".into(), 10.into()); - - #[allow(deprecated)] - AssetHubPolkadotChainSpec::from_genesis( - // Name - "Polkadot Asset Hub Local", - // ID - "asset-hub-polkadot-local", - ChainType::Local, - move || { - asset_hub_polkadot_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: "polkadot-local".into(), para_id: 1000 }, - asset_hub_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not built, please build it!"), - ) -} - -// Not used for syncing, but just to determine the genesis values set for the upgrade from shell. -pub fn asset_hub_polkadot_config() -> AssetHubPolkadotChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("ss58Format".into(), 0.into()); - properties.insert("tokenSymbol".into(), "DOT".into()); - properties.insert("tokenDecimals".into(), 10.into()); - - #[allow(deprecated)] - AssetHubPolkadotChainSpec::from_genesis( - // Name - "Polkadot Asset Hub", - // ID - "asset-hub-polkadot", - ChainType::Live, - move || { - asset_hub_polkadot_genesis( - // initial collators. - vec![ - ( - hex!("4c3d674d2a01060f0ded218e5dcc6f90c1726f43df79885eb3e22d97a20d5421") - .into(), - hex!("4c3d674d2a01060f0ded218e5dcc6f90c1726f43df79885eb3e22d97a20d5421") - .unchecked_into(), - ), - ( - hex!("c7d7d38d16bc23c6321152c50306212dc22c0efc04a2e52b5cccfc31ab3d7811") - .into(), - hex!("c7d7d38d16bc23c6321152c50306212dc22c0efc04a2e52b5cccfc31ab3d7811") - .unchecked_into(), - ), - ( - hex!("c5c07ba203d7375675f5c1ebe70f0a5bb729ae57b48bcc877fcc2ab21309b762") - .into(), - hex!("c5c07ba203d7375675f5c1ebe70f0a5bb729ae57b48bcc877fcc2ab21309b762") - .unchecked_into(), - ), - ( - hex!("0b2d0013fb974794bd7aa452465b567d48ef70373fe231a637c1fb7c547e85b3") - .into(), - hex!("0b2d0013fb974794bd7aa452465b567d48ef70373fe231a637c1fb7c547e85b3") - .unchecked_into(), - ), - ], - vec![], - 1000u32.into(), - ) - }, - vec![ - "/ip4/34.65.251.121/tcp/30334/p2p/12D3KooWG3GrM6XKMM4gp3cvemdwUvu96ziYoJmqmetLZBXE8bSa".parse().unwrap(), - "/ip4/34.65.35.228/tcp/30334/p2p/12D3KooWMRyTLrCEPcAQD6c4EnudL3vVzg9zji3whvsMYPUYevpq".parse().unwrap(), - "/ip4/34.83.247.146/tcp/30334/p2p/12D3KooWE4jFh5FpJDkWVZhnWtFnbSqRhdjvC7Dp9b8b3FTuubQC".parse().unwrap(), - "/ip4/104.199.117.230/tcp/30334/p2p/12D3KooWG9R8pVXKumVo2rdkeVD4j5PVhRTqmYgLHY3a4yPYgLqM".parse().unwrap(), - ], - None, - None, - None, - Some(properties), - Extensions { relay_chain: "polkadot".into(), para_id: 1000 }, - asset_hub_polkadot_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - ) -} - -fn asset_hub_polkadot_genesis( - invulnerables: Vec<(AccountId, AssetHubPolkadotAuraId)>, - endowed_accounts: Vec, - id: ParaId, -) -> asset_hub_polkadot_runtime::RuntimeGenesisConfig { - asset_hub_polkadot_runtime::RuntimeGenesisConfig { - system: asset_hub_polkadot_runtime::SystemConfig::default(), - balances: asset_hub_polkadot_runtime::BalancesConfig { - balances: endowed_accounts - .iter() - .cloned() - .map(|k| (k, ASSET_HUB_POLKADOT_ED * 4096)) - .collect(), - }, - parachain_info: asset_hub_polkadot_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() - }, - collator_selection: 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(), - }, - // no need to pass anything to aura, in fact it will panic if we do. Session will take care - // of this. - aura: Default::default(), - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: asset_hub_polkadot_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, - } -} - -pub fn asset_hub_kusama_development_config() -> AssetHubKusamaChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("ss58Format".into(), 2.into()); - properties.insert("tokenSymbol".into(), "KSM".into()); - properties.insert("tokenDecimals".into(), 12.into()); - - #[allow(deprecated)] - AssetHubKusamaChainSpec::from_genesis( - // Name - "Kusama Asset Hub Development", - // ID - "asset-hub-kusama-dev", - ChainType::Local, - move || { - asset_hub_kusama_genesis( - // initial collators. - vec![( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - )], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - ], - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: "kusama-dev".into(), para_id: 1000 }, - asset_hub_kusama_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - ) -} - -pub fn asset_hub_kusama_local_config() -> AssetHubKusamaChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("ss58Format".into(), 2.into()); - properties.insert("tokenSymbol".into(), "KSM".into()); - properties.insert("tokenDecimals".into(), 12.into()); - - #[allow(deprecated)] - AssetHubKusamaChainSpec::from_genesis( - // Name - "Kusama Asset Hub Local", - // ID - "asset-hub-kusama-local", - ChainType::Local, - move || { - asset_hub_kusama_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: "kusama-local".into(), para_id: 1000 }, - asset_hub_kusama_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - ) -} - -pub fn asset_hub_kusama_config() -> AssetHubKusamaChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("ss58Format".into(), 2.into()); - properties.insert("tokenSymbol".into(), "KSM".into()); - properties.insert("tokenDecimals".into(), 12.into()); - - #[allow(deprecated)] - AssetHubKusamaChainSpec::from_genesis( - // Name - "Kusama Asset Hub", - // ID - "asset-hub-kusama", - ChainType::Live, - move || { - asset_hub_kusama_genesis( - // initial collators. - vec![ - ( - hex!("50673d59020488a4ffc9d8c6de3062a65977046e6990915617f85fef6d349730") - .into(), - hex!("50673d59020488a4ffc9d8c6de3062a65977046e6990915617f85fef6d349730") - .unchecked_into(), - ), - ( - hex!("fe8102dbc244e7ea2babd9f53236d67403b046154370da5c3ea99def0bd0747a") - .into(), - hex!("fe8102dbc244e7ea2babd9f53236d67403b046154370da5c3ea99def0bd0747a") - .unchecked_into(), - ), - ( - hex!("38144b5398e5d0da5ec936a3af23f5a96e782f676ab19d45f29075ee92eca76a") - .into(), - hex!("38144b5398e5d0da5ec936a3af23f5a96e782f676ab19d45f29075ee92eca76a") - .unchecked_into(), - ), - ( - hex!("3253947640e309120ae70fa458dcacb915e2ddd78f930f52bd3679ec63fc4415") - .into(), - hex!("3253947640e309120ae70fa458dcacb915e2ddd78f930f52bd3679ec63fc4415") - .unchecked_into(), - ), - ], - Vec::new(), - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: "kusama".into(), para_id: 1000 }, - asset_hub_kusama_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - ) -} - -fn asset_hub_kusama_genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - id: ParaId, -) -> asset_hub_kusama_runtime::RuntimeGenesisConfig { - asset_hub_kusama_runtime::RuntimeGenesisConfig { - system: asset_hub_kusama_runtime::SystemConfig::default(), - balances: asset_hub_kusama_runtime::BalancesConfig { - balances: endowed_accounts - .iter() - .cloned() - .map(|k| (k, ASSET_HUB_KUSAMA_ED * 524_288)) - .collect(), - }, - parachain_info: asset_hub_kusama_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() - }, - collator_selection: 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(), - }, - aura: Default::default(), - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: asset_hub_kusama_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, - } -} - -pub fn asset_hub_westend_development_config() -> AssetHubWestendChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("tokenSymbol".into(), "WND".into()); - properties.insert("tokenDecimals".into(), 12.into()); - - #[allow(deprecated)] - AssetHubWestendChainSpec::from_genesis( - // Name - "Westend Asset Hub Development", - // ID - "asset-hub-westend-dev", - ChainType::Local, - move || { - asset_hub_westend_genesis( - // initial collators. - vec![( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - )], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - ], - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: "westend".into(), para_id: 1000 }, - asset_hub_westend_runtime::WASM_BINARY - .expect("WASM binary was not built, please build it!"), - ) -} - -pub fn asset_hub_westend_local_config() -> AssetHubWestendChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("tokenSymbol".into(), "WND".into()); - properties.insert("tokenDecimals".into(), 12.into()); - - #[allow(deprecated)] - AssetHubWestendChainSpec::from_genesis( - // Name - "Westend Asset Hub Local", - // ID - "asset-hub-westend-local", - ChainType::Local, - move || { - asset_hub_westend_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: "westend-local".into(), para_id: 1000 }, - asset_hub_westend_runtime::WASM_BINARY - .expect("WASM binary was not built, please build it!"), - ) -} - -pub fn asset_hub_westend_config() -> AssetHubWestendChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("tokenSymbol".into(), "WND".into()); - properties.insert("tokenDecimals".into(), 12.into()); - - #[allow(deprecated)] - AssetHubWestendChainSpec::from_genesis( - // Name - "Westend Asset Hub", - // ID - "asset-hub-westend", - ChainType::Live, - move || { - asset_hub_westend_genesis( - // initial collators. - vec![ - ( - hex!("9cfd429fa002114f33c1d3e211501d62830c9868228eb3b4b8ae15a83de04325") - .into(), - hex!("9cfd429fa002114f33c1d3e211501d62830c9868228eb3b4b8ae15a83de04325") - .unchecked_into(), - ), - ( - hex!("12a03fb4e7bda6c9a07ec0a11d03c24746943e054ff0bb04938970104c783876") - .into(), - hex!("12a03fb4e7bda6c9a07ec0a11d03c24746943e054ff0bb04938970104c783876") - .unchecked_into(), - ), - ( - hex!("1256436307dfde969324e95b8c62cb9101f520a39435e6af0f7ac07b34e1931f") - .into(), - hex!("1256436307dfde969324e95b8c62cb9101f520a39435e6af0f7ac07b34e1931f") - .unchecked_into(), - ), - ( - hex!("98102b7bca3f070f9aa19f58feed2c0a4e107d203396028ec17a47e1ed80e322") - .into(), - hex!("98102b7bca3f070f9aa19f58feed2c0a4e107d203396028ec17a47e1ed80e322") - .unchecked_into(), - ), - ], - Vec::new(), - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: "westend".into(), para_id: 1000 }, - asset_hub_westend_runtime::WASM_BINARY - .expect("WASM binary was not built, please build it!"), - ) -} - -fn asset_hub_westend_genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - id: ParaId, -) -> asset_hub_westend_runtime::RuntimeGenesisConfig { - asset_hub_westend_runtime::RuntimeGenesisConfig { - system: asset_hub_westend_runtime::SystemConfig::default(), - balances: asset_hub_westend_runtime::BalancesConfig { - balances: endowed_accounts - .iter() - .cloned() - .map(|k| (k, ASSET_HUB_WESTEND_ED * 4096)) - .collect(), - }, - parachain_info: asset_hub_westend_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() - }, - collator_selection: asset_hub_westend_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: ASSET_HUB_WESTEND_ED * 16, - ..Default::default() - }, - session: asset_hub_westend_runtime::SessionConfig { - keys: invulnerables - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - asset_hub_westend_session_keys(aura), // session keys - ) - }) - .collect(), - }, - // no need to pass anything to aura, in fact it will panic if we do. Session will take care - // of this. - aura: Default::default(), - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: asset_hub_westend_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, - } -} - -pub fn asset_hub_rococo_development_config() -> AssetHubRococoChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("ss58Format".into(), 42.into()); - properties.insert("tokenSymbol".into(), "ROC".into()); - properties.insert("tokenDecimals".into(), 12.into()); - asset_hub_rococo_like_development_config( - properties, - "Rococo Asset Hub Development", - "asset-hub-rococo-dev", - 1000, - ) -} - -pub fn asset_hub_wococo_development_config() -> AssetHubWococoChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("ss58Format".into(), 42.into()); - properties.insert("tokenSymbol".into(), "WOC".into()); - properties.insert("tokenDecimals".into(), 12.into()); - asset_hub_rococo_like_development_config( - properties, - "Wococo Asset Hub Development", - "asset-hub-wococo-dev", - 1000, - ) -} - -fn asset_hub_rococo_like_development_config( - properties: sc_chain_spec::Properties, - name: &str, - chain_id: &str, - para_id: u32, -) -> AssetHubRococoChainSpec { - #[allow(deprecated)] - AssetHubRococoChainSpec::from_genesis( - // Name - name, - // ID - chain_id, - ChainType::Local, - move || { - asset_hub_rococo_genesis( - // initial collators. - vec![( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - )], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - ], - para_id.into(), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: "rococo-dev".into(), para_id }, - asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - ) -} - -pub fn asset_hub_rococo_local_config() -> AssetHubRococoChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("ss58Format".into(), 42.into()); - properties.insert("tokenSymbol".into(), "ROC".into()); - properties.insert("tokenDecimals".into(), 12.into()); - asset_hub_rococo_like_local_config( - properties, - "Rococo Asset Hub Local", - "asset-hub-rococo-local", - 1000, - ) -} - -pub fn asset_hub_wococo_local_config() -> AssetHubWococoChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("ss58Format".into(), 42.into()); - properties.insert("tokenSymbol".into(), "WOC".into()); - properties.insert("tokenDecimals".into(), 12.into()); - asset_hub_rococo_like_local_config( - properties, - "Wococo Asset Hub Local", - "asset-hub-wococo-local", - 1000, - ) -} - -fn asset_hub_rococo_like_local_config( - properties: sc_chain_spec::Properties, - name: &str, - chain_id: &str, - para_id: u32, -) -> AssetHubRococoChainSpec { - #[allow(deprecated)] - AssetHubRococoChainSpec::from_genesis( - // Name - name, - // ID - chain_id, - ChainType::Local, - move || { - asset_hub_rococo_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - para_id.into(), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: "rococo-local".into(), para_id }, - asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - ) -} - -pub fn asset_hub_rococo_genesis_config() -> AssetHubRococoChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("tokenSymbol".into(), "ROC".into()); - properties.insert("tokenDecimals".into(), 12.into()); - let para_id = 1000; - #[allow(deprecated)] - AssetHubRococoChainSpec::from_genesis( - // Name - "Rococo Asset Hub", - // ID - "asset-hub-rococo", - ChainType::Live, - move || { - asset_hub_rococo_genesis( - // initial collators. - vec![ - // E8XC6rTJRsioKCp6KMy6zd24ykj4gWsusZ3AkSeyavpVBAG - ( - hex!("44cb62d1d6cdd2fff2a5ef3bb7ef827be5b3e117a394ecaa634d8dd9809d5608") - .into(), - hex!("44cb62d1d6cdd2fff2a5ef3bb7ef827be5b3e117a394ecaa634d8dd9809d5608") - .unchecked_into(), - ), - // G28iWEybndgGRbhfx83t7Q42YhMPByHpyqWDUgeyoGF94ri - ( - hex!("9864b85e23aa4506643db9879c3dbbeabaa94d269693a4447f537dd6b5893944") - .into(), - hex!("9864b85e23aa4506643db9879c3dbbeabaa94d269693a4447f537dd6b5893944") - .unchecked_into(), - ), - // G839e2eMiq7UXbConsY6DS1XDAYG2XnQxAmLuRLGGQ3Px9c - ( - hex!("9ce5741ee2f1ac3bdedbde9f3339048f4da2cb88ddf33a0977fa0b4cf86e2948") - .into(), - hex!("9ce5741ee2f1ac3bdedbde9f3339048f4da2cb88ddf33a0977fa0b4cf86e2948") - .unchecked_into(), - ), - // GLao4ukFUW6qhexuZowdFrKa2NLCfnEjZMftSXXfvGv1vvt - ( - hex!("a676ed15f5a325eab49ed8d5f8c00f3f814b19bb58cda14ad10894c078dd337f") - .into(), - hex!("a676ed15f5a325eab49ed8d5f8c00f3f814b19bb58cda14ad10894c078dd337f") - .unchecked_into(), - ), - ], - Vec::new(), - para_id.into(), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: "rococo".into(), para_id }, - asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - ) -} - -pub fn asset_hub_wococo_genesis_config() -> AssetHubWococoChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("ss58Format".into(), 42.into()); - properties.insert("tokenSymbol".into(), "WOC".into()); - properties.insert("tokenDecimals".into(), 12.into()); - let para_id = 1000; - #[allow(deprecated)] - AssetHubWococoChainSpec::from_genesis( - // Name - "Wococo Asset Hub", - // ID - "asset-hub-wococo", - ChainType::Live, - move || { - asset_hub_rococo_genesis( - // initial collators. - vec![ - // 5C8RGkS8t5K93fB2hkgKbvSYs5iG6AknJMuQmbBDeazon9Lj - ( - hex!("02d526f43cf27e94f478f9db785dc86052a77c695e7c855211839d3fde3ce534") - .into(), - hex!("02d526f43cf27e94f478f9db785dc86052a77c695e7c855211839d3fde3ce534") - .unchecked_into(), - ), - // 5GePeDZQeBagXH7kH5QPKnQKi39Z5hoYFB5FmUtEvc4yxKej - ( - hex!("caa1f623ca183296c4521b56cc29c484ca017830f8cb538f30f2d4664d631814") - .into(), - hex!("caa1f623ca183296c4521b56cc29c484ca017830f8cb538f30f2d4664d631814") - .unchecked_into(), - ), - // 5CfnTTb9NMJDNKDntA83mHKoedZ7wjDC8ypLCTDd4NwUx3zv - ( - hex!("1ac112d635db2bd34e79ae2b99486cf7c0b71a928668e4feb3dc4633d368f965") - .into(), - hex!("1ac112d635db2bd34e79ae2b99486cf7c0b71a928668e4feb3dc4633d368f965") - .unchecked_into(), - ), - // 5EqheiwiG22gvGpN7cvrbeaQzhg7rzsYYVkYK4yj5vRrTQRQ - ( - hex!("7ac9d11be07334cd27e9eb849f5fc7677a10ad36b6ab38b377d3c8b2c0b08b66") - .into(), - hex!("7ac9d11be07334cd27e9eb849f5fc7677a10ad36b6ab38b377d3c8b2c0b08b66") - .unchecked_into(), - ), - ], - Vec::new(), - para_id.into(), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: "wococo".into(), para_id }, - asset_hub_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - ) -} - -fn asset_hub_rococo_genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - id: ParaId, -) -> asset_hub_rococo_runtime::RuntimeGenesisConfig { - asset_hub_rococo_runtime::RuntimeGenesisConfig { - system: asset_hub_rococo_runtime::SystemConfig::default(), - balances: asset_hub_rococo_runtime::BalancesConfig { - balances: endowed_accounts - .iter() - .cloned() - .map(|k| (k, ASSET_HUB_ROCOCO_ED * 524_288)) - .collect(), - }, - parachain_info: asset_hub_rococo_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() - }, - collator_selection: asset_hub_rococo_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: ASSET_HUB_ROCOCO_ED * 16, - ..Default::default() - }, - session: asset_hub_rococo_runtime::SessionConfig { - keys: invulnerables - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - asset_hub_rococo_session_keys(aura), // session keys - ) - }) - .collect(), - }, - aura: Default::default(), - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: asset_hub_rococo_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, - } -} diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/bridge_hubs.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/bridge_hubs.rs deleted file mode 100644 index 05cec27c882a..000000000000 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/bridge_hubs.rs +++ /dev/null @@ -1,753 +0,0 @@ -// Copyright 2022 Parity Technologies (UK) Ltd. -// This file is part of Cumulus. - -// Cumulus 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. - -// Cumulus 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 Cumulus. If not, see . -// - -#![allow(dead_code)] - -use crate::chain_spec::{get_account_id_from_seed, get_collator_keys_from_seed}; -use cumulus_primitives_core::ParaId; -use parachains_common::Balance as BridgeHubBalance; -use sc_chain_spec::ChainSpec; -use sp_core::sr25519; -use std::{path::PathBuf, str::FromStr}; - -/// Collects all supported BridgeHub configurations -#[derive(Debug, PartialEq)] -pub enum BridgeHubRuntimeType { - Rococo, - RococoLocal, - // used by benchmarks - RococoDevelopment, - - Wococo, - WococoLocal, - - Kusama, - KusamaLocal, - // used by benchmarks - KusamaDevelopment, - - Polkadot, - PolkadotLocal, - // used by benchmarks - PolkadotDevelopment, - - // used with kusama runtime - Westend, -} - -impl FromStr for BridgeHubRuntimeType { - type Err = String; - - fn from_str(value: &str) -> Result { - match value { - polkadot::BRIDGE_HUB_POLKADOT => Ok(BridgeHubRuntimeType::Polkadot), - polkadot::BRIDGE_HUB_POLKADOT_LOCAL => Ok(BridgeHubRuntimeType::PolkadotLocal), - polkadot::BRIDGE_HUB_POLKADOT_DEVELOPMENT => - Ok(BridgeHubRuntimeType::PolkadotDevelopment), - kusama::BRIDGE_HUB_KUSAMA => Ok(BridgeHubRuntimeType::Kusama), - kusama::BRIDGE_HUB_KUSAMA_LOCAL => Ok(BridgeHubRuntimeType::KusamaLocal), - kusama::BRIDGE_HUB_KUSAMA_DEVELOPMENT => Ok(BridgeHubRuntimeType::KusamaDevelopment), - westend::BRIDGE_HUB_WESTEND => Ok(BridgeHubRuntimeType::Westend), - rococo::BRIDGE_HUB_ROCOCO => Ok(BridgeHubRuntimeType::Rococo), - rococo::BRIDGE_HUB_ROCOCO_LOCAL => Ok(BridgeHubRuntimeType::RococoLocal), - rococo::BRIDGE_HUB_ROCOCO_DEVELOPMENT => Ok(BridgeHubRuntimeType::RococoDevelopment), - wococo::BRIDGE_HUB_WOCOCO => Ok(BridgeHubRuntimeType::Wococo), - wococo::BRIDGE_HUB_WOCOCO_LOCAL => Ok(BridgeHubRuntimeType::WococoLocal), - _ => Err(format!("Value '{}' is not configured yet", value)), - } - } -} - -impl BridgeHubRuntimeType { - pub const ID_PREFIX: &'static str = "bridge-hub"; - - pub fn chain_spec_from_json_file(&self, path: PathBuf) -> Result, String> { - match self { - BridgeHubRuntimeType::Polkadot | - BridgeHubRuntimeType::PolkadotLocal | - BridgeHubRuntimeType::PolkadotDevelopment => - Ok(Box::new(polkadot::BridgeHubChainSpec::from_json_file(path)?)), - BridgeHubRuntimeType::Kusama | - BridgeHubRuntimeType::KusamaLocal | - BridgeHubRuntimeType::KusamaDevelopment => - Ok(Box::new(kusama::BridgeHubChainSpec::from_json_file(path)?)), - BridgeHubRuntimeType::Westend => - Ok(Box::new(westend::BridgeHubChainSpec::from_json_file(path)?)), - BridgeHubRuntimeType::Rococo | - BridgeHubRuntimeType::RococoLocal | - BridgeHubRuntimeType::RococoDevelopment => - Ok(Box::new(rococo::BridgeHubChainSpec::from_json_file(path)?)), - BridgeHubRuntimeType::Wococo | BridgeHubRuntimeType::WococoLocal => - Ok(Box::new(wococo::BridgeHubChainSpec::from_json_file(path)?)), - } - } - - pub fn load_config(&self) -> Result, String> { - match self { - BridgeHubRuntimeType::Polkadot => - Ok(Box::new(polkadot::BridgeHubChainSpec::from_json_bytes( - &include_bytes!("../../../parachains/chain-specs/bridge-hub-polkadot.json")[..], - )?)), - BridgeHubRuntimeType::PolkadotLocal => Ok(Box::new(polkadot::local_config( - polkadot::BRIDGE_HUB_POLKADOT_LOCAL, - "Polkadot BridgeHub Local", - "polkadot-local", - ParaId::new(1002), - ))), - BridgeHubRuntimeType::PolkadotDevelopment => Ok(Box::new(polkadot::local_config( - polkadot::BRIDGE_HUB_POLKADOT_DEVELOPMENT, - "Polkadot BridgeHub Development", - "polkadot-dev", - ParaId::new(1002), - ))), - BridgeHubRuntimeType::Kusama => - Ok(Box::new(kusama::BridgeHubChainSpec::from_json_bytes( - &include_bytes!("../../../parachains/chain-specs/bridge-hub-kusama.json")[..], - )?)), - BridgeHubRuntimeType::KusamaLocal => Ok(Box::new(kusama::local_config( - kusama::BRIDGE_HUB_KUSAMA_LOCAL, - "Kusama BridgeHub Local", - "kusama-local", - ParaId::new(1003), - ))), - BridgeHubRuntimeType::KusamaDevelopment => Ok(Box::new(kusama::local_config( - kusama::BRIDGE_HUB_KUSAMA_DEVELOPMENT, - "Kusama BridgeHub Development", - "kusama-dev", - ParaId::new(1003), - ))), - BridgeHubRuntimeType::Westend => - Ok(Box::new(westend::BridgeHubChainSpec::from_json_bytes( - &include_bytes!("../../../parachains/chain-specs/bridge-hub-westend.json")[..], - )?)), - BridgeHubRuntimeType::Rococo => - Ok(Box::new(rococo::BridgeHubChainSpec::from_json_bytes( - &include_bytes!("../../../parachains/chain-specs/bridge-hub-rococo.json")[..], - )?)), - BridgeHubRuntimeType::RococoLocal => Ok(Box::new(rococo::local_config( - rococo::BRIDGE_HUB_ROCOCO_LOCAL, - "Rococo BridgeHub Local", - "rococo-local", - ParaId::new(1013), - Some("Bob".to_string()), - |_| (), - ))), - BridgeHubRuntimeType::RococoDevelopment => Ok(Box::new(rococo::local_config( - rococo::BRIDGE_HUB_ROCOCO_DEVELOPMENT, - "Rococo BridgeHub Development", - "rococo-dev", - ParaId::new(1013), - Some("Bob".to_string()), - |_| (), - ))), - BridgeHubRuntimeType::Wococo => - Ok(Box::new(wococo::BridgeHubChainSpec::from_json_bytes( - &include_bytes!("../../../parachains/chain-specs/bridge-hub-wococo.json")[..], - )?)), - BridgeHubRuntimeType::WococoLocal => Ok(Box::new(wococo::local_config( - wococo::BRIDGE_HUB_WOCOCO_LOCAL, - "Wococo BridgeHub Local", - "wococo-local", - ParaId::new(1014), - Some("Bob".to_string()), - ))), - } - } -} - -/// Check if 'id' satisfy BridgeHub-like format -fn ensure_id(id: &str) -> Result<&str, String> { - if id.starts_with(BridgeHubRuntimeType::ID_PREFIX) { - Ok(id) - } else { - Err(format!( - "Invalid 'id' attribute ({}), should start with prefix: {}", - id, - BridgeHubRuntimeType::ID_PREFIX - )) - } -} - -/// Sub-module for Rococo setup -pub mod rococo { - use super::{get_account_id_from_seed, get_collator_keys_from_seed, sr25519, ParaId}; - use crate::legacy_chain_spec::{Extensions, SAFE_XCM_VERSION}; - use parachains_common::{AccountId, AuraId}; - use sc_chain_spec::ChainType; - - use super::BridgeHubBalance; - - pub(crate) const BRIDGE_HUB_ROCOCO: &str = "bridge-hub-rococo"; - pub(crate) const BRIDGE_HUB_ROCOCO_LOCAL: &str = "bridge-hub-rococo-local"; - pub(crate) const BRIDGE_HUB_ROCOCO_DEVELOPMENT: &str = "bridge-hub-rococo-dev"; - const BRIDGE_HUB_ROCOCO_ED: BridgeHubBalance = - parachains_common::rococo::currency::EXISTENTIAL_DEPOSIT; - - /// Specialized `ChainSpec` for the normal parachain runtime. - pub type BridgeHubChainSpec = - sc_service::GenericChainSpec; - - pub type RuntimeApi = bridge_hub_rococo_runtime::RuntimeApi; - - pub fn local_config( - id: &str, - chain_name: &str, - relay_chain: &str, - para_id: ParaId, - bridges_pallet_owner_seed: Option, - modify_props: ModifyProperties, - ) -> BridgeHubChainSpec { - // Rococo defaults - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("ss58Format".into(), 42.into()); - properties.insert("tokenSymbol".into(), "ROC".into()); - properties.insert("tokenDecimals".into(), 12.into()); - modify_props(&mut properties); - - #[allow(deprecated)] - BridgeHubChainSpec::from_genesis( - // Name - chain_name, - // ID - super::ensure_id(id).expect("invalid id"), - ChainType::Local, - move || { - genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - para_id, - bridges_pallet_owner_seed - .as_ref() - .map(|seed| get_account_id_from_seed::(seed)), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, - bridge_hub_rococo_runtime::WASM_BINARY - .expect("WASM binary was not built, please build it!"), - ) - } - - fn genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - id: ParaId, - bridges_pallet_owner: Option, - ) -> bridge_hub_rococo_runtime::RuntimeGenesisConfig { - bridge_hub_rococo_runtime::RuntimeGenesisConfig { - system: bridge_hub_rococo_runtime::SystemConfig::default(), - balances: bridge_hub_rococo_runtime::BalancesConfig { - balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), - }, - parachain_info: bridge_hub_rococo_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() - }, - collator_selection: bridge_hub_rococo_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: BRIDGE_HUB_ROCOCO_ED * 16, - ..Default::default() - }, - session: bridge_hub_rococo_runtime::SessionConfig { - keys: invulnerables - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - bridge_hub_rococo_runtime::SessionKeys { aura }, // session keys - ) - }) - .collect(), - }, - aura: Default::default(), - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: bridge_hub_rococo_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, - bridge_wococo_grandpa: bridge_hub_rococo_runtime::BridgeWococoGrandpaConfig { - owner: bridges_pallet_owner.clone(), - ..Default::default() - }, - bridge_westend_grandpa: bridge_hub_rococo_runtime::BridgeWestendGrandpaConfig { - owner: bridges_pallet_owner.clone(), - ..Default::default() - }, - bridge_rococo_grandpa: bridge_hub_rococo_runtime::BridgeRococoGrandpaConfig { - owner: bridges_pallet_owner.clone(), - ..Default::default() - }, - bridge_rococo_messages: bridge_hub_rococo_runtime::BridgeRococoMessagesConfig { - owner: bridges_pallet_owner.clone(), - ..Default::default() - }, - bridge_wococo_messages: bridge_hub_rococo_runtime::BridgeWococoMessagesConfig { - owner: bridges_pallet_owner.clone(), - ..Default::default() - }, - bridge_westend_messages: bridge_hub_rococo_runtime::BridgeWestendMessagesConfig { - owner: bridges_pallet_owner.clone(), - ..Default::default() - }, - } - } -} - -/// Sub-module for Wococo setup (reuses stuff from Rococo) -pub mod wococo { - use super::ParaId; - use crate::chain_spec::bridge_hubs::rococo; - - pub(crate) const BRIDGE_HUB_WOCOCO: &str = "bridge-hub-wococo"; - pub(crate) const BRIDGE_HUB_WOCOCO_LOCAL: &str = "bridge-hub-wococo-local"; - - pub type BridgeHubChainSpec = rococo::BridgeHubChainSpec; - pub type RuntimeApi = rococo::RuntimeApi; - - pub fn local_config( - id: &str, - chain_name: &str, - relay_chain: &str, - para_id: ParaId, - bridges_pallet_owner_seed: Option, - ) -> BridgeHubChainSpec { - rococo::local_config( - id, - chain_name, - relay_chain, - para_id, - bridges_pallet_owner_seed, - |properties| { - properties.insert("tokenSymbol".into(), "WOOK".into()); - }, - ) - } -} - -/// Sub-module for Kusama setup -pub mod kusama { - use super::{BridgeHubBalance, ParaId}; - use crate::legacy_chain_spec::{ - get_account_id_from_seed, get_collator_keys_from_seed, Extensions, SAFE_XCM_VERSION, - }; - use parachains_common::{AccountId, AuraId}; - use sc_chain_spec::ChainType; - use sp_core::sr25519; - - pub(crate) const BRIDGE_HUB_KUSAMA: &str = "bridge-hub-kusama"; - pub(crate) const BRIDGE_HUB_KUSAMA_LOCAL: &str = "bridge-hub-kusama-local"; - pub(crate) const BRIDGE_HUB_KUSAMA_DEVELOPMENT: &str = "bridge-hub-kusama-dev"; - const BRIDGE_HUB_KUSAMA_ED: BridgeHubBalance = - parachains_common::kusama::currency::EXISTENTIAL_DEPOSIT; - - /// Specialized `ChainSpec` for the normal parachain runtime. - pub type BridgeHubChainSpec = - sc_service::GenericChainSpec; - pub type RuntimeApi = bridge_hub_kusama_runtime::RuntimeApi; - - pub fn local_config( - id: &str, - chain_name: &str, - relay_chain: &str, - para_id: ParaId, - ) -> BridgeHubChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("ss58Format".into(), 2.into()); - properties.insert("tokenSymbol".into(), "KSM".into()); - properties.insert("tokenDecimals".into(), 12.into()); - - #[allow(deprecated)] - BridgeHubChainSpec::from_genesis( - // Name - chain_name, - // ID - super::ensure_id(id).expect("invalid id"), - ChainType::Local, - move || { - genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - para_id, - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, - bridge_hub_kusama_runtime::WASM_BINARY - .expect("WASM binary was not built, please build it!"), - ) - } - - fn genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - id: ParaId, - ) -> bridge_hub_kusama_runtime::RuntimeGenesisConfig { - bridge_hub_kusama_runtime::RuntimeGenesisConfig { - system: bridge_hub_kusama_runtime::SystemConfig::default(), - balances: bridge_hub_kusama_runtime::BalancesConfig { - balances: endowed_accounts - .iter() - .cloned() - .map(|k| (k, BRIDGE_HUB_KUSAMA_ED * 524_288)) - .collect(), - }, - parachain_info: bridge_hub_kusama_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() - }, - collator_selection: 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_runtime::SessionKeys { aura }, // session keys - ) - }) - .collect(), - }, - aura: Default::default(), - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: bridge_hub_kusama_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, - } - } -} - -/// Sub-module for Westend setup. -pub mod westend { - use super::{get_account_id_from_seed, get_collator_keys_from_seed, sr25519, ParaId}; - use crate::legacy_chain_spec::{Extensions, SAFE_XCM_VERSION}; - use parachains_common::{AccountId, AuraId}; - use sc_chain_spec::ChainType; - - use super::BridgeHubBalance; - - pub(crate) const BRIDGE_HUB_WESTEND: &str = "bridge-hub-westend"; - pub(crate) const BRIDGE_HUB_WESTEND_LOCAL: &str = "bridge-hub-westend-local"; - pub(crate) const BRIDGE_HUB_WESTEND_DEVELOPMENT: &str = "bridge-hub-westend-dev"; - const BRIDGE_HUB_WESTEND_ED: BridgeHubBalance = - parachains_common::westend::currency::EXISTENTIAL_DEPOSIT; - - /// Specialized `ChainSpec` for the normal parachain runtime. - pub type BridgeHubChainSpec = - sc_service::GenericChainSpec; - pub type RuntimeApi = bridge_hub_westend_runtime::RuntimeApi; - - pub fn local_config( - id: &str, - chain_name: &str, - relay_chain: &str, - para_id: ParaId, - bridges_pallet_owner_seed: Option, - ) -> BridgeHubChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("tokenSymbol".into(), "WND".into()); - properties.insert("tokenDecimals".into(), 12.into()); - - #[allow(deprecated)] - BridgeHubChainSpec::from_genesis( - // Name - chain_name, - // ID - super::ensure_id(id).expect("invalid id"), - ChainType::Local, - move || { - genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - para_id, - bridges_pallet_owner_seed - .as_ref() - .map(|seed| get_account_id_from_seed::(seed)), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, - bridge_hub_westend_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!"), - ) - } - - fn genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - id: ParaId, - bridges_pallet_owner: Option, - ) -> bridge_hub_westend_runtime::RuntimeGenesisConfig { - bridge_hub_westend_runtime::RuntimeGenesisConfig { - system: bridge_hub_westend_runtime::SystemConfig::default(), - balances: bridge_hub_westend_runtime::BalancesConfig { - balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), - }, - parachain_info: bridge_hub_westend_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() - }, - collator_selection: bridge_hub_westend_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: BRIDGE_HUB_WESTEND_ED * 16, - ..Default::default() - }, - session: bridge_hub_westend_runtime::SessionConfig { - keys: invulnerables - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - bridge_hub_westend_runtime::SessionKeys { aura }, // session keys - ) - }) - .collect(), - }, - aura: Default::default(), - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: bridge_hub_westend_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, - bridge_rococo_grandpa: bridge_hub_westend_runtime::BridgeRococoGrandpaConfig { - owner: bridges_pallet_owner.clone(), - ..Default::default() - }, - bridge_rococo_messages: bridge_hub_westend_runtime::BridgeRococoMessagesConfig { - owner: bridges_pallet_owner.clone(), - ..Default::default() - }, - } - } -} - -/// Sub-module for Polkadot setup -pub mod polkadot { - use super::{BridgeHubBalance, ParaId}; - use crate::legacy_chain_spec::{ - get_account_id_from_seed, get_collator_keys_from_seed, Extensions, SAFE_XCM_VERSION, - }; - use parachains_common::{AccountId, AuraId}; - use sc_chain_spec::ChainType; - use sp_core::sr25519; - - pub(crate) const BRIDGE_HUB_POLKADOT: &str = "bridge-hub-polkadot"; - pub(crate) const BRIDGE_HUB_POLKADOT_LOCAL: &str = "bridge-hub-polkadot-local"; - pub(crate) const BRIDGE_HUB_POLKADOT_DEVELOPMENT: &str = "bridge-hub-polkadot-dev"; - const BRIDGE_HUB_POLKADOT_ED: BridgeHubBalance = - parachains_common::polkadot::currency::EXISTENTIAL_DEPOSIT; - - /// Specialized `ChainSpec` for the normal parachain runtime. - pub type BridgeHubChainSpec = - sc_service::GenericChainSpec; - pub type RuntimeApi = bridge_hub_polkadot_runtime::RuntimeApi; - - pub fn local_config( - id: &str, - chain_name: &str, - relay_chain: &str, - para_id: ParaId, - ) -> BridgeHubChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("ss58Format".into(), 0.into()); - properties.insert("tokenSymbol".into(), "DOT".into()); - properties.insert("tokenDecimals".into(), 10.into()); - - #[allow(deprecated)] - BridgeHubChainSpec::from_genesis( - // Name - chain_name, - // ID - super::ensure_id(id).expect("invalid id"), - ChainType::Local, - move || { - genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - para_id, - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: relay_chain.to_string(), para_id: para_id.into() }, - bridge_hub_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not built, please build it!"), - ) - } - - fn genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - id: ParaId, - ) -> bridge_hub_polkadot_runtime::RuntimeGenesisConfig { - bridge_hub_polkadot_runtime::RuntimeGenesisConfig { - system: bridge_hub_polkadot_runtime::SystemConfig::default(), - balances: bridge_hub_polkadot_runtime::BalancesConfig { - balances: endowed_accounts - .iter() - .cloned() - .map(|k| (k, BRIDGE_HUB_POLKADOT_ED * 4096)) - .collect(), - }, - parachain_info: bridge_hub_polkadot_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() - }, - collator_selection: 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_runtime::SessionKeys { aura }, // session keys - ) - }) - .collect(), - }, - aura: Default::default(), - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: bridge_hub_polkadot_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, - } - } -} diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/collectives.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/collectives.rs deleted file mode 100644 index a064a742d208..000000000000 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/collectives.rs +++ /dev/null @@ -1,184 +0,0 @@ -// Copyright 2022 Parity Technologies (UK) Ltd. -// This file is part of Cumulus. - -// Cumulus 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. - -// Cumulus 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 Cumulus. If not, see . - -use crate::legacy_chain_spec::{ - get_account_id_from_seed, get_collator_keys_from_seed, Extensions, SAFE_XCM_VERSION, -}; -use cumulus_primitives_core::ParaId; -use parachains_common::{AccountId, AuraId, Balance as CollectivesBalance}; -use sc_service::ChainType; -use sp_core::sr25519; - -pub type CollectivesPolkadotChainSpec = - sc_service::GenericChainSpec; - -const COLLECTIVES_POLKADOT_ED: CollectivesBalance = - parachains_common::polkadot::currency::EXISTENTIAL_DEPOSIT; - -/// 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 } -} - -pub fn collectives_polkadot_development_config() -> CollectivesPolkadotChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("ss58Format".into(), 0.into()); - properties.insert("tokenSymbol".into(), "DOT".into()); - properties.insert("tokenDecimals".into(), 10.into()); - - #[allow(deprecated)] - CollectivesPolkadotChainSpec::from_genesis( - // Name - "Polkadot Collectives Development", - // ID - "collectives_polkadot_dev", - ChainType::Local, - move || { - collectives_polkadot_genesis( - // initial collators. - vec![( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - )], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - ], - // 1002 avoids a potential collision with Kusama-1001 (Encointer) should there ever - // be a collective para on Kusama. - 1002.into(), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: "polkadot-dev".into(), para_id: 1002 }, - collectives_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not built, please build it!"), - ) -} - -/// Collectives Polkadot Local Config. -pub fn collectives_polkadot_local_config() -> CollectivesPolkadotChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("ss58Format".into(), 0.into()); - properties.insert("tokenSymbol".into(), "DOT".into()); - properties.insert("tokenDecimals".into(), 10.into()); - - #[allow(deprecated)] - CollectivesPolkadotChainSpec::from_genesis( - // Name - "Polkadot Collectives Local", - // ID - "collectives_polkadot_local", - ChainType::Local, - move || { - collectives_polkadot_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - 1002.into(), - ) - }, - Vec::new(), - None, - None, - None, - Some(properties), - Extensions { relay_chain: "polkadot-local".into(), para_id: 1002 }, - collectives_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not built, please build it!"), - ) -} - -fn collectives_polkadot_genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - id: ParaId, -) -> collectives_polkadot_runtime::RuntimeGenesisConfig { - collectives_polkadot_runtime::RuntimeGenesisConfig { - system: collectives_polkadot_runtime::SystemConfig::default(), - balances: collectives_polkadot_runtime::BalancesConfig { - balances: endowed_accounts - .iter() - .cloned() - .map(|k| (k, COLLECTIVES_POLKADOT_ED * 4096)) - .collect(), - }, - parachain_info: collectives_polkadot_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() - }, - collator_selection: 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(), - }, - // no need to pass anything to aura, in fact it will panic if we do. Session will take care - // of this. - aura: Default::default(), - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: collectives_polkadot_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, - alliance: Default::default(), - alliance_motion: Default::default(), - } -} diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/contracts.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/contracts.rs deleted file mode 100644 index cbb3b5fe42ed..000000000000 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/contracts.rs +++ /dev/null @@ -1,287 +0,0 @@ -// Copyright 2019-2021 Parity Technologies (UK) Ltd. -// This file is part of Cumulus. - -// Cumulus 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. - -// Cumulus 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 Cumulus. If not, see . - -use crate::legacy_chain_spec::{ - get_account_id_from_seed, get_collator_keys_from_seed, Extensions, SAFE_XCM_VERSION, -}; -use cumulus_primitives_core::ParaId; -use hex_literal::hex; -use parachains_common::{AccountId, AuraId}; -use sc_service::ChainType; -use sp_core::{crypto::UncheckedInto, sr25519}; - -pub type ContractsRococoChainSpec = - sc_service::GenericChainSpec; - -/// No relay chain suffix because the id is the same over all relay chains. -const CONTRACTS_PARACHAIN_ID: u32 = 1002; - -/// The existential deposit is determined by the runtime "contracts-rococo". -const CONTRACTS_ROCOCO_ED: contracts_rococo_runtime::Balance = - parachains_common::rococo::currency::EXISTENTIAL_DEPOSIT; - -pub fn contracts_rococo_development_config() -> ContractsRococoChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("tokenSymbol".into(), "ROC".into()); - properties.insert("tokenDecimals".into(), 12.into()); - - #[allow(deprecated)] - ContractsRococoChainSpec::from_genesis( - // Name - "Contracts on Rococo Development", - // ID - "contracts-rococo-dev", - ChainType::Development, - move || { - contracts_rococo_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - CONTRACTS_PARACHAIN_ID.into(), - ) - }, - Vec::new(), - None, - None, - None, - None, - Extensions { - relay_chain: "rococo-local".into(), // You MUST set this to the correct network! - para_id: CONTRACTS_PARACHAIN_ID, - }, - contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - ) -} - -pub fn contracts_rococo_local_config() -> ContractsRococoChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("tokenSymbol".into(), "ROC".into()); - properties.insert("tokenDecimals".into(), 12.into()); - - #[allow(deprecated)] - ContractsRococoChainSpec::from_genesis( - // Name - "Contracts on Rococo", - // ID - "contracts-rococo-local", - ChainType::Local, - move || { - contracts_rococo_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - CONTRACTS_PARACHAIN_ID.into(), - ) - }, - // Bootnodes - Vec::new(), - // Telemetry - None, - // Protocol ID - None, - // Fork ID - None, - // Properties - Some(properties), - // Extensions - Extensions { - relay_chain: "rococo-local".into(), // You MUST set this to the correct network! - para_id: CONTRACTS_PARACHAIN_ID, - }, - // Code - contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - ) -} - -pub fn contracts_rococo_config() -> ContractsRococoChainSpec { - // Give your base currency a unit name and decimal places - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("tokenSymbol".into(), "ROC".into()); - properties.insert("tokenDecimals".into(), 12.into()); - - #[allow(deprecated)] - ContractsRococoChainSpec::from_genesis( - // Name - "Contracts on Rococo", - // ID - "contracts-rococo", - ChainType::Live, - move || { - contracts_rococo_genesis( - vec![ - // 5GKFbTTgrVS4Vz1UWWHPqMZQNFWZtqo7H2KpCDyYhEL3aS26 - ( - hex!["bc09354c12c054c8f6b3da208485eacec4ac648bad348895273b37bab5a0937c"] - .into(), - hex!["bc09354c12c054c8f6b3da208485eacec4ac648bad348895273b37bab5a0937c"] - .unchecked_into(), - ), - // 5EPRJHm2GpABVWcwnAujcrhnrjFZyDGd5TwKFzkBoGgdRyv2 - ( - hex!["66be63b7bcbfb91040e5248e2d1ceb822cf219c57848c5924ffa3a1f8e67ba72"] - .into(), - hex!["66be63b7bcbfb91040e5248e2d1ceb822cf219c57848c5924ffa3a1f8e67ba72"] - .unchecked_into(), - ), - // 5GH62vrJrVZxLREcHzm2PR5uTLAT5RQMJitoztCGyaP4o3uM - ( - hex!["ba62886472a0a9f66b5e39f1469ce1c5b3d8cad6be39078daf16f111e89d1e44"] - .into(), - hex!["ba62886472a0a9f66b5e39f1469ce1c5b3d8cad6be39078daf16f111e89d1e44"] - .unchecked_into(), - ), - // 5FHfoJDLdjRYX5KXLRqMDYBbWrwHLMtti21uK4QByUoUAbJF - ( - hex!["8e97f65cda001976311df9bed39e8d0c956089093e94a75ef76fe9347a0eda7b"] - .into(), - hex!["8e97f65cda001976311df9bed39e8d0c956089093e94a75ef76fe9347a0eda7b"] - .unchecked_into(), - ), - ], - // Warning: The configuration for a production chain should not contain - // any endowed accounts here, otherwise it'll be minting extra native tokens - // from the relay chain on the parachain. - vec![ - // NOTE: Remove endowed accounts if deployed on other relay chains. - // Endowed accounts - hex!["baa78c7154c7f82d6d377177e20bcab65d327eca0086513f9964f5a0f6bdad56"].into(), - // AccountId of an account which `ink-waterfall` uses for automated testing - hex!["0e47e2344d523c3cc5c34394b0d58b9a4200e813a038e6c5a6163cc07d70b069"].into(), - ], - CONTRACTS_PARACHAIN_ID.into(), - ) - }, - // Bootnodes - vec![ - "/dns/contracts-collator-0.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWKg3Rpxcr9oJ8n6khoxpGKWztCZydtUZk2cojHqnfLrpj" - .parse() - .expect("MultiaddrWithPeerId"), - "/dns/contracts-collator-1.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWPEXYrz8tHU3nDtPoPw4V7ou5dzMEWSTuUj7vaWiYVAVh" - .parse() - .expect("MultiaddrWithPeerId"), - "/dns/contracts-collator-2.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWEVU8AFNary4nP4qEnEcwJaRuy59Wefekzdu9pKbnVEhk" - .parse() - .expect("MultiaddrWithPeerId"), - "/dns/contracts-collator-3.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWP6pV3ZmcXzGDjv8ZMgA6nZxfAKDxSz4VNiLx6vVCQgJX" - .parse() - .expect("MultiaddrWithPeerId"), - ], - // Telemetry - None, - // Protocol ID - None, - // Fork ID - None, - // Properties - Some(properties), - // Extensions - Extensions { relay_chain: "rococo".into(), para_id: CONTRACTS_PARACHAIN_ID }, - // Code - contracts_rococo_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - ) -} - -fn contracts_rococo_genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - id: ParaId, -) -> contracts_rococo_runtime::RuntimeGenesisConfig { - contracts_rococo_runtime::RuntimeGenesisConfig { - system: contracts_rococo_runtime::SystemConfig::default(), - balances: contracts_rococo_runtime::BalancesConfig { - balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), - }, - parachain_info: contracts_rococo_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() - }, - collator_selection: contracts_rococo_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: CONTRACTS_ROCOCO_ED * 16, - ..Default::default() - }, - session: contracts_rococo_runtime::SessionConfig { - keys: invulnerables - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - contracts_rococo_runtime::SessionKeys { aura }, // session keys - ) - }) - .collect(), - }, - // no need to pass anything to aura, in fact it will panic if we do. Session will take care - // of this. - aura: Default::default(), - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: contracts_rococo_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, - sudo: contracts_rococo_runtime::SudoConfig { - key: Some( - hex!["2681a28014e7d3a5bfb32a003b3571f53c408acbc28d351d6bf58f5028c4ef14"].into(), - ), - }, - } -} diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/glutton.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/glutton.rs deleted file mode 100644 index d5379e86e1c0..000000000000 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/glutton.rs +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Cumulus. - -// Cumulus 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. - -// Cumulus 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 Cumulus. If not, see . - -use crate::chain_spec::{get_account_id_from_seed, Extensions}; -use cumulus_primitives_core::ParaId; -use parachains_common::AuraId; -use sc_service::ChainType; -use sp_core::sr25519; - -use super::get_collator_keys_from_seed; - -/// Specialized `ChainSpec` for the Glutton parachain runtime. -pub type GluttonChainSpec = - sc_service::GenericChainSpec; - -pub fn glutton_development_config(para_id: ParaId) -> GluttonChainSpec { - #[allow(deprecated)] - GluttonChainSpec::from_genesis( - // Name - "Glutton Development", - // ID - "glutton_dev", - ChainType::Local, - move || glutton_genesis(para_id, vec![get_collator_keys_from_seed::("Alice")]), - Vec::new(), - None, - None, - None, - None, - Extensions { relay_chain: "kusama-dev".into(), para_id: para_id.into() }, - glutton_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - ) -} - -pub fn glutton_local_config(para_id: ParaId) -> GluttonChainSpec { - #[allow(deprecated)] - GluttonChainSpec::from_genesis( - // Name - "Glutton Local", - // ID - "glutton_local", - ChainType::Local, - move || { - glutton_genesis( - para_id, - vec![ - get_collator_keys_from_seed::("Alice"), - get_collator_keys_from_seed::("Bob"), - ], - ) - }, - Vec::new(), - None, - None, - None, - None, - Extensions { relay_chain: "kusama-local".into(), para_id: para_id.into() }, - glutton_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - ) -} - -pub fn glutton_config(para_id: ParaId) -> GluttonChainSpec { - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("ss58Format".into(), 2.into()); - - #[allow(deprecated)] - GluttonChainSpec::from_genesis( - // Name - format!("Glutton {}", para_id).as_str(), - // ID - format!("glutton-kusama-{}", para_id).as_str(), - ChainType::Live, - move || { - glutton_genesis( - para_id, - vec![ - get_collator_keys_from_seed::("Alice"), - get_collator_keys_from_seed::("Bob"), - ], - ) - }, - Vec::new(), - None, - // Protocol ID - Some(format!("glutton-kusama-{}", para_id).as_str()), - None, - Some(properties), - Extensions { relay_chain: "kusama".into(), para_id: para_id.into() }, - glutton_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - ) -} - -fn glutton_genesis( - parachain_id: ParaId, - collators: Vec, -) -> glutton_runtime::RuntimeGenesisConfig { - glutton_runtime::RuntimeGenesisConfig { - system: glutton_runtime::SystemConfig::default(), - parachain_info: glutton_runtime::ParachainInfoConfig { parachain_id, ..Default::default() }, - parachain_system: Default::default(), - glutton: glutton_runtime::GluttonConfig { - compute: Default::default(), - storage: Default::default(), - trash_data_count: Default::default(), - ..Default::default() - }, - aura: glutton_runtime::AuraConfig { authorities: collators }, - aura_ext: Default::default(), - sudo: glutton_runtime::SudoConfig { - key: Some(get_account_id_from_seed::("Alice")), - }, - } -} diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/json_vs_legacy_tests.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/json_vs_legacy_tests.rs deleted file mode 100644 index d76b6a28979e..000000000000 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/json_vs_legacy_tests.rs +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright 2023 Parity Technologies (UK) Ltd. -// This file is part of Cumulus. - -// Cumulus 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. - -// Cumulus 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 Cumulus. If not, see . - -//! Tests for verifying if raw ChainSpecs generated using legacy RuntimeGenesisConfig based approach -//! are identical to ChainSpec generated using JSON approach. -//! Entire file shall be removed once native runtime is removed. - -macro_rules! test { - ($test_name:ident, $tested_fn:expr) => { - #[test] - fn $test_name() { - sp_tracing::try_init_simple(); - let j1 = { - use crate::chain_spec::*; - $tested_fn.as_json(true).unwrap() - }; - let j2 = { - use crate::legacy_chain_spec::*; - $tested_fn.as_json(true).unwrap() - }; - assert_eq!(j1, j2); - } - }; -} - -test!(test00, asset_hubs::asset_hub_polkadot_development_config()); -test!(test01, asset_hubs::asset_hub_polkadot_local_config()); -test!(test02, asset_hubs::asset_hub_polkadot_config()); -test!(test03, asset_hubs::asset_hub_kusama_development_config()); -test!(test04, asset_hubs::asset_hub_kusama_local_config()); -test!(test05, asset_hubs::asset_hub_kusama_config()); -test!(test06, asset_hubs::asset_hub_westend_development_config()); -test!(test07, asset_hubs::asset_hub_westend_local_config()); -test!(test08, asset_hubs::asset_hub_westend_config()); -test!(test09, asset_hubs::asset_hub_rococo_development_config()); -test!(test10, asset_hubs::asset_hub_wococo_development_config()); -test!(test11, asset_hubs::asset_hub_rococo_local_config()); -test!(test12, asset_hubs::asset_hub_wococo_local_config()); -test!(test13, asset_hubs::asset_hub_rococo_genesis_config()); -test!(test14, asset_hubs::asset_hub_wococo_genesis_config()); -test!(test15, collectives::collectives_polkadot_development_config()); -test!(test16, collectives::collectives_polkadot_local_config()); -test!(test17, contracts::contracts_rococo_development_config()); -test!(test18, contracts::contracts_rococo_local_config()); -test!(test19, contracts::contracts_rococo_config()); -test!(test20, glutton::glutton_development_config(667.into())); -test!(test21, glutton::glutton_local_config(667.into())); -test!(test22, glutton::glutton_config(667.into())); -test!(test23, penpal::get_penpal_chain_spec(667.into(), "test")); -test!(test24, rococo_parachain::rococo_parachain_local_config()); -test!(test25, rococo_parachain::staging_rococo_parachain_local_config()); -test!(test26, seedling::get_seedling_chain_spec()); -test!(test27, shell::get_shell_chain_spec()); -test!( - test28, - bridge_hubs::rococo::local_config( - "bridge-hub-rococo-local", - "Test", - "test", - 667.into(), - Some("Bob".to_string()), - |_| {} - ) -); -test!( - test29, - bridge_hubs::wococo::local_config( - "bridge-hub-wococo-local", - "Test", - "test", - 667.into(), - Some("Bob".to_string()) - ) -); -test!( - test30, - bridge_hubs::kusama::local_config("bridge-hub-kusama-local", "Test", "test", 667.into()) -); -test!( - test31, - bridge_hubs::polkadot::local_config("bridge-hub-polkadot-local", "Test", "test", 667.into()) -); - -test!( - test32, - bridge_hubs::westend::local_config( - "bridge-hub-westend-local", - "Test", - "test", - 664.into(), - Some("Alice".to_string()) - ) -); diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/mod.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/mod.rs deleted file mode 100644 index 14d55663ad20..000000000000 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/mod.rs +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2019-2021 Parity Technologies (UK) Ltd. -// This file is part of Cumulus. - -// Cumulus 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. - -// Cumulus 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 Cumulus. If not, see . - -//! RuntimeGenesisConfig-based (legacy) polkadot-parachain ChainSpec configurations. Used for -//! testing ChainSpecs against the JSON-based genesis configs. Entire file shall be removed once -//! native runtime is removed. This is just a verbatim copy of chain_spec mod. - -#![allow(dead_code)] - -use parachains_common::{AccountId, Signature}; -use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup}; -use serde::{Deserialize, Serialize}; -use sp_core::{Pair, Public}; -use sp_runtime::traits::{IdentifyAccount, Verify}; - -pub mod asset_hubs; -pub mod bridge_hubs; -pub mod collectives; -pub mod contracts; -pub mod glutton; -pub mod penpal; -pub mod rococo_parachain; -pub mod seedling; -pub mod shell; - -#[cfg(test)] -mod json_vs_legacy_tests; - -/// The default XCM version to set in genesis config. -const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; - -/// Generic extensions for Parachain ChainSpecs. -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)] -#[serde(deny_unknown_fields)] -pub struct Extensions { - /// The relay chain of the Parachain. - pub relay_chain: String, - /// The id of the Parachain. - pub para_id: u32, -} - -impl Extensions { - /// Try to get the extension from the given `ChainSpec`. - pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> { - sc_chain_spec::get_extension(chain_spec.extensions()) - } -} - -/// Helper function to generate a crypto pair from seed -pub fn get_from_seed(seed: &str) -> ::Public { - TPublic::Pair::from_string(&format!("//{}", seed), None) - .expect("static values are valid; qed") - .public() -} - -type AccountPublic = ::Signer; - -/// Helper function to generate an account ID from seed -pub fn get_account_id_from_seed(seed: &str) -> AccountId -where - AccountPublic: From<::Public>, -{ - AccountPublic::from(get_from_seed::(seed)).into_account() -} - -/// Generate collator keys from seed. -/// -/// This function's return type must always match the session keys of the chain in tuple format. -pub fn get_collator_keys_from_seed(seed: &str) -> ::Public { - get_from_seed::(seed) -} diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/penpal.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/penpal.rs deleted file mode 100644 index 59c0ccf3eecc..000000000000 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/penpal.rs +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright 2019-2021 Parity Technologies (UK) Ltd. -// This file is part of Cumulus. - -// Cumulus 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. - -// Cumulus 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 Cumulus. If not, see . - -use crate::legacy_chain_spec::{ - get_account_id_from_seed, get_collator_keys_from_seed, Extensions, SAFE_XCM_VERSION, -}; -use cumulus_primitives_core::ParaId; -use parachains_common::{AccountId, AuraId}; -use sc_service::ChainType; -use sp_core::sr25519; -/// Specialized `ChainSpec` for the normal parachain runtime. -pub type PenpalChainSpec = - sc_service::GenericChainSpec; - -pub fn get_penpal_chain_spec(id: ParaId, relay_chain: &str) -> PenpalChainSpec { - // Give your base currency a unit name and decimal places - let mut properties = sc_chain_spec::Properties::new(); - properties.insert("tokenSymbol".into(), "UNIT".into()); - properties.insert("tokenDecimals".into(), 12u32.into()); - properties.insert("ss58Format".into(), 42u32.into()); - - #[allow(deprecated)] - PenpalChainSpec::from_genesis( - // Name - "Penpal Parachain", - // ID - &format!("penpal-{}", relay_chain.replace("-local", "")), - ChainType::Development, - move || { - penpal_testnet_genesis( - // initial collators. - vec![ - ( - get_account_id_from_seed::("Alice"), - get_collator_keys_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_collator_keys_from_seed::("Bob"), - ), - ], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - id, - ) - }, - Vec::new(), - None, - None, - None, - None, - Extensions { - relay_chain: relay_chain.into(), // You MUST set this to the correct network! - para_id: id.into(), - }, - penpal_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - ) -} - -fn penpal_testnet_genesis( - invulnerables: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - id: ParaId, -) -> penpal_runtime::RuntimeGenesisConfig { - penpal_runtime::RuntimeGenesisConfig { - system: penpal_runtime::SystemConfig::default(), - balances: penpal_runtime::BalancesConfig { - balances: endowed_accounts - .iter() - .cloned() - .map(|k| (k, penpal_runtime::EXISTENTIAL_DEPOSIT * 4096)) - .collect(), - }, - parachain_info: penpal_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() - }, - collator_selection: penpal_runtime::CollatorSelectionConfig { - invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(), - candidacy_bond: penpal_runtime::EXISTENTIAL_DEPOSIT * 16, - ..Default::default() - }, - session: penpal_runtime::SessionConfig { - keys: invulnerables - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - penpal_session_keys(aura), // session keys - ) - }) - .collect(), - }, - // no need to pass anything to aura, in fact it will panic if we do. Session will take care - // of this. - aura: Default::default(), - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: penpal_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, - sudo: penpal_runtime::SudoConfig { - key: Some(get_account_id_from_seed::("Alice")), - }, - } -} - -/// 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 penpal_session_keys(keys: AuraId) -> penpal_runtime::SessionKeys { - penpal_runtime::SessionKeys { aura: keys } -} diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/rococo_parachain.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/rococo_parachain.rs deleted file mode 100644 index ddf2aa16fe5e..000000000000 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/rococo_parachain.rs +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright 2022 Parity Technologies (UK) Ltd. -// This file is part of Cumulus. - -// Cumulus 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. - -// Cumulus 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 Cumulus. If not, see . - -//! ChainSpecs dedicated to Rococo parachain setups (for testing and example purposes) - -use crate::legacy_chain_spec::{get_from_seed, Extensions, SAFE_XCM_VERSION}; -use cumulus_primitives_core::ParaId; -use hex_literal::hex; -use parachains_common::AccountId; -use polkadot_service::chain_spec::get_account_id_from_seed; -use rococo_parachain_runtime::AuraId; -use sc_chain_spec::ChainType; -use sp_core::{crypto::UncheckedInto, sr25519}; - -pub type RococoParachainChainSpec = - sc_service::GenericChainSpec; - -pub fn rococo_parachain_local_config() -> RococoParachainChainSpec { - #[allow(deprecated)] - RococoParachainChainSpec::from_genesis( - "Rococo Parachain Local", - "local_testnet", - ChainType::Local, - move || { - testnet_genesis( - get_account_id_from_seed::("Alice"), - vec![get_from_seed::("Alice"), get_from_seed::("Bob")], - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - None, - Extensions { relay_chain: "rococo-local".into(), para_id: 1000 }, - rococo_parachain_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - ) -} - -pub fn staging_rococo_parachain_local_config() -> RococoParachainChainSpec { - #[allow(deprecated)] - RococoParachainChainSpec::from_genesis( - "Staging Rococo Parachain Local", - "staging_testnet", - ChainType::Live, - move || { - testnet_genesis( - hex!["9ed7705e3c7da027ba0583a22a3212042f7e715d3c168ba14f1424e2bc111d00"].into(), - vec![ - // $secret//one - hex!["aad9fa2249f87a210a0f93400b7f90e47b810c6d65caa0ca3f5af982904c2a33"] - .unchecked_into(), - // $secret//two - hex!["d47753f0cca9dd8da00c70e82ec4fc5501a69c49a5952a643d18802837c88212"] - .unchecked_into(), - ], - vec![ - hex!["9ed7705e3c7da027ba0583a22a3212042f7e715d3c168ba14f1424e2bc111d00"].into() - ], - 1000.into(), - ) - }, - Vec::new(), - None, - None, - None, - None, - Extensions { relay_chain: "rococo-local".into(), para_id: 1000 }, - rococo_parachain_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - ) -} - -pub(crate) fn testnet_genesis( - root_key: AccountId, - initial_authorities: Vec, - endowed_accounts: Vec, - id: ParaId, -) -> rococo_parachain_runtime::RuntimeGenesisConfig { - rococo_parachain_runtime::RuntimeGenesisConfig { - system: rococo_parachain_runtime::SystemConfig::default(), - balances: rococo_parachain_runtime::BalancesConfig { - balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), - }, - sudo: rococo_parachain_runtime::SudoConfig { key: Some(root_key) }, - parachain_info: rococo_parachain_runtime::ParachainInfoConfig { - parachain_id: id, - ..Default::default() - }, - aura: rococo_parachain_runtime::AuraConfig { authorities: initial_authorities }, - aura_ext: Default::default(), - parachain_system: Default::default(), - polkadot_xcm: rococo_parachain_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, - } -} diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/seedling.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/seedling.rs deleted file mode 100644 index 9be675fbe673..000000000000 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/seedling.rs +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Cumulus. - -// Cumulus 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. - -// Cumulus 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 Cumulus. If not, see . - -use crate::chain_spec::{get_account_id_from_seed, Extensions}; -use cumulus_primitives_core::ParaId; -use parachains_common::{AccountId, AuraId}; -use sc_service::ChainType; -use sp_core::sr25519; - -use super::get_collator_keys_from_seed; - -/// Specialized `ChainSpec` for the seedling parachain runtime. -pub type SeedlingChainSpec = - sc_service::GenericChainSpec; - -pub fn get_seedling_chain_spec() -> SeedlingChainSpec { - #[allow(deprecated)] - SeedlingChainSpec::from_genesis( - "Seedling Local Testnet", - "seedling_local_testnet", - ChainType::Local, - move || { - seedling_testnet_genesis( - get_account_id_from_seed::("Alice"), - 2000.into(), - vec![get_collator_keys_from_seed::("Alice")], - ) - }, - Vec::new(), - None, - None, - None, - None, - Extensions { relay_chain: "westend".into(), para_id: 2000 }, - seedling_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - ) -} - -fn seedling_testnet_genesis( - root_key: AccountId, - parachain_id: ParaId, - collators: Vec, -) -> seedling_runtime::RuntimeGenesisConfig { - seedling_runtime::RuntimeGenesisConfig { - system: seedling_runtime::SystemConfig::default(), - sudo: seedling_runtime::SudoConfig { key: Some(root_key) }, - parachain_info: seedling_runtime::ParachainInfoConfig { - parachain_id, - ..Default::default() - }, - parachain_system: Default::default(), - aura: seedling_runtime::AuraConfig { authorities: collators }, - aura_ext: Default::default(), - } -} diff --git a/cumulus/polkadot-parachain/src/legacy_chain_spec/shell.rs b/cumulus/polkadot-parachain/src/legacy_chain_spec/shell.rs deleted file mode 100644 index a9bc0b47497a..000000000000 --- a/cumulus/polkadot-parachain/src/legacy_chain_spec/shell.rs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// This file is part of Cumulus. - -// Cumulus 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. - -// Cumulus 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 Cumulus. If not, see . - -use crate::chain_spec::Extensions; -use cumulus_primitives_core::ParaId; -use parachains_common::AuraId; -use sc_service::ChainType; - -use super::get_collator_keys_from_seed; - -/// Specialized `ChainSpec` for the shell parachain runtime. -pub type ShellChainSpec = - sc_service::GenericChainSpec; - -pub fn get_shell_chain_spec() -> ShellChainSpec { - #[allow(deprecated)] - ShellChainSpec::from_genesis( - "Shell Local Testnet", - "shell_local_testnet", - ChainType::Local, - move || { - shell_testnet_genesis(1000.into(), vec![get_collator_keys_from_seed::("Alice")]) - }, - Vec::new(), - None, - None, - None, - None, - Extensions { relay_chain: "westend".into(), para_id: 1000 }, - shell_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"), - ) -} - -fn shell_testnet_genesis( - parachain_id: ParaId, - collators: Vec, -) -> shell_runtime::RuntimeGenesisConfig { - shell_runtime::RuntimeGenesisConfig { - system: shell_runtime::SystemConfig::default(), - parachain_info: shell_runtime::ParachainInfoConfig { parachain_id, ..Default::default() }, - parachain_system: Default::default(), - aura: shell_runtime::AuraConfig { authorities: collators }, - aura_ext: Default::default(), - } -} diff --git a/cumulus/polkadot-parachain/src/main.rs b/cumulus/polkadot-parachain/src/main.rs index fc508689cfc2..e40af8128f71 100644 --- a/cumulus/polkadot-parachain/src/main.rs +++ b/cumulus/polkadot-parachain/src/main.rs @@ -26,11 +26,6 @@ mod cli; mod command; mod rpc; -#[cfg(test)] -// Tests for verifying if raw ChainSpecs generated using legacy RuntimeGenesisConfig based approach -// are identical to ChainSpec generated using JSON approach. -mod legacy_chain_spec; - fn main() -> sc_cli::Result<()> { command::run() } diff --git a/polkadot/node/service/src/chain_spec.rs b/polkadot/node/service/src/chain_spec.rs index eb02240d00a2..04e142230b4c 100644 --- a/polkadot/node/service/src/chain_spec.rs +++ b/polkadot/node/service/src/chain_spec.rs @@ -1138,146 +1138,3 @@ pub fn versi_local_testnet_config() -> Result { .with_protocol_id("versi") .build()) } - -#[cfg(any( - feature = "polkadot-native", - feature = "kusama-native", - feature = "westend-native", - feature = "rococo-native" -))] -#[cfg(test)] -mod legacy_chain_spec; - -// Tests RuntimeGenesisConfig-based ChainSpecs (old) against the JSON-genesis-config-based (new) -// ChainSpecs. Shall be removed once native runtime is removed. -#[cfg(any( - feature = "polkadot-native", - feature = "kusama-native", - feature = "westend-native", - feature = "rococo-native" -))] -#[cfg(test)] -mod json_vs_legacy_tests { - #[cfg(any( - feature = "polkadot-native", - feature = "kusama-native", - feature = "westend-native", - feature = "rococo-native" - ))] - use super::{legacy_chain_spec as legacy, *}; - - #[test] - #[cfg(feature = "westend-native")] - fn westend_staging_testnet_config_compare_test() { - let j1 = westend_staging_testnet_config().unwrap().as_json(true).unwrap(); - let j2 = legacy::westend_staging_testnet_config().unwrap().as_json(true).unwrap(); - assert_eq!(j1, j2); - } - - #[test] - #[cfg(feature = "westend-native")] - fn westend_development_config_compare_test() { - let j1 = westend_development_config().unwrap().as_json(true).unwrap(); - let j2 = legacy::westend_development_config().unwrap().as_json(true).unwrap(); - assert_eq!(j1, j2); - } - - #[test] - #[cfg(feature = "westend-native")] - fn westend_local_testnet_config_compare_test() { - let j1 = westend_local_testnet_config().unwrap().as_json(true).unwrap(); - let j2 = legacy::westend_local_testnet_config().unwrap().as_json(true).unwrap(); - assert_eq!(j1, j2); - } - - #[test] - #[cfg(feature = "rococo-native")] - fn rococo_staging_testnet_config_compare_test() { - let mut j1 = rococo_staging_testnet_config().unwrap().as_json(true).unwrap(); - let mut j2 = legacy::rococo_staging_testnet_config().unwrap().as_json(true).unwrap(); - (j1, j2) = adjust_rococo_output(j1, j2); - assert_eq!(j1, j2); - } - - #[test] - #[cfg(feature = "rococo-native")] - fn rococo_development_config_compare_test() { - let mut j1 = rococo_development_config().unwrap().as_json(true).unwrap(); - let mut j2 = legacy::rococo_development_config().unwrap().as_json(true).unwrap(); - (j1, j2) = adjust_rococo_output(j1, j2); - assert_eq!(j1, j2); - } - - #[test] - #[cfg(feature = "rococo-native")] - fn rococo_local_testnet_config_compare_test() { - let mut j1 = rococo_local_testnet_config().unwrap().as_json(true).unwrap(); - let mut j2 = legacy::rococo_local_testnet_config().unwrap().as_json(true).unwrap(); - (j1, j2) = adjust_rococo_output(j1, j2); - assert_eq!(j1, j2); - } - - #[test] - #[cfg(feature = "rococo-native")] - fn wococo_development_config_compare_test() { - let mut j1 = wococo_development_config().unwrap().as_json(true).unwrap(); - let mut j2 = legacy::wococo_development_config().unwrap().as_json(true).unwrap(); - (j1, j2) = adjust_rococo_output(j1, j2); - assert_eq!(j1, j2); - } - - #[test] - #[cfg(feature = "rococo-native")] - fn wococo_local_testnet_config_compare_test() { - let mut j1 = wococo_local_testnet_config().unwrap().as_json(true).unwrap(); - let mut j2 = legacy::wococo_local_testnet_config().unwrap().as_json(true).unwrap(); - (j1, j2) = adjust_rococo_output(j1, j2); - assert_eq!(j1, j2); - } - - // since we changed how EpochDurationInBlocks is handleded (legacy: in state storage vs new: - // feature-based const), and since we have 3 versions of code, we need to do some adjustments. - fn adjust_rococo_output(input1: String, input2: String) -> (String, String) { - let mut json1 = serde_json::from_str::>(&input1).unwrap(); - let mut json2 = serde_json::from_str::>(&input2).unwrap(); - - let _ = json1.remove("code"); - let _ = json2.remove("code"); - let _ = json2.get_mut("genesis").map(|g| { - g.as_object_mut().unwrap().get_mut("raw").map(|r| { - r.as_object_mut().unwrap().get_mut("top").map(|t| { - let _ = t.as_object_mut().unwrap().remove("0x39e295d143ed41353167609a3d816584"); - }) - }) - }); - - (serde_json::to_string(&json1).unwrap(), serde_json::to_string(&json2).unwrap()) - } - - #[test] - #[cfg(feature = "rococo-native")] - fn versi_staging_testnet_config_compare_test() { - let mut j1 = versi_staging_testnet_config().unwrap().as_json(true).unwrap(); - let mut j2 = legacy::versi_staging_testnet_config().unwrap().as_json(true).unwrap(); - (j1, j2) = adjust_rococo_output(j1, j2); - assert_eq!(j1, j2); - } - - #[test] - #[cfg(feature = "rococo-native")] - fn versi_development_config_compare_test() { - let mut j1 = versi_development_config().unwrap().as_json(true).unwrap(); - let mut j2 = legacy::versi_development_config().unwrap().as_json(true).unwrap(); - (j1, j2) = adjust_rococo_output(j1, j2); - assert_eq!(j1, j2); - } - - #[test] - #[cfg(feature = "rococo-native")] - fn versi_local_testnet_config_compare_test() { - let mut j1 = versi_local_testnet_config().unwrap().as_json(true).unwrap(); - let mut j2 = legacy::versi_local_testnet_config().unwrap().as_json(true).unwrap(); - (j1, j2) = adjust_rococo_output(j1, j2); - assert_eq!(j1, j2); - } -} diff --git a/polkadot/node/service/src/chain_spec/legacy_chain_spec.rs b/polkadot/node/service/src/chain_spec/legacy_chain_spec.rs deleted file mode 100644 index 7375eb934e4a..000000000000 --- a/polkadot/node/service/src/chain_spec/legacy_chain_spec.rs +++ /dev/null @@ -1,1289 +0,0 @@ -// 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 . - -//! RuntimeGenesisConfig-based (legacy) Polkadot chain configurations. Used for testing ChainSpecs -//! against the JSON-based genesis configs. Entire file shall be removed once native runtime is -//! removed. - -use beefy_primitives::ecdsa_crypto::AuthorityId as BeefyId; -use grandpa::AuthorityId as GrandpaId; -use pallet_im_online::sr25519::AuthorityId as ImOnlineId; -#[cfg(feature = "westend-native")] -use pallet_staking::Forcing; -use polkadot_primitives::{AccountId, AccountPublic, AssignmentId, ValidatorId}; -use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; -use sp_consensus_babe::AuthorityId as BabeId; - -#[cfg(feature = "rococo-native")] -use rococo_runtime as rococo; -#[cfg(feature = "rococo-native")] -use rococo_runtime_constants::currency::UNITS as ROC; -use sc_chain_spec::ChainSpecExtension; -#[cfg(any(feature = "westend-native", feature = "rococo-native"))] -use sc_chain_spec::ChainType; -use serde::{Deserialize, Serialize}; -use sp_core::{sr25519, Pair, Public}; -use sp_runtime::traits::IdentifyAccount; -#[cfg(feature = "westend-native")] -use sp_runtime::Perbill; -#[cfg(any(feature = "westend-native", feature = "rococo-native"))] -use telemetry::TelemetryEndpoints; -#[cfg(feature = "westend-native")] -use westend_runtime as westend; -#[cfg(feature = "westend-native")] -use westend_runtime_constants::currency::UNITS as WND; - -#[cfg(feature = "westend-native")] -const WESTEND_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; -#[cfg(feature = "rococo-native")] -const ROCOCO_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; -#[cfg(feature = "rococo-native")] -const VERSI_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; -#[cfg(any(feature = "westend-native", feature = "rococo-native"))] -const DEFAULT_PROTOCOL_ID: &str = "dot"; - -/// Node `ChainSpec` extensions. -/// -/// Additional parameters for some Substrate core modules, -/// customizable from the chain spec. -#[derive(Default, Clone, Serialize, Deserialize, ChainSpecExtension)] -#[serde(rename_all = "camelCase")] -pub struct Extensions { - /// Block numbers with known hashes. - pub fork_blocks: sc_client_api::ForkBlocks, - /// Known bad block hashes. - pub bad_blocks: sc_client_api::BadBlocks, - /// The light sync state. - /// - /// This value will be set by the `sync-state rpc` implementation. - pub light_sync_state: sc_sync_state_rpc::LightSyncStateExtension, -} - -/// The `ChainSpec` parameterized for the westend runtime. -#[cfg(feature = "westend-native")] -pub type WestendChainSpec = service::GenericChainSpec; - -/// The `ChainSpec` parameterized for the rococo runtime. -#[cfg(feature = "rococo-native")] -pub type RococoChainSpec = service::GenericChainSpec; - -/// Extension for the Rococo genesis config to support a custom changes to the genesis state. -#[derive(serde::Serialize, serde::Deserialize)] -#[cfg(feature = "rococo-native")] -pub struct RococoGenesisExt { - /// The runtime genesis config. - runtime_genesis_config: rococo::RuntimeGenesisConfig, - /// The session length in blocks. - /// - /// If `None` is supplied, the default value is used. - session_length_in_blocks: Option, -} - -#[cfg(feature = "rococo-native")] -impl sp_runtime::BuildStorage for RococoGenesisExt { - fn assimilate_storage(&self, storage: &mut sp_core::storage::Storage) -> Result<(), String> { - sp_state_machine::BasicExternalities::execute_with_storage(storage, || { - if let Some(length) = self.session_length_in_blocks.as_ref() { - rococo_runtime_constants::time::EpochDurationInBlocks::set(length); - } - }); - self.runtime_genesis_config.assimilate_storage(storage) - } -} - -/// The default parachains host configuration. -#[cfg(any(feature = "rococo-native", feature = "westend-native",))] -fn default_parachains_host_configuration( -) -> polkadot_runtime_parachains::configuration::HostConfiguration -{ - use polkadot_primitives::{MAX_CODE_SIZE, MAX_POV_SIZE}; - - polkadot_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, - group_rotation_frequency: 20, - paras_availability_period: 4, - 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, - ..Default::default() - } -} - -#[cfg(any(feature = "rococo-native", feature = "westend-native",))] -#[test] -fn default_parachains_host_configuration_is_consistent() { - default_parachains_host_configuration().panic_if_not_consistent(); -} - -#[cfg(feature = "westend-native")] -fn westend_session_keys( - babe: BabeId, - grandpa: GrandpaId, - im_online: ImOnlineId, - para_validator: ValidatorId, - para_assignment: AssignmentId, - authority_discovery: AuthorityDiscoveryId, - beefy: BeefyId, -) -> westend::SessionKeys { - westend::SessionKeys { - babe, - grandpa, - im_online, - para_validator, - para_assignment, - authority_discovery, - beefy, - } -} - -#[cfg(feature = "rococo-native")] -fn rococo_session_keys( - babe: BabeId, - grandpa: GrandpaId, - im_online: ImOnlineId, - para_validator: ValidatorId, - para_assignment: AssignmentId, - authority_discovery: AuthorityDiscoveryId, - beefy: BeefyId, -) -> rococo_runtime::SessionKeys { - rococo_runtime::SessionKeys { - babe, - grandpa, - im_online, - para_validator, - para_assignment, - authority_discovery, - beefy, - } -} - -#[cfg(feature = "westend-native")] -fn westend_staging_testnet_config_genesis() -> westend::RuntimeGenesisConfig { - use hex_literal::hex; - use sp_core::crypto::UncheckedInto; - - // Following keys are used in genesis config for development chains. - // DO NOT use them in production chains as the secret seed is public. - // - // SECRET_SEED="slow awkward present example safe bundle science ocean cradle word tennis earn" - // subkey inspect -n polkadot "$SECRET_SEED" - let endowed_accounts = vec![ - // 15S75FkhCWEowEGfxWwVfrW3LQuy8w8PNhVmrzfsVhCMjUh1 - hex!["c416837e232d9603e83162ef4bda08e61580eeefe60fe92fc044aa508559ae42"].into(), - ]; - // SECRET=$SECRET_SEED ./scripts/prepare-test-net.sh 4 - let initial_authorities: Vec<( - AccountId, - AccountId, - BabeId, - GrandpaId, - ImOnlineId, - ValidatorId, - AssignmentId, - AuthorityDiscoveryId, - BeefyId, - )> = vec![ - ( - //5EvydUTtHvt39Khac3mMxNPgzcfu49uPDzUs3TL7KEzyrwbw - hex!["7ecfd50629cdd246649959d88d490b31508db511487e111a52a392e6e458f518"].into(), - //5HQyX5gyy77m9QLXguAhiwjTArHYjYspeY98dYDu1JDetfZg - hex!["eca2cca09bdc66a7e6d8c3d9499a0be2ad4690061be8a9834972e17d13d2fe7e"].into(), - //5G13qYRudTyttwTJvHvnwp8StFtcfigyPnwfD4v7LNopsnX4 - hex!["ae27367cb77850fb195fe1f9c60b73210409e68c5ad953088070f7d8513d464c"] - .unchecked_into(), - //5Eb7wM65PNgtY6e33FEAzYtU5cRTXt6WQvZTnzaKQwkVcABk - hex!["6faae44b21c6f2681a7f60df708e9f79d340f7d441d28bd987fab8d05c6487e8"] - .unchecked_into(), - //5CdS2wGo4qdTQceVfEnbZH8vULeBrnGYCxSCxDna4tQSMV6y - hex!["18f5d55f138bfa8e0ea26ed6fa56817b247de3c2e2030a908c63fb37c146473f"] - .unchecked_into(), - //5FqMLAgygdX9UqzukDp15Uid9PAKdFAR621U7xtp5ut2NfrW - hex!["a6c1a5b501985a83cb1c37630c5b41e6b0a15b3675b2fd94694758e6cfa6794d"] - .unchecked_into(), - //5DhXAV75BKvF9o447ikWqLttyL2wHtLMFSX7GrsKF9Ny61Ta - hex!["485051748ab9c15732f19f3fbcf1fd00a6d9709635f084505107fbb059c33d2f"] - .unchecked_into(), - //5GNHfmrtWLTawnGCmc39rjAEiW97vKvE7DGePYe4am5JtE4i - hex!["be59ed75a72f7b47221ce081ba4262cf2e1ea7867e30e0b3781822f942b97677"] - .unchecked_into(), - //5DA6Z8RUF626stn94aTRBCeobDCYcFbU7Pdk4Tz1R9vA8B8F - hex!["0207e43990799e1d02b0507451e342a1240ff836ea769c57297589a5fd072ad8f4"] - .unchecked_into(), - ), - ( - //5DFpvDUdCgw54E3E357GR1PyJe3Ft9s7Qyp7wbELAoJH9RQa - hex!["34b7b3efd35fcc3c1926ca065381682b1af29b57dabbcd091042c6de1d541b7d"].into(), - //5DZSSsND5wCjngvyXv27qvF3yPzt3MCU8rWnqNy4imqZmjT8 - hex!["4226796fa792ac78875e023ff2e30e3c2cf79f0b7b3431254cd0f14a3007bc0e"].into(), - //5CPrgfRNDQvQSnLRdeCphP3ibj5PJW9ESbqj2fw29vBMNQNn - hex!["0e9b60f04be3bffe362eb2212ea99d2b909b052f4bff7c714e13c2416a797f5d"] - .unchecked_into(), - //5FXFsPReTUEYPRNKhbTdUathcWBsxTNsLbk2mTpYdKCJewjA - hex!["98f4d81cb383898c2c3d54dab28698c0f717c81b509cb32dc6905af3cc697b18"] - .unchecked_into(), - //5CDYSCJK91r8y2r1V4Ddrit4PFMEkwZXJe8mNBqGXJ4xWCWq - hex!["06bd7dd4ab4c808c7d09d9cb6bd27fbcd99ad8400e99212b335056c475c24031"] - .unchecked_into(), - //5CZjurB78XbSHf6SLkLhCdkqw52Zm7aBYUDdfkLqEDWJ9Zhj - hex!["162508accd470e379b04cb0c7c60b35a7d5357e84407a89ed2dd48db4b726960"] - .unchecked_into(), - //5DkAqCtSjUMVoJFauuGoAbSEgn2aFCRGziKJiLGpPwYgE1pS - hex!["4a559c028b69a7f784ce553393e547bec0aa530352157603396d515f9c83463b"] - .unchecked_into(), - //5GsBt9MhGwkg8Jfb1F9LAy2kcr88WNyNy4L5ezwbCr8NWKQU - hex!["d464908266c878acbf181bf8fda398b3aa3fd2d05508013e414aaece4cf0d702"] - .unchecked_into(), - //5DtJVkz8AHevEnpszy3X4dUcPvACW6x1qBMQZtFxjexLr5bq - hex!["02fdf30222d2cb88f2376d558d3de9cb83f9fde3aa4b2dd40c93e3104e3488bcd2"] - .unchecked_into(), - ), - ( - //5E2cob2jrXsBkTih56pizwSqENjE4siaVdXhaD6akLdDyVq7 - hex!["56e0f73c563d49ee4a3971c393e17c44eaa313dabad7fcf297dc3271d803f303"].into(), - //5D4rNYgP9uFNi5GMyDEXTfiaFLjXyDEEX2VvuqBVi3f1qgCh - hex!["2c58e5e1d5aef77774480cead4f6876b1a1a6261170166995184d7f86140572b"].into(), - //5Ea2D65KXqe625sz4uV1jjhSfuigVnkezC8VgEj9LXN7ERAk - hex!["6ed45cb7af613be5d88a2622921e18d147225165f24538af03b93f2a03ce6e13"] - .unchecked_into(), - //5G4kCbgqUhEyrRHCyFwFEkgBZXoYA8sbgsRxT9rY8Tp5Jj5F - hex!["b0f8d2b9e4e1eafd4dab6358e0b9d5380d78af27c094e69ae9d6d30ca300fd86"] - .unchecked_into(), - //5HVhFBLFTKSZK9fX6RktckWDTgYNoSd33fgonsEC8zfr4ddm - hex!["f03c3e184b2883eec9beaeb97f54321587e7476b228831ea0b5fc6da847ea975"] - .unchecked_into(), - //5CS7thd2n54WfqeKU3cjvZzK4z5p7zku1Zw97mSzXgPioAAs - hex!["1055100a283968271a0781450b389b9093231be809be1e48a305ebad2a90497e"] - .unchecked_into(), - //5DSaL4ZmSYarZSazhL5NQh7LT6pWhNRDcefk2QS9RxEXfsJe - hex!["3cea4ab74bab4adf176cf05a6e18c1599a7bc217d4c6c217275bfbe3b037a527"] - .unchecked_into(), - //5CaNLkYEbFYXZodXhd3UjV6RNLjFGNLiYafc8X5NooMkZiAq - hex!["169faa81aebfe74533518bda28567f2e2664014c8905aa07ea003336afda5a58"] - .unchecked_into(), - //5ERwhKiePayukzZStMuzGzRJGxGRFpwxYUXVarQpMSMrXzDS - hex!["03429d0d20f6ac5ca8b349f04d014f7b5b864acf382a744104d5d9a51108156c0f"] - .unchecked_into(), - ), - ( - //5H6j9ovzYk9opckVjvM9SvVfaK37ASTtPTzWeRfqk1tgLJUN - hex!["deb804ed2ed2bb696a3dd4ed7de4cd5c496528a2b204051c6ace385bacd66a3a"].into(), - //5DJ51tMW916mGwjMpfS1o9skcNt6Sb28YnZQXaKVg4h89agE - hex!["366da6a748afedb31f07902f2de36ab265beccee37762d3ae1f237de234d9c36"].into(), - //5CSPYDYoCDGSoSLgSp4EHkJ52YasZLHG2woqhPZkdbtNQpke - hex!["1089bc0cd60237d061872925e81d36c9d9205d250d5d8b542c8e08a8ecf1b911"] - .unchecked_into(), - //5ChfdrAqmLjCeDJvynbMjcxYLHYzPe8UWXd3HnX9JDThUMbn - hex!["1c309a70b4e274314b84c9a0a1f973c9c4fc084df5479ef686c54b1ae4950424"] - .unchecked_into(), - //5DnsMm24575xK2b2aGfmafiDxwCet6Mr4iiZQeDdWvi8CzuF - hex!["4c64868ba6d8ace235d3efb4c10d745a67cf3bdfeae23b264d7ea2f3439dec42"] - .unchecked_into(), - //5D8C3HHEp5E8fJsXRD56494F413CdRSR9QKGXe7v5ZEfymdj - hex!["2ee4d78f328db178c54f205ac809da12e291a33bcbd4f29f081ce7e74bdc5044"] - .unchecked_into(), - //5GxeTYCGmp1C3ZRLDkRWqJc6gB2GYmuqnygweuH3vsivMQq6 - hex!["d88e40e3c2c7a7c5abf96ffdd8f7b7bec8798cc277bc97e255881871ab73b529"] - .unchecked_into(), - //5DoGpsgSLcJsHa9B8V4PKjxegWAqDZttWfxicAd68prUX654 - hex!["4cb3863271b70daa38612acd5dae4f5afcb7c165fa277629e5150d2214df322a"] - .unchecked_into(), - //5G1KLjqFyMsPAodnjSRkwRFJztTTEzmZWxow2Q3ZSRCPdthM - hex!["03be5ec86d10a94db89c9b7a396d3c7742e3bec5f85159d4cf308cef505966ddf5"] - .unchecked_into(), - ), - ]; - - const ENDOWMENT: u128 = 1_000_000 * WND; - const STASH: u128 = 100 * WND; - - westend::RuntimeGenesisConfig { - system: westend::SystemConfig::default(), - balances: westend::BalancesConfig { - balances: endowed_accounts - .iter() - .map(|k: &AccountId| (k.clone(), ENDOWMENT)) - .chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH))) - .collect(), - }, - beefy: Default::default(), - indices: westend::IndicesConfig { indices: vec![] }, - session: westend::SessionConfig { - keys: initial_authorities - .iter() - .map(|x| { - ( - x.0.clone(), - x.0.clone(), - westend_session_keys( - x.2.clone(), - x.3.clone(), - x.4.clone(), - x.5.clone(), - x.6.clone(), - x.7.clone(), - x.8.clone(), - ), - ) - }) - .collect::>(), - }, - staking: westend::StakingConfig { - validator_count: 50, - minimum_validator_count: 4, - stakers: initial_authorities - .iter() - .map(|x| (x.0.clone(), x.0.clone(), STASH, westend::StakerStatus::Validator)) - .collect(), - invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(), - force_era: Forcing::ForceNone, - slash_reward_fraction: Perbill::from_percent(10), - ..Default::default() - }, - babe: westend::BabeConfig { - authorities: Default::default(), - epoch_config: Some(westend::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() - }, - grandpa: Default::default(), - im_online: Default::default(), - authority_discovery: westend::AuthorityDiscoveryConfig { - keys: vec![], - ..Default::default() - }, - vesting: westend::VestingConfig { vesting: vec![] }, - sudo: westend::SudoConfig { key: Some(endowed_accounts[0].clone()) }, - hrmp: Default::default(), - treasury: Default::default(), - configuration: westend::ConfigurationConfig { - config: default_parachains_host_configuration(), - }, - paras: Default::default(), - registrar: westend_runtime::RegistrarConfig { - next_free_para_id: polkadot_primitives::LOWEST_PUBLIC_ID, - ..Default::default() - }, - xcm_pallet: Default::default(), - nomination_pools: Default::default(), - assigned_slots: Default::default(), - } -} - -#[cfg(feature = "rococo-native")] -fn rococo_staging_testnet_config_genesis() -> rococo_runtime::RuntimeGenesisConfig { - use hex_literal::hex; - use sp_core::crypto::UncheckedInto; - - // subkey inspect "$SECRET" - let endowed_accounts = vec![ - // 5DwBmEFPXRESyEam5SsQF1zbWSCn2kCjyLW51hJHXe9vW4xs - hex!["52bc71c1eca5353749542dfdf0af97bf764f9c2f44e860cd485f1cd86400f649"].into(), - ]; - - // ./scripts/prepare-test-net.sh 8 - let initial_authorities: Vec<( - AccountId, - AccountId, - BabeId, - GrandpaId, - ImOnlineId, - ValidatorId, - AssignmentId, - AuthorityDiscoveryId, - BeefyId, - )> = vec![ - ( - //5EHZkbp22djdbuMFH9qt1DVzSCvqi3zWpj6DAYfANa828oei - hex!["62475fe5406a7cb6a64c51d0af9d3ab5c2151bcae982fb812f7a76b706914d6a"].into(), - //5FeSEpi9UYYaWwXXb3tV88qtZkmSdB3mvgj3pXkxKyYLGhcd - hex!["9e6e781a76810fe93187af44c79272c290c2b9e2b8b92ee11466cd79d8023f50"].into(), - //5Fh6rDpMDhM363o1Z3Y9twtaCPfizGQWCi55BSykTQjGbP7H - hex!["a076ef1280d768051f21d060623da3ab5b56944d681d303ed2d4bf658c5bed35"] - .unchecked_into(), - //5CPd3zoV9Aaah4xWucuDivMHJ2nEEmpdi864nPTiyRZp4t87 - hex!["0e6d7d1afbcc6547b92995a394ba0daed07a2420be08220a5a1336c6731f0bfa"] - .unchecked_into(), - //5F7BEa1LGFksUihyatf3dCDYneB8pWzVyavnByCsm5nBgezi - hex!["86975a37211f8704e947a365b720f7a3e2757988eaa7d0f197e83dba355ef743"] - .unchecked_into(), - //5CP6oGfwqbEfML8efqm1tCZsUgRsJztp9L8ZkEUxA16W8PPz - hex!["0e07a51d3213842f8e9363ce8e444255990a225f87e80a3d651db7841e1a0205"] - .unchecked_into(), - //5HQdwiDh8Qtd5dSNWajNYpwDvoyNWWA16Y43aEkCNactFc2b - hex!["ec60e71fe4a567ef9fef99d4bbf37ffae70564b41aa6f94ef0317c13e0a5477b"] - .unchecked_into(), - //5HbSgM72xVuscsopsdeG3sCSCYdAeM1Tay9p79N6ky6vwDGq - hex!["f49eae66a0ac9f610316906ec8f1a0928e20d7059d76a5ca53cbcb5a9b50dd3c"] - .unchecked_into(), - //5DPSWdgw38Spu315r6LSvYCggeeieBAJtP5A1qzuzKhqmjVu - hex!["034f68c5661a41930c82f26a662276bf89f33467e1c850f2fb8ef687fe43d62276"] - .unchecked_into(), - ), - ( - //5DvH8oEjQPYhzCoQVo7WDU91qmQfLZvxe9wJcrojmJKebCmG - hex!["520b48452969f6ddf263b664de0adb0c729d0e0ad3b0e5f3cb636c541bc9022a"].into(), - //5ENZvCRzyXJJYup8bM6yEzb2kQHEb1NDpY2ZEyVGBkCfRdj3 - hex!["6618289af7ae8621981ffab34591e7a6486e12745dfa3fd3b0f7e6a3994c7b5b"].into(), - //5DLjSUfqZVNAADbwYLgRvHvdzXypiV1DAEaDMjcESKTcqMoM - hex!["38757d0de00a0c739e7d7984ef4bc01161bd61e198b7c01b618425c16bb5bd5f"] - .unchecked_into(), - //5HnDVBN9mD6mXyx8oryhDbJtezwNSj1VRXgLoYCBA6uEkiao - hex!["fcd5f87a6fd5707a25122a01b4dac0a8482259df7d42a9a096606df1320df08d"] - .unchecked_into(), - //5DhyXZiuB1LvqYKFgT5tRpgGsN3is2cM9QxgW7FikvakbAZP - hex!["48a910c0af90898f11bd57d37ceaea53c78994f8e1833a7ade483c9a84bde055"] - .unchecked_into(), - //5EPEWRecy2ApL5n18n3aHyU1956zXTRqaJpzDa9DoqiggNwF - hex!["669a10892119453e9feb4e3f1ee8e028916cc3240022920ad643846fbdbee816"] - .unchecked_into(), - //5ES3fw5X4bndSgLNmtPfSbM2J1kLqApVB2CCLS4CBpM1UxUZ - hex!["68bf52c482630a8d1511f2edd14f34127a7d7082219cccf7fd4c6ecdb535f80d"] - .unchecked_into(), - //5HeXbwb5PxtcRoopPZTp5CQun38atn2UudQ8p2AxR5BzoaXw - hex!["f6f8fe475130d21165446a02fb1dbce3a7bf36412e5d98f4f0473aed9252f349"] - .unchecked_into(), - //5F7nTtN8MyJV4UsXpjg7tHSnfANXZ5KRPJmkASc1ZSH2Xoa5 - hex!["03a90c2bb6d3b7000020f6152fe2e5002fa970fd1f42aafb6c8edda8dacc2ea77e"] - .unchecked_into(), - ), - ( - //5FPMzsezo1PRxYbVpJMWK7HNbR2kUxidsAAxH4BosHa4wd6S - hex!["92ef83665b39d7a565e11bf8d18d41d45a8011601c339e57a8ea88c8ff7bba6f"].into(), - //5G6NQidFG7YiXsvV7hQTLGArir9tsYqD4JDxByhgxKvSKwRx - hex!["b235f57244230589523271c27b8a490922ffd7dccc83b044feaf22273c1dc735"].into(), - //5GpZhzAVg7SAtzLvaAC777pjquPEcNy1FbNUAG2nZvhmd6eY - hex!["d2644c1ab2c63a3ad8d40ad70d4b260969e3abfe6d7e6665f50dc9f6365c9d2a"] - .unchecked_into(), - //5HAes2RQYPbYKbLBfKb88f4zoXv6pPA6Ke8CjN7dob3GpmSP - hex!["e1b68fbd84333e31486c08e6153d9a1415b2e7e71b413702b7d64e9b631184a1"] - .unchecked_into(), - //5HTXBf36LXmkFWJLokNUK6fPxVpkr2ToUnB1pvaagdGu4c1T - hex!["ee93e26259decb89afcf17ef2aa0fa2db2e1042fb8f56ecfb24d19eae8629878"] - .unchecked_into(), - //5FtAGDZYJKXkhVhAxCQrXmaP7EE2mGbBMfmKDHjfYDgq2BiU - hex!["a8e61ffacafaf546283dc92d14d7cc70ea0151a5dd81fdf73ff5a2951f2b6037"] - .unchecked_into(), - //5CtK7JHv3h6UQZ44y54skxdwSVBRtuxwPE1FYm7UZVhg8rJV - hex!["244f3421b310c68646e99cdbf4963e02067601f57756b072a4b19431448c186e"] - .unchecked_into(), - //5D4r6YaB6F7A7nvMRHNFNF6zrR9g39bqDJFenrcaFmTCRwfa - hex!["2c57f81fd311c1ab53813c6817fe67f8947f8d39258252663b3384ab4195494d"] - .unchecked_into(), - //5EPoHj8uV4fFKQHYThc6Z9fDkU7B6ih2ncVzQuDdNFb8UyhF - hex!["039d065fe4f9234f0a4f13cc3ae585f2691e9c25afa469618abb6645111f607a53"] - .unchecked_into(), - ), - ( - //5DMNx7RoX6d7JQ38NEM7DWRcW2THu92LBYZEWvBRhJeqcWgR - hex!["38f3c2f38f6d47f161e98c697bbe3ca0e47c033460afda0dda314ab4222a0404"].into(), - //5GGdKNDr9P47dpVnmtq3m8Tvowwf1ot1abw6tPsTYYFoKm2v - hex!["ba0898c1964196474c0be08d364cdf4e9e1d47088287f5235f70b0590dfe1704"].into(), - //5EjkyPCzR2SjhDZq8f7ufsw6TfkvgNRepjCRQFc4TcdXdaB1 - hex!["764186bc30fd5a02477f19948dc723d6d57ab174debd4f80ed6038ec960bfe21"] - .unchecked_into(), - //5DJV3zCBTJBLGNDCcdWrYxWDacSz84goGTa4pFeKVvehEBte - hex!["36be9069cdb4a8a07ecd51f257875150f0a8a1be44a10d9d98dabf10a030aef4"] - .unchecked_into(), - //5FHf8kpK4fPjEJeYcYon2gAPwEBubRvtwpzkUbhMWSweKPUY - hex!["8e95b9b5b4dc69790b67b566567ca8bf8cdef3a3a8bb65393c0d1d1c87cd2d2c"] - .unchecked_into(), - //5F9FsRjpecP9GonktmtFL3kjqNAMKjHVFjyjRdTPa4hbQRZA - hex!["882d72965e642677583b333b2d173ac94b5fd6c405c76184bb14293be748a13b"] - .unchecked_into(), - //5F1FZWZSj3JyTLs8sRBxU6QWyGLSL9BMRtmSKDmVEoiKFxSP - hex!["821271c99c958b9220f1771d9f5e29af969edfa865631dba31e1ab7bc0582b75"] - .unchecked_into(), - //5CtgRR74VypK4h154s369abs78hDUxZSJqcbWsfXvsjcHJNA - hex!["2496f28d887d84705c6dae98aee8bf90fc5ad10bb5545eca1de6b68425b70f7c"] - .unchecked_into(), - //5CPx6dsr11SCJHKFkcAQ9jpparS7FwXQBrrMznRo4Hqv1PXz - hex!["0307d29bbf6a5c4061c2157b44fda33b7bb4ec52a5a0305668c74688cedf288d58"] - .unchecked_into(), - ), - ( - //5C8AL1Zb4bVazgT3EgDxFgcow1L4SJjVu44XcLC9CrYqFN4N - hex!["02a2d8cfcf75dda85fafc04ace3bcb73160034ed1964c43098fb1fe831de1b16"].into(), - //5FLYy3YKsAnooqE4hCudttAsoGKbVG3hYYBtVzwMjJQrevPa - hex!["90cab33f0bb501727faa8319f0845faef7d31008f178b65054b6629fe531b772"].into(), - //5Et3tfbVf1ByFThNAuUq5pBssdaPPskip5yob5GNyUFojXC7 - hex!["7c94715e5dd8ab54221b1b6b2bfa5666f593f28a92a18e28052531de1bd80813"] - .unchecked_into(), - //5EX1JBghGbQqWohTPU6msR9qZ2nYPhK9r3RTQ2oD1K8TCxaG - hex!["6c878e33b83c20324238d22240f735457b6fba544b383e70bb62a27b57380c81"] - .unchecked_into(), - //5GqL8RbVAuNXpDhjQi1KrS1MyNuKhvus2AbmQwRGjpuGZmFu - hex!["d2f9d537ffa59919a4028afdb627c14c14c97a1547e13e8e82203d2049b15b1a"] - .unchecked_into(), - //5EUNaBpX9mJgcmLQHyG5Pkms6tbDiKuLbeTEJS924Js9cA1N - hex!["6a8570b9c6408e54bacf123cc2bb1b0f087f9c149147d0005badba63a5a4ac01"] - .unchecked_into(), - //5CaZuueRVpMATZG4hkcrgDoF4WGixuz7zu83jeBdY3bgWGaG - hex!["16c69ea8d595e80b6736f44be1eaeeef2ac9c04a803cc4fd944364cb0d617a33"] - .unchecked_into(), - //5DABsdQCDUGuhzVGWe5xXzYQ9rtrVxRygW7RXf9Tsjsw1aGJ - hex!["306ac5c772fe858942f92b6e28bd82fb7dd8cdd25f9a4626c1b0eee075fcb531"] - .unchecked_into(), - //5H91T5mHhoCw9JJG4NjghDdQyhC6L7XcSuBWKD3q3TAhEVvQ - hex!["02fb0330356e63a35dd930bc74525edf28b3bf5eb44aab9e9e4962c8309aaba6a6"] - .unchecked_into(), - ), - ( - //5C8XbDXdMNKJrZSrQURwVCxdNdk8AzG6xgLggbzuA399bBBF - hex!["02ea6bfa8b23b92fe4b5db1063a1f9475e3acd0ab61e6b4f454ed6ba00b5f864"].into(), - //5GsyzFP8qtF8tXPSsjhjxAeU1v7D1PZofuQKN9TdCc7Dp1JM - hex!["d4ffc4c05b47d1115ad200f7f86e307b20b46c50e1b72a912ec4f6f7db46b616"].into(), - //5GHWB8ZDzegLcMW7Gdd1BS6WHVwDdStfkkE4G7KjPjZNJBtD - hex!["bab3cccdcc34401e9b3971b96a662686cf755aa869a5c4b762199ce531b12c5b"] - .unchecked_into(), - //5GzDPGbUM9uH52ZEwydasTj8edokGUJ7vEpoFWp9FE1YNuFB - hex!["d9c056c98ca0e6b4eb7f5c58c007c1db7be0fe1f3776108f797dd4990d1ccc33"] - .unchecked_into(), - //5GWZbVkJEfWZ7fRca39YAQeqri2Z7pkeHyd7rUctUHyQifLp - hex!["c4a980da30939d5bb9e4a734d12bf81259ae286aa21fa4b65405347fa40eff35"] - .unchecked_into(), - //5CmLCFeSurRXXtwMmLcVo7sdJ9EqDguvJbuCYDcHkr3cpqyE - hex!["1efc23c0b51ad609ab670ecf45807e31acbd8e7e5cb7c07cf49ee42992d2867c"] - .unchecked_into(), - //5DnsSy8a8pfE2aFjKBDtKw7WM1V4nfE5sLzP15MNTka53GqS - hex!["4c64d3f06d28adeb36a892fdaccecace150bec891f04694448a60b74fa469c22"] - .unchecked_into(), - //5CZdFnyzZvKetZTeUwj5APAYskVJe4QFiTezo5dQNsrnehGd - hex!["160ea09c5717270e958a3da42673fa011613a9539b2e4ebcad8626bc117ca04a"] - .unchecked_into(), - //5HgoR9JJkdBusxKrrs3zgd3ToppgNoGj1rDyAJp4e7eZiYyT - hex!["020019a8bb188f8145d02fa855e9c36e9914457d37c500e03634b5223aa5702474"] - .unchecked_into(), - ), - ( - //5HinEonzr8MywkqedcpsmwpxKje2jqr9miEwuzyFXEBCvVXM - hex!["fa373e25a1c4fe19c7148acde13bc3db1811cf656dc086820f3dda736b9c4a00"].into(), - //5EHJbj6Td6ks5HDnyfN4ttTSi57osxcQsQexm7XpazdeqtV7 - hex!["62145d721967bd88622d08625f0f5681463c0f1b8bcd97eb3c2c53f7660fd513"].into(), - //5EeCsC58XgJ1DFaoYA1WktEpP27jvwGpKdxPMFjicpLeYu96 - hex!["720537e2c1c554654d73b3889c3ef4c3c2f95a65dd3f7c185ebe4afebed78372"] - .unchecked_into(), - //5DnEySxbnppWEyN8cCLqvGjAorGdLRg2VmkY96dbJ1LHFK8N - hex!["4bea0b37e0cce9bddd80835fa2bfd5606f5dcfb8388bbb10b10c483f0856cf14"] - .unchecked_into(), - //5E1Y1FJ7dVP7qtE3wm241pTm72rTMcDT5Jd8Czv7Pwp7N3AH - hex!["560d90ca51e9c9481b8a9810060e04d0708d246714960439f804e5c6f40ca651"] - .unchecked_into(), - //5CAC278tFCHAeHYqE51FTWYxHmeLcENSS1RG77EFRTvPZMJT - hex!["042f07fc5268f13c026bbe199d63e6ac77a0c2a780f71cda05cee5a6f1b3f11f"] - .unchecked_into(), - //5HjRTLWcQjZzN3JDvaj1UzjNSayg5ZD9ZGWMstaL7Ab2jjAa - hex!["fab485e87ed1537d089df521edf983a777c57065a702d7ed2b6a2926f31da74f"] - .unchecked_into(), - //5ELv74v7QcsS6FdzvG4vL2NnYDGWmRnJUSMKYwdyJD7Xcdi7 - hex!["64d59feddb3d00316a55906953fb3db8985797472bd2e6c7ea1ab730cc339d7f"] - .unchecked_into(), - //5FaUcPt4fPz93vBhcrCJqmDkjYZ7jCbzAF56QJoCmvPaKrmx - hex!["033f1a6d47fe86f88934e4b83b9fae903b92b5dcf4fec97d5e3e8bf4f39df03685"] - .unchecked_into(), - ), - ( - //5Ey3NQ3dfabaDc16NUv7wRLsFCMDFJSqZFzKVycAsWuUC6Di - hex!["8062e9c21f1d92926103119f7e8153cebdb1e5ab3e52d6f395be80bb193eab47"].into(), - //5HiWsuSBqt8nS9pnggexXuHageUifVPKPHDE2arTKqhTp1dV - hex!["fa0388fa88f3f0cb43d583e2571fbc0edad57dff3a6fd89775451dd2c2b8ea00"].into(), - //5H168nKX2Yrfo3bxj7rkcg25326Uv3CCCnKUGK6uHdKMdPt8 - hex!["da6b2df18f0f9001a6dcf1d301b92534fe9b1f3ccfa10c49449fee93adaa8349"] - .unchecked_into(), - //5DrA2fZdzmNqT5j6DXNwVxPBjDV9jhkAqvjt6Us3bQHKy3cF - hex!["4ee66173993dd0db5d628c4c9cb61a27b76611ad3c3925947f0d0011ee2c5dcc"] - .unchecked_into(), - //5FNFDUGNLUtqg5LgrwYLNmBiGoP8KRxsvQpBkc7GQP6qaBUG - hex!["92156f54a114ee191415898f2da013d9db6a5362d6b36330d5fc23e27360ab66"] - .unchecked_into(), - //5Gx6YeNhynqn8qkda9QKpc9S7oDr4sBrfAu516d3sPpEt26F - hex!["d822d4088b20dca29a580a577a97d6f024bb24c9550bebdfd7d2d18e946a1c7d"] - .unchecked_into(), - //5DhDcHqwxoes5s89AyudGMjtZXx1nEgrk5P45X88oSTR3iyx - hex!["481538f8c2c011a76d7d57db11c2789a5e83b0f9680dc6d26211d2f9c021ae4c"] - .unchecked_into(), - //5DqAvikdpfRdk5rR35ZobZhqaC5bJXZcEuvzGtexAZP1hU3T - hex!["4e262811acdfe94528bfc3c65036080426a0e1301b9ada8d687a70ffcae99c26"] - .unchecked_into(), - //5E41Znrr2YtZu8bZp3nvRuLVHg3jFksfQ3tXuviLku4wsao7 - hex!["025e84e95ed043e387ddb8668176b42f8e2773ddd84f7f58a6d9bf436a4b527986"] - .unchecked_into(), - ), - ]; - - const ENDOWMENT: u128 = 1_000_000 * ROC; - const STASH: u128 = 100 * ROC; - - rococo_runtime::RuntimeGenesisConfig { - system: rococo_runtime::SystemConfig::default(), - balances: rococo_runtime::BalancesConfig { - balances: endowed_accounts - .iter() - .map(|k: &AccountId| (k.clone(), ENDOWMENT)) - .chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH))) - .collect(), - }, - beefy: Default::default(), - indices: rococo_runtime::IndicesConfig { indices: vec![] }, - session: rococo_runtime::SessionConfig { - keys: initial_authorities - .iter() - .map(|x| { - ( - x.0.clone(), - x.0.clone(), - rococo_session_keys( - x.2.clone(), - x.3.clone(), - x.4.clone(), - x.5.clone(), - x.6.clone(), - x.7.clone(), - x.8.clone(), - ), - ) - }) - .collect::>(), - }, - babe: rococo_runtime::BabeConfig { - authorities: Default::default(), - epoch_config: Some(rococo_runtime::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() - }, - grandpa: Default::default(), - im_online: Default::default(), - treasury: Default::default(), - authority_discovery: rococo_runtime::AuthorityDiscoveryConfig { - keys: vec![], - ..Default::default() - }, - claims: rococo::ClaimsConfig { claims: vec![], vesting: vec![] }, - vesting: rococo::VestingConfig { vesting: vec![] }, - sudo: rococo_runtime::SudoConfig { key: Some(endowed_accounts[0].clone()) }, - paras: rococo_runtime::ParasConfig { paras: vec![], ..Default::default() }, - hrmp: Default::default(), - configuration: rococo_runtime::ConfigurationConfig { - config: default_parachains_host_configuration(), - }, - registrar: rococo_runtime::RegistrarConfig { - next_free_para_id: polkadot_primitives::LOWEST_PUBLIC_ID, - ..Default::default() - }, - xcm_pallet: Default::default(), - nis_counterpart_balances: Default::default(), - assigned_slots: Default::default(), - } -} - -/// Westend staging testnet config. -#[cfg(feature = "westend-native")] -pub fn westend_staging_testnet_config() -> Result { - let boot_nodes = vec![]; - - #[allow(deprecated)] - Ok(WestendChainSpec::from_genesis( - "Westend Staging Testnet", - "westend_staging_testnet", - ChainType::Live, - move || westend_staging_testnet_config_genesis(), - boot_nodes, - Some( - TelemetryEndpoints::new(vec![(WESTEND_STAGING_TELEMETRY_URL.to_string(), 0)]) - .expect("Westend Staging telemetry url is valid; qed"), - ), - Some(DEFAULT_PROTOCOL_ID), - None, - None, - Default::default(), - westend::WASM_BINARY.ok_or("Westend development wasm not available")?, - )) -} - -/// Rococo staging testnet config. -#[cfg(feature = "rococo-native")] -pub fn rococo_staging_testnet_config() -> Result { - let boot_nodes = vec![]; - - #[allow(deprecated)] - Ok(RococoChainSpec::from_genesis( - "Rococo Staging Testnet", - "rococo_staging_testnet", - ChainType::Live, - move || RococoGenesisExt { - runtime_genesis_config: rococo_staging_testnet_config_genesis(), - session_length_in_blocks: None, - }, - boot_nodes, - Some( - TelemetryEndpoints::new(vec![(ROCOCO_STAGING_TELEMETRY_URL.to_string(), 0)]) - .expect("Rococo Staging telemetry url is valid; qed"), - ), - Some(DEFAULT_PROTOCOL_ID), - None, - None, - Default::default(), - rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?, - )) -} - -pub fn versi_chain_spec_properties() -> serde_json::map::Map { - serde_json::json!({ - "ss58Format": 42, - "tokenDecimals": 12, - "tokenSymbol": "VRS", - }) - .as_object() - .expect("Map given; qed") - .clone() -} - -/// Versi staging testnet config. -#[cfg(feature = "rococo-native")] -pub fn versi_staging_testnet_config() -> Result { - let boot_nodes = vec![]; - - #[allow(deprecated)] - Ok(RococoChainSpec::from_genesis( - "Versi Staging Testnet", - "versi_staging_testnet", - ChainType::Live, - move || RococoGenesisExt { - runtime_genesis_config: rococo_staging_testnet_config_genesis(), - session_length_in_blocks: Some(100), - }, - boot_nodes, - Some( - TelemetryEndpoints::new(vec![(VERSI_STAGING_TELEMETRY_URL.to_string(), 0)]) - .expect("Versi Staging telemetry url is valid; qed"), - ), - Some("versi"), - None, - Some(versi_chain_spec_properties()), - Default::default(), - rococo::WASM_BINARY.ok_or("Versi development wasm not available")?, - )) -} - -/// 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, - ImOnlineId, - 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, keys.7, 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, - ImOnlineId, - 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), - get_from_seed::(seed), - ) -} - -#[cfg(any(feature = "westend-native", feature = "rococo-native"))] -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 create westend `RuntimeGenesisConfig` for testing -#[cfg(feature = "westend-native")] -pub fn westend_testnet_genesis( - initial_authorities: Vec<( - AccountId, - AccountId, - BabeId, - GrandpaId, - ImOnlineId, - ValidatorId, - AssignmentId, - AuthorityDiscoveryId, - BeefyId, - )>, - root_key: AccountId, - endowed_accounts: Option>, -) -> westend::RuntimeGenesisConfig { - let endowed_accounts: Vec = endowed_accounts.unwrap_or_else(testnet_accounts); - - const ENDOWMENT: u128 = 1_000_000 * WND; - const STASH: u128 = 100 * WND; - - westend::RuntimeGenesisConfig { - system: westend::SystemConfig::default(), - indices: westend::IndicesConfig { indices: vec![] }, - balances: westend::BalancesConfig { - balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(), - }, - beefy: Default::default(), - session: westend::SessionConfig { - keys: initial_authorities - .iter() - .map(|x| { - ( - x.0.clone(), - x.0.clone(), - westend_session_keys( - x.2.clone(), - x.3.clone(), - x.4.clone(), - x.5.clone(), - x.6.clone(), - x.7.clone(), - x.8.clone(), - ), - ) - }) - .collect::>(), - }, - staking: westend::StakingConfig { - minimum_validator_count: 1, - validator_count: initial_authorities.len() as u32, - stakers: initial_authorities - .iter() - .map(|x| (x.0.clone(), x.0.clone(), STASH, westend::StakerStatus::Validator)) - .collect(), - invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(), - force_era: Forcing::NotForcing, - slash_reward_fraction: Perbill::from_percent(10), - ..Default::default() - }, - babe: westend::BabeConfig { - authorities: Default::default(), - epoch_config: Some(westend::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() - }, - grandpa: Default::default(), - im_online: Default::default(), - authority_discovery: westend::AuthorityDiscoveryConfig { - keys: vec![], - ..Default::default() - }, - vesting: westend::VestingConfig { vesting: vec![] }, - sudo: westend::SudoConfig { key: Some(root_key) }, - hrmp: Default::default(), - treasury: Default::default(), - configuration: westend::ConfigurationConfig { - config: default_parachains_host_configuration(), - }, - paras: Default::default(), - registrar: westend_runtime::RegistrarConfig { - next_free_para_id: polkadot_primitives::LOWEST_PUBLIC_ID, - ..Default::default() - }, - xcm_pallet: Default::default(), - nomination_pools: Default::default(), - assigned_slots: Default::default(), - } -} - -/// Helper function to create rococo `RuntimeGenesisConfig` for testing -#[cfg(feature = "rococo-native")] -pub fn rococo_testnet_genesis( - initial_authorities: Vec<( - AccountId, - AccountId, - BabeId, - GrandpaId, - ImOnlineId, - ValidatorId, - AssignmentId, - AuthorityDiscoveryId, - BeefyId, - )>, - root_key: AccountId, - endowed_accounts: Option>, -) -> rococo_runtime::RuntimeGenesisConfig { - let endowed_accounts: Vec = endowed_accounts.unwrap_or_else(testnet_accounts); - - const ENDOWMENT: u128 = 1_000_000 * ROC; - - rococo_runtime::RuntimeGenesisConfig { - system: rococo_runtime::SystemConfig::default(), - beefy: Default::default(), - indices: rococo_runtime::IndicesConfig { indices: vec![] }, - balances: rococo_runtime::BalancesConfig { - balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(), - }, - session: rococo_runtime::SessionConfig { - keys: initial_authorities - .iter() - .map(|x| { - ( - x.0.clone(), - x.0.clone(), - rococo_session_keys( - x.2.clone(), - x.3.clone(), - x.4.clone(), - x.5.clone(), - x.6.clone(), - x.7.clone(), - x.8.clone(), - ), - ) - }) - .collect::>(), - }, - babe: rococo_runtime::BabeConfig { - authorities: Default::default(), - epoch_config: Some(rococo_runtime::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() - }, - grandpa: Default::default(), - im_online: Default::default(), - treasury: Default::default(), - claims: rococo::ClaimsConfig { claims: vec![], vesting: vec![] }, - vesting: rococo::VestingConfig { vesting: vec![] }, - authority_discovery: rococo_runtime::AuthorityDiscoveryConfig { - keys: vec![], - ..Default::default() - }, - sudo: rococo_runtime::SudoConfig { key: Some(root_key.clone()) }, - hrmp: Default::default(), - configuration: rococo_runtime::ConfigurationConfig { - config: polkadot_runtime_parachains::configuration::HostConfiguration { - max_validators_per_core: Some(1), - ..default_parachains_host_configuration() - }, - }, - paras: rococo_runtime::ParasConfig { paras: vec![], ..Default::default() }, - registrar: rococo_runtime::RegistrarConfig { - next_free_para_id: polkadot_primitives::LOWEST_PUBLIC_ID, - ..Default::default() - }, - xcm_pallet: Default::default(), - nis_counterpart_balances: Default::default(), - assigned_slots: Default::default(), - } -} - -#[cfg(feature = "westend-native")] -fn westend_development_config_genesis() -> westend::RuntimeGenesisConfig { - westend_testnet_genesis( - vec![get_authority_keys_from_seed("Alice")], - get_account_id_from_seed::("Alice"), - None, - ) -} - -#[cfg(feature = "rococo-native")] -fn rococo_development_config_genesis() -> rococo_runtime::RuntimeGenesisConfig { - rococo_testnet_genesis( - vec![get_authority_keys_from_seed("Alice")], - get_account_id_from_seed::("Alice"), - None, - ) -} - -/// Westend development config (single validator Alice) -#[cfg(feature = "westend-native")] -pub fn westend_development_config() -> Result { - #[allow(deprecated)] - Ok(WestendChainSpec::from_genesis( - "Development", - "westend_dev", - ChainType::Development, - move || westend_development_config_genesis(), - vec![], - None, - Some(DEFAULT_PROTOCOL_ID), - None, - None, - Default::default(), - westend::WASM_BINARY.ok_or("Westend development wasm not available")?, - )) -} - -/// Rococo development config (single validator Alice) -#[cfg(feature = "rococo-native")] -pub fn rococo_development_config() -> Result { - #[allow(deprecated)] - Ok(RococoChainSpec::from_genesis( - "Development", - "rococo_dev", - ChainType::Development, - move || RococoGenesisExt { - runtime_genesis_config: rococo_development_config_genesis(), - // Use 1 minute session length. - session_length_in_blocks: Some(10), - }, - vec![], - None, - Some(DEFAULT_PROTOCOL_ID), - None, - None, - Default::default(), - rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?, - )) -} - -/// `Versi` development config (single validator Alice) -#[cfg(feature = "rococo-native")] -pub fn versi_development_config() -> Result { - #[allow(deprecated)] - Ok(RococoChainSpec::from_genesis( - "Development", - "versi_dev", - ChainType::Development, - move || RococoGenesisExt { - runtime_genesis_config: rococo_development_config_genesis(), - // Use 1 minute session length. - session_length_in_blocks: Some(10), - }, - vec![], - None, - Some("versi"), - None, - None, - Default::default(), - rococo::WASM_BINARY.ok_or("Versi development wasm not available")?, - )) -} - -/// Wococo development config (single validator Alice) -#[cfg(feature = "rococo-native")] -pub fn wococo_development_config() -> Result { - const WOCOCO_DEV_PROTOCOL_ID: &str = "woco"; - - #[allow(deprecated)] - Ok(RococoChainSpec::from_genesis( - "Development", - "wococo_dev", - ChainType::Development, - move || RococoGenesisExt { - runtime_genesis_config: rococo_development_config_genesis(), - // Use 1 minute session length. - session_length_in_blocks: Some(10), - }, - vec![], - None, - Some(WOCOCO_DEV_PROTOCOL_ID), - None, - None, - Default::default(), - rococo::WASM_BINARY.ok_or("Wococo development wasm not available")?, - )) -} - -#[cfg(feature = "westend-native")] -fn westend_local_testnet_genesis() -> westend::RuntimeGenesisConfig { - westend_testnet_genesis( - vec![get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob")], - get_account_id_from_seed::("Alice"), - None, - ) -} - -/// Westend local testnet config (multivalidator Alice + Bob) -#[cfg(feature = "westend-native")] -pub fn westend_local_testnet_config() -> Result { - #[allow(deprecated)] - Ok(WestendChainSpec::from_genesis( - "Westend Local Testnet", - "westend_local_testnet", - ChainType::Local, - move || westend_local_testnet_genesis(), - vec![], - None, - Some(DEFAULT_PROTOCOL_ID), - None, - None, - Default::default(), - westend::WASM_BINARY.ok_or("Westend development wasm not available")?, - )) -} - -#[cfg(feature = "rococo-native")] -fn rococo_local_testnet_genesis() -> rococo_runtime::RuntimeGenesisConfig { - rococo_testnet_genesis( - vec![get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob")], - get_account_id_from_seed::("Alice"), - None, - ) -} - -/// Rococo local testnet config (multivalidator Alice + Bob) -#[cfg(feature = "rococo-native")] -pub fn rococo_local_testnet_config() -> Result { - #[allow(deprecated)] - Ok(RococoChainSpec::from_genesis( - "Rococo Local Testnet", - "rococo_local_testnet", - ChainType::Local, - move || RococoGenesisExt { - runtime_genesis_config: rococo_local_testnet_genesis(), - // Use 1 minute session length. - session_length_in_blocks: Some(10), - }, - vec![], - None, - Some(DEFAULT_PROTOCOL_ID), - None, - None, - Default::default(), - rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?, - )) -} - -/// Wococo is a temporary testnet that uses almost the same runtime as rococo. -#[cfg(feature = "rococo-native")] -fn wococo_local_testnet_genesis() -> rococo_runtime::RuntimeGenesisConfig { - rococo_testnet_genesis( - vec![ - get_authority_keys_from_seed("Alice"), - get_authority_keys_from_seed("Bob"), - get_authority_keys_from_seed("Charlie"), - get_authority_keys_from_seed("Dave"), - ], - get_account_id_from_seed::("Alice"), - None, - ) -} - -/// Wococo local testnet config (multivalidator Alice + Bob + Charlie + Dave) -#[cfg(feature = "rococo-native")] -pub fn wococo_local_testnet_config() -> Result { - #[allow(deprecated)] - Ok(RococoChainSpec::from_genesis( - "Wococo Local Testnet", - "wococo_local_testnet", - ChainType::Local, - move || RococoGenesisExt { - runtime_genesis_config: wococo_local_testnet_genesis(), - // Use 1 minute session length. - session_length_in_blocks: Some(10), - }, - vec![], - None, - Some(DEFAULT_PROTOCOL_ID), - None, - None, - Default::default(), - rococo::WASM_BINARY.ok_or("Wococo development wasm not available")?, - )) -} - -/// `Versi` is a temporary testnet that uses the same runtime as rococo. -#[cfg(feature = "rococo-native")] -fn versi_local_testnet_genesis() -> rococo_runtime::RuntimeGenesisConfig { - rococo_testnet_genesis( - vec![ - get_authority_keys_from_seed("Alice"), - get_authority_keys_from_seed("Bob"), - get_authority_keys_from_seed("Charlie"), - get_authority_keys_from_seed("Dave"), - ], - get_account_id_from_seed::("Alice"), - None, - ) -} - -/// `Versi` local testnet config (multivalidator Alice + Bob + Charlie + Dave) -#[cfg(feature = "rococo-native")] -pub fn versi_local_testnet_config() -> Result { - #[allow(deprecated)] - Ok(RococoChainSpec::from_genesis( - "Versi Local Testnet", - "versi_local_testnet", - ChainType::Local, - move || RococoGenesisExt { - runtime_genesis_config: versi_local_testnet_genesis(), - // Use 1 minute session length. - session_length_in_blocks: Some(10), - }, - vec![], - None, - Some("versi"), - None, - None, - Default::default(), - rococo::WASM_BINARY.ok_or("Versi development wasm not available")?, - )) -} diff --git a/substrate/bin/minimal/node/src/chain_spec.rs b/substrate/bin/minimal/node/src/chain_spec.rs index 71468f62bc8f..6b721deb6d1d 100644 --- a/substrate/bin/minimal/node/src/chain_spec.rs +++ b/substrate/bin/minimal/node/src/chain_spec.rs @@ -53,51 +53,3 @@ fn testnet_genesis() -> Value { "sudo": SudoConfig { key: Some(AccountKeyring::Alice.to_account_id()) }, }) } - -#[cfg(test)] -mod test { - use super::*; - use runtime::RuntimeGenesisConfig; - pub type LegacyChainSpec = sc_service::GenericChainSpec; - - fn development_config_legacy() -> Result { - Ok( - #[allow(deprecated)] - LegacyChainSpec::from_genesis( - "Development", - "dev", - ChainType::Development, - move || testnet_genesis_legacy(), - vec![], - None, - None, - None, - Some(props()), - None, - WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?, - ), - ) - } - - /// Configure initial storage state for FRAME pallets (legacy version). - fn testnet_genesis_legacy() -> RuntimeGenesisConfig { - use frame::traits::Get; - use runtime::interface::{Balance, MinimumBalance}; - let endowment = >::get().max(1) * 1000; - let balances = AccountKeyring::iter() - .map(|a| (a.to_account_id(), endowment)) - .collect::>(); - RuntimeGenesisConfig { - balances: BalancesConfig { balances }, - sudo: SudoConfig { key: Some(AccountKeyring::Alice.to_account_id()) }, - ..Default::default() - } - } - - #[test] - fn legacy_vs_json_based_chainspec_check() { - let j1 = development_config().unwrap().as_json(true).unwrap(); - let j2 = development_config_legacy().unwrap().as_json(true).unwrap(); - assert_eq!(j1, j2); - } -} diff --git a/substrate/bin/node/cli/src/chain_spec.rs b/substrate/bin/node/cli/src/chain_spec.rs index 65ba9ab8cf60..3559348d188c 100644 --- a/substrate/bin/node/cli/src/chain_spec.rs +++ b/substrate/bin/node/cli/src/chain_spec.rs @@ -496,309 +496,4 @@ pub(crate) mod tests { fn test_staging_test_net_chain_spec() { staging_testnet_config().build_storage().unwrap(); } - - // This compares the output of RuntimeGenesisConfig-based ChainSpec building against JSON-based - // ChainSpec building. Once RuntimeGenesisConfig is removed from client-side, entire mod can be - // removed. - mod json_vs_legacy { - use crate::chain_spec::*; - use kitchensink_runtime::{ - wasm_binary_unwrap, BabeConfig, BalancesConfig, CouncilConfig, DemocracyConfig, - ElectionsConfig, ImOnlineConfig, IndicesConfig, NominationPoolsConfig, SessionConfig, - SocietyConfig, StakingConfig, SudoConfig, TechnicalCommitteeConfig, - }; - use sp_runtime::BuildStorage; - /// Helper function to create RuntimeGenesisConfig for testing. - pub(super) fn testnet_genesis_legacy( - initial_authorities: Vec<( - AccountId, - AccountId, - GrandpaId, - BabeId, - ImOnlineId, - AuthorityDiscoveryId, - MixnetId, - )>, - initial_nominators: Vec, - root_key: AccountId, - endowed_accounts: Option>, - ) -> RuntimeGenesisConfig { - let (initial_authorities, endowed_accounts, num_endowed_accounts, stakers) = - configure_accounts( - initial_authorities, - initial_nominators, - endowed_accounts, - STASH, - ); - - RuntimeGenesisConfig { - system: Default::default(), - balances: BalancesConfig { - balances: endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect(), - }, - indices: IndicesConfig { indices: vec![] }, - session: SessionConfig { - keys: initial_authorities - .iter() - .map(|x| { - ( - x.0.clone(), - x.0.clone(), - session_keys( - x.2.clone(), - x.3.clone(), - x.4.clone(), - x.5.clone(), - x.6.clone(), - ), - ) - }) - .collect::>(), - }, - staking: StakingConfig { - validator_count: initial_authorities.len() as u32, - minimum_validator_count: initial_authorities.len() as u32, - invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(), - slash_reward_fraction: Perbill::from_percent(10), - stakers, - ..Default::default() - }, - democracy: DemocracyConfig::default(), - elections: ElectionsConfig { - members: endowed_accounts - .iter() - .take((num_endowed_accounts + 1) / 2) - .cloned() - .map(|member| (member, STASH)) - .collect(), - }, - council: CouncilConfig::default(), - technical_committee: TechnicalCommitteeConfig { - members: endowed_accounts - .iter() - .take((num_endowed_accounts + 1) / 2) - .cloned() - .collect(), - phantom: Default::default(), - }, - sudo: SudoConfig { key: Some(root_key) }, - babe: BabeConfig { - epoch_config: Some(kitchensink_runtime::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() - }, - im_online: ImOnlineConfig { keys: vec![] }, - authority_discovery: Default::default(), - grandpa: Default::default(), - technical_membership: Default::default(), - treasury: Default::default(), - society: SocietyConfig { pot: 0 }, - vesting: Default::default(), - assets: pallet_assets::GenesisConfig { - // This asset is used by the NIS pallet as counterpart currency. - assets: vec![( - 9, - get_account_id_from_seed::("Alice"), - true, - 1, - )], - ..Default::default() - }, - pool_assets: Default::default(), - transaction_storage: Default::default(), - transaction_payment: Default::default(), - alliance: Default::default(), - safe_mode: Default::default(), - tx_pause: Default::default(), - alliance_motion: Default::default(), - nomination_pools: NominationPoolsConfig { - min_create_bond: 10 * DOLLARS, - min_join_bond: 1 * DOLLARS, - ..Default::default() - }, - glutton: Default::default(), - mixnet: Default::default(), - } - } - - fn development_config_genesis_legacy() -> RuntimeGenesisConfig { - testnet_genesis_legacy( - vec![authority_keys_from_seed("Alice")], - vec![], - get_account_id_from_seed::("Alice"), - None, - ) - } - - /// Development config (single validator Alice). Legacy building method, for testing. - fn development_config_legacy() -> ChainSpec { - #[allow(deprecated)] - ChainSpec::from_genesis( - "Development", - "dev", - ChainType::Development, - development_config_genesis_legacy, - vec![], - None, - None, - None, - None, - Default::default(), - wasm_binary_unwrap(), - ) - } - - #[test] - fn development_config_building_test() { - sp_tracing::try_init_simple(); - let j1 = development_config().as_json(true).unwrap(); - let j2 = development_config_legacy().as_json(true).unwrap(); - assert_eq!(j1, j2); - } - - pub(super) fn local_testnet_genesis_legacy() -> RuntimeGenesisConfig { - testnet_genesis_legacy( - vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")], - vec![], - get_account_id_from_seed::("Alice"), - None, - ) - } - /// Local testnet config (multivalidator Alice + Bob). Legacy building method, for testing. - fn local_testnet_config_legacy() -> ChainSpec { - #[allow(deprecated)] - ChainSpec::from_genesis( - "Local Testnet", - "local_testnet", - ChainType::Local, - local_testnet_genesis_legacy, - vec![], - None, - None, - None, - None, - Default::default(), - wasm_binary_unwrap(), - ) - } - - #[test] - fn local_testnet_config_building_test() { - sp_tracing::try_init_simple(); - let j1 = local_testnet_config().as_json(true).unwrap(); - let j2 = local_testnet_config_legacy().as_json(true).unwrap(); - assert_eq!(j1, j2); - } - - fn staging_testnet_config_genesis_legacy() -> RuntimeGenesisConfig { - let (initial_authorities, root_key, endowed_accounts) = - configure_accounts_for_staging_testnet(); - testnet_genesis_legacy(initial_authorities, vec![], root_key, Some(endowed_accounts)) - } - - /// Staging testnet config. Legacy building method, for testing. - fn staging_testnet_config_legacy() -> ChainSpec { - let boot_nodes = vec![]; - #[allow(deprecated)] - ChainSpec::from_genesis( - "Staging Testnet", - "staging_testnet", - ChainType::Live, - staging_testnet_config_genesis_legacy, - boot_nodes, - Some( - TelemetryEndpoints::new(vec![(STAGING_TELEMETRY_URL.to_string(), 0)]) - .expect("Staging telemetry url is valid; qed"), - ), - None, - None, - None, - Default::default(), - wasm_binary_unwrap(), - ) - } - - fn hex(x: T) -> String - where - T: array_bytes::Hex, - { - x.hex(Default::default()) - } - - #[test] - fn staging_testnet_config_building_test() { - sp_tracing::try_init_simple(); - - let chain_spec = staging_testnet_config(); - let storage = chain_spec.build_storage().unwrap(); - let mut keys = storage.top.keys().cloned().map(hex).collect::>(); - keys.sort(); - - let chain_spec = staging_testnet_config_legacy(); - let storage = chain_spec.build_storage().unwrap(); - let mut keys_expected = storage.top.keys().cloned().map(hex).collect::>(); - keys_expected.sort(); - assert_eq!(keys, keys_expected); - } - - fn local_testnet_genesis_instant_single_legacy() -> RuntimeGenesisConfig { - testnet_genesis_legacy( - vec![authority_keys_from_seed("Alice")], - vec![], - get_account_id_from_seed::("Alice"), - None, - ) - } - - /// Local testnet config (single validator - Alice) - pub(super) fn integration_test_config_with_single_authority_legacy() -> ChainSpec { - #[allow(deprecated)] - ChainSpec::from_genesis( - "Integration Test", - "test", - ChainType::Development, - local_testnet_genesis_instant_single_legacy, - vec![], - None, - None, - None, - None, - Default::default(), - wasm_binary_unwrap(), - ) - } - - #[test] - fn integration_test_config_with_single_authority_legacy_compare_test() { - sp_tracing::try_init_simple(); - let j1 = integration_test_config_with_single_authority_legacy().as_json(true).unwrap(); - let j2 = super::integration_test_config_with_single_authority().as_json(true).unwrap(); - assert_eq!(j1, j2); - } - - /// Local testnet config (multivalidator Alice + Bob) - pub fn integration_test_config_with_two_authorities_legacy() -> ChainSpec { - #[allow(deprecated)] - ChainSpec::from_genesis( - "Integration Test", - "test", - ChainType::Development, - local_testnet_genesis_legacy, - vec![], - None, - None, - None, - None, - Default::default(), - wasm_binary_unwrap(), - ) - } - - #[test] - fn integration_test_config_with_with_two_authorities_compare_test() { - sp_tracing::try_init_simple(); - let j1 = integration_test_config_with_two_authorities_legacy().as_json(true).unwrap(); - let j2 = super::integration_test_config_with_two_authorities().as_json(true).unwrap(); - assert_eq!(j1, j2); - } - } } From 45a03d6beffa0ce60abae2eba27ae51250ac47c1 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Sun, 5 Nov 2023 14:22:40 +0100 Subject: [PATCH 98/98] zombienet image bumped --- .gitlab-ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a8e5d42805c5..f507afda23e3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,8 +30,7 @@ variables: RUSTY_CACHIER_COMPRESSION_METHOD: zstd NEXTEST_FAILURE_OUTPUT: immediate-final NEXTEST_SUCCESS_OUTPUT: final - #todo: remove once zombienet is released: - ZOMBIENET_IMAGE: "docker.io/paritypr/zombienet:df998b63" + ZOMBIENET_IMAGE: "docker.io/paritytech/zombienet:v1.3.79" DOCKER_IMAGES_VERSION: "${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHORT_SHA}" default: