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

Set frame_system::LastRuntimeUpgrade after running try-runtime migrations #2515

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion substrate/frame/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,16 +362,27 @@ where
Ok(frame_system::Pallet::<System>::block_weight().total())
}

/// Execute all `OnRuntimeUpgrade` of this runtime.
/// Execute all Migrations of this runtime.
///
/// The `checks` param determines whether to execute `pre/post_upgrade` and `try_state` hooks.
///
/// [`frame_system::LastRuntimeUpgrade`] is set to the current runtime version after
/// migrations execute. This is important for idempotency checks, because some migrations use
/// this value to determine whether or not they should execute.
pub fn try_runtime_upgrade(checks: UpgradeCheckSelect) -> Result<Weight, TryRuntimeError> {
let before_all_weight =
<AllPalletsWithSystem as BeforeAllRuntimeMigrations>::before_all_runtime_migrations();
let try_on_runtime_upgrade_weight =
<(COnRuntimeUpgrade, AllPalletsWithSystem) as OnRuntimeUpgrade>::try_on_runtime_upgrade(
checks.pre_and_post(),
)?;

frame_system::LastRuntimeUpgrade::<System>::put(
frame_system::LastRuntimeUpgradeInfo::from(
<System::Version as frame_support::traits::Get<_>>::get(),
),
);

// Nothing should modify the state after the migrations ran:
let _guard = StorageNoopGuard::default();

Expand Down