Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions pallets/maintenance-mode/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ pub mod pallet {
#[pallet::without_storage_info]
pub struct Pallet<T>(PhantomData<T>);

/// Pause and resume execution of XCM
pub trait PauseXcmExecution {
fn suspend_xcm_execution();
fn resume_xcm_execution();
Comment thread
girazoki marked this conversation as resolved.
Outdated
}

impl PauseXcmExecution for () {
fn suspend_xcm_execution() {}
fn resume_xcm_execution() {}
}

/// Configuration trait of this pallet.
#[pallet::config]
pub trait Config: frame_system::Config {
Expand All @@ -88,6 +99,9 @@ pub mod pallet {
/// able to return to normal mode. For example, if your MaintenanceOrigin is a council, make
/// sure that your councilors can still cast votes.
type MaintenanceOrigin: EnsureOrigin<Self::Origin>;
/// Handler to suspend and resume XCM execution
#[cfg(feature = "xcm-support")]
type XcmExecutionManager: PauseXcmExecution;
/// The DMP handler to be used in normal operating mode
#[cfg(feature = "xcm-support")]
type NormalDmpHandler: DmpMessageHandler;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we need the Handlers at all now?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hmmm I think we do, the new code just stops executing XCM in xcmp_queue::on_idle. I don't think it changes how messages are otherwise handled...

Expand Down Expand Up @@ -163,6 +177,8 @@ pub mod pallet {

// Write to storage
MaintenanceMode::<T>::put(true);
// Suspend XCM execution
T::XcmExecutionManager::suspend_xcm_execution();

// Event
<Pallet<T>>::deposit_event(Event::EnteredMaintenanceMode);
Expand Down Expand Up @@ -190,6 +206,8 @@ pub mod pallet {

// Write to storage
MaintenanceMode::<T>::put(false);
// Resume XCM execution
T::XcmExecutionManager::resume_xcm_execution();

// Event
<Pallet<T>>::deposit_event(Event::NormalOperationResumed);
Expand Down
2 changes: 2 additions & 0 deletions pallets/maintenance-mode/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ impl Config for Test {
type MaintenanceCallFilter = MaintenanceCallFilter;
type MaintenanceOrigin = EnsureRoot<AccountId>;
#[cfg(feature = "xcm-support")]
type XcmExecutionManager = ();
#[cfg(feature = "xcm-support")]
type NormalDmpHandler = NormalDmpHandler;
#[cfg(feature = "xcm-support")]
type MaintenanceDmpHandler = MaintenanceDmpHandler;
Expand Down
12 changes: 12 additions & 0 deletions runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,17 @@ impl Contains<Call> for NormalFilter {
use cumulus_primitives_core::{
relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler, ParaId, XcmpMessageHandler,
};

pub struct XcmExecutionManager;
impl pallet_maintenance_mode::PauseXcmExecution for XcmExecutionManager {
fn suspend_xcm_execution() {
XcmpQueue::suspend_xcm_execution(Origin::root());
}
fn resume_xcm_execution() {
XcmpQueue::resume_xcm_execution(Origin::root());
}
}

pub struct MaintenanceDmpHandler;
impl DmpMessageHandler for MaintenanceDmpHandler {
// This implementation makes messages be queued
Expand Down Expand Up @@ -1217,6 +1228,7 @@ impl pallet_maintenance_mode::Config for Runtime {
type MaintenanceCallFilter = MaintenanceFilter;
type MaintenanceOrigin =
pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, TechCommitteeInstance>;
type XcmExecutionManager = XcmExecutionManager;
type NormalDmpHandler = DmpQueue;
type MaintenanceDmpHandler = MaintenanceDmpHandler;
type NormalXcmpHandler = XcmpQueue;
Expand Down
11 changes: 11 additions & 0 deletions runtime/moonbeam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,16 @@ impl Contains<Call> for NormalFilter {
}
}

pub struct XcmExecutionManager;
impl pallet_maintenance_mode::PauseXcmExecution for XcmExecutionManager {
fn suspend_xcm_execution() {
XcmpQueue::suspend_xcm_execution(Origin::root());
}
fn resume_xcm_execution() {
XcmpQueue::resume_xcm_execution(Origin::root());
}
}

pub struct MaintenanceDmpHandler;
impl DmpMessageHandler for MaintenanceDmpHandler {
// This implementation makes messages be queued
Expand Down Expand Up @@ -1164,6 +1174,7 @@ impl pallet_maintenance_mode::Config for Runtime {
type MaintenanceCallFilter = MaintenanceFilter;
type MaintenanceOrigin =
pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, TechCommitteeInstance>;
type XcmExecutionManager = XcmExecutionManager;
type NormalDmpHandler = DmpQueue;
type MaintenanceDmpHandler = MaintenanceDmpHandler;
type NormalXcmpHandler = XcmpQueue;
Expand Down
11 changes: 11 additions & 0 deletions runtime/moonriver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,16 @@ impl Contains<Call> for NormalFilter {
}
}

pub struct XcmExecutionManager;
impl pallet_maintenance_mode::PauseXcmExecution for XcmExecutionManager {
fn suspend_xcm_execution() {
XcmpQueue::suspend_xcm_execution(Origin::root());
}
fn resume_xcm_execution() {
XcmpQueue::resume_xcm_execution(Origin::root());
}
}

pub struct MaintenanceDmpHandler;
impl DmpMessageHandler for MaintenanceDmpHandler {
// This implementation makes messages be queued
Expand Down Expand Up @@ -1194,6 +1204,7 @@ impl pallet_maintenance_mode::Config for Runtime {
type MaintenanceCallFilter = MaintenanceFilter;
type MaintenanceOrigin =
pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, TechCommitteeInstance>;
type XcmExecutionManager = XcmExecutionManager;
type NormalDmpHandler = DmpQueue;
type MaintenanceDmpHandler = MaintenanceDmpHandler;
type NormalXcmpHandler = XcmpQueue;
Expand Down