From 50aba6b817b6c54f701db48d40063e53ad41d4bf Mon Sep 17 00:00:00 2001 From: rustlang-dev Date: Mon, 16 Sep 2024 15:14:06 +0100 Subject: [PATCH] fix genesis build. made compatible with stable0724 version. json genesis --- Cargo.lock | 2 ++ Cargo.toml | 1 + node/Cargo.toml | 1 + node/src/chain_spec.rs | 6 ++++++ node/src/command.rs | 4 +++- runtime/Cargo.toml | 1 + runtime/src/lib.rs | 18 ++++++++++++++++++ 7 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index a64a2bbe9..58f28a47f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1471,6 +1471,7 @@ dependencies = [ "sc-transaction-pool", "sc-transaction-pool-api", "serde", + "serde_json", "sp-api", "sp-block-builder", "sp-blockchain", @@ -1681,6 +1682,7 @@ dependencies = [ "sp-block-builder", "sp-consensus-babe", "sp-core", + "sp-genesis-builder", "sp-inherents", "sp-offchain", "sp-runtime", diff --git a/Cargo.toml b/Cargo.toml index b6122116c..ff5e8c76c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -159,6 +159,7 @@ substrate-test-runtime-client = { git = "https://github.com/paritytech/polkadot substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407" } generate-bags = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407" } xcm = { package = "staging-xcm", git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407" } +sp-genesis-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false } # Frontier Client fc-api = { git = "https://github.com/paritytech/frontier", rev = "80c768f688d86bfb350753f3e2aebc9d89037727" } diff --git a/node/Cargo.toml b/node/Cargo.toml index facbd5052..b7ec7fd78 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -15,6 +15,7 @@ build = "build.rs" targets = ["x86_64-unknown-linux-gnu"] [dependencies] +serde_json = { workspace = true } async-trait = { workspace = true } clap = { workspace = true } futures = { workspace = true } diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index 4afe897b8..f102fddf4 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -151,10 +151,13 @@ pub fn development_config(enable_manual_seal: Option) -> ChainSpec { SS58Prefix::get() as u64, ); + let config_json = serde_json::to_value(&rgc).expect("Could not build genesis config."); + return ChainSpec::builder(wasm_binary, None) .with_name("Development") .with_id("dev") .with_chain_type(ChainType::Development) + .with_genesis_config(config_json) .with_properties(properties()) .build(); @@ -243,10 +246,13 @@ pub fn local_testnet_config() -> ChainSpec { SS58Prefix::get() as u64, ); + let config_json = serde_json::to_value(&rgc).expect("Could not build genesis config."); + return ChainSpec::builder(wasm_binary, None) .with_name("Local Testnet") .with_id("local_testnet") .with_chain_type(ChainType::Local) + .with_genesis_config(config_json) .with_properties(properties()) .build(); diff --git a/node/src/command.rs b/node/src/command.rs index de267e592..17adfa301 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -61,7 +61,9 @@ impl SubstrateCli for Cli { let ret = match id { "dev" => { let enable_manual_seal = self.sealing.map(|_| true); - Box::new(chain_spec::development_config(enable_manual_seal)) + let x = Box::new(chain_spec::development_config(enable_manual_seal)); + // panic!("eeeeeee"); + x } "devnet" => Box::new(chain_spec::devnet_config()?), "testnet" => Box::new(chain_spec::testnet_config()?), diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index fc49cfc24..ce39bce8d 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -19,6 +19,7 @@ scale-info = { workspace = true } smallvec = "1.13.2" # Substrate +sp-genesis-builder = { workspace = true } sp-api = { workspace = true } sp-block-builder = { workspace = true } sp-consensus-babe = { workspace = true } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 9ff80df5e..ada0e9c82 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -19,6 +19,10 @@ use sp_core::{ crypto::{ByteArray, KeyTypeId}, OpaqueMetadata, H160, H256, U256, }; +use frame_support::{ + genesis_builder_helper::{build_state, get_preset}, + // traits::VariantCountOf, +}; use sp_runtime::{ generic, impl_opaque_keys, traits::{ @@ -1678,6 +1682,20 @@ impl_runtime_apis! { } } + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn build_state(config: Vec) -> sp_genesis_builder::Result { + build_state::(config) + } + + fn get_preset(id: &Option) -> Option> { + get_preset::(id, |_| None) + } + + fn preset_names() -> Vec { + vec![] + } + } + } #[cfg(test)]