Skip to content

Commit

Permalink
genesis-builder: implemented for all runtimes (paritytech#1492)
Browse files Browse the repository at this point in the history
This PR implements [`GenesisBuilder`
API](https://github.com/paritytech/polkadot-sdk/blob/a414ea7515c9cdc81f1d12410e646afc148250e8/substrate/primitives/genesis-builder/src/lib.rs#L38)
for all the runtimes in polkadot repo.

Step towards: paritytech#25

---------

Co-authored-by: ordian <[email protected]>
  • Loading branch information
michalkucharczyk and ordian authored Sep 27, 2023
1 parent 0f4d3bd commit 7f9c125
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 22 deletions.
2 changes: 2 additions & 0 deletions substrate/bin/node-template/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ sp-std = { path = "../../../primitives/std", default-features = false}
sp-storage = { path = "../../../primitives/storage", default-features = false}
sp-transaction-pool = { path = "../../../primitives/transaction-pool", default-features = false}
sp-version = { path = "../../../primitives/version", default-features = false}
sp-genesis-builder = { version = "0.1.0-dev", default-features = false, path = "../../../primitives/genesis-builder" }

# Used for the node template's RPCs
frame-system-rpc-runtime-api = { path = "../../../frame/system/rpc/runtime-api", default-features = false}
Expand Down Expand Up @@ -79,6 +80,7 @@ std = [
"sp-consensus-aura/std",
"sp-consensus-grandpa/std",
"sp-core/std",
"sp-genesis-builder/std",
"sp-inherents/std",
"sp-offchain/std",
"sp-runtime/std",
Expand Down
11 changes: 11 additions & 0 deletions substrate/bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use sp_std::prelude::*;
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;

use frame_support::genesis_builder_helper::{build_config, create_default_config};
// A few exports that help ease life for downstream crates.
pub use frame_support::{
construct_runtime, parameter_types,
Expand Down Expand Up @@ -571,4 +572,14 @@ impl_runtime_apis! {
Executive::try_execute_block(block, state_root_check, signature_check, select).expect("execute-block failed")
}
}

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)
}
}
}
2 changes: 2 additions & 0 deletions substrate/bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ sp-authority-discovery = { path = "../../../primitives/authority-discovery", def
sp-consensus-babe = { path = "../../../primitives/consensus/babe", default-features = false}
sp-consensus-grandpa = { path = "../../../primitives/consensus/grandpa", default-features = false}
sp-block-builder = { path = "../../../primitives/block-builder", default-features = false}
sp-genesis-builder = { version = "0.1.0-dev", default-features = false, path = "../../../primitives/genesis-builder" }
sp-inherents = { path = "../../../primitives/inherents", default-features = false}
node-primitives = { path = "../primitives", default-features = false}
sp-offchain = { path = "../../../primitives/offchain", default-features = false}
Expand Down Expand Up @@ -231,6 +232,7 @@ std = [
"sp-consensus-babe/std",
"sp-consensus-grandpa/std",
"sp-core/std",
"sp-genesis-builder/std",
"sp-inherents/std",
"sp-io/std",
"sp-offchain/std",
Expand Down
11 changes: 11 additions & 0 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use frame_election_provider_support::{
use frame_support::{
construct_runtime,
dispatch::DispatchClass,
genesis_builder_helper::{build_config, create_default_config},
instances::{Instance1, Instance2},
ord_parameter_types,
pallet_prelude::Get,
Expand Down Expand Up @@ -2750,6 +2751,16 @@ impl_runtime_apis! {
Ok(batches)
}
}

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)
}
}
}

#[cfg(test)]
Expand Down
3 changes: 0 additions & 3 deletions substrate/test-utils/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,3 @@ std = [
]
# Special feature to disable logging
disable-logging = [ "sp-api/disable-logging" ]

#Enabling this flag will disable GenesisBuilder API implementation in runtime.
disable-genesis-builder = []
15 changes: 0 additions & 15 deletions substrate/test-utils/runtime/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

const BUILD_NO_GENESIS_BUILDER_SUPPORT_ENV: &str = "BUILD_NO_GENESIS_BUILDER_SUPPORT";

fn main() {
#[cfg(feature = "std")]
{
Expand All @@ -31,19 +29,6 @@ fn main() {
.build();
}

#[cfg(feature = "std")]
if std::env::var(BUILD_NO_GENESIS_BUILDER_SUPPORT_ENV).is_ok() {
substrate_wasm_builder::WasmBuilder::new()
.with_current_project()
.export_heap_base()
.append_to_rust_flags("-Clink-arg=-zstack-size=1048576")
.set_file_name("wasm_binary_no_genesis_builder")
.import_memory()
.enable_feature("disable-genesis-builder")
.build();
}
println!("cargo:rerun-if-env-changed={}", BUILD_NO_GENESIS_BUILDER_SUPPORT_ENV);

#[cfg(feature = "std")]
{
substrate_wasm_builder::WasmBuilder::new()
Expand Down
5 changes: 1 addition & 4 deletions substrate/test-utils/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ pub mod genesismap;
pub mod substrate_test_pallet;

use codec::{Decode, Encode};
#[cfg(not(feature = "disable-genesis-builder"))]
use frame_support::genesis_builder_helper::{build_config, create_default_config};
use frame_support::{
construct_runtime,
dispatch::DispatchClass,
genesis_builder_helper::{build_config, create_default_config},
parameter_types,
traits::{ConstU32, ConstU64},
weights::{
Expand Down Expand Up @@ -722,7 +721,6 @@ impl_runtime_apis! {
}
}

#[cfg(not(feature = "disable-genesis-builder"))]
impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
fn create_default_config() -> Vec<u8> {
create_default_config::<RuntimeGenesisConfig>()
Expand Down Expand Up @@ -1203,7 +1201,6 @@ mod tests {
})
}

#[cfg(not(feature = "disable-genesis-builder"))]
mod genesis_builder_tests {
use super::*;
use crate::genesismap::GenesisStorageBuilder;
Expand Down

0 comments on commit 7f9c125

Please sign in to comment.