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

{suspend, resume} xcm execution when {enter, exit}ing maintenance-mode #1359

Merged
merged 15 commits into from
Mar 25, 2022
Merged
Prev Previous commit
Next Next commit
try remove xcm and dmp handlers expect failure
4meta5 committed Mar 23, 2022
commit b768ba502f7d46691ad6718f8f0af7448ac6a306
45 changes: 0 additions & 45 deletions pallets/maintenance-mode/src/lib.rs
Original file line number Diff line number Diff line change
@@ -54,18 +54,12 @@ pub use pallet::*;

#[pallet]
pub mod pallet {
#[cfg(feature = "xcm-support")]
use cumulus_primitives_core::{
relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler, ParaId, XcmpMessageHandler,
};
use frame_support::pallet_prelude::*;
use frame_support::traits::{
Contains, EnsureOrigin, OffchainWorker, OnFinalize, OnIdle, OnInitialize, OnRuntimeUpgrade,
};
use frame_system::pallet_prelude::*;
use sp_runtime::DispatchResult;
#[cfg(feature = "xcm-support")]
use sp_std::vec::Vec;
/// Pallet for migrations
#[pallet::pallet]
#[pallet::without_storage_info]
@@ -106,18 +100,6 @@ pub mod pallet {
/// 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;
/// The DMP handler to be used in maintenance mode
#[cfg(feature = "xcm-support")]
type MaintenanceDmpHandler: DmpMessageHandler;
/// The XCMP handler to be used in normal operating mode
#[cfg(feature = "xcm-support")]
type NormalXcmpHandler: XcmpMessageHandler;
/// The XCMP handler to be used in maintenance mode
#[cfg(feature = "xcm-support")]
type MaintenanceXcmpHandler: XcmpMessageHandler;
/// The executive hooks that will be used in normal operating mode
/// Important: Use AllPalletsReversedWithSystemFirst here if you dont want to modify the
/// hooks behaviour
@@ -254,31 +236,4 @@ pub mod pallet {
}
}
}
#[cfg(feature = "xcm-support")]
impl<T: Config> DmpMessageHandler for Pallet<T> {
fn handle_dmp_messages(
iter: impl Iterator<Item = (RelayBlockNumber, Vec<u8>)>,
limit: Weight,
) -> Weight {
if MaintenanceMode::<T>::get() {
T::MaintenanceDmpHandler::handle_dmp_messages(iter, limit)
} else {
T::NormalDmpHandler::handle_dmp_messages(iter, limit)
}
}
}

#[cfg(feature = "xcm-support")]
impl<T: Config> XcmpMessageHandler for Pallet<T> {
fn handle_xcmp_messages<'a, I: Iterator<Item = (ParaId, RelayBlockNumber, &'a [u8])>>(
iter: I,
limit: Weight,
) -> Weight {
if MaintenanceMode::<T>::get() {
T::MaintenanceXcmpHandler::handle_xcmp_messages(iter, limit)
} else {
T::NormalXcmpHandler::handle_xcmp_messages(iter, limit)
}
}
}
}
64 changes: 1 addition & 63 deletions pallets/maintenance-mode/src/mock.rs
Original file line number Diff line number Diff line change
@@ -17,9 +17,7 @@
//! A minimal runtime including the maintenance-mode pallet
use super::*;
use crate as pallet_maintenance_mode;
use cumulus_primitives_core::{
relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler, ParaId, XcmpMessageHandler,
};
use cumulus_primitives_core::relay_chain::BlockNumber as RelayBlockNumber;
use frame_support::{
construct_runtime, parameter_types,
traits::{
@@ -98,58 +96,6 @@ impl Contains<Call> for MaintenanceCallFilter {
}
}

pub struct MaintenanceXcmpHandler;
#[cfg(feature = "xcm-support")]
impl XcmpMessageHandler for MaintenanceXcmpHandler {
// This implementation makes messages be queued
// Since the limit is 0, messages are queued for next iteration
fn handle_xcmp_messages<'a, I: Iterator<Item = (ParaId, RelayBlockNumber, &'a [u8])>>(
_iter: I,
_limit: Weight,
) -> Weight {
return 1;
}
}

pub struct NormalXcmpHandler;
#[cfg(feature = "xcm-support")]
impl XcmpMessageHandler for NormalXcmpHandler {
// This implementation makes messages be queued
// Since the limit is 0, messages are queued for next iteration
fn handle_xcmp_messages<'a, I: Iterator<Item = (ParaId, RelayBlockNumber, &'a [u8])>>(
_iter: I,
_limit: Weight,
) -> Weight {
return 0;
}
}

pub struct MaintenanceDmpHandler;
#[cfg(feature = "xcm-support")]
impl DmpMessageHandler for MaintenanceDmpHandler {
// This implementation makes messages be queued
// Since the limit is 0, messages are queued for next iteration
fn handle_dmp_messages(
_iter: impl Iterator<Item = (RelayBlockNumber, Vec<u8>)>,
_limit: Weight,
) -> Weight {
return 1;
}
}

pub struct NormalDmpHandler;
#[cfg(feature = "xcm-support")]
impl DmpMessageHandler for NormalDmpHandler {
// This implementation makes messages be queued
// Since the limit is 0, messages are queued for next iteration
fn handle_dmp_messages(
_iter: impl Iterator<Item = (RelayBlockNumber, Vec<u8>)>,
_limit: Weight,
) -> Weight {
return 0;
}
}

impl mock_pallet_maintenance_hooks::Config for Test {
type Event = Event;
}
@@ -285,14 +231,6 @@ impl Config for Test {
type MaintenanceOrigin = EnsureRoot<AccountId>;
#[cfg(feature = "xcm-support")]
type XcmExecutionManager = ();
#[cfg(feature = "xcm-support")]
type NormalDmpHandler = NormalDmpHandler;
#[cfg(feature = "xcm-support")]
type MaintenanceDmpHandler = MaintenanceDmpHandler;
#[cfg(feature = "xcm-support")]
type NormalXcmpHandler = NormalXcmpHandler;
#[cfg(feature = "xcm-support")]
type MaintenanceXcmpHandler = MaintenanceXcmpHandler;
type NormalExecutiveHooks = NormalHooks;
type MaitenanceExecutiveHooks = MaintenanceHooks;
}
37 changes: 0 additions & 37 deletions pallets/maintenance-mode/src/tests.rs
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@ use crate::mock::{
events, mock_events, Call as OuterCall, ExtBuilder, MaintenanceMode, Origin, Test,
};
use crate::{Call, Error, Event, ExecutiveHooks};
use cumulus_primitives_core::{DmpMessageHandler, XcmpMessageHandler};
use frame_support::{
assert_noop, assert_ok,
dispatch::Dispatchable,
@@ -124,42 +123,6 @@ fn cannot_resume_normal_operation_while_already_operating_normally() {
})
}

#[cfg(feature = "xcm-support")]
#[test]
fn normal_dmp_and_xcmp_in_non_maintenance() {
ExtBuilder::default()
.with_maintenance_mode(false)
.build()
.execute_with(|| {
assert_eq!(
MaintenanceMode::handle_dmp_messages(vec![].into_iter(), 1),
0
);
assert_eq!(
MaintenanceMode::handle_xcmp_messages(vec![].into_iter(), 1),
0
);
})
}

#[cfg(feature = "xcm-support")]
#[test]
fn maintenance_dmp_and_xcmp_in_maintenance() {
ExtBuilder::default()
.with_maintenance_mode(true)
.build()
.execute_with(|| {
assert_eq!(
MaintenanceMode::handle_dmp_messages(vec![].into_iter(), 1),
1
);
assert_eq!(
MaintenanceMode::handle_xcmp_messages(vec![].into_iter(), 1),
1
);
})
}

#[test]
fn normal_hooks_in_non_maintenance() {
ExtBuilder::default()
32 changes: 2 additions & 30 deletions runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
@@ -745,10 +745,10 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type Event = Event;
type OnSystemEvent = ();
type SelfParaId = ParachainInfo;
type DmpMessageHandler = MaintenanceMode;
type DmpMessageHandler = DmpQueue;
type ReservedDmpWeight = ReservedDmpWeight;
type OutboundXcmpMessageSource = XcmpQueue;
type XcmpMessageHandler = MaintenanceMode;
type XcmpMessageHandler = XcmpQueue;
type ReservedXcmpWeight = ReservedXcmpWeight;
}

@@ -1150,30 +1150,6 @@ impl pallet_maintenance_mode::PauseXcmExecution for XcmExecutionManager {
}
}

pub struct MaintenanceDmpHandler;
impl DmpMessageHandler for MaintenanceDmpHandler {
// This implementation makes messages be queued
// Since the limit is 0, messages are queued for next iteration
fn handle_dmp_messages(
iter: impl Iterator<Item = (RelayBlockNumber, Vec<u8>)>,
_limit: Weight,
) -> Weight {
DmpQueue::handle_dmp_messages(iter, 0)
}
}

pub struct MaintenanceXcmpHandler;
impl XcmpMessageHandler for MaintenanceXcmpHandler {
// This implementation makes messages be queued
// Since the limit is 0, messages are queued for next iteration
fn handle_xcmp_messages<'a, I: Iterator<Item = (ParaId, RelayBlockNumber, &'a [u8])>>(
iter: I,
_limit: Weight,
) -> Weight {
XcmpQueue::handle_xcmp_messages(iter, 0)
}
}

/// The hooks we wnat to run in Maintenance Mode
pub struct MaintenanceHooks;

