forked from paritytech/polkadot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrations: prevent accidentally using unversioned migrations instead…
… of `VersionedMigration` (paritytech#3835) closes paritytech#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>
- Loading branch information
Showing
22 changed files
with
257 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# 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" |
Oops, something went wrong.