5

I have seen two methods of executing runtime migrations:

  1. Execute the migration code directly in the pallet's on_runtime_upgrade hook
  2. Create a struct and implement the OnRuntimeUpgrade trait. Include the struct in the last generic of the Executive struct within the runtime.

It seems that using the pallet's on_runtime_upgrade hook is disencouraged for numerous reasons, for example potentially unknown amount of block weight consumption and opaqueness (see this PR and this PR).

I have two question, but also feel free to add additional information in regards to this topic that is beyond the scope of those questions:

  1. What is the current best practice to execute migrations? What should devs put their attention towards when applying this method? Are there pitfalls?
  2. When using the second method described earlier in post (or the best practice method you provided), are overweight blocks still an issue?

2 Answers 2

6

What is the current best practice to execute migrations? What should devs put their attention towards when applying this method? Are there pitfalls?

When you are developing a Pallet for external people, aka you are not just using it in your own runtime. I would recommend to use the "external" migration, aka put it into the runtime lib.rs. This makes it for users easier discoverable that there are migrations being applied and to reason about them. For sure it requires that you mention them in the release nodes of your Pallet.

However, if you are the "only" user of your Pallet you can also go the way and putting the migration directly into the Pallet. From a technical PoV there is no difference in what you do.

When using the second method described earlier in post (or the best practice method you provided), are overweight blocks still an issue?

Where you place the runtime upgrade, doesn't change anything in regards to overweight blocks. How should it? It will execute the same code in both cases.

1
  • Can you provide an example of how to define a migration in the runtime lib.rs? Apr 5, 2022 at 9:22
0

According to the doc, OnRuntimeUpgrade trait can cover the feature of on_runtime_upgrade hook. I don't think there's too many difference between these two methods when you just do some simple migrations.

NOTE: this doesn’t include all pallet logic triggered on runtime upgrade. For instance it doesn’t include the write of the pallet version in storage. The final complete logic triggered on runtime upgrade is given by implementation of OnRuntimeUpgrade trait by Pallet.

And for overweight blocks, it's always an issue, no matter how you cause it.

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.