@@ -1229,10 +1205,6 @@ impl pallet_maintenance_mode::Config for Runtime {
type MaintenanceOrigin =
pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, TechCommitteeInstance>;
type XcmExecutionManager = XcmExecutionManager;
type NormalDmpHandler = DmpQueue;
type MaintenanceDmpHandler = MaintenanceDmpHandler;
type NormalXcmpHandler = XcmpQueue;
type MaintenanceXcmpHandler = MaintenanceXcmpHandler;
// We use AllPalletsReversedWithSystemFirst because we dont want to change the hooks in normal
// operation
type NormalExecutiveHooks = AllPalletsReversedWithSystemFirst;
32 changes: 2 additions & 30 deletions runtime/moonbeam/src/lib.rs
Original file line number Diff line number Diff line change
@@ -679,10 +679,10 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type Event = Event;
type OnSystemEvent = ();
type SelfParaId = ParachainInfo;
type DmpMessageHandler = MaintenanceMode;
type DmpMessageHandler = DmpQueue;
type ReservedDmpWeight = ReservedDmpWeight;
type OutboundXcmpMessageSource = XcmpQueue;
type XcmpMessageHandler = MaintenanceMode;
type XcmpMessageHandler = XcmpQueue;
type ReservedXcmpWeight = ReservedXcmpWeight;
}
impl parachain_info::Config for Runtime {}
@@ -1096,30 +1096,6 @@ impl pallet_maintenance_mode::PauseXcmExecution for XcmExecutionManager {
}
}

pub struct MaintenanceDmpHandler;
impl DmpMessageHandler for MaintenanceDmpHandler {
// This implementation makes messages be queued
// Since the limit is 0, messages are queued for next iteration
fn handle_dmp_messages(
iter: impl Iterator<Item = (RelayBlockNumber, Vec<u8>)>,
_limit: Weight,
) -> Weight {
DmpQueue::handle_dmp_messages(iter, 0)
}
}

pub struct MaintenanceXcmpHandler;
impl XcmpMessageHandler for MaintenanceXcmpHandler {
// This implementation makes messages be queued
// Since the limit is 0, messages are queued for next iteration
fn handle_xcmp_messages<'a, I: Iterator<Item = (ParaId, RelayBlockNumber, &'a [u8])>>(
iter: I,
_limit: Weight,
) -> Weight {
XcmpQueue::handle_xcmp_messages(iter, 0)
}
}

/// The hooks we want to run in Maintenance Mode
pub struct MaintenanceHooks;

@@ -1175,10 +1151,6 @@ impl pallet_maintenance_mode::Config for Runtime {
type MaintenanceOrigin =
pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, TechCommitteeInstance>;
type XcmExecutionManager = XcmExecutionManager;
type NormalDmpHandler = DmpQueue;
type MaintenanceDmpHandler = MaintenanceDmpHandler;
type NormalXcmpHandler = XcmpQueue;
type MaintenanceXcmpHandler = MaintenanceXcmpHandler;
// We use AllPalletsReversedWithSystemFirst because we dont want to change the hooks in normal
// operation
type NormalExecutiveHooks = AllPalletsReversedWithSystemFirst;
32 changes: 2 additions & 30 deletions runtime/moonriver/src/lib.rs
Original file line number Diff line number Diff line change
@@ -701,10 +701,10 @@ impl cumulus_pallet_parachain_system::Config for Runtime {
type Event = Event;
type OnSystemEvent = ();
type SelfParaId = ParachainInfo;
type DmpMessageHandler = MaintenanceMode;
type DmpMessageHandler = DmpQueue;
type ReservedDmpWeight = ReservedDmpWeight;
type OutboundXcmpMessageSource = XcmpQueue;
type XcmpMessageHandler = MaintenanceMode;
type XcmpMessageHandler = XcmpQueue;
type ReservedXcmpWeight = ReservedXcmpWeight;
}

@@ -1126,30 +1126,6 @@ impl pallet_maintenance_mode::PauseXcmExecution for XcmExecutionManager {
}
}

pub struct MaintenanceDmpHandler;
impl DmpMessageHandler for MaintenanceDmpHandler {
// This implementation makes messages be queued
// Since the limit is 0, messages are queued for next iteration
fn handle_dmp_messages(
iter: impl Iterator<Item = (RelayBlockNumber, Vec<u8>)>,
_limit: Weight,
) -> Weight {
DmpQueue::handle_dmp_messages(iter, 0)
}
}

pub struct MaintenanceXcmpHandler;
impl XcmpMessageHandler for MaintenanceXcmpHandler {
// This implementation makes messages be queued
// Since the limit is 0, messages are queued for next iteration
fn handle_xcmp_messages<'a, I: Iterator<Item = (ParaId, RelayBlockNumber, &'a [u8])>>(
iter: I,
_limit: Weight,
) -> Weight {
XcmpQueue::handle_xcmp_messages(iter, 0)
}
}

/// The hooks we wantt to run in Maintenance Mode
pub struct MaintenanceHooks;

@@ -1205,10 +1181,6 @@ impl pallet_maintenance_mode::Config for Runtime {
type MaintenanceOrigin =
pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, TechCommitteeInstance>;
type XcmExecutionManager = XcmExecutionManager;
type NormalDmpHandler = DmpQueue;
type MaintenanceDmpHandler = MaintenanceDmpHandler;
type NormalXcmpHandler = XcmpQueue;
type MaintenanceXcmpHandler = MaintenanceXcmpHandler;
// We use AllPalletsReversedWithSystemFirst because we dont want to change the hooks in normal
// operation
type NormalExecutiveHooks = AllPalletsReversedWithSystemFirst;