From 28d5d8aec848cd438be864e951760fad61e90b0c Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Fri, 21 Jun 2024 19:38:14 +0800 Subject: [PATCH] paritytech/polkadot-sdk#1256 --- Cargo.lock | 1 + node/Cargo.toml | 1 + node/src/chain_spec/crab.rs | 491 +++++++++++++------------------- node/src/chain_spec/darwinia.rs | 478 ++++++++++++------------------- node/src/chain_spec/koi.rs | 433 ++++++++++------------------ node/src/chain_spec/mod.rs | 49 ++-- node/src/command.rs | 42 +-- 7 files changed, 584 insertions(+), 911 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dc403c2a2..f4f7276ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2692,6 +2692,7 @@ dependencies = [ "sc-transaction-pool", "sc-transaction-pool-api", "serde", + "serde_json", "sp-api", "sp-block-builder", "sp-blockchain", diff --git a/node/Cargo.toml b/node/Cargo.toml index 41682b310..57c46fdff 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -18,6 +18,7 @@ futures = { version = "0.3" } jsonrpsee = { version = "0.16", features = ["server"] } log = { version = "0.4" } serde = { version = "1.0", features = ["derive"] } +serde_json = { version = "1.0" } tokio = { version = "1.33" } trauma = { version = "2.2" } diff --git a/node/src/chain_spec/crab.rs b/node/src/chain_spec/crab.rs index 4c4c6cba3..92520db34 100644 --- a/node/src/chain_spec/crab.rs +++ b/node/src/chain_spec/crab.rs @@ -37,311 +37,50 @@ use sc_service::{ChainType, GenericChainSpec}; use sc_telemetry::TelemetryEndpoints; use sp_core::{crypto::UncheckedInto, H160}; -/// Specialized `ChainSpec` for the normal parachain runtime. -pub type ChainSpec = GenericChainSpec; +const PARA_ID: u32 = 2105; -fn properties() -> Properties { - super::properties("CRAB") -} - -// 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). -fn session_keys(keys: AuraId) -> SessionKeys { - SessionKeys { aura: keys } -} +// FIXME: https://github.com/paritytech/polkadot-sdk/issues/4853. pub fn development_config() -> ChainSpec { - ChainSpec::from_genesis( - // Fulfill Polkadot.JS metadata upgrade requirements. - "Crab2 D", - "crab2-d", - ChainType::Live, - move || { - testnet_genesis( - vec![ - // Bind the `Alice` to `Alith` to make `--alice` available for testnet. - ( - array_bytes::hex_n_into_unchecked::<_, _, 20>(ALITH), - get_collator_keys_from_seed("Alice"), - ), - ], - vec![ - array_bytes::hex_n_into_unchecked::<_, _, 20>(ALITH), - array_bytes::hex_n_into_unchecked::<_, _, 20>(BALTATHAR), - array_bytes::hex_n_into_unchecked::<_, _, 20>(CHARLETH), - array_bytes::hex_n_into_unchecked::<_, _, 20>(DOROTHY), - array_bytes::hex_n_into_unchecked::<_, _, 20>(ETHAN), - array_bytes::hex_n_into_unchecked::<_, _, 20>(FAITH), - ], - 2105.into(), - ) - }, - Vec::new(), - None, - Some(PROTOCOL_ID), - None, - Some(properties()), - Extensions { - relay_chain: "rococo-local".into(), // You MUST set this to the correct network! - para_id: 2105, - }, - ) -} - -pub fn local_config() -> ChainSpec { - ChainSpec::from_genesis( - // Fulfill Polkadot.JS metadata upgrade requirements. - "Crab2 L", - "crab2-l", - ChainType::Live, - move || { - testnet_genesis( - vec![ - // Bind the `Alice` to `Alith` to make `--alice` available for testnet. - ( - array_bytes::hex_n_into_unchecked::<_, _, 20>(ALITH), - get_collator_keys_from_seed("Alice"), - ), - // Bind the `Bob` to `Balthar` to make `--bob` available for testnet. - ( - array_bytes::hex_n_into_unchecked::<_, _, 20>(BALTATHAR), - get_collator_keys_from_seed("Bob"), - ), - // Bind the `Charlie` to `CHARLETH` to make `--charlie` available for testnet. - ( - array_bytes::hex_n_into_unchecked::<_, _, 20>(CHARLETH), - get_collator_keys_from_seed("Charlie"), - ), - ], - vec![ - array_bytes::hex_n_into_unchecked::<_, _, 20>(ALITH), - array_bytes::hex_n_into_unchecked::<_, _, 20>(BALTATHAR), - array_bytes::hex_n_into_unchecked::<_, _, 20>(CHARLETH), - array_bytes::hex_n_into_unchecked::<_, _, 20>(DOROTHY), - array_bytes::hex_n_into_unchecked::<_, _, 20>(ETHAN), - array_bytes::hex_n_into_unchecked::<_, _, 20>(FAITH), - ], - 2105.into(), - ) - }, - Vec::new(), - None, - Some(PROTOCOL_ID), - None, - Some(properties()), - Extensions { - relay_chain: "rococo-local".into(), // You MUST set this to the correct network! - para_id: 2105, - }, - ) -} - -pub fn genesis_config() -> ChainSpec { - let collators = [ - ( - "0x196f03b77a1acd0db080006b04d2f3a991ebbe68", - "0xa05255010ee986b9684a444d10a74aa0ecbe781f5002e871665add894752cc7e", - ), - ( - "0x4D3D5958B948e8d749FaB0236b179fCC55d9aAc0", - "0xf8f82edfc6899552e5a32aa381e53723d2c39594638cb8f7e2572fef74b05255", - ), - ( - "0x7aE2a0914db8bFBdad538b0eAc3Fa473A0e07843", - "0xdaf5c4506b82f617245150216a73c0eb4f2603848c02413db66f991846777845", - ), - ( - "0x9F33a4809aA708d7a399fedBa514e0A0d15EfA85", - "0xdcff1219121687391353b17e798b10e87f6e578b2a01e032375f2f14a0712b57", - ), - ( - "0x0a1287977578F888bdc1c7627781AF1cc000e6ab", - "0x28a8af71db9703e6b8960d1dcb742deca13c574f81f781be5dbde84ec8d66d45", - ), - ( - "0xEB7e82A67CDFA3E742e0f3315Fd4EEd7B05730CC", - "0xfee21e4e4865380734882253d27612da0e4413c93e5c817e38b8c5e034de7270", - ), - ]; - - ChainSpec::from_genesis( - "Crab2", - "crab2", - ChainType::Live, - move || { - RuntimeGenesisConfig { - // System stuff. - system: SystemConfig { code: WASM_BINARY.unwrap().to_vec(), ..Default::default() }, - parachain_system: Default::default(), - parachain_info: ParachainInfoConfig { parachain_id: 2105.into(), ..Default::default() }, - - // Monetary stuff. - balances: BalancesConfig { - balances: collators - .iter() - .map(|(k, _)| (array_bytes::hex_n_into_unchecked::<_, _, 20>(k), 10_000 * UNIT)) - .collect(), - }, - transaction_payment: Default::default(), - assets: AssetsConfig { - assets: vec![(AssetIds::CKton as _, ROOT, true, 1)], - metadata: vec![( - AssetIds::CKton as _, - b"Crab Commitment Token".to_vec(), - b"CKTON".to_vec(), - 18, - )], - ..Default::default() - }, - vesting: Default::default(), - - // Consensus stuff. - darwinia_staking: DarwiniaStakingConfig { - now: SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(), - elapsed_time: 0, - rate_limit: 20_000_000 * UNIT, - collator_count: 6, - collators: collators - .iter() - .map(|(k, _)| (array_bytes::hex_n_into_unchecked::<_, _, 20>(k), 1_000 * UNIT)) - .collect(), - }, - session: SessionConfig { - keys: collators - .iter() - .map(|(k, a)| { - ( - array_bytes::hex_n_into_unchecked::<_, _, 20>(k), - array_bytes::hex_n_into_unchecked::<_, _, 20>(k), - session_keys(array_bytes::hex2array_unchecked(a).unchecked_into()), - ) - }) - .collect(), - }, - aura: Default::default(), - aura_ext: Default::default(), - - // Governance stuff. - technical_committee: Default::default(), - treasury: Default::default(), - - // Utility stuff. - tx_pause: Default::default(), - - // XCM stuff. - polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION), ..Default::default() }, - - // EVM stuff. - ethereum: Default::default(), - evm: EVMConfig { - accounts: { - BTreeMap::from_iter( - CrabPrecompiles::::used_addresses().iter().map(|p| { - ( - p.to_owned(), - GenesisAccount { - nonce: Default::default(), - balance: Default::default(), - storage: Default::default(), - code: REVERT_BYTECODE.to_vec(), - }, - ) - }), - ) - }, - ..Default::default() - }, - } - }, - vec![ - "/dns/g1.crab2.darwinia.network/tcp/30333/ws/p2p/12D3KooWEDiHG6pjt53HqnfYepnLzp9rFTh8MJrBX7AZeGShBMM4".parse().unwrap() - ], - TelemetryEndpoints::new(vec![(TELEMETRY_URL.into(), 0)]).ok(), - Some(PROTOCOL_ID), - None, - Some(properties()), - Extensions { - relay_chain: "kusama".into(), // You MUST set this to the correct network! - para_id: 2105, - }, - ) -} - -pub fn config() -> ChainSpec { - load_config("crab2.json", 0) -} - -fn testnet_genesis( - collators: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - id: ParaId, -) -> RuntimeGenesisConfig { - RuntimeGenesisConfig { + let (collators, endowed_accounts) = dev_accounts::(session_keys); + let genesis_config_patch = serde_json::json!({ // System stuff. - system: SystemConfig { code: WASM_BINARY.unwrap().to_vec(), ..Default::default() }, - parachain_system: Default::default(), - parachain_info: ParachainInfoConfig { parachain_id: id, ..Default::default() }, + "parachainInfo": { "parachainId": PARA_ID }, // Monetary stuff. - balances: BalancesConfig { - balances: endowed_accounts.iter().cloned().map(|k| (k, 100_000_000 * UNIT)).collect(), + "balances": { + "balances": endowed_accounts.iter().map(|a| (a, 100_000_000 * UNIT)).collect::>() }, - transaction_payment: Default::default(), - assets: AssetsConfig { - assets: vec![(AssetIds::CKton as _, ROOT, true, 1)], - metadata: vec![( - AssetIds::CKton as _, - b"Crab Commitment Token".to_vec(), - b"CKTON".to_vec(), - 18, - )], - ..Default::default() + "assets": { + "assets": [(AssetIds::CKton as u32, ROOT, true, 1)], + "metadata": [( + AssetIds::CKton as u32, + b"Crab Commitment Token", + b"CKTON", + 18 + )] }, - vesting: Default::default(), // Consensus stuff. - darwinia_staking: DarwiniaStakingConfig { - now: SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(), - elapsed_time: 0, - rate_limit: 20_000_000 * UNIT, - collator_count: collators.len() as _, - collators: collators.iter().map(|(a, _)| (a.to_owned(), UNIT)).collect(), + "darwiniaStaking": { + "now": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(), + "elapsedTime": 0, + "rateLimit": 20_000_000 * UNIT, + "collatorCount": collators.len(), + "collators": collators.iter().map(|(a, _)| (a, UNIT)).collect::>() }, - session: SessionConfig { - keys: collators - .into_iter() - .map(|(acc, aura)| { - ( - acc, // account id - acc, // validator id - session_keys(aura), // session keys - ) - }) - .collect(), + "session": { + "keys": collators.into_iter().map(|(a, sks)| (a, a, sks)).collect::>() }, - aura: Default::default(), - aura_ext: Default::default(), - - // Governance stuff. - technical_committee: Default::default(), - treasury: Default::default(), - - // Utility stuff. - tx_pause: Default::default(), // XCM stuff. - polkadot_xcm: PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, + "polkadotXcm": { "safeXcmVersion": Some(SAFE_XCM_VERSION) }, // EVM stuff. - ethereum: Default::default(), - evm: EVMConfig { - accounts: { + "evm": { + "accounts": { BTreeMap::from_iter( - CrabPrecompiles::::used_addresses() + >::used_addresses() .iter() .map(|p| { ( @@ -367,8 +106,178 @@ fn testnet_genesis( ), ]), ) - }, - ..Default::default() + } + } + }); + + ChainSpec::builder( + WASM_BINARY.unwrap().to_vec(), + Extensions { + relay_chain: "rococo-local".into(), // You MUST set this to the correct network! + para_id: PARA_ID, + }, + ) + .with_name("Crab2 D") + .with_id("crab2-d") + .with_chain_type(ChainType::Live) + .with_protocol_id(PROTOCOL_ID) + .with_properties(properties()) + .with_genesis_config_patch(genesis_config_patch) + .build() +} + +pub fn genesis_config() -> ChainSpec { + let collators = [ + ( + array_bytes::hex_n_into_unchecked::<_, AccountId, 20>( + "0x196f03b77a1acd0db080006b04d2f3a991ebbe68", + ), + session_keys( + array_bytes::hex2array_unchecked( + "0xa05255010ee986b9684a444d10a74aa0ecbe781f5002e871665add894752cc7e", + ) + .unchecked_into(), + ), + ), + ( + array_bytes::hex_n_into_unchecked::<_, AccountId, 20>( + "0x4D3D5958B948e8d749FaB0236b179fCC55d9aAc0", + ), + session_keys( + array_bytes::hex2array_unchecked( + "0xf8f82edfc6899552e5a32aa381e53723d2c39594638cb8f7e2572fef74b05255", + ) + .unchecked_into(), + ), + ), + ( + array_bytes::hex_n_into_unchecked::<_, AccountId, 20>( + "0x7aE2a0914db8bFBdad538b0eAc3Fa473A0e07843", + ), + session_keys( + array_bytes::hex2array_unchecked( + "0xdaf5c4506b82f617245150216a73c0eb4f2603848c02413db66f991846777845", + ) + .unchecked_into(), + ), + ), + ( + array_bytes::hex_n_into_unchecked::<_, AccountId, 20>( + "0x9F33a4809aA708d7a399fedBa514e0A0d15EfA85", + ), + session_keys( + array_bytes::hex2array_unchecked( + "0xdcff1219121687391353b17e798b10e87f6e578b2a01e032375f2f14a0712b57", + ) + .unchecked_into(), + ), + ), + ( + array_bytes::hex_n_into_unchecked::<_, AccountId, 20>( + "0x0a1287977578F888bdc1c7627781AF1cc000e6ab", + ), + session_keys( + array_bytes::hex2array_unchecked( + "0x28a8af71db9703e6b8960d1dcb742deca13c574f81f781be5dbde84ec8d66d45", + ) + .unchecked_into(), + ), + ), + ( + array_bytes::hex_n_into_unchecked::<_, AccountId, 20>( + "0xEB7e82A67CDFA3E742e0f3315Fd4EEd7B05730CC", + ), + session_keys( + array_bytes::hex2array_unchecked( + "0xfee21e4e4865380734882253d27612da0e4413c93e5c817e38b8c5e034de7270", + ) + .unchecked_into(), + ), + ), + ]; + let genesis_config_patch = serde_json::json!({ + // System stuff. + "parachainInfo": { "parachainId": PARA_ID }, + + // Monetary stuff. + "balances": { + "balances": collators.iter().map(|a| (a, 10_000 * UNIT)).collect::>() + }, + "assets": { + "assets": [(AssetIds::CKton as u32, ROOT, true, 1)], + "metadata": [( + AssetIds::CKton as u32, + b"Crab Commitment Token", + b"CKTON", + 18 + )] + }, + + // Consensus stuff. + "darwiniaStaking": { + "now": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(), + "elapsedTime": 0, + "rateLimit": 20_000_000 * UNIT, + "collatorCount": 6, + "collators": collators.iter().map(|(a, _)| (a, 1_000 * UNIT)).collect::>() }, - } + session: { + "keys": collators.iter().map(|(a, sks)| (a, a, sks)).collect::>() + }, + + // XCM stuff. + "polkadotXcm": { "safeXcmVersion": Some(SAFE_XCM_VERSION) }, + + // EVM stuff. + "evm": { + "accounts": { + BTreeMap::from_iter( + >::used_addresses().iter().map(|p| { + ( + p, + GenesisAccount { + nonce: Default::default(), + balance: Default::default(), + storage: Default::default(), + code: REVERT_BYTECODE.to_vec(), + }, + ) + }), + ) + } + } + }); + + ChainSpec::builder(WASM_BINARY.unwrap().to_vec(), Extensions { + relay_chain: "kusama".into(), // You MUST set this to the correct network! + para_id: PARA_ID, + }) + .with_name("Crab2") + .with_id("crab2") + .with_chain_type(ChainType::Live) + .with_protocol_id(PROTOCOL_ID) + .with_properties(properties()) + .with_genesis_config_patch(genesis_config_patch) + .with_boot_nodes(vec![ + "/dns/g1.crab2.darwinia.network/tcp/30333/ws/p2p/12D3KooWEDiHG6pjt53HqnfYepnLzp9rFTh8MJrBX7AZeGShBMM4".parse().unwrap() + ]) + .with_telemetry_endpoints( + TelemetryEndpoints::new(vec![(TELEMETRY_URL.into(), 0)]).unwrap() + ) + .build() +} + +pub fn config() -> ChainSpec { + load_config("crab2.json", 0) +} + +fn properties() -> Properties { + super::properties("CRAB") +} + +// 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). +fn session_keys(keys: AuraId) -> SessionKeys { + SessionKeys { aura: keys } } diff --git a/node/src/chain_spec/darwinia.rs b/node/src/chain_spec/darwinia.rs index 37f068214..9eed32934 100644 --- a/node/src/chain_spec/darwinia.rs +++ b/node/src/chain_spec/darwinia.rs @@ -37,311 +37,48 @@ use sc_service::{ChainType, GenericChainSpec}; use sc_telemetry::TelemetryEndpoints; use sp_core::{crypto::UncheckedInto, H160}; -/// Specialized `ChainSpec` for the normal parachain runtime. -pub type ChainSpec = GenericChainSpec; - -fn properties() -> Properties { - super::properties("RING") -} - -// 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). -fn session_keys(keys: AuraId) -> SessionKeys { - SessionKeys { aura: keys } -} +const PARA_ID: u32 = 2046; pub fn development_config() -> ChainSpec { - ChainSpec::from_genesis( - // Fulfill Polkadot.JS metadata upgrade requirements. - "Darwinia2 D", - "darwinia2-d", - ChainType::Live, - move || { - testnet_genesis( - vec![ - // Bind the `Alice` to `Alith` to make `--alice` available for testnet. - ( - array_bytes::hex_n_into_unchecked::<_, _, 20>(ALITH), - get_collator_keys_from_seed("Alice"), - ), - ], - vec![ - array_bytes::hex_n_into_unchecked::<_, _, 20>(ALITH), - array_bytes::hex_n_into_unchecked::<_, _, 20>(BALTATHAR), - array_bytes::hex_n_into_unchecked::<_, _, 20>(CHARLETH), - array_bytes::hex_n_into_unchecked::<_, _, 20>(DOROTHY), - array_bytes::hex_n_into_unchecked::<_, _, 20>(ETHAN), - array_bytes::hex_n_into_unchecked::<_, _, 20>(FAITH), - ], - 2046.into(), - ) - }, - Vec::new(), - None, - Some(PROTOCOL_ID), - None, - Some(properties()), - Extensions { - relay_chain: "rococo-local".into(), // You MUST set this to the correct network! - para_id: 2046, - }, - ) -} - -pub fn local_config() -> ChainSpec { - ChainSpec::from_genesis( - // Fulfill Polkadot.JS metadata upgrade requirements. - "Darwinia2 L", - "darwinia2-l", - ChainType::Live, - move || { - testnet_genesis( - vec![ - // Bind the `Alice` to `Alith` to make `--alice` available for testnet. - ( - array_bytes::hex_n_into_unchecked::<_, _, 20>(ALITH), - get_collator_keys_from_seed("Alice"), - ), - // Bind the `Bob` to `Balthar` to make `--bob` available for testnet. - ( - array_bytes::hex_n_into_unchecked::<_, _, 20>(BALTATHAR), - get_collator_keys_from_seed("Bob"), - ), - // Bind the `Charlie` to `CHARLETH` to make `--charlie` available for testnet. - ( - array_bytes::hex_n_into_unchecked::<_, _, 20>(CHARLETH), - get_collator_keys_from_seed("Charlie"), - ), - ], - vec![ - array_bytes::hex_n_into_unchecked::<_, _, 20>(ALITH), - array_bytes::hex_n_into_unchecked::<_, _, 20>(BALTATHAR), - array_bytes::hex_n_into_unchecked::<_, _, 20>(CHARLETH), - array_bytes::hex_n_into_unchecked::<_, _, 20>(DOROTHY), - array_bytes::hex_n_into_unchecked::<_, _, 20>(ETHAN), - array_bytes::hex_n_into_unchecked::<_, _, 20>(FAITH), - ], - 2046.into(), - ) - }, - Vec::new(), - None, - Some(PROTOCOL_ID), - None, - Some(properties()), - Extensions { - relay_chain: "rococo-local".into(), // You MUST set this to the correct network! - para_id: 2046, - }, - ) -} - -pub fn genesis_config() -> ChainSpec { - let collators = [ - ( - "0x196f03b77a1acd0db080006b04d2f3a991ebbe68", - "0xa05255010ee986b9684a444d10a74aa0ecbe781f5002e871665add894752cc7e", - ), - ( - "0x7aE2a0914db8bFBdad538b0eAc3Fa473A0e07843", - "0xdaf5c4506b82f617245150216a73c0eb4f2603848c02413db66f991846777845", - ), - ( - "0x9F33a4809aA708d7a399fedBa514e0A0d15EfA85", - "0xdcff1219121687391353b17e798b10e87f6e578b2a01e032375f2f14a0712b57", - ), - ( - "0x0a1287977578F888bdc1c7627781AF1cc000e6ab", - "0x28a8af71db9703e6b8960d1dcb742deca13c574f81f781be5dbde84ec8d66d45", - ), - ( - "0xEB7e82A67CDFA3E742e0f3315Fd4EEd7B05730CC", - "0xfee21e4e4865380734882253d27612da0e4413c93e5c817e38b8c5e034de7270", - ), - ]; - - ChainSpec::from_genesis( - "Darwinia2", - "darwinia2", - ChainType::Live, - move || { - RuntimeGenesisConfig { - // System stuff. - system: SystemConfig { code: WASM_BINARY.unwrap().to_vec(), ..Default::default() }, - parachain_system: Default::default(), - parachain_info: ParachainInfoConfig { parachain_id: 2046.into(), ..Default::default() }, - - // Monetary stuff. - balances: BalancesConfig { - balances: collators - .iter() - .map(|(k, _)| (array_bytes::hex_n_into_unchecked::<_, _, 20>(k), 10_000 * UNIT)) - .collect(), - }, - transaction_payment: Default::default(), - assets: AssetsConfig { - assets: vec![(AssetIds::Kton as _, ROOT, true, 1)], - metadata: vec![( - AssetIds::Kton as _, - b"Darwinia Commitment Token".to_vec(), - b"KTON".to_vec(), - 18, - )], - ..Default::default() - }, - vesting: Default::default(), - - // Consensus stuff. - darwinia_staking: DarwiniaStakingConfig { - now: SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(), - elapsed_time: 0, - rate_limit: 20_000_000 * UNIT, - collator_count: 5, - collators: collators - .iter() - .map(|(k, _)| (array_bytes::hex_n_into_unchecked::<_, _, 20>(k), 1_000 * UNIT)) - .collect(), - }, - session: SessionConfig { - keys: collators - .iter() - .map(|(k, a)| { - ( - array_bytes::hex_n_into_unchecked::<_, _, 20>(k), - array_bytes::hex_n_into_unchecked::<_, _, 20>(k), - session_keys(array_bytes::hex2array_unchecked(a).unchecked_into()), - ) - }) - .collect(), - }, - aura: Default::default(), - aura_ext: Default::default(), - - // Governance stuff. - democracy: Default::default(), - council: Default::default(), - technical_committee: Default::default(), - treasury: Default::default(), - - // Utility stuff. - // tx_pause: Default::default(), - - // XCM stuff. - polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION), ..Default::default() }, - - // EVM stuff. - ethereum: Default::default(), - evm: EVMConfig { - accounts: { - BTreeMap::from_iter( - DarwiniaPrecompiles::::used_addresses().iter().map(|p| { - ( - p.to_owned(), - GenesisAccount { - nonce: Default::default(), - balance: Default::default(), - storage: Default::default(), - code: REVERT_BYTECODE.to_vec(), - }, - ) - }), - ) - }, - ..Default::default() - }, - } - }, - vec![ - "/dns/g1.darwinia2.darwinia.network/tcp/30333/ws/p2p/12D3KooWM2eentxcGA3W5tnw5TYwJUjRktSMSTu4zkzEaD8k6mr4".parse().unwrap() - ], - TelemetryEndpoints::new(vec![(TELEMETRY_URL.into(), 0)]).ok(), - Some(PROTOCOL_ID), - None, - Some(properties()), - Extensions { - relay_chain: "polkadot".into(), // You MUST set this to the correct network! - para_id: 2046, - }, - ) -} - -pub fn config() -> ChainSpec { - load_config("darwinia2.json", 0) -} - -fn testnet_genesis( - collators: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - id: ParaId, -) -> RuntimeGenesisConfig { - RuntimeGenesisConfig { + let (collators, endowed_accounts) = dev_accounts::(session_keys); + let genesis_config_patch = serde_json::json!({ // System stuff. - system: SystemConfig { code: WASM_BINARY.unwrap().to_vec(), ..Default::default() }, - parachain_system: Default::default(), - parachain_info: ParachainInfoConfig { parachain_id: id, ..Default::default() }, + "parachainInfo": { "parachainId": PARA_ID }, // Monetary stuff. - balances: BalancesConfig { - balances: endowed_accounts.iter().cloned().map(|k| (k, 100_000_000 * UNIT)).collect(), + "balances": { + "balances": endowed_accounts.iter().map(|a| (a, 100_000_000 * UNIT)).collect::>() }, - transaction_payment: Default::default(), - assets: AssetsConfig { - assets: vec![(AssetIds::Kton as _, ROOT, true, 1)], - metadata: vec![( + "assets": { + "assets": [(AssetIds::Kton as _, ROOT, true, 1)], + "metadata": [( AssetIds::Kton as _, - b"Darwinia Commitment Token".to_vec(), - b"KTON".to_vec(), - 18, - )], - ..Default::default() + b"Darwinia Commitment Token", + b"KTON", + 18 + )] }, - vesting: Default::default(), // Consensus stuff. - darwinia_staking: DarwiniaStakingConfig { - now: SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(), - elapsed_time: 0, - rate_limit: 20_000_000 * UNIT, - collator_count: collators.len() as _, - collators: collators.iter().map(|(a, _)| (a.to_owned(), UNIT)).collect(), + "darwiniaStaking": { + "now": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(), + "elapsedTime": 0, + "rateLimit": 20_000_000 * UNIT, + "collatorCount": collators.len(), + "collators": collators.iter().map(|(a, _)| (a, UNIT)).collect::>() }, - session: SessionConfig { - keys: collators - .into_iter() - .map(|(acc, aura)| { - ( - acc, // account id - acc, // validator id - session_keys(aura), // session keys - ) - }) - .collect(), + "session": { + "keys": collators.into_iter().map(|(a, sks)| (a, a, sks)).collect::>() }, - aura: Default::default(), - aura_ext: Default::default(), - - // Governance stuff. - democracy: Default::default(), - council: Default::default(), - technical_committee: Default::default(), - treasury: Default::default(), - - // Utility stuff. - // tx_pause: Default::default(), // XCM stuff. - polkadot_xcm: PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, + "polkadotXcm": { "safeXcmVersion": Some(SAFE_XCM_VERSION) }, // EVM stuff. - ethereum: Default::default(), - evm: EVMConfig { - accounts: { + "evm": { + "accounts": { BTreeMap::from_iter( - DarwiniaPrecompiles::::used_addresses() + >::used_addresses() .iter() .map(|p| { ( @@ -367,8 +104,167 @@ fn testnet_genesis( ), ]), ) - }, - ..Default::default() + } + } + }); + + ChainSpec::builder( + WASM_BINARY.unwrap().to_vec(), + Extensions { + relay_chain: "rococo-local".into(), // You MUST set this to the correct network! + para_id: PARA_ID, + }, + ) + .with_name("Darwinia2 D") + .with_id("darwinia2-d") + .with_chain_type(ChainType::Live) + .with_protocol_id(PROTOCOL_ID) + .with_properties(properties()) + .with_genesis_config_patch(genesis_config_patch) + .build() +} + +pub fn genesis_config() -> ChainSpec { + let collators = [ + ( + array_bytes::hex_n_into_unchecked::<_, AccountId, 20>( + "0x196f03b77a1acd0db080006b04d2f3a991ebbe68", + ), + session_keys( + array_bytes::hex2array_unchecked( + "0xa05255010ee986b9684a444d10a74aa0ecbe781f5002e871665add894752cc7e", + ) + .unchecked_into(), + ), + ), + ( + array_bytes::hex_n_into_unchecked::<_, AccountId, 20>( + "0x7aE2a0914db8bFBdad538b0eAc3Fa473A0e07843", + ), + session_keys( + array_bytes::hex2array_unchecked( + "0xdaf5c4506b82f617245150216a73c0eb4f2603848c02413db66f991846777845", + ) + .unchecked_into(), + ), + ), + ( + array_bytes::hex_n_into_unchecked::<_, AccountId, 20>( + "0x9F33a4809aA708d7a399fedBa514e0A0d15EfA85", + ), + session_keys( + array_bytes::hex2array_unchecked( + "0xdcff1219121687391353b17e798b10e87f6e578b2a01e032375f2f14a0712b57", + ) + .unchecked_into(), + ), + ), + ( + array_bytes::hex_n_into_unchecked::<_, AccountId, 20>( + "0x0a1287977578F888bdc1c7627781AF1cc000e6ab", + ), + session_keys( + array_bytes::hex2array_unchecked( + "0x28a8af71db9703e6b8960d1dcb742deca13c574f81f781be5dbde84ec8d66d45", + ) + .unchecked_into(), + ), + ), + ( + array_bytes::hex_n_into_unchecked::<_, AccountId, 20>( + "0xEB7e82A67CDFA3E742e0f3315Fd4EEd7B05730CC", + ), + session_keys( + array_bytes::hex2array_unchecked( + "0xfee21e4e4865380734882253d27612da0e4413c93e5c817e38b8c5e034de7270", + ) + .unchecked_into(), + ), + ), + ]; + let genesis_config_patch = serde_json::json!({ + // System stuff. + "parachainInfo": { "parachainId": PARA_ID }, + + // Monetary stuff. + "balances": { + "balances": collators.iter().map(|a| (a, 10_000 * UNIT)).collect::>() }, - } + "assets": { + "assets": [(AssetIds::Kton as _, ROOT, true, 1)], + "metadata": [( + AssetIds::Kton as _, + b"Darwinia Commitment Token", + b"KTON", + 18 + )] + }, + + // Consensus stuff. + "darwiniaStaking" { + "now": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(), + "elapsedTime": 0, + "rateLimit": 20_000_000 * UNIT, + "collatorCount": 5, + "collators": collators.iter().map(|(a, _)| (a, 1_000 * UNIT)).collect::>() + }, + "session": { + "keys": collators.iter().map(|(a, sks)| (a, a, sks)).collect::>() + }, + + // XCM stuff. + "polkadotXcm": { "safeXcmVersion": Some(SAFE_XCM_VERSION) }, + + // EVM stuff. + "evm": { + "accounts": { + BTreeMap::from_iter( + >::used_addresses().iter().map(|p| { + ( + p, + GenesisAccount { + nonce: Default::default(), + balance: Default::default(), + storage: Default::default(), + code: REVERT_BYTECODE.to_vec(), + }, + ) + }), + ) + } + } + }); + + ChainSpec::builder(WASM_BINARY.unwrap().to_vec(), Extensions { + relay_chain: "polkadot".into(), // You MUST set this to the correct network! + para_id: PARA_ID, + }) + .with_name("Darwinia2") + .with_id("darwinia2") + .with_chain_type(ChainType::Live) + .with_protocol_id(PROTOCOL_ID) + .with_properties(properties()) + .with_genesis_config_patch(genesis_config_patch) + .with_boot_nodes(vec![ + "/dns/g1.darwinia2.darwinia.network/tcp/30333/ws/p2p/12D3KooWM2eentxcGA3W5tnw5TYwJUjRktSMSTu4zkzEaD8k6mr4".parse().unwrap() + ]) + .with_telemetry_endpoints( + TelemetryEndpoints::new(vec![(TELEMETRY_URL.into(), 0)]).unwrap() + ) + .build() +} + +pub fn config() -> ChainSpec { + load_config("darwinia2.json", 0) +} + +fn properties() -> Properties { + super::properties("RING") +} + +// 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). +fn session_keys(keys: AuraId) -> SessionKeys { + SessionKeys { aura: keys } } diff --git a/node/src/chain_spec/koi.rs b/node/src/chain_spec/koi.rs index 9d57995a6..64f6a3402 100644 --- a/node/src/chain_spec/koi.rs +++ b/node/src/chain_spec/koi.rs @@ -37,306 +37,59 @@ use sc_service::{ChainType, GenericChainSpec}; use sc_telemetry::TelemetryEndpoints; use sp_core::{crypto::UncheckedInto, H160}; -/// Specialized `ChainSpec` for the normal parachain runtime. -pub type ChainSpec = GenericChainSpec; - -fn properties() -> Properties { - super::properties("KRING") -} - -// 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). -fn session_keys(keys: AuraId) -> SessionKeys { - SessionKeys { aura: keys } -} +const PARA_ID: u32 = 2105; pub fn development_config() -> ChainSpec { - ChainSpec::from_genesis( - // Fulfill Polkadot.JS metadata upgrade requirements. - "Darwinia Koi D", - "darwinia-koi-d", - ChainType::Live, - move || { - testnet_genesis( - vec![ - // Bind the `Alice` to `Alith` to make `--alice` available for testnet. - ( - array_bytes::hex_n_into_unchecked::<_, _, 20>(ALITH), - get_collator_keys_from_seed("Alice"), - ), - ], - vec![ - array_bytes::hex_n_into_unchecked::<_, _, 20>(ALITH), - array_bytes::hex_n_into_unchecked::<_, _, 20>(BALTATHAR), - array_bytes::hex_n_into_unchecked::<_, _, 20>(CHARLETH), - array_bytes::hex_n_into_unchecked::<_, _, 20>(DOROTHY), - array_bytes::hex_n_into_unchecked::<_, _, 20>(ETHAN), - array_bytes::hex_n_into_unchecked::<_, _, 20>(FAITH), - ], - 2105.into(), - ) - }, - Vec::new(), - None, - Some(PROTOCOL_ID), - None, - Some(properties()), - Extensions { - relay_chain: "rococo-local".into(), // You MUST set this to the correct network! - para_id: 2105, - }, - ) -} - -pub fn local_config() -> ChainSpec { - ChainSpec::from_genesis( - // Fulfill Polkadot.JS metadata upgrade requirements. - "Darwinia Koi L", - "darwinia-koi-l", - // Fulfill Polkadot.JS metadata upgrade requirements. - ChainType::Live, - move || { - testnet_genesis( - vec![ - // Bind the `Alice` to `Alith` to make `--alice` available for testnet. - ( - array_bytes::hex_n_into_unchecked::<_, _, 20>(ALITH), - get_collator_keys_from_seed("Alice"), - ), - // Bind the `Bob` to `Balthar` to make `--bob` available for testnet. - ( - array_bytes::hex_n_into_unchecked::<_, _, 20>(BALTATHAR), - get_collator_keys_from_seed("Bob"), - ), - // Bind the `Charlie` to `CHARLETH` to make `--charlie` available for testnet. - ( - array_bytes::hex_n_into_unchecked::<_, _, 20>(CHARLETH), - get_collator_keys_from_seed("Charlie"), - ), - ], - vec![ - array_bytes::hex_n_into_unchecked::<_, _, 20>(ALITH), - array_bytes::hex_n_into_unchecked::<_, _, 20>(BALTATHAR), - array_bytes::hex_n_into_unchecked::<_, _, 20>(CHARLETH), - array_bytes::hex_n_into_unchecked::<_, _, 20>(DOROTHY), - array_bytes::hex_n_into_unchecked::<_, _, 20>(ETHAN), - array_bytes::hex_n_into_unchecked::<_, _, 20>(FAITH), - ], - 2105.into(), - ) - }, - Vec::new(), - None, - Some(PROTOCOL_ID), - None, - Some(properties()), - Extensions { - relay_chain: "rococo-local".into(), // You MUST set this to the correct network! - para_id: 2105, - }, - ) -} - -pub fn genesis_config() -> ChainSpec { - ChainSpec::from_genesis( - "Darwinia Koi", - "darwinia-koi", - ChainType::Live, - move || { - RuntimeGenesisConfig { - // System stuff. - system: SystemConfig { code: WASM_BINARY.unwrap().to_vec(), ..Default::default() }, - parachain_system: Default::default(), - parachain_info: ParachainInfoConfig { parachain_id: 2105.into(), ..Default::default() }, - - // Monetary stuff. - balances: BalancesConfig { - balances: vec![ - (array_bytes::hex_n_into_unchecked::<_, _, 20>(C1), 10_000 * UNIT), - (array_bytes::hex_n_into_unchecked::<_, _, 20>(C2), 10_000 * UNIT), - (array_bytes::hex_n_into_unchecked::<_, _, 20>(C3), 10_000 * UNIT), - ], - }, - transaction_payment: Default::default(), - assets: AssetsConfig { - assets: vec![(AssetIds::PKton as _, ROOT, true, 1)], - metadata: vec![( - AssetIds::PKton as _, - b"Koi Commitment Token".to_vec(), - b"PKTON".to_vec(), - 18, - )], - ..Default::default() - }, - - // Consensus stuff. - darwinia_staking: DarwiniaStakingConfig { - now: SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(), - elapsed_time: 0, - rate_limit: 20_000_000 * UNIT, - collator_count: 3, - collators: vec![ - (array_bytes::hex_n_into_unchecked::<_, _, 20>(C1), UNIT), - (array_bytes::hex_n_into_unchecked::<_, _, 20>(C2), UNIT), - (array_bytes::hex_n_into_unchecked::<_, _, 20>(C3), UNIT), - ], - }, - session: SessionConfig { - keys: vec![ - ( - array_bytes::hex_n_into_unchecked::<_, _, 20>(C1), - array_bytes::hex_n_into_unchecked::<_, _, 20>(C1), - session_keys( - array_bytes::hex2array_unchecked(C1_AURA).unchecked_into(), - ), - ), - ( - array_bytes::hex_n_into_unchecked::<_, _, 20>(C2), - array_bytes::hex_n_into_unchecked::<_, _, 20>(C2), - session_keys( - array_bytes::hex2array_unchecked(C2_AURA).unchecked_into(), - ), - ), - ( - array_bytes::hex_n_into_unchecked::<_, _, 20>(C3), - array_bytes::hex_n_into_unchecked::<_, _, 20>(C3), - session_keys( - array_bytes::hex2array_unchecked(C3_AURA).unchecked_into(), - ), - ), - ], - }, - aura: Default::default(), - aura_ext: Default::default(), - - // Governance stuff. - technical_committee: Default::default(), - treasury: Default::default(), - - // Utility stuff. - sudo: SudoConfig { key: Some(array_bytes::hex_n_into_unchecked::<_, _, 20>(SUDO)) }, - tx_pause: Default::default(), - - // XCM stuff. - polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION), ..Default::default() }, - - // EVM stuff. - ethereum: Default::default(), - evm: EVMConfig { - accounts: { - BTreeMap::from_iter( - KoiPrecompiles::::used_addresses().iter().map(|p| { - ( - p.to_owned(), - GenesisAccount { - nonce: Default::default(), - balance: Default::default(), - storage: Default::default(), - code: REVERT_BYTECODE.to_vec(), - }, - ) - }), - ) - }, - ..Default::default() - }, - } - }, - vec![ - "/dns/g1.testnets.darwinia.network/tcp/30330/p2p/12D3KooWLjJE7oNzQrEM26vUZ1uKuNYhvqjYrEATt1RdoAMTnvL9".parse().unwrap() - ], - TelemetryEndpoints::new(vec![(TELEMETRY_URL.into(), 0)]).ok(), - Some(PROTOCOL_ID), - None, - Some(properties()), - Extensions { - relay_chain: "paseo".into(), // You MUST set this to the correct network! - para_id: 2105, - }, - ) -} - -pub fn config() -> ChainSpec { - load_config("koi.json", 0) -} - -fn testnet_genesis( - collators: Vec<(AccountId, AuraId)>, - endowed_accounts: Vec, - id: ParaId, -) -> RuntimeGenesisConfig { - RuntimeGenesisConfig { + let (collators, endowed_accounts) = dev_accounts::(session_keys); + let genesis_config_patch = serde_json::json!({ // System stuff. - system: SystemConfig { code: WASM_BINARY.unwrap().to_vec(), ..Default::default() }, - parachain_system: Default::default(), - parachain_info: ParachainInfoConfig { parachain_id: id, ..Default::default() }, + "parachainInfo": { "parachainId": PARA_ID }, // Monetary stuff. - balances: BalancesConfig { - balances: endowed_accounts.iter().cloned().map(|k| (k, 100_000_000 * UNIT)).collect(), + "balances": { + "balances": endowed_accounts.iter().map(|a| (a, 100_000_000 * UNIT)).collect::>() }, - transaction_payment: Default::default(), - assets: AssetsConfig { - assets: vec![(AssetIds::PKton as _, ROOT, true, 1)], - metadata: vec![( - AssetIds::PKton as _, - b"Koi Commitment Token".to_vec(), - b"PKTON".to_vec(), + "assets": { + "assets": [(AssetIds::PKton as _, ROOT, true, 1)], + "metadata": [( + AssetIds::PKton as u32, + b"Koi Commitment Token", + b"PKTON", 18, - )], - ..Default::default() + )] }, // Consensus stuff. - darwinia_staking: DarwiniaStakingConfig { - now: SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(), - elapsed_time: 0, - rate_limit: 20_000_000 * UNIT, - collator_count: collators.len() as _, - collators: collators.iter().map(|(a, _)| (a.to_owned(), UNIT)).collect(), + "darwiniaStaking": { + "now": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(), + "elapsedTime": 0, + "rateLimit": 20_000_000 * UNIT, + "collatorCount": collators.len(), + "collators": collators.iter().map(|(a, _)| (a, UNIT)).collect::>() }, - session: SessionConfig { - keys: collators - .into_iter() - .map(|(acc, aura)| { - ( - acc, // account id - acc, // validator id - session_keys(aura), // session keys - ) - }) - .collect(), + "session": { + "keys": collators.into_iter().map(|(a, sks)| (a, a, sks)).collect::>() }, - aura: Default::default(), - aura_ext: Default::default(), // Governance stuff. - technical_committee: TechnicalCommitteeConfig { - members: vec![ + "technicalCommittee": { + "members": [ array_bytes::hex_n_into_unchecked::<_, _, 20>(ALITH), - array_bytes::hex_n_into_unchecked::<_, _, 20>(BALTATHAR), - ], - ..Default::default() + array_bytes::hex_n_into_unchecked::<_, _, 20>(BALTATHAR) + ] }, - treasury: Default::default(), // Utility stuff. - sudo: SudoConfig { key: Some(array_bytes::hex_n_into_unchecked::<_, _, 20>(ALITH)) }, - tx_pause: Default::default(), + "sudo": { "key": Some(array_bytes::hex_n_into_unchecked::<_, _, 20>(ALITH)) }, // XCM stuff. - polkadot_xcm: PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, + "polkadotXcm": { "safeXcmVersion": Some(SAFE_XCM_VERSION) }, // EVM stuff. - ethereum: Default::default(), - evm: EVMConfig { - accounts: { + "evm": { + "accounts": { BTreeMap::from_iter( - KoiPrecompiles::::used_addresses() + >::used_addresses() .iter() .map(|p| { ( @@ -362,8 +115,128 @@ fn testnet_genesis( ), ]), ) - }, - ..Default::default() + } + } + }); + + ChainSpec::builder( + WASM_BINARY.unwrap().to_vec(), + Extensions { + relay_chain: "rococo-local".into(), // You MUST set this to the correct network! + para_id: PARA_ID, + }, + ) + .with_name("Darwinia Koi D") + .with_id("darwinia-koi-d") + .with_chain_type(ChainType::Live) + .with_protocol_id(PROTOCOL_ID) + .with_properties(properties()) + .with_genesis_config_patch(genesis_config_patch) + .build() +} + +pub fn genesis_config() -> ChainSpec { + let collators = [ + ( + array_bytes::hex_n_into_unchecked::<_, AccountId, 20>(C1), + session_keys(array_bytes::hex2array_unchecked(C1_AURA).unchecked_into()), + ), + ( + array_bytes::hex_n_into_unchecked::<_, AccountId, 20>(C2), + session_keys(array_bytes::hex2array_unchecked(C2_AURA).unchecked_into()), + ), + ( + array_bytes::hex_n_into_unchecked::<_, AccountId, 20>(C3), + session_keys(array_bytes::hex2array_unchecked(C3_AURA).unchecked_into()), + ), + ]; + let genesis_config_patch = serde_json::json!({ + // System stuff. + "parachainInfo": { "parachainId": PARA_ID }, + + // Monetary stuff. + "balances": { + "balances": collators.iter().map(|a| (a, 10_000 * UNIT)).collect::>(), }, - } + "assets": { + "assets": [(AssetIds::PKton as _, ROOT, true, 1)], + "metadata": [( + AssetIds::PKton as u32, + b"Koi Commitment Token", + b"PKTON", + 18, + )] + }, + + // Consensus stuff. + "darwiniaStaking": { + "now": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(), + "elapsedTime": 0, + "rateLimit": 20_000_000 * UNIT, + "collatorCount": 3, + "collators": collators.iter().map(|(a, _)| (a, UNIT)).collect::>() + }, + "session": { + "keys": collators.iter().map(|(a, sks)| (a, a, sks)).collect::>() + }, + + // Utility stuff. + "sudo": { "key": Some(array_bytes::hex_n_into_unchecked::<_, _, 20>(SUDO)) }, + + // XCM stuff. + "polkadotXcm": { "safeXcmVersion": Some(SAFE_XCM_VERSION) }, + + // EVM stuff. + "evm": { + "accounts": { + BTreeMap::from_iter( + >::used_addresses().iter().map(|p| { + ( + p, + GenesisAccount { + nonce: Default::default(), + balance: Default::default(), + storage: Default::default(), + code: REVERT_BYTECODE.to_vec(), + }, + ) + }), + ) + } + } + }); + + ChainSpec::builder( + WASM_BINARY.unwrap().to_vec(), + Extensions { + relay_chain: "paseo".into(), // You MUST set this to the correct network! + para_id: PARA_ID, + }, + ) + .with_name("Darwinia Koi") + .with_id("darwinia-koi") + .with_chain_type(ChainType::Live) + .with_protocol_id(PROTOCOL_ID) + .with_properties(properties()) + .with_genesis_config_patch(genesis_config_patch) + .with_boot_nodes( + vec!["/dns/g1.testnets.darwinia.network/tcp/30330/p2p/12D3KooWLjJE7oNzQrEM26vUZ1uKuNYhvqjYrEATt1RdoAMTnvL9".parse().unwrap()] + ) + .with_telemetry_endpoints(TelemetryEndpoints::new(vec![(TELEMETRY_URL.into(), 0)]).unwrap()) + .build() +} + +pub fn config() -> ChainSpec { + load_config("koi.json", 0) +} + +fn properties() -> Properties { + super::properties("KRING") +} + +// 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). +fn session_keys(keys: AuraId) -> SessionKeys { + SessionKeys { aura: keys } } diff --git a/node/src/chain_spec/mod.rs b/node/src/chain_spec/mod.rs index 6ff1f9d3c..5111cd057 100644 --- a/node/src/chain_spec/mod.rs +++ b/node/src/chain_spec/mod.rs @@ -20,24 +20,12 @@ #[cfg(feature = "darwinia-native")] pub mod darwinia; -#[cfg(feature = "darwinia-native")] -pub use darwinia::{self as darwinia_chain_spec, ChainSpec as DarwiniaChainSpec}; -#[cfg(not(feature = "darwinia-native"))] -pub type DarwiniaChainSpec = DummyChainSpec; #[cfg(feature = "crab-native")] pub mod crab; -#[cfg(feature = "crab-native")] -pub use crab::{self as crab_chain_spec, ChainSpec as CrabChainSpec}; -#[cfg(not(feature = "crab-native"))] -pub type CrabChainSpec = DummyChainSpec; #[cfg(feature = "koi-native")] pub mod koi; -#[cfg(feature = "koi-native")] -pub use koi::{self as koi_chain_spec, ChainSpec as KoiChainSpec}; -#[cfg(not(feature = "koi-native"))] -pub type KoiChainSpec = DummyChainSpec; #[cfg(feature = "koi-native")] mod testnet_keys { @@ -63,9 +51,7 @@ use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup, GenericChainSpec, Proper use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_core::{Pair, Public}; -// Dummy chain spec, in case when we don't have the native runtime. -#[allow(unused)] -pub type DummyChainSpec = sc_chain_spec::GenericChainSpec<(), Extensions>; +pub type ChainSpec = sc_service::GenericChainSpec<(), Extensions>; const TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit"; @@ -112,12 +98,37 @@ fn properties(token_symbol: &str) -> Properties { } fn get_collator_keys_from_seed(seed: &str) -> AuraId { + fn get_from_seed(seed: &str) -> ::Public { + TPublic::Pair::from_string(&format!("//{}", seed), None) + .expect("static values are valid; qed") + .public() + } + get_from_seed::(seed) } -fn get_from_seed(seed: &str) -> ::Public { - TPublic::Pair::from_string(&format!("//{}", seed), None) - .expect("static values are valid; qed") - .public() + +fn dev_accounts(f: F) -> ([(A, Sks); 1], [A; 6]) +where + A: From<[u8; 20]>, + F: Fn(AuraId) -> Sks, +{ + ( + [ + // Bind the `Alice` to `Alith` to make `--alice` work for development. + ( + array_bytes::hex_n_into_unchecked::<_, _, 20>(ALITH), + f(get_collator_keys_from_seed("Alice")), + ), + ], + [ + array_bytes::hex_n_into_unchecked::<_, _, 20>(ALITH), + array_bytes::hex_n_into_unchecked::<_, _, 20>(BALTATHAR), + array_bytes::hex_n_into_unchecked::<_, _, 20>(CHARLETH), + array_bytes::hex_n_into_unchecked::<_, _, 20>(DOROTHY), + array_bytes::hex_n_into_unchecked::<_, _, 20>(ETHAN), + array_bytes::hex_n_into_unchecked::<_, _, 20>(FAITH), + ], + ) } fn load_config(name: &'static str, mut retries: u8) -> GenericChainSpec diff --git a/node/src/command.rs b/node/src/command.rs index ab2eb1b10..449302933 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -33,7 +33,7 @@ use sc_cli::{ }; use sc_service::{ config::{BasePath, PrometheusConfig}, - ChainSpec, DatabaseSource, + ChainSpec as ChainSpecT, DatabaseSource, }; use sp_core::crypto::{self, Ss58AddressFormatRegistry}; use sp_runtime::traits::AccountIdConversion; @@ -71,7 +71,7 @@ impl SubstrateCli for Cli { 2018 } - fn load_spec(&self, id: &str) -> std::result::Result, String> { + fn load_spec(&self, id: &str) -> std::result::Result, String> { load_spec(id) } } @@ -107,7 +107,7 @@ impl SubstrateCli for RelayChainCli { 2018 } - fn load_spec(&self, id: &str) -> std::result::Result, String> { + fn load_spec(&self, id: &str) -> std::result::Result, String> { polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id) } } @@ -152,7 +152,7 @@ impl CliConfiguration for RelayChainCli { fn prometheus_config( &self, default_listen_port: u16, - chain_spec: &Box, + chain_spec: &Box, ) -> Result> { self.base.base.prometheus_config(default_listen_port, chain_spec) } @@ -222,7 +222,7 @@ impl CliConfiguration for RelayChainCli { fn telemetry_endpoints( &self, - chain_spec: &Box, + chain_spec: &Box, ) -> Result> { self.base.base.telemetry_endpoints(chain_spec) } @@ -587,7 +587,7 @@ pub fn run() -> Result<()> { } } -fn load_spec(id: &str) -> std::result::Result, String> { +fn load_spec(id: &str) -> std::result::Result, String> { let id = if id.is_empty() { let n = get_exec_name().unwrap_or_default(); ["darwinia", "crab", "koi"] @@ -598,52 +598,34 @@ fn load_spec(id: &str) -> std::result::Result, String> { } else { id }; - - Ok(match id.to_lowercase().as_str() { + let chain_spec = match id.to_lowercase().as_str() { #[cfg(feature = "crab-native")] "crab" => Box::new(crab_chain_spec::config()), #[cfg(feature = "crab-native")] "crab-genesis" => Box::new(crab_chain_spec::genesis_config()), #[cfg(feature = "crab-native")] "crab-dev" => Box::new(crab_chain_spec::development_config()), - #[cfg(feature = "crab-native")] - "crab-local" => Box::new(crab_chain_spec::local_config()), #[cfg(feature = "darwinia-native")] "darwinia" => Box::new(darwinia_chain_spec::config()), #[cfg(feature = "darwinia-native")] "darwinia-genesis" => Box::new(darwinia_chain_spec::genesis_config()), #[cfg(feature = "darwinia-native")] "darwinia-dev" => Box::new(darwinia_chain_spec::development_config()), - #[cfg(feature = "darwinia-native")] - "darwinia-local" => Box::new(darwinia_chain_spec::local_config()), #[cfg(feature = "koi-native")] "koi" => Box::new(koi_chain_spec::config()), #[cfg(feature = "koi-native")] "koi-genesis" => Box::new(koi_chain_spec::genesis_config()), #[cfg(feature = "koi-native")] "koi-dev" => Box::new(koi_chain_spec::development_config()), - #[cfg(feature = "koi-native")] - "koi-local" => Box::new(koi_chain_spec::local_config()), _ => { let path = PathBuf::from(id); - let chain_spec = - Box::new(DummyChainSpec::from_json_file(path.clone())?) as Box; + let chain_spec = Box::new(ChainSpec::from_json_file(path.clone())?); - if chain_spec.is_crab() { - return Ok(Box::new(CrabChainSpec::from_json_file(path)?)); - } - - if chain_spec.is_darwinia() { - return Ok(Box::new(DarwiniaChainSpec::from_json_file(path)?)); - } - - if chain_spec.is_koi() { - return Ok(Box::new(KoiChainSpec::from_json_file(path)?)); - } - - panic!("No feature(crab-native, darwinia-native, koi-native) is enabled!") + chain_spec }, - }) + }; + + Ok(chain_spec) } fn get_exec_name() -> Option {