From 541e804c1672545c3ab766b6604565ea9fa688c3 Mon Sep 17 00:00:00 2001 From: muharem Date: Thu, 6 Feb 2025 17:41:37 +0800 Subject: [PATCH] pause scheduler during migraiton --- pallets/ah-migrator/src/lib.rs | 12 ++++++++++++ pallets/rc-migrator/src/lib.rs | 15 ++++++++++++--- pallets/rc-migrator/src/scheduler.md | 2 ++ pallets/rc-migrator/src/types.rs | 19 +++++++++++++++++++ relay/polkadot/src/lib.rs | 3 ++- .../asset-hubs/asset-hub-polkadot/src/lib.rs | 2 +- 6 files changed, 48 insertions(+), 5 deletions(-) diff --git a/pallets/ah-migrator/src/lib.rs b/pallets/ah-migrator/src/lib.rs index 35880d4406..96cb7d8c28 100644 --- a/pallets/ah-migrator/src/lib.rs +++ b/pallets/ah-migrator/src/lib.rs @@ -44,6 +44,7 @@ pub mod staking; pub mod types; pub use pallet::*; +pub use pallet_rc_migrator::types::ZeroWeightOr; use frame_support::{ pallet_prelude::*, @@ -526,4 +527,15 @@ pub mod pallet { Weight::zero() } } + + impl pallet_rc_migrator::types::MigrationStatus for Pallet { + fn is_ongoing() -> bool { + // TODO: implement + true + } + fn is_finished() -> bool { + // TODO: implement + false + } + } } diff --git a/pallets/rc-migrator/src/lib.rs b/pallets/rc-migrator/src/lib.rs index 31984a37fe..87d1e192b7 100644 --- a/pallets/rc-migrator/src/lib.rs +++ b/pallets/rc-migrator/src/lib.rs @@ -55,7 +55,7 @@ use frame_support::{ tokens::{Fortitude, Precision, Preservation}, Contains, Defensive, LockableCurrency, ReservableCurrency, }, - weights::WeightMeter, + weights::{Weight, WeightMeter}, }; use frame_system::{pallet_prelude::*, AccountInfo}; use multisig::MultisigMigrator; @@ -212,14 +212,14 @@ impl { /// Whether the migration is finished. /// - /// This is **not** the same as `!self.is_ongoing()`. + /// This is **not** the same as `!self.is_ongoing()` since it may not have started. pub fn is_finished(&self) -> bool { matches!(self, MigrationStage::MigrationDone) } /// Whether the migration is ongoing. /// - /// This is **not** the same as `!self.is_finished()`. + /// This is **not** the same as `!self.is_finished()` since it may not have started. pub fn is_ongoing(&self) -> bool { !matches!(self, MigrationStage::Pending | MigrationStage::MigrationDone) } @@ -929,6 +929,15 @@ pub mod pallet { Ok(()) } } + + impl types::MigrationStatus for Pallet { + fn is_ongoing() -> bool { + RcMigrationStage::::get().is_ongoing() + } + fn is_finished() -> bool { + RcMigrationStage::::get().is_finished() + } + } } impl Contains<::RuntimeCall> for Pallet { diff --git a/pallets/rc-migrator/src/scheduler.md b/pallets/rc-migrator/src/scheduler.md index 1f9d327aa8..693b82a267 100644 --- a/pallets/rc-migrator/src/scheduler.md +++ b/pallets/rc-migrator/src/scheduler.md @@ -5,3 +5,5 @@ Based on the scheduler pallet's usage in the Polkadot/Kusama runtime, it primari 2. Service tasks from the referendum pallet, specifically `nudge_referendum` and `refund_submission_deposit` We plan to map all calls that are used in the Governance by inspecting the production snapshots. + +During the migration process, we will disable the processing of scheduled tasks on both the Relay Chain and Asset Hub. This is achieved by setting the `MaximumWeight` parameter to zero for the scheduler using the `rc_pallet_migrator::types::ZeroWeightOr` helper type. Once the migration is complete, any tasks that are due for execution on Asset Hub will be processed, even if they are delayed. This behavior is appropriate for both types of tasks we handle. diff --git a/pallets/rc-migrator/src/types.rs b/pallets/rc-migrator/src/types.rs index 999b631dcf..3770688b56 100644 --- a/pallets/rc-migrator/src/types.rs +++ b/pallets/rc-migrator/src/types.rs @@ -121,3 +121,22 @@ pub trait PalletMigrationChecks { /// Run some checks after the migration and use the intermediate payload. fn post_check(payload: Self::Payload); } + +pub trait MigrationStatus { + /// Whether the migration is finished. + /// + /// This is **not** the same as `!self.is_ongoing()` since it may not have started. + fn is_finished() -> bool; + /// Whether the migration is ongoing. + /// + /// This is **not** the same as `!self.is_finished()` since it may not have started. + fn is_ongoing() -> bool; +} + +/// A weight that is zero if the migration is ongoing, otherwise it is the default weight. +pub struct ZeroWeightOr(PhantomData<(Status, Default)>); +impl> Get for ZeroWeightOr { + fn get() -> Weight { + Status::is_ongoing().then(Weight::zero).unwrap_or_else(Default::get) + } +} diff --git a/relay/polkadot/src/lib.rs b/relay/polkadot/src/lib.rs index 863ef93ebe..48fce633da 100644 --- a/relay/polkadot/src/lib.rs +++ b/relay/polkadot/src/lib.rs @@ -253,7 +253,8 @@ impl pallet_scheduler::Config for Runtime { type RuntimeEvent = RuntimeEvent; type PalletsOrigin = OriginCaller; type RuntimeCall = RuntimeCall; - type MaximumWeight = MaximumSchedulerWeight; + type MaximumWeight = + pallet_rc_migrator::types::ZeroWeightOr; // The goal of having ScheduleOrigin include AuctionAdmin is to allow the auctions track of // OpenGov to schedule periodic auctions. // Also allow Treasurer to schedule recurring payments. diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs index 21c43f1b02..7f9ba02219 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs @@ -1079,7 +1079,7 @@ impl pallet_scheduler::Config for Runtime { type RuntimeEvent = RuntimeEvent; type PalletsOrigin = OriginCaller; type RuntimeCall = RuntimeCall; - type MaximumWeight = MaximumSchedulerWeight; + type MaximumWeight = pallet_ah_migrator::ZeroWeightOr; // Also allow Treasurer to schedule recurring payments. type ScheduleOrigin = EitherOf, Treasurer>; type MaxScheduledPerBlock = MaxScheduledPerBlock;