From d8fc2caaab50df1d4726142946d33e89fddda9b4 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 17 Jul 2023 17:47:00 +0200 Subject: [PATCH 01/15] ChainSpec: code moved from pallet_system to ChainSpec --- node/service/src/chain_spec.rs | 156 +++++++++++++--------------- node/test/client/src/lib.rs | 2 +- node/test/service/src/chain_spec.rs | 7 +- 3 files changed, 77 insertions(+), 88 deletions(-) diff --git a/node/service/src/chain_spec.rs b/node/service/src/chain_spec.rs index 1253cd182264..94f7671fbaab 100644 --- a/node/service/src/chain_spec.rs +++ b/node/service/src/chain_spec.rs @@ -331,7 +331,7 @@ fn rococo_session_keys( } #[cfg(feature = "polkadot-native")] -fn polkadot_staging_testnet_config_genesis(wasm_binary: &[u8]) -> polkadot::RuntimeGenesisConfig { +fn polkadot_staging_testnet_config_genesis() -> polkadot::RuntimeGenesisConfig { // subkey inspect "$SECRET" let endowed_accounts = vec![]; @@ -350,7 +350,7 @@ fn polkadot_staging_testnet_config_genesis(wasm_binary: &[u8]) -> polkadot::Runt const STASH: u128 = 100 * DOT; polkadot::RuntimeGenesisConfig { - system: polkadot::SystemConfig { code: wasm_binary.to_vec(), ..Default::default() }, + system: polkadot::SystemConfig::default(), balances: polkadot::BalancesConfig { balances: endowed_accounts .iter() @@ -423,7 +423,7 @@ fn polkadot_staging_testnet_config_genesis(wasm_binary: &[u8]) -> polkadot::Runt } #[cfg(feature = "westend-native")] -fn westend_staging_testnet_config_genesis(wasm_binary: &[u8]) -> westend::RuntimeGenesisConfig { +fn westend_staging_testnet_config_genesis() -> westend::RuntimeGenesisConfig { use hex_literal::hex; use sp_core::crypto::UncheckedInto; @@ -545,7 +545,7 @@ fn westend_staging_testnet_config_genesis(wasm_binary: &[u8]) -> westend::Runtim const STASH: u128 = 100 * WND; westend::RuntimeGenesisConfig { - system: westend::SystemConfig { code: wasm_binary.to_vec(), ..Default::default() }, + system: westend::SystemConfig::default(), balances: westend::BalancesConfig { balances: endowed_accounts .iter() @@ -613,7 +613,7 @@ fn westend_staging_testnet_config_genesis(wasm_binary: &[u8]) -> westend::Runtim } #[cfg(feature = "kusama-native")] -fn kusama_staging_testnet_config_genesis(wasm_binary: &[u8]) -> kusama::RuntimeGenesisConfig { +fn kusama_staging_testnet_config_genesis() -> kusama::RuntimeGenesisConfig { use hex_literal::hex; use sp_core::crypto::UncheckedInto; @@ -740,7 +740,7 @@ fn kusama_staging_testnet_config_genesis(wasm_binary: &[u8]) -> kusama::RuntimeG const STASH: u128 = 100 * KSM; kusama::RuntimeGenesisConfig { - system: kusama::SystemConfig { code: wasm_binary.to_vec(), ..Default::default() }, + system: kusama::SystemConfig::default(), balances: kusama::BalancesConfig { balances: endowed_accounts .iter() @@ -806,9 +806,7 @@ fn kusama_staging_testnet_config_genesis(wasm_binary: &[u8]) -> kusama::RuntimeG } #[cfg(feature = "rococo-native")] -fn rococo_staging_testnet_config_genesis( - wasm_binary: &[u8], -) -> rococo_runtime::RuntimeGenesisConfig { +fn rococo_staging_testnet_config_genesis() -> rococo_runtime::RuntimeGenesisConfig { use hex_literal::hex; use sp_core::crypto::UncheckedInto; @@ -1052,7 +1050,7 @@ fn rococo_staging_testnet_config_genesis( const STASH: u128 = 100 * ROC; rococo_runtime::RuntimeGenesisConfig { - system: rococo_runtime::SystemConfig { code: wasm_binary.to_vec(), ..Default::default() }, + system: rococo_runtime::SystemConfig::default(), balances: rococo_runtime::BalancesConfig { balances: endowed_accounts .iter() @@ -1132,14 +1130,14 @@ pub fn polkadot_chain_spec_properties() -> serde_json::map::Map Result { - let wasm_binary = polkadot::WASM_BINARY.ok_or("Polkadot development wasm not available")?; let boot_nodes = vec![]; + #[allow(deprecated)] Ok(PolkadotChainSpec::from_genesis( "Polkadot Staging Testnet", "polkadot_staging_testnet", ChainType::Live, - move || polkadot_staging_testnet_config_genesis(wasm_binary), + move || polkadot_staging_testnet_config_genesis(), boot_nodes, Some( TelemetryEndpoints::new(vec![(POLKADOT_STAGING_TELEMETRY_URL.to_string(), 0)]) @@ -1149,20 +1147,21 @@ pub fn polkadot_staging_testnet_config() -> Result { None, Some(polkadot_chain_spec_properties()), Default::default(), + polkadot::WASM_BINARY.ok_or("Polkadot development wasm not available")?, )) } /// Staging testnet config. #[cfg(feature = "kusama-native")] pub fn kusama_staging_testnet_config() -> Result { - let wasm_binary = kusama::WASM_BINARY.ok_or("Kusama development wasm not available")?; let boot_nodes = vec![]; + #[allow(deprecated)] Ok(KusamaChainSpec::from_genesis( "Kusama Staging Testnet", "kusama_staging_testnet", ChainType::Live, - move || kusama_staging_testnet_config_genesis(wasm_binary), + move || kusama_staging_testnet_config_genesis(), boot_nodes, Some( TelemetryEndpoints::new(vec![(KUSAMA_STAGING_TELEMETRY_URL.to_string(), 0)]) @@ -1172,20 +1171,21 @@ pub fn kusama_staging_testnet_config() -> Result { 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 wasm_binary = westend::WASM_BINARY.ok_or("Westend development wasm not available")?; let boot_nodes = vec![]; + #[allow(deprecated)] Ok(WestendChainSpec::from_genesis( "Westend Staging Testnet", "westend_staging_testnet", ChainType::Live, - move || westend_staging_testnet_config_genesis(wasm_binary), + move || westend_staging_testnet_config_genesis(), boot_nodes, Some( TelemetryEndpoints::new(vec![(WESTEND_STAGING_TELEMETRY_URL.to_string(), 0)]) @@ -1195,21 +1195,22 @@ pub fn westend_staging_testnet_config() -> Result { 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 wasm_binary = rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?; 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(wasm_binary), + runtime_genesis_config: rococo_staging_testnet_config_genesis(), session_length_in_blocks: None, }, boot_nodes, @@ -1221,6 +1222,7 @@ pub fn rococo_staging_testnet_config() -> Result { None, None, Default::default(), + rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?, )) } @@ -1238,15 +1240,15 @@ 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![]; + #[allow(deprecated)] Ok(RococoChainSpec::from_genesis( "Versi Staging Testnet", "versi_staging_testnet", ChainType::Live, move || RococoGenesisExt { - runtime_genesis_config: rococo_staging_testnet_config_genesis(wasm_binary), + runtime_genesis_config: rococo_staging_testnet_config_genesis(), session_length_in_blocks: Some(100), }, boot_nodes, @@ -1258,6 +1260,7 @@ pub fn versi_staging_testnet_config() -> Result { None, Some(versi_chain_spec_properties()), Default::default(), + rococo::WASM_BINARY.ok_or("Versi development wasm not available")?, )) } @@ -1345,7 +1348,6 @@ fn testnet_accounts() -> Vec { /// Helper function to create polkadot `RuntimeGenesisConfig` for testing #[cfg(feature = "polkadot-native")] pub fn polkadot_testnet_genesis( - wasm_binary: &[u8], initial_authorities: Vec<( AccountId, AccountId, @@ -1365,7 +1367,7 @@ pub fn polkadot_testnet_genesis( const STASH: u128 = 100 * DOT; polkadot::RuntimeGenesisConfig { - system: polkadot::SystemConfig { code: wasm_binary.to_vec(), ..Default::default() }, + system: polkadot::SystemConfig::default(), indices: polkadot::IndicesConfig { indices: vec![] }, balances: polkadot::BalancesConfig { balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(), @@ -1436,7 +1438,6 @@ pub fn polkadot_testnet_genesis( /// Helper function to create kusama `RuntimeGenesisConfig` for testing #[cfg(feature = "kusama-native")] pub fn kusama_testnet_genesis( - wasm_binary: &[u8], initial_authorities: Vec<( AccountId, AccountId, @@ -1456,7 +1457,7 @@ pub fn kusama_testnet_genesis( const STASH: u128 = 100 * KSM; kusama::RuntimeGenesisConfig { - system: kusama::SystemConfig { code: wasm_binary.to_vec(), ..Default::default() }, + system: kusama::SystemConfig::default(), indices: kusama::IndicesConfig { indices: vec![] }, balances: kusama::BalancesConfig { balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(), @@ -1520,7 +1521,6 @@ pub fn kusama_testnet_genesis( /// Helper function to create westend `RuntimeGenesisConfig` for testing #[cfg(feature = "westend-native")] pub fn westend_testnet_genesis( - wasm_binary: &[u8], initial_authorities: Vec<( AccountId, AccountId, @@ -1540,7 +1540,7 @@ pub fn westend_testnet_genesis( const STASH: u128 = 100 * WND; westend::RuntimeGenesisConfig { - system: westend::SystemConfig { code: wasm_binary.to_vec(), ..Default::default() }, + system: westend::SystemConfig::default(), indices: westend::IndicesConfig { indices: vec![] }, balances: westend::BalancesConfig { balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(), @@ -1606,7 +1606,6 @@ pub fn westend_testnet_genesis( /// Helper function to create rococo `RuntimeGenesisConfig` for testing #[cfg(feature = "rococo-native")] pub fn rococo_testnet_genesis( - wasm_binary: &[u8], initial_authorities: Vec<( AccountId, AccountId, @@ -1626,7 +1625,7 @@ pub fn rococo_testnet_genesis( const ENDOWMENT: u128 = 1_000_000 * ROC; rococo_runtime::RuntimeGenesisConfig { - system: rococo_runtime::SystemConfig { code: wasm_binary.to_vec(), ..Default::default() }, + system: rococo_runtime::SystemConfig::default(), beefy: Default::default(), indices: rococo_runtime::IndicesConfig { indices: vec![] }, balances: rococo_runtime::BalancesConfig { @@ -1693,9 +1692,8 @@ pub fn rococo_testnet_genesis( } #[cfg(feature = "polkadot-native")] -fn polkadot_development_config_genesis(wasm_binary: &[u8]) -> polkadot::RuntimeGenesisConfig { +fn polkadot_development_config_genesis() -> polkadot::RuntimeGenesisConfig { polkadot_testnet_genesis( - wasm_binary, vec![get_authority_keys_from_seed_no_beefy("Alice")], get_account_id_from_seed::("Alice"), None, @@ -1703,9 +1701,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() -> kusama::RuntimeGenesisConfig { kusama_testnet_genesis( - wasm_binary, vec![get_authority_keys_from_seed_no_beefy("Alice")], get_account_id_from_seed::("Alice"), None, @@ -1713,9 +1710,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() -> westend::RuntimeGenesisConfig { westend_testnet_genesis( - wasm_binary, vec![get_authority_keys_from_seed_no_beefy("Alice")], get_account_id_from_seed::("Alice"), None, @@ -1723,9 +1719,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() -> rococo_runtime::RuntimeGenesisConfig { rococo_testnet_genesis( - wasm_binary, vec![get_authority_keys_from_seed("Alice")], get_account_id_from_seed::("Alice"), None, @@ -1735,71 +1730,70 @@ 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")?; - + #[allow(deprecated)] Ok(PolkadotChainSpec::from_genesis( "Development", "polkadot_dev", ChainType::Development, - move || polkadot_development_config_genesis(wasm_binary), + 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 { - let wasm_binary = kusama::WASM_BINARY.ok_or("Kusama development wasm not available")?; - + #[allow(deprecated)] Ok(KusamaChainSpec::from_genesis( "Development", "kusama_dev", ChainType::Development, - move || kusama_development_config_genesis(wasm_binary), + 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 { - let wasm_binary = westend::WASM_BINARY.ok_or("Westend development wasm not available")?; - + #[allow(deprecated)] Ok(WestendChainSpec::from_genesis( "Development", "westend_dev", ChainType::Development, - move || westend_development_config_genesis(wasm_binary), + 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 { - let wasm_binary = rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?; - + #[allow(deprecated)] Ok(RococoChainSpec::from_genesis( "Development", "rococo_dev", ChainType::Development, move || RococoGenesisExt { - runtime_genesis_config: rococo_development_config_genesis(wasm_binary), + runtime_genesis_config: rococo_development_config_genesis(), // Use 1 minute session length. session_length_in_blocks: Some(10), }, @@ -1809,20 +1803,20 @@ pub fn rococo_development_config() -> Result { 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 { - let wasm_binary = rococo::WASM_BINARY.ok_or("Versi development wasm not available")?; - + #[allow(deprecated)] Ok(RococoChainSpec::from_genesis( "Development", "versi_dev", ChainType::Development, move || RococoGenesisExt { - runtime_genesis_config: rococo_development_config_genesis(wasm_binary), + runtime_genesis_config: rococo_development_config_genesis(), // Use 1 minute session length. session_length_in_blocks: Some(10), }, @@ -1832,6 +1826,7 @@ pub fn versi_development_config() -> Result { None, None, Default::default(), + rococo::WASM_BINARY.ok_or("Versi development wasm not available")?, )) } @@ -1839,14 +1834,14 @@ pub fn versi_development_config() -> Result { #[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")?; + #[allow(deprecated)] Ok(RococoChainSpec::from_genesis( "Development", "wococo_dev", ChainType::Development, move || RococoGenesisExt { - runtime_genesis_config: rococo_development_config_genesis(wasm_binary), + runtime_genesis_config: rococo_development_config_genesis(), // Use 1 minute session length. session_length_in_blocks: Some(10), }, @@ -1856,13 +1851,13 @@ pub fn wococo_development_config() -> Result { None, None, Default::default(), + rococo::WASM_BINARY.ok_or("Wococo development wasm not available")?, )) } #[cfg(feature = "polkadot-native")] -fn polkadot_local_testnet_genesis(wasm_binary: &[u8]) -> polkadot::RuntimeGenesisConfig { +fn polkadot_local_testnet_genesis() -> polkadot::RuntimeGenesisConfig { polkadot_testnet_genesis( - wasm_binary, vec![ get_authority_keys_from_seed_no_beefy("Alice"), get_authority_keys_from_seed_no_beefy("Bob"), @@ -1875,26 +1870,25 @@ 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")?; - + #[allow(deprecated)] Ok(PolkadotChainSpec::from_genesis( "Local Testnet", "local_testnet", ChainType::Local, - move || polkadot_local_testnet_genesis(wasm_binary), + 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(wasm_binary: &[u8]) -> kusama::RuntimeGenesisConfig { +fn kusama_local_testnet_genesis() -> kusama::RuntimeGenesisConfig { kusama_testnet_genesis( - wasm_binary, vec![ get_authority_keys_from_seed_no_beefy("Alice"), get_authority_keys_from_seed_no_beefy("Bob"), @@ -1907,26 +1901,25 @@ 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")?; - + #[allow(deprecated)] Ok(KusamaChainSpec::from_genesis( "Kusama Local Testnet", "kusama_local_testnet", ChainType::Local, - move || kusama_local_testnet_genesis(wasm_binary), + 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(wasm_binary: &[u8]) -> westend::RuntimeGenesisConfig { +fn westend_local_testnet_genesis() -> westend::RuntimeGenesisConfig { westend_testnet_genesis( - wasm_binary, vec![ get_authority_keys_from_seed_no_beefy("Alice"), get_authority_keys_from_seed_no_beefy("Bob"), @@ -1939,26 +1932,25 @@ 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")?; - + #[allow(deprecated)] Ok(WestendChainSpec::from_genesis( "Westend Local Testnet", "westend_local_testnet", ChainType::Local, - move || westend_local_testnet_genesis(wasm_binary), + 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(wasm_binary: &[u8]) -> rococo_runtime::RuntimeGenesisConfig { +fn rococo_local_testnet_genesis() -> rococo_runtime::RuntimeGenesisConfig { 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, @@ -1968,14 +1960,13 @@ 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")?; - + #[allow(deprecated)] Ok(RococoChainSpec::from_genesis( "Rococo Local Testnet", "rococo_local_testnet", ChainType::Local, move || RococoGenesisExt { - runtime_genesis_config: rococo_local_testnet_genesis(wasm_binary), + runtime_genesis_config: rococo_local_testnet_genesis(), // Use 1 minute session length. session_length_in_blocks: Some(10), }, @@ -1985,14 +1976,14 @@ pub fn rococo_local_testnet_config() -> Result { 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(wasm_binary: &[u8]) -> rococo_runtime::RuntimeGenesisConfig { +fn wococo_local_testnet_genesis() -> rococo_runtime::RuntimeGenesisConfig { rococo_testnet_genesis( - wasm_binary, vec![ get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob"), @@ -2007,14 +1998,13 @@ 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")?; - + #[allow(deprecated)] Ok(RococoChainSpec::from_genesis( "Wococo Local Testnet", "wococo_local_testnet", ChainType::Local, move || RococoGenesisExt { - runtime_genesis_config: wococo_local_testnet_genesis(wasm_binary), + runtime_genesis_config: wococo_local_testnet_genesis(), // Use 1 minute session length. session_length_in_blocks: Some(10), }, @@ -2024,14 +2014,14 @@ pub fn wococo_local_testnet_config() -> Result { 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(wasm_binary: &[u8]) -> rococo_runtime::RuntimeGenesisConfig { +fn versi_local_testnet_genesis() -> rococo_runtime::RuntimeGenesisConfig { rococo_testnet_genesis( - wasm_binary, vec![ get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob"), @@ -2046,14 +2036,13 @@ 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")?; - + #[allow(deprecated)] Ok(RococoChainSpec::from_genesis( "Versi Local Testnet", "versi_local_testnet", ChainType::Local, move || RococoGenesisExt { - runtime_genesis_config: versi_local_testnet_genesis(wasm_binary), + runtime_genesis_config: versi_local_testnet_genesis(), // Use 1 minute session length. session_length_in_blocks: Some(10), }, @@ -2063,5 +2052,6 @@ pub fn versi_local_testnet_config() -> Result { None, None, Default::default(), + rococo::WASM_BINARY.ok_or("Versi development wasm not available")?, )) } diff --git a/node/test/client/src/lib.rs b/node/test/client/src/lib.rs index 5d97ffcdf1da..6b205c09f2f3 100644 --- a/node/test/client/src/lib.rs +++ b/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/node/test/service/src/chain_spec.rs b/node/test/service/src/chain_spec.rs index 876bbb8806b4..c5a665ff8af3 100644 --- a/node/test/service/src/chain_spec.rs +++ b/node/test/service/src/chain_spec.rs @@ -38,6 +38,7 @@ pub type PolkadotChainSpec = /// Local testnet config (multivalidator Alice + Bob) pub fn polkadot_local_testnet_config() -> PolkadotChainSpec { + #[allow(deprecated)] PolkadotChainSpec::from_genesis( "Local Testnet", "local_testnet", @@ -49,6 +50,7 @@ pub fn polkadot_local_testnet_config() -> PolkadotChainSpec { None, Some(polkadot_chain_spec_properties()), Default::default(), + polkadot_test_runtime::WASM_BINARY.expect("Wasm binary must be built for testing"), ) } @@ -115,10 +117,7 @@ fn polkadot_testnet_genesis( 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() - }, + system: runtime::SystemConfig { ..Default::default() }, indices: runtime::IndicesConfig { indices: vec![] }, balances: runtime::BalancesConfig { balances: endowed_accounts.iter().map(|k| (k.clone(), ENDOWMENT)).collect(), From 9d6fc63a252cc06ed8c0e1f901ea44c4d7144b80 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 18 Jul 2023 11:44:31 +0200 Subject: [PATCH 02/15] ChainSpec: tests agains legacy added --- node/service/src/chain_spec.rs | 137 ++ .../src/chain_spec/legacy_chain_spec.rs | 2058 +++++++++++++++++ 2 files changed, 2195 insertions(+) create mode 100644 node/service/src/chain_spec/legacy_chain_spec.rs diff --git a/node/service/src/chain_spec.rs b/node/service/src/chain_spec.rs index 94f7671fbaab..a5ea1f99d27e 100644 --- a/node/service/src/chain_spec.rs +++ b/node/service/src/chain_spec.rs @@ -2055,3 +2055,140 @@ pub fn versi_local_testnet_config() -> Result { rococo::WASM_BINARY.ok_or("Versi development wasm not available")?, )) } + +mod legacy_chain_spec; +// Tests RuntimeGenesisConfig-based ChainSpecs against the JSON-genesis-config-based +// ChainSpecs. Shall be removed once native runtime is removed. +#[cfg(test)] +mod json_vs_legacy_tests { + 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 j1 = rococo_staging_testnet_config().unwrap().as_json(true).unwrap(); + let j2 = legacy::rococo_staging_testnet_config().unwrap().as_json(true).unwrap(); + assert_eq!(j1, j2); + } + + #[test] + #[cfg(feature = "rococo-native")] + fn rococo_development_config_compare_test() { + let j1 = rococo_development_config().unwrap().as_json(true).unwrap(); + let j2 = legacy::rococo_development_config().unwrap().as_json(true).unwrap(); + assert_eq!(j1, j2); + } + + #[test] + #[cfg(feature = "rococo-native")] + fn rococo_local_testnet_config_compare_test() { + let j1 = rococo_local_testnet_config().unwrap().as_json(true).unwrap(); + let j2 = legacy::rococo_local_testnet_config().unwrap().as_json(true).unwrap(); + assert_eq!(j1, j2); + } + + #[test] + #[cfg(feature = "rococo-native")] + fn wococo_development_config_compare_test() { + let j1 = wococo_development_config().unwrap().as_json(true).unwrap(); + let j2 = legacy::wococo_development_config().unwrap().as_json(true).unwrap(); + assert_eq!(j1, j2); + } + + #[test] + #[cfg(feature = "rococo-native")] + fn wococo_local_testnet_config_compare_test() { + let j1 = wococo_local_testnet_config().unwrap().as_json(true).unwrap(); + let j2 = legacy::wococo_local_testnet_config().unwrap().as_json(true).unwrap(); + assert_eq!(j1, j2); + } + + + #[test] + #[cfg(feature = "rococo-native")] + fn versi_staging_testnet_config_compare_test() { + let j1 = versi_staging_testnet_config().unwrap().as_json(true).unwrap(); + let j2 = legacy::versi_staging_testnet_config().unwrap().as_json(true).unwrap(); + assert_eq!(j1, j2); + } + + #[test] + #[cfg(feature = "rococo-native")] + fn versi_development_config_compare_test() { + let j1 = versi_development_config().unwrap().as_json(true).unwrap(); + let j2 = legacy::versi_development_config().unwrap().as_json(true).unwrap(); + assert_eq!(j1, j2); + } + + #[test] + #[cfg(feature = "rococo-native")] + fn versi_local_testnet_config_compare_test() { + let j1 = versi_local_testnet_config().unwrap().as_json(true).unwrap(); + let j2 = legacy::versi_local_testnet_config().unwrap().as_json(true).unwrap(); + assert_eq!(j1, j2); + } +} diff --git a/node/service/src/chain_spec/legacy_chain_spec.rs b/node/service/src/chain_spec/legacy_chain_spec.rs new file mode 100644 index 000000000000..ba3da2a05f12 --- /dev/null +++ b/node/service/src/chain_spec/legacy_chain_spec.rs @@ -0,0 +1,2058 @@ +// 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::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 = "polkadot-native")] +const POLKADOT_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; +#[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; + +// Dummy chain spec, in case when we don't have the native runtime. +pub type DummyChainSpec = service::GenericChainSpec<(), Extensions>; + +// Dummy chain spec, but that is fine when we don't have the native runtime. +#[cfg(not(feature = "polkadot-native"))] +pub type PolkadotChainSpec = DummyChainSpec; + +/// 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 `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 = 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")[..]) +} + +pub fn kusama_config() -> Result { + KusamaChainSpec::from_json_bytes(&include_bytes!("../../chain-specs/kusama.json")[..]) +} + +pub fn westend_config() -> Result { + WestendChainSpec::from_json_bytes(&include_bytes!("../../chain-specs/westend.json")[..]) +} + +pub fn rococo_config() -> Result { + RococoChainSpec::from_json_bytes(&include_bytes!("../../chain-specs/rococo.json")[..]) +} + +/// This is a temporary testnet that uses the same runtime as rococo. +pub fn wococo_config() -> Result { + RococoChainSpec::from_json_bytes(&include_bytes!("../../chain-specs/wococo.json")[..]) +} + +/// 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 = "polkadot-native")] +fn polkadot_staging_testnet_config_genesis() -> polkadot::RuntimeGenesisConfig { + // subkey inspect "$SECRET" + let endowed_accounts = vec![]; + + let initial_authorities: Vec<( + AccountId, + AccountId, + BabeId, + GrandpaId, + ImOnlineId, + ValidatorId, + AssignmentId, + AuthorityDiscoveryId, + )> = vec![]; + + const ENDOWMENT: u128 = 1_000_000 * DOT; + const STASH: u128 = 100 * DOT; + + polkadot::RuntimeGenesisConfig { + system: polkadot::SystemConfig::default(), + balances: polkadot::BalancesConfig { + balances: endowed_accounts + .iter() + .map(|k: &AccountId| (k.clone(), ENDOWMENT)) + .chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH))) + .collect(), + }, + indices: polkadot::IndicesConfig { indices: vec![] }, + 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 { + validator_count: 50, + minimum_validator_count: 4, + 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::ForceNone, + slash_reward_fraction: Perbill::from_percent(10), + ..Default::default() + }, + phragmen_election: Default::default(), + democracy: Default::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(), + } +} + +#[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() +} + +/// Polkadot staging testnet config. +#[cfg(feature = "polkadot-native")] +pub fn polkadot_staging_testnet_config() -> Result { + let boot_nodes = vec![]; + + #[allow(deprecated)] + Ok(PolkadotChainSpec::from_genesis( + "Polkadot Staging Testnet", + "polkadot_staging_testnet", + ChainType::Live, + move || polkadot_staging_testnet_config_genesis(), + boot_nodes, + Some( + TelemetryEndpoints::new(vec![(POLKADOT_STAGING_TELEMETRY_URL.to_string(), 0)]) + .expect("Polkadot Staging telemetry url is valid; qed"), + ), + Some(DEFAULT_PROTOCOL_ID), + None, + Some(polkadot_chain_spec_properties()), + Default::default(), + polkadot::WASM_BINARY.ok_or("Polkadot development wasm not available")?, + )) +} + +/// 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")?, + )) +} From 9f0581aba0b11443140e89d09c915f30b9d6469c Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 18 Jul 2023 11:57:09 +0200 Subject: [PATCH 03/15] runtimes: genesis-builder implemented --- runtime/kusama/Cargo.toml | 1 + runtime/kusama/src/lib.rs | 14 +++++++++++++- runtime/polkadot/Cargo.toml | 1 + runtime/polkadot/src/lib.rs | 15 ++++++++++++++- runtime/rococo/Cargo.toml | 1 + runtime/rococo/src/lib.rs | 14 +++++++++++++- runtime/westend/Cargo.toml | 1 + runtime/westend/src/lib.rs | 14 +++++++++++++- 8 files changed, 57 insertions(+), 4 deletions(-) diff --git a/runtime/kusama/Cargo.toml b/runtime/kusama/Cargo.toml index 34de027369af..c4252b6f0614 100644 --- a/runtime/kusama/Cargo.toml +++ b/runtime/kusama/Cargo.toml @@ -25,6 +25,7 @@ inherents = { package = "sp-inherents", git = "https://github.com/paritytech/sub offchain-primitives = { package = "sp-offchain", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-std = { package = "sp-std", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +sp-genesis-builder = { package = "sp-genesis-builder", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-mmr-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index 17d5d8b4bdac..6a53b6abb323 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -56,7 +56,9 @@ use frame_election_provider_support::{ generate_solution_type, onchain, NposSolution, SequentialPhragmen, }; use frame_support::{ - construct_runtime, parameter_types, + construct_runtime, + genesis_builder_helper::{build_config, create_default_config}, + parameter_types, traits::{ ConstU32, Contains, EitherOf, EitherOfDiverse, InstanceFilter, KeyOwnerProofSystem, PrivilegeCmp, ProcessMessage, ProcessMessageError, StorageMapShim, WithdrawReasons, @@ -2294,6 +2296,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/runtime/polkadot/Cargo.toml b/runtime/polkadot/Cargo.toml index bfd31702d02c..ccab983871eb 100644 --- a/runtime/polkadot/Cargo.toml +++ b/runtime/polkadot/Cargo.toml @@ -26,6 +26,7 @@ tx-pool-api = { package = "sp-transaction-pool", git = "https://github.com/parit sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-std = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +sp-genesis-builder = { package = "sp-genesis-builder", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-mmr-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } diff --git a/runtime/polkadot/src/lib.rs b/runtime/polkadot/src/lib.rs index 627a336b8bcb..80fcf136895f 100644 --- a/runtime/polkadot/src/lib.rs +++ b/runtime/polkadot/src/lib.rs @@ -42,7 +42,9 @@ use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; use beefy_primitives::crypto::{AuthorityId as BeefyId, Signature as BeefySignature}; use frame_election_provider_support::{generate_solution_type, onchain, SequentialPhragmen}; use frame_support::{ - construct_runtime, parameter_types, + construct_runtime, + genesis_builder_helper::{build_config, create_default_config}, + parameter_types, traits::{ ConstU32, EitherOf, EitherOfDiverse, InstanceFilter, KeyOwnerProofSystem, LockIdentifier, PrivilegeCmp, ProcessMessage, ProcessMessageError, WithdrawReasons, @@ -2161,6 +2163,17 @@ 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/runtime/rococo/Cargo.toml b/runtime/rococo/Cargo.toml index ae4a5777f497..d57be06fe2bf 100644 --- a/runtime/rococo/Cargo.toml +++ b/runtime/rococo/Cargo.toml @@ -23,6 +23,7 @@ sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", d inherents = { package = "sp-inherents", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } offchain-primitives = { package = "sp-offchain", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-std = { package = "sp-std", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +sp-genesis-builder = { package = "sp-genesis-builder", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-mmr-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index 9c57305f8e3f..c91aabbd8b6e 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -56,7 +56,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, @@ -2325,6 +2327,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/runtime/westend/Cargo.toml b/runtime/westend/Cargo.toml index b68615ff1a4f..e2848a972300 100644 --- a/runtime/westend/Cargo.toml +++ b/runtime/westend/Cargo.toml @@ -22,6 +22,7 @@ inherents = { package = "sp-inherents", git = "https://github.com/paritytech/sub offchain-primitives = { package = "sp-offchain", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-std = { package = "sp-std", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +sp-genesis-builder = { package = "sp-genesis-builder", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-mmr-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index 4a7551873b3b..a85af06293b0 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -24,7 +24,9 @@ use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; use beefy_primitives::crypto::{AuthorityId as BeefyId, Signature as BeefySignature}; 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::{ ConstU32, InstanceFilter, KeyOwnerProofSystem, ProcessMessage, ProcessMessageError, WithdrawReasons, @@ -2035,6 +2037,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)] From f6a65f238da1e2f1d529d0022a608cb9d2cc6241 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 20 Jul 2023 11:57:00 +0200 Subject: [PATCH 04/15] rococo-runtime: EpochDurationInBlock is controlled by feature New feature fast-runtime-10m was added. This adds new rococo-runtime blob with hard-coded epochDuration. This prevents from manipulating the state to change the runtime constants. This commit also allows to remove `RococoGenesisExt` hack. --- runtime/common/src/lib.rs | 14 +++++++++++- runtime/rococo/Cargo.toml | 3 ++- runtime/rococo/build.rs | 35 ++++++++++++++++++++++++----- runtime/rococo/constants/Cargo.toml | 4 ++++ runtime/rococo/constants/src/lib.rs | 3 ++- runtime/rococo/src/lib.rs | 10 +++++++++ 6 files changed, 61 insertions(+), 8 deletions(-) diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index ea525132b7b3..8d340473ea8c 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -247,7 +247,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: @@ -256,6 +257,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] @@ -267,6 +270,15 @@ macro_rules! prod_or_fast { $prod } }; + ($prod:expr, $feature1:expr, $value1:expr, $feature2:expr, $value2:expr) => { + if cfg!(feature = $feature1) { + $value1 + } else if cfg!(feature = $feature2) { + $value2 + } else { + $prod + } + }; ($prod:expr, $test:expr, $env:expr) => { if cfg!(feature = "fast-runtime") { core::option_env!($env).map(|s| s.parse().ok()).flatten().unwrap_or($test) diff --git a/runtime/rococo/Cargo.toml b/runtime/rococo/Cargo.toml index d57be06fe2bf..d227d011042a 100644 --- a/runtime/rococo/Cargo.toml +++ b/runtime/rococo/Cargo.toml @@ -274,6 +274,7 @@ 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" ] +fast-runtime-10m = [ "rococo-runtime-constants/fast-runtime-10m" ] runtime-metrics = ["runtime-parachains/runtime-metrics", "sp-io/with-tracing"] diff --git a/runtime/rococo/build.rs b/runtime/rococo/build.rs index e7134e0ef723..8937d92ea758 100644 --- a/runtime/rococo/build.rs +++ b/runtime/rococo/build.rs @@ -17,9 +17,34 @@ use substrate_wasm_builder::WasmBuilder; fn main() { - WasmBuilder::new() - .with_current_project() - .import_memory() - .export_heap_base() - .build() + #[cfg(feature = "std")] + { + WasmBuilder::new() + .with_current_project() + .import_memory() + .export_heap_base() + .build(); + } + + #[cfg(feature = "std")] + { + WasmBuilder::new() + .with_current_project() + .set_file_name("rococo_runtime_fast_runtime_1m.rs") + .import_memory() + .export_heap_base() + .enable_feature("fast-runtime") + .build(); + } + + #[cfg(feature = "std")] + { + WasmBuilder::new() + .with_current_project() + .set_file_name("rococo_runtime_fast_runtime_10m.rs") + .import_memory() + .export_heap_base() + .enable_feature("fast-runtime-10m") + .build() + } } diff --git a/runtime/rococo/constants/Cargo.toml b/runtime/rococo/constants/Cargo.toml index 9383a9de6c68..c8a7e2ea943d 100644 --- a/runtime/rococo/constants/Cargo.toml +++ b/runtime/rococo/constants/Cargo.toml @@ -24,3 +24,7 @@ std = [ "sp-runtime/std", "sp-weights/std" ] + +# Set timing constants (e.g. session period) to faster versions to speed up testing. +fast-runtime = [] +fast-runtime-10m = [] diff --git a/runtime/rococo/constants/src/lib.rs b/runtime/rococo/constants/src/lib.rs index 214e2f3fa980..e3f8da4936d2 100644 --- a/runtime/rococo/constants/src/lib.rs +++ b/runtime/rococo/constants/src/lib.rs @@ -41,7 +41,8 @@ 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); + pub const DEFAULT_EPOCH_DURATION: BlockNumber = + prod_or_fast!(1 * HOURS, "fast-runtime", 1 * MINUTES, "fast-runtime-10m", 10 * MINUTES); frame_support::parameter_types! { pub storage EpochDurationInBlocks: BlockNumber = DEFAULT_EPOCH_DURATION; } diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index c91aabbd8b6e..f21ffce86598 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -108,6 +108,16 @@ impl_runtime_weights!(rococo_runtime_constants); #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); +#[cfg(feature = "std")] +pub mod rococo_runtime_fast_runtime_10m { + include!(concat!(env!("OUT_DIR"), "/rococo_runtime_fast_runtime_10m.rs")); +} + +#[cfg(feature = "std")] +pub mod rococo_runtime_fast_runtime_1m { + include!(concat!(env!("OUT_DIR"), "/rococo_runtime_fast_runtime_1m.rs")); +} + /// Runtime version (Rococo). #[sp_version::runtime_version] pub const VERSION: RuntimeVersion = RuntimeVersion { From 52b4d8c13e51854665982551ad09615aea780fdc Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 20 Jul 2023 12:06:07 +0200 Subject: [PATCH 05/15] polkadot_staging_testnet_config removed --- cli/src/command.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/cli/src/command.rs b/cli/src/command.rs index 6184a8349234..8697f999b545 100644 --- a/cli/src/command.rs +++ b/cli/src/command.rs @@ -105,8 +105,6 @@ impl SubstrateCli for Cli { "polkadot-dev" | "dev" => Box::new(service::chain_spec::polkadot_development_config()?), #[cfg(feature = "polkadot-native")] "polkadot-local" => Box::new(service::chain_spec::polkadot_local_testnet_config()?), - #[cfg(feature = "polkadot-native")] - "polkadot-staging" => Box::new(service::chain_spec::polkadot_staging_testnet_config()?), "rococo" => Box::new(service::chain_spec::rococo_config()?), #[cfg(feature = "rococo-native")] "rococo-dev" => Box::new(service::chain_spec::rococo_development_config()?), From cfc2dcbb9a6e278e2dc83d2761f2b990fe72e6c0 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 20 Jul 2023 12:30:25 +0200 Subject: [PATCH 06/15] chain-specs: RuntimeGenesisConfig remove, JSON patches added In this commit: - all references to `RuntimeGenesisConfig` are removed, - `RococoGenesisExt` is removed. It was the hack to allow overwriting `EpochDurationInBlocks` (1m/10m/60m rococo runtimes are now available), - all `(kusama|polkadot|versi|rococo|wococo)_(staging|dev)_genesis_config` functions now return the JSON patch for default runtime `GenesisConfig`, - ChainSpecBuilder is used, `from_gensis` is removed, --- node/service/src/chain_spec.rs | 1039 ++++++++++++-------------------- 1 file changed, 396 insertions(+), 643 deletions(-) diff --git a/node/service/src/chain_spec.rs b/node/service/src/chain_spec.rs index a5ea1f99d27e..d6d57d56ecf2 100644 --- a/node/service/src/chain_spec.rs +++ b/node/service/src/chain_spec.rs @@ -107,7 +107,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>; @@ -118,7 +118,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. @@ -127,7 +127,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. @@ -136,42 +136,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")[..]) } @@ -423,7 +394,7 @@ fn polkadot_staging_testnet_config_genesis() -> polkadot::RuntimeGenesisConfig { } #[cfg(feature = "westend-native")] -fn westend_staging_testnet_config_genesis() -> westend::RuntimeGenesisConfig { +fn westend_staging_testnet_config_genesis() -> serde_json::Value { use hex_literal::hex; use sp_core::crypto::UncheckedInto; @@ -544,18 +515,16 @@ fn westend_staging_testnet_config_genesis() -> westend::RuntimeGenesisConfig { const ENDOWMENT: u128 = 1_000_000 * WND; const STASH: u128 = 100 * WND; - westend::RuntimeGenesisConfig { - system: westend::SystemConfig::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::>(), }, - indices: westend::IndicesConfig { indices: vec![] }, - session: westend::SessionConfig { - keys: initial_authorities + "session": { + "keys": initial_authorities .iter() .map(|x| { ( @@ -573,47 +542,32 @@ fn westend_staging_testnet_config_genesis() -> westend::RuntimeGenesisConfig { }) .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(), - } + }) } #[cfg(feature = "kusama-native")] -fn kusama_staging_testnet_config_genesis() -> kusama::RuntimeGenesisConfig { +fn kusama_staging_testnet_config_genesis() -> serde_json::Value { use hex_literal::hex; use sp_core::crypto::UncheckedInto; @@ -739,18 +693,16 @@ fn kusama_staging_testnet_config_genesis() -> kusama::RuntimeGenesisConfig { const ENDOWMENT: u128 = 1_000_000 * KSM; const STASH: u128 = 100 * KSM; - kusama::RuntimeGenesisConfig { - system: kusama::SystemConfig::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::>(), }, - indices: kusama::IndicesConfig { indices: vec![] }, - session: kusama::SessionConfig { - keys: initial_authorities + "session": { + "keys": initial_authorities .iter() .map(|x| { ( @@ -768,45 +720,28 @@ fn kusama_staging_testnet_config_genesis() -> kusama::RuntimeGenesisConfig { }) .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() + .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), }, - babe: kusama::BabeConfig { - authorities: Default::default(), - epoch_config: Some(kusama::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() + "babe": { + "epochConfig": Some(kusama::BABE_GENESIS_EPOCH_CONFIG), }, - grandpa: Default::default(), - im_online: Default::default(), - authority_discovery: kusama::AuthorityDiscoveryConfig { - keys: vec![], - ..Default::default() + "configuration": { + "config": default_parachains_host_configuration(), }, - 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 { +fn rococo_staging_testnet_config_genesis() -> serde_json::Value { use hex_literal::hex; use sp_core::crypto::UncheckedInto; @@ -1049,19 +984,16 @@ fn rococo_staging_testnet_config_genesis() -> rococo_runtime::RuntimeGenesisConf 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 + 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| { ( @@ -1080,41 +1012,17 @@ fn rococo_staging_testnet_config_genesis() -> rococo_runtime::RuntimeGenesisConf }) .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(), + "babe": { + "epochConfig": Some(rococo_runtime::BABE_GENESIS_EPOCH_CONFIG), }, - technical_membership: Default::default(), - treasury: Default::default(), - authority_discovery: rococo_runtime::AuthorityDiscoveryConfig { - keys: vec![], - ..Default::default() + "sudo": { "key": Some(endowed_accounts[0].clone()) }, + "configuration": { + "config": default_parachains_host_configuration(), }, - 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": { + "nextFreeParaId": polkadot_primitives::LOWEST_PUBLIC_ID, }, - 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`]. @@ -1127,103 +1035,58 @@ pub fn polkadot_chain_spec_properties() -> serde_json::map::Map Result { - let boot_nodes = vec![]; - - #[allow(deprecated)] - Ok(PolkadotChainSpec::from_genesis( - "Polkadot Staging Testnet", - "polkadot_staging_testnet", - ChainType::Live, - move || polkadot_staging_testnet_config_genesis(), - boot_nodes, - Some( - TelemetryEndpoints::new(vec![(POLKADOT_STAGING_TELEMETRY_URL.to_string(), 0)]) - .expect("Polkadot Staging telemetry url is valid; qed"), - ), - Some(DEFAULT_PROTOCOL_ID), - None, - Some(polkadot_chain_spec_properties()), - Default::default(), - polkadot::WASM_BINARY.ok_or("Polkadot development wasm not available")?, - )) -} - /// 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( + 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(), - kusama::WASM_BINARY.ok_or("Kusama development wasm not available")?, - )) + ) + .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 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( + 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(), - westend::WASM_BINARY.ok_or("Westend development wasm not available")?, - )) + ) + .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 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( + 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(), - rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?, - )) + ) + .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 { @@ -1240,28 +1103,23 @@ pub fn versi_chain_spec_properties() -> serde_json::map::Map 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( + 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(), - rococo::WASM_BINARY.ok_or("Versi development wasm not available")?, - )) + ) + .with_protocol_id("versi") + .with_properties(versi_chain_spec_properties()) + .with_extensions(Default::default()) + .with_code( + rococo::rococo_runtime_fast_runtime_10m::WASM_BINARY + .ok_or("Versi development wasm not available")?, + ) + .build()) } /// Helper function to generate a crypto pair from seed @@ -1345,7 +1203,7 @@ 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( initial_authorities: Vec<( @@ -1360,20 +1218,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::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| { ( @@ -1391,51 +1247,27 @@ 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() - }, - 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() + .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( initial_authorities: Vec<( @@ -1450,20 +1282,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::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::>(), }, - session: kusama::SessionConfig { - keys: initial_authorities + "session": { + "keys": initial_authorities .iter() .map(|x| { ( @@ -1481,44 +1311,27 @@ 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() + .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), }, - babe: kusama::BabeConfig { - authorities: Default::default(), - epoch_config: Some(kusama::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() + "babe": { + "epochConfig": Some(kusama::BABE_GENESIS_EPOCH_CONFIG), }, - 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(), + "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( initial_authorities: Vec<( @@ -1533,20 +1346,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::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::>(), }, - session: westend::SessionConfig { - keys: initial_authorities + "session": { + "keys": initial_authorities .iter() .map(|x| { ( @@ -1564,46 +1375,31 @@ 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() + .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), }, - babe: westend::BabeConfig { - authorities: Default::default(), - epoch_config: Some(westend::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() + "babe": { + "epochConfig": Some(westend::BABE_GENESIS_EPOCH_CONFIG), }, - grandpa: Default::default(), - im_online: Default::default(), - authority_discovery: westend::AuthorityDiscoveryConfig { - keys: vec![], - ..Default::default() + "sudo": { "key": Some(root_key) }, + "configuration": { + "config": default_parachains_host_configuration(), }, - vesting: westend::VestingConfig { vesting: vec![] }, - sudo: westend::SudoConfig { key: Some(root_key) }, - hrmp: Default::default(), - configuration: westend::ConfigurationConfig { - config: default_parachains_host_configuration(), + "registrar": { + "nextFreeParaId": polkadot_primitives::LOWEST_PUBLIC_ID, }, - 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 +/// Helper function to create rococo runtime `GenesisConfig` patch for testing #[cfg(feature = "rococo-native")] pub fn rococo_testnet_genesis( initial_authorities: Vec<( @@ -1619,20 +1415,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::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| { ( @@ -1651,48 +1444,24 @@ pub fn rococo_testnet_genesis( }) .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() + "babe": { + "epochConfig": Some(rococo_runtime::BABE_GENESIS_EPOCH_CONFIG), }, - 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(), - } + "registrar": { + "nextFreeParaId": polkadot_primitives::LOWEST_PUBLIC_ID, + } + }) } #[cfg(feature = "polkadot-native")] -fn polkadot_development_config_genesis() -> polkadot::RuntimeGenesisConfig { +fn polkadot_development_config_genesis() -> serde_json::Value { polkadot_testnet_genesis( vec![get_authority_keys_from_seed_no_beefy("Alice")], get_account_id_from_seed::("Alice"), @@ -1701,7 +1470,7 @@ fn polkadot_development_config_genesis() -> polkadot::RuntimeGenesisConfig { } #[cfg(feature = "kusama-native")] -fn kusama_development_config_genesis() -> kusama::RuntimeGenesisConfig { +fn kusama_development_config_genesis() -> serde_json::Value { kusama_testnet_genesis( vec![get_authority_keys_from_seed_no_beefy("Alice")], get_account_id_from_seed::("Alice"), @@ -1710,7 +1479,7 @@ fn kusama_development_config_genesis() -> kusama::RuntimeGenesisConfig { } #[cfg(feature = "westend-native")] -fn westend_development_config_genesis() -> westend::RuntimeGenesisConfig { +fn westend_development_config_genesis() -> serde_json::Value { westend_testnet_genesis( vec![get_authority_keys_from_seed_no_beefy("Alice")], get_account_id_from_seed::("Alice"), @@ -1719,7 +1488,7 @@ fn westend_development_config_genesis() -> westend::RuntimeGenesisConfig { } #[cfg(feature = "rococo-native")] -fn rococo_development_config_genesis() -> rococo_runtime::RuntimeGenesisConfig { +fn rococo_development_config_genesis() -> serde_json::Value { rococo_testnet_genesis( vec![get_authority_keys_from_seed("Alice")], get_account_id_from_seed::("Alice"), @@ -1730,133 +1499,100 @@ fn rococo_development_config_genesis() -> rococo_runtime::RuntimeGenesisConfig { /// 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")?, - )) + 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 { - #[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")?, - )) + 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 { - #[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")?, - )) + 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 { - #[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")?, - )) + 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::rococo_runtime_fast_runtime_1m::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 { - #[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")?, - )) + 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::rococo_runtime_fast_runtime_1m::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"; - - #[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")?, - )) + 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::rococo_runtime_fast_runtime_1m::WASM_BINARY + .ok_or("Wococo development wasm not available")?, + ) + .build()) } #[cfg(feature = "polkadot-native")] -fn polkadot_local_testnet_genesis() -> polkadot::RuntimeGenesisConfig { +fn polkadot_local_testnet_genesis() -> serde_json::Value { polkadot_testnet_genesis( vec![ get_authority_keys_from_seed_no_beefy("Alice"), @@ -1870,24 +1606,20 @@ fn polkadot_local_testnet_genesis() -> polkadot::RuntimeGenesisConfig { /// 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")?, - )) + 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() -> kusama::RuntimeGenesisConfig { +fn kusama_local_testnet_genesis() -> serde_json::Value { kusama_testnet_genesis( vec![ get_authority_keys_from_seed_no_beefy("Alice"), @@ -1901,24 +1633,19 @@ fn kusama_local_testnet_genesis() -> kusama::RuntimeGenesisConfig { /// 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")?, - )) + 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() -> westend::RuntimeGenesisConfig { +fn westend_local_testnet_genesis() -> serde_json::Value { westend_testnet_genesis( vec![ get_authority_keys_from_seed_no_beefy("Alice"), @@ -1932,24 +1659,19 @@ fn westend_local_testnet_genesis() -> westend::RuntimeGenesisConfig { /// 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")?, - )) + 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() -> rococo_runtime::RuntimeGenesisConfig { +fn rococo_local_testnet_genesis() -> serde_json::Value { rococo_testnet_genesis( vec![get_authority_keys_from_seed("Alice"), get_authority_keys_from_seed("Bob")], get_account_id_from_seed::("Alice"), @@ -1960,29 +1682,23 @@ fn rococo_local_testnet_genesis() -> rococo_runtime::RuntimeGenesisConfig { /// 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")?, - )) + 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::rococo_runtime_fast_runtime_1m::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() -> rococo_runtime::RuntimeGenesisConfig { +fn wococo_local_testnet_genesis() -> serde_json::Value { rococo_testnet_genesis( vec![ get_authority_keys_from_seed("Alice"), @@ -1998,29 +1714,23 @@ fn wococo_local_testnet_genesis() -> rococo_runtime::RuntimeGenesisConfig { /// 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")?, - )) + 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::rococo_runtime_fast_runtime_1m::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() -> rococo_runtime::RuntimeGenesisConfig { +fn versi_local_testnet_genesis() -> serde_json::Value { rococo_testnet_genesis( vec![ get_authority_keys_from_seed("Alice"), @@ -2036,31 +1746,45 @@ fn versi_local_testnet_genesis() -> rococo_runtime::RuntimeGenesisConfig { /// `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")?, - )) + 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::rococo_runtime_fast_runtime_1m::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 against the JSON-genesis-config-based + +// 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] @@ -2138,57 +1862,86 @@ mod json_vs_legacy_tests { #[test] #[cfg(feature = "rococo-native")] fn rococo_development_config_compare_test() { - let j1 = rococo_development_config().unwrap().as_json(true).unwrap(); - let j2 = legacy::rococo_development_config().unwrap().as_json(true).unwrap(); + let mut j1 = rococo_development_config().unwrap().as_json(true).unwrap(); + let mut j2 = legacy::rococo_development_config().unwrap().as_json(true).unwrap(); + std::fs::write("/tmp/j1.o.json", j1.clone()).unwrap(); + std::fs::write("/tmp/j2.o.json", j2.clone()).unwrap(); + (j1, j2) = adjust_rococo_output(j1, j2); + std::fs::write("/tmp/j1.json", j1.clone()).unwrap(); + std::fs::write("/tmp/j2.json", j2.clone()).unwrap(); assert_eq!(j1, j2); } #[test] #[cfg(feature = "rococo-native")] fn rococo_local_testnet_config_compare_test() { - let j1 = rococo_local_testnet_config().unwrap().as_json(true).unwrap(); - let j2 = legacy::rococo_local_testnet_config().unwrap().as_json(true).unwrap(); + 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 j1 = wococo_development_config().unwrap().as_json(true).unwrap(); - let j2 = legacy::wococo_development_config().unwrap().as_json(true).unwrap(); + 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 j1 = wococo_local_testnet_config().unwrap().as_json(true).unwrap(); - let j2 = legacy::wococo_local_testnet_config().unwrap().as_json(true).unwrap(); + 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 j1 = versi_staging_testnet_config().unwrap().as_json(true).unwrap(); - let j2 = legacy::versi_staging_testnet_config().unwrap().as_json(true).unwrap(); + 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 j1 = versi_development_config().unwrap().as_json(true).unwrap(); - let j2 = legacy::versi_development_config().unwrap().as_json(true).unwrap(); + 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 j1 = versi_local_testnet_config().unwrap().as_json(true).unwrap(); - let j2 = legacy::versi_local_testnet_config().unwrap().as_json(true).unwrap(); + 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); } } From ae9f7328f88442271dbfbddaff3fe9c10632a1fb Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 20 Jul 2023 12:31:47 +0200 Subject: [PATCH 07/15] polkadot_staging_testnet_config_genesis: removed --- node/service/src/chain_spec.rs | 92 ---------------------------------- 1 file changed, 92 deletions(-) diff --git a/node/service/src/chain_spec.rs b/node/service/src/chain_spec.rs index d6d57d56ecf2..b74b272c95ec 100644 --- a/node/service/src/chain_spec.rs +++ b/node/service/src/chain_spec.rs @@ -301,98 +301,6 @@ fn rococo_session_keys( } } -#[cfg(feature = "polkadot-native")] -fn polkadot_staging_testnet_config_genesis() -> polkadot::RuntimeGenesisConfig { - // subkey inspect "$SECRET" - let endowed_accounts = vec![]; - - let initial_authorities: Vec<( - AccountId, - AccountId, - BabeId, - GrandpaId, - ImOnlineId, - ValidatorId, - AssignmentId, - AuthorityDiscoveryId, - )> = vec![]; - - const ENDOWMENT: u128 = 1_000_000 * DOT; - const STASH: u128 = 100 * DOT; - - polkadot::RuntimeGenesisConfig { - system: polkadot::SystemConfig::default(), - balances: polkadot::BalancesConfig { - balances: endowed_accounts - .iter() - .map(|k: &AccountId| (k.clone(), ENDOWMENT)) - .chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH))) - .collect(), - }, - indices: polkadot::IndicesConfig { indices: vec![] }, - 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 { - validator_count: 50, - minimum_validator_count: 4, - 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::ForceNone, - slash_reward_fraction: Perbill::from_percent(10), - ..Default::default() - }, - phragmen_election: Default::default(), - democracy: Default::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(), - } -} - #[cfg(feature = "westend-native")] fn westend_staging_testnet_config_genesis() -> serde_json::Value { use hex_literal::hex; From 39d2de34184a40d646be27b15626699b01d49809 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 20 Jul 2023 12:58:02 +0200 Subject: [PATCH 08/15] polkadot_staging: removed --- .../src/chain_spec/legacy_chain_spec.rs | 116 ------------------ 1 file changed, 116 deletions(-) diff --git a/node/service/src/chain_spec/legacy_chain_spec.rs b/node/service/src/chain_spec/legacy_chain_spec.rs index ba3da2a05f12..5d863de33945 100644 --- a/node/service/src/chain_spec/legacy_chain_spec.rs +++ b/node/service/src/chain_spec/legacy_chain_spec.rs @@ -331,98 +331,6 @@ fn rococo_session_keys( } } -#[cfg(feature = "polkadot-native")] -fn polkadot_staging_testnet_config_genesis() -> polkadot::RuntimeGenesisConfig { - // subkey inspect "$SECRET" - let endowed_accounts = vec![]; - - let initial_authorities: Vec<( - AccountId, - AccountId, - BabeId, - GrandpaId, - ImOnlineId, - ValidatorId, - AssignmentId, - AuthorityDiscoveryId, - )> = vec![]; - - const ENDOWMENT: u128 = 1_000_000 * DOT; - const STASH: u128 = 100 * DOT; - - polkadot::RuntimeGenesisConfig { - system: polkadot::SystemConfig::default(), - balances: polkadot::BalancesConfig { - balances: endowed_accounts - .iter() - .map(|k: &AccountId| (k.clone(), ENDOWMENT)) - .chain(initial_authorities.iter().map(|x| (x.0.clone(), STASH))) - .collect(), - }, - indices: polkadot::IndicesConfig { indices: vec![] }, - 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 { - validator_count: 50, - minimum_validator_count: 4, - 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::ForceNone, - slash_reward_fraction: Perbill::from_percent(10), - ..Default::default() - }, - phragmen_election: Default::default(), - democracy: Default::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(), - } -} - #[cfg(feature = "westend-native")] fn westend_staging_testnet_config_genesis() -> westend::RuntimeGenesisConfig { use hex_literal::hex; @@ -1128,30 +1036,6 @@ pub fn polkadot_chain_spec_properties() -> serde_json::map::Map Result { - let boot_nodes = vec![]; - - #[allow(deprecated)] - Ok(PolkadotChainSpec::from_genesis( - "Polkadot Staging Testnet", - "polkadot_staging_testnet", - ChainType::Live, - move || polkadot_staging_testnet_config_genesis(), - boot_nodes, - Some( - TelemetryEndpoints::new(vec![(POLKADOT_STAGING_TELEMETRY_URL.to_string(), 0)]) - .expect("Polkadot Staging telemetry url is valid; qed"), - ), - Some(DEFAULT_PROTOCOL_ID), - None, - Some(polkadot_chain_spec_properties()), - Default::default(), - polkadot::WASM_BINARY.ok_or("Polkadot development wasm not available")?, - )) -} - /// Staging testnet config. #[cfg(feature = "kusama-native")] pub fn kusama_staging_testnet_config() -> Result { From 352bbb0ae64068c9339e38363b06cb392e2292eb Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 20 Jul 2023 19:51:44 +0200 Subject: [PATCH 09/15] polkadot-test-service: RuntimeGenesisConfig removed, JSON patch added --- node/test/service/Cargo.toml | 2 +- node/test/service/src/chain_spec.rs | 107 ++++++++++++---------------- runtime/test-runtime/Cargo.toml | 1 + runtime/test-runtime/src/lib.rs | 14 +++- 4 files changed, 61 insertions(+), 63 deletions(-) diff --git a/node/test/service/Cargo.toml b/node/test/service/Cargo.toml index 504ee5beca74..3840969a104a 100644 --- a/node/test/service/Cargo.toml +++ b/node/test/service/Cargo.toml @@ -53,10 +53,10 @@ sp-keyring = { git = "https://github.com/paritytech/substrate", branch = "master sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "master" } substrate-test-client = { git = "https://github.com/paritytech/substrate", branch = "master" } +serde_json = "1.0.96" [dev-dependencies] pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -serde_json = "1.0.96" substrate-test-utils = { git = "https://github.com/paritytech/substrate", branch = "master" } tokio = { version = "1.24.2", features = ["macros"] } diff --git a/node/test/service/src/chain_spec.rs b/node/test/service/src/chain_spec.rs index c5a665ff8af3..7ecca15eded0 100644 --- a/node/test/service/src/chain_spec.rs +++ b/node/test/service/src/chain_spec.rs @@ -38,24 +38,22 @@ pub type PolkadotChainSpec = /// Local testnet config (multivalidator Alice + Bob) pub fn polkadot_local_testnet_config() -> PolkadotChainSpec { - #[allow(deprecated)] - 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(), - polkadot_test_runtime::WASM_BINARY.expect("Wasm binary must be built for testing"), - ) + 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"), @@ -108,7 +106,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); @@ -116,14 +114,12 @@ fn polkadot_testnet_genesis( const ENDOWMENT: u128 = 1_000_000 * DOTS; const STASH: u128 = 100 * DOTS; - runtime::RuntimeGenesisConfig { - system: runtime::SystemConfig { ..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| { ( @@ -140,48 +136,37 @@ 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, - chain_availability_period: 4, - thread_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, + "chainAvailabilityPeriod": 4, + "threadAvailabilityPeriod": 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/runtime/test-runtime/Cargo.toml b/runtime/test-runtime/Cargo.toml index 1de4d34fd0c0..16f383428fcb 100644 --- a/runtime/test-runtime/Cargo.toml +++ b/runtime/test-runtime/Cargo.toml @@ -26,6 +26,7 @@ sp-io = { git = "https://github.com/paritytech/substrate", branch = "master", de sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-staking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +sp-genesis-builder = { package = "sp-genesis-builder", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-mmr-primitives = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-session = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sp-version = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } diff --git a/runtime/test-runtime/src/lib.rs b/runtime/test-runtime/src/lib.rs index 035adcc007c2..1fc293b36dd2 100644 --- a/runtime/test-runtime/src/lib.rs +++ b/runtime/test-runtime/src/lib.rs @@ -38,7 +38,9 @@ use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; use beefy_primitives::crypto::{AuthorityId as BeefyId, Signature as BeefySignature}; 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}; @@ -1125,4 +1127,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) + } + } } From b4f54b743b66a0029ca16720d095b405db2faed5 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 21 Jul 2023 11:29:38 +0200 Subject: [PATCH 10/15] runtimes: disable-genesis-builder feature added --- runtime/kusama/Cargo.toml | 5 +++++ runtime/kusama/build.rs | 12 +++++++++++- runtime/kusama/src/lib.rs | 8 +++++--- runtime/polkadot/Cargo.toml | 5 +++++ runtime/polkadot/build.rs | 12 +++++++++++- runtime/polkadot/src/lib.rs | 7 ++++--- 6 files changed, 41 insertions(+), 8 deletions(-) diff --git a/runtime/kusama/Cargo.toml b/runtime/kusama/Cargo.toml index c4252b6f0614..da0242817536 100644 --- a/runtime/kusama/Cargo.toml +++ b/runtime/kusama/Cargo.toml @@ -316,9 +316,14 @@ disable-runtime-api = [] # to make it smaller like logging for example. 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 = [] +# When enabled, the GenesisBuilder API will not be supprted, GenesisConfig shall be +# stripped from the final binary +disable-genesis-builder = [] + runtime-metrics = ["runtime-parachains/runtime-metrics", "sp-io/with-tracing"] diff --git a/runtime/kusama/build.rs b/runtime/kusama/build.rs index 404ba3f2fdbd..55630c348358 100644 --- a/runtime/kusama/build.rs +++ b/runtime/kusama/build.rs @@ -21,5 +21,15 @@ fn main() { .with_current_project() .import_memory() .export_heap_base() - .build() + .build(); + + if std::env::var("BUILD_NO_GENESIS_BUILDER_SUPPORT").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(); + }; } diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index 3c5ecd67fd2f..0b69438f0c6b 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -55,10 +55,11 @@ use beefy_primitives::crypto::{AuthorityId as BeefyId, Signature as BeefySignatu use frame_election_provider_support::{ 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, - genesis_builder_helper::{build_config, create_default_config}, - parameter_types, + construct_runtime, parameter_types, traits::{ ConstU32, Contains, EitherOf, EitherOfDiverse, InstanceFilter, KeyOwnerProofSystem, PrivilegeCmp, ProcessMessage, ProcessMessageError, StorageMapShim, WithdrawReasons, @@ -2219,6 +2220,7 @@ sp_api::impl_runtime_apis! { } } + #[cfg(not(feature = "disable-genesis-builder"))] impl sp_genesis_builder::GenesisBuilder for Runtime { fn create_default_config() -> Vec { create_default_config::() diff --git a/runtime/polkadot/Cargo.toml b/runtime/polkadot/Cargo.toml index edb15c29c7c7..973184fe5ebf 100644 --- a/runtime/polkadot/Cargo.toml +++ b/runtime/polkadot/Cargo.toml @@ -299,9 +299,14 @@ disable-runtime-api = [] # to make it smaller like logging for example. 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 = [] +# When enabled, the GenesisBuilder API will not be supprted, GenesisConfig shall be +# stripped from the final binary +disable-genesis-builder = [] + runtime-metrics = ["runtime-parachains/runtime-metrics", "sp-io/with-tracing"] diff --git a/runtime/polkadot/build.rs b/runtime/polkadot/build.rs index 428c971bc132..96808174c726 100644 --- a/runtime/polkadot/build.rs +++ b/runtime/polkadot/build.rs @@ -21,5 +21,15 @@ fn main() { .with_current_project() .import_memory() .export_heap_base() - .build() + .build(); + + if std::env::var("BUILD_NO_GENESIS_BUILDER_SUPPORT").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(); + }; } diff --git a/runtime/polkadot/src/lib.rs b/runtime/polkadot/src/lib.rs index 945761c2fecd..e987bd5255f2 100644 --- a/runtime/polkadot/src/lib.rs +++ b/runtime/polkadot/src/lib.rs @@ -41,10 +41,10 @@ use runtime_parachains::{ use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId; use beefy_primitives::crypto::{AuthorityId as BeefyId, Signature as BeefySignature}; use frame_election_provider_support::{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}, - parameter_types, + construct_runtime, parameter_types, traits::{ ConstU32, EitherOf, EitherOfDiverse, InstanceFilter, KeyOwnerProofSystem, LockIdentifier, PrivilegeCmp, ProcessMessage, ProcessMessageError, WithdrawReasons, @@ -2193,6 +2193,7 @@ sp_api::impl_runtime_apis! { } } + #[cfg(not(feature = "disable-genesis-builder"))] impl sp_genesis_builder::GenesisBuilder for Runtime { fn create_default_config() -> Vec { create_default_config::() From 0229867306399fca05600f7b4d38e39f6afe2f94 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 24 Jul 2023 13:12:55 +0200 Subject: [PATCH 11/15] rococo-runtime: pre-built variants removed Explicitly building 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 ``` --- node/service/src/chain_spec.rs | 44 +++++++---------------------- runtime/common/src/lib.rs | 9 ------ runtime/rococo/Cargo.toml | 1 - runtime/rococo/build.rs | 39 +++++++++---------------- runtime/rococo/constants/Cargo.toml | 1 - runtime/rococo/constants/src/lib.rs | 5 ++-- runtime/rococo/src/lib.rs | 10 ------- 7 files changed, 26 insertions(+), 83 deletions(-) diff --git a/node/service/src/chain_spec.rs b/node/service/src/chain_spec.rs index ff30f47c4321..f4d6ad362410 100644 --- a/node/service/src/chain_spec.rs +++ b/node/service/src/chain_spec.rs @@ -1021,10 +1021,7 @@ pub fn versi_staging_testnet_config() -> Result { .with_protocol_id("versi") .with_properties(versi_chain_spec_properties()) .with_extensions(Default::default()) - .with_code( - rococo::rococo_runtime_fast_runtime_10m::WASM_BINARY - .ok_or("Versi development wasm not available")?, - ) + .with_code(rococo::WASM_BINARY.ok_or("Versi development wasm not available")?) .build()) } @@ -1455,10 +1452,7 @@ pub fn rococo_development_config() -> Result { .with_genesis_config_patch(rococo_development_config_genesis()) .with_protocol_id(DEFAULT_PROTOCOL_ID) .with_extensions(Default::default()) - .with_code( - rococo::rococo_runtime_fast_runtime_1m::WASM_BINARY - .ok_or("Rococo development wasm not available")?, - ) + .with_code(rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?) .build()) } @@ -1472,10 +1466,7 @@ pub fn versi_development_config() -> Result { .with_genesis_config_patch(rococo_development_config_genesis()) .with_protocol_id("versi") .with_extensions(Default::default()) - .with_code( - rococo::rococo_runtime_fast_runtime_1m::WASM_BINARY - .ok_or("Versi development wasm not available")?, - ) + .with_code(rococo::WASM_BINARY.ok_or("Versi development wasm not available")?) .build()) } @@ -1490,10 +1481,7 @@ pub fn wococo_development_config() -> Result { .with_genesis_config_patch(rococo_development_config_genesis()) .with_protocol_id(WOCOCO_DEV_PROTOCOL_ID) .with_extensions(Default::default()) - .with_code( - rococo::rococo_runtime_fast_runtime_1m::WASM_BINARY - .ok_or("Wococo development wasm not available")?, - ) + .with_code(rococo::WASM_BINARY.ok_or("Wococo development wasm not available")?) .build()) } @@ -1595,10 +1583,7 @@ pub fn rococo_local_testnet_config() -> Result { .with_genesis_config_patch(rococo_local_testnet_genesis()) .with_protocol_id(DEFAULT_PROTOCOL_ID) .with_extensions(Default::default()) - .with_code( - rococo::rococo_runtime_fast_runtime_1m::WASM_BINARY - .ok_or("Rococo development wasm not available")?, - ) + .with_code(rococo::WASM_BINARY.ok_or("Rococo development wasm not available")?) .build()) } @@ -1627,10 +1612,7 @@ pub fn wococo_local_testnet_config() -> Result { .with_genesis_config_patch(wococo_local_testnet_genesis()) .with_protocol_id(DEFAULT_PROTOCOL_ID) .with_extensions(Default::default()) - .with_code( - rococo::rococo_runtime_fast_runtime_1m::WASM_BINARY - .ok_or("Wococo development wasm not available")?, - ) + .with_code(rococo::WASM_BINARY.ok_or("Wococo development wasm not available")?) .build()) } @@ -1659,10 +1641,7 @@ pub fn versi_local_testnet_config() -> Result { .with_genesis_config_patch(versi_local_testnet_genesis()) .with_protocol_id("versi") .with_extensions(Default::default()) - .with_code( - rococo::rococo_runtime_fast_runtime_1m::WASM_BINARY - .ok_or("Versi development wasm not available")?, - ) + .with_code(rococo::WASM_BINARY.ok_or("Versi development wasm not available")?) .build()) } @@ -1760,8 +1739,9 @@ mod json_vs_legacy_tests { #[test] #[cfg(feature = "rococo-native")] fn rococo_staging_testnet_config_compare_test() { - let j1 = rococo_staging_testnet_config().unwrap().as_json(true).unwrap(); - let j2 = legacy::rococo_staging_testnet_config().unwrap().as_json(true).unwrap(); + 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); } @@ -1770,11 +1750,7 @@ mod json_vs_legacy_tests { 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(); - std::fs::write("/tmp/j1.o.json", j1.clone()).unwrap(); - std::fs::write("/tmp/j2.o.json", j2.clone()).unwrap(); (j1, j2) = adjust_rococo_output(j1, j2); - std::fs::write("/tmp/j1.json", j1.clone()).unwrap(); - std::fs::write("/tmp/j2.json", j2.clone()).unwrap(); assert_eq!(j1, j2); } diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 4eb266a902fe..5a73a76d0472 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -269,15 +269,6 @@ macro_rules! prod_or_fast { $prod } }; - ($prod:expr, $feature1:expr, $value1:expr, $feature2:expr, $value2:expr) => { - if cfg!(feature = $feature1) { - $value1 - } else if cfg!(feature = $feature2) { - $value2 - } else { - $prod - } - }; ($prod:expr, $test:expr, $env:expr) => { if cfg!(feature = "fast-runtime") { core::option_env!($env).map(|s| s.parse().ok()).flatten().unwrap_or($test) diff --git a/runtime/rococo/Cargo.toml b/runtime/rococo/Cargo.toml index d227d011042a..162e154bad40 100644 --- a/runtime/rococo/Cargo.toml +++ b/runtime/rococo/Cargo.toml @@ -275,6 +275,5 @@ disable-runtime-api = [] # Set timing constants (e.g. session period) to faster versions to speed up testing. fast-runtime = [ "rococo-runtime-constants/fast-runtime" ] -fast-runtime-10m = [ "rococo-runtime-constants/fast-runtime-10m" ] runtime-metrics = ["runtime-parachains/runtime-metrics", "sp-io/with-tracing"] diff --git a/runtime/rococo/build.rs b/runtime/rococo/build.rs index 8937d92ea758..f960a21b4200 100644 --- a/runtime/rococo/build.rs +++ b/runtime/rococo/build.rs @@ -14,37 +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() { #[cfg(feature = "std")] { - WasmBuilder::new() - .with_current_project() - .import_memory() - .export_heap_base() - .build(); - } + let mut builder = + WasmBuilder::new().with_current_project().import_memory().export_heap_base(); - #[cfg(feature = "std")] - { - WasmBuilder::new() - .with_current_project() - .set_file_name("rococo_runtime_fast_runtime_1m.rs") - .import_memory() - .export_heap_base() - .enable_feature("fast-runtime") - .build(); - } + if env::var(ROCOCO_EPOCH_DURATION_ENV).is_ok() | env::var(ROCOCO_FAST_RUNTIME_ENV).is_ok() { + builder = builder.enable_feature("fast-runtime") + }; - #[cfg(feature = "std")] - { - WasmBuilder::new() - .with_current_project() - .set_file_name("rococo_runtime_fast_runtime_10m.rs") - .import_memory() - .export_heap_base() - .enable_feature("fast-runtime-10m") - .build() + 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/runtime/rococo/constants/Cargo.toml b/runtime/rococo/constants/Cargo.toml index c8a7e2ea943d..c6043eece79d 100644 --- a/runtime/rococo/constants/Cargo.toml +++ b/runtime/rococo/constants/Cargo.toml @@ -27,4 +27,3 @@ std = [ # Set timing constants (e.g. session period) to faster versions to speed up testing. fast-runtime = [] -fast-runtime-10m = [] diff --git a/runtime/rococo/constants/src/lib.rs b/runtime/rococo/constants/src/lib.rs index e3f8da4936d2..3b2ff696f185 100644 --- a/runtime/rococo/constants/src/lib.rs +++ b/runtime/rococo/constants/src/lib.rs @@ -41,10 +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, "fast-runtime", 1 * MINUTES, "fast-runtime-10m", 10 * 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/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index a0e43ea234d0..60f2d5d1be98 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -108,16 +108,6 @@ impl_runtime_weights!(rococo_runtime_constants); #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -#[cfg(feature = "std")] -pub mod rococo_runtime_fast_runtime_10m { - include!(concat!(env!("OUT_DIR"), "/rococo_runtime_fast_runtime_10m.rs")); -} - -#[cfg(feature = "std")] -pub mod rococo_runtime_fast_runtime_1m { - include!(concat!(env!("OUT_DIR"), "/rococo_runtime_fast_runtime_1m.rs")); -} - /// Runtime version (Rococo). #[sp_version::runtime_version] pub const VERSION: RuntimeVersion = RuntimeVersion { From 3d7412e9f9e2dbb28ac61c828e2b21f0eeb925ca Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 25 Jul 2023 11:32:53 +0200 Subject: [PATCH 12/15] warnings fixed --- .../src/chain_spec/legacy_chain_spec.rs | 35 ------------------- 1 file changed, 35 deletions(-) diff --git a/node/service/src/chain_spec/legacy_chain_spec.rs b/node/service/src/chain_spec/legacy_chain_spec.rs index 5d863de33945..d421e698991c 100644 --- a/node/service/src/chain_spec/legacy_chain_spec.rs +++ b/node/service/src/chain_spec/legacy_chain_spec.rs @@ -71,8 +71,6 @@ use westend_runtime as westend; #[cfg(feature = "westend-native")] use westend_runtime_constants::currency::UNITS as WND; -#[cfg(feature = "polkadot-native")] -const POLKADOT_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; #[cfg(feature = "kusama-native")] const KUSAMA_STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; #[cfg(feature = "westend-native")] @@ -110,13 +108,6 @@ pub struct Extensions { #[cfg(feature = "polkadot-native")] pub type PolkadotChainSpec = service::GenericChainSpec; -// Dummy chain spec, in case when we don't have the native runtime. -pub type DummyChainSpec = service::GenericChainSpec<(), Extensions>; - -// Dummy chain spec, but that is fine when we don't have the native runtime. -#[cfg(not(feature = "polkadot-native"))] -pub type PolkadotChainSpec = DummyChainSpec; - /// The `ChainSpec` parameterized for the kusama runtime. #[cfg(feature = "kusama-native")] pub type KusamaChainSpec = service::GenericChainSpec; @@ -139,11 +130,6 @@ pub type WestendChainSpec = DummyChainSpec; #[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"))] @@ -173,27 +159,6 @@ impl sp_runtime::BuildStorage for RococoGenesisExt { } } -pub fn polkadot_config() -> Result { - PolkadotChainSpec::from_json_bytes(&include_bytes!("../../chain-specs/polkadot.json")[..]) -} - -pub fn kusama_config() -> Result { - KusamaChainSpec::from_json_bytes(&include_bytes!("../../chain-specs/kusama.json")[..]) -} - -pub fn westend_config() -> Result { - WestendChainSpec::from_json_bytes(&include_bytes!("../../chain-specs/westend.json")[..]) -} - -pub fn rococo_config() -> Result { - RococoChainSpec::from_json_bytes(&include_bytes!("../../chain-specs/rococo.json")[..]) -} - -/// This is a temporary testnet that uses the same runtime as rococo. -pub fn wococo_config() -> Result { - RococoChainSpec::from_json_bytes(&include_bytes!("../../chain-specs/wococo.json")[..]) -} - /// The default parachains host configuration. #[cfg(any( feature = "rococo-native", From 478b332ed52d62b3926e0a035888830720acc4a5 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 3 Aug 2023 07:08:41 +0200 Subject: [PATCH 13/15] beefy::crypto -> ecdsa_crypto --- node/service/src/chain_spec/legacy_chain_spec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/service/src/chain_spec/legacy_chain_spec.rs b/node/service/src/chain_spec/legacy_chain_spec.rs index d421e698991c..41b8a917bf8d 100644 --- a/node/service/src/chain_spec/legacy_chain_spec.rs +++ b/node/service/src/chain_spec/legacy_chain_spec.rs @@ -17,7 +17,7 @@ //! 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::crypto::AuthorityId as BeefyId; +use beefy_primitives::ecdsa_crypto::AuthorityId as BeefyId; use grandpa::AuthorityId as GrandpaId; #[cfg(feature = "kusama-native")] use kusama_runtime as kusama; From 9078fab295729d56847900c40c07a3f925cf5e8d Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 3 Aug 2023 07:10:16 +0200 Subject: [PATCH 14/15] node/test: polkadot_test_runtime::RuntimeGenesisConfig removed in ChainSpec --- node/test/service/src/chain_spec.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/node/test/service/src/chain_spec.rs b/node/test/service/src/chain_spec.rs index 7ecca15eded0..a9515a7fd3ec 100644 --- a/node/test/service/src/chain_spec.rs +++ b/node/test/service/src/chain_spec.rs @@ -33,8 +33,7 @@ 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 { From 18ee1abdca95b5e884bf8454538999bde9c62fa0 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 3 Aug 2023 07:11:23 +0200 Subject: [PATCH 15/15] runtimes: build.rs env cleanup --- runtime/kusama/build.rs | 5 ++++- runtime/polkadot/build.rs | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/runtime/kusama/build.rs b/runtime/kusama/build.rs index 55630c348358..c076fa43523f 100644 --- a/runtime/kusama/build.rs +++ b/runtime/kusama/build.rs @@ -16,6 +16,8 @@ use substrate_wasm_builder::WasmBuilder; +const NO_GENESIS_BUILDER_ENV: &str = "BUILD_NO_GENESIS_BUILDER_SUPPORT"; + fn main() { WasmBuilder::new() .with_current_project() @@ -23,7 +25,7 @@ fn main() { .export_heap_base() .build(); - if std::env::var("BUILD_NO_GENESIS_BUILDER_SUPPORT").is_ok() { + if std::env::var(NO_GENESIS_BUILDER_ENV).is_ok() { WasmBuilder::new() .with_current_project() .import_memory() @@ -32,4 +34,5 @@ fn main() { .set_file_name("kusama_runtime_no_genesis_builder") .build(); }; + println!("cargo:rerun-if-env-changed={}", NO_GENESIS_BUILDER_ENV); } diff --git a/runtime/polkadot/build.rs b/runtime/polkadot/build.rs index 96808174c726..5460ef4bf6ce 100644 --- a/runtime/polkadot/build.rs +++ b/runtime/polkadot/build.rs @@ -16,6 +16,8 @@ use substrate_wasm_builder::WasmBuilder; +const NO_GENESIS_BUILDER_ENV: &str = "BUILD_NO_GENESIS_BUILDER_SUPPORT"; + fn main() { WasmBuilder::new() .with_current_project() @@ -23,7 +25,7 @@ fn main() { .export_heap_base() .build(); - if std::env::var("BUILD_NO_GENESIS_BUILDER_SUPPORT").is_ok() { + if std::env::var(NO_GENESIS_BUILDER_ENV).is_ok() { WasmBuilder::new() .with_current_project() .import_memory() @@ -32,4 +34,5 @@ fn main() { .set_file_name("polkadot_runtime_no_genesis_builder") .build(); }; + println!("cargo:rerun-if-env-changed={}", NO_GENESIS_BUILDER_ENV); }