-
Notifications
You must be signed in to change notification settings - Fork 1.1k
chain-spec: getting ready for native-runtime-free world
#1256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
1446ea3
037c5ae
3eb5768
a2d2152
8e4c7ca
b2bdc55
8f46827
bf9bbaf
21a4fa0
141f7cc
e499a0b
65ae3a2
125de59
a247f58
3de595a
6bfc04d
fb433fb
a9ab958
c121b80
cb71977
86bacb1
dcfd2f7
569cdaa
72d0c5a
153ff6e
dc458e9
224b0d3
a784a72
678cbfa
a370177
76c5574
d18a393
88df79c
4b09014
4f6157e
4694e89
5f953e5
4a23546
bcce94e
ef77c7a
21d73f5
7468963
1459e59
1163c53
fbc2b96
55d9585
992af8f
d663916
8018987
ec400d8
3038707
e56f1bc
c038d26
37a9701
fb9b3d5
ca85b96
6f8e125
0687f81
a654716
6da1de6
987a8d1
d4010cd
83a3f73
074e36a
b23e073
afa6ede
6f6596e
56ec31c
3ee6fc9
aee8fd8
5a7e2c1
b40484a
3c62e17
7a86589
f57a227
ce4a355
ddaac44
454b9e5
271a642
8f83e65
03fe6d2
7c821ca
5754843
6473b91
b9e850d
6a7c717
4d71564
dec047a
5f7781f
ea2e1f1
69f0aeb
8564093
aedaf4f
8c7d66f
69442e3
f1ad7ba
3d8347e
ceb6b16
87e60ac
88369c6
fc3cef2
c3b99aa
2702ef6
91bc747
60dae23
ffc779e
8d29feb
14d8e04
54e6ba8
2e2c749
c82e634
1ca2238
ac41e78
f687591
e6b9866
98a53d0
8dc196e
ed7b137
30ffe7c
253aabe
af239cb
cbb493e
e94b476
c41092a
8e85faf
00ca55d
670e837
393ce9d
3df6b4d
cf70573
1393fcb
03ae1bc
f4d3f32
45a03d6
09862df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,14 +18,17 @@ | |
|
|
||
| #![allow(rustdoc::private_intra_doc_links)] | ||
|
|
||
| //! # Substrate chain configurations. | ||
| //! This crate includes structs and utilities for defining configuration files (known as chain | ||
| //! specification) for both runtime and node. | ||
| //! | ||
| //! The chain specification is a JSON file that describes the properties and initial state of the | ||
| //! chain. | ||
| //! # Intro: chain specification. | ||
michalkucharczyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! | ||
| //! In summary, though not restirced to, the main role of the chain spec is to provide a list of | ||
| //! The chain specification is a collection of information that describes the properties and an | ||
| //! initial state of a chain. Typically user interacts with the JSON representation of the chain | ||
michalkucharczyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! spec. Internally the chain spec is embodied by [`GenericChainSpec`] struct, specific | ||
| //! properties can be accessed using the [`ChainSpec`] trait. | ||
michalkucharczyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! | ||
| //! In summary, though not restirced to, the primary role of the chain spec is to provide a list of | ||
michalkucharczyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! well-known boot nodes for the blockchain network and the means for initializing the genesis | ||
| //! storage. This initialization is necessary for creating a genesis block upon which subsequent | ||
| //! blocks are built. When the node is launched for the first time, it reads the chain spec, | ||
|
|
@@ -108,51 +111,98 @@ | |
| //! </tbody> | ||
| //! </table> | ||
| //! | ||
| //! # Initial runtime state aka genesis storage | ||
| //! # `genesis`: initial runtime state | ||
michalkucharczyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! | ||
| //! All nodes in the network must build subsequent blocks upon exactly the same genesis block. | ||
| //! | ||
| //! The information configured in the `genesis` section of a chain specification is used to build | ||
| //! the genesis storage, which is essential for creating the genesis block, since the block header | ||
| //! includes the storage root hash. | ||
| //! | ||
| //! The `genesis` key of the chain specification definition describes the | ||
| //! initial state of the runtime. For example it may contain: | ||
michalkucharczyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! - initial list of funded accounts, | ||
| //! - the sudo key, | ||
| //! - the administrative account that controls the sudo key | ||
| //! - initial authorities set for consensus, etc. | ||
| //! | ||
| //! The compiled WASM blob of the runtime code is stored in the state (and therefore on the chain). | ||
| //! As a result, the initial runtime must also be provided within the chain specification (under the | ||
| //! `code` field). | ||
michalkucharczyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! | ||
| //! The genesis state can be represented in the formats described by [`chain_spec::Genesis<G>`] | ||
|
||
| //! enum. It includes: | ||
| //! <table> | ||
| //! <thead> | ||
| //! <tr> | ||
| //! <th>Format</th> | ||
| //! <th>Description</th> | ||
| //! </tr> | ||
| //! </thead> | ||
| //! <tbody> | ||
| //! <tr> | ||
| //! <td><code>runtime</code></td> | ||
| //! <td>A JSON object that provides an explicit and comprehensive representation of the | ||
| //! <code>RuntimeGenesisConfig</code> struct. This struct is declared by the runtime and is opaque | ||
| //! to the node.</td> | ||
| //! </tr> | ||
| //! <tr> | ||
| //! <td><code>runtimeGenesisConfig</code></td> | ||
| //! <td>An alias for the <code>runtime</code> format.</td> | ||
| //! </tr> | ||
| //! <tr> | ||
| //! <td><code>runtimeGenesisConfigPatch</code></td> | ||
| //! <td>A JSON object that offers a partial representation of the | ||
| //! <code>RuntimeGenesisConfig</code> | ||
| //! provided by the runtime. It contains a patch, which is essentially a list of keys to customize | ||
| //! in the default runtime's <code>RuntimeGenesisConfig</code>. It is opaque to the node.</td> | ||
| //! </tr> | ||
| //! <tr> | ||
| //! <td><code>raw</code></td> | ||
| //! <td>A JSON object with two fields: <code>top</code> and <code>children_default</code> Each | ||
michalkucharczyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! field is a map of <code>key => value</code> pairs representing entries in a genesis storage | ||
| //! trie.</td> </tr> | ||
| //! <tr> | ||
| //! <td><code>stateRootHash</code></td> | ||
| //! <td>A single hex-encoded hash representing the genesis hash. The hash type | ||
| //! depends on the hash used by the chain.</td> | ||
| //! </tr> | ||
| //! </tbody> | ||
| //! </table> | ||
| //! | ||
| //! - `runtime` - a JSON object that is an explicit and comprehensive representation of the | ||
| //! `RuntimeGenesisConfig` struct. The `RuntimeGenesisConfig` struct is declared by the runtime | ||
| //! and opaque to the node. | ||
| //! - `runtimeGenesisConfig` - an alias for `runtime`, | ||
| //! - `runtimeGenesisConfigPatch` - a JSON object that is partial representation of | ||
| //! `RuntimeGenesisConfig` provided by runtime. It contains a patch which is essentially a list of | ||
| //! keys that are to be customized in the default runtime's `RuntimeGenesisConfig`. It is opaque | ||
| //! to the node. | ||
| //! - `raw` is a JSON object with two fields `top` and `children_default`. Each of these fields is a | ||
| //! map of `key => value`. These key/value pairs represent the entries in a genesis storage trie. | ||
| //! - `stateRootHash` is a single hex encoded hash that represents the genesis hash. The hash type | ||
| //! depends on the hash used by the chain. | ||
| //! | ||
| //! For production or long living chain specification `raw` format is recommended. | ||
| //! For production or long lasting chain specification `raw` format is recommended. | ||
michalkucharczyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! | ||
| //! JSON examples in the [following section](#json-chain-specification-example) illustrate the `raw` | ||
| //! and `runtimeGenesisConfigPatch` genesis fields. | ||
| //! | ||
| //! # From initial state to raw genesis. | ||
michalkucharczyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! | ||
| //! To generate a raw genesis storage from the JSON representation of the runtime genesis config the | ||
michalkucharczyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! node needs to interact with the runtime. | ||
| //! | ||
| //! This interaction involves passing the runtime genesis config JSON blob to the runtime using the | ||
| //! [`sp_genesis_builder::GenesisBuilder::build_config`] function. It is a crucial step for | ||
| //! computing the storage root hash, which is a key component in determining the genesis hash. | ||
| //! [`sp_genesis_builder::GenesisBuilder::build_config`] function. During this operation runtime | ||
michalkucharczyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! converts the JSON representation of genesis config into [`sp_io::storage`] items. It is a | ||
michalkucharczyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! crucial step for computing the storage root hash, which is a key component in determining the | ||
| //! genesis hash. | ||
| //! | ||
| //! Consequently, the runtime must support the [`sp_genesis_builder::GenesisBuilder`] API to | ||
| //! utilize either [`chain_spec::Genesis<G>::RuntimeGenesisConfigPatch`] or | ||
| //! [`chain_spec::Genesis<G>::RuntimeGenesisConfig`] formats. | ||
| //! utilize either [`RuntimeGenesisConfigPatch`][patch] or [`RuntimeGenesisConfig`][full] formats. | ||
| //! | ||
| //! [patch]: chain_spec::Genesis<G>::RuntimeGenesisConfigPatch | ||
| //! [full]: chain_spec::Genesis<G>::RuntimeGenesisConfig | ||
| //! | ||
| //! This whole process is encapsulated within the implementation of the [`BuildStorage`] trait, | ||
| //! which can be accessed through the [`ChainSpec::as_storage_builder`] method. | ||
| //! This entire process is encapsulated within the implementation of the [`BuildStorage`] trait, | ||
| //! which can be accessed through the [`ChainSpec::as_storage_builder`] method. There is an | ||
| //! intermediate internal helper that facilitates this interaction, | ||
| //! [`GenesisConfigBuilderRuntimeCaller`], which serves as a straightforward wrapper for | ||
| //! [`sc_executor::WasmExecutor`]. | ||
| //! | ||
| //! In case of `raw` genesis state the node does not interact with the runtime regarding the | ||
| //! computation of initial state. | ||
| //! | ||
| //! The plain and `raw` chain specification JSON blobs can be found in | ||
| //! [JSON examples](#json-chain-specification-example) section. | ||
| //! | ||
| //! # Optional code mapping | ||
michalkucharczyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! Optional map of `block_number` to `wasm_code`. | ||
| //! | ||
|
|
@@ -165,24 +215,24 @@ | |
| //! there is no other way around it and only patch the problematic bug, the rest should be done | ||
michalkucharczyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! with a on-chain runtime upgrade. | ||
michalkucharczyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! | ||
| //! The [`ChainSpec`] trait represents the API to access values defined in JSON chain specification. | ||
| //! | ||
| //! # Building a chain specification. | ||
michalkucharczyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! The [`ChainSpecBuilder`] shall be used to create an instance of chain specification. Its API | ||
michalkucharczyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! allows to configure all fields of the chain spec. For details on how to generate a JSON | ||
| //! representation of chain specification refer to [`ChainSpec::as_json`]. | ||
| //! allows to configure all fields of the chain spec. To generate a JSON representation of chain | ||
michalkucharczyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! specification, use [`ChainSpec::as_json`]. | ||
| //! | ||
| //! The sample code to generate a chain spec is as follows: | ||
| #![doc = docify::embed!("src/chain_spec.rs", build_chain_spec_with_patch_works)] | ||
| //! # JSON chain specification example | ||
| //! The following are the `raw` and plain versions of the chain specification JSON files, resulting | ||
| //! from executing above example: | ||
| //! ``` | ||
| //! The following are the plain and `raw` ersions of the chain specification JSON files, resulting | ||
michalkucharczyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! from executing of the above [example](#building-a-chain-specification): | ||
| //! ```ignore | ||
| #![doc = include_str!("../res/substrate_test_runtime_from_patch.json")] | ||
| //! ``` | ||
| //! ``` | ||
| //! ```ignore | ||
| #![doc = include_str!("../res/substrate_test_runtime_from_patch_raw.json")] | ||
| //! ``` | ||
| //! The [`ChainSpec`] trait represents the API to access values defined in JSON chain specification. | ||
michalkucharczyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! | ||
| //! # Custom chain spec extensions | ||
michalkucharczyk marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //! Basic chain spec type containing all required parameters is [`GenericChainSpec`]. It can be | ||
| //! extended with additional options that contain configuration specific to your chain. Usually the | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.