This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
GenesisBuilder
runtime API
#14131
Merged
paritytech-processbot
merged 32 commits into
master
from
mku-genesis-builder-api-proposal
Jun 26, 2023
Merged
GenesisBuilder
runtime API
#14131
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
926f828
GenesisConfigBuilder: preliminary API proposal
michalkucharczyk f5b4cbe
fmt
michalkucharczyk d24fbba
comment removed
michalkucharczyk 139341a
build_default_config removed
michalkucharczyk 587770b
Update client/genesis-builder/src/lib.rs
michalkucharczyk 78f467b
config -> gensis_config
michalkucharczyk 75c1f73
GenesisConfigBuilder: helper added
michalkucharczyk 5756776
moved to primitives
michalkucharczyk 1b3f8ab
licesne changed to apache-2.0
michalkucharczyk 0b3e084
Cargo.toml: name/path to genesis-builder updated
michalkucharczyk fcd2ee9
helper removed
michalkucharczyk bed8d05
Merge remote-tracking branch 'origin/master' into mku-genesis-builder…
michalkucharczyk 5ae93f6
sp-sd version bumped
michalkucharczyk 77c6504
Merge remote-tracking branch 'origin/master' into mku-genesis-builder…
cc91d46
sp-std bump
michalkucharczyk 679a970
naming + new function
michalkucharczyk aa1f77c
fix
michalkucharczyk 43a5d41
build_from_patch_json -> build_with_patch
michalkucharczyk 82bb745
fix
michalkucharczyk 8ca9b44
Merge remote-tracking branch 'origin/master' into mku-genesis-builder…
f9926bd
Cargo.lock updated
michalkucharczyk 706f3f2
readme: license updated
michalkucharczyk b35c443
Update primitives/genesis-builder/src/lib.rs
michalkucharczyk 14a251b
Update primitives/genesis-builder/src/lib.rs
michalkucharczyk 2435e42
Update primitives/genesis-builder/Cargo.toml
michalkucharczyk 8b62fcf
Cargo.lock updated
michalkucharczyk 2547761
removed redundant function
michalkucharczyk a1b64de
GenesisConfigBuilder API: no_defaults function added
michalkucharczyk 750ddb2
Cargo.lock updated
michalkucharczyk cfbd0d2
Merge remote-tracking branch 'origin/master' into mku-genesis-builder…
4c615f0
GenesisConfigBuilder API: patching fn removed
michalkucharczyk b02e21e
trigger CI job
michalkucharczyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[package] | ||
name = "sp-genesis-builder" | ||
version = "0.1.0" | ||
authors = ["Parity Technologies <[email protected]>"] | ||
edition = "2021" | ||
license = "Apache-2.0" | ||
homepage = "https://substrate.io" | ||
repository = "https://github.com/paritytech/substrate/" | ||
description = "Substrate GenesisConfig builder API" | ||
readme = "README.md" | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
||
[dependencies] | ||
sp-api = { version = "4.0.0-dev", default-features = false, path = "../../primitives/api" } | ||
sp-runtime = { version = "24.0.0", default-features = false, path = "../../primitives/runtime" } | ||
sp-std = { version = "8.0.0", default-features = false, path = "../../primitives/std" } | ||
serde_json = { version = "1.0.85", default-features = false, features = ["alloc"] } | ||
|
||
[features] | ||
default = [ "std" ] | ||
std = [ | ||
"sp-api/std", | ||
"sp-std/std", | ||
"serde_json/std", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Substrate genesis builder. | ||
|
||
Refer to the module doc for more details. | ||
|
||
License: Apache-2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,73 @@ | ||||||
// This file is part of Substrate. | ||||||
|
||||||
// Copyright (C) Parity Technologies (UK) Ltd. | ||||||
// SPDX-License-Identifier: Apache-2.0 | ||||||
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
// you may not use this file except in compliance with the License. | ||||||
// You may obtain a copy of the License at | ||||||
// | ||||||
// http://www.apache.org/licenses/LICENSE-2.0 | ||||||
// | ||||||
// Unless required by applicable law or agreed to in writing, software | ||||||
// distributed under the License is distributed on an "AS IS" BASIS, | ||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
// See the License for the specific language governing permissions and | ||||||
// limitations under the License. | ||||||
|
||||||
#![cfg_attr(not(feature = "std"), no_std)] | ||||||
|
||||||
//! 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 | ||||||
//! `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. | ||||||
//! | ||||||
//! 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. | ||||||
|
||||||
/// 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 | ||||||
pub trait GenesisBuilder { | ||||||
/// Get the default `GenesisConfig` 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`. | ||||||
fn get_default_as_json() -> sp_std::vec::Vec<u8>; | ||||||
|
||||||
/// Patch default `GenesisConfig` using given JSON patch and store it in the storage. | ||||||
/// | ||||||
/// 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. | ||||||
/// | ||||||
/// If the provided JSON patch is incorrect or the deserialization fails the error will be returned. | ||||||
/// Method may panic if creation of json representation of default config fails. | ||||||
/// | ||||||
/// The patching process modifies the default `GenesisConfig` 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`. | ||||||
/// 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. | ||||||
/// | ||||||
/// Please note that the patch may contain full `GenesisConfig`. | ||||||
fn build_config(patch: sp_std::vec::Vec<u8>) -> Result; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
/// Build `GenesisConfig` 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. | ||||||
/// 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. | ||||||
fn build_config_no_defaults(json: sp_std::vec::Vec<u8>) -> Result; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.