Skip to content

Commit bf7ba60

Browse files
ggwpezjoepetrowski
andauthored
[AHM] Schedule migration on runtime upgrade (#934)
Schedule the AHM on runtime upgrade so we can avoid doing another fellowship call. Exact values will be set in the subsequent runtime release MR. Changes: - Factor scheduling logic out into `do_schedule_migration` - Add `KickoffAhm` to Kusama RC runtime - Put a placeholder for the actual scheduling values that we can fill in later --------- Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: joe petrowski <25483142+joepetrowski@users.noreply.github.com>
1 parent 7057f10 commit bf7ba60

File tree

2 files changed

+66
-20
lines changed

2 files changed

+66
-20
lines changed

pallets/rc-migrator/src/lib.rs

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -965,26 +965,13 @@ pub mod pallet {
965965
) -> DispatchResultWithPostInfo {
966966
Self::ensure_admin_or_manager(origin)?;
967967

968-
let now = frame_system::Pallet::<T>::block_number();
969-
let start = start.evaluate(now);
970-
971-
ensure!(start > now, Error::<T>::PastBlockNumber);
972-
973-
if !unsafe_ignore_staking_lock_check {
974-
let until_start = start.saturating_sub(now);
975-
let two_session_duration: u32 = <T as Config>::SessionDuration::get()
976-
.saturating_mul(2)
977-
.try_into()
978-
.map_err(|_| Error::<T>::EraEndsTooSoon)?;
968+
Self::do_schedule_migration(
969+
start,
970+
warm_up,
971+
cool_off,
972+
unsafe_ignore_staking_lock_check,
973+
)?;
979974

980-
// We check > and not >= here since the on_initialize for this block already ran.
981-
ensure!(until_start > two_session_duration.into(), Error::<T>::EraEndsTooSoon);
982-
}
983-
984-
WarmUpPeriod::<T>::put(warm_up);
985-
CoolOffPeriod::<T>::put(cool_off);
986-
987-
Self::transition(MigrationStage::Scheduled { start });
988975
Ok(Pays::No.into())
989976
}
990977

@@ -2392,6 +2379,34 @@ pub mod pallet {
23922379
}
23932380

23942381
impl<T: Config> Pallet<T> {
2382+
pub fn do_schedule_migration(
2383+
start: DispatchTime<BlockNumberFor<T>>,
2384+
warm_up: DispatchTime<BlockNumberFor<T>>,
2385+
cool_off: DispatchTime<BlockNumberFor<T>>,
2386+
unsafe_ignore_staking_lock_check: bool,
2387+
) -> DispatchResult {
2388+
let now = frame_system::Pallet::<T>::block_number();
2389+
let start = start.evaluate(now);
2390+
2391+
ensure!(start > now, Error::<T>::PastBlockNumber);
2392+
2393+
if !unsafe_ignore_staking_lock_check {
2394+
let until_start = start.saturating_sub(now);
2395+
let two_session_duration: u32 = <T as Config>::SessionDuration::get()
2396+
.saturating_mul(2)
2397+
.try_into()
2398+
.map_err(|_| Error::<T>::EraEndsTooSoon)?;
2399+
2400+
// We check > and not >= here since the on_initialize for this block already ran.
2401+
ensure!(until_start > two_session_duration.into(), Error::<T>::EraEndsTooSoon);
2402+
}
2403+
2404+
WarmUpPeriod::<T>::put(warm_up);
2405+
CoolOffPeriod::<T>::put(cool_off);
2406+
2407+
Self::transition(MigrationStage::Scheduled { start });
2408+
Ok(())
2409+
}
23952410
/// Ensure that the origin is [`Config::AdminOrigin`] or signed by [`Manager`] account id.
23962411
fn ensure_admin_or_manager(origin: OriginFor<T>) -> DispatchResult {
23972412
if let Ok(account_id) = ensure_signed(origin.clone()) {

relay/kusama/src/lib.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2190,12 +2190,43 @@ pub type Migrations = (migrations::Unreleased, migrations::Permanent);
21902190
#[allow(deprecated, missing_docs)]
21912191
pub mod migrations {
21922192
use super::*;
2193+
use frame_support::traits::OnRuntimeUpgrade;
2194+
use pallet_rc_migrator::{MigrationStage, MigrationStartBlock, RcMigrationStage};
21932195

21942196
/// Unreleased migrations. Add new ones here:
2195-
pub type Unreleased = ();
2197+
pub type Unreleased = (KickOffAhm<Runtime>,);
21962198

21972199
/// Migrations/checks that do not need to be versioned and can run on every update.
21982200
pub type Permanent = pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>;
2201+
2202+
/// Kick off the Asset Hub Migration.
2203+
pub struct KickOffAhm<T>(pub core::marker::PhantomData<T>);
2204+
impl<T: pallet_rc_migrator::Config> OnRuntimeUpgrade for KickOffAhm<T> {
2205+
fn on_runtime_upgrade() -> Weight {
2206+
if MigrationStartBlock::<T>::exists() ||
2207+
RcMigrationStage::<T>::get() != MigrationStage::Pending
2208+
{
2209+
// Already started or scheduled
2210+
log::info!("KickOffAhm: Asset Hub Migration already started or scheduled");
2211+
return T::DbWeight::get().reads(2)
2212+
}
2213+
2214+
// We will set this as part of the release MR
2215+
/*let result = pallet_rc_migrator::Pallet::<T>::do_schedule_migration(
2216+
DispatchTime::After(/* START */),
2217+
DispatchTime::After(/* WARM UP */),
2218+
DispatchTime::After(/* COOL OFF */),
2219+
Default::default(),
2220+
);
2221+
if let Err(e) = result {
2222+
log::error!("KickOffAhm: Failed to schedule Asset Hub Migration: {:?}", e);
2223+
} else {
2224+
log::info!("KickOffAhm: Scheduled Asset Hub Migration");
2225+
}*/
2226+
2227+
T::DbWeight::get().reads_writes(1, 1)
2228+
}
2229+
}
21992230
}
22002231

22012232
/// Unchecked extrinsic type as expected by this runtime.

0 commit comments

Comments
 (0)