Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Contracts: Use RuntimeUpgrade hooks instead of Hooks::on_runtime_upgrade #2570

Merged
merged 11 commits into from
Jun 5, 2023

Conversation

pgherveou
Copy link
Contributor

@pgherveou pgherveou commented May 12, 2023

We are trying to upgrade contracts-rococo to the latest version, but try-runtime fails because some pallets do not export a struct that implements OnRuntimeUpgrade that we can pass to frame_executive::Executive.

This PR brings the following changes:

  • Define such missing OnRuntimeUpgrade structs for the pallets contracts-rococo depends on
  • Fixes the STORAGE_VERSION for pallets that have a STORAGE_VERSION that does not match the one set by the migration
  • Remove the on_runtime_upgrade hooks for cumulus_pallet_parachain_system, cumulus_pallet_xcmp_queue, cumulus_pallet_dmp_queue (pallets contracts-rococo depends on) and instead move these migrations to the runtime through frame_executive

Depends on paritytech/substrate#14045

@athei
Copy link
Member

athei commented May 12, 2023

The background here is that we want to upgrade contracts-rococo and we are upgrading from an older release. Apparently the hooks are no longer called (at least during try-runtime) so we need to migrate.

@pgherveou pgherveou marked this pull request as ready for review May 12, 2023 11:29
@pgherveou pgherveou added B0-silent Changes should not be mentioned in any release notes A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit labels May 12, 2023
@pgherveou
Copy link
Contributor Author

Note:
it looks like leaving the Hooks:on_runtime_upgrade
generate these warnings in try-runtime

2023-05-12 13:23:53 ⚠️ ParachainSystem declares internal migrations (which *might* execute). On-chain `StorageVersion(2)` vs current storage version `StorageVersion(2)`
2023-05-12 13:23:53 ⚠️ XcmpQueue declares internal migrations (which *might* execute). On-chain `StorageVersion(3)` vs current storage version `StorageVersion(3)`
2023-05-12 13:23:53 ⚠️ PolkadotXcm declares internal migrations (which *might* execute). On-chain `StorageVersion(1)` vs current storage version `StorageVersion(1)`
2023-05-12 13:23:53 ⚠️ DmpQueue declares internal migrations (which *might* execute). On-chain `StorageVersion(2)` vs current storage version `StorageVersion(2)`
2

Should we get rid of them in this PR?

@athei
Copy link
Member

athei commented May 12, 2023

I am not entirely sure we need some reviews here.

@bkchr
Copy link
Member

bkchr commented May 12, 2023

Note: it looks like leaving the Hooks:on_runtime_upgrade generate these warnings in try-runtime

2023-05-12 13:23:53 ⚠️ ParachainSystem declares internal migrations (which *might* execute). On-chain `StorageVersion(2)` vs current storage version `StorageVersion(2)`
2023-05-12 13:23:53 ⚠️ XcmpQueue declares internal migrations (which *might* execute). On-chain `StorageVersion(3)` vs current storage version `StorageVersion(3)`
2023-05-12 13:23:53 ⚠️ PolkadotXcm declares internal migrations (which *might* execute). On-chain `StorageVersion(1)` vs current storage version `StorageVersion(1)`
2023-05-12 13:23:53 ⚠️ DmpQueue declares internal migrations (which *might* execute). On-chain `StorageVersion(2)` vs current storage version `StorageVersion(2)`
2

Should we get rid of them in this PR?

This is being printed because the pallets declare a on runtime upgrade.

@pgherveou pgherveou requested a review from bkchr May 12, 2023 12:54
@KiChjang
Copy link
Contributor

Since we've touched the DMP pallet migration here, we may also want to include the DMP Migration struct into all of the runtimes that uses the DMP pallet, so that they get the right storage version.

@paritytech-ci paritytech-ci requested review from a team May 15, 2023 11:46
@pgherveou
Copy link
Contributor Author

@KiChjang @bkchr I should have addressed your comments

@pgherveou
Copy link
Contributor Author

@bkchr anything else blocking here? if not can you ✅ 🙏

Copy link
Member

@bkchr bkchr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we already executed the migrations for almost all chains?

Comment on lines 772 to 774
cumulus_pallet_parachain_system::migration::Migration<Runtime>,
cumulus_pallet_xcmp_queue::migration::Migration<Runtime>,
cumulus_pallet_dmp_queue::migration::Migration<Runtime>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably already have applied these migrations?

Copy link
Contributor Author

@pgherveou pgherveou May 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but isn't is good practice to keep it here for next time we update these chains?

parachain-template/runtime/src/lib.rs Outdated Show resolved Hide resolved
@paritytech-ci paritytech-ci requested review from a team May 17, 2023 11:58
@pgherveou pgherveou added the E0-runtime_migration PR introduces code that might require downstream chains to run a runtime upgrade. label May 17, 2023
@bkchr
Copy link
Member

bkchr commented May 17, 2023

Sorry for not having said this earlier, but I did not thought of this before. Basically you don't want to carry around all the migrations that were ever written. For 3 migrations it probably doesn't make such a big difference, but at some point you will see an impact on the size of the wasm file, which is bad. Because you will pay for useless code size.

So, the best would actually be to split up all the Migrations into single migrations as we do it for all the other pallets in FRAME. Sorry 🙈

@KiChjang
Copy link
Contributor

The only exception to that is the DMP one; we've touched the storage version there, so I think it's a good idea to leave it there as we did bump the storage version.

@pgherveou
Copy link
Contributor Author

gotcha, so should I undo all changes that don't touch the chain my team owns (contracts-rococo). All teams willing to upgrade their chain should just run try-runtime and fix all the errors themself, then once the upgrade is done , they can adjust the migration, to drop what's not necessary for the next upgrade.

This is what the new design unlock right? The migration code is configured by the runtime instead of the pallet and leave the responsibility to the runtime to pick and choose the migrations that are needed, using try-runtime to ensure that everything is properly configured

@pgherveou
Copy link
Contributor Author

So, the best would actually be to split up all the Migrations into single migrations as we do it for all the other pallets in FRAME. Sorry 🙈

Fyi that's what we do now in our multiblock migration framework we are shipping soon (for pallets-contract), plus as a bonus we make sure at compile time that there are no versions missing (ie if you go from 9 -> 11, we ensure that you have v9,10,11)

@bkchr
Copy link
Member

bkchr commented May 20, 2023

This is what the new design unlock right? The migration code is configured by the runtime instead of the pallet and leave the responsibility to the runtime to pick and choose the migrations that are needed, using try-runtime to ensure that everything is properly configured

Yes

@pgherveou pgherveou requested a review from bkchr May 30, 2023 08:15
@pgherveou
Copy link
Contributor Author

Sorry for not having said this earlier, but I did not thought of this before. Basically you don't want to carry around all the migrations that were ever written. For 3 migrations it probably doesn't make such a big difference, but at some point you will see an impact on the size of the wasm file, which is bad. Because you will pay for useless code size.

So, the best would actually be to split up all the Migrations into single migrations as we do it for all the other pallets in FRAME. Sorry 🙈

removed all but our stuff, anyone that runs a migration on a chain should probably run try-runtime and fixed the errors.

@pgherveou
Copy link
Contributor Author

bot merge

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit E0-runtime_migration PR introduces code that might require downstream chains to run a runtime upgrade.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants