How to use try runtime in when upgrading a chain/parachin to latest substrate release?
If there are any upstream migrations, you should use try-runtime on-runtime-upgrade subcommand to test that the storage migration is successful before you apply the changes in a production environment.
What is the best practice regarding try-runtime, what errors and warnings should one look out for in the output.
In regards to on-runtime-upgrade
you want to make sure that the storage migration was applied correctly on your storage by using pre- and post-upgrade checks. When running try-runtime on-runtime-upgrade you also want to confirm that the runtime spec version was bumped. In regards to a pallet storage migration you may need to bump the storage_version for your pallet.
When running try-runtime on-runtime-upgrade, ideally you have an RPC node dedicated for this with flags set to enable large request/response size so that you can test off of live chain state:
./node-try-runtime \
try-runtime \
--runtime runtime-try-runtime.wasm \
-lruntime=debug \
on-runtime-upgrade \
live --uri ws://try-runtime-prod-chain-rpc-node:9921
All your migrations should pass with green. Look at the output of the try-runtime logs, it will tell you. You may also want to look at the consumed weight for your migrations, wildly off consumed weight may indicate a flaw in your storage migration's logic. Never take the upstream migrations blindly, always review the code and see if it fits your chain.
A good pipeline is to test with try-runtime-upgrade, then test on a live test network for some time by enacting the upgrade there, then if all is good --> production.
Ideally, you have a try-runtime CI workflow set with your repo for testing releases as well as try-runtime bot that you can kick off manually.
The on-runtime-upgrade subcommand also has an optional try-state hook which can be used to check the pallet's state (sanity check)
Of course, this is only the icing on the cake, try-runtime include a few other subcommands which can be useful for testing such as:
execute-block Executes the given block against some state
offchain-worker Executes *the offchain worker hooks* of a given block against some state
follow-chain Follow the given chain's finalized blocks and apply all of its extrinsics
For example, say you're testing a complex storage migration that your team wrote and it touches several aspects of your pallets storage, you may want to on-runtime-upgrade
to ensure your storage migration executed as expected and for added peace-of-mind you may also want to test that the chain continues to produce blocks as expected using follow-chain
.
try-runtime can also be used for testing other scenarios, not only storage migrations. For example, perhaps your team discovered a bug in your code that happened in production at block X. Your team then writes code to fix the bug and they could use the try-runtime execute-block subcommand to execute that code against block X to make sure the bug has been fixed before rolling out the fix to production.
Resource
Related