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

[AHM] pause scheduler during migration #580

Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions pallets/ah-migrator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*,
Expand Down Expand Up @@ -526,4 +527,15 @@ pub mod pallet {
Weight::zero()
}
}

impl<T: Config> pallet_rc_migrator::types::MigrationStatus for Pallet<T> {
fn is_ongoing() -> bool {
// TODO: implement
true
}
fn is_finished() -> bool {
// TODO: implement
false
}
}
}
15 changes: 12 additions & 3 deletions pallets/rc-migrator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -212,14 +212,14 @@ impl<AccountId, BlockNumber, BagsListScore, VotingClass>
{
/// 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)
}
Expand Down Expand Up @@ -929,6 +929,15 @@ pub mod pallet {
Ok(())
}
}

impl<T: Config> types::MigrationStatus for Pallet<T> {
fn is_ongoing() -> bool {
RcMigrationStage::<T>::get().is_ongoing()
}
fn is_finished() -> bool {
RcMigrationStage::<T>::get().is_finished()
}
}
}

impl<T: Config> Contains<<T as frame_system::Config>::RuntimeCall> for Pallet<T> {
Expand Down
2 changes: 2 additions & 0 deletions pallets/rc-migrator/src/scheduler.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
19 changes: 19 additions & 0 deletions pallets/rc-migrator/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Status, Default>(PhantomData<(Status, Default)>);
impl<Status: MigrationStatus, Default: Get<Weight>> Get<Weight> for ZeroWeightOr<Status, Default> {
fn get() -> Weight {
Status::is_ongoing().then(Weight::zero).unwrap_or_else(Default::get)
}
}
3 changes: 2 additions & 1 deletion relay/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RcMigrator, MaximumSchedulerWeight>;
// 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.
Expand Down
2 changes: 1 addition & 1 deletion system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AhMigrator, MaximumSchedulerWeight>;
// Also allow Treasurer to schedule recurring payments.
type ScheduleOrigin = EitherOf<EnsureRoot<AccountId>, Treasurer>;
type MaxScheduledPerBlock = MaxScheduledPerBlock;
Expand Down
Loading