Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MBM try-runtime support #4251

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

MBM try-runtime support #4251

wants to merge 2 commits into from

Conversation

liamaharon
Copy link
Member

@liamaharon liamaharon commented Apr 23, 2024

  • Replaces UpgradeCheckSelect enum with a struct implementing the builder pattern, TryOnRuntimeUpgradeOpts. This allows much easier control over which checks to run in try_on_runtime_upgrade
  • Adds try-runtime gated methods pre_upgrade and post_upgrade on SteppedMigration
  • Adds try-runtime gated methods nth_pre_upgrade and nth_post_upgrade on SteppedMigrations
  • Adds try-runtime gated method try_mbms to MultiStepMigrator, which execs the pre_upgrade, steps, and post_upgrades of all MBMs.
  • Modifies Executive try_on_runtime_upgrade to call try_mbms if the option is selected.

TODO

  • Test this thoroughly with try-runtime-cli, and release a pre-release version that uses the new TryOnRuntimeUpgradeOpts
  • PRDoc with detailed code migration instructions and example
  • Fix up warnings

@liamaharon liamaharon added the T1-FRAME This PR/Issue is related to core FRAME, the framework. label Apr 23, 2024
@liamaharon liamaharon requested a review from ggwpez April 23, 2024 07:47
@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: cargo-clippy
Logs: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/6018412

@@ -460,6 +460,11 @@ impl MultiStepMigrator for MockedModeGetter {
fn step() -> Weight {
Weight::zero()
}

#[cfg(feature = "try-runtime")]
fn try_mbms() -> Result<(), sp_runtime::TryRuntimeError> {
Copy link
Member

Choose a reason for hiding this comment

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

We used this approach a lot in the past, but i think it can cause some difficult to debug issues.
Maybe we can try this time to use an extension trait, like trait MultiStepMigratorTryRuntime : MultiStepMigrator that has this function, and then requiring that trait instead.
You think it could work?

Copy link
Member Author

Choose a reason for hiding this comment

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

What kinds of issues are you referring to and what use case is there?

My initial reaction is I'm not sure about it, because MultiStepMigratorTryRuntime would just be MultiStepMigrator with the try-runtime feature enabled.

@@ -649,6 +685,16 @@ impl SteppedMigrations for () {
None
}

#[cfg(feature = "try-runtime")]
fn nth_pre_upgrade(_n: u32) -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
Ok(Vec::new())
Copy link
Member

Choose a reason for hiding this comment

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

I think normally it still wraps the return value in an Option, in case that the index is out of bounds.
Why is it different here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I'll update it

log::debug!("Block {}", System::<T>::block_number());
System::<T>::set_block_number(System::<T>::block_number() + 1u32.into());
System::<T>::on_initialize(System::<T>::block_number());
crate::Pallet::<T>::on_initialize(System::<T>::block_number());
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if we need these. The step could also be called multiple times per block i think.

<frame_system::Pallet<T>>::on_finalize(System::<T>::block_number());

// Check events for `UpgradeCompleted` or `UpgradeFailed`.
for e in System::<T>::events().iter() {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for e in System::<T>::events().iter() {
for e in frame_system::Events::<T>::take().into_iter() {

Should make it a bit faster to not hold old events.

///
/// Returns some bytes which are passed into `post_upgrade` after the migration is completed.
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
Copy link
Member

@ggwpez ggwpez Apr 23, 2024

Choose a reason for hiding this comment

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

Same comment here about possible extension trait instead of feature gate.
Dont know if it is really better, but could try.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure about creating an extension trait that just adds some feature gated methods, what's the use case?

Generally I like to keep code simple with minimal indirection, only adding complexity and indirection when there is tangible benefit.

@bkchr
Copy link
Member

bkchr commented Apr 24, 2024

I remember that you asked somewhere which approach to take. I would take the approach of building multiple blocks until the MBMs are finished. I know that this is more complicated, but this directly checks that your runtime can handle this properly and also that you stay always in the POV limits.

(Didn't check the pr yet :D)

@liamaharon
Copy link
Member Author

I remember that you asked somewhere which approach to take. I would take the approach of building multiple blocks until the MBMs are finished. I know that this is more complicated, but this directly checks that your runtime can handle this properly and also that you stay always in the POV limits.

(Didn't check the pr yet :D)

Here's the discussion paritytech/try-runtime-cli#17 (comment)

I missed that Kian also supports building proper blocks. Although more involved, I will proceed with that approach :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T1-FRAME This PR/Issue is related to core FRAME, the framework.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants