Skip to content

Commit

Permalink
remove deprecated type 'GenesisConfig' (paritytech#3378)
Browse files Browse the repository at this point in the history
# Description

Removed deprecated type `GenesisConfig` from the codebase.

Closes paritytech#175

# Checklist

- [x] My PR includes a detailed description as outlined in the
"Description" section above
- [x] My PR follows the [labeling requirements](CONTRIBUTING.md#Process)
of this project (at minimum one label for `T`
  required)
- [x] I have made corresponding changes to the documentation (if
applicable)

---------

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
Co-authored-by: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 5, 2024
1 parent d195199 commit 83222ff
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 31 deletions.
24 changes: 13 additions & 11 deletions substrate/client/chain-spec/src/genesis_config_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ where
.0
}

/// Returns the default `GenesisConfig` provided by the `runtime`.
/// Returns a json representation of the default `RuntimeGenesisConfig` provided by the
/// `runtime`.
///
/// Calls [`GenesisBuilder::create_default_config`](sp_genesis_builder::GenesisBuilder::create_default_config) in the `runtime`.
pub fn get_default_config(&self) -> core::result::Result<Value, String> {
Expand All @@ -94,7 +95,7 @@ where
Ok(from_slice(&default_config[..]).expect("returned value is json. qed."))
}

/// Build the given `GenesisConfig` and returns the genesis state.
/// Builds `RuntimeGenesisConfig` from given json blob and returns the genesis state.
///
/// Calls [`GenesisBuilder::build_config`](sp_genesis_builder::GenesisBuilder::build_config)
/// provided by the `runtime`.
Expand All @@ -111,25 +112,26 @@ where
Ok(ext.into_storages())
}

/// Creates the genesis state by patching the default `GenesisConfig` and applying it.
/// Creates the genesis state by patching the default `RuntimeGenesisConfig`.
///
/// This function generates the `GenesisConfig` for the runtime by applying a provided JSON
/// patch. The patch modifies the default `GenesisConfig` allowing customization of the specific
/// keys. The resulting `GenesisConfig` is then deserialized from the patched JSON
/// representation and stored in the storage.
/// This function generates the `RuntimeGenesisConfig` for the runtime by applying a provided
/// JSON patch. The patch modifies the default `RuntimeGenesisConfig` allowing customization of
/// the specific keys. The resulting `RuntimeGenesisConfig` is then deserialized from the
/// patched JSON representation and stored in the storage.
///
/// If the provided JSON patch is incorrect or the deserialization fails the error will be
/// returned.
///
/// The patching process modifies the default `GenesisConfig` according to the following rules:
/// The patching process modifies the default `RuntimeGenesisConfig` according to the following
/// rules:
/// 1. Existing keys in the default configuration will be overridden by the corresponding values
/// in the patch.
/// 2. If a key exists in the patch but not in the default configuration, it will be added to
/// the resulting `GenesisConfig`.
/// the resulting `RuntimeGenesisConfig`.
/// 3. Keys in the default configuration that have null values in the patch will be removed from
/// the resulting `GenesisConfig`. This is helpful for changing enum variant value.
/// the resulting `RuntimeGenesisConfig`. This is helpful for changing enum variant value.
///
/// Please note that the patch may contain full `GenesisConfig`.
/// Please note that the patch may contain full `RuntimeGenesisConfig`.
pub fn get_storage_for_patch(&self, patch: Value) -> core::result::Result<Storage, String> {
let mut config = self.get_default_config()?;
crate::json_patch::merge(&mut config, patch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ pub fn expand_outer_config(
#fields
}

#[cfg(any(feature = "std", test))]
#[deprecated(note = "GenesisConfig is planned to be removed in December 2023. Use `RuntimeGenesisConfig` instead.")]
pub type GenesisConfig = RuntimeGenesisConfig;

#[cfg(any(feature = "std", test))]
impl #scrate::sp_runtime::BuildStorage for RuntimeGenesisConfig {
fn assimilate_storage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ error[E0277]: the trait bound `Runtime: Config` is not satisfied
26 | System: frame_system::{Pallet, Call, Storage, Config<T>, Event<T>},
| ^^^^^^ the trait `Config` is not implemented for `Runtime`
|
note: required by a bound in `frame_system::GenesisConfig`
note: required by a bound in `GenesisConfig`
--> $WORKSPACE/substrate/frame/system/src/lib.rs
|
| pub struct GenesisConfig<T: Config> {
Expand Down
2 changes: 1 addition & 1 deletion substrate/primitives/genesis-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition.workspace = true
license = "Apache-2.0"
homepage = "https://substrate.io"
repository.workspace = true
description = "Substrate GenesisConfig builder API"
description = "Substrate RuntimeGenesisConfig builder API"
readme = "README.md"

[lints]
Expand Down
29 changes: 15 additions & 14 deletions substrate/primitives/genesis-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,37 @@

//! Substrate genesis config builder
//!
//! This Runtime API allows to construct `GenesisConfig`, in particular:
//! - serialize the runtime default `GenesisConfig` struct into json format,
//! - put the GenesisConfig struct into the storage. Internally this operation calls
//! This Runtime API allows to construct `RuntimeGenesisConfig`, in particular:
//! - serialize the runtime default `RuntimeGenesisConfig` struct into json format,
//! - put the RuntimeGenesisConfig struct into the storage. Internally this operation calls
//! `GenesisBuild::build` function for all runtime pallets, which is typically provided by
//! pallet's author.
//! - deserialize the `GenesisConfig` from given json blob and put `GenesisConfig` into the state
//! storage. Allows to build customized configuration.
//! - deserialize the `RuntimeGenesisConfig` from given json blob and put `RuntimeGenesisConfig`
//! into the state storage. Allows to build customized configuration.
//!
//! Providing externalities with empty storage and putting `GenesisConfig` into storage allows to
//! catch and build the raw storage of `GenesisConfig` which is the foundation for genesis block.
//! Providing externalities with empty storage and putting `RuntimeGenesisConfig` into storage
//! allows to catch and build the raw storage of `RuntimeGenesisConfig` which is the foundation for
//! genesis block.
/// The result type alias, used in build methods. `Err` contains formatted error message.
pub type Result = core::result::Result<(), sp_runtime::RuntimeString>;

sp_api::decl_runtime_apis! {
/// API to interact with GenesisConfig for the runtime
/// API to interact with RuntimeGenesisConfig for the runtime
pub trait GenesisBuilder {
/// Creates the default `GenesisConfig` and returns it as a JSON blob.
/// Creates the default `RuntimeGenesisConfig` and returns it as a JSON blob.
///
/// This function instantiates the default `GenesisConfig` struct for the runtime and serializes it into a JSON
/// blob. It returns a `Vec<u8>` containing the JSON representation of the default `GenesisConfig`.
/// This function instantiates the default `RuntimeGenesisConfig` struct for the runtime and serializes it into a JSON
/// blob. It returns a `Vec<u8>` containing the JSON representation of the default `RuntimeGenesisConfig`.
fn create_default_config() -> sp_std::vec::Vec<u8>;

/// Build `GenesisConfig` from a JSON blob not using any defaults and store it in the storage.
/// Build `RuntimeGenesisConfig` from a JSON blob not using any defaults and store it in the storage.
///
/// This function deserializes the full `GenesisConfig` from the given JSON blob and puts it into the storage.
/// This function deserializes the full `RuntimeGenesisConfig` from the given JSON blob and puts it into the storage.
/// If the provided JSON blob is incorrect or incomplete or the deserialization fails, an error is returned.
/// It is recommended to log any errors encountered during the process.
///
/// Please note that provided json blob must contain all `GenesisConfig` fields, no defaults will be used.
/// Please note that provided json blob must contain all `RuntimeGenesisConfig` fields, no defaults will be used.
fn build_config(json: sp_std::vec::Vec<u8>) -> Result;
}
}

0 comments on commit 83222ff

Please sign in to comment.