I need to store the chain state after some interval and start it with new genesis. How I can do that? Please read this issue for reference. Also, is there any other way to achieve this except re-genesis?
1 Answer
There are a lot of ways you can dump the existing state of your chain, and use that as the genesis state for a new chain.
Note that all state for a Substrate chain is simply a key-value pair, so by copying the keys and values into your new chain, you will basically copy the state. You should be a bit careful, things like the current block number, block hash, consensus information, and other things which you DO intend to reset should not be copied over to your new chain.
Probably the easiest tool to do this for you automatically is: https://github.com/maxsam4/fork-off-substrate
Which automates the steps of:
- grabbing all keys and values from an existing chain
- cleaning up any keys which you do not want to migrate
- placing the final key and values into a genesis json that can be used to start your new chain
You can of course write your own tool to do this quite easily.
-
thanks, After re-genesis will chain-spec file of new chain be different?– rahulCommented Feb 9, 2022 at 8:19
-
Yes, certainly the chain-spec will be different than the original chain since you will have a bunch of new storage keys inside the regenerated chain. The genesis hash of your chain will be different too, signifying you have a truly new chain.– Shawn Tabrizi ♦Commented Feb 9, 2022 at 8:21
-
thanks, can we call it hardfork? can we keep the same chain spec file ? basicaly i want to save the state and reset chain after some interval.– rahulCommented Feb 9, 2022 at 8:38
-
The chain spec is literally just a definition of the state at the beginning of your chain. I don't see how you can keep the same chain spec while also trying to change the state of your chain. These seem in conflict with one another.– Shawn Tabrizi ♦Commented Feb 9, 2022 at 8:41
-
please check out this quetion substrate.stackexchange.com/questions/117/…– rahulCommented Feb 10, 2022 at 7:46