2

The use case is that maybe the existing chain has bricked down (not producing block anymore possibly due to no block having been produced in the past epoch), or I want to copy the current production chain data to a test environment and try out storage migration.

Is it possible to to export the running chain data, import it to a new chain with the new chain resumed and run (continue producing blocks)? If yes, is there a guide on how to do it?

Thanks.

2 Answers 2

3

Substrate already has a export-state sub-command that exports the state of a running chain at a given block into a chain-spec. Then you can run a new chain, with the --chain pointing to this newly created chain-spec.

The only thing you need to be careful about, is that the authorities/validators in the chain-spec probably do not exist (i.e. there are no nodes running with those keys) and you want to remove them from the chain-spec. If you are running your new node with --dev, you want to replace all of those accounts with Alice's account (bottom drive obey lake curtain smoke basket hold race lonely fit walk//Alice, which is 15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5).

fork-of-substrate is a very useful tool that simplifies the above process.

1
  • When you say "the authorities/ validators in the chain-spec propably does not exists ". I have several questions: 1. Does it means, if I am running a a parachian collator with custom collator keys connected with a relay chain. When I apply the export-state command on my parachain binary, the chain spec, it produces will not have my original collator keys? 2. If the answer to the above question is YES, will you please tel me how to inject my collator keys in the chain specs produced by export-state, since it produces a raw chain specs. Commented Apr 16, 2023 at 20:16
2

Yes it is possible and as @kianenigma mentioned, Substrate has the export-state command to do it.

To export the chain state from a specific block number:

./target/release/parachain-template-node export-state --chain=raw-parachain-chainspec.json --base-path /tmp/parachain/alice 20 > chain-exported-20.json

In case you are running a parachain and want generate the genesis state and the WebAssembly runtime:

  1. Generate the chain genesis state, indicating the chain file created above. ./target/release/parachain-template-node export-genesis-state --chain=chain-exported-20.json > chain-exported-genesis-state-20

  2. Export the WebAssembly runtime for the chain, indicating the chain file created above.

    ./target/release/parachain-template-node export-genesis-wasm --chain=chain-exported-20.json > chain-exported-genesis-wasm-20

Now you can restart the chain specifying the new chain in the command line:

--chain chain-exported-20.json \
7
  • I have several questions: 1. Once we generate a chain_specs of a running parachain and also generate the necessary files (genesis, wasm) than we will have to re start the relay chain as well? 2. We need to De register and register the same parachain with the relacychain again? (using the new files generated) Commented Apr 13, 2023 at 17:35
  • The first question no, you don't have to and to the second one yes, you have to reregister the parachain with the new generated files
    – Alex Bean
    Commented Apr 14, 2023 at 8:10
  • Thanks for the help @Alex Bean. So, to register our parachain with the same relaychain, since the parachain was already registered with the relaychain, we first need to De-Register it. Right? Can you please guide me how to De-Register a parachain? Commented Apr 14, 2023 at 8:45
  • See this tutorial, to see how to offboard the parachain: hackmd.io/3BAy3HEzRVO2sBFnUaBVKA
    – Alex Bean
    Commented Apr 14, 2023 at 8:54
  • Thank you very much for your time and help @Alex Commented Apr 14, 2023 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.