Skip to content

Substrate Chain State Generate Tools

HackFisher edited this page Jun 21, 2021 · 2 revisions

Within Substrate framework, there are several builtin chain state generate tools, and also there are some other tools to fork off and customize the chain state.

  1. Build Spec cli command, build the genesis state using runtime GenesisConfig

build-spec --raw and build-spec --dev --raw

https://github.com/paritytech/substrate/blob/d03a91a181d0b22d00a6b9ba2a8007dc254779e3/client/cli/src/commands/build_spec_cmd.rs#L31

  1. Export existing chain state using export-state command.

https://github.com/paritytech/substrate/blob/d03a91a181d0b22d00a6b9ba2a8007dc254779e3/client/cli/src/commands/export_state_cmd.rs#L31

  1. Build Parachain Genesis Header and Validation Code, Here the state root in Genesis Header might require the genesis state(storages), and if we want to do parachain hot-connect solution, we will probably need to export chain state from the solo chain, fork off by replacing some storage keys, and use the spec generated. Refer a. Cumulus b. Parachain Spec Raw Res c. Command for parachain build spec, genesis header and validation code
target/release/crab-redirect-collator build-spec --disable-default-bootnode --raw --chain crab-redirect-genesis > res/crab-redirect.json
target/release/crab-redirect-collator export-genesis-wasm -r > res/crab-redirect.wasm
target/release/crab-redirect-collator export-genesis-state > res/crab-redirect.hex
  1. Use the fork-off-substrate tool (https://github.com/maxsam4/fork-off-substrate) to create a new chain spec from your state and use that. Refer: a. HardSpoon Discussions b. Currently the chunk fetch have a bug and does not seem to improve node side performance(current implementation still iterate over all storage keys?), only network bandwith for each rpc call can be split into chunks if enable it.

  2. Test runtime upgrade using try-runtime

https://github.com/paritytech/substrate/tree/master/utils/frame/try-runtime