difftreelog
fix use ChainSpecBuilder
in: master
8 files changed
Cargo.lockdiffbeforeafterboth6380 "sp-block-builder",6380 "sp-block-builder",6381 "sp-consensus-aura",6381 "sp-consensus-aura",6382 "sp-core",6382 "sp-core",6383 "sp-genesis-builder",6383 "sp-inherents",6384 "sp-inherents",6384 "sp-io",6385 "sp-io",6385 "sp-offchain",6386 "sp-offchain",10261 "sp-block-builder",10262 "sp-block-builder",10262 "sp-consensus-aura",10263 "sp-consensus-aura",10263 "sp-core",10264 "sp-core",10265 "sp-genesis-builder",10264 "sp-inherents",10266 "sp-inherents",10265 "sp-io",10267 "sp-io",10266 "sp-offchain",10268 "sp-offchain",15134 "sp-block-builder",15136 "sp-block-builder",15135 "sp-consensus-aura",15137 "sp-consensus-aura",15136 "sp-core",15138 "sp-core",15139 "sp-genesis-builder",15137 "sp-inherents",15140 "sp-inherents",15138 "sp-io",15141 "sp-io",15139 "sp-offchain",15142 "sp-offchain",Cargo.tomldiffbeforeafterboth181sp-trie = { default-features = false, version = "32.0.0" }181sp-trie = { default-features = false, version = "32.0.0" }182sp-version = { default-features = false, version = "32.0.0" }182sp-version = { default-features = false, version = "32.0.0" }183sp-weights = { default-features = false, version = "30.0.0" }183sp-weights = { default-features = false, version = "30.0.0" }184sp-genesis-builder = { default-features = false, version = "0.10.0" }184staging-parachain-info = { default-features = false, version = "0.10.0" }185staging-parachain-info = { default-features = false, version = "0.10.0" }185staging-xcm = { default-features = false, version = "10.0.0" }186staging-xcm = { default-features = false, version = "10.0.0" }186staging-xcm-builder = { default-features = false, version = "10.0.0" }187staging-xcm-builder = { default-features = false, version = "10.0.0" }217log = { version = "0.4.20", default-features = false }218log = { version = "0.4.20", default-features = false }218num_enum = { version = "0.7.0", default-features = false }219num_enum = { version = "0.7.0", default-features = false }219serde = { default-features = false, features = ['derive'], version = "1.0.188" }220serde = { default-features = false, features = ['derive'], version = "1.0.188" }221serde_json = "1"220smallvec = "1.11.1"222smallvec = "1.11.1"221223node/cli/src/chain_spec.rsdiffbeforeafterboth14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use std::collections::BTreeMap;181619use default_runtime::WASM_BINARY;17use default_runtime::WASM_BINARY;20#[cfg(all(not(feature = "unique-runtime"), not(feature = "quartz-runtime")))]18#[cfg(all(not(feature = "unique-runtime"), not(feature = "quartz-runtime")))]24use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};22use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};25use sc_service::ChainType;23use sc_service::ChainType;26use serde::{Deserialize, Serialize};24use serde::{Deserialize, Serialize};27use serde_json::map::Map;25use serde_json::{json, map::Map};28use sp_core::{sr25519, Pair, Public};26use sp_core::{sr25519, Pair, Public};29use sp_runtime::traits::{IdentifyAccount, Verify};27use sp_runtime::traits::{IdentifyAccount, Verify};30#[cfg(feature = "unique-runtime")]28#[cfg(feature = "unique-runtime")]142 AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()140 AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()143}141}144142145#[cfg(not(feature = "unique-runtime"))]146macro_rules! testnet_genesis {147 (148 $runtime:path,149 $root_key:expr,143pub fn test_config(chain_id: &str, relay_chain: &str) -> DefaultChainSpec {150 $initial_invulnerables:expr,151 $endowed_accounts:expr,152 $id:expr153 ) => {{154 use $runtime::*;155156 RuntimeGenesisConfig {157 system: Default::default(),144 DefaultChainSpec::builder(145 WASM_BINARY.expect("WASM binary was not build, please build it!"),158 balances: BalancesConfig {146 Extensions {159 balances: $endowed_accounts147 relay_chain: relay_chain.into(),160 .iter()161 .cloned()162 // 1e13 UNQ163 .map(|k| (k, 1 << 100))164 .collect(),148 para_id: PARA_ID,165 },149 },166 sudo: SudoConfig {150 )167 key: Some($root_key),168 },169170 vesting: VestingConfig { vesting: vec![] },151 .with_id(&format!(171 parachain_info: ParachainInfoConfig {152 "{}_{}",153 default_runtime::VERSION.spec_name,154 chain_id155 ))172 parachain_id: $id.into(),156 .with_name(&format!(157 "{}{}",173 ..Default::default()158 default_runtime::VERSION.spec_name.to_uppercase(),174 },175 collator_selection: CollatorSelectionConfig {176 invulnerables: $initial_invulnerables177 .iter()178 .cloned()159 if cfg!(feature = "unique-runtime") {160 ""161 } else {162 " by UNIQUE"163 }164 ))179 .map(|(acc, _)| acc)165 .with_properties(chain_properties())180 .collect(),166 .with_chain_type(ChainType::Development)181 },182 session: SessionConfig {183 keys: $initial_invulnerables184 .into_iter()167 .with_genesis_config_patch(genesis_patch())185 .map(|(acc, aura)| {186 (187 acc.clone(), // account id188 acc, // validator id189 SessionKeys { aura }, // session keys190 )191 })192 .collect(),168 .build()193 },194 evm: EVMConfig {195 accounts: BTreeMap::new(),196 ..Default::default()197 },198 ..Default::default()199 }200 }};169}201}202203#[cfg(feature = "unique-runtime")]204macro_rules! testnet_genesis {205 (206 $runtime:path,207 $root_key:expr,208 $initial_invulnerables:expr,209 $endowed_accounts:expr,210 $id:expr211 ) => {{212 use $runtime::*;213214 RuntimeGenesisConfig {215 system: Default::default(),216 balances: BalancesConfig {217 balances: $endowed_accounts218 .iter()219 .cloned()220 // 1e13 UNQ221 .map(|k| (k, 1 << 100))222 .collect(),223 },224 sudo: SudoConfig {225 key: Some($root_key),226 },227 vesting: VestingConfig { vesting: vec![] },228 parachain_info: ParachainInfoConfig {229 parachain_id: $id.into(),230 ..Default::default()231 },232 aura: AuraConfig {233 authorities: $initial_invulnerables234 .into_iter()235 .map(|(_, aura)| aura)236 .collect(),237 },238 evm: EVMConfig {239 accounts: BTreeMap::new(),240 ..Default::default()241 },242 ..Default::default()243 }244 }};245}246170247pub fn development_config() -> DefaultChainSpec {171fn genesis_patch() -> serde_json::Value {248 let mut properties = Map::new();249 properties.insert("tokenSymbol".into(), default_runtime::TOKEN_SYMBOL.into());172 use default_runtime::*;173250 properties.insert("tokenDecimals".into(), default_runtime::DECIMALS.into());174 let invulnerables = ["Alice", "Bob"];251 properties.insert(175252 "ss58Format".into(),253 default_runtime::SS58Prefix::get().into(),254 );255256 DefaultChainSpec::from_genesis(257 // Name258 format!(259 "{}{}",260 default_runtime::VERSION.spec_name.to_uppercase(),261 if cfg!(feature = "unique-runtime") {262 ""263 } else {264 " by UNIQUE"265 }266 )267 .as_str(),268 // ID269 format!("{}_dev", default_runtime::VERSION.spec_name).as_str(),176 #[allow(unused_mut)]270 ChainType::Local,271 move || {272 testnet_genesis!(177 let mut patch = json!({178 "parachainInfo": {273 default_runtime,179 "parachainId": PARA_ID,274 // Sudo account180 },181182 "aura": {183 "authorities": invulnerables.into_iter()275 get_account_id_from_seed::<sr25519::Public>("Alice"),184 .map(|name| get_from_seed::<AuraId>(name))276 [185 .collect::<Vec<_>>(),186 },187188 "session": {189 "keys": invulnerables.into_iter()277 (190 .map(|name| {278 get_account_id_from_seed::<sr25519::Public>("Alice"),191 let account = get_account_id_from_seed::<sr25519::Public>(name);279 get_from_seed::<AuraId>("Alice"),192 let aura = get_from_seed::<AuraId>(name);193194 (195 /* account id: */ account.clone(),196 /* validator id: */ account,197 /* session keys: */ SessionKeys { aura },198 )280 ),199 })281 (200 .collect::<Vec<_>>()201 },202203 "sudo": {282 get_account_id_from_seed::<sr25519::Public>("Bob"),204 "key": get_account_id_from_seed::<sr25519::Public>("Alice"),283 get_from_seed::<AuraId>("Bob"),284 ),285 ],205 },286 // Pre-funded accounts206207 "balances": {287 vec![208 "balances": &[288 get_account_id_from_seed::<sr25519::Public>("Alice"),209 get_account_id_from_seed::<sr25519::Public>("Alice"),289 get_account_id_from_seed::<sr25519::Public>("Bob"),210 get_account_id_from_seed::<sr25519::Public>("Bob"),290 get_account_id_from_seed::<sr25519::Public>("Charlie"),211 get_account_id_from_seed::<sr25519::Public>("Charlie"),297 get_account_id_from_seed::<sr25519::Public>("Dave//stash"),218 get_account_id_from_seed::<sr25519::Public>("Dave//stash"),298 get_account_id_from_seed::<sr25519::Public>("Eve//stash"),219 get_account_id_from_seed::<sr25519::Public>("Eve//stash"),299 get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),220 get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),300 ],221 ].into_iter()301 PARA_ID222 .map(|k| (k, /* ~1.2e+12 UNQ */ 1u128 << 100))223 .collect::<Vec<_>>(),224 },302 )225 });303 },226304 // Bootnodes227 #[cfg(feature = "unique-runtime")]305 vec![],228 {306 // Telemetry229 patch307 None,230 .as_object_mut()308 // Protocol ID231 .expect("the genesis patch is always an object; qed")309 None,232 .remove("session");310 None,233 }311 // Properties234312 Some(properties),235 patch313 // Extensions236}314 Extensions {315 relay_chain: "rococo-dev".into(),316 para_id: PARA_ID,317 },318 WASM_BINARY.expect("WASM binary was not build, please build it!"),319 )320}321237322pub fn local_testnet_config() -> DefaultChainSpec {238fn chain_properties() -> sc_chain_spec::Properties {323 let mut properties = Map::new();239 let mut properties = Map::new();324 properties.insert("tokenSymbol".into(), default_runtime::TOKEN_SYMBOL.into());240 properties.insert("tokenSymbol".into(), default_runtime::TOKEN_SYMBOL.into());325 properties.insert("tokenDecimals".into(), default_runtime::DECIMALS.into());241 properties.insert("tokenDecimals".into(), default_runtime::DECIMALS.into());328 default_runtime::SS58Prefix::get().into(),244 default_runtime::SS58Prefix::get().into(),329 );245 );330246331 DefaultChainSpec::from_genesis(332 // Name333 format!(334 "{}{}",335 default_runtime::VERSION.impl_name.to_uppercase(),336 if cfg!(feature = "unique-runtime") {337 ""338 } else {339 " by UNIQUE"340 }341 )342 .as_str(),343 // ID344 format!("{}_local", default_runtime::VERSION.spec_name).as_str(),345 ChainType::Local,346 move || {347 testnet_genesis!(348 default_runtime,349 // Sudo account350 get_account_id_from_seed::<sr25519::Public>("Alice"),351 [352 (353 get_account_id_from_seed::<sr25519::Public>("Alice"),354 get_from_seed::<AuraId>("Alice"),355 ),356 (357 get_account_id_from_seed::<sr25519::Public>("Bob"),358 get_from_seed::<AuraId>("Bob"),359 ),360 ],361 // Pre-funded accounts362 vec![363 get_account_id_from_seed::<sr25519::Public>("Alice"),364 get_account_id_from_seed::<sr25519::Public>("Bob"),365 get_account_id_from_seed::<sr25519::Public>("Charlie"),366 get_account_id_from_seed::<sr25519::Public>("Dave"),367 get_account_id_from_seed::<sr25519::Public>("Eve"),368 get_account_id_from_seed::<sr25519::Public>("Ferdie"),369 get_account_id_from_seed::<sr25519::Public>("Alice//stash"),370 get_account_id_from_seed::<sr25519::Public>("Bob//stash"),371 get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),372 get_account_id_from_seed::<sr25519::Public>("Dave//stash"),373 get_account_id_from_seed::<sr25519::Public>("Eve//stash"),374 get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),375 ],376 PARA_ID377 )378 },379 // Bootnodes380 vec![],381 // Telemetry382 None,383 // Protocol ID384 None,385 None,386 // Properties387 Some(properties),247 properties388 // Extensions389 Extensions {390 relay_chain: "westend-local".into(),391 para_id: PARA_ID,392 },393 WASM_BINARY.expect("WASM binary was not build, please build it!"),394 )395}248}396249node/cli/src/command.rsdiffbeforeafterboth50 chain_spec::{self, RuntimeIdentification, ServiceId, ServiceIdentification},50 chain_spec::{self, RuntimeIdentification, ServiceId, ServiceIdentification},51 cli::{Cli, RelayChainCli, Subcommand},51 cli::{Cli, RelayChainCli, Subcommand},52 service::{52 service::{new_partial, start_dev_node, start_node, OpalRuntimeExecutor},53 new_partial, start_dev_node, start_node, OpalRuntimeExecutor, ParachainHostFunctions,54 },55};53};5654656366fn load_spec(id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {64fn load_spec(id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {67 Ok(match id {65 Ok(match id {68 "dev" => Box::new(chain_spec::development_config()),66 "dev" => Box::new(chain_spec::test_config("dev", "rococo-dev")),69 "" | "local" => Box::new(chain_spec::local_testnet_config()),67 "" | "local" => Box::new(chain_spec::test_config("local", "westend-local")),70 path => {68 path => {71 let path = std::path::PathBuf::from(path);69 let path = std::path::PathBuf::from(path);72 #[allow(clippy::redundant_clone)]70 #[allow(clippy::redundant_clone)]352 use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};350 use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};353 use polkadot_cli::Block;351 use polkadot_cli::Block;352353 use crate::service::ParachainHostFunctions;354354355 type Header = <Block as sp_runtime::traits::Block>::Header;355 type Header = <Block as sp_runtime::traits::Block>::Header;356 type Hasher = <Header as sp_runtime::traits::Header>::Hashing;356 type Hasher = <Header as sp_runtime::traits::Header>::Hashing;403 use std::{future::Future, pin::Pin};403 use std::{future::Future, pin::Pin};404404405 use polkadot_cli::Block;405 use polkadot_cli::Block;406 use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, NativeExecutionDispatch};406 use sc_executor::NativeExecutionDispatch;407 use try_runtime_cli::block_building_info::timestamp_with_aura_info;407 use try_runtime_cli::block_building_info::timestamp_with_aura_info;408408409 let runner = cli.create_runner(cmd)?;409 let runner = cli.create_runner(cmd)?;runtime/common/runtime_apis.rsdiffbeforeafterboth43 ApplyExtrinsicResult, DispatchError, ExtrinsicInclusionMode,43 ApplyExtrinsicResult, DispatchError, ExtrinsicInclusionMode,44 };44 };45 use frame_support::{45 use frame_support::{46 genesis_builder_helper::{build_config, create_default_config},46 pallet_prelude::Weight,47 pallet_prelude::Weight,47 traits::OnFinalize,48 traits::OnFinalize,48 };49 };711 }712 }712 }713 }714715 impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {716 fn create_default_config() -> Vec<u8> {717 create_default_config::<RuntimeGenesisConfig>()718 }719720 fn build_config(config: Vec<u8>) -> sp_genesis_builder::Result {721 build_config::<RuntimeGenesisConfig>(config)722 }723 }713 }724 }714 }725 }715}726}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.tomldiffbeforeafterboth145 'sp-std/std',145 'sp-std/std',146 'sp-transaction-pool/std',146 'sp-transaction-pool/std',147 'sp-version/std',147 'sp-version/std',148 'sp-genesis-builder/std',148 'staging-parachain-info/std',149 'staging-parachain-info/std',149 'staging-xcm-builder/std',150 'staging-xcm-builder/std',150 'staging-xcm-executor/std',151 'staging-xcm-executor/std',283sp-storage = { workspace = true }284sp-storage = { workspace = true }284sp-transaction-pool = { workspace = true }285sp-transaction-pool = { workspace = true }285sp-version = { workspace = true }286sp-version = { workspace = true }287sp-genesis-builder = { workspace = true }286staging-parachain-info = { workspace = true }288staging-parachain-info = { workspace = true }287staging-xcm = { workspace = true }289staging-xcm = { workspace = true }288staging-xcm-builder = { workspace = true }290staging-xcm-builder = { workspace = true }runtime/unique/Cargo.tomldiffbeforeafterboth143 'sp-std/std',143 'sp-std/std',144 'sp-transaction-pool/std',144 'sp-transaction-pool/std',145 'sp-version/std',145 'sp-version/std',146 'sp-genesis-builder/std',146 'staging-parachain-info/std',147 'staging-parachain-info/std',147 'staging-xcm-builder/std',148 'staging-xcm-builder/std',148 'staging-xcm-executor/std',149 'staging-xcm-executor/std',287sp-storage = { workspace = true }288sp-storage = { workspace = true }288sp-transaction-pool = { workspace = true }289sp-transaction-pool = { workspace = true }289sp-version = { workspace = true }290sp-version = { workspace = true }291sp-genesis-builder = { workspace = true }290staging-parachain-info = { workspace = true }292staging-parachain-info = { workspace = true }291staging-xcm = { workspace = true }293staging-xcm = { workspace = true }292staging-xcm-builder = { workspace = true }294staging-xcm-builder = { workspace = true }