-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for starting this!
Looks good, I saw the example in https://github.com/paritytech/polkadot/compare/liam-versioned-runtime-upgrade-example type VersionCheckedMigrateToV6 = frame_support::migrations::VersionedRuntimeUpgrade<
V5ToV6,
parachains_configuration::migration::v6::VersionedUncheckedMigrateToV6<Runtime>,
Configuration,
RocksDbWeight,
>, |
Thanks @ggwpez and @thiolliere for your comments. I've addressed them:
and also written some tests. Ready to review again when you have some time. |
Question: after merging, should we apply this to applicable |
The main reason I suggested removing Moreover, we have always considered a new hook for when a pallet is added to the runtime. All in all
can be solved in various other ways. -- From a DevEx perspective, I still want to suggest finding a way to not do this, as having both the onchain version and the fixed pallet version is not optimal. All in all, I do agree that this is a clear improvement over the existing mechanism. My comment is that the existing mechanism is itself somewhat clunky/broken and can be reconsidered. |
/// that the upgrade was a noop and should probably be removed. | ||
/// | ||
/// Example: | ||
/// ```ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
possibly not to difficult to make this not be ignore
and actually compile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you thinking I'd use the dummy pallet and upgrades from my test file? I'd rather not use a migration from a real pallet since it creates a dependency that could break. I'm also curious what the benefit/s are of making the comment compile
I think we still use the |
Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com>
Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com>
Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com>
Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com>
Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com>
…rsioned-runtime-upgrade
…rsioned-runtime-upgrade
bot merge |
* VersionedRuntimeUpgrade * only require one version and add a pre-upgrade check * add docs * improve warning log * improve comments * fix log * use associated constants * allow passing from and to versions * test versioned_runtime_upgrade * fix typo * improve docs * docs * docs * remove event from dummy pallet * remove pre_upgrade current storage version check * derive_impl * skip pre/post checks if the actual migration will not run * improve variable naming * docs * fix post_upgrade 'should run' logic * fix comments * pre and post hook tests * feature gate try-runtime stuff * remove deprecated macro * Update frame/support/src/migrations.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * decode_all * make experimental * use rust generics * add info log when running * simplify tests * improve log * improve log * cleaner pre_upgrade encoding * Update frame/support/src/migrations.rs Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com> * Update frame/support/src/migrations.rs Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com> * Update frame/support/src/migrations.rs Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com> * Update frame/support/src/migrations.rs Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com> * Update frame/support/src/migrations.rs Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com> * VersionedPostUpgradeData enum * move versioned runtime upgrade tests to test/tests * fix rust doc * clarify comment --------- Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: Gonçalo Pestana <g6pestana@gmail.com>
Closes #13107
Description
Make it easier to write versioned runtime upgrades.
VersionedRuntimeUpgrade allows developers to write migrations without worrying about checking and setting storage versions. Instead, the developer wraps their migration in this struct which takes care of version handling using best practices.
It takes 5 type parameters:
From
: The version being upgraded fromTo
: The version being upgraded toInner
: An implementation ofOnRuntimeUpgrade
Pallet
: The Pallet being upgradedWeight
: The runtime's RuntimeDbWeight implementationWhen a VersionedRuntimeUpgrades
on_runtime_upgrade
method is called, the on-chain version of the pallet is compared toFrom
. If they match,Inner::on_runtime_upgrade
is called and the pallets on-chain version is set toTo
. Otherwise, a warning is logged notifying the developer that the upgrade was a noop and should probably be removed.Example
Example using this for a migration in the Polkadot repo: https://github.com/paritytech/polkadot/compare/liam-versioned-runtime-upgrade-example
Decision not to remove
#[pallet::storage_version]
The possibility of removing
#[pallet::storage_version]
leaving only an on-chain version has been discussed. Although this would be nice, I think it is necessary to keep so that we may correctly set the initial on-chain version of a pallet when it is first initialized.See paritytech/polkadot-sdk#109 for more which I'm planning to work on soon, which appears to require
#[pallet::storage_version]
.Decision to use
From
andTo
rather than justVersion
(From
)See #14311 (comment)
TODOs
experimental
tests [FRAME/Meta/PM] "experimental"FRAME
features #14345 (comment)