Files
pezkuwi-subxt/prdoc/pr_3835.prdoc
T
Dastan e54279699b migrations: prevent accidentally using unversioned migrations instead of VersionedMigration (#3835)
closes #1324 

#### Problem
Currently, it is possible to accidentally use inner unversioned
migration instead of `VersionedMigration` since both implement
`OnRuntimeUpgrade`.

#### Solution

With this change, we make it clear that value of `Inner` is not intended
to be used directly. It is achieved by bounding `Inner` to new trait
`UncheckedOnRuntimeUpgrade`, which has the same interface (except
`unchecked_` prefix) as `OnRuntimeUpgrade`.

#### `try-runtime` functions

Since developers can implement `try-runtime` for `Inner` value in
`VersionedMigration` and have custom logic for it, I added the same
`try-runtime` functions to `UncheckedOnRuntimeUpgrade`. I looked for a
ways to not duplicate functions, but couldn't find anything that doesn't
significantly change the codebase. So I would appreciate If you have any
suggestions to improve this

cc @liamaharon @xlc 

polkadot address: 16FqwPZ8GRC5U5D4Fu7W33nA55ZXzXGWHwmbnE1eT6pxuqcT

---------

Co-authored-by: Liam Aharon <liam.aharon@hotmail.com>
2024-04-02 13:43:09 +00:00

55 lines
2.0 KiB
Plaintext

# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
title: "migrations: prevent accidentally using inner unversioned migration instead of `VersionedMigration`"
doc:
- audience: Runtime Dev
description: |
Currently, it is possible to accidentally use inner unversioned migration instead of `VersionedMigration`
since both implement `OnRuntimeUpgrade`. With this change, we make it clear that `Inner` is not intended
to be used directly. It is achieved by bounding `Inner` to new trait `UncheckedOnRuntimeUpgrade`, which
has the same interface as `OnRuntimeUpgrade`, but can not be used directly for runtime upgrade migrations.
This change will break all existing migrations passed to `VersionedMigration`. Developers should simply change
those migrations to implement `UncheckedOnRuntimeUpgrade` instead of `OnRuntimeUpgrade`.
Example:
```
--- a/path/to/migration.rs
+++ b/path/to/migration.rs
@@ -1,7 +1,7 @@
-impl<T: Config> OnRuntimeUpgrade for MigrateVNToVM<T> {
+impl<T: Config> UncheckedOnRuntimeUpgrade for MigrateVNToVM<T> {
fn on_runtime_upgrade() -> Weight {
// Migration logic here
// Adjust the migration logic if necessary to align with the expectations
// of new `UncheckedOnRuntimeUpgrade` trait.
0
}
}
```
crates:
- name: "pallet-example-single-block-migrations"
bump: "major"
- name: "pallet-xcm"
bump: "major"
- name: "pallet-grandpa"
bump: "major"
- name: "pallet-identity"
bump: "major"
- name: "pallet-nomination-pools"
bump: "major"
- name: "pallet-society"
bump: "major"
- name: "frame-support"
bump: "major"
- name: "pallet-uniques"
bump: "major"
- name: "polkadot-runtime-parachains"
bump: "major"
- name: "polkadot-runtime-common"
bump: "major"