chain-spec: getting ready for native-runtime-free world#1256
Conversation
- adds support for:
- JSON based GenesisConfig (patch/full-config) to ChainSpec allowing
interaction with runtime GenesisBuilder API.
- interacting with arbitrary runtime wasm blob to chain-spec-builder command line util,
- GenesisBuilder API in kitchensink runtime
- removes `code` from system_pallet
- adds `code` to the ChainSpec
- deprecates ChainSpec::from_genesis, but also changes the signature of
this method extending it with code argument. ChainSpec::builder()
should be used instead.
- implements GenesisBuilder API for node-template-runtime and kitchensink-runtime.
Squash commit of work made in: paritytech/substrate#14562
- all references to `RuntimeGenesisConfig` in node/service are removed,
- `RococoGenesisExt` is removed. It was the hack to allow overwriting
`EpochDurationInBlocks`. Removal of `RococGenesisExt` prevents from
manipulating the state to change the runtime constants, what allows to
keep metadata const.
- all `(kusama|polkadot|versi|rococo|wococo)_(staging|dev)_genesis_config`
functions now return the JSON patch for default runtime `GenesisConfig`,
- `ChainSpecBuilder` is used, ChainSpec::from_genesis is removed,
- rococo-runtime changes:
-- Explicit building of fast-runtime version of rococo-runtime is no longer done.
-- Environment variables which control the time::EpochDurationInBlocks value were added:
`ROCOCO_FAST_RUNTIME` - enables the fast runtime version of
runtime with default value of EpochDurationInBlocks set to 10. Value of
env does not matter.
`ROCOCO_EPOCH_DURATION` - enables the fast runtime version with
provided value of EpochDurationInBlocks (epoch duration will be set to
the value of env).
Examples:
- to build runtime for `versi_staging_testnet_config which had
EpochDurationInBlocks set to 100:
```
ROCOCO_EPOCH_DURATION=100 cargo build -p rococo
```
- to build runtime for `versi_staging_testnet_config which had
EpochDurationInBlocks set to 100:
```
ROCOCO_EPOCH_DURATION=100 cargo build -p rococo-runtime
```
- to build runtime for `wococo_development`
```
ROCOCO_EPOCH_DURATION=10 cargo build -p rococo-runtime
or
ROCOCO_FAST_RUNTIME=1 cargo build -p rococo-runtime
```
- ChainSpec: tests against legacy added
- integration-tests: storages building migrated to GenesisConfig JSON patches
- parachain-template: GenesisBuilder implemented + JSON patch in ChainSpec
- parachains/runtimes: GenesisBuilder API implemented
- chain-specs: RuntimeGenesisConfig removed, JSON patches added
- json_vs_legacy_tests: tests for json-based ChainSpecs added
Copy of current chain_spec files (using deprecated from_genesis) was
created in order to test json-patching vs old from_genesis version.
- chain-specs: code moved from pallet_system to ChainSpec
chain-spec: getting ready for _native-runtime-free_ worldchain-spec: getting ready for native-runtime-free world
|
Continuation of work done in: paritytech/substrate#14562 |
|
bot fmt |
…ort-ready-for-non-native
This reverts commit a247f58.
| json!({ | ||
| "balances": BalancesConfig { balances }, | ||
| "sudo": SudoConfig { key: Some(AccountKeyring::Alice.to_account_id()) }, | ||
| }) |
There was a problem hiding this comment.
I no longer see a way to do this in more type-safe way without json!, which is very annoying. Even though generated GenesisConfig is JSON-serializable, so I constructed it explicitly and then tried to serialize, serialization failed for me with this non-descriptive error:
Error("number out of range", line: 0, column: 0)
And it comes from pallet-balances 😞
Any recommendations?
There was a problem hiding this comment.
Well, json! also doesn't work with u128::MAX / 2 balance, while ChainSpec::from_genesis worked. Created an issue about this: #2963
There was a problem hiding this comment.
Can you try arbitrary_precision feature on serde_json crate in minimal runtime? (just trying out of my head, remember that I had similar issue).
There was a problem hiding this comment.
Please see the proposal of fix:
https://github.com/michalkucharczyk/polkadot-sdk/tree/mku-u128-balances-fix (michalkucharczyk@879917e)
./minimal-node build-spec --chain dev works fine (also --raw):
...
[
"5Fxune7f71ZbpP2FoY3mhYcmM596Erhv1gRue4nsPwkxMR4n",
170141183460469231731687303715884105727
],
[
"5CUjxa4wVKMj3FqKdqAUf7zcEMr4MYAjXeWmUf44B41neLmJ",
170141183460469231731687303715884105727
]
...
There was a problem hiding this comment.
If that works - great (it is a bit difficult to test due to a series of downstream patches on top of Substrate). Why did it work with ChainSpec::from_genesis though? It should have unified features of serde_json if one of the dependencies enabled arbitrary_precision.
There was a problem hiding this comment.
I think no deps are enabling this feature in substrate. It is runtime serializing big numbers, so it must be enabled there. Just guessing - maybe we should add it to frame somewhere.
ChainSpec::from_genesis assumed that all rust types (including RuntimeGenesisConfig) were available on native side of node (which is no longer a case as we want to get rid of this dep). So there was no json boundary to cross.
There was a problem hiding this comment.
(it is a bit difficult to test due to a series of downstream patches on top of Substrate
This single line in runtime/Cargo.tom should do the job:
serde_json = { version = "1.0.108", default-features = false, features = ["alloc", "arbitrary_precision"] }
…on` (#2987) [`arbitrary_precision`](https://github.com/serde-rs/json/blob/6d44b9fac9269b4decf76acac5d68e8ec9d10c58/Cargo.toml#L69-L75) feature allows to (de-)serialize big numbers w/o error. For some details refer also to #1256 (comment) fixes: #2963
That was introduced in paritytech/polkadot-sdk#1256. Without this fix updating the chain_spec pod in versi fails with: ``` + BOOTNODES='"bootNodes": ["/dns/versi-tick-501-alice-node-0/tcp/30334/p2p/12D3KooWBsK6fux5wY2QqmNhE5HwfRVZiWFTL1T51XeBuE8op49t","/dns/versi-tick-501-bob-node-0/tcp/30334/p2p/12D3KooWMD4MDy2Vks4ErjTDaN6xb1P1Q5i5XTv5S3p1sj81tKzd"],'+ sed 's;"bootNodes.*;"bootNodes": ["/dns/versi-tick-501-alice-node-0/tcp/30334/p2p/12D3KooWBsK6fux5wY2QqmNhE5HwfRVZiWFTL1T51XeBuE8op49t","/dns/versi-tick-501-bob-node-0/tcp/30334/p2p/12D3KooWMD4MDy2Vks4ErjTDaN6xb1P1Q5i5XTv5S3p1sj81tKzd"],;' -i /dir/tick-dev-plain-01.json+ /usr/local/bin/polkadot-parachain build-spec --chain /dir/tick-dev-plain-01.json --rawError: Service(Other("Error parsing spec file: expected value at line 40 column 5")) ``` Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
* Setup deps * Remove Koi from account migration test * paritytech/polkadot-sdk#1495 * Bump * paritytech/polkadot-sdk#1524 * !! paritytech/polkadot-sdk#1363 * paritytech/polkadot-sdk#1492 * paritytech/polkadot-sdk#1911 * paritytech/polkadot-sdk#1900 Signed-off-by: Xavier Lau <xavier@inv.cafe> * paritytech/polkadot-sdk#1661 * paritytech/polkadot-sdk#2144 * paritytech/polkadot-sdk#2048 * paritytech/polkadot-sdk#1672 * paritytech/polkadot-sdk#2303 * paritytech/polkadot-sdk#1256 * Remove identity and vesting * Fixes * paritytech/polkadot-sdk#2657 * paritytech/polkadot-sdk#1313 * paritytech/polkadot-sdk#2331 * paritytech/polkadot-sdk#2409 part.1 * paritytech/polkadot-sdk#2767 * paritytech/polkadot-sdk#2521 Signed-off-by: Xavier Lau <xavier@inv.cafe> * paritytech/polkadot-sdk#1222 * paritytech/polkadot-sdk#1234 part.1 * Satisfy compiler * XCM V4 part.1 * paritytech/polkadot-sdk#1246 * Remove pallet-democracy part.1 * paritytech/polkadot-sdk#2142 * paritytech/polkadot-sdk#2428 * paritytech/polkadot-sdk#3228 * XCM V4 part.2 * Bump * Build all runtimes * Build node * Remove pallet-democracy Signed-off-by: Xavier Lau <xavier@inv.cafe> * Format * Fix pallet tests * Fix precompile tests * Format * Fixes * Async, remove council, common pallet config * Fix `ethtx-forward` test case (#1519) * Fix ethtx-forward tests * Format * Fix following the review * Fixes * Fixes * Use default impl * Benchmark helper * Bench part.1 * Bench part.2 * Bench part.3 * Fix all tests * Typo * Feat * Fix EVM tracing build * Reuse upstream `proof_size_base_cost()` (#1521) * Format issue * Fixes * Fix CI --------- Signed-off-by: Xavier Lau <xavier@inv.cafe> Co-authored-by: Bear Wang <boundless.forest@outlook.com>
* Setup deps * Remove Koi from account migration test * paritytech/polkadot-sdk#1495 * Bump * paritytech/polkadot-sdk#1524 * !! paritytech/polkadot-sdk#1363 * paritytech/polkadot-sdk#1492 * paritytech/polkadot-sdk#1911 * paritytech/polkadot-sdk#1900 Signed-off-by: Xavier Lau <xavier@inv.cafe> * paritytech/polkadot-sdk#1661 * paritytech/polkadot-sdk#2144 * paritytech/polkadot-sdk#2048 * paritytech/polkadot-sdk#1672 * paritytech/polkadot-sdk#2303 * paritytech/polkadot-sdk#1256 * Remove identity and vesting * Fixes * paritytech/polkadot-sdk#2657 * paritytech/polkadot-sdk#1313 * paritytech/polkadot-sdk#2331 * paritytech/polkadot-sdk#2409 part.1 * paritytech/polkadot-sdk#2767 * paritytech/polkadot-sdk#2521 Signed-off-by: Xavier Lau <xavier@inv.cafe> * paritytech/polkadot-sdk#1222 * paritytech/polkadot-sdk#1234 part.1 * Satisfy compiler * XCM V4 part.1 * paritytech/polkadot-sdk#1246 * Remove pallet-democracy part.1 * paritytech/polkadot-sdk#2142 * paritytech/polkadot-sdk#2428 * paritytech/polkadot-sdk#3228 * XCM V4 part.2 * Bump * Build all runtimes * Build node * Remove pallet-democracy Signed-off-by: Xavier Lau <xavier@inv.cafe> * Format * Fix pallet tests * Fix precompile tests * Format * Fixes * Async, remove council, common pallet config * Fix `ethtx-forward` test case (#1519) * Fix ethtx-forward tests * Format * Fix following the review * Fixes * Fixes * Use default impl * Benchmark helper * Bench part.1 * Bench part.2 * Bench part.3 * Fix all tests * Typo * Feat * Fix EVM tracing build * Reuse upstream `proof_size_base_cost()` (#1521) * Format issue * Fixes * Fix CI --------- Signed-off-by: Xavier Lau <xavier@inv.cafe> Co-authored-by: Bear Wang <boundless.forest@outlook.com>
* Setup deps * Remove Koi from account migration test * paritytech/polkadot-sdk#1495 * Bump * paritytech/polkadot-sdk#1524 * !! paritytech/polkadot-sdk#1363 * paritytech/polkadot-sdk#1492 * paritytech/polkadot-sdk#1911 * paritytech/polkadot-sdk#1900 Signed-off-by: Xavier Lau <xavier@inv.cafe> * paritytech/polkadot-sdk#1661 * paritytech/polkadot-sdk#2144 * paritytech/polkadot-sdk#2048 * paritytech/polkadot-sdk#1672 * paritytech/polkadot-sdk#2303 * paritytech/polkadot-sdk#1256 * Remove identity and vesting * Fixes * paritytech/polkadot-sdk#2657 * paritytech/polkadot-sdk#1313 * paritytech/polkadot-sdk#2331 * paritytech/polkadot-sdk#2409 part.1 * paritytech/polkadot-sdk#2767 * paritytech/polkadot-sdk#2521 Signed-off-by: Xavier Lau <xavier@inv.cafe> * paritytech/polkadot-sdk#1222 * paritytech/polkadot-sdk#1234 part.1 * Satisfy compiler * XCM V4 part.1 * paritytech/polkadot-sdk#1246 * Remove pallet-democracy part.1 * paritytech/polkadot-sdk#2142 * paritytech/polkadot-sdk#2428 * paritytech/polkadot-sdk#3228 * XCM V4 part.2 * Bump * Build all runtimes * Build node * Remove pallet-democracy Signed-off-by: Xavier Lau <xavier@inv.cafe> * Format * Fix pallet tests * Fix precompile tests * Format * Fixes * Async, remove council, common pallet config * Fix `ethtx-forward` test case (#1519) * Fix ethtx-forward tests * Format * Fix following the review * Fixes * Fixes * Use default impl * Benchmark helper * Bench part.1 * Bench part.2 * Bench part.3 * Fix all tests * Typo * Feat * Fix EVM tracing build * Reuse upstream `proof_size_base_cost()` (#1521) * Format issue * Fixes * Fix CI --------- Signed-off-by: Xavier Lau <xavier@inv.cafe> Co-authored-by: Bear Wang <boundless.forest@outlook.com>
* Setup deps * Remove Koi from account migration test * paritytech/polkadot-sdk#1495 * Bump * paritytech/polkadot-sdk#1524 * !! paritytech/polkadot-sdk#1363 * paritytech/polkadot-sdk#1492 * paritytech/polkadot-sdk#1911 * paritytech/polkadot-sdk#1900 Signed-off-by: Xavier Lau <xavier@inv.cafe> * paritytech/polkadot-sdk#1661 * paritytech/polkadot-sdk#2144 * paritytech/polkadot-sdk#2048 * paritytech/polkadot-sdk#1672 * paritytech/polkadot-sdk#2303 * paritytech/polkadot-sdk#1256 * Remove identity and vesting * Fixes * paritytech/polkadot-sdk#2657 * paritytech/polkadot-sdk#1313 * paritytech/polkadot-sdk#2331 * paritytech/polkadot-sdk#2409 part.1 * paritytech/polkadot-sdk#2767 * paritytech/polkadot-sdk#2521 Signed-off-by: Xavier Lau <xavier@inv.cafe> * paritytech/polkadot-sdk#1222 * paritytech/polkadot-sdk#1234 part.1 * Satisfy compiler * XCM V4 part.1 * paritytech/polkadot-sdk#1246 * Remove pallet-democracy part.1 * paritytech/polkadot-sdk#2142 * paritytech/polkadot-sdk#2428 * paritytech/polkadot-sdk#3228 * XCM V4 part.2 * Bump * Build all runtimes * Build node * Remove pallet-democracy Signed-off-by: Xavier Lau <xavier@inv.cafe> * Format * Fix pallet tests * Fix precompile tests * Format * Fixes * Async, remove council, common pallet config * Fix `ethtx-forward` test case (#1519) * Fix ethtx-forward tests * Format * Fix following the review * Fixes * Fixes * Use default impl * Benchmark helper * Bench part.1 * Bench part.2 * Bench part.3 * Fix all tests * Typo * Feat * Fix EVM tracing build * Reuse upstream `proof_size_base_cost()` (#1521) * Format issue * Fixes * Fix CI --------- Signed-off-by: Xavier Lau <xavier@inv.cafe> Co-authored-by: Bear Wang <boundless.forest@outlook.com>
This PR prepares chains specs for native-runtime-free world.
This PR has following changes:
substrate:GenesisConfigtoChainSpecallowing interaction with runtimeGenesisBuilderAPI.chain-spec-buildercommand line util,codefromsystem_palletcodeto theChainSpecChainSpec::from_genesis, but also changes the signature of this method extending it withcodeargument.ChainSpec::builder()should be used instead.polkadot:RuntimeGenesisConfiginnode/serviceare removed,(kusama|polkadot|versi|rococo|wococo)_(staging|dev)_genesis_configfunctions now return the JSON patch for default runtimeGenesisConfig,ChainSpecBuilderis used,ChainSpec::from_genesisis removed,cumulus:ChainSpecBuilderis used,ChainSpec::from_genesisis removed,RuntimeGenesisConfig structin all chain specs.Note on testing: all old chain-spec generating functions were copied to legacy test mods in order to make sure that raw storage generated by new (json) and old (runtime genesis config struct) functions is exactly the same.
codemoved intoChainSpecIn raw formats the code is one of the key-pair entry (
0x3a636f6465)Example:
{ "name": "TestName", "id": "test_id", "chainType": "Local", ... "genesis": { "raw": { "top": { "0x3a636f6465": "0x010101" }, "childrenDefault": {} } }, }In plain chain specs using the patch or full JSON config, the code hex encoded blob shall be provided under the
genesis::runtimeGenesis::codepath, example:{ "name": "TestName", "id": "test_id", "chainType": "Local", "bootNodes": [], "telemetryEndpoints": null, "protocolId": null, "properties": null, "codeSubstitutes": {}, "genesis": { "runtimeGenesis": { "patch": { "babe": { "epochConfig": { "allowed_slots": "PrimaryAndSecondaryPlainSlots", "c": [ 7, 10 ] } }, "substrateTest": { "authorities": [ "5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL", "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" ] } }, "code": "0x0..." } } }JSON based GenesisConfig in
ChainSpec:Patch
The
ChainSpeccan now be built using genesis config JSON patch (which contains some key-value pairs meant to override runtime's genesis config default values). This can be achieved withwith_genesis_patchmethod of the builder:Resulting
ChainSpecinstance can be converted to raw version of chain spec JSON file. This was not changed and can be done withchain_spec.as_json(true)method. Sample output is here. The runtime'sGenesisBuilder::build_configAPI is called during this conversion.The
ChainSpecinstance can also be written to chain spec JSON file in human readable form. The resulting chain spec file will contain the genesis config patch (partial genesis config). Sample output is hereFull Config
It is also possible to build
ChainSpecusing full genesis config JSON (containing all the genesis config key-value pairs). No defaults will be used in this approach. The sample code is as follows:Again, resulting
ChainSpecinstance can be converted to the raw version of chain spec JSON file (which involves callingGenesisBuilder::build_configruntime method) .It can be also stored in human readable version, sample output here.
chain-spec-builderutilNew commands allowing to interact with arbitrary WASM runtime blob were added. Use cases are as follows:
Get default config from runtime
Queries the default genesis config from the provided
runtime.wasmand uses it in the chain spec. Can also store runtime's default genesis config in given file (-d):Note:
GenesisBuilder::create_default_configruntime function is called.Generate raw storage chain spec using genesis config patch
Patches the runtime's default genesis config with provided
patch.jsonand generates raw storage (-s) version of chain spec:Note:
GenesisBuilder::build_configruntime function is called.Generate raw storage chain spec using full genesis config
Build the chain spec using provided full genesis config json file. No defaults will be used:
Note:
GenesisBuilder::build_configruntime function is called.Generate human readable chain spec using genesis config patch
Note: No runtime API is called.
Generate human readable chain spec using full genesis config
Note: No runtime API is called.
Some extra utils:
verify: allows to verify if human readable chain spec is valid (precisely: all required fields in genesis config are initialized),edit, allows to:Some open questions/issues:
naming.with_no_genesis_defaults+ in chain spec json keys:JsonPatch/JsonFull,.GenesisSourcesource for patch and full configNew/Generatecommands in `chain-spec-builder? (IMO we can remove them).Step towards: #25