Test runtime upgrades
The following guide shows how to test runtime upgrades.
A key feature of Substrate is its support for forkless upgrades. Testing the blockchain runtime upgrade process is essential to ensure a seamless network transition without disruptions.
To simulate and validate the process of upgrading a blockchain's runtime, the on-runtime-upgrade executes the OnRuntimeUpgrade hooks of a runtime against the state of a live blockchain or a snapshot.
Hence, there are two subcommands live and snap to specify the source of the runtime state.
Usage: pop test on-runtime-upgrade [OPTIONS] [COMMAND]
Commands:
live A live chain
snap A state snapshot
help Print this message or the help of the given subcommand(s)Test migrations
By running the command pop test on-runtime-upgrade, you can test the Runtime Upgrades and Storage Migrations in a simulated environment.
β Pop CLI : Testing migrations
β
β Do you want to specify which runtime to run the migration on?
β If not provided, use the code of the remote node, or a snapshot.
β β Yes / β No
βBefore running the migration, you will be prompted to confirm if you want to specify which runtime to run the migration on:
If you choose to specify, you will be prompted to select the runtime to run the migration on. The feature requires your runtime to be built with
--try-runtimefeature.
Pop CLI will automatically locate the runtime binary based on the provided
--profile. Pop CLI will automatically build the runtime if not found.
If not, the migration will be run against the code that's currently running on the remote node or the one stored inside the snapshot file you provide.
Snapshot can be created with
pop test create-snapshot.
Test migrations against a live chain
You'll be asked to enter the URI of a live node and optionally provide a block hash. If a block hash is given, the state will be executed at the specified block hash on the provided network.
To run the migrations on top of live state manually:
Note: The specified runtime and the remote node's runtime must have the same name and version. If not, the migration will fail. You can add the flag --disable-spec-version-check and --disable-spec-name-check to bypass the checks.
After that, you can select the upgrade checks to perform:
Test migrations with a snapshot file
A second approach to test migrations is with a snapshot file. First, you need to create a snapshot file of a live network. You can do this by running the following command:
The interactive interface to prompts for the live URI and the path of the snapshot file:
To skip the interactive prompt, use the --uri and --path flags:
If the path of snapshot file is not provided, the default name following a format <spec-name>-<spec-version>@<block-hash>.snap will be used. Note that the remote node must be built with --try-runtime feature enabled.
Assume there is a snapshot file created with the name example.snap:
To run migrations with a snapshot manually:
Learning Resources
π§βπ« To learn about Polkadot in general, Polkadot.network website is a good starting point.
π§βπ§ For technical introduction of the
try-runtime, here.Learn more about Runtime Upgrades and Storage Migrations.
Need help?
Ask on Polkadot Stack Exchange (tag it pop) or drop by our Telegram. We're here to help!
Last updated
Was this helpful?