From 9c42f0e871b15e8c1a196aaa1a90d0d409ee5874 Mon Sep 17 00:00:00 2001 From: Iulian Barbu Date: Mon, 23 Sep 2024 19:57:13 +0300 Subject: [PATCH 01/15] Added dev genesis config preset for minimal Signed-off-by: Iulian Barbu --- Cargo.lock | 1 + templates/minimal/runtime/Cargo.toml | 1 + .../runtime/src/genesis_config_presets.rs | 75 +++++++++++++++++++ templates/minimal/runtime/src/lib.rs | 18 ++++- 4 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 templates/minimal/runtime/src/genesis_config_presets.rs diff --git a/Cargo.lock b/Cargo.lock index c10d1e93907ed..1e6cb106a9e6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9613,6 +9613,7 @@ dependencies = [ "parity-scale-codec", "polkadot-sdk", "scale-info", + "serde_json", ] [[package]] diff --git a/templates/minimal/runtime/Cargo.toml b/templates/minimal/runtime/Cargo.toml index 49ddf3987e96f..250efc73d6b98 100644 --- a/templates/minimal/runtime/Cargo.toml +++ b/templates/minimal/runtime/Cargo.toml @@ -21,6 +21,7 @@ polkadot-sdk = { workspace = true, features = [ "pallet-transaction-payment-rpc-runtime-api", "runtime", ] } +serde_json = { workspace = true, default-features = false } # local pallet templates pallet-minimal-template = { workspace = true } diff --git a/templates/minimal/runtime/src/genesis_config_presets.rs b/templates/minimal/runtime/src/genesis_config_presets.rs new file mode 100644 index 0000000000000..a288a5d3a3430 --- /dev/null +++ b/templates/minimal/runtime/src/genesis_config_presets.rs @@ -0,0 +1,75 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use polkadot_sdk::sp_genesis_builder::{self, PresetId}; +use serde_json::Value; + +use crate::{AccountId, Balances, BalancesConfig, RuntimeGenesisConfig, Sudo, SudoConfig}; + +fn testnet_genesis(endowed_accounts: Vec, root: AccountId) -> Value { + let config = RuntimeGenesisConfig { + //balances: Balances(vec![]), + balances: BalancesConfig { + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, 1u128 << 60)) + .collect::>(), + }, + sudo: SudoConfig { key: Some(root) }, + ..Default::default() + }; + + serde_json::to_value(config).expect("Could not build genesis config.") +} + +fn development_config_genesis() -> Value { + testnet_genesis( + vec![ + polkadot_sdk::sp_keyring::AccountKeyring::Alice.to_account_id(), + polkadot_sdk::sp_keyring::AccountKeyring::Bob.to_account_id(), + polkadot_sdk::sp_keyring::AccountKeyring::Bob.to_account_id(), + polkadot_sdk::sp_keyring::AccountKeyring::Dave.to_account_id(), + polkadot_sdk::sp_keyring::AccountKeyring::Ferdie.to_account_id(), + polkadot_sdk::sp_keyring::AccountKeyring::AliceStash.to_account_id(), + polkadot_sdk::sp_keyring::AccountKeyring::BobStash.to_account_id(), + polkadot_sdk::sp_keyring::AccountKeyring::CharlieStash.to_account_id(), + polkadot_sdk::sp_keyring::AccountKeyring::DaveStash.to_account_id(), + polkadot_sdk::sp_keyring::AccountKeyring::EveStash.to_account_id(), + polkadot_sdk::sp_keyring::AccountKeyring::FerdieStash.to_account_id(), + ], + polkadot_sdk::sp_keyring::AccountKeyring::Alice.to_account_id(), + ) +} + +/// Provides the JSON representation of predefined genesis config for given `id`. +pub fn get_preset(id: &PresetId) -> Option> { + let patch = match id.try_into() { + Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => development_config_genesis(), + _ => return None, + }; + Some( + serde_json::to_string(&patch) + .expect("serialization to json is expected to work. qed.") + .into_bytes(), + ) +} + +/// List of supported presets. +pub fn preset_names() -> Vec { + vec![PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET)] +} diff --git a/templates/minimal/runtime/src/lib.rs b/templates/minimal/runtime/src/lib.rs index cce13c48af71a..a4e261791171e 100644 --- a/templates/minimal/runtime/src/lib.rs +++ b/templates/minimal/runtime/src/lib.rs @@ -35,6 +35,20 @@ use polkadot_sdk::{ }, *, }; +use sp_runtime::{ + traits::{IdentifyAccount, Verify}, + MultiSignature, +}; + +// Provides helpers for genesis configuration presets setup. +mod genesis_config_presets; + +/// Alias to 512-bit hash when used in the context of a transaction signature on the chain. +pub type Signature = MultiSignature; + +/// Some way of identifying an account on the chain. We intentionally make it equivalent +/// to the public key of our transaction signing scheme. +pub type AccountId = <::Signer as IdentifyAccount>::AccountId; /// The runtime version. #[runtime_version] @@ -272,11 +286,11 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id, |_| None) + get_preset::(id, crate::genesis_config_presets::get_preset) } fn preset_names() -> Vec { - vec![] + crate::genesis_config_presets::preset_names() } } } From 4bb97892f1c831936ff6796893188b4e770e52b4 Mon Sep 17 00:00:00 2001 From: Iulian Barbu Date: Tue, 24 Sep 2024 10:08:01 +0300 Subject: [PATCH 02/15] added solochain dev genesis config preset Signed-off-by: Iulian Barbu --- Cargo.lock | 2 + templates/solochain/runtime/Cargo.toml | 2 + templates/solochain/runtime/src/apis.rs | 4 +- .../runtime/src/genesis_config_presets.rs | 75 +++++++++++++++++++ templates/solochain/runtime/src/lib.rs | 2 + 5 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 templates/solochain/runtime/src/genesis_config_presets.rs diff --git a/Cargo.lock b/Cargo.lock index 1e6cb106a9e6f..ecb658c2d8a50 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21409,6 +21409,7 @@ dependencies = [ "pallet-transaction-payment-rpc-runtime-api", "parity-scale-codec", "scale-info", + "serde_json", "sp-api 26.0.0", "sp-block-builder", "sp-consensus-aura", @@ -21416,6 +21417,7 @@ dependencies = [ "sp-core 28.0.0", "sp-genesis-builder", "sp-inherents", + "sp-keyring", "sp-offchain", "sp-runtime 31.0.1", "sp-session", diff --git a/templates/solochain/runtime/Cargo.toml b/templates/solochain/runtime/Cargo.toml index 9a1f7145c2ca3..4ac240c7fe82c 100644 --- a/templates/solochain/runtime/Cargo.toml +++ b/templates/solochain/runtime/Cargo.toml @@ -20,6 +20,7 @@ scale-info = { features = [ "derive", "serde", ], workspace = true } +serde_json = { workspace = true, default-features = false } # frame frame-support = { features = ["experimental"], workspace = true } @@ -45,6 +46,7 @@ sp-consensus-aura = { features = [ sp-consensus-grandpa = { features = [ "serde", ], workspace = true } +sp-keyring = { workspace = true } sp-core = { features = [ "serde", ], workspace = true } diff --git a/templates/solochain/runtime/src/apis.rs b/templates/solochain/runtime/src/apis.rs index 1e3dc452857c9..165460c27cc07 100644 --- a/templates/solochain/runtime/src/apis.rs +++ b/templates/solochain/runtime/src/apis.rs @@ -285,11 +285,11 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id, |_| None) + get_preset::(id, crate::genesis_config_presets::get_preset) } fn preset_names() -> Vec { - vec![] + crate::genesis_config_presets::preset_names() } } } diff --git a/templates/solochain/runtime/src/genesis_config_presets.rs b/templates/solochain/runtime/src/genesis_config_presets.rs new file mode 100644 index 0000000000000..1c6b1a54e53ee --- /dev/null +++ b/templates/solochain/runtime/src/genesis_config_presets.rs @@ -0,0 +1,75 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use serde_json::Value; +use sp_genesis_builder::{self, PresetId}; + +use crate::{AccountId, Balances, BalancesConfig, RuntimeGenesisConfig, Sudo, SudoConfig}; + +fn testnet_genesis(endowed_accounts: Vec, root: AccountId) -> Value { + let config = RuntimeGenesisConfig { + //balances: Balances(vec![]), + balances: BalancesConfig { + balances: endowed_accounts + .iter() + .cloned() + .map(|k| (k, 1u128 << 60)) + .collect::>(), + }, + sudo: SudoConfig { key: Some(root) }, + ..Default::default() + }; + + serde_json::to_value(config).expect("Could not build genesis config.") +} + +fn development_config_genesis() -> Value { + testnet_genesis( + vec![ + sp_keyring::AccountKeyring::Alice.to_account_id(), + sp_keyring::AccountKeyring::Bob.to_account_id(), + sp_keyring::AccountKeyring::Bob.to_account_id(), + sp_keyring::AccountKeyring::Dave.to_account_id(), + sp_keyring::AccountKeyring::Ferdie.to_account_id(), + sp_keyring::AccountKeyring::AliceStash.to_account_id(), + sp_keyring::AccountKeyring::BobStash.to_account_id(), + sp_keyring::AccountKeyring::CharlieStash.to_account_id(), + sp_keyring::AccountKeyring::DaveStash.to_account_id(), + sp_keyring::AccountKeyring::EveStash.to_account_id(), + sp_keyring::AccountKeyring::FerdieStash.to_account_id(), + ], + sp_keyring::AccountKeyring::Alice.to_account_id(), + ) +} + +/// Provides the JSON representation of predefined genesis config for given `id`. +pub fn get_preset(id: &PresetId) -> Option> { + let patch = match id.try_into() { + Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => development_config_genesis(), + _ => return None, + }; + Some( + serde_json::to_string(&patch) + .expect("serialization to json is expected to work. qed.") + .into_bytes(), + ) +} + +/// List of supported presets. +pub fn preset_names() -> Vec { + vec![PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET)] +} diff --git a/templates/solochain/runtime/src/lib.rs b/templates/solochain/runtime/src/lib.rs index 279518c8f47ca..6e3a98f155bc8 100644 --- a/templates/solochain/runtime/src/lib.rs +++ b/templates/solochain/runtime/src/lib.rs @@ -25,6 +25,8 @@ pub use pallet_timestamp::Call as TimestampCall; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; +mod genesis_config_presets; + /// Opaque types. These are used by the CLI to instantiate machinery that don't need to know /// the specifics of the runtime. They can then be made to be agnostic over specific formats /// of data like extrinsics, allowing for them to continue syncing the network through upgrades From 1117f9b03006aeb8d24e82f28b823b876d50ff58 Mon Sep 17 00:00:00 2001 From: Iulian Barbu Date: Tue, 24 Sep 2024 14:06:19 +0300 Subject: [PATCH 03/15] simplify genesis config preset creation Signed-off-by: Iulian Barbu --- .../runtime/src/genesis_config_presets.rs | 29 +++++-------------- .../runtime/src/genesis_config_presets.rs | 22 ++++---------- 2 files changed, 13 insertions(+), 38 deletions(-) diff --git a/templates/minimal/runtime/src/genesis_config_presets.rs b/templates/minimal/runtime/src/genesis_config_presets.rs index a288a5d3a3430..4ecd3756a9a05 100644 --- a/templates/minimal/runtime/src/genesis_config_presets.rs +++ b/templates/minimal/runtime/src/genesis_config_presets.rs @@ -15,20 +15,15 @@ // See the License for the specific language governing permissions and // limitations under the License. +use crate::{AccountId, BalancesConfig, RuntimeGenesisConfig, SudoConfig, Vec}; use polkadot_sdk::sp_genesis_builder::{self, PresetId}; +use polkadot_sdk::sp_keyring::AccountKeyring; use serde_json::Value; -use crate::{AccountId, Balances, BalancesConfig, RuntimeGenesisConfig, Sudo, SudoConfig}; - fn testnet_genesis(endowed_accounts: Vec, root: AccountId) -> Value { let config = RuntimeGenesisConfig { - //balances: Balances(vec![]), balances: BalancesConfig { - balances: endowed_accounts - .iter() - .cloned() - .map(|k| (k, 1u128 << 60)) - .collect::>(), + balances: endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::>(), }, sudo: SudoConfig { key: Some(root) }, ..Default::default() @@ -39,20 +34,10 @@ fn testnet_genesis(endowed_accounts: Vec, root: AccountId) -> Value { fn development_config_genesis() -> Value { testnet_genesis( - vec![ - polkadot_sdk::sp_keyring::AccountKeyring::Alice.to_account_id(), - polkadot_sdk::sp_keyring::AccountKeyring::Bob.to_account_id(), - polkadot_sdk::sp_keyring::AccountKeyring::Bob.to_account_id(), - polkadot_sdk::sp_keyring::AccountKeyring::Dave.to_account_id(), - polkadot_sdk::sp_keyring::AccountKeyring::Ferdie.to_account_id(), - polkadot_sdk::sp_keyring::AccountKeyring::AliceStash.to_account_id(), - polkadot_sdk::sp_keyring::AccountKeyring::BobStash.to_account_id(), - polkadot_sdk::sp_keyring::AccountKeyring::CharlieStash.to_account_id(), - polkadot_sdk::sp_keyring::AccountKeyring::DaveStash.to_account_id(), - polkadot_sdk::sp_keyring::AccountKeyring::EveStash.to_account_id(), - polkadot_sdk::sp_keyring::AccountKeyring::FerdieStash.to_account_id(), - ], - polkadot_sdk::sp_keyring::AccountKeyring::Alice.to_account_id(), + AccountKeyring::iter() + .filter(|v| v != AccountKeyring::One && v != AccountKeyring::Two) + .collect(), + AccountKeyring::Alice.to_account_id(), ) } diff --git a/templates/solochain/runtime/src/genesis_config_presets.rs b/templates/solochain/runtime/src/genesis_config_presets.rs index 1c6b1a54e53ee..699b11428812e 100644 --- a/templates/solochain/runtime/src/genesis_config_presets.rs +++ b/templates/solochain/runtime/src/genesis_config_presets.rs @@ -15,14 +15,14 @@ // See the License for the specific language governing permissions and // limitations under the License. +use crate::{AccountId, BalancesConfig, RuntimeGenesisConfig, SudoConfig, Vec}; +use alloc::vec; use serde_json::Value; use sp_genesis_builder::{self, PresetId}; - -use crate::{AccountId, Balances, BalancesConfig, RuntimeGenesisConfig, Sudo, SudoConfig}; +use sp_keyring::AccountKeyring; fn testnet_genesis(endowed_accounts: Vec, root: AccountId) -> Value { let config = RuntimeGenesisConfig { - //balances: Balances(vec![]), balances: BalancesConfig { balances: endowed_accounts .iter() @@ -39,19 +39,9 @@ fn testnet_genesis(endowed_accounts: Vec, root: AccountId) -> Value { fn development_config_genesis() -> Value { testnet_genesis( - vec![ - sp_keyring::AccountKeyring::Alice.to_account_id(), - sp_keyring::AccountKeyring::Bob.to_account_id(), - sp_keyring::AccountKeyring::Bob.to_account_id(), - sp_keyring::AccountKeyring::Dave.to_account_id(), - sp_keyring::AccountKeyring::Ferdie.to_account_id(), - sp_keyring::AccountKeyring::AliceStash.to_account_id(), - sp_keyring::AccountKeyring::BobStash.to_account_id(), - sp_keyring::AccountKeyring::CharlieStash.to_account_id(), - sp_keyring::AccountKeyring::DaveStash.to_account_id(), - sp_keyring::AccountKeyring::EveStash.to_account_id(), - sp_keyring::AccountKeyring::FerdieStash.to_account_id(), - ], + sp_keyring::AccountKeyring::iter() + .filter(|v| v != AccountKeyring::One && v != AccountKeyring::Two) + .collect(), sp_keyring::AccountKeyring::Alice.to_account_id(), ) } From 217541972f36feb7e821a7b41082797e6f9ffac9 Mon Sep 17 00:00:00 2001 From: Iulian Barbu Date: Wed, 25 Sep 2024 20:26:46 +0300 Subject: [PATCH 04/15] wip: need to fix stuff I purposely wronged Signed-off-by: Iulian Barbu --- Cargo.toml | 88 +++++++++---------- .../runtime/src/genesis_config_presets.rs | 21 +++-- templates/minimal/runtime/src/lib.rs | 1 - .../runtime/src/genesis_config_presets.rs | 2 +- 4 files changed, 60 insertions(+), 52 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a30b5b57d3618..5c34dfa50b2f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1408,47 +1408,47 @@ overflow-checks = true # # This list is ordered alphabetically. [profile.dev.package] -blake2 = { opt-level = 3 } -blake2b_simd = { opt-level = 3 } -chacha20poly1305 = { opt-level = 3 } -cranelift-codegen = { opt-level = 3 } -cranelift-wasm = { opt-level = 3 } -crc32fast = { opt-level = 3 } -crossbeam-deque = { opt-level = 3 } -crypto-mac = { opt-level = 3 } -curve25519-dalek = { opt-level = 3 } -ed25519-dalek = { opt-level = 3 } -flate2 = { opt-level = 3 } -futures-channel = { opt-level = 3 } -hash-db = { opt-level = 3 } -hashbrown = { opt-level = 3 } -hmac = { opt-level = 3 } -httparse = { opt-level = 3 } -integer-sqrt = { opt-level = 3 } -keccak = { opt-level = 3 } -libm = { opt-level = 3 } -librocksdb-sys = { opt-level = 3 } -libsecp256k1 = { opt-level = 3 } -libz-sys = { opt-level = 3 } -mio = { opt-level = 3 } -nalgebra = { opt-level = 3 } -num-bigint = { opt-level = 3 } -parking_lot = { opt-level = 3 } -parking_lot_core = { opt-level = 3 } -percent-encoding = { opt-level = 3 } -polkavm-linker = { opt-level = 3 } -primitive-types = { opt-level = 3 } -reed-solomon-novelpoly = { opt-level = 3 } -ring = { opt-level = 3 } -rustls = { opt-level = 3 } -sha2 = { opt-level = 3 } -sha3 = { opt-level = 3 } -smallvec = { opt-level = 3 } -snow = { opt-level = 3 } -substrate-bip39 = { opt-level = 3 } -twox-hash = { opt-level = 3 } -uint = { opt-level = 3 } -wasmi = { opt-level = 3 } -x25519-dalek = { opt-level = 3 } -yamux = { opt-level = 3 } -zeroize = { opt-level = 3 } +blake2 = { opt-level = 0 } +blake2b_simd = { opt-level = 0 } +chacha20poly1305 = { opt-level = 0 } +cranelift-codegen = { opt-level = 0 } +cranelift-wasm = { opt-level = 0 } +crc32fast = { opt-level = 0 } +crossbeam-deque = { opt-level = 0 } +crypto-mac = { opt-level = 0 } +curve25519-dalek = { opt-level = 0 } +ed25519-dalek = { opt-level = 0 } +flate2 = { opt-level = 0 } +futures-channel = { opt-level = 0 } +hash-db = { opt-level = 0 } +hashbrown = { opt-level = 0 } +hmac = { opt-level = 0 } +httparse = { opt-level = 0 } +integer-sqrt = { opt-level = 0 } +keccak = { opt-level = 0 } +libm = { opt-level = 0 } +librocksdb-sys = { opt-level = 0 } +libsecp256k1 = { opt-level = 0 } +libz-sys = { opt-level = 0 } +mio = { opt-level = 0 } +nalgebra = { opt-level = 0 } +num-bigint = { opt-level = 0 } +parking_lot = { opt-level = 0 } +parking_lot_core = { opt-level = 0 } +percent-encoding = { opt-level = 0 } +polkavm-linker = { opt-level = 0 } +primitive-types = { opt-level = 0 } +reed-solomon-novelpoly = { opt-level = 0 } +ring = { opt-level = 0 } +rustls = { opt-level = 0 } +sha2 = { opt-level = 0 } +sha3 = { opt-level = 0 } +smallvec = { opt-level = 0 } +snow = { opt-level = 0 } +substrate-bip39 = { opt-level = 0 } +twox-hash = { opt-level = 0 } +uint = { opt-level = 0 } +wasmi = { opt-level = 0 } +x25519-dalek = { opt-level = 0 } +yamux = { opt-level = 0 } +zeroize = { opt-level = 0 } diff --git a/templates/minimal/runtime/src/genesis_config_presets.rs b/templates/minimal/runtime/src/genesis_config_presets.rs index 4ecd3756a9a05..edd8d62d7766d 100644 --- a/templates/minimal/runtime/src/genesis_config_presets.rs +++ b/templates/minimal/runtime/src/genesis_config_presets.rs @@ -16,15 +16,16 @@ // limitations under the License. use crate::{AccountId, BalancesConfig, RuntimeGenesisConfig, SudoConfig, Vec}; -use polkadot_sdk::sp_genesis_builder::{self, PresetId}; -use polkadot_sdk::sp_keyring::AccountKeyring; +use polkadot_sdk::{ + sp_genesis_builder::{self, PresetId}, + sp_keyring::AccountKeyring, +}; use serde_json::Value; fn testnet_genesis(endowed_accounts: Vec, root: AccountId) -> Value { + let balances = endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::>(); let config = RuntimeGenesisConfig { - balances: BalancesConfig { - balances: endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::>(), - }, + balances: BalancesConfig { balances }, sudo: SudoConfig { key: Some(root) }, ..Default::default() }; @@ -35,7 +36,13 @@ fn testnet_genesis(endowed_accounts: Vec, root: AccountId) -> Value { fn development_config_genesis() -> Value { testnet_genesis( AccountKeyring::iter() - .filter(|v| v != AccountKeyring::One && v != AccountKeyring::Two) + .filter_map(|v| { + if v != AccountKeyring::One && v != AccountKeyring::Two { + Some(v.to_account_id()) + } else { + None + } + }) .collect(), AccountKeyring::Alice.to_account_id(), ) @@ -47,6 +54,8 @@ pub fn get_preset(id: &PresetId) -> Option> { Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => development_config_genesis(), _ => return None, }; + + let x = Some( serde_json::to_string(&patch) .expect("serialization to json is expected to work. qed.") diff --git a/templates/minimal/runtime/src/lib.rs b/templates/minimal/runtime/src/lib.rs index a4e261791171e..5f0b013e652d8 100644 --- a/templates/minimal/runtime/src/lib.rs +++ b/templates/minimal/runtime/src/lib.rs @@ -25,7 +25,6 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); extern crate alloc; -use alloc::{vec, vec::Vec}; use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo}; use polkadot_sdk::{ polkadot_sdk_frame::{ diff --git a/templates/solochain/runtime/src/genesis_config_presets.rs b/templates/solochain/runtime/src/genesis_config_presets.rs index 699b11428812e..9d1b7efdbc36e 100644 --- a/templates/solochain/runtime/src/genesis_config_presets.rs +++ b/templates/solochain/runtime/src/genesis_config_presets.rs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::{AccountId, BalancesConfig, RuntimeGenesisConfig, SudoConfig, Vec}; +use crate::{AccountId, BalancesConfig, RuntimeGenesisConfig, SudoConfig}; use alloc::vec; use serde_json::Value; use sp_genesis_builder::{self, PresetId}; From 2bcb6cef2ab5716296670c378a40fd025735220f Mon Sep 17 00:00:00 2001 From: Iulian Barbu Date: Sat, 28 Sep 2024 16:16:29 +0300 Subject: [PATCH 05/15] fixed genesis config presets for minimal and solochain Signed-off-by: Iulian Barbu --- .../minimal/runtime/src/genesis_config_presets.rs | 14 ++++---------- templates/minimal/runtime/src/lib.rs | 1 + templates/solochain/runtime/src/apis.rs | 2 +- .../runtime/src/genesis_config_presets.rs | 6 ++++-- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/templates/minimal/runtime/src/genesis_config_presets.rs b/templates/minimal/runtime/src/genesis_config_presets.rs index edd8d62d7766d..b355b6631d3fb 100644 --- a/templates/minimal/runtime/src/genesis_config_presets.rs +++ b/templates/minimal/runtime/src/genesis_config_presets.rs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::{AccountId, BalancesConfig, RuntimeGenesisConfig, SudoConfig, Vec}; +use crate::{vec, AccountId, BalancesConfig, RuntimeGenesisConfig, SudoConfig, Vec}; use polkadot_sdk::{ sp_genesis_builder::{self, PresetId}, sp_keyring::AccountKeyring, @@ -36,13 +36,9 @@ fn testnet_genesis(endowed_accounts: Vec, root: AccountId) -> Value { fn development_config_genesis() -> Value { testnet_genesis( AccountKeyring::iter() - .filter_map(|v| { - if v != AccountKeyring::One && v != AccountKeyring::Two { - Some(v.to_account_id()) - } else { - None - } - }) + .filter(|v| v != &AccountKeyring::One) + .filter(|v| v != &AccountKeyring::Two) + .map(|v| v.to_account_id()) .collect(), AccountKeyring::Alice.to_account_id(), ) @@ -54,8 +50,6 @@ pub fn get_preset(id: &PresetId) -> Option> { Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => development_config_genesis(), _ => return None, }; - - let x = Some( serde_json::to_string(&patch) .expect("serialization to json is expected to work. qed.") diff --git a/templates/minimal/runtime/src/lib.rs b/templates/minimal/runtime/src/lib.rs index 5f0b013e652d8..a4e261791171e 100644 --- a/templates/minimal/runtime/src/lib.rs +++ b/templates/minimal/runtime/src/lib.rs @@ -25,6 +25,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); extern crate alloc; +use alloc::{vec, vec::Vec}; use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo}; use polkadot_sdk::{ polkadot_sdk_frame::{ diff --git a/templates/solochain/runtime/src/apis.rs b/templates/solochain/runtime/src/apis.rs index 165460c27cc07..87a09a5f7feef 100644 --- a/templates/solochain/runtime/src/apis.rs +++ b/templates/solochain/runtime/src/apis.rs @@ -24,7 +24,7 @@ // For more information, please refer to // External crates imports -use alloc::{vec, vec::Vec}; +use alloc::vec::Vec; use frame_support::{ genesis_builder_helper::{build_state, get_preset}, weights::Weight, diff --git a/templates/solochain/runtime/src/genesis_config_presets.rs b/templates/solochain/runtime/src/genesis_config_presets.rs index 9d1b7efdbc36e..de456e50e8eb7 100644 --- a/templates/solochain/runtime/src/genesis_config_presets.rs +++ b/templates/solochain/runtime/src/genesis_config_presets.rs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::{AccountId, BalancesConfig, RuntimeGenesisConfig, SudoConfig}; +use crate::{AccountId, BalancesConfig, RuntimeGenesisConfig, SudoConfig, Vec}; use alloc::vec; use serde_json::Value; use sp_genesis_builder::{self, PresetId}; @@ -40,7 +40,9 @@ fn testnet_genesis(endowed_accounts: Vec, root: AccountId) -> Value { fn development_config_genesis() -> Value { testnet_genesis( sp_keyring::AccountKeyring::iter() - .filter(|v| v != AccountKeyring::One && v != AccountKeyring::Two) + .filter(|v| v != &AccountKeyring::One) + .filter(|v| v != &AccountKeyring::Two) + .map(|v| v.to_account_id()) .collect(), sp_keyring::AccountKeyring::Alice.to_account_id(), ) From 04a4e63ab9c9f888a2fdd50d4d2a36c160efa34a Mon Sep 17 00:00:00 2001 From: Iulian Barbu Date: Mon, 30 Sep 2024 11:07:00 +0300 Subject: [PATCH 06/15] Revert "wip: need to fix stuff I purposely wronged" This reverts commit 217541972f36feb7e821a7b41082797e6f9ffac9. --- Cargo.toml | 88 +++++++++---------- .../runtime/src/genesis_config_presets.rs | 5 +- 2 files changed, 47 insertions(+), 46 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5c34dfa50b2f7..a30b5b57d3618 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1408,47 +1408,47 @@ overflow-checks = true # # This list is ordered alphabetically. [profile.dev.package] -blake2 = { opt-level = 0 } -blake2b_simd = { opt-level = 0 } -chacha20poly1305 = { opt-level = 0 } -cranelift-codegen = { opt-level = 0 } -cranelift-wasm = { opt-level = 0 } -crc32fast = { opt-level = 0 } -crossbeam-deque = { opt-level = 0 } -crypto-mac = { opt-level = 0 } -curve25519-dalek = { opt-level = 0 } -ed25519-dalek = { opt-level = 0 } -flate2 = { opt-level = 0 } -futures-channel = { opt-level = 0 } -hash-db = { opt-level = 0 } -hashbrown = { opt-level = 0 } -hmac = { opt-level = 0 } -httparse = { opt-level = 0 } -integer-sqrt = { opt-level = 0 } -keccak = { opt-level = 0 } -libm = { opt-level = 0 } -librocksdb-sys = { opt-level = 0 } -libsecp256k1 = { opt-level = 0 } -libz-sys = { opt-level = 0 } -mio = { opt-level = 0 } -nalgebra = { opt-level = 0 } -num-bigint = { opt-level = 0 } -parking_lot = { opt-level = 0 } -parking_lot_core = { opt-level = 0 } -percent-encoding = { opt-level = 0 } -polkavm-linker = { opt-level = 0 } -primitive-types = { opt-level = 0 } -reed-solomon-novelpoly = { opt-level = 0 } -ring = { opt-level = 0 } -rustls = { opt-level = 0 } -sha2 = { opt-level = 0 } -sha3 = { opt-level = 0 } -smallvec = { opt-level = 0 } -snow = { opt-level = 0 } -substrate-bip39 = { opt-level = 0 } -twox-hash = { opt-level = 0 } -uint = { opt-level = 0 } -wasmi = { opt-level = 0 } -x25519-dalek = { opt-level = 0 } -yamux = { opt-level = 0 } -zeroize = { opt-level = 0 } +blake2 = { opt-level = 3 } +blake2b_simd = { opt-level = 3 } +chacha20poly1305 = { opt-level = 3 } +cranelift-codegen = { opt-level = 3 } +cranelift-wasm = { opt-level = 3 } +crc32fast = { opt-level = 3 } +crossbeam-deque = { opt-level = 3 } +crypto-mac = { opt-level = 3 } +curve25519-dalek = { opt-level = 3 } +ed25519-dalek = { opt-level = 3 } +flate2 = { opt-level = 3 } +futures-channel = { opt-level = 3 } +hash-db = { opt-level = 3 } +hashbrown = { opt-level = 3 } +hmac = { opt-level = 3 } +httparse = { opt-level = 3 } +integer-sqrt = { opt-level = 3 } +keccak = { opt-level = 3 } +libm = { opt-level = 3 } +librocksdb-sys = { opt-level = 3 } +libsecp256k1 = { opt-level = 3 } +libz-sys = { opt-level = 3 } +mio = { opt-level = 3 } +nalgebra = { opt-level = 3 } +num-bigint = { opt-level = 3 } +parking_lot = { opt-level = 3 } +parking_lot_core = { opt-level = 3 } +percent-encoding = { opt-level = 3 } +polkavm-linker = { opt-level = 3 } +primitive-types = { opt-level = 3 } +reed-solomon-novelpoly = { opt-level = 3 } +ring = { opt-level = 3 } +rustls = { opt-level = 3 } +sha2 = { opt-level = 3 } +sha3 = { opt-level = 3 } +smallvec = { opt-level = 3 } +snow = { opt-level = 3 } +substrate-bip39 = { opt-level = 3 } +twox-hash = { opt-level = 3 } +uint = { opt-level = 3 } +wasmi = { opt-level = 3 } +x25519-dalek = { opt-level = 3 } +yamux = { opt-level = 3 } +zeroize = { opt-level = 3 } diff --git a/templates/minimal/runtime/src/genesis_config_presets.rs b/templates/minimal/runtime/src/genesis_config_presets.rs index b355b6631d3fb..7679f3dbd6fae 100644 --- a/templates/minimal/runtime/src/genesis_config_presets.rs +++ b/templates/minimal/runtime/src/genesis_config_presets.rs @@ -23,9 +23,10 @@ use polkadot_sdk::{ use serde_json::Value; fn testnet_genesis(endowed_accounts: Vec, root: AccountId) -> Value { - let balances = endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::>(); let config = RuntimeGenesisConfig { - balances: BalancesConfig { balances }, + balances: BalancesConfig { + balances: endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::>(), + }, sudo: SudoConfig { key: Some(root) }, ..Default::default() }; From 54f7739e9fff918f49e999a53f85bf6a43b28914 Mon Sep 17 00:00:00 2001 From: Iulian Barbu Date: Mon, 30 Sep 2024 11:18:54 +0300 Subject: [PATCH 07/15] disambiguate imports Signed-off-by: Iulian Barbu --- templates/solochain/runtime/src/genesis_config_presets.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/solochain/runtime/src/genesis_config_presets.rs b/templates/solochain/runtime/src/genesis_config_presets.rs index de456e50e8eb7..44e2c2d207ca1 100644 --- a/templates/solochain/runtime/src/genesis_config_presets.rs +++ b/templates/solochain/runtime/src/genesis_config_presets.rs @@ -15,8 +15,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::{AccountId, BalancesConfig, RuntimeGenesisConfig, SudoConfig, Vec}; -use alloc::vec; +use crate::{AccountId, BalancesConfig, RuntimeGenesisConfig, SudoConfig}; +use alloc::{vec, vec::Vec}; use serde_json::Value; use sp_genesis_builder::{self, PresetId}; use sp_keyring::AccountKeyring; From 4586b27248c0cb62807e3410f6f535e9b5d762c0 Mon Sep 17 00:00:00 2001 From: Iulian Barbu Date: Mon, 30 Sep 2024 12:09:29 +0300 Subject: [PATCH 08/15] simplified even more Signed-off-by: Iulian Barbu --- .../minimal/runtime/src/genesis_config_presets.rs | 7 +++---- templates/minimal/runtime/src/lib.rs | 11 ----------- .../solochain/runtime/src/genesis_config_presets.rs | 3 +-- 3 files changed, 4 insertions(+), 17 deletions(-) diff --git a/templates/minimal/runtime/src/genesis_config_presets.rs b/templates/minimal/runtime/src/genesis_config_presets.rs index 7679f3dbd6fae..c509481e637e4 100644 --- a/templates/minimal/runtime/src/genesis_config_presets.rs +++ b/templates/minimal/runtime/src/genesis_config_presets.rs @@ -15,7 +15,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use crate::{vec, AccountId, BalancesConfig, RuntimeGenesisConfig, SudoConfig, Vec}; +use crate::{interface::AccountId, vec, BalancesConfig, RuntimeGenesisConfig, SudoConfig, Vec}; use polkadot_sdk::{ sp_genesis_builder::{self, PresetId}, sp_keyring::AccountKeyring, @@ -25,7 +25,7 @@ use serde_json::Value; fn testnet_genesis(endowed_accounts: Vec, root: AccountId) -> Value { let config = RuntimeGenesisConfig { balances: BalancesConfig { - balances: endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::>(), + balances: endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 30)).collect::>(), }, sudo: SudoConfig { key: Some(root) }, ..Default::default() @@ -37,8 +37,7 @@ fn testnet_genesis(endowed_accounts: Vec, root: AccountId) -> Value { fn development_config_genesis() -> Value { testnet_genesis( AccountKeyring::iter() - .filter(|v| v != &AccountKeyring::One) - .filter(|v| v != &AccountKeyring::Two) + .filter(|v| v != &AccountKeyring::One && v != &AccountKeyring::Two) .map(|v| v.to_account_id()) .collect(), AccountKeyring::Alice.to_account_id(), diff --git a/templates/minimal/runtime/src/lib.rs b/templates/minimal/runtime/src/lib.rs index a4e261791171e..91dc473c8ba58 100644 --- a/templates/minimal/runtime/src/lib.rs +++ b/templates/minimal/runtime/src/lib.rs @@ -35,21 +35,10 @@ use polkadot_sdk::{ }, *, }; -use sp_runtime::{ - traits::{IdentifyAccount, Verify}, - MultiSignature, -}; // Provides helpers for genesis configuration presets setup. mod genesis_config_presets; -/// Alias to 512-bit hash when used in the context of a transaction signature on the chain. -pub type Signature = MultiSignature; - -/// Some way of identifying an account on the chain. We intentionally make it equivalent -/// to the public key of our transaction signing scheme. -pub type AccountId = <::Signer as IdentifyAccount>::AccountId; - /// The runtime version. #[runtime_version] pub const VERSION: RuntimeVersion = RuntimeVersion { diff --git a/templates/solochain/runtime/src/genesis_config_presets.rs b/templates/solochain/runtime/src/genesis_config_presets.rs index 44e2c2d207ca1..4451dd4a2f35e 100644 --- a/templates/solochain/runtime/src/genesis_config_presets.rs +++ b/templates/solochain/runtime/src/genesis_config_presets.rs @@ -40,8 +40,7 @@ fn testnet_genesis(endowed_accounts: Vec, root: AccountId) -> Value { fn development_config_genesis() -> Value { testnet_genesis( sp_keyring::AccountKeyring::iter() - .filter(|v| v != &AccountKeyring::One) - .filter(|v| v != &AccountKeyring::Two) + .filter(|v| v != &AccountKeyring::One && v != &AccountKeyring::Two) .map(|v| v.to_account_id()) .collect(), sp_keyring::AccountKeyring::Alice.to_account_id(), From 1dc92adc1ab45a05237afb0723912ee844a9e31d Mon Sep 17 00:00:00 2001 From: Iulian Barbu Date: Mon, 30 Sep 2024 14:13:50 +0300 Subject: [PATCH 09/15] reuse the genesis config presets in node chain specs Signed-off-by: Iulian Barbu --- templates/minimal/node/src/chain_spec.rs | 22 +---- .../runtime/src/genesis_config_presets.rs | 63 ------------ templates/minimal/runtime/src/lib.rs | 61 +++++++++++- templates/solochain/node/src/chain_spec.rs | 97 ++----------------- templates/solochain/node/src/command.rs | 2 +- .../runtime/src/genesis_config_presets.rs | 67 +++++++++++-- templates/solochain/runtime/src/lib.rs | 2 +- 7 files changed, 130 insertions(+), 184 deletions(-) delete mode 100644 templates/minimal/runtime/src/genesis_config_presets.rs diff --git a/templates/minimal/node/src/chain_spec.rs b/templates/minimal/node/src/chain_spec.rs index 0646460acef64..6607128738262 100644 --- a/templates/minimal/node/src/chain_spec.rs +++ b/templates/minimal/node/src/chain_spec.rs @@ -15,13 +15,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -use minimal_template_runtime::{BalancesConfig, SudoConfig, WASM_BINARY}; +use minimal_template_runtime::WASM_BINARY; use polkadot_sdk::{ sc_service::{ChainType, Properties}, - sp_keyring::AccountKeyring, *, }; -use serde_json::{json, Value}; /// This is a specialization of the general Substrate ChainSpec type. pub type ChainSpec = sc_service::GenericChainSpec; @@ -38,21 +36,9 @@ pub fn development_config() -> Result { .with_name("Development") .with_id("dev") .with_chain_type(ChainType::Development) - .with_genesis_config_patch(testnet_genesis()) + .with_genesis_config_patch( + minimal_template_runtime::genesis_config_presets::development_config_genesis(), + ) .with_properties(props()) .build()) } - -/// Configure initial storage state for FRAME pallets. -fn testnet_genesis() -> Value { - use minimal_template_runtime::interface::{Balance, MinimumBalance}; - use polkadot_sdk::polkadot_sdk_frame::traits::Get; - let endowment = >::get().max(1) * 1000; - let balances = AccountKeyring::iter() - .map(|a| (a.to_account_id(), endowment)) - .collect::>(); - json!({ - "balances": BalancesConfig { balances }, - "sudo": SudoConfig { key: Some(AccountKeyring::Alice.to_account_id()) }, - }) -} diff --git a/templates/minimal/runtime/src/genesis_config_presets.rs b/templates/minimal/runtime/src/genesis_config_presets.rs deleted file mode 100644 index c509481e637e4..0000000000000 --- a/templates/minimal/runtime/src/genesis_config_presets.rs +++ /dev/null @@ -1,63 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::{interface::AccountId, vec, BalancesConfig, RuntimeGenesisConfig, SudoConfig, Vec}; -use polkadot_sdk::{ - sp_genesis_builder::{self, PresetId}, - sp_keyring::AccountKeyring, -}; -use serde_json::Value; - -fn testnet_genesis(endowed_accounts: Vec, root: AccountId) -> Value { - let config = RuntimeGenesisConfig { - balances: BalancesConfig { - balances: endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 30)).collect::>(), - }, - sudo: SudoConfig { key: Some(root) }, - ..Default::default() - }; - - serde_json::to_value(config).expect("Could not build genesis config.") -} - -fn development_config_genesis() -> Value { - testnet_genesis( - AccountKeyring::iter() - .filter(|v| v != &AccountKeyring::One && v != &AccountKeyring::Two) - .map(|v| v.to_account_id()) - .collect(), - AccountKeyring::Alice.to_account_id(), - ) -} - -/// Provides the JSON representation of predefined genesis config for given `id`. -pub fn get_preset(id: &PresetId) -> Option> { - let patch = match id.try_into() { - Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => development_config_genesis(), - _ => return None, - }; - Some( - serde_json::to_string(&patch) - .expect("serialization to json is expected to work. qed.") - .into_bytes(), - ) -} - -/// List of supported presets. -pub fn preset_names() -> Vec { - vec![PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET)] -} diff --git a/templates/minimal/runtime/src/lib.rs b/templates/minimal/runtime/src/lib.rs index 91dc473c8ba58..7a267b15669af 100644 --- a/templates/minimal/runtime/src/lib.rs +++ b/templates/minimal/runtime/src/lib.rs @@ -25,7 +25,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); extern crate alloc; -use alloc::{vec, vec::Vec}; +use alloc::vec::Vec; use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo}; use polkadot_sdk::{ polkadot_sdk_frame::{ @@ -36,8 +36,59 @@ use polkadot_sdk::{ *, }; -// Provides helpers for genesis configuration presets setup. -mod genesis_config_presets; +/// Provides getters for genesis configuration presets. +pub mod genesis_config_presets { + use crate::{ + interface::{AccountId, Balance, MinimumBalance}, + sp_genesis_builder::PresetId, + sp_keyring::AccountKeyring, + BalancesConfig, RuntimeGenesisConfig, SudoConfig, + }; + + use alloc::{vec, vec::Vec}; + use polkadot_sdk::{sp_core::Get, sp_genesis_builder}; + use serde_json::Value; + + // Returns a genesis config preset populated with given parameters. + fn testnet_genesis(endowed_accounts: Vec<(AccountId, u64)>, root: AccountId) -> Value { + let config = RuntimeGenesisConfig { + balances: BalancesConfig { balances: endowed_accounts }, + sudo: SudoConfig { key: Some(root) }, + ..Default::default() + }; + + serde_json::to_value(config).expect("Could not build genesis config.") + } + + /// Returns a development genesis config preset. + pub fn development_config_genesis() -> Value { + let endowment = >::get().max(1) * 1000; + testnet_genesis( + AccountKeyring::iter() + .map(|a| (a.to_account_id(), endowment)) + .collect::>(), + AccountKeyring::Alice.to_account_id(), + ) + } + + /// Get the set of the available genesis config presets. + pub fn get_preset(id: &PresetId) -> Option> { + let patch = match id.try_into() { + Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => development_config_genesis(), + _ => return None, + }; + Some( + serde_json::to_string(&patch) + .expect("serialization to json is expected to work. qed.") + .into_bytes(), + ) + } + + /// List of supported presets. + pub fn preset_names() -> Vec { + vec![PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET)] + } +} /// The runtime version. #[runtime_version] @@ -275,11 +326,11 @@ impl_runtime_apis! { } fn get_preset(id: &Option) -> Option> { - get_preset::(id, crate::genesis_config_presets::get_preset) + get_preset::(id, self::genesis_config_presets::get_preset) } fn preset_names() -> Vec { - crate::genesis_config_presets::preset_names() + self::genesis_config_presets::preset_names() } } } diff --git a/templates/solochain/node/src/chain_spec.rs b/templates/solochain/node/src/chain_spec.rs index 651025e68ded9..165f410ac32f8 100644 --- a/templates/solochain/node/src/chain_spec.rs +++ b/templates/solochain/node/src/chain_spec.rs @@ -1,9 +1,5 @@ use sc_service::ChainType; -use solochain_template_runtime::{AccountId, Signature, WASM_BINARY}; -use sp_consensus_aura::sr25519::AuthorityId as AuraId; -use sp_consensus_grandpa::AuthorityId as GrandpaId; -use sp_core::{sr25519, Pair, Public}; -use sp_runtime::traits::{IdentifyAccount, Verify}; +use solochain_template_runtime::WASM_BINARY; // The URL for the telemetry server. // const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; @@ -11,28 +7,6 @@ use sp_runtime::traits::{IdentifyAccount, Verify}; /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. pub type ChainSpec = sc_service::GenericChainSpec; -/// Generate a crypto pair from seed. -pub fn get_from_seed(seed: &str) -> ::Public { - TPublic::Pair::from_string(&format!("//{}", seed), None) - .expect("static values are valid; qed") - .public() -} - -type AccountPublic = ::Signer; - -/// Generate an account ID from seed. -pub fn get_account_id_from_seed(seed: &str) -> AccountId -where - AccountPublic: From<::Public>, -{ - AccountPublic::from(get_from_seed::(seed)).into_account() -} - -/// Generate an Aura authority key. -pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) { - (get_from_seed::(s), get_from_seed::(s)) -} - pub fn development_config() -> Result { Ok(ChainSpec::builder( WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?, @@ -41,24 +15,13 @@ pub fn development_config() -> Result { .with_name("Development") .with_id("dev") .with_chain_type(ChainType::Development) - .with_genesis_config_patch(testnet_genesis( - // Initial PoA authorities - vec![authority_keys_from_seed("Alice")], - // Sudo account - get_account_id_from_seed::("Alice"), - // Pre-funded accounts - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - ], - true, - )) + .with_genesis_config_patch( + solochain_template_runtime::genesis_config_presets::development_config_genesis(), + ) .build()) } -pub fn local_testnet_config() -> Result { +pub fn local_config() -> Result { Ok(ChainSpec::builder( WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?, None, @@ -66,52 +29,8 @@ pub fn local_testnet_config() -> Result { .with_name("Local Testnet") .with_id("local_testnet") .with_chain_type(ChainType::Local) - .with_genesis_config_patch(testnet_genesis( - // Initial PoA authorities - vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")], - // Sudo account - get_account_id_from_seed::("Alice"), - // Pre-funded accounts - vec![ - get_account_id_from_seed::("Alice"), - get_account_id_from_seed::("Bob"), - get_account_id_from_seed::("Charlie"), - get_account_id_from_seed::("Dave"), - get_account_id_from_seed::("Eve"), - get_account_id_from_seed::("Ferdie"), - get_account_id_from_seed::("Alice//stash"), - get_account_id_from_seed::("Bob//stash"), - get_account_id_from_seed::("Charlie//stash"), - get_account_id_from_seed::("Dave//stash"), - get_account_id_from_seed::("Eve//stash"), - get_account_id_from_seed::("Ferdie//stash"), - ], - true, - )) + .with_genesis_config_patch( + solochain_template_runtime::genesis_config_presets::local_config_genesis(), + ) .build()) } - -/// Configure initial storage state for FRAME modules. -fn testnet_genesis( - initial_authorities: Vec<(AuraId, GrandpaId)>, - root_key: AccountId, - endowed_accounts: Vec, - _enable_println: bool, -) -> serde_json::Value { - serde_json::json!({ - "balances": { - // Configure endowed accounts with initial balance of 1 << 60. - "balances": endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::>(), - }, - "aura": { - "authorities": initial_authorities.iter().map(|x| (x.0.clone())).collect::>(), - }, - "grandpa": { - "authorities": initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect::>(), - }, - "sudo": { - // Assign network admin rights. - "key": Some(root_key), - }, - }) -} diff --git a/templates/solochain/node/src/command.rs b/templates/solochain/node/src/command.rs index 624ace1bf350a..fbf0cf8beaba9 100644 --- a/templates/solochain/node/src/command.rs +++ b/templates/solochain/node/src/command.rs @@ -38,7 +38,7 @@ impl SubstrateCli for Cli { fn load_spec(&self, id: &str) -> Result, String> { Ok(match id { "dev" => Box::new(chain_spec::development_config()?), - "" | "local" => Box::new(chain_spec::local_testnet_config()?), + "" | "local" => Box::new(chain_spec::local_config()?), path => Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?), }) diff --git a/templates/solochain/runtime/src/genesis_config_presets.rs b/templates/solochain/runtime/src/genesis_config_presets.rs index 4451dd4a2f35e..d937e27fe370d 100644 --- a/templates/solochain/runtime/src/genesis_config_presets.rs +++ b/templates/solochain/runtime/src/genesis_config_presets.rs @@ -16,12 +16,20 @@ // limitations under the License. use crate::{AccountId, BalancesConfig, RuntimeGenesisConfig, SudoConfig}; -use alloc::{vec, vec::Vec}; +use alloc::{format, vec, vec::Vec}; use serde_json::Value; +use sp_consensus_aura::sr25519::AuthorityId as AuraId; +use sp_consensus_grandpa::AuthorityId as GrandpaId; +use sp_core::{Pair, Public}; use sp_genesis_builder::{self, PresetId}; use sp_keyring::AccountKeyring; -fn testnet_genesis(endowed_accounts: Vec, root: AccountId) -> Value { +// Returns the genesis config presets populated with given parameters. +fn testnet_genesis( + initial_authorities: Vec<(AuraId, GrandpaId)>, + endowed_accounts: Vec, + root: AccountId, +) -> Value { let config = RuntimeGenesisConfig { balances: BalancesConfig { balances: endowed_accounts @@ -30,6 +38,13 @@ fn testnet_genesis(endowed_accounts: Vec, root: AccountId) -> Value { .map(|k| (k, 1u128 << 60)) .collect::>(), }, + aura: pallet_aura::GenesisConfig { + authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect::>(), + }, + grandpa: pallet_grandpa::GenesisConfig { + authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect::>(), + ..Default::default() + }, sudo: SudoConfig { key: Some(root) }, ..Default::default() }; @@ -37,13 +52,47 @@ fn testnet_genesis(endowed_accounts: Vec, root: AccountId) -> Value { serde_json::to_value(config).expect("Could not build genesis config.") } -fn development_config_genesis() -> Value { +// Generate a crypto pair from seed. +fn get_from_seed(seed: &str) -> ::Public +where + TPublic: Public, +{ + TPublic::Pair::from_string(&format!("//{}", seed), None) + .expect("static values are valid; qed") + .public() +} + +// Generate authority keys to be passed to the genesis config presets. +fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) { + (get_from_seed::(s), get_from_seed::(s)) +} + +/// Return the development genesis config. +pub fn development_config_genesis() -> Value { testnet_genesis( - sp_keyring::AccountKeyring::iter() + vec![authority_keys_from_seed(&AccountKeyring::Alice.to_seed())], + vec![ + AccountKeyring::Alice.to_account_id(), + AccountKeyring::Bob.to_account_id(), + AccountKeyring::AliceStash.to_account_id(), + AccountKeyring::BobStash.to_account_id(), + ], + sp_keyring::AccountKeyring::Alice.to_account_id(), + ) +} + +/// Return the local genesis config preset. +pub fn local_config_genesis() -> Value { + testnet_genesis( + vec![ + authority_keys_from_seed(&AccountKeyring::Alice.to_seed()), + authority_keys_from_seed(&AccountKeyring::Bob.to_seed()), + ], + AccountKeyring::iter() .filter(|v| v != &AccountKeyring::One && v != &AccountKeyring::Two) .map(|v| v.to_account_id()) - .collect(), - sp_keyring::AccountKeyring::Alice.to_account_id(), + .collect::>(), + AccountKeyring::Alice.to_account_id(), ) } @@ -51,6 +100,7 @@ fn development_config_genesis() -> Value { pub fn get_preset(id: &PresetId) -> Option> { let patch = match id.try_into() { Ok(sp_genesis_builder::DEV_RUNTIME_PRESET) => development_config_genesis(), + Ok(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET) => local_config_genesis(), _ => return None, }; Some( @@ -62,5 +112,8 @@ pub fn get_preset(id: &PresetId) -> Option> { /// List of supported presets. pub fn preset_names() -> Vec { - vec![PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET)] + vec![ + PresetId::from(sp_genesis_builder::DEV_RUNTIME_PRESET), + PresetId::from(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET), + ] } diff --git a/templates/solochain/runtime/src/lib.rs b/templates/solochain/runtime/src/lib.rs index 6e3a98f155bc8..bc47f3aeac85d 100644 --- a/templates/solochain/runtime/src/lib.rs +++ b/templates/solochain/runtime/src/lib.rs @@ -25,7 +25,7 @@ pub use pallet_timestamp::Call as TimestampCall; #[cfg(any(feature = "std", test))] pub use sp_runtime::BuildStorage; -mod genesis_config_presets; +pub mod genesis_config_presets; /// Opaque types. These are used by the CLI to instantiate machinery that don't need to know /// the specifics of the runtime. They can then be made to be agnostic over specific formats From d13c8dc1c9b614b10b2feab2ccb16d2cfe0d5fe6 Mon Sep 17 00:00:00 2001 From: Iulian Barbu Date: Mon, 30 Sep 2024 15:16:01 +0300 Subject: [PATCH 10/15] fix umbrella Signed-off-by: Iulian Barbu --- templates/minimal/runtime/Cargo.toml | 1 + templates/solochain/runtime/Cargo.toml | 2 ++ 2 files changed, 3 insertions(+) diff --git a/templates/minimal/runtime/Cargo.toml b/templates/minimal/runtime/Cargo.toml index 250efc73d6b98..f1ff00fa474e7 100644 --- a/templates/minimal/runtime/Cargo.toml +++ b/templates/minimal/runtime/Cargo.toml @@ -38,4 +38,5 @@ std = [ "pallet-minimal-template/std", "polkadot-sdk/std", "scale-info/std", + "serde_json/std" ] diff --git a/templates/solochain/runtime/Cargo.toml b/templates/solochain/runtime/Cargo.toml index 4ac240c7fe82c..c5838977d3eb0 100644 --- a/templates/solochain/runtime/Cargo.toml +++ b/templates/solochain/runtime/Cargo.toml @@ -117,6 +117,8 @@ std = [ "sp-version/std", "substrate-wasm-builder", + "sp-keyring/std", + "serde_json/std" ] runtime-benchmarks = [ From b33a7ce364a55459302a675c6d2c47f716e7cf33 Mon Sep 17 00:00:00 2001 From: Iulian Barbu Date: Mon, 30 Sep 2024 17:33:30 +0300 Subject: [PATCH 11/15] generate chain spec with genesis config preset name Signed-off-by: Iulian Barbu --- Cargo.lock | 1 + templates/minimal/node/src/chain_spec.rs | 4 +--- templates/solochain/node/Cargo.toml | 23 +++++++++++----------- templates/solochain/node/src/chain_spec.rs | 8 ++------ 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ecb658c2d8a50..e3a7792682a1e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21378,6 +21378,7 @@ dependencies = [ "sp-consensus-aura", "sp-consensus-grandpa", "sp-core 28.0.0", + "sp-genesis-builder", "sp-inherents", "sp-io 30.0.0", "sp-keyring", diff --git a/templates/minimal/node/src/chain_spec.rs b/templates/minimal/node/src/chain_spec.rs index 6607128738262..af8ee6df51219 100644 --- a/templates/minimal/node/src/chain_spec.rs +++ b/templates/minimal/node/src/chain_spec.rs @@ -36,9 +36,7 @@ pub fn development_config() -> Result { .with_name("Development") .with_id("dev") .with_chain_type(ChainType::Development) - .with_genesis_config_patch( - minimal_template_runtime::genesis_config_presets::development_config_genesis(), - ) + .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET) .with_properties(props()) .build()) } diff --git a/templates/solochain/node/Cargo.toml b/templates/solochain/node/Cargo.toml index 8f74c6b3cb55b..1ea56480fa010 100644 --- a/templates/solochain/node/Cargo.toml +++ b/templates/solochain/node/Cargo.toml @@ -35,6 +35,7 @@ sp-consensus-aura = { workspace = true, default-features = true } sc-consensus = { workspace = true, default-features = true } sc-consensus-grandpa = { workspace = true, default-features = true } sp-consensus-grandpa = { workspace = true, default-features = true } +sp-genesis-builder = { workspace = true } sc-client-api = { workspace = true, default-features = true } sc-basic-authorship = { workspace = true, default-features = true } @@ -66,22 +67,20 @@ substrate-build-script-utils = { workspace = true, default-features = true } [features] default = ["std"] -std = [ - "solochain-template-runtime/std", -] +std = ["solochain-template-runtime/std"] # Dependencies that are only required if runtime benchmarking should be build. runtime-benchmarks = [ - "frame-benchmarking-cli/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "sc-service/runtime-benchmarks", - "solochain-template-runtime/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", + "frame-benchmarking-cli/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "sc-service/runtime-benchmarks", + "solochain-template-runtime/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", ] # Enable features that allow the runtime to be tried and debugged. Name might be subject to change # in the near future. try-runtime = [ - "frame-system/try-runtime", - "pallet-transaction-payment/try-runtime", - "solochain-template-runtime/try-runtime", - "sp-runtime/try-runtime", + "frame-system/try-runtime", + "pallet-transaction-payment/try-runtime", + "solochain-template-runtime/try-runtime", + "sp-runtime/try-runtime", ] diff --git a/templates/solochain/node/src/chain_spec.rs b/templates/solochain/node/src/chain_spec.rs index 165f410ac32f8..9f1adbda1a4ff 100644 --- a/templates/solochain/node/src/chain_spec.rs +++ b/templates/solochain/node/src/chain_spec.rs @@ -15,9 +15,7 @@ pub fn development_config() -> Result { .with_name("Development") .with_id("dev") .with_chain_type(ChainType::Development) - .with_genesis_config_patch( - solochain_template_runtime::genesis_config_presets::development_config_genesis(), - ) + .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET) .build()) } @@ -29,8 +27,6 @@ pub fn local_config() -> Result { .with_name("Local Testnet") .with_id("local_testnet") .with_chain_type(ChainType::Local) - .with_genesis_config_patch( - solochain_template_runtime::genesis_config_presets::local_config_genesis(), - ) + .with_genesis_config_preset_name(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET) .build()) } From 2090acaa5ae99d5b37aa10d0adabcc83e81e61ec Mon Sep 17 00:00:00 2001 From: Iulian Barbu Date: Mon, 30 Sep 2024 18:11:23 +0300 Subject: [PATCH 12/15] fix taplo Signed-off-by: Iulian Barbu --- templates/minimal/runtime/Cargo.toml | 2 +- templates/solochain/node/Cargo.toml | 18 +++++++++--------- templates/solochain/runtime/Cargo.toml | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/templates/minimal/runtime/Cargo.toml b/templates/minimal/runtime/Cargo.toml index f1ff00fa474e7..c08b72f4b22e7 100644 --- a/templates/minimal/runtime/Cargo.toml +++ b/templates/minimal/runtime/Cargo.toml @@ -38,5 +38,5 @@ std = [ "pallet-minimal-template/std", "polkadot-sdk/std", "scale-info/std", - "serde_json/std" + "serde_json/std", ] diff --git a/templates/solochain/node/Cargo.toml b/templates/solochain/node/Cargo.toml index 1ea56480fa010..51b5bed0ddea0 100644 --- a/templates/solochain/node/Cargo.toml +++ b/templates/solochain/node/Cargo.toml @@ -70,17 +70,17 @@ default = ["std"] std = ["solochain-template-runtime/std"] # Dependencies that are only required if runtime benchmarking should be build. runtime-benchmarks = [ - "frame-benchmarking-cli/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "sc-service/runtime-benchmarks", - "solochain-template-runtime/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", + "frame-benchmarking-cli/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "sc-service/runtime-benchmarks", + "solochain-template-runtime/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", ] # Enable features that allow the runtime to be tried and debugged. Name might be subject to change # in the near future. try-runtime = [ - "frame-system/try-runtime", - "pallet-transaction-payment/try-runtime", - "solochain-template-runtime/try-runtime", - "sp-runtime/try-runtime", + "frame-system/try-runtime", + "pallet-transaction-payment/try-runtime", + "solochain-template-runtime/try-runtime", + "sp-runtime/try-runtime", ] diff --git a/templates/solochain/runtime/Cargo.toml b/templates/solochain/runtime/Cargo.toml index c5838977d3eb0..ba825dbd411a4 100644 --- a/templates/solochain/runtime/Cargo.toml +++ b/templates/solochain/runtime/Cargo.toml @@ -116,9 +116,9 @@ std = [ "sp-transaction-pool/std", "sp-version/std", - "substrate-wasm-builder", + "serde_json/std", "sp-keyring/std", - "serde_json/std" + "substrate-wasm-builder", ] runtime-benchmarks = [ From 93fe70e1456f509a2061e0e5cc8ad6fb519ca11d Mon Sep 17 00:00:00 2001 From: Iulian Barbu Date: Mon, 30 Sep 2024 18:22:50 +0300 Subject: [PATCH 13/15] enable default-features for sp-genesis-builder Signed-off-by: Iulian Barbu --- templates/solochain/node/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/solochain/node/Cargo.toml b/templates/solochain/node/Cargo.toml index 51b5bed0ddea0..a0285e048d1b4 100644 --- a/templates/solochain/node/Cargo.toml +++ b/templates/solochain/node/Cargo.toml @@ -35,7 +35,7 @@ sp-consensus-aura = { workspace = true, default-features = true } sc-consensus = { workspace = true, default-features = true } sc-consensus-grandpa = { workspace = true, default-features = true } sp-consensus-grandpa = { workspace = true, default-features = true } -sp-genesis-builder = { workspace = true } +sp-genesis-builder = { workspace = true, default-features = true } sc-client-api = { workspace = true, default-features = true } sc-basic-authorship = { workspace = true, default-features = true } From cc761df41aa4232846022e611abe15442d9c92df Mon Sep 17 00:00:00 2001 From: Iulian Barbu Date: Tue, 1 Oct 2024 19:13:16 +0300 Subject: [PATCH 14/15] adjust after seb review Signed-off-by: Iulian Barbu --- templates/solochain/node/src/chain_spec.rs | 3 -- .../runtime/src/genesis_config_presets.rs | 33 ++++++++----------- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/templates/solochain/node/src/chain_spec.rs b/templates/solochain/node/src/chain_spec.rs index 9f1adbda1a4ff..6f7882ec1fb09 100644 --- a/templates/solochain/node/src/chain_spec.rs +++ b/templates/solochain/node/src/chain_spec.rs @@ -1,9 +1,6 @@ use sc_service::ChainType; use solochain_template_runtime::WASM_BINARY; -// The URL for the telemetry server. -// const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; - /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. pub type ChainSpec = sc_service::GenericChainSpec; diff --git a/templates/solochain/runtime/src/genesis_config_presets.rs b/templates/solochain/runtime/src/genesis_config_presets.rs index d937e27fe370d..693ae5c2221f2 100644 --- a/templates/solochain/runtime/src/genesis_config_presets.rs +++ b/templates/solochain/runtime/src/genesis_config_presets.rs @@ -16,11 +16,10 @@ // limitations under the License. use crate::{AccountId, BalancesConfig, RuntimeGenesisConfig, SudoConfig}; -use alloc::{format, vec, vec::Vec}; +use alloc::{vec, vec::Vec}; use serde_json::Value; use sp_consensus_aura::sr25519::AuthorityId as AuraId; use sp_consensus_grandpa::AuthorityId as GrandpaId; -use sp_core::{Pair, Public}; use sp_genesis_builder::{self, PresetId}; use sp_keyring::AccountKeyring; @@ -52,25 +51,13 @@ fn testnet_genesis( serde_json::to_value(config).expect("Could not build genesis config.") } -// Generate a crypto pair from seed. -fn get_from_seed(seed: &str) -> ::Public -where - TPublic: Public, -{ - TPublic::Pair::from_string(&format!("//{}", seed), None) - .expect("static values are valid; qed") - .public() -} - -// Generate authority keys to be passed to the genesis config presets. -fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) { - (get_from_seed::(s), get_from_seed::(s)) -} - /// Return the development genesis config. pub fn development_config_genesis() -> Value { testnet_genesis( - vec![authority_keys_from_seed(&AccountKeyring::Alice.to_seed())], + vec![( + sp_keyring::Sr25519Keyring::Alice.public().into(), + sp_keyring::Ed25519Keyring::Alice.public().into(), + )], vec![ AccountKeyring::Alice.to_account_id(), AccountKeyring::Bob.to_account_id(), @@ -85,8 +72,14 @@ pub fn development_config_genesis() -> Value { pub fn local_config_genesis() -> Value { testnet_genesis( vec![ - authority_keys_from_seed(&AccountKeyring::Alice.to_seed()), - authority_keys_from_seed(&AccountKeyring::Bob.to_seed()), + ( + sp_keyring::Sr25519Keyring::Alice.public().into(), + sp_keyring::Ed25519Keyring::Alice.public().into(), + ), + ( + sp_keyring::Sr25519Keyring::Bob.public().into(), + sp_keyring::Ed25519Keyring::Bob.public().into(), + ), ], AccountKeyring::iter() .filter(|v| v != &AccountKeyring::One && v != &AccountKeyring::Two) From 2a1d44b8b9698de1ac59d38e87438f4bf8a484fc Mon Sep 17 00:00:00 2001 From: Iulian Barbu Date: Wed, 2 Oct 2024 11:04:37 +0300 Subject: [PATCH 15/15] adjust after michal review Signed-off-by: Iulian Barbu --- templates/minimal/node/src/chain_spec.rs | 2 +- templates/minimal/node/src/command.rs | 2 +- templates/minimal/runtime/Cargo.toml | 2 +- templates/minimal/runtime/src/lib.rs | 26 +++++++++------------- templates/parachain/node/src/chain_spec.rs | 4 ++-- templates/parachain/node/src/command.rs | 6 ++--- templates/parachain/runtime/Cargo.toml | 2 +- templates/solochain/node/src/chain_spec.rs | 4 ++-- templates/solochain/node/src/command.rs | 4 ++-- templates/solochain/runtime/Cargo.toml | 2 +- 10 files changed, 24 insertions(+), 30 deletions(-) diff --git a/templates/minimal/node/src/chain_spec.rs b/templates/minimal/node/src/chain_spec.rs index af8ee6df51219..17b98137b416a 100644 --- a/templates/minimal/node/src/chain_spec.rs +++ b/templates/minimal/node/src/chain_spec.rs @@ -31,7 +31,7 @@ fn props() -> Properties { properties } -pub fn development_config() -> Result { +pub fn development_chain_spec() -> Result { Ok(ChainSpec::builder(WASM_BINARY.expect("Development wasm not available"), Default::default()) .with_name("Development") .with_id("dev") diff --git a/templates/minimal/node/src/command.rs b/templates/minimal/node/src/command.rs index b09ea1fab2379..5cb0694d98282 100644 --- a/templates/minimal/node/src/command.rs +++ b/templates/minimal/node/src/command.rs @@ -49,7 +49,7 @@ impl SubstrateCli for Cli { fn load_spec(&self, id: &str) -> Result, String> { Ok(match id { - "dev" => Box::new(chain_spec::development_config()?), + "dev" => Box::new(chain_spec::development_chain_spec()?), path => Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?), }) diff --git a/templates/minimal/runtime/Cargo.toml b/templates/minimal/runtime/Cargo.toml index c08b72f4b22e7..74a09b9396e50 100644 --- a/templates/minimal/runtime/Cargo.toml +++ b/templates/minimal/runtime/Cargo.toml @@ -21,7 +21,7 @@ polkadot-sdk = { workspace = true, features = [ "pallet-transaction-payment-rpc-runtime-api", "runtime", ] } -serde_json = { workspace = true, default-features = false } +serde_json = { workspace = true, default-features = false, features = ["alloc"] } # local pallet templates pallet-minimal-template = { workspace = true } diff --git a/templates/minimal/runtime/src/lib.rs b/templates/minimal/runtime/src/lib.rs index 7a267b15669af..7379e33b6b3e8 100644 --- a/templates/minimal/runtime/src/lib.rs +++ b/templates/minimal/runtime/src/lib.rs @@ -39,7 +39,7 @@ use polkadot_sdk::{ /// Provides getters for genesis configuration presets. pub mod genesis_config_presets { use crate::{ - interface::{AccountId, Balance, MinimumBalance}, + interface::{Balance, MinimumBalance}, sp_genesis_builder::PresetId, sp_keyring::AccountKeyring, BalancesConfig, RuntimeGenesisConfig, SudoConfig, @@ -49,28 +49,22 @@ pub mod genesis_config_presets { use polkadot_sdk::{sp_core::Get, sp_genesis_builder}; use serde_json::Value; - // Returns a genesis config preset populated with given parameters. - fn testnet_genesis(endowed_accounts: Vec<(AccountId, u64)>, root: AccountId) -> Value { + /// Returns a development genesis config preset. + pub fn development_config_genesis() -> Value { + let endowment = >::get().max(1) * 1000; let config = RuntimeGenesisConfig { - balances: BalancesConfig { balances: endowed_accounts }, - sudo: SudoConfig { key: Some(root) }, + balances: BalancesConfig { + balances: AccountKeyring::iter() + .map(|a| (a.to_account_id(), endowment)) + .collect::>(), + }, + sudo: SudoConfig { key: Some(AccountKeyring::Alice.to_account_id()) }, ..Default::default() }; serde_json::to_value(config).expect("Could not build genesis config.") } - /// Returns a development genesis config preset. - pub fn development_config_genesis() -> Value { - let endowment = >::get().max(1) * 1000; - testnet_genesis( - AccountKeyring::iter() - .map(|a| (a.to_account_id(), endowment)) - .collect::>(), - AccountKeyring::Alice.to_account_id(), - ) - } - /// Get the set of the available genesis config presets. pub fn get_preset(id: &PresetId) -> Option> { let patch = match id.try_into() { diff --git a/templates/parachain/node/src/chain_spec.rs b/templates/parachain/node/src/chain_spec.rs index 7cdd362dffb80..af82607bc8e41 100644 --- a/templates/parachain/node/src/chain_spec.rs +++ b/templates/parachain/node/src/chain_spec.rs @@ -24,7 +24,7 @@ impl Extensions { } } -pub fn development_config() -> ChainSpec { +pub fn development_chain_spec() -> ChainSpec { // Give your base currency a unit name and decimal places let mut properties = sc_chain_spec::Properties::new(); properties.insert("tokenSymbol".into(), "UNIT".into()); @@ -46,7 +46,7 @@ pub fn development_config() -> ChainSpec { .build() } -pub fn local_testnet_config() -> ChainSpec { +pub fn local_chain_spec() -> ChainSpec { // Give your base currency a unit name and decimal places let mut properties = sc_chain_spec::Properties::new(); properties.insert("tokenSymbol".into(), "UNIT".into()); diff --git a/templates/parachain/node/src/command.rs b/templates/parachain/node/src/command.rs index 610dbd7a686a9..6b9deade1271b 100644 --- a/templates/parachain/node/src/command.rs +++ b/templates/parachain/node/src/command.rs @@ -17,9 +17,9 @@ use crate::{ fn load_spec(id: &str) -> std::result::Result, String> { Ok(match id { - "dev" => Box::new(chain_spec::development_config()), - "template-rococo" => Box::new(chain_spec::local_testnet_config()), - "" | "local" => Box::new(chain_spec::local_testnet_config()), + "dev" => Box::new(chain_spec::development_chain_spec()), + "template-rococo" => Box::new(chain_spec::local_chain_spec()), + "" | "local" => Box::new(chain_spec::local_chain_spec()), path => Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?), }) } diff --git a/templates/parachain/runtime/Cargo.toml b/templates/parachain/runtime/Cargo.toml index 45c77d18e8167..236b7c048632e 100644 --- a/templates/parachain/runtime/Cargo.toml +++ b/templates/parachain/runtime/Cargo.toml @@ -27,7 +27,7 @@ scale-info = { features = [ ], workspace = true } smallvec = { workspace = true, default-features = true } docify = { workspace = true } -serde_json = { workspace = true, default-features = false } +serde_json = { workspace = true, default-features = false, features = ["alloc"] } # Local pallet-parachain-template = { workspace = true } diff --git a/templates/solochain/node/src/chain_spec.rs b/templates/solochain/node/src/chain_spec.rs index 6f7882ec1fb09..086bf7accf3a9 100644 --- a/templates/solochain/node/src/chain_spec.rs +++ b/templates/solochain/node/src/chain_spec.rs @@ -4,7 +4,7 @@ use solochain_template_runtime::WASM_BINARY; /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. pub type ChainSpec = sc_service::GenericChainSpec; -pub fn development_config() -> Result { +pub fn development_chain_spec() -> Result { Ok(ChainSpec::builder( WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?, None, @@ -16,7 +16,7 @@ pub fn development_config() -> Result { .build()) } -pub fn local_config() -> Result { +pub fn local_chain_spec() -> Result { Ok(ChainSpec::builder( WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?, None, diff --git a/templates/solochain/node/src/command.rs b/templates/solochain/node/src/command.rs index fbf0cf8beaba9..e2c7657c95cce 100644 --- a/templates/solochain/node/src/command.rs +++ b/templates/solochain/node/src/command.rs @@ -37,8 +37,8 @@ impl SubstrateCli for Cli { fn load_spec(&self, id: &str) -> Result, String> { Ok(match id { - "dev" => Box::new(chain_spec::development_config()?), - "" | "local" => Box::new(chain_spec::local_config()?), + "dev" => Box::new(chain_spec::development_chain_spec()?), + "" | "local" => Box::new(chain_spec::local_chain_spec()?), path => Box::new(chain_spec::ChainSpec::from_json_file(std::path::PathBuf::from(path))?), }) diff --git a/templates/solochain/runtime/Cargo.toml b/templates/solochain/runtime/Cargo.toml index ba825dbd411a4..8a7fa74a59779 100644 --- a/templates/solochain/runtime/Cargo.toml +++ b/templates/solochain/runtime/Cargo.toml @@ -20,7 +20,7 @@ scale-info = { features = [ "derive", "serde", ], workspace = true } -serde_json = { workspace = true, default-features = false } +serde_json = { workspace = true, default-features = false, features = ["alloc"] } # frame frame-support = { features = ["experimental"], workspace = true }