Skip to content
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

GenesisConfig presets for runtime #2714

Merged
merged 93 commits into from
Apr 4, 2024

Conversation

michalkucharczyk
Copy link
Contributor

@michalkucharczyk michalkucharczyk commented Dec 14, 2023

The runtime now can provide a number of predefined presets of RuntimeGenesisConfig struct. This presets are intended to be used in different deployments, e.g.: local, staging, etc, and should be included into the corresponding chain-specs.

Having GenesisConfig presets in runtime allows to fully decouple node from runtime types (the problem is described in #1984).

Summary of changes:

  • The GenesisBuilder API was adjusted to enable this functionality (and provide better naming - Adjust GenesisBuilder naming #150):

     fn preset_names() -> Vec<PresetId>;
     fn get_preset(id: Option<PresetId>) -> Option<serde_json::Value>; //`None` means default
     fn build_state(value: serde_json::Value);
     pub struct PresetId(Vec<u8>);
  • Breaking change: Old create_default_config method was removed, build_config was renamed to build_state. As a consequence a node won't be able to interact with genesis config for older runtimes. The cleanup was made for sake of API simplicity. Also IMO maintaining compatibility with old API is not so crucial.

  • Reference implementation was provided for substrate-test-runtime and rococo runtimes. For rococo new genesis_configs_presets module was added and is used in GenesisBuilder presets-related methods.

  • The chain-spec-builder util was also improved and allows to (doc):

    • list presets provided by given runtime (list-presets),
    • display preset or default config provided by the runtime (display-preset),
    • build chain-spec using named preset (create ... named-preset),
  • The ChainSpecBuilder is extended with with_genesis_config_preset_name method which allows to build chain-spec using named preset provided by the runtime. Sample usage on the node side here.

Implementation of #1984.
fixes: #150
part of: #25

@michalkucharczyk michalkucharczyk requested review from a team December 14, 2023 16:27
@michalkucharczyk
Copy link
Contributor Author

michalkucharczyk commented Dec 14, 2023

This requires #2044.

Allows some nice functionality:

  • list GenesisConfig presets provided by runtime:
    ./chain-spec-builder list-presets -r substrate_test_runtime.wasm
    Known presets are:
    [
        "foobar",
        "staging",
    ]
    
  • display the GenesisConfig preset with given name:
    ./chain-spec-builder display-preset -r substrate_test_runtime.wasm -p "staging"
    {"balances":{"balances":[["5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty",1000000000000000],["5FLSigC9HGRKVhB9FiEo4Y3koPsNmBmLJbpXg2mp1hXcS59Y",1000000000000000]]},"substrateTest":{"authorities":["5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY","5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL"]}}
    
    please note: it may contain only the keys that should be overwritten in default runtime GenesisConfig.
  • and finally, build the chain-spec using the named GenesisConfig preset:
    ./chain-spec-builder create -r substrate_test_runtime.wasm named-preset staging
    

/// The presets from the list can be queried with [`GenesisBuilder::get_preset`] method. If no named presets are
/// provided by the runtime the list is empty.
#[api_version(2)]
fn preset_names() -> sp_std::vec::Vec<sp_runtime::RuntimeString>;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bkchr I'd appreciate feedback on naming. config is not advised (see #150), so maybe preset will do the job?

I am also not sure if we need to keep create_default_config method. Maybe we can remove it?

Copy link
Member

@ggwpez ggwpez Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also not sure if we need to keep create_default_config method. Maybe we can remove it?

I am currently using that in the new chain-agnostic runtime benchmarker (#3512), how would i know what preset is the default?
RuntimeGenesisConfig does implement Default after all.

Copy link
Contributor Author

@michalkucharczyk michalkucharczyk Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_preset(None) would return default (equivalent of create_default_config)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some cleanup here.

I dropped old API and introduced new functions as I assume the node will not support old runtimes when it comes to spec generating.

@michalkucharczyk michalkucharczyk marked this pull request as draft December 15, 2023 11:55
This reverts commit 262bd70bcd73fbcb1fd5f709823f1a511a61f14e.
@michalkucharczyk michalkucharczyk deleted the mku-chain-spec-support-in-runtime branch April 4, 2024 19:01
Ank4n pushed a commit that referenced this pull request Apr 9, 2024
The runtime now can provide a number of predefined presets of
`RuntimeGenesisConfig` struct. This presets are intended to be used in
different deployments, e.g.: `local`, `staging`, etc, and should be
included into the corresponding chain-specs.

Having `GenesisConfig` presets in runtime allows to fully decouple node
from runtime types (the problem is described in #1984).

**Summary of changes:**
- The `GenesisBuilder` API was adjusted to enable this functionality
(and provide better naming - #150):
   ```rust
    fn preset_names() -> Vec<PresetId>;
fn get_preset(id: Option<PresetId>) -> Option<serde_json::Value>;
//`None` means default
    fn build_state(value: serde_json::Value);
    pub struct PresetId(Vec<u8>);
   ```

- **Breaking change**: Old `create_default_config` method was removed,
`build_config` was renamed to `build_state`. As a consequence a node
won't be able to interact with genesis config for older runtimes. The
cleanup was made for sake of API simplicity. Also IMO maintaining
compatibility with old API is not so crucial.
- Reference implementation was provided for `substrate-test-runtime` and
`rococo` runtimes. For rococo new
[`genesis_configs_presets`](https://github.com/paritytech/polkadot-sdk/blob/3b41d66b97c5ff0ec4a1989da5ffd8b9f3f588e3/polkadot/runtime/rococo/src/genesis_config_presets.rs#L530)
module was added and is used in `GenesisBuilder`
[_presets-related_](https://github.com/paritytech/polkadot-sdk/blob/3b41d66b97c5ff0ec4a1989da5ffd8b9f3f588e3/polkadot/runtime/rococo/src/lib.rs#L2462-L2485)
methods.

- The `chain-spec-builder` util was also improved and allows to
([_doc_](https://github.com/paritytech/polkadot-sdk/blob/3b41d66b97c5ff0ec4a1989da5ffd8b9f3f588e3/substrate/bin/utils/chain-spec-builder/src/lib.rs#L19)):
   - list presets provided by given runtime (`list-presets`),
- display preset or default config provided by the runtime
(`display-preset`),
   - build chain-spec using named preset (`create ... named-preset`),


- The `ChainSpecBuilder` is extended with
[`with_genesis_config_preset_name`](https://github.com/paritytech/polkadot-sdk/blob/3b41d66b97c5ff0ec4a1989da5ffd8b9f3f588e3/substrate/client/chain-spec/src/chain_spec.rs#L447)
method which allows to build chain-spec using named preset provided by
the runtime. Sample usage on the node side
[here](https://github.com/paritytech/polkadot-sdk/blob/2caffaae803e08a3d5b46c860e8016da023ff4ce/polkadot/node/service/src/chain_spec.rs#L404).

Implementation of #1984.
fixes: #150
part of: #25

---------

Co-authored-by: Sebastian Kunert <[email protected]>
Co-authored-by: Kian Paimani <[email protected]>
Co-authored-by: Oliver Tale-Yazdi <[email protected]>
dharjeezy pushed a commit to dharjeezy/polkadot-sdk that referenced this pull request Apr 9, 2024
The runtime now can provide a number of predefined presets of
`RuntimeGenesisConfig` struct. This presets are intended to be used in
different deployments, e.g.: `local`, `staging`, etc, and should be
included into the corresponding chain-specs.

Having `GenesisConfig` presets in runtime allows to fully decouple node
from runtime types (the problem is described in paritytech#1984).

**Summary of changes:**
- The `GenesisBuilder` API was adjusted to enable this functionality
(and provide better naming - paritytech#150):
   ```rust
    fn preset_names() -> Vec<PresetId>;
fn get_preset(id: Option<PresetId>) -> Option<serde_json::Value>;
//`None` means default
    fn build_state(value: serde_json::Value);
    pub struct PresetId(Vec<u8>);
   ```

- **Breaking change**: Old `create_default_config` method was removed,
`build_config` was renamed to `build_state`. As a consequence a node
won't be able to interact with genesis config for older runtimes. The
cleanup was made for sake of API simplicity. Also IMO maintaining
compatibility with old API is not so crucial.
- Reference implementation was provided for `substrate-test-runtime` and
`rococo` runtimes. For rococo new
[`genesis_configs_presets`](https://github.com/paritytech/polkadot-sdk/blob/3b41d66b97c5ff0ec4a1989da5ffd8b9f3f588e3/polkadot/runtime/rococo/src/genesis_config_presets.rs#L530)
module was added and is used in `GenesisBuilder`
[_presets-related_](https://github.com/paritytech/polkadot-sdk/blob/3b41d66b97c5ff0ec4a1989da5ffd8b9f3f588e3/polkadot/runtime/rococo/src/lib.rs#L2462-L2485)
methods.

- The `chain-spec-builder` util was also improved and allows to
([_doc_](https://github.com/paritytech/polkadot-sdk/blob/3b41d66b97c5ff0ec4a1989da5ffd8b9f3f588e3/substrate/bin/utils/chain-spec-builder/src/lib.rs#L19)):
   - list presets provided by given runtime (`list-presets`),
- display preset or default config provided by the runtime
(`display-preset`),
   - build chain-spec using named preset (`create ... named-preset`),


- The `ChainSpecBuilder` is extended with
[`with_genesis_config_preset_name`](https://github.com/paritytech/polkadot-sdk/blob/3b41d66b97c5ff0ec4a1989da5ffd8b9f3f588e3/substrate/client/chain-spec/src/chain_spec.rs#L447)
method which allows to build chain-spec using named preset provided by
the runtime. Sample usage on the node side
[here](https://github.com/paritytech/polkadot-sdk/blob/2caffaae803e08a3d5b46c860e8016da023ff4ce/polkadot/node/service/src/chain_spec.rs#L404).

Implementation of paritytech#1984.
fixes: paritytech#150
part of: paritytech#25

---------

Co-authored-by: Sebastian Kunert <[email protected]>
Co-authored-by: Kian Paimani <[email protected]>
Co-authored-by: Oliver Tale-Yazdi <[email protected]>
@Polkadot-Forum
Copy link

This pull request has been mentioned on Polkadot Forum. There might be relevant details there:

https://forum.polkadot.network/t/stabilizing-polkadot/7175/24

enddynayn added a commit to frequency-chain/frequency that referenced this pull request Aug 12, 2024
- Upgrade Polkadot-sdk 1.10.0 to 1.11.0
- Update weights to reflect the new version.

Notable Changes:
- [Apply patch `run_with_spec`](paritytech/polkadot-sdk#3512)
- [Genesis Presets](paritytech/polkadot-sdk#2714)
- [Integrate LiteP2P](paritytech/polkadot-sdk#2944)
- [Template Simplification](https://github.com/paritytech/polkadot-sdk/pull/3801/files)

For more details, please refer to:

[Release Notes](https://github.com/paritytech/polkadot-sdk/releases/tag/polkadot-v1.11.0)

issue-1957
enddynayn added a commit to frequency-chain/frequency that referenced this pull request Aug 13, 2024
- Upgrade Polkadot-sdk 1.10.0 to 1.11.0
- Update weights to reflect the new version.

Notable Changes:
- [Apply patch `run_with_spec`](paritytech/polkadot-sdk#3512)
- [Genesis Presets](paritytech/polkadot-sdk#2714)
- [Integrate LiteP2P](paritytech/polkadot-sdk#2944)
- [Template Simplification](https://github.com/paritytech/polkadot-sdk/pull/3801/files)

For more details, please refer to:

[Release Notes](https://github.com/paritytech/polkadot-sdk/releases/tag/polkadot-v1.11.0)

issue-1957
enddynayn added a commit to frequency-chain/frequency that referenced this pull request Aug 13, 2024
- Upgrade Polkadot-sdk 1.10.0 to 1.11.0
- Update weights to reflect the new version.

Notable Changes:
- [Apply patch `run_with_spec`](paritytech/polkadot-sdk#3512)
- [Genesis Presets](paritytech/polkadot-sdk#2714)
- [Integrate LiteP2P](paritytech/polkadot-sdk#2944)
- [Template Simplification](https://github.com/paritytech/polkadot-sdk/pull/3801/files)

For more details, please refer to:

[Release Notes](https://github.com/paritytech/polkadot-sdk/releases/tag/polkadot-v1.11.0)

issue-1957
enddynayn added a commit to frequency-chain/frequency that referenced this pull request Aug 13, 2024
- Upgrade Polkadot-sdk 1.10.0 to 1.11.0
- Update weights to reflect the new version.

Notable Changes:
- [Apply patch `run_with_spec`](paritytech/polkadot-sdk#3512)
- [Genesis Presets](paritytech/polkadot-sdk#2714)
- [Integrate LiteP2P](paritytech/polkadot-sdk#2944)
- [Template Simplification](https://github.com/paritytech/polkadot-sdk/pull/3801/files)

For more details, please refer to:

[Release Notes](https://github.com/paritytech/polkadot-sdk/releases/tag/polkadot-v1.11.0)

issue-1957
enddynayn added a commit to frequency-chain/frequency that referenced this pull request Aug 13, 2024
- Upgrade Polkadot-sdk 1.10.0 to 1.11.0
- Update weights to reflect the new version.

Notable Changes:
- [Apply patch
`run_with_spec`](paritytech/polkadot-sdk#3512)
- [Genesis
Presets](paritytech/polkadot-sdk#2714)
- [Integrate
LiteP2P](paritytech/polkadot-sdk#2944)
- [Template
Simplification](https://github.com/paritytech/polkadot-sdk/pull/3801/files)
- [Remove
try-runtime-cli](https://github.com/paritytech/polkadot-sdk/pull/4017/files#diff-3a3aa5e088741f8ab1ca38fbe314c7a150d18b7466426f4ad2569113017e8439)

For more details, please refer to:

[Release
Notes](https://github.com/paritytech/polkadot-sdk/releases/tag/polkadot-v1.11.0)

#1957
aramikm pushed a commit to frequency-chain/frequency that referenced this pull request Aug 15, 2024
- Upgrade Polkadot-sdk 1.10.0 to 1.11.0
- Update weights to reflect the new version.

Notable Changes:
- [Apply patch
`run_with_spec`](paritytech/polkadot-sdk#3512)
- [Genesis
Presets](paritytech/polkadot-sdk#2714)
- [Integrate
LiteP2P](paritytech/polkadot-sdk#2944)
- [Template
Simplification](https://github.com/paritytech/polkadot-sdk/pull/3801/files)
- [Remove
try-runtime-cli](https://github.com/paritytech/polkadot-sdk/pull/4017/files#diff-3a3aa5e088741f8ab1ca38fbe314c7a150d18b7466426f4ad2569113017e8439)

For more details, please refer to:

[Release
Notes](https://github.com/paritytech/polkadot-sdk/releases/tag/polkadot-v1.11.0)
rustadot pushed a commit to rustadot/recurrency that referenced this pull request Sep 5, 2024
- Upgrade Polkadot-sdk 1.10.0 to 1.11.0
- Update weights to reflect the new version.

Notable Changes:
- [Apply patch
`run_with_spec`](paritytech/polkadot-sdk#3512)
- [Genesis
Presets](paritytech/polkadot-sdk#2714)
- [Integrate
LiteP2P](paritytech/polkadot-sdk#2944)
- [Template
Simplification](https://github.com/paritytech/polkadot-sdk/pull/3801/files)
- [Remove
try-runtime-cli](https://github.com/paritytech/polkadot-sdk/pull/4017/files#diff-3a3aa5e088741f8ab1ca38fbe314c7a150d18b7466426f4ad2569113017e8439)

For more details, please refer to:

[Release
Notes](https://github.com/paritytech/polkadot-sdk/releases/tag/polkadot-v1.11.0)

#1957
AurevoirXavier added a commit to darwinia-network/darwinia that referenced this pull request Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T0-node This PR/Issue is related to the topic “node”. T4-runtime_API This PR/Issue is related to runtime APIs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Decouple node chain-specs from runtime types Adjust GenesisBuilder naming
6 participants