diff --git a/cli/src/chain_spec.rs b/cli/src/chain_spec.rs index f6fa86e11af0..8c00c6d9b64f 100644 --- a/cli/src/chain_spec.rs +++ b/cli/src/chain_spec.rs @@ -22,16 +22,22 @@ use service; /// specification). #[derive(Clone, Debug)] pub enum ChainSpec { - /// Whatever the current runtime is, with just Alice as an auth. - Development, - /// Whatever the current runtime is, with simple Alice/Bob auths. - LocalTestnet, + /// Whatever the current polkadot runtime is, with just Alice as an auth. + PolkadotDevelopment, + /// Whatever the current pokadot runtime is, with simple Alice/Bob auths. + PolkadotLocalTestnet, /// The Kusama network. Kusama, + /// Whatever the current kusama runtime is, with just Alice as an auth. + KusamaDevelopment, /// The Westend network, Westend, - /// Whatever the current runtime is with the "global testnet" defaults. - StagingTestnet, + /// Whatever the current polkadot runtime is with the "global testnet" defaults. + PolkadotStagingTestnet, + /// Whatever the current kusama runtime is with the "global testnet" defaults. + KusamaStagingTestnet, + /// Whatever the current kusama runtime is, with simple Alice/Bob auths. + KusamaLocalTestnet, } impl Default for ChainSpec { @@ -42,23 +48,29 @@ impl Default for ChainSpec { /// Get a chain config from a spec setting. impl ChainSpec { - pub(crate) fn load(self) -> Result { - match self { - ChainSpec::Development => Ok(service::chain_spec::development_config()), - ChainSpec::LocalTestnet => Ok(service::chain_spec::local_testnet_config()), - ChainSpec::StagingTestnet => Ok(service::chain_spec::staging_testnet_config()), - ChainSpec::Westend => service::chain_spec::westend_config(), - ChainSpec::Kusama => service::chain_spec::kusama_config(), - } + pub(crate) fn load(self) -> Result, String> { + Ok(match self { + ChainSpec::PolkadotDevelopment => Box::new(service::chain_spec::polkadot_development_config()), + ChainSpec::PolkadotLocalTestnet => Box::new(service::chain_spec::polkadot_local_testnet_config()), + ChainSpec::PolkadotStagingTestnet => Box::new(service::chain_spec::polkadot_staging_testnet_config()), + ChainSpec::KusamaDevelopment =>Box::new(service::chain_spec::kusama_development_config()), + ChainSpec::KusamaLocalTestnet => Box::new(service::chain_spec::kusama_local_testnet_config()), + ChainSpec::KusamaStagingTestnet => Box::new(service::chain_spec::kusama_staging_testnet_config()), + ChainSpec::Westend => Box::new(service::chain_spec::westend_config()?), + ChainSpec::Kusama => Box::new(service::chain_spec::kusama_config()?), + }) } pub(crate) fn from(s: &str) -> Option { match s { - "dev" => Some(ChainSpec::Development), - "local" => Some(ChainSpec::LocalTestnet), + "polkadot-dev" => Some(ChainSpec::PolkadotDevelopment), + "polkadot-local" => Some(ChainSpec::PolkadotLocalTestnet), + "polkadot-staging" => Some(ChainSpec::PolkadotStagingTestnet), + "kusama-dev" => Some(ChainSpec::KusamaDevelopment), + "kusama-local" => Some(ChainSpec::KusamaLocalTestnet), + "kusama-staging" => Some(ChainSpec::KusamaStagingTestnet), "kusama" => Some(ChainSpec::Kusama), "westend" => Some(ChainSpec::Westend), - "staging" => Some(ChainSpec::StagingTestnet), "" => Some(ChainSpec::default()), _ => None, } @@ -66,9 +78,11 @@ impl ChainSpec { } /// Load the `ChainSpec` for the given `id`. -pub fn load_spec(id: &str) -> Result, String> { +/// `force_kusama` treats chain specs coming from a file as kusama specs. +pub fn load_spec(id: &str, force_kusama: bool) -> Result, String> { Ok(match ChainSpec::from(id) { - Some(spec) => Some(spec.load()?), - None => None, + Some(spec) => spec.load()?, + None if force_kusama => Box::new(service::KusamaChainSpec::from_json_file(std::path::PathBuf::from(id))?), + None => Box::new(service::PolkadotChainSpec::from_json_file(std::path::PathBuf::from(id))?), }) } diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 89ecf411f477..e995effcaefa 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -17,7 +17,6 @@ //! Polkadot CLI library. use structopt::StructOpt; -pub use sc_cli::RunCmd; #[allow(missing_docs)] #[derive(Debug, StructOpt, Clone)] @@ -45,6 +44,18 @@ pub struct ValidationWorkerCommand { pub mem_id: String, } +#[allow(missing_docs)] +#[derive(Debug, StructOpt, Clone)] +pub struct RunCmd { + #[allow(missing_docs)] + #[structopt(flatten)] + pub base: sc_cli::RunCmd, + + /// Force using Kusama native runtime. + #[structopt(long = "force-kusama")] + pub force_kusama: bool, +} + #[allow(missing_docs)] #[derive(Debug, StructOpt, Clone)] #[structopt(settings = &[ diff --git a/cli/src/command.rs b/cli/src/command.rs index 131d7f98cc98..009b138703b7 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -29,13 +29,18 @@ pub fn run(version: VersionInfo) -> sc_cli::Result<()> { let mut config = service::Configuration::from_version(&version); config.impl_name = "parity-polkadot"; + let force_kusama = opt.run.force_kusama; match opt.subcommand { None => { - opt.run.init(&version)?; - opt.run.update_config(&mut config, load_spec, &version)?; + opt.run.base.init(&version)?; + opt.run.base.update_config( + &mut config, + |id| load_spec(id, force_kusama), + &version + )?; - let is_kusama = config.chain_spec.as_ref().map_or(false, |s| s.is_kusama()); + let is_kusama = config.expect_chain_spec().is_kusama(); info!("{}", version.name); info!(" version {}", config.full_version()); @@ -69,9 +74,13 @@ pub fn run(version: VersionInfo) -> sc_cli::Result<()> { }, Some(Subcommand::Base(cmd)) => { cmd.init(&version)?; - cmd.update_config(&mut config, load_spec, &version)?; + cmd.update_config( + &mut config, + |id| load_spec(id, force_kusama), + &version + )?; - let is_kusama = config.chain_spec.as_ref().map_or(false, |s| s.is_kusama()); + let is_kusama = config.expect_chain_spec().is_kusama(); if is_kusama { cmd.run(config, service::new_chain_ops::< diff --git a/service/src/chain_spec.rs b/service/src/chain_spec.rs index 699d7368765d..f67ca26793cd 100644 --- a/service/src/chain_spec.rs +++ b/service/src/chain_spec.rs @@ -19,7 +19,9 @@ use sp_core::{Pair, Public, crypto::UncheckedInto, sr25519}; use polkadot_primitives::{AccountId, AccountPublic, parachain::ValidatorId}; use polkadot_runtime as polkadot; -use polkadot_runtime::constants::currency::DOTS; +use kusama_runtime as kusama; +use polkadot::constants::currency::DOTS; +use kusama::constants::currency::DOTS as KSM; use sc_chain_spec::ChainSpecExtension; use sp_runtime::{traits::IdentifyAccount, Perbill}; use serde::{Serialize, Deserialize}; @@ -31,7 +33,8 @@ use im_online::sr25519::{AuthorityId as ImOnlineId}; use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; use pallet_staking::Forcing; -const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; +const POLKADOT_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; +const KUSAMA_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; const DEFAULT_PROTOCOL_ID: &str = "dot"; /// Node `ChainSpec` extensions. @@ -47,24 +50,27 @@ pub struct Extensions { pub bad_blocks: sc_client::BadBlocks, } -/// The `ChainSpec`. -/// -/// We use the same `ChainSpec` type for Polkadot and Kusama. As Kusama -/// is only loaded from a file, the `GenesisConfig` type is not used. -pub type ChainSpec = service::ChainSpec< +/// The `ChainSpec parametrised for polkadot runtime`. +pub type PolkadotChainSpec = service::GenericChainSpec< polkadot::GenesisConfig, Extensions, >; -pub fn kusama_config() -> Result { - ChainSpec::from_json_bytes(&include_bytes!("../res/kusama.json")[..]) +/// The `ChainSpec parametrised for kusama runtime`. +pub type KusamaChainSpec = service::GenericChainSpec< + kusama::GenesisConfig, + Extensions, +>; + +pub fn kusama_config() -> Result { + KusamaChainSpec::from_json_bytes(&include_bytes!("../res/kusama.json")[..]) } -pub fn westend_config() -> Result { - ChainSpec::from_json_bytes(&include_bytes!("../res/westend.json")[..]) +pub fn westend_config() -> Result { + PolkadotChainSpec::from_json_bytes(&include_bytes!("../res/westend.json")[..]) } -fn session_keys( +fn polkadot_session_keys( babe: BabeId, grandpa: GrandpaId, im_online: ImOnlineId, @@ -74,18 +80,20 @@ fn session_keys( polkadot::SessionKeys { babe, grandpa, im_online, parachain_validator, authority_discovery } } -fn staging_testnet_config_genesis() -> polkadot::GenesisConfig { +fn kusama_session_keys( + babe: BabeId, + grandpa: GrandpaId, + im_online: ImOnlineId, + parachain_validator: ValidatorId, + authority_discovery: AuthorityDiscoveryId +) -> kusama::SessionKeys { + kusama::SessionKeys { babe, grandpa, im_online, parachain_validator, authority_discovery } +} + +fn polkadot_staging_testnet_config_genesis() -> polkadot::GenesisConfig { // subkey inspect "$SECRET" - let endowed_accounts = vec![ - // 5CVFESwfkk7NmhQ6FwHCM9roBvr9BGa4vJHFYU8DnGQxrXvz - hex!["12b782529c22032ed4694e0f6e7d486be7daa6d12088f6bc74d593b3900b8438"].into(), - ]; + let endowed_accounts = vec![]; - // 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 parachains; do subkey --sr25519 inspect "$SECRET//$i//$j"; done; done let initial_authorities: Vec<( AccountId, AccountId, @@ -94,67 +102,7 @@ fn staging_testnet_config_genesis() -> polkadot::GenesisConfig { ImOnlineId, ValidatorId, 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(), - ),( - // 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(), - ),( - // 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(), - ),( - // 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(), - )]; + )> = vec![]; const ENDOWMENT: u128 = 1_000_000 * DOTS; const STASH: u128 = 100 * DOTS; @@ -177,7 +125,7 @@ fn staging_testnet_config_genesis() -> polkadot::GenesisConfig { 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()), + polkadot_session_keys(x.2.clone(), x.3.clone(), x.4.clone(), x.5.clone(), x.6.clone()), )).collect::>(), }), staking: Some(polkadot::StakingConfig { @@ -228,15 +176,181 @@ fn staging_testnet_config_genesis() -> polkadot::GenesisConfig { } } +fn kusama_staging_testnet_config_genesis() -> kusama::GenesisConfig { + // 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 parachains; do subkey --sr25519 inspect "$SECRET//$i//$j"; done; done + let initial_authorities: Vec<( + AccountId, + AccountId, + BabeId, + GrandpaId, + ImOnlineId, + ValidatorId, + 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(), + ),( + // 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(), + ),( + // 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(), + ),( + // 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(), + )]; + + const ENDOWMENT: u128 = 1_000_000 * KSM; + const STASH: u128 = 100 * KSM; + + kusama::GenesisConfig { + system: Some(kusama::SystemConfig { + code: kusama::WASM_BINARY.to_vec(), + changes_trie_config: Default::default(), + }), + balances: Some(kusama::BalancesConfig { + balances: endowed_accounts.iter() + .map(|k: &AccountId| (k.clone(), ENDOWMENT)) + .chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH))) + .collect(), + }), + indices: Some(kusama::IndicesConfig { + indices: vec![], + }), + session: Some(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()), + )).collect::>(), + }), + staking: Some(kusama::StakingConfig { + validator_count: 50, + minimum_validator_count: 4, + stakers: initial_authorities + .iter() + .map(|x| (x.0.clone(), x.1.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() + }), + democracy: Some(Default::default()), + collective_Instance1: Some(kusama::CouncilConfig { + members: vec![], + phantom: Default::default(), + }), + collective_Instance2: Some(kusama::TechnicalCommitteeConfig { + members: vec![], + phantom: Default::default(), + }), + membership_Instance1: Some(Default::default()), + babe: Some(Default::default()), + grandpa: Some(Default::default()), + im_online: Some(Default::default()), + authority_discovery: Some(kusama::AuthorityDiscoveryConfig { + keys: vec![], + }), + parachains: Some(kusama::ParachainsConfig { + authorities: vec![], + }), + registrar: Some(kusama::RegistrarConfig { + parachains: vec![], + _phdata: Default::default(), + }), + claims: Some(kusama::ClaimsConfig { + claims: vec![], + vesting: vec![], + }), + vesting: Some(kusama::VestingConfig { + vesting: vec![], + }), + } +} + +/// Polkadot staging testnet config. +pub fn polkadot_staging_testnet_config() -> PolkadotChainSpec { + let boot_nodes = vec![]; + PolkadotChainSpec::from_genesis( + "Polkadot Staging Testnet", + "polkadot_staging_testnet", + polkadot_staging_testnet_config_genesis, + boot_nodes, + Some(TelemetryEndpoints::new(vec![(POLKADOT_STAGING_TELEMETRY_URL.to_string(), 0)])), + Some(DEFAULT_PROTOCOL_ID), + None, + Default::default(), + ) +} + /// Staging testnet config. -pub fn staging_testnet_config() -> ChainSpec { +pub fn kusama_staging_testnet_config() -> KusamaChainSpec { let boot_nodes = vec![]; - ChainSpec::from_genesis( - "Staging Testnet", - "staging_testnet", - staging_testnet_config_genesis, + KusamaChainSpec::from_genesis( + "Kusama Staging Testnet", + "kusama_staging_testnet", + kusama_staging_testnet_config_genesis, boot_nodes, - Some(TelemetryEndpoints::new(vec![(STAGING_TELEMETRY_URL.to_string(), 0)])), + Some(TelemetryEndpoints::new(vec![(KUSAMA_STAGING_TELEMETRY_URL.to_string(), 0)])), Some(DEFAULT_PROTOCOL_ID), None, Default::default(), @@ -279,28 +393,30 @@ pub fn get_authority_keys_from_seed(seed: &str) -> ( ) } -/// Helper function to create GenesisConfig for testing -pub fn testnet_genesis( +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 GenesisConfig for testing +pub fn polkadot_testnet_genesis( initial_authorities: Vec<(AccountId, AccountId, BabeId, GrandpaId, ImOnlineId, ValidatorId, AuthorityDiscoveryId)>, root_key: AccountId, endowed_accounts: Option>, ) -> polkadot::GenesisConfig { - let endowed_accounts: Vec = endowed_accounts.unwrap_or_else(|| { - 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"), - ] - }); + let endowed_accounts: Vec = endowed_accounts.unwrap_or_else(testnet_accounts); const ENDOWMENT: u128 = 1_000_000 * DOTS; const STASH: u128 = 100 * DOTS; @@ -318,10 +434,10 @@ pub fn testnet_genesis( }), session: Some(polkadot::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::>(), + x.0.clone(), + x.0.clone(), + polkadot_session_keys(x.2.clone(), x.3.clone(), x.4.clone(), x.5.clone(), x.6.clone()), + )).collect::>(), }), staking: Some(polkadot::StakingConfig { minimum_validator_count: 1, @@ -329,10 +445,10 @@ pub fn testnet_genesis( stakers: initial_authorities.iter() .map(|x| (x.0.clone(), x.1.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() + invulnerables: initial_authorities.iter().map(|x| x.0.clone()).collect(), + force_era: Forcing::NotForcing, + slash_reward_fraction: Perbill::from_percent(10), + .. Default::default() }), democracy: Some(polkadot::DemocracyConfig::default()), collective_Instance1: Some(polkadot::CouncilConfig { @@ -370,8 +486,81 @@ pub fn testnet_genesis( } } -fn development_config_genesis() -> polkadot::GenesisConfig { - testnet_genesis( +/// Helper function to create kusama GenesisConfig for testing +pub fn kusama_testnet_genesis( + initial_authorities: Vec<(AccountId, AccountId, BabeId, GrandpaId, ImOnlineId, ValidatorId, AuthorityDiscoveryId)>, + _root_key: AccountId, + endowed_accounts: Option>, +) -> kusama::GenesisConfig { + let endowed_accounts: Vec = endowed_accounts.unwrap_or_else(testnet_accounts); + + const ENDOWMENT: u128 = 1_000_000 * KSM; + const STASH: u128 = 100 * KSM; + + kusama::GenesisConfig { + system: Some(kusama::SystemConfig { + code: kusama::WASM_BINARY.to_vec(), + changes_trie_config: Default::default(), + }), + indices: Some(kusama::IndicesConfig { + indices: vec![], + }), + balances: Some(kusama::BalancesConfig { + balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(), + }), + session: Some(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()), + )).collect::>(), + }), + staking: Some(kusama::StakingConfig { + minimum_validator_count: 1, + validator_count: 2, + stakers: initial_authorities.iter() + .map(|x| (x.0.clone(), x.1.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() + }), + democracy: Some(kusama::DemocracyConfig::default()), + collective_Instance1: Some(kusama::CouncilConfig { + members: vec![], + phantom: Default::default(), + }), + collective_Instance2: Some(kusama::TechnicalCommitteeConfig { + members: vec![], + phantom: Default::default(), + }), + membership_Instance1: Some(Default::default()), + babe: Some(Default::default()), + grandpa: Some(Default::default()), + im_online: Some(Default::default()), + authority_discovery: Some(kusama::AuthorityDiscoveryConfig { + keys: vec![], + }), + parachains: Some(kusama::ParachainsConfig { + authorities: vec![], + }), + registrar: Some(kusama::RegistrarConfig{ + parachains: vec![], + _phdata: Default::default(), + }), + claims: Some(kusama::ClaimsConfig { + claims: vec![], + vesting: vec![], + }), + vesting: Some(kusama::VestingConfig { + vesting: vec![], + }), + } +} + +fn polkadot_development_config_genesis() -> polkadot::GenesisConfig { + polkadot_testnet_genesis( vec![ get_authority_keys_from_seed("Alice"), ], @@ -380,12 +569,36 @@ fn development_config_genesis() -> polkadot::GenesisConfig { ) } -/// Development config (single validator Alice) -pub fn development_config() -> ChainSpec { - ChainSpec::from_genesis( +fn kusama_development_config_genesis() -> kusama::GenesisConfig { + kusama_testnet_genesis( + vec![ + get_authority_keys_from_seed("Alice"), + ], + get_account_id_from_seed::("Alice"), + None, + ) +} + +/// Polkadot development config (single validator Alice) +pub fn polkadot_development_config() -> PolkadotChainSpec { + PolkadotChainSpec::from_genesis( "Development", "dev", - development_config_genesis, + polkadot_development_config_genesis, + vec![], + None, + Some(DEFAULT_PROTOCOL_ID), + None, + Default::default(), + ) +} + +/// Kusama development config (single validator Alice) +pub fn kusama_development_config() -> KusamaChainSpec { + KusamaChainSpec::from_genesis( + "Development", + "kusama_dev", + kusama_development_config_genesis, vec![], None, Some(DEFAULT_PROTOCOL_ID), @@ -394,8 +607,8 @@ pub fn development_config() -> ChainSpec { ) } -fn local_testnet_genesis() -> polkadot::GenesisConfig { - testnet_genesis( +fn polkadot_local_testnet_genesis() -> polkadot::GenesisConfig { + polkadot_testnet_genesis( vec![ get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob"), @@ -405,12 +618,37 @@ fn local_testnet_genesis() -> polkadot::GenesisConfig { ) } -/// Local testnet config (multivalidator Alice + Bob) -pub fn local_testnet_config() -> ChainSpec { - ChainSpec::from_genesis( +/// Polkadot local testnet config (multivalidator Alice + Bob) +pub fn polkadot_local_testnet_config() -> PolkadotChainSpec { + PolkadotChainSpec::from_genesis( "Local Testnet", "local_testnet", - local_testnet_genesis, + polkadot_local_testnet_genesis, + vec![], + None, + Some(DEFAULT_PROTOCOL_ID), + None, + Default::default(), + ) +} + +fn kusama_local_testnet_genesis() -> kusama::GenesisConfig { + kusama_testnet_genesis( + vec![ + get_authority_keys_from_seed("Alice"), + get_authority_keys_from_seed("Bob"), + ], + get_account_id_from_seed::("Alice"), + None, + ) +} + +/// Kusama local testnet config (multivalidator Alice + Bob) +pub fn kusama_local_testnet_config() -> KusamaChainSpec { + KusamaChainSpec::from_genesis( + "Kusama Local Testnet", + "kusama_local_testnet", + kusama_local_testnet_genesis, vec![], None, Some(DEFAULT_PROTOCOL_ID), diff --git a/service/src/lib.rs b/service/src/lib.rs index e4a66120107d..25c87c977cd4 100644 --- a/service/src/lib.rs +++ b/service/src/lib.rs @@ -32,6 +32,7 @@ use log::info; pub use service::{ AbstractService, Roles, PruningMode, TransactionPoolOptions, Error, RuntimeGenesis, ServiceBuilderCommand, TFullClient, TLightClient, TFullBackend, TLightBackend, TFullCallExecutor, TLightCallExecutor, + Configuration, ChainSpec, }; pub use service::config::{DatabaseConfig, PrometheusConfig, full_version_from_strs}; pub use sc_executor::NativeExecutionDispatch; @@ -43,7 +44,7 @@ pub use consensus_common::SelectChain; pub use polkadot_primitives::parachain::{CollatorId, ParachainHost}; pub use polkadot_primitives::Block; pub use sp_runtime::traits::{Block as BlockT, self as runtime_traits, BlakeTwo256}; -pub use chain_spec::ChainSpec; +pub use chain_spec::{PolkadotChainSpec, KusamaChainSpec}; #[cfg(not(target_os = "unknown"))] pub use consensus::run_validation_worker; pub use codec::Codec; @@ -51,14 +52,6 @@ pub use polkadot_runtime; pub use kusama_runtime; use prometheus_endpoint::Registry; -/// Configuration type that is being used. -/// -/// See [`ChainSpec`] for more information why Polkadot `GenesisConfig` is safe here. -pub type Configuration = service::Configuration< - polkadot_runtime::GenesisConfig, - chain_spec::Extensions, ->; - native_executor_instance!( pub PolkadotExecutor, polkadot_runtime::api::dispatch, @@ -121,9 +114,9 @@ pub trait IsKusama { fn is_kusama(&self) -> bool; } -impl IsKusama for ChainSpec { +impl IsKusama for &dyn ChainSpec { fn is_kusama(&self) -> bool { - self.name().starts_with("Kusama") + self.id().starts_with("kusama") || self.id().starts_with("ksm") } } diff --git a/test-parachains/adder/collator/src/main.rs b/test-parachains/adder/collator/src/main.rs index 4f28fdc0720b..69772181382d 100644 --- a/test-parachains/adder/collator/src/main.rs +++ b/test-parachains/adder/collator/src/main.rs @@ -133,7 +133,7 @@ fn main() { }; let mut config = Configuration::default(); - config.chain_spec = load_spec("dev").unwrap(); + config.chain_spec = Some(load_spec("dev", false).unwrap()); let res = collator::run_collator( context,