4

Some of the pallets storage migrations fail the idempotent test because in the pre_upgrade method there is an ensure! check to make sure that the current storage version is the one that applies for the migration, even if the actual on_runtime_upgrade does not fail if the storage has already been upgraded. So is it bad practice to perform this kind of ensure! checks in the pre_upgrade method? Ex. The assets pallet migration performs this type of check.

Thanks,

2 Answers 2

2

There is a new pattern where migrations do not need to check the pre- and post-version anymore. Doing this manually is error-prone, hence there is now a VersionedMigration wrapper that can be used lik:

pub type MigrationV1ToV2<T> = frame_support::migrations::VersionedMigration<
    1,
    2,
    UncheckedMigrationV1ToV2<T>,
    Pallet<T>,
    <T as frame_system::Config>::DbWeight,
>;

The actual migration is in the UncheckedMigrationToV2, which now does not need to do any version checks since the versions are passed as const generics to the wrapper. This simplifies the code and removes copy&paste overhead.

2
  • This issue typically arises when a new pallet is added to the runtime without properly setting its version. Sometimes the pallet author forgot to update the pallet version after adding a migration. Dec 19, 2023 at 4:31
  • There should also be a check in place now to prevent this when the try-runtime-cli is used. It errors and reports that some pallet version must be initialized. Dec 19, 2023 at 12:52
0

even if the actual on_runtime_upgrade does not fail if the storage has already been upgraded

But I want to ask. Why do you need this migration if you have already upgraded the storage? Simply remove this migration from your runtime Executive and the try runtime will ignore it.


I came across this issue this morning.

I think Substrate does not currently have any adaptations for the new feature of idempotency testing. (please correct me if I'm mistaken)

Here's what I did: https://github.com/darwinia-network/darwinia/pull/1321/commits/c15b4a3c0878c8930f097b7214b6e3af2e88ea83.

Simply change the ensure! to log::warn!.

3
  • The try-runtime tool runs the migration twice to check for idempotent test, the upgrade has not yet been applied on my runtime
    – Sebastian
    Nov 16, 2023 at 15:40
  • Updated my answer. Nov 17, 2023 at 8:58
  • Thanks for your answer! The issue here is that the pallets with the issue are frame pallets, which I don't want to modify, but I guess is not much of an issue as long as you know what is causing the issue
    – Sebastian
    Nov 17, 2023 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.