Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

chain-spec: support for json config/patch (and GenesisBuilder API) #2936

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
e52d278
ChainSpec: code moved from pallet_system to ChainSpec
michalkucharczyk Jul 25, 2023
2241a03
Merge remote-tracking branch 'origin/master' into mku-chain-spec-supp…
Jul 25, 2023
0a216fe
Cargo.lock updated
michalkucharczyk Jul 25, 2023
3855d9a
Merge remote-tracking branch 'origin/master' into mku-chain-spec-supp…
michalkucharczyk Jul 25, 2023
3ea02db
ChainSpec: code moved from pallet_system to ChainSpec (FIX)
michalkucharczyk Jul 27, 2023
f70bc26
json_vs_legacy_tests: tests for json-based ChainSpecs added
michalkucharczyk Jul 26, 2023
49ce346
parachains/runtimes: GenesisBuilder API implemented
michalkucharczyk Jul 27, 2023
41916ff
chain-specs: RuntimeGenesisConfig removed, JSON patches added
michalkucharczyk Jul 27, 2023
82fb8b3
dead code allowed for legacy tests
michalkucharczyk Jul 27, 2023
44eff2d
Merge remote-tracking branch 'origin/master' into mku-chain-spec-supp…
Aug 1, 2023
9c32c33
Merge remote-tracking branch 'origin/master' into mku-chain-spec-supp…
michalkucharczyk Aug 1, 2023
79baf70
parachains: missing sp-genesis-builder/std added for std feature
michalkucharczyk Aug 1, 2023
1b2a67e
parachain-template: GenesisBuilder implemented + JSON patch in ChainSpec
michalkucharczyk Aug 2, 2023
544dd82
removed RuntimeGenesisConfig from ChainSpec definition
michalkucharczyk Aug 2, 2023
2b753a7
Merge remote-tracking branch 'origin/master' into mku-chain-spec-supp…
Aug 2, 2023
d2a7497
some docs for legacy tests added
michalkucharczyk Aug 3, 2023
56515c5
fmt
michalkucharczyk Aug 3, 2023
5c8631e
integration-tests: storages building migrated to GenesisConfig JSON p…
michalkucharczyk Aug 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions parachain-template/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub fn development_config() -> ChainSpec {
properties.insert("tokenDecimals".into(), 12.into());
properties.insert("ss58Format".into(), 42.into());

#[allow(deprecated)]
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved
ChainSpec::from_genesis(
// Name
"Development",
Expand Down Expand Up @@ -114,6 +115,8 @@ pub fn development_config() -> ChainSpec {
relay_chain: "rococo-local".into(), // You MUST set this to the correct network!
para_id: 1000,
},
parachain_template_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!"),
)
}

Expand All @@ -124,6 +127,7 @@ pub fn local_testnet_config() -> ChainSpec {
properties.insert("tokenDecimals".into(), 12.into());
properties.insert("ss58Format".into(), 42.into());

#[allow(deprecated)]
ChainSpec::from_genesis(
// Name
"Local Testnet",
Expand Down Expand Up @@ -176,6 +180,8 @@ pub fn local_testnet_config() -> ChainSpec {
relay_chain: "rococo-local".into(), // You MUST set this to the correct network!
para_id: 1000,
},
parachain_template_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!"),
)
}

Expand All @@ -186,12 +192,7 @@ fn testnet_genesis(
id: ParaId,
) -> parachain_template_runtime::RuntimeGenesisConfig {
parachain_template_runtime::RuntimeGenesisConfig {
system: parachain_template_runtime::SystemConfig {
code: parachain_template_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!")
.to_vec(),
..Default::default()
},
system: parachain_template_runtime::SystemConfig::default(),
balances: parachain_template_runtime::BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
},
Expand Down
139 changes: 63 additions & 76 deletions parachains/integration-tests/emulated/common/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ where
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
}

fn build_genesis_storage(builder: &dyn BuildStorage, code: &[u8]) -> Storage {
let mut storage = builder.build_storage().unwrap();
storage
.top
.insert(sp_core::storage::well_known_keys::CODE.to_vec(), code.into());
storage
}

pub mod accounts {
use super::*;
pub const ALICE: &str = "Alice";
Expand Down Expand Up @@ -153,10 +161,7 @@ pub mod polkadot {

pub fn genesis() -> Storage {
michalkucharczyk marked this conversation as resolved.
Show resolved Hide resolved
let genesis_config = polkadot_runtime::RuntimeGenesisConfig {
system: polkadot_runtime::SystemConfig {
code: polkadot_runtime::WASM_BINARY.unwrap().to_vec(),
..Default::default()
},
system: polkadot_runtime::SystemConfig::default(),
balances: polkadot_runtime::BalancesConfig {
balances: accounts::init_balances()
.iter()
Expand Down Expand Up @@ -209,7 +214,7 @@ pub mod polkadot {
..Default::default()
};

genesis_config.build_storage().unwrap()
build_genesis_storage(&genesis_config, polkadot_runtime::WASM_BINARY.unwrap())
}
}

Expand Down Expand Up @@ -252,10 +257,7 @@ pub mod westend {

pub fn genesis() -> Storage {
let genesis_config = westend_runtime::RuntimeGenesisConfig {
system: westend_runtime::SystemConfig {
code: westend_runtime::WASM_BINARY.unwrap().to_vec(),
..Default::default()
},
system: westend_runtime::SystemConfig::default(),
balances: westend_runtime::BalancesConfig {
balances: accounts::init_balances()
.iter()
Expand Down Expand Up @@ -308,7 +310,7 @@ pub mod westend {
..Default::default()
};

genesis_config.build_storage().unwrap()
build_genesis_storage(&genesis_config, westend_runtime::WASM_BINARY.unwrap())
}
}

Expand Down Expand Up @@ -351,10 +353,7 @@ pub mod kusama {

pub fn genesis() -> Storage {
let genesis_config = kusama_runtime::RuntimeGenesisConfig {
system: kusama_runtime::SystemConfig {
code: kusama_runtime::WASM_BINARY.unwrap().to_vec(),
..Default::default()
},
system: kusama_runtime::SystemConfig::default(),
balances: kusama_runtime::BalancesConfig {
balances: accounts::init_balances()
.iter()
Expand Down Expand Up @@ -406,7 +405,7 @@ pub mod kusama {
..Default::default()
};

genesis_config.build_storage().unwrap()
build_genesis_storage(&genesis_config, kusama_runtime::WASM_BINARY.unwrap())
}
}

Expand Down Expand Up @@ -449,10 +448,7 @@ pub mod rococo {

pub fn genesis() -> Storage {
let genesis_config = rococo_runtime::RuntimeGenesisConfig {
system: rococo_runtime::SystemConfig {
code: rococo_runtime::WASM_BINARY.unwrap().to_vec(),
..Default::default()
},
system: rococo_runtime::SystemConfig::default(),
balances: rococo_runtime::BalancesConfig {
balances: accounts::init_balances()
.iter()
Expand Down Expand Up @@ -496,7 +492,7 @@ pub mod rococo {
..Default::default()
};

genesis_config.build_storage().unwrap()
build_genesis_storage(&genesis_config, rococo_runtime::WASM_BINARY.unwrap())
}
}

Expand All @@ -508,12 +504,7 @@ pub mod asset_hub_polkadot {

pub fn genesis() -> Storage {
let genesis_config = asset_hub_polkadot_runtime::RuntimeGenesisConfig {
system: asset_hub_polkadot_runtime::SystemConfig {
code: asset_hub_polkadot_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!")
.to_vec(),
..Default::default()
},
system: asset_hub_polkadot_runtime::SystemConfig::default(),
balances: asset_hub_polkadot_runtime::BalancesConfig {
balances: accounts::init_balances()
.iter()
Expand Down Expand Up @@ -553,7 +544,11 @@ pub mod asset_hub_polkadot {
..Default::default()
};

genesis_config.build_storage().unwrap()
build_genesis_storage(
&genesis_config,
asset_hub_polkadot_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!"),
)
}
}

Expand All @@ -565,12 +560,7 @@ pub mod asset_hub_westend {

pub fn genesis() -> Storage {
let genesis_config = asset_hub_westend_runtime::RuntimeGenesisConfig {
system: asset_hub_westend_runtime::SystemConfig {
code: asset_hub_westend_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!")
.to_vec(),
..Default::default()
},
system: asset_hub_westend_runtime::SystemConfig::default(),
balances: asset_hub_westend_runtime::BalancesConfig {
balances: accounts::init_balances()
.iter()
Expand Down Expand Up @@ -610,7 +600,11 @@ pub mod asset_hub_westend {
..Default::default()
};

genesis_config.build_storage().unwrap()
build_genesis_storage(
&genesis_config,
asset_hub_westend_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!"),
)
}
}

Expand All @@ -622,12 +616,7 @@ pub mod asset_hub_kusama {

pub fn genesis() -> Storage {
let genesis_config = asset_hub_kusama_runtime::RuntimeGenesisConfig {
system: asset_hub_kusama_runtime::SystemConfig {
code: asset_hub_kusama_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!")
.to_vec(),
..Default::default()
},
system: asset_hub_kusama_runtime::SystemConfig::default(),
balances: asset_hub_kusama_runtime::BalancesConfig {
balances: accounts::init_balances()
.iter()
Expand Down Expand Up @@ -667,7 +656,11 @@ pub mod asset_hub_kusama {
..Default::default()
};

genesis_config.build_storage().unwrap()
build_genesis_storage(
&genesis_config,
asset_hub_kusama_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!"),
)
}
}

Expand All @@ -679,12 +672,7 @@ pub mod penpal {

pub fn genesis(para_id: u32) -> Storage {
let genesis_config = penpal_runtime::RuntimeGenesisConfig {
system: penpal_runtime::SystemConfig {
code: penpal_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!")
.to_vec(),
..Default::default()
},
system: penpal_runtime::SystemConfig::default(),
balances: penpal_runtime::BalancesConfig {
balances: accounts::init_balances()
.iter()
Expand Down Expand Up @@ -727,7 +715,10 @@ pub mod penpal {
..Default::default()
};

genesis_config.build_storage().unwrap()
build_genesis_storage(
&genesis_config,
penpal_runtime::WASM_BINARY.expect("WASM binary was not build, please build it!"),
)
}
}

Expand All @@ -739,12 +730,7 @@ pub mod collectives {

pub fn genesis() -> Storage {
let genesis_config = collectives_polkadot_runtime::RuntimeGenesisConfig {
system: collectives_polkadot_runtime::SystemConfig {
code: collectives_polkadot_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!")
.to_vec(),
..Default::default()
},
system: collectives_polkadot_runtime::SystemConfig::default(),
balances: collectives_polkadot_runtime::BalancesConfig {
balances: accounts::init_balances()
.iter()
Expand Down Expand Up @@ -784,7 +770,11 @@ pub mod collectives {
..Default::default()
};

genesis_config.build_storage().unwrap()
build_genesis_storage(
&genesis_config,
collectives_polkadot_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!"),
)
}
}

Expand All @@ -796,12 +786,7 @@ pub mod bridge_hub_kusama {

pub fn genesis() -> Storage {
let genesis_config = bridge_hub_kusama_runtime::RuntimeGenesisConfig {
system: bridge_hub_kusama_runtime::SystemConfig {
code: bridge_hub_kusama_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!")
.to_vec(),
..Default::default()
},
system: bridge_hub_kusama_runtime::SystemConfig::default(),
balances: bridge_hub_kusama_runtime::BalancesConfig {
balances: accounts::init_balances()
.iter()
Expand Down Expand Up @@ -841,7 +826,11 @@ pub mod bridge_hub_kusama {
..Default::default()
};

genesis_config.build_storage().unwrap()
build_genesis_storage(
&genesis_config,
bridge_hub_kusama_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!"),
)
}
}

Expand All @@ -853,12 +842,7 @@ pub mod bridge_hub_polkadot {

pub fn genesis() -> Storage {
let genesis_config = bridge_hub_polkadot_runtime::RuntimeGenesisConfig {
system: bridge_hub_polkadot_runtime::SystemConfig {
code: bridge_hub_polkadot_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!")
.to_vec(),
..Default::default()
},
system: bridge_hub_polkadot_runtime::SystemConfig::default(),
balances: bridge_hub_polkadot_runtime::BalancesConfig {
balances: accounts::init_balances()
.iter()
Expand Down Expand Up @@ -898,7 +882,11 @@ pub mod bridge_hub_polkadot {
..Default::default()
};

genesis_config.build_storage().unwrap()
build_genesis_storage(
&genesis_config,
bridge_hub_polkadot_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!"),
)
}
}

Expand All @@ -910,12 +898,7 @@ pub mod bridge_hub_rococo {

pub fn genesis() -> Storage {
let genesis_config = bridge_hub_rococo_runtime::RuntimeGenesisConfig {
system: bridge_hub_rococo_runtime::SystemConfig {
code: bridge_hub_rococo_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!")
.to_vec(),
..Default::default()
},
system: bridge_hub_rococo_runtime::SystemConfig::default(),
balances: bridge_hub_rococo_runtime::BalancesConfig {
balances: accounts::init_balances()
.iter()
Expand Down Expand Up @@ -971,6 +954,10 @@ pub mod bridge_hub_rococo {
..Default::default()
};

genesis_config.build_storage().unwrap()
build_genesis_storage(
&genesis_config,
bridge_hub_rococo_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!"),
)
}
}
1 change: 1 addition & 0 deletions parachains/runtimes/assets/asset-hub-kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ sp-api = { git = "https://github.com/paritytech/substrate", default-features = f
sp-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-core = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-genesis-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-inherents = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-offchain = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" }
Expand Down
11 changes: 11 additions & 0 deletions parachains/runtimes/assets/asset-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ use constants::{currency::*, fee::WeightToFee};
use frame_support::{
construct_runtime,
dispatch::DispatchClass,
genesis_builder_helper::{build_config, create_default_config},
parameter_types,
traits::{
AsEnsureOriginWithArg, ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse,
Expand Down Expand Up @@ -1229,6 +1230,16 @@ impl_runtime_apis! {
Ok(batches)
}
}

impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
Copy link
Contributor Author

@michalkucharczyk michalkucharczyk Aug 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need disable-genesis-builder feature here?
Refer to this

fn create_default_config() -> Vec<u8> {
create_default_config::<RuntimeGenesisConfig>()
}

fn build_config(config: Vec<u8>) -> sp_genesis_builder::Result {
build_config::<RuntimeGenesisConfig>(config)
}
}
}

struct CheckInherents;
Expand Down
Loading
Loading