From 8dfe976aa366454bd8140c869f07f17948dd5936 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Tue, 22 Mar 2022 00:53:27 -0400 Subject: [PATCH 01/14] suspend and resume xcm execution in on idle of xcmp queue pallet --- pallets/maintenance-mode/src/lib.rs | 18 ++++++++++++++++++ pallets/maintenance-mode/src/mock.rs | 2 ++ runtime/moonbase/src/lib.rs | 12 ++++++++++++ runtime/moonbeam/src/lib.rs | 11 +++++++++++ runtime/moonriver/src/lib.rs | 11 +++++++++++ 5 files changed, 54 insertions(+) diff --git a/pallets/maintenance-mode/src/lib.rs b/pallets/maintenance-mode/src/lib.rs index 51ad775608..f24af7095a 100644 --- a/pallets/maintenance-mode/src/lib.rs +++ b/pallets/maintenance-mode/src/lib.rs @@ -71,6 +71,17 @@ pub mod pallet { #[pallet::without_storage_info] pub struct Pallet(PhantomData); + /// Pause and resume execution of XCM + pub trait PauseXcmExecution { + fn suspend_xcm_execution(); + fn resume_xcm_execution(); + } + + impl PauseXcmExecution for () { + fn suspend_xcm_execution() {} + fn resume_xcm_execution() {} + } + /// Configuration trait of this pallet. #[pallet::config] pub trait Config: frame_system::Config { @@ -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; + /// 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; @@ -163,6 +177,8 @@ pub mod pallet { // Write to storage MaintenanceMode::::put(true); + // Suspend XCM execution + T::XcmExecutionManager::suspend_xcm_execution(); // Event >::deposit_event(Event::EnteredMaintenanceMode); @@ -190,6 +206,8 @@ pub mod pallet { // Write to storage MaintenanceMode::::put(false); + // Resume XCM execution + T::XcmExecutionManager::resume_xcm_execution(); // Event >::deposit_event(Event::NormalOperationResumed); diff --git a/pallets/maintenance-mode/src/mock.rs b/pallets/maintenance-mode/src/mock.rs index f0b2e58874..d8fcaf703e 100644 --- a/pallets/maintenance-mode/src/mock.rs +++ b/pallets/maintenance-mode/src/mock.rs @@ -284,6 +284,8 @@ impl Config for Test { type MaintenanceCallFilter = MaintenanceCallFilter; type MaintenanceOrigin = EnsureRoot; #[cfg(feature = "xcm-support")] + type XcmExecutionManager = (); + #[cfg(feature = "xcm-support")] type NormalDmpHandler = NormalDmpHandler; #[cfg(feature = "xcm-support")] type MaintenanceDmpHandler = MaintenanceDmpHandler; diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 6ca2ff7b24..8bd1b99490 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -1139,6 +1139,17 @@ impl Contains 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 @@ -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; diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 21f8f5f585..96f462950f 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -1086,6 +1086,16 @@ impl Contains 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 @@ -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; diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 8420624313..10561221d9 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -1116,6 +1116,16 @@ impl Contains 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 @@ -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; From d817191179770265d63cc81a62e8002f5139334a Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Tue, 22 Mar 2022 01:38:14 -0400 Subject: [PATCH 02/14] expect resume suspend calls to never fail and add integration tests to ensure this effectively --- runtime/moonbase/src/lib.rs | 4 ++-- runtime/moonbase/tests/integration_test.rs | 12 +++++++++++- runtime/moonbeam/src/lib.rs | 4 ++-- runtime/moonbeam/tests/integration_test.rs | 12 +++++++++++- runtime/moonriver/src/lib.rs | 4 ++-- runtime/moonriver/tests/integration_test.rs | 12 +++++++++++- 6 files changed, 39 insertions(+), 9 deletions(-) diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 8bd1b99490..fa75b5e7b4 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -1143,10 +1143,10 @@ use cumulus_primitives_core::{ pub struct XcmExecutionManager; impl pallet_maintenance_mode::PauseXcmExecution for XcmExecutionManager { fn suspend_xcm_execution() { - XcmpQueue::suspend_xcm_execution(Origin::root()); + XcmpQueue::suspend_xcm_execution(Origin::root()).expect("ControllerOrigin = EnsureRoot "); } fn resume_xcm_execution() { - XcmpQueue::resume_xcm_execution(Origin::root()); + XcmpQueue::resume_xcm_execution(Origin::root()).expect("ControllerOrigin = EnsureRoot"); } } diff --git a/runtime/moonbase/tests/integration_test.rs b/runtime/moonbase/tests/integration_test.rs index 4578605d0e..ceffa07b24 100644 --- a/runtime/moonbase/tests/integration_test.rs +++ b/runtime/moonbase/tests/integration_test.rs @@ -25,7 +25,7 @@ use fp_evm::{Context, ExitSucceed, PrecompileOutput}; use frame_support::{ assert_noop, assert_ok, dispatch::Dispatchable, - traits::{fungible::Inspect, PalletInfo, StorageInfo, StorageInfoTrait}, + traits::{fungible::Inspect, EnsureOrigin, PalletInfo, StorageInfo, StorageInfoTrait}, weights::{DispatchClass, Weight}, StorageHasher, Twox128, }; @@ -53,6 +53,16 @@ use sp_runtime::{ }; use xcm::latest::prelude::*; +#[test] +fn xcmp_queue_controller_origin_is_root() { + // important for the XcmExecutionManager impl of PauseExecution which uses root origin + // to suspend/resume XCM execution in xcmp_queue::on_idle + assert_ok!( + ::ControllerOrigin::ensure_origin(root_origin()) + ); +} + #[test] fn fast_track_available() { assert!(::InstantAllowed::get()); diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 96f462950f..d674d81851 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -1089,10 +1089,10 @@ impl Contains for NormalFilter { pub struct XcmExecutionManager; impl pallet_maintenance_mode::PauseXcmExecution for XcmExecutionManager { fn suspend_xcm_execution() { - XcmpQueue::suspend_xcm_execution(Origin::root()); + XcmpQueue::suspend_xcm_execution(Origin::root()).expect("ControllerOrigin = EnsureRoot "); } fn resume_xcm_execution() { - XcmpQueue::resume_xcm_execution(Origin::root()); + XcmpQueue::resume_xcm_execution(Origin::root()).expect("ControllerOrigin = EnsureRoot"); } } diff --git a/runtime/moonbeam/tests/integration_test.rs b/runtime/moonbeam/tests/integration_test.rs index 62eb53b465..e8b7796d07 100644 --- a/runtime/moonbeam/tests/integration_test.rs +++ b/runtime/moonbeam/tests/integration_test.rs @@ -25,7 +25,7 @@ use fp_evm::{Context, ExitSucceed, PrecompileOutput}; use frame_support::{ assert_noop, assert_ok, dispatch::Dispatchable, - traits::{fungible::Inspect, PalletInfo, StorageInfo, StorageInfoTrait}, + traits::{fungible::Inspect, EnsureOrigin, PalletInfo, StorageInfo, StorageInfoTrait}, weights::{DispatchClass, Weight}, StorageHasher, Twox128, }; @@ -52,6 +52,16 @@ use xcm::latest::prelude::*; use xcm::{VersionedMultiAsset, VersionedMultiAssets, VersionedMultiLocation}; use xtokens_precompiles::Action as XtokensAction; +#[test] +fn xcmp_queue_controller_origin_is_root() { + // important for the XcmExecutionManager impl of PauseExecution which uses root origin + // to suspend/resume XCM execution in xcmp_queue::on_idle + assert_ok!( + ::ControllerOrigin::ensure_origin(root_origin()) + ); +} + #[test] fn fast_track_available() { assert!(::InstantAllowed::get()); diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 10561221d9..0cdd6f7ef9 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -1119,10 +1119,10 @@ impl Contains for NormalFilter { pub struct XcmExecutionManager; impl pallet_maintenance_mode::PauseXcmExecution for XcmExecutionManager { fn suspend_xcm_execution() { - XcmpQueue::suspend_xcm_execution(Origin::root()); + XcmpQueue::suspend_xcm_execution(Origin::root()).expect("ControllerOrigin = EnsureRoot "); } fn resume_xcm_execution() { - XcmpQueue::resume_xcm_execution(Origin::root()); + XcmpQueue::resume_xcm_execution(Origin::root()).expect("ControllerOrigin = EnsureRoot"); } } diff --git a/runtime/moonriver/tests/integration_test.rs b/runtime/moonriver/tests/integration_test.rs index 7d9d921c2d..d80d2df06b 100644 --- a/runtime/moonriver/tests/integration_test.rs +++ b/runtime/moonriver/tests/integration_test.rs @@ -25,7 +25,7 @@ use fp_evm::{Context, ExitSucceed, PrecompileOutput}; use frame_support::{ assert_noop, assert_ok, dispatch::Dispatchable, - traits::{fungible::Inspect, PalletInfo, StorageInfo, StorageInfoTrait}, + traits::{fungible::Inspect, EnsureOrigin, PalletInfo, StorageInfo, StorageInfoTrait}, weights::{DispatchClass, Weight}, StorageHasher, Twox128, }; @@ -50,6 +50,16 @@ use xcm::latest::prelude::*; use xcm::{VersionedMultiAssets, VersionedMultiLocation}; use xtokens_precompiles::Action as XtokensAction; +#[test] +fn xcmp_queue_controller_origin_is_root() { + // important for the XcmExecutionManager impl of PauseExecution which uses root origin + // to suspend/resume XCM execution in xcmp_queue::on_idle + assert_ok!( + ::ControllerOrigin::ensure_origin(root_origin()) + ); +} + #[test] fn fast_track_available() { assert!(::InstantAllowed::get()); From c9edfa747d78fa88ef90ec5385b87d75ba3fa072 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Tue, 22 Mar 2022 10:46:58 -0400 Subject: [PATCH 03/14] return error but only emit event if errors instead of blocking maintenance mode --- pallets/maintenance-mode/src/lib.rs | 24 ++++++++++++++++++------ runtime/moonbase/src/lib.rs | 8 ++++---- runtime/moonbeam/src/lib.rs | 8 ++++---- runtime/moonriver/src/lib.rs | 8 ++++---- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/pallets/maintenance-mode/src/lib.rs b/pallets/maintenance-mode/src/lib.rs index f24af7095a..db0d60cd40 100644 --- a/pallets/maintenance-mode/src/lib.rs +++ b/pallets/maintenance-mode/src/lib.rs @@ -73,13 +73,17 @@ pub mod pallet { /// Pause and resume execution of XCM pub trait PauseXcmExecution { - fn suspend_xcm_execution(); - fn resume_xcm_execution(); + fn suspend_xcm_execution() -> DispatchResult; + fn resume_xcm_execution() -> DispatchResult; } impl PauseXcmExecution for () { - fn suspend_xcm_execution() {} - fn resume_xcm_execution() {} + fn suspend_xcm_execution() -> DispatchResult { + Ok(()) + } + fn resume_xcm_execution() -> DispatchResult { + Ok(()) + } } /// Configuration trait of this pallet. @@ -139,6 +143,10 @@ pub mod pallet { EnteredMaintenanceMode, /// The chain returned to its normal operating state NormalOperationResumed, + /// The call to suspend XCM execution failed with inner error + FailedToSuspendXcmExecution { error: DispatchError }, + /// The call to resume XCM execution failed with inner error + FailedToResumeXcmExecution { error: DispatchError }, } /// An error that can occur while executing this pallet's extrinsics. @@ -178,7 +186,9 @@ pub mod pallet { // Write to storage MaintenanceMode::::put(true); // Suspend XCM execution - T::XcmExecutionManager::suspend_xcm_execution(); + if let Err(error) = T::XcmExecutionManager::suspend_xcm_execution() { + >::deposit_event(Event::FailedToSuspendXcmExecution { error }); + } // Event >::deposit_event(Event::EnteredMaintenanceMode); @@ -207,7 +217,9 @@ pub mod pallet { // Write to storage MaintenanceMode::::put(false); // Resume XCM execution - T::XcmExecutionManager::resume_xcm_execution(); + if let Err(error) = T::XcmExecutionManager::resume_xcm_execution() { + >::deposit_event(Event::FailedToResumeXcmExecution { error }); + } // Event >::deposit_event(Event::NormalOperationResumed); diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index fa75b5e7b4..7b6bda344d 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -1142,11 +1142,11 @@ use cumulus_primitives_core::{ pub struct XcmExecutionManager; impl pallet_maintenance_mode::PauseXcmExecution for XcmExecutionManager { - fn suspend_xcm_execution() { - XcmpQueue::suspend_xcm_execution(Origin::root()).expect("ControllerOrigin = EnsureRoot "); + fn suspend_xcm_execution() -> DispatchResult { + XcmpQueue::suspend_xcm_execution(Origin::root()) } - fn resume_xcm_execution() { - XcmpQueue::resume_xcm_execution(Origin::root()).expect("ControllerOrigin = EnsureRoot"); + fn resume_xcm_execution() -> DispatchResult { + XcmpQueue::resume_xcm_execution(Origin::root()) } } diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index d674d81851..b0b76817d4 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -1088,11 +1088,11 @@ impl Contains for NormalFilter { pub struct XcmExecutionManager; impl pallet_maintenance_mode::PauseXcmExecution for XcmExecutionManager { - fn suspend_xcm_execution() { - XcmpQueue::suspend_xcm_execution(Origin::root()).expect("ControllerOrigin = EnsureRoot "); + fn suspend_xcm_execution() -> DispatchResult { + XcmpQueue::suspend_xcm_execution(Origin::root()) } - fn resume_xcm_execution() { - XcmpQueue::resume_xcm_execution(Origin::root()).expect("ControllerOrigin = EnsureRoot"); + fn resume_xcm_execution() -> DispatchResult { + XcmpQueue::resume_xcm_execution(Origin::root()) } } diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 0cdd6f7ef9..26a2af0832 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -1118,11 +1118,11 @@ impl Contains for NormalFilter { pub struct XcmExecutionManager; impl pallet_maintenance_mode::PauseXcmExecution for XcmExecutionManager { - fn suspend_xcm_execution() { - XcmpQueue::suspend_xcm_execution(Origin::root()).expect("ControllerOrigin = EnsureRoot "); + fn suspend_xcm_execution() -> DispatchResult { + XcmpQueue::suspend_xcm_execution(Origin::root()) } - fn resume_xcm_execution() { - XcmpQueue::resume_xcm_execution(Origin::root()).expect("ControllerOrigin = EnsureRoot"); + fn resume_xcm_execution() -> DispatchResult { + XcmpQueue::resume_xcm_execution(Origin::root()) } } From 5aa8e69b51d05f15c0f88733a8134404a83fd60f Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Tue, 22 Mar 2022 10:58:54 -0400 Subject: [PATCH 04/14] one more write now for maintenance mode extrinsics to enter and exit mmode --- pallets/maintenance-mode/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pallets/maintenance-mode/src/lib.rs b/pallets/maintenance-mode/src/lib.rs index db0d60cd40..761adf7d8c 100644 --- a/pallets/maintenance-mode/src/lib.rs +++ b/pallets/maintenance-mode/src/lib.rs @@ -169,8 +169,8 @@ pub mod pallet { /// /// Weight cost is: /// * One DB read to ensure we're not already in maintenance mode - /// * Two DB writes - 1 for the mode and 1 for the event - #[pallet::weight(T::DbWeight::get().read + 2 * T::DbWeight::get().write)] + /// * Three DB writes - 1 for the mode, 1 for suspending xcm execution, 1 for the event + #[pallet::weight(T::DbWeight::get().read + 3 * T::DbWeight::get().write)] pub fn enter_maintenance_mode(origin: OriginFor) -> DispatchResultWithPostInfo { // Ensure Origin T::MaintenanceOrigin::ensure_origin(origin)?; @@ -200,8 +200,8 @@ pub mod pallet { /// /// Weight cost is: /// * One DB read to ensure we're in maintenance mode - /// * Two DB writes - 1 for the mode and 1 for the event - #[pallet::weight(T::DbWeight::get().read + 2 * T::DbWeight::get().write)] + /// * Three DB writes - 1 for the mode, 1 for resuming xcm execution, 1 for the event + #[pallet::weight(T::DbWeight::get().read + 3 * T::DbWeight::get().write)] pub fn resume_normal_operation(origin: OriginFor) -> DispatchResultWithPostInfo { // Ensure Origin T::MaintenanceOrigin::ensure_origin(origin)?; From 1c02695e8e2f51db6e8b25262f256bf9d021cede Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Tue, 22 Mar 2022 12:55:29 -0400 Subject: [PATCH 05/14] better naming --- pallets/maintenance-mode/src/lib.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pallets/maintenance-mode/src/lib.rs b/pallets/maintenance-mode/src/lib.rs index 761adf7d8c..6d79dca18b 100644 --- a/pallets/maintenance-mode/src/lib.rs +++ b/pallets/maintenance-mode/src/lib.rs @@ -58,14 +58,14 @@ pub mod pallet { use cumulus_primitives_core::{ relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler, ParaId, XcmpMessageHandler, }; - #[cfg(feature = "xcm-support")] - use sp_std::vec::Vec; - 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] @@ -143,10 +143,10 @@ pub mod pallet { EnteredMaintenanceMode, /// The chain returned to its normal operating state NormalOperationResumed, - /// The call to suspend XCM execution failed with inner error - FailedToSuspendXcmExecution { error: DispatchError }, - /// The call to resume XCM execution failed with inner error - FailedToResumeXcmExecution { error: DispatchError }, + /// The call to suspend on_idle XCM execution failed with inner error + FailedToSuspendIdleXcmExecution { error: DispatchError }, + /// The call to resume on_idle XCM execution failed with inner error + FailedToResumeIdleXcmExecution { error: DispatchError }, } /// An error that can occur while executing this pallet's extrinsics. @@ -187,7 +187,7 @@ pub mod pallet { MaintenanceMode::::put(true); // Suspend XCM execution if let Err(error) = T::XcmExecutionManager::suspend_xcm_execution() { - >::deposit_event(Event::FailedToSuspendXcmExecution { error }); + >::deposit_event(Event::FailedToSuspendIdleXcmExecution { error }); } // Event @@ -218,7 +218,7 @@ pub mod pallet { MaintenanceMode::::put(false); // Resume XCM execution if let Err(error) = T::XcmExecutionManager::resume_xcm_execution() { - >::deposit_event(Event::FailedToResumeXcmExecution { error }); + >::deposit_event(Event::FailedToResumeIdleXcmExecution { error }); } // Event From b768ba502f7d46691ad6718f8f0af7448ac6a306 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Wed, 23 Mar 2022 14:10:08 -0400 Subject: [PATCH 06/14] try remove xcm and dmp handlers expect failure --- pallets/maintenance-mode/src/lib.rs | 45 ------------------- pallets/maintenance-mode/src/mock.rs | 64 +-------------------------- pallets/maintenance-mode/src/tests.rs | 37 ---------------- runtime/moonbase/src/lib.rs | 32 +------------- runtime/moonbeam/src/lib.rs | 32 +------------- runtime/moonriver/src/lib.rs | 32 +------------- 6 files changed, 7 insertions(+), 235 deletions(-) diff --git a/pallets/maintenance-mode/src/lib.rs b/pallets/maintenance-mode/src/lib.rs index 6d79dca18b..b271f595f6 100644 --- a/pallets/maintenance-mode/src/lib.rs +++ b/pallets/maintenance-mode/src/lib.rs @@ -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 DmpMessageHandler for Pallet { - fn handle_dmp_messages( - iter: impl Iterator)>, - limit: Weight, - ) -> Weight { - if MaintenanceMode::::get() { - T::MaintenanceDmpHandler::handle_dmp_messages(iter, limit) - } else { - T::NormalDmpHandler::handle_dmp_messages(iter, limit) - } - } - } - - #[cfg(feature = "xcm-support")] - impl XcmpMessageHandler for Pallet { - fn handle_xcmp_messages<'a, I: Iterator>( - iter: I, - limit: Weight, - ) -> Weight { - if MaintenanceMode::::get() { - T::MaintenanceXcmpHandler::handle_xcmp_messages(iter, limit) - } else { - T::NormalXcmpHandler::handle_xcmp_messages(iter, limit) - } - } - } } diff --git a/pallets/maintenance-mode/src/mock.rs b/pallets/maintenance-mode/src/mock.rs index d8fcaf703e..709e39e7a3 100644 --- a/pallets/maintenance-mode/src/mock.rs +++ b/pallets/maintenance-mode/src/mock.rs @@ -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 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>( - _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>( - _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)>, - _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)>, - _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; #[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; } diff --git a/pallets/maintenance-mode/src/tests.rs b/pallets/maintenance-mode/src/tests.rs index a1f926b320..4dbc96b94a 100644 --- a/pallets/maintenance-mode/src/tests.rs +++ b/pallets/maintenance-mode/src/tests.rs @@ -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() diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 7b6bda344d..63208f481c 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -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)>, - _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>( - 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; diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index b0b76817d4..273c1c51e1 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -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)>, - _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>( - 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; diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 26a2af0832..c366762a28 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -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)>, - _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>( - 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; From 340527b406ef3c7c5e5bf8cac11520f4b2a5e4e9 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Wed, 23 Mar 2022 15:23:52 -0400 Subject: [PATCH 07/14] wow so ts tests dont run unless 0 rust warnings hmmmmm --- runtime/moonbase/src/lib.rs | 4 ---- runtime/moonbeam/src/lib.rs | 4 ---- runtime/moonriver/src/lib.rs | 3 --- 3 files changed, 11 deletions(-) diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index e8646887f6..89d574900b 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -1051,10 +1051,6 @@ impl Contains 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() -> DispatchResult { diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 393350f6a8..409441e63e 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -83,10 +83,6 @@ use pallet_evm_precompile_assets_erc20::AccountIdAssetIdConversion; use xcm::latest::prelude::*; -use cumulus_primitives_core::{ - relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler, ParaId, XcmpMessageHandler, -}; - #[cfg(feature = "std")] use sp_version::NativeVersion; use sp_version::RuntimeVersion; diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index fb871ccea7..554af4081f 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -81,9 +81,6 @@ use sp_runtime::{ }; use sp_std::{convert::TryFrom, prelude::*}; -use cumulus_primitives_core::{ - relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler, ParaId, XcmpMessageHandler, -}; use smallvec::smallvec; #[cfg(feature = "std")] use sp_version::NativeVersion; From 560663a52bb618371edb9b2a32256d81bd577cc4 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Wed, 23 Mar 2022 15:51:00 -0400 Subject: [PATCH 08/14] more warnings --- pallets/maintenance-mode/src/mock.rs | 1 - pallets/maintenance-mode/src/tests.rs | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/pallets/maintenance-mode/src/mock.rs b/pallets/maintenance-mode/src/mock.rs index 709e39e7a3..5b2021eee9 100644 --- a/pallets/maintenance-mode/src/mock.rs +++ b/pallets/maintenance-mode/src/mock.rs @@ -17,7 +17,6 @@ //! 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; use frame_support::{ construct_runtime, parameter_types, traits::{ diff --git a/pallets/maintenance-mode/src/tests.rs b/pallets/maintenance-mode/src/tests.rs index 4dbc96b94a..146ad95e9d 100644 --- a/pallets/maintenance-mode/src/tests.rs +++ b/pallets/maintenance-mode/src/tests.rs @@ -15,9 +15,7 @@ // along with Moonbeam. If not, see . //! Unit testing -use crate::mock::{ - events, mock_events, Call as OuterCall, ExtBuilder, MaintenanceMode, Origin, Test, -}; +use crate::mock::{events, mock_events, Call as OuterCall, ExtBuilder, Origin, Test}; use crate::{Call, Error, Event, ExecutiveHooks}; use frame_support::{ assert_noop, assert_ok, From 0d4f37858d1d02ba44ee1388205ac37cc146d294 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 24 Mar 2022 12:25:35 -0400 Subject: [PATCH 09/14] add back dmp handlers --- pallets/maintenance-mode/src/lib.rs | 25 ++++++++++++++++++++ pallets/maintenance-mode/src/mock.rs | 31 +++++++++++++++++++++++++ pallets/maintenance-mode/src/tests.rs | 33 ++++++++++++++++++++++++++- runtime/moonbase/src/lib.rs | 17 ++++++++++++++ runtime/moonbeam/src/lib.rs | 17 ++++++++++++++ runtime/moonriver/src/lib.rs | 16 +++++++++++++ 6 files changed, 138 insertions(+), 1 deletion(-) diff --git a/pallets/maintenance-mode/src/lib.rs b/pallets/maintenance-mode/src/lib.rs index b271f595f6..bbe5f0e795 100644 --- a/pallets/maintenance-mode/src/lib.rs +++ b/pallets/maintenance-mode/src/lib.rs @@ -54,12 +54,18 @@ pub use pallet::*; #[pallet] pub mod pallet { + #[cfg(feature = "xcm-support")] + use cumulus_primitives_core::{ + relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler, + }; 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] @@ -100,6 +106,12 @@ 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 executive hooks that will be used in normal operating mode /// Important: Use AllPalletsReversedWithSystemFirst here if you dont want to modify the /// hooks behaviour @@ -236,4 +248,17 @@ pub mod pallet { } } } + #[cfg(feature = "xcm-support")] + impl DmpMessageHandler for Pallet { + fn handle_dmp_messages( + iter: impl Iterator)>, + limit: Weight, + ) -> Weight { + if MaintenanceMode::::get() { + T::MaintenanceDmpHandler::handle_dmp_messages(iter, limit) + } else { + T::NormalDmpHandler::handle_dmp_messages(iter, limit) + } + } + } } diff --git a/pallets/maintenance-mode/src/mock.rs b/pallets/maintenance-mode/src/mock.rs index 5b2021eee9..b509c8ed6e 100644 --- a/pallets/maintenance-mode/src/mock.rs +++ b/pallets/maintenance-mode/src/mock.rs @@ -17,6 +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}; use frame_support::{ construct_runtime, parameter_types, traits::{ @@ -95,6 +96,32 @@ impl Contains for MaintenanceCallFilter { } } +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)>, + _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)>, + _limit: Weight, + ) -> Weight { + return 0; + } +} + impl mock_pallet_maintenance_hooks::Config for Test { type Event = Event; } @@ -230,6 +257,10 @@ impl Config for Test { type MaintenanceOrigin = EnsureRoot; #[cfg(feature = "xcm-support")] type XcmExecutionManager = (); + #[cfg(feature = "xcm-support")] + type NormalDmpHandler = NormalDmpHandler; + #[cfg(feature = "xcm-support")] + type MaintenanceDmpHandler = MaintenanceDmpHandler; type NormalExecutiveHooks = NormalHooks; type MaitenanceExecutiveHooks = MaintenanceHooks; } diff --git a/pallets/maintenance-mode/src/tests.rs b/pallets/maintenance-mode/src/tests.rs index 146ad95e9d..557ad50327 100644 --- a/pallets/maintenance-mode/src/tests.rs +++ b/pallets/maintenance-mode/src/tests.rs @@ -15,8 +15,11 @@ // along with Moonbeam. If not, see . //! Unit testing -use crate::mock::{events, mock_events, Call as OuterCall, ExtBuilder, Origin, Test}; +use crate::mock::{ + events, mock_events, Call as OuterCall, ExtBuilder, MaintenanceMode, Origin, Test, +}; use crate::{Call, Error, Event, ExecutiveHooks}; +use cumulus_primitives_core::DmpMessageHandler; use frame_support::{ assert_noop, assert_ok, dispatch::Dispatchable, @@ -121,6 +124,34 @@ fn cannot_resume_normal_operation_while_already_operating_normally() { }) } +#[cfg(feature = "xcm-support")] +#[test] +fn normal_dmp_in_non_maintenance() { + ExtBuilder::default() + .with_maintenance_mode(false) + .build() + .execute_with(|| { + assert_eq!( + MaintenanceMode::handle_dmp_messages(vec![].into_iter(), 1), + 0 + ); + }) +} + +#[cfg(feature = "xcm-support")] +#[test] +fn maintenance_dmp_in_maintenance() { + ExtBuilder::default() + .with_maintenance_mode(true) + .build() + .execute_with(|| { + assert_eq!( + MaintenanceMode::handle_dmp_messages(vec![].into_iter(), 1), + 1 + ); + }) +} + #[test] fn normal_hooks_in_non_maintenance() { ExtBuilder::default() diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 89d574900b..74a2053ed8 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -1051,6 +1051,10 @@ impl Contains 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() -> DispatchResult { @@ -1061,6 +1065,18 @@ 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)>, + _limit: Weight, + ) -> Weight { + DmpQueue::handle_dmp_messages(iter, 0) + } +} + /// The hooks we wnat to run in Maintenance Mode pub struct MaintenanceHooks; @@ -1116,6 +1132,7 @@ impl pallet_maintenance_mode::Config for Runtime { type MaintenanceOrigin = pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, TechCommitteeInstance>; type XcmExecutionManager = XcmExecutionManager; + type DmpMessageHandler = MaintenanceDmpHandler; // We use AllPalletsReversedWithSystemFirst because we dont want to change the hooks in normal // operation type NormalExecutiveHooks = AllPalletsReversedWithSystemFirst; diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 409441e63e..c59c683202 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -83,6 +83,10 @@ use pallet_evm_precompile_assets_erc20::AccountIdAssetIdConversion; use xcm::latest::prelude::*; +use cumulus_primitives_core::{ + relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler, ParaId, XcmpMessageHandler, +}; + #[cfg(feature = "std")] use sp_version::NativeVersion; use sp_version::RuntimeVersion; @@ -1002,6 +1006,18 @@ 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)>, + _limit: Weight, + ) -> Weight { + DmpQueue::handle_dmp_messages(iter, 0) + } +} + /// The hooks we want to run in Maintenance Mode pub struct MaintenanceHooks; @@ -1057,6 +1073,7 @@ impl pallet_maintenance_mode::Config for Runtime { type MaintenanceOrigin = pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, TechCommitteeInstance>; type XcmExecutionManager = XcmExecutionManager; + type DmpMessageHandler = MaintenanceDmpHandler; // We use AllPalletsReversedWithSystemFirst because we dont want to change the hooks in normal // operation type NormalExecutiveHooks = AllPalletsReversedWithSystemFirst; diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 554af4081f..97229b0600 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -81,6 +81,9 @@ use sp_runtime::{ }; use sp_std::{convert::TryFrom, prelude::*}; +use cumulus_primitives_core::{ + relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler, ParaId, XcmpMessageHandler, +}; use smallvec::smallvec; #[cfg(feature = "std")] use sp_version::NativeVersion; @@ -1038,6 +1041,18 @@ 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)>, + _limit: Weight, + ) -> Weight { + DmpQueue::handle_dmp_messages(iter, 0) + } +} + /// The hooks we wantt to run in Maintenance Mode pub struct MaintenanceHooks; @@ -1093,6 +1108,7 @@ impl pallet_maintenance_mode::Config for Runtime { type MaintenanceOrigin = pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, TechCommitteeInstance>; type XcmExecutionManager = XcmExecutionManager; + type DmpMessageHandler = MaintenanceDmpHandler; // We use AllPalletsReversedWithSystemFirst because we dont want to change the hooks in normal // operation type NormalExecutiveHooks = AllPalletsReversedWithSystemFirst; From 9b74e2fc38847808d6e1223ce577026c368a99e7 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 24 Mar 2022 15:08:07 -0400 Subject: [PATCH 10/14] add comments to remove DmpHandlers in pallet once PR is merged --- pallets/maintenance-mode/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pallets/maintenance-mode/src/lib.rs b/pallets/maintenance-mode/src/lib.rs index bbe5f0e795..88d8b19ab8 100644 --- a/pallets/maintenance-mode/src/lib.rs +++ b/pallets/maintenance-mode/src/lib.rs @@ -107,9 +107,11 @@ pub mod pallet { #[cfg(feature = "xcm-support")] type XcmExecutionManager: PauseXcmExecution; /// The DMP handler to be used in normal operating mode + /// TODO: remove once https://github.com/paritytech/polkadot/pull/5035 is merged #[cfg(feature = "xcm-support")] type NormalDmpHandler: DmpMessageHandler; /// The DMP handler to be used in maintenance mode + /// TODO: remove once https://github.com/paritytech/polkadot/pull/5035 is merged #[cfg(feature = "xcm-support")] type MaintenanceDmpHandler: DmpMessageHandler; /// The executive hooks that will be used in normal operating mode From df07b34cf9e09a38400c15e670463cdfcfe94382 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 24 Mar 2022 16:20:40 -0400 Subject: [PATCH 11/14] fix runtime configs --- runtime/moonbase/src/lib.rs | 3 ++- runtime/moonbeam/src/lib.rs | 3 ++- runtime/moonriver/src/lib.rs | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 74a2053ed8..ea9cb92136 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -1132,7 +1132,8 @@ impl pallet_maintenance_mode::Config for Runtime { type MaintenanceOrigin = pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, TechCommitteeInstance>; type XcmExecutionManager = XcmExecutionManager; - type DmpMessageHandler = MaintenanceDmpHandler; + type NormalDmpHandler = DmpQueue; + type MaintenanceDmpHandler = MaintenanceDmpHandler; // We use AllPalletsReversedWithSystemFirst because we dont want to change the hooks in normal // operation type NormalExecutiveHooks = AllPalletsReversedWithSystemFirst; diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index c59c683202..7111a6f0ee 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -1073,7 +1073,8 @@ impl pallet_maintenance_mode::Config for Runtime { type MaintenanceOrigin = pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, TechCommitteeInstance>; type XcmExecutionManager = XcmExecutionManager; - type DmpMessageHandler = MaintenanceDmpHandler; + type NormalDmpHandler = DmpQueue; + type MaintenanceDmpHandler = MaintenanceDmpHandler; // We use AllPalletsReversedWithSystemFirst because we dont want to change the hooks in normal // operation type NormalExecutiveHooks = AllPalletsReversedWithSystemFirst; diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 97229b0600..a965e3abbb 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -1108,7 +1108,8 @@ impl pallet_maintenance_mode::Config for Runtime { type MaintenanceOrigin = pallet_collective::EnsureProportionAtLeast<_2, _3, AccountId, TechCommitteeInstance>; type XcmExecutionManager = XcmExecutionManager; - type DmpMessageHandler = MaintenanceDmpHandler; + type NormalDmpHandler = DmpQueue; + type MaintenanceDmpHandler = MaintenanceDmpHandler; // We use AllPalletsReversedWithSystemFirst because we dont want to change the hooks in normal // operation type NormalExecutiveHooks = AllPalletsReversedWithSystemFirst; From 462936615f560a12502215a892e0831d4893342d Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 24 Mar 2022 16:42:11 -0400 Subject: [PATCH 12/14] fmt --- runtime/moonbase/src/lib.rs | 4 +--- runtime/moonriver/src/lib.rs | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index ea9cb92136..d08a6bfd35 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -1051,9 +1051,7 @@ impl Contains for NormalFilter { } } -use cumulus_primitives_core::{ - relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler, ParaId, XcmpMessageHandler, -}; +use cumulus_primitives_core::{relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler}; pub struct XcmExecutionManager; impl pallet_maintenance_mode::PauseXcmExecution for XcmExecutionManager { diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index a965e3abbb..11ede82dc1 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -81,9 +81,7 @@ use sp_runtime::{ }; use sp_std::{convert::TryFrom, prelude::*}; -use cumulus_primitives_core::{ - relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler, ParaId, XcmpMessageHandler, -}; +use cumulus_primitives_core::{relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler}; use smallvec::smallvec; #[cfg(feature = "std")] use sp_version::NativeVersion; From 1996b1bbd4cc8539625e4d364cdd7d002906e9ed Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 24 Mar 2022 17:16:32 -0400 Subject: [PATCH 13/14] fmt --- runtime/moonbeam/src/lib.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 7111a6f0ee..3c10e58f78 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -83,9 +83,7 @@ use pallet_evm_precompile_assets_erc20::AccountIdAssetIdConversion; use xcm::latest::prelude::*; -use cumulus_primitives_core::{ - relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler, ParaId, XcmpMessageHandler, -}; +use cumulus_primitives_core::{relay_chain::BlockNumber as RelayBlockNumber, DmpMessageHandler}; #[cfg(feature = "std")] use sp_version::NativeVersion; From 9343d3965fdb2f4c6b87d44b0c1230a4af215ce1 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Thu, 24 Mar 2022 18:12:05 -0400 Subject: [PATCH 14/14] fix --- runtime/moonbase/src/lib.rs | 2 +- runtime/moonbeam/src/lib.rs | 2 +- runtime/moonriver/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index d08a6bfd35..ea22a648e6 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -694,7 +694,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type Event = Event; type OnSystemEvent = (); type SelfParaId = ParachainInfo; - type DmpMessageHandler = DmpQueue; + type DmpMessageHandler = MaintenanceMode; type ReservedDmpWeight = ReservedDmpWeight; type OutboundXcmpMessageSource = XcmpQueue; type XcmpMessageHandler = XcmpQueue; diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 3c10e58f78..b758778c00 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -621,7 +621,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type Event = Event; type OnSystemEvent = (); type SelfParaId = ParachainInfo; - type DmpMessageHandler = DmpQueue; + type DmpMessageHandler = MaintenanceMode; type ReservedDmpWeight = ConstU64<{ MAXIMUM_BLOCK_WEIGHT / 4 }>; type OutboundXcmpMessageSource = XcmpQueue; type XcmpMessageHandler = XcmpQueue; diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 11ede82dc1..5e2914a1c5 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -648,7 +648,7 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type Event = Event; type OnSystemEvent = (); type SelfParaId = ParachainInfo; - type DmpMessageHandler = DmpQueue; + type DmpMessageHandler = MaintenanceMode; type ReservedDmpWeight = ReservedDmpWeight; type OutboundXcmpMessageSource = XcmpQueue; type XcmpMessageHandler = XcmpQueue;