difftreelog
fix use ChainSpecBuilder
in: master
8 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6380,6 +6380,7 @@
"sp-block-builder",
"sp-consensus-aura",
"sp-core",
+ "sp-genesis-builder",
"sp-inherents",
"sp-io",
"sp-offchain",
@@ -10261,6 +10262,7 @@
"sp-block-builder",
"sp-consensus-aura",
"sp-core",
+ "sp-genesis-builder",
"sp-inherents",
"sp-io",
"sp-offchain",
@@ -15134,6 +15136,7 @@
"sp-block-builder",
"sp-consensus-aura",
"sp-core",
+ "sp-genesis-builder",
"sp-inherents",
"sp-io",
"sp-offchain",
Cargo.tomldiffbeforeafterboth--- a/Cargo.toml
+++ b/Cargo.toml
@@ -181,6 +181,7 @@
sp-trie = { default-features = false, version = "32.0.0" }
sp-version = { default-features = false, version = "32.0.0" }
sp-weights = { default-features = false, version = "30.0.0" }
+sp-genesis-builder = { default-features = false, version = "0.10.0" }
staging-parachain-info = { default-features = false, version = "0.10.0" }
staging-xcm = { default-features = false, version = "10.0.0" }
staging-xcm-builder = { default-features = false, version = "10.0.0" }
@@ -217,4 +218,5 @@
log = { version = "0.4.20", default-features = false }
num_enum = { version = "0.7.0", default-features = false }
serde = { default-features = false, features = ['derive'], version = "1.0.188" }
+serde_json = "1"
smallvec = "1.11.1"
node/cli/src/chain_spec.rsdiffbeforeafterboth--- a/node/cli/src/chain_spec.rs
+++ b/node/cli/src/chain_spec.rs
@@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-use std::collections::BTreeMap;
-
use default_runtime::WASM_BINARY;
#[cfg(all(not(feature = "unique-runtime"), not(feature = "quartz-runtime")))]
pub use opal_runtime as default_runtime;
@@ -24,7 +22,7 @@
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::ChainType;
use serde::{Deserialize, Serialize};
-use serde_json::map::Map;
+use serde_json::{json, map::Map};
use sp_core::{sr25519, Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};
#[cfg(feature = "unique-runtime")]
@@ -142,184 +140,102 @@
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
}
-#[cfg(not(feature = "unique-runtime"))]
-macro_rules! testnet_genesis {
- (
- $runtime:path,
- $root_key:expr,
- $initial_invulnerables:expr,
- $endowed_accounts:expr,
- $id:expr
- ) => {{
- use $runtime::*;
-
- RuntimeGenesisConfig {
- system: Default::default(),
- balances: BalancesConfig {
- balances: $endowed_accounts
- .iter()
- .cloned()
- // 1e13 UNQ
- .map(|k| (k, 1 << 100))
- .collect(),
- },
- sudo: SudoConfig {
- key: Some($root_key),
- },
-
- vesting: VestingConfig { vesting: vec![] },
- parachain_info: ParachainInfoConfig {
- parachain_id: $id.into(),
- ..Default::default()
- },
- collator_selection: CollatorSelectionConfig {
- invulnerables: $initial_invulnerables
- .iter()
- .cloned()
- .map(|(acc, _)| acc)
- .collect(),
- },
- session: SessionConfig {
- keys: $initial_invulnerables
- .into_iter()
- .map(|(acc, aura)| {
- (
- acc.clone(), // account id
- acc, // validator id
- SessionKeys { aura }, // session keys
- )
- })
- .collect(),
- },
- evm: EVMConfig {
- accounts: BTreeMap::new(),
- ..Default::default()
- },
- ..Default::default()
+pub fn test_config(chain_id: &str, relay_chain: &str) -> DefaultChainSpec {
+ DefaultChainSpec::builder(
+ WASM_BINARY.expect("WASM binary was not build, please build it!"),
+ Extensions {
+ relay_chain: relay_chain.into(),
+ para_id: PARA_ID,
+ },
+ )
+ .with_id(&format!(
+ "{}_{}",
+ default_runtime::VERSION.spec_name,
+ chain_id
+ ))
+ .with_name(&format!(
+ "{}{}",
+ default_runtime::VERSION.spec_name.to_uppercase(),
+ if cfg!(feature = "unique-runtime") {
+ ""
+ } else {
+ " by UNIQUE"
}
- }};
+ ))
+ .with_properties(chain_properties())
+ .with_chain_type(ChainType::Development)
+ .with_genesis_config_patch(genesis_patch())
+ .build()
}
-#[cfg(feature = "unique-runtime")]
-macro_rules! testnet_genesis {
- (
- $runtime:path,
- $root_key:expr,
- $initial_invulnerables:expr,
- $endowed_accounts:expr,
- $id:expr
- ) => {{
- use $runtime::*;
+fn genesis_patch() -> serde_json::Value {
+ use default_runtime::*;
- RuntimeGenesisConfig {
- system: Default::default(),
- balances: BalancesConfig {
- balances: $endowed_accounts
- .iter()
- .cloned()
- // 1e13 UNQ
- .map(|k| (k, 1 << 100))
- .collect(),
- },
- sudo: SudoConfig {
- key: Some($root_key),
- },
- vesting: VestingConfig { vesting: vec![] },
- parachain_info: ParachainInfoConfig {
- parachain_id: $id.into(),
- ..Default::default()
- },
- aura: AuraConfig {
- authorities: $initial_invulnerables
- .into_iter()
- .map(|(_, aura)| aura)
- .collect(),
- },
- evm: EVMConfig {
- accounts: BTreeMap::new(),
- ..Default::default()
- },
- ..Default::default()
- }
- }};
-}
+ let invulnerables = ["Alice", "Bob"];
-pub fn development_config() -> DefaultChainSpec {
- let mut properties = Map::new();
- properties.insert("tokenSymbol".into(), default_runtime::TOKEN_SYMBOL.into());
- properties.insert("tokenDecimals".into(), default_runtime::DECIMALS.into());
- properties.insert(
- "ss58Format".into(),
- default_runtime::SS58Prefix::get().into(),
- );
+ #[allow(unused_mut)]
+ let mut patch = json!({
+ "parachainInfo": {
+ "parachainId": PARA_ID,
+ },
- DefaultChainSpec::from_genesis(
- // Name
- format!(
- "{}{}",
- default_runtime::VERSION.spec_name.to_uppercase(),
- if cfg!(feature = "unique-runtime") {
- ""
- } else {
- " by UNIQUE"
- }
- )
- .as_str(),
- // ID
- format!("{}_dev", default_runtime::VERSION.spec_name).as_str(),
- ChainType::Local,
- move || {
- testnet_genesis!(
- default_runtime,
- // Sudo account
- get_account_id_from_seed::<sr25519::Public>("Alice"),
- [
+ "aura": {
+ "authorities": invulnerables.into_iter()
+ .map(|name| get_from_seed::<AuraId>(name))
+ .collect::<Vec<_>>(),
+ },
+
+ "session": {
+ "keys": invulnerables.into_iter()
+ .map(|name| {
+ let account = get_account_id_from_seed::<sr25519::Public>(name);
+ let aura = get_from_seed::<AuraId>(name);
+
(
- get_account_id_from_seed::<sr25519::Public>("Alice"),
- get_from_seed::<AuraId>("Alice"),
- ),
- (
- get_account_id_from_seed::<sr25519::Public>("Bob"),
- get_from_seed::<AuraId>("Bob"),
- ),
- ],
- // Pre-funded accounts
- vec![
- get_account_id_from_seed::<sr25519::Public>("Alice"),
- get_account_id_from_seed::<sr25519::Public>("Bob"),
- get_account_id_from_seed::<sr25519::Public>("Charlie"),
- get_account_id_from_seed::<sr25519::Public>("Dave"),
- get_account_id_from_seed::<sr25519::Public>("Eve"),
- get_account_id_from_seed::<sr25519::Public>("Ferdie"),
- get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
- get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
- get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
- get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
- get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
- get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
- ],
- PARA_ID
- )
+ /* account id: */ account.clone(),
+ /* validator id: */ account,
+ /* session keys: */ SessionKeys { aura },
+ )
+ })
+ .collect::<Vec<_>>()
+ },
+
+ "sudo": {
+ "key": get_account_id_from_seed::<sr25519::Public>("Alice"),
},
- // Bootnodes
- vec![],
- // Telemetry
- None,
- // Protocol ID
- None,
- None,
- // Properties
- Some(properties),
- // Extensions
- Extensions {
- relay_chain: "rococo-dev".into(),
- para_id: PARA_ID,
+
+ "balances": {
+ "balances": &[
+ get_account_id_from_seed::<sr25519::Public>("Alice"),
+ get_account_id_from_seed::<sr25519::Public>("Bob"),
+ get_account_id_from_seed::<sr25519::Public>("Charlie"),
+ get_account_id_from_seed::<sr25519::Public>("Dave"),
+ get_account_id_from_seed::<sr25519::Public>("Eve"),
+ get_account_id_from_seed::<sr25519::Public>("Ferdie"),
+ get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
+ get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
+ get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
+ get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
+ get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
+ get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
+ ].into_iter()
+ .map(|k| (k, /* ~1.2e+12 UNQ */ 1u128 << 100))
+ .collect::<Vec<_>>(),
},
- WASM_BINARY.expect("WASM binary was not build, please build it!"),
- )
+ });
+
+ #[cfg(feature = "unique-runtime")]
+ {
+ patch
+ .as_object_mut()
+ .expect("the genesis patch is always an object; qed")
+ .remove("session");
+ }
+
+ patch
}
-pub fn local_testnet_config() -> DefaultChainSpec {
+fn chain_properties() -> sc_chain_spec::Properties {
let mut properties = Map::new();
properties.insert("tokenSymbol".into(), default_runtime::TOKEN_SYMBOL.into());
properties.insert("tokenDecimals".into(), default_runtime::DECIMALS.into());
@@ -328,68 +244,5 @@
default_runtime::SS58Prefix::get().into(),
);
- DefaultChainSpec::from_genesis(
- // Name
- format!(
- "{}{}",
- default_runtime::VERSION.impl_name.to_uppercase(),
- if cfg!(feature = "unique-runtime") {
- ""
- } else {
- " by UNIQUE"
- }
- )
- .as_str(),
- // ID
- format!("{}_local", default_runtime::VERSION.spec_name).as_str(),
- ChainType::Local,
- move || {
- testnet_genesis!(
- default_runtime,
- // Sudo account
- get_account_id_from_seed::<sr25519::Public>("Alice"),
- [
- (
- get_account_id_from_seed::<sr25519::Public>("Alice"),
- get_from_seed::<AuraId>("Alice"),
- ),
- (
- get_account_id_from_seed::<sr25519::Public>("Bob"),
- get_from_seed::<AuraId>("Bob"),
- ),
- ],
- // Pre-funded accounts
- vec![
- get_account_id_from_seed::<sr25519::Public>("Alice"),
- get_account_id_from_seed::<sr25519::Public>("Bob"),
- get_account_id_from_seed::<sr25519::Public>("Charlie"),
- get_account_id_from_seed::<sr25519::Public>("Dave"),
- get_account_id_from_seed::<sr25519::Public>("Eve"),
- get_account_id_from_seed::<sr25519::Public>("Ferdie"),
- get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
- get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
- get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
- get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
- get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
- get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
- ],
- PARA_ID
- )
- },
- // Bootnodes
- vec![],
- // Telemetry
- None,
- // Protocol ID
- None,
- None,
- // Properties
- Some(properties),
- // Extensions
- Extensions {
- relay_chain: "westend-local".into(),
- para_id: PARA_ID,
- },
- WASM_BINARY.expect("WASM binary was not build, please build it!"),
- )
+ properties
}
node/cli/src/command.rsdiffbeforeafterboth--- a/node/cli/src/command.rs
+++ b/node/cli/src/command.rs
@@ -49,9 +49,7 @@
use crate::{
chain_spec::{self, RuntimeIdentification, ServiceId, ServiceIdentification},
cli::{Cli, RelayChainCli, Subcommand},
- service::{
- new_partial, start_dev_node, start_node, OpalRuntimeExecutor, ParachainHostFunctions,
- },
+ service::{new_partial, start_dev_node, start_node, OpalRuntimeExecutor},
};
macro_rules! no_runtime_err {
@@ -65,8 +63,8 @@
fn load_spec(id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(match id {
- "dev" => Box::new(chain_spec::development_config()),
- "" | "local" => Box::new(chain_spec::local_testnet_config()),
+ "dev" => Box::new(chain_spec::test_config("dev", "rococo-dev")),
+ "" | "local" => Box::new(chain_spec::test_config("local", "westend-local")),
path => {
let path = std::path::PathBuf::from(path);
#[allow(clippy::redundant_clone)]
@@ -352,6 +350,8 @@
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
use polkadot_cli::Block;
+ use crate::service::ParachainHostFunctions;
+
type Header = <Block as sp_runtime::traits::Block>::Header;
type Hasher = <Header as sp_runtime::traits::Header>::Hashing;
@@ -403,7 +403,7 @@
use std::{future::Future, pin::Pin};
use polkadot_cli::Block;
- use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, NativeExecutionDispatch};
+ use sc_executor::NativeExecutionDispatch;
use try_runtime_cli::block_building_info::timestamp_with_aura_info;
let runner = cli.create_runner(cmd)?;
runtime/common/runtime_apis.rsdiffbeforeafterboth--- a/runtime/common/runtime_apis.rs
+++ b/runtime/common/runtime_apis.rs
@@ -43,6 +43,7 @@
ApplyExtrinsicResult, DispatchError, ExtrinsicInclusionMode,
};
use frame_support::{
+ genesis_builder_helper::{build_config, create_default_config},
pallet_prelude::Weight,
traits::OnFinalize,
};
@@ -710,6 +711,16 @@
)
}
}
+
+ impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
+ fn create_default_config() -> Vec<u8> {
+ create_default_config::<RuntimeGenesisConfig>()
+ }
+
+ fn build_config(config: Vec<u8>) -> sp_genesis_builder::Result {
+ build_config::<RuntimeGenesisConfig>(config)
+ }
+ }
}
}
}
runtime/opal/Cargo.tomldiffbeforeafterboth146 'sp-storage/std',146 'sp-storage/std',147 'sp-transaction-pool/std',147 'sp-transaction-pool/std',148 'sp-version/std',148 'sp-version/std',149 'sp-genesis-builder/std',149 'staging-parachain-info/std',150 'staging-parachain-info/std',150 'staging-xcm-builder/std',151 'staging-xcm-builder/std',151 'staging-xcm-executor/std',152 'staging-xcm-executor/std',295sp-storage = { workspace = true }296sp-storage = { workspace = true }296sp-transaction-pool = { workspace = true }297sp-transaction-pool = { workspace = true }297sp-version = { workspace = true }298sp-version = { workspace = true }299sp-genesis-builder = { workspace = true }298staging-parachain-info = { workspace = true }300staging-parachain-info = { workspace = true }299staging-xcm = { workspace = true }301staging-xcm = { workspace = true }300staging-xcm-builder = { workspace = true }302staging-xcm-builder = { workspace = true }runtime/quartz/Cargo.tomldiffbeforeafterboth--- a/runtime/quartz/Cargo.toml
+++ b/runtime/quartz/Cargo.toml
@@ -145,6 +145,7 @@
'sp-std/std',
'sp-transaction-pool/std',
'sp-version/std',
+ 'sp-genesis-builder/std',
'staging-parachain-info/std',
'staging-xcm-builder/std',
'staging-xcm-executor/std',
@@ -283,6 +284,7 @@
sp-storage = { workspace = true }
sp-transaction-pool = { workspace = true }
sp-version = { workspace = true }
+sp-genesis-builder = { workspace = true }
staging-parachain-info = { workspace = true }
staging-xcm = { workspace = true }
staging-xcm-builder = { workspace = true }
runtime/unique/Cargo.tomldiffbeforeafterboth--- a/runtime/unique/Cargo.toml
+++ b/runtime/unique/Cargo.toml
@@ -143,6 +143,7 @@
'sp-std/std',
'sp-transaction-pool/std',
'sp-version/std',
+ 'sp-genesis-builder/std',
'staging-parachain-info/std',
'staging-xcm-builder/std',
'staging-xcm-executor/std',
@@ -287,6 +288,7 @@
sp-storage = { workspace = true }
sp-transaction-pool = { workspace = true }
sp-version = { workspace = true }
+sp-genesis-builder = { workspace = true }
staging-parachain-info = { workspace = true }
staging-xcm = { workspace = true }
staging-xcm-builder = { workspace = true }