From 5392f09feae3a4f39cba5dbb68c917813df8ab5f Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Wed, 12 Jan 2022 02:35:44 -0800 Subject: [PATCH 1/8] Add the ability to suspend or resume XCM execution on the XCMP queue --- pallets/xcmp-queue/src/lib.rs | 38 +++++++++++++++++++ pallets/xcmp-queue/src/mock.rs | 1 + pallets/xcmp-queue/src/tests.rs | 18 +++++++++ parachain-template/runtime/src/lib.rs | 1 + .../rococo-parachain/src/lib.rs | 1 + polkadot-parachains/statemint/src/lib.rs | 1 + polkadot-parachains/westmint/src/lib.rs | 1 + 7 files changed, 61 insertions(+) diff --git a/pallets/xcmp-queue/src/lib.rs b/pallets/xcmp-queue/src/lib.rs index cab3a18e424..762ddac022b 100644 --- a/pallets/xcmp-queue/src/lib.rs +++ b/pallets/xcmp-queue/src/lib.rs @@ -81,6 +81,9 @@ pub mod pallet { /// The origin that is allowed to execute overweight messages. type ExecuteOverweightOrigin: EnsureOrigin; + + /// The origin that is allowed to resume or suspend the XCMP queue. + type ControllerOrigin: EnsureOrigin; } #[pallet::hooks] @@ -129,6 +132,32 @@ pub mod pallet { Self::deposit_event(Event::OverweightServiced(index, used)); Ok(Some(used.saturating_add(1_000_000)).into()) } + + /// Suspends all XCM executions for the XCMP queue, regardless of the sender's origin. + /// + /// - `origin`: Must pass `ControllerOrigin`. + #[pallet::weight(T::DbWeight::get().writes(1))] + pub fn suspend_xcm_execution(origin: OriginFor) -> DispatchResult { + T::ControllerOrigin::ensure_origin(origin)?; + + QueueActive::::put(false); + + Ok(()) + } + + /// Resumes all XCM executions for the XCMP queue. + /// + /// Note that this function doesn't change the status of the in/out bound channels. + /// + /// - `origin`: Must pass `ControllerOrigin`. + #[pallet::weight(T::DbWeight::get().writes(1))] + pub fn resume_xcm_execution(origin: OriginFor) -> DispatchResult { + T::ControllerOrigin::ensure_origin(origin)?; + + QueueActive::::put(true); + + Ok(()) + } } #[pallet::event] @@ -220,6 +249,10 @@ pub mod pallet { /// available free overweight index. #[pallet::storage] pub(super) type OverweightCount = StorageValue<_, OverweightIndex, ValueQuery>; + + /// Whether or not the XCMP queue is active in executing incoming XCMs or not. + #[pallet::storage] + pub(super) type QueueActive = StorageValue<_, bool, ValueQuery>; } #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug, TypeInfo)] @@ -619,6 +652,11 @@ impl Pallet { /// for the second &c. though empirical and or practical factors may give rise to adjusting it /// further. fn service_xcmp_queue(max_weight: Weight) -> Weight { + let active = QueueActive::::get(); + if !active { + return 0 + } + let mut status = >::get(); // <- sorted. if status.len() == 0 { return 0 diff --git a/pallets/xcmp-queue/src/mock.rs b/pallets/xcmp-queue/src/mock.rs index cd0622d2f8c..666f1bc79f6 100644 --- a/pallets/xcmp-queue/src/mock.rs +++ b/pallets/xcmp-queue/src/mock.rs @@ -160,6 +160,7 @@ impl Config for Test { type ChannelInfo = ParachainSystem; type VersionWrapper = (); type ExecuteOverweightOrigin = EnsureRoot; + type ControllerOrigin = EnsureRoot; } pub fn new_test_ext() -> sp_io::TestExternalities { diff --git a/pallets/xcmp-queue/src/tests.rs b/pallets/xcmp-queue/src/tests.rs index bb352e69ff6..96627af41a6 100644 --- a/pallets/xcmp-queue/src/tests.rs +++ b/pallets/xcmp-queue/src/tests.rs @@ -82,3 +82,21 @@ fn service_overweight_bad_xcm_format() { assert_noop!(XcmpQueue::service_overweight(Origin::root(), 0, 1000), Error::::BadXcm); }); } + +#[test] +fn suspend_xcm_execution_works() { + new_test_ext().execute_with(|| { + QueueActive::::put(false); + + let xcm = Instruction::<()>::ClearOrigin.encode(); + let mut message_format = XcmpMessageFormat::ConcatenatedVersionedXcm.encode(); + message_format.extend(xcm.clone()); + let messages = vec![(Default::default(), 1u32.into(), message_format.as_slice())]; + + // This shouldn't have executed the incoming XCM + XcmpQueue::handle_xcmp_messages(messages.into_iter(), Weight::max_value()); + + let queued_xcm = InboundXcmpMessages::::get(ParaId::default(), 1u32); + assert_eq!(queued_xcm, xcm); + }); +} diff --git a/parachain-template/runtime/src/lib.rs b/parachain-template/runtime/src/lib.rs index 1949fe5e295..79cac58f199 100644 --- a/parachain-template/runtime/src/lib.rs +++ b/parachain-template/runtime/src/lib.rs @@ -525,6 +525,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ChannelInfo = ParachainSystem; type VersionWrapper = (); type ExecuteOverweightOrigin = EnsureRoot; + type ControllerOrigin = EnsureRoot; } impl cumulus_pallet_dmp_queue::Config for Runtime { diff --git a/polkadot-parachains/rococo-parachain/src/lib.rs b/polkadot-parachains/rococo-parachain/src/lib.rs index 94eb03e87a1..01d67ca4cb6 100644 --- a/polkadot-parachains/rococo-parachain/src/lib.rs +++ b/polkadot-parachains/rococo-parachain/src/lib.rs @@ -454,6 +454,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ChannelInfo = ParachainSystem; type VersionWrapper = (); type ExecuteOverweightOrigin = EnsureRoot; + type ControllerOrigin = EnsureRoot; } impl cumulus_pallet_dmp_queue::Config for Runtime { diff --git a/polkadot-parachains/statemint/src/lib.rs b/polkadot-parachains/statemint/src/lib.rs index d0aedfe1250..11f9407d88a 100644 --- a/polkadot-parachains/statemint/src/lib.rs +++ b/polkadot-parachains/statemint/src/lib.rs @@ -616,6 +616,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ChannelInfo = ParachainSystem; type VersionWrapper = PolkadotXcm; type ExecuteOverweightOrigin = EnsureRoot; + type ControllerOrigin = EnsureRoot; } impl cumulus_pallet_dmp_queue::Config for Runtime { diff --git a/polkadot-parachains/westmint/src/lib.rs b/polkadot-parachains/westmint/src/lib.rs index d4102849e7b..13c17f92305 100644 --- a/polkadot-parachains/westmint/src/lib.rs +++ b/polkadot-parachains/westmint/src/lib.rs @@ -596,6 +596,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ChannelInfo = ParachainSystem; type VersionWrapper = PolkadotXcm; type ExecuteOverweightOrigin = EnsureRoot; + type ControllerOrigin = EnsureRoot; } impl cumulus_pallet_dmp_queue::Config for Runtime { From 1839ffc55b0477c7988c21cd9ffc9ba5bbb35b60 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Wed, 12 Jan 2022 18:08:58 -0800 Subject: [PATCH 2/8] Rename QueueActive to QueueSuspended --- pallets/xcmp-queue/src/lib.rs | 12 ++++++------ pallets/xcmp-queue/src/tests.rs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pallets/xcmp-queue/src/lib.rs b/pallets/xcmp-queue/src/lib.rs index 762ddac022b..c15e6747feb 100644 --- a/pallets/xcmp-queue/src/lib.rs +++ b/pallets/xcmp-queue/src/lib.rs @@ -140,7 +140,7 @@ pub mod pallet { pub fn suspend_xcm_execution(origin: OriginFor) -> DispatchResult { T::ControllerOrigin::ensure_origin(origin)?; - QueueActive::::put(false); + QueueSuspended::::put(true); Ok(()) } @@ -154,7 +154,7 @@ pub mod pallet { pub fn resume_xcm_execution(origin: OriginFor) -> DispatchResult { T::ControllerOrigin::ensure_origin(origin)?; - QueueActive::::put(true); + QueueSuspended::::put(false); Ok(()) } @@ -250,9 +250,9 @@ pub mod pallet { #[pallet::storage] pub(super) type OverweightCount = StorageValue<_, OverweightIndex, ValueQuery>; - /// Whether or not the XCMP queue is active in executing incoming XCMs or not. + /// Whether or not the XCMP queue is suspended from executing incoming XCMs or not. #[pallet::storage] - pub(super) type QueueActive = StorageValue<_, bool, ValueQuery>; + pub(super) type QueueSuspended = StorageValue<_, bool, ValueQuery>; } #[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug, TypeInfo)] @@ -652,8 +652,8 @@ impl Pallet { /// for the second &c. though empirical and or practical factors may give rise to adjusting it /// further. fn service_xcmp_queue(max_weight: Weight) -> Weight { - let active = QueueActive::::get(); - if !active { + let suspended = QueueSuspended::::get(); + if suspended { return 0 } diff --git a/pallets/xcmp-queue/src/tests.rs b/pallets/xcmp-queue/src/tests.rs index 96627af41a6..16bab7ff98b 100644 --- a/pallets/xcmp-queue/src/tests.rs +++ b/pallets/xcmp-queue/src/tests.rs @@ -86,7 +86,7 @@ fn service_overweight_bad_xcm_format() { #[test] fn suspend_xcm_execution_works() { new_test_ext().execute_with(|| { - QueueActive::::put(false); + QueueSuspended::::put(true); let xcm = Instruction::<()>::ClearOrigin.encode(); let mut message_format = XcmpMessageFormat::ConcatenatedVersionedXcm.encode(); From 363ca09b41e40fce3f2740e7ab78f5c54781ca5c Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Wed, 12 Jan 2022 18:25:47 -0800 Subject: [PATCH 3/8] Add the ability to suspend the DMP queue --- pallets/dmp-queue/src/lib.rs | 60 +++++++++++++++++++ parachain-template/runtime/src/lib.rs | 1 + .../rococo-parachain/src/lib.rs | 3 +- polkadot-parachains/statemine/src/lib.rs | 2 + polkadot-parachains/statemint/src/lib.rs | 1 + polkadot-parachains/westmint/src/lib.rs | 1 + 6 files changed, 67 insertions(+), 1 deletion(-) diff --git a/pallets/dmp-queue/src/lib.rs b/pallets/dmp-queue/src/lib.rs index eb6ed6e3f50..5b2cf067694 100644 --- a/pallets/dmp-queue/src/lib.rs +++ b/pallets/dmp-queue/src/lib.rs @@ -89,6 +89,9 @@ pub mod pallet { /// Origin which is allowed to execute overweight messages. type ExecuteOverweightOrigin: EnsureOrigin; + + /// The origin that is allowed to resume or suspend the XCMP queue. + type ControllerOrigin: EnsureOrigin; } /// The configuration. @@ -109,6 +112,10 @@ pub mod pallet { pub(super) type Overweight = StorageMap<_, Blake2_128Concat, OverweightIndex, (RelayBlockNumber, Vec), OptionQuery>; + /// Whether or not the XCMP queue is suspended from executing incoming XCMs or not. + #[pallet::storage] + pub(super) type QueueSuspended = StorageValue<_, bool, ValueQuery>; + #[pallet::error] pub enum Error { /// The message index given is unknown. @@ -154,6 +161,32 @@ pub mod pallet { Self::deposit_event(Event::OverweightServiced(index, used)); Ok(Some(used.saturating_add(1_000_000)).into()) } + + /// Suspends all XCM executions for the XCMP queue, regardless of the sender's origin. + /// + /// - `origin`: Must pass `ControllerOrigin`. + #[pallet::weight(T::DbWeight::get().writes(1))] + pub fn suspend_xcm_execution(origin: OriginFor) -> DispatchResult { + T::ControllerOrigin::ensure_origin(origin)?; + + QueueSuspended::::put(true); + + Ok(()) + } + + /// Resumes all XCM executions for the XCMP queue. + /// + /// Note that this function doesn't change the status of the in/out bound channels. + /// + /// - `origin`: Must pass `ControllerOrigin`. + #[pallet::weight(T::DbWeight::get().writes(1))] + pub fn resume_xcm_execution(origin: OriginFor) -> DispatchResult { + T::ControllerOrigin::ensure_origin(origin)?; + + QueueSuspended::::put(false); + + Ok(()) + } } #[pallet::event] @@ -184,6 +217,11 @@ pub mod pallet { /// /// Returns the weight consumed by executing messages in the queue. fn service_queue(limit: Weight) -> Weight { + let suspended = QueueSuspended::::get(); + if suspended { + return 0 + } + PageIndex::::mutate(|page_index| Self::do_service_queue(limit, page_index)) } @@ -263,6 +301,11 @@ pub mod pallet { iter: impl Iterator)>, limit: Weight, ) -> Weight { + let suspended = QueueSuspended::::get(); + if suspended { + return 0 + } + let mut page_index = PageIndex::::get(); let config = Configuration::::get(); @@ -447,6 +490,7 @@ mod tests { type Event = Event; type XcmExecutor = MockExec; type ExecuteOverweightOrigin = frame_system::EnsureRoot; + type ControllerOrigin = frame_system::EnsureRoot; } pub(crate) fn new_test_ext() -> sp_io::TestExternalities { @@ -786,4 +830,20 @@ mod tests { assert_eq!(pages_queued(), 1); }); } + + #[test] + fn suspend_xcm_execution_works() { + new_test_ext().execute_with(|| { + QueueSuspended::::put(true); + + let incoming = [msg(1000), msg(1001)]; + enqueue(&incoming[..]); + + let weight_used = handle_messages(&incoming, 5000); + + assert_eq!(weight_used, 0); + assert_eq!(take_trace(), Vec::new()); + assert_eq!(pages_queued(), 1); + }); + } } diff --git a/parachain-template/runtime/src/lib.rs b/parachain-template/runtime/src/lib.rs index 79cac58f199..7867a886802 100644 --- a/parachain-template/runtime/src/lib.rs +++ b/parachain-template/runtime/src/lib.rs @@ -532,6 +532,7 @@ impl cumulus_pallet_dmp_queue::Config for Runtime { type Event = Event; type XcmExecutor = XcmExecutor; type ExecuteOverweightOrigin = EnsureRoot; + type ControllerOrigin = EnsureRoot; } parameter_types! { diff --git a/polkadot-parachains/rococo-parachain/src/lib.rs b/polkadot-parachains/rococo-parachain/src/lib.rs index 01d67ca4cb6..3f6411bb2a9 100644 --- a/polkadot-parachains/rococo-parachain/src/lib.rs +++ b/polkadot-parachains/rococo-parachain/src/lib.rs @@ -460,7 +460,8 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { impl cumulus_pallet_dmp_queue::Config for Runtime { type Event = Event; type XcmExecutor = XcmExecutor; - type ExecuteOverweightOrigin = frame_system::EnsureRoot; + type ExecuteOverweightOrigin = EnsureRoot; + type ControllerOrigin = EnsureRoot; } impl cumulus_ping::Config for Runtime { diff --git a/polkadot-parachains/statemine/src/lib.rs b/polkadot-parachains/statemine/src/lib.rs index 0da8de22380..03ec54f99a2 100644 --- a/polkadot-parachains/statemine/src/lib.rs +++ b/polkadot-parachains/statemine/src/lib.rs @@ -604,12 +604,14 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type ChannelInfo = ParachainSystem; type VersionWrapper = PolkadotXcm; type ExecuteOverweightOrigin = EnsureRoot; + type ControllerOrigin = EnsureRoot; } impl cumulus_pallet_dmp_queue::Config for Runtime { type Event = Event; type XcmExecutor = XcmExecutor; type ExecuteOverweightOrigin = EnsureRoot; + type ControllerOrigin = EnsureRoot; } parameter_types! { diff --git a/polkadot-parachains/statemint/src/lib.rs b/polkadot-parachains/statemint/src/lib.rs index 11f9407d88a..9399e906a3a 100644 --- a/polkadot-parachains/statemint/src/lib.rs +++ b/polkadot-parachains/statemint/src/lib.rs @@ -623,6 +623,7 @@ impl cumulus_pallet_dmp_queue::Config for Runtime { type Event = Event; type XcmExecutor = XcmExecutor; type ExecuteOverweightOrigin = EnsureRoot; + type ControllerOrigin = EnsureRoot; } parameter_types! { diff --git a/polkadot-parachains/westmint/src/lib.rs b/polkadot-parachains/westmint/src/lib.rs index 13c17f92305..9c159e97f3f 100644 --- a/polkadot-parachains/westmint/src/lib.rs +++ b/polkadot-parachains/westmint/src/lib.rs @@ -603,6 +603,7 @@ impl cumulus_pallet_dmp_queue::Config for Runtime { type Event = Event; type XcmExecutor = XcmExecutor; type ExecuteOverweightOrigin = EnsureRoot; + type ControllerOrigin = EnsureRoot; } parameter_types! { From f4027e5559874e30b164a7a5c9f42da7294e0c7b Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Thu, 13 Jan 2022 02:59:45 -0800 Subject: [PATCH 4/8] Rename XCMP to DMP in comments where appropriate Co-authored-by: Alexander Popiak --- pallets/dmp-queue/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pallets/dmp-queue/src/lib.rs b/pallets/dmp-queue/src/lib.rs index 5b2cf067694..41e3458b54c 100644 --- a/pallets/dmp-queue/src/lib.rs +++ b/pallets/dmp-queue/src/lib.rs @@ -112,7 +112,7 @@ pub mod pallet { pub(super) type Overweight = StorageMap<_, Blake2_128Concat, OverweightIndex, (RelayBlockNumber, Vec), OptionQuery>; - /// Whether or not the XCMP queue is suspended from executing incoming XCMs or not. + /// Whether or not the DMP queue is suspended from executing incoming XCMs or not. #[pallet::storage] pub(super) type QueueSuspended = StorageValue<_, bool, ValueQuery>; @@ -162,7 +162,7 @@ pub mod pallet { Ok(Some(used.saturating_add(1_000_000)).into()) } - /// Suspends all XCM executions for the XCMP queue, regardless of the sender's origin. + /// Suspends all XCM executions for the DMP queue, regardless of the sender's origin. /// /// - `origin`: Must pass `ControllerOrigin`. #[pallet::weight(T::DbWeight::get().writes(1))] @@ -174,7 +174,7 @@ pub mod pallet { Ok(()) } - /// Resumes all XCM executions for the XCMP queue. + /// Resumes all XCM executions for the DMP queue. /// /// Note that this function doesn't change the status of the in/out bound channels. /// From 0ad9324f9341844d5f95e8ee09931da95ccadff9 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Sat, 22 Jan 2022 04:58:13 -0800 Subject: [PATCH 5/8] Add a bypass for XCMP queue suspension --- pallets/xcmp-queue/src/lib.rs | 22 +++++++++++--- pallets/xcmp-queue/src/mock.rs | 29 ++++++++++++++++++- pallets/xcmp-queue/src/tests.rs | 16 +++++++--- parachain-template/runtime/src/lib.rs | 1 + .../rococo-parachain/src/lib.rs | 1 + polkadot-parachains/statemine/src/lib.rs | 1 + polkadot-parachains/statemint/src/lib.rs | 1 + polkadot-parachains/westmint/src/lib.rs | 1 + primitives/core/src/lib.rs | 2 +- 9 files changed, 64 insertions(+), 10 deletions(-) diff --git a/pallets/xcmp-queue/src/lib.rs b/pallets/xcmp-queue/src/lib.rs index 6b87c1562e8..c0ec4cafa1f 100644 --- a/pallets/xcmp-queue/src/lib.rs +++ b/pallets/xcmp-queue/src/lib.rs @@ -38,7 +38,10 @@ use cumulus_primitives_core::{ relay_chain::BlockNumber as RelayBlockNumber, ChannelStatus, GetChannelInfo, MessageSendError, ParaId, XcmpMessageFormat, XcmpMessageHandler, XcmpMessageSource, }; -use frame_support::weights::{constants::WEIGHT_PER_MILLIS, Weight}; +use frame_support::{ + traits::EnsureOrigin, + weights::{constants::WEIGHT_PER_MILLIS, Weight}, +}; use rand_chacha::{ rand_core::{RngCore, SeedableRng}, ChaChaRng, @@ -47,6 +50,7 @@ use scale_info::TypeInfo; use sp_runtime::{traits::Hash, RuntimeDebug}; use sp_std::{convert::TryFrom, prelude::*}; use xcm::{latest::prelude::*, VersionedXcm, WrapVersion, MAX_XCM_DECODE_DEPTH}; +use xcm_executor::traits::ConvertOrigin; pub use pallet::*; @@ -80,6 +84,8 @@ pub mod pallet { /// Means of converting an `Xcm` into a `VersionedXcm`. type VersionWrapper: WrapVersion; + type OriginConverter: ConvertOrigin; + /// The origin that is allowed to execute overweight messages. type ExecuteOverweightOrigin: EnsureOrigin; @@ -652,9 +658,6 @@ impl Pallet { /// further. fn service_xcmp_queue(max_weight: Weight) -> Weight { let suspended = QueueSuspended::::get(); - if suspended { - return 0 - } let mut status = >::get(); // <- sorted. if status.len() == 0 { @@ -687,6 +690,17 @@ impl Pallet { { let index = shuffled[shuffle_index]; let sender = status[index].sender; + let sender_origin = T::OriginConverter::convert_origin( + (1, Parachain(sender.into())), + OriginKind::Superuser, + ); + let is_controller = sender_origin + .map_or(false, |origin| T::ControllerOrigin::try_origin(origin).is_ok()); + + if suspended && !is_controller { + shuffle_index += 1; + continue + } if weight_available != max_weight { // Get incrementally closer to freeing up max_weight for message execution over the diff --git a/pallets/xcmp-queue/src/mock.rs b/pallets/xcmp-queue/src/mock.rs index fdfae75d3f9..4a5e9508dad 100644 --- a/pallets/xcmp-queue/src/mock.rs +++ b/pallets/xcmp-queue/src/mock.rs @@ -15,16 +15,20 @@ use super::*; use crate as xcmp_queue; -use frame_support::parameter_types; +use core::marker::PhantomData; +use cumulus_primitives_core::{IsSystem, ParaId}; +use frame_support::{parameter_types, traits::OriginTrait}; use frame_system::EnsureRoot; use sp_core::H256; use sp_runtime::{ testing::Header, traits::{BlakeTwo256, IdentityLookup}, }; +use xcm::prelude::*; use xcm_builder::{ CurrencyAdapter, FixedWeightBounds, IsConcrete, LocationInverter, NativeAsset, ParentIsPreset, }; +use xcm_executor::traits::ConvertOrigin; type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; @@ -154,11 +158,34 @@ pub type XcmRouter = ( XcmpQueue, ); +pub struct SystemParachainAsSuperuser(PhantomData); +impl ConvertOrigin for SystemParachainAsSuperuser { + fn convert_origin( + origin: impl Into, + kind: OriginKind, + ) -> Result { + let origin = origin.into(); + if kind == OriginKind::Superuser && + matches!( + origin, + MultiLocation { + parents: 1, + interior: X1(Parachain(id)), + } if ParaId::from(id).is_system(), + ) { + Ok(Origin::root()) + } else { + Err(origin) + } + } +} + impl Config for Test { type Event = Event; type XcmExecutor = xcm_executor::XcmExecutor; type ChannelInfo = ParachainSystem; type VersionWrapper = (); + type OriginConverter = SystemParachainAsSuperuser; type ExecuteOverweightOrigin = EnsureRoot; type ControllerOrigin = EnsureRoot; } diff --git a/pallets/xcmp-queue/src/tests.rs b/pallets/xcmp-queue/src/tests.rs index 0351ce7e0cc..1ec894c5676 100644 --- a/pallets/xcmp-queue/src/tests.rs +++ b/pallets/xcmp-queue/src/tests.rs @@ -16,7 +16,7 @@ use super::*; use cumulus_primitives_core::XcmpMessageHandler; use frame_support::assert_noop; -use mock::{new_test_ext, Origin, Test, XcmpQueue}; +use mock::{new_test_ext, Call, Origin, Test, XcmpQueue}; #[test] fn one_message_does_not_panic() { @@ -89,15 +89,23 @@ fn suspend_xcm_execution_works() { new_test_ext().execute_with(|| { QueueSuspended::::put(true); - let xcm = Instruction::<()>::ClearOrigin.encode(); + let xcm = VersionedXcm::from(Xcm::(vec![Instruction::::ClearOrigin])).encode(); let mut message_format = XcmpMessageFormat::ConcatenatedVersionedXcm.encode(); message_format.extend(xcm.clone()); - let messages = vec![(Default::default(), 1u32.into(), message_format.as_slice())]; + let messages = vec![(ParaId::from(999), 1u32.into(), message_format.as_slice())]; + + // This should have executed the incoming XCM, because it came from a system parachain + XcmpQueue::handle_xcmp_messages(messages.into_iter(), Weight::max_value()); + + let queued_xcm = InboundXcmpMessages::::get(ParaId::from(999), 1u32); + assert!(queued_xcm.is_empty()); + + let messages = vec![(ParaId::from(2000), 1u32.into(), message_format.as_slice())]; // This shouldn't have executed the incoming XCM XcmpQueue::handle_xcmp_messages(messages.into_iter(), Weight::max_value()); - let queued_xcm = InboundXcmpMessages::::get(ParaId::default(), 1u32); + let queued_xcm = InboundXcmpMessages::::get(ParaId::from(2000), 1u32); assert_eq!(queued_xcm, xcm); }); } diff --git a/parachain-template/runtime/src/lib.rs b/parachain-template/runtime/src/lib.rs index 79bb08dbbd2..501798f22a7 100644 --- a/parachain-template/runtime/src/lib.rs +++ b/parachain-template/runtime/src/lib.rs @@ -524,6 +524,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type XcmExecutor = XcmExecutor; type ChannelInfo = ParachainSystem; type VersionWrapper = (); + type OriginConverter = XcmOriginToTransactDispatchOrigin; type ExecuteOverweightOrigin = EnsureRoot; type ControllerOrigin = EnsureRoot; } diff --git a/polkadot-parachains/rococo-parachain/src/lib.rs b/polkadot-parachains/rococo-parachain/src/lib.rs index f5286d46e34..3eeb2248818 100644 --- a/polkadot-parachains/rococo-parachain/src/lib.rs +++ b/polkadot-parachains/rococo-parachain/src/lib.rs @@ -453,6 +453,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type XcmExecutor = XcmExecutor; type ChannelInfo = ParachainSystem; type VersionWrapper = (); + type OriginConverter = XcmOriginToTransactDispatchOrigin; type ExecuteOverweightOrigin = EnsureRoot; type ControllerOrigin = EnsureRoot; } diff --git a/polkadot-parachains/statemine/src/lib.rs b/polkadot-parachains/statemine/src/lib.rs index 2cfe6eff0fb..39d5c845c51 100644 --- a/polkadot-parachains/statemine/src/lib.rs +++ b/polkadot-parachains/statemine/src/lib.rs @@ -608,6 +608,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type XcmExecutor = XcmExecutor; type ChannelInfo = ParachainSystem; type VersionWrapper = PolkadotXcm; + type OriginConverter = XcmOriginToTransactDispatchOrigin; type ExecuteOverweightOrigin = EnsureRoot; type ControllerOrigin = EnsureRoot; } diff --git a/polkadot-parachains/statemint/src/lib.rs b/polkadot-parachains/statemint/src/lib.rs index c7c0bc8387c..e26b87e7fcf 100644 --- a/polkadot-parachains/statemint/src/lib.rs +++ b/polkadot-parachains/statemint/src/lib.rs @@ -621,6 +621,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type XcmExecutor = XcmExecutor; type ChannelInfo = ParachainSystem; type VersionWrapper = PolkadotXcm; + type OriginConverter = XcmOriginToTransactDispatchOrigin; type ExecuteOverweightOrigin = EnsureRoot; type ControllerOrigin = EnsureRoot; } diff --git a/polkadot-parachains/westmint/src/lib.rs b/polkadot-parachains/westmint/src/lib.rs index a46fd88df2a..a961976811b 100644 --- a/polkadot-parachains/westmint/src/lib.rs +++ b/polkadot-parachains/westmint/src/lib.rs @@ -595,6 +595,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type XcmExecutor = XcmExecutor; type ChannelInfo = ParachainSystem; type VersionWrapper = PolkadotXcm; + type OriginConverter = XcmOriginToTransactDispatchOrigin; type ExecuteOverweightOrigin = EnsureRoot; type ControllerOrigin = EnsureRoot; } diff --git a/primitives/core/src/lib.rs b/primitives/core/src/lib.rs index 93019c47b75..e2519e67879 100644 --- a/primitives/core/src/lib.rs +++ b/primitives/core/src/lib.rs @@ -25,7 +25,7 @@ use sp_std::prelude::*; pub use polkadot_core_primitives::InboundDownwardMessage; pub use polkadot_parachain::primitives::{ - DmpMessageHandler, Id as ParaId, UpwardMessage, ValidationParams, XcmpMessageFormat, + DmpMessageHandler, Id as ParaId, IsSystem, UpwardMessage, ValidationParams, XcmpMessageFormat, XcmpMessageHandler, }; pub use polkadot_primitives::v1::{ From 08b1a3f254f46825c80030e62c341ab169080d5b Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Mon, 24 Jan 2022 10:50:20 -0800 Subject: [PATCH 6/8] Revert "Add the ability to suspend the DMP queue" This reverts commit 363ca09b41e40fce3f2740e7ab78f5c54781ca5c. --- pallets/dmp-queue/src/lib.rs | 60 ------------------- parachain-template/runtime/src/lib.rs | 1 - .../rococo-parachain/src/lib.rs | 3 +- polkadot-parachains/statemine/src/lib.rs | 2 - polkadot-parachains/statemint/src/lib.rs | 1 - polkadot-parachains/westmint/src/lib.rs | 1 - 6 files changed, 1 insertion(+), 67 deletions(-) diff --git a/pallets/dmp-queue/src/lib.rs b/pallets/dmp-queue/src/lib.rs index 50e8f496743..73cca9487b5 100644 --- a/pallets/dmp-queue/src/lib.rs +++ b/pallets/dmp-queue/src/lib.rs @@ -90,9 +90,6 @@ pub mod pallet { /// Origin which is allowed to execute overweight messages. type ExecuteOverweightOrigin: EnsureOrigin; - - /// The origin that is allowed to resume or suspend the XCMP queue. - type ControllerOrigin: EnsureOrigin; } /// The configuration. @@ -113,10 +110,6 @@ pub mod pallet { pub(super) type Overweight = StorageMap<_, Blake2_128Concat, OverweightIndex, (RelayBlockNumber, Vec), OptionQuery>; - /// Whether or not the DMP queue is suspended from executing incoming XCMs or not. - #[pallet::storage] - pub(super) type QueueSuspended = StorageValue<_, bool, ValueQuery>; - #[pallet::error] pub enum Error { /// The message index given is unknown. @@ -162,32 +155,6 @@ pub mod pallet { Self::deposit_event(Event::OverweightServiced(index, used)); Ok(Some(used.saturating_add(1_000_000)).into()) } - - /// Suspends all XCM executions for the DMP queue, regardless of the sender's origin. - /// - /// - `origin`: Must pass `ControllerOrigin`. - #[pallet::weight(T::DbWeight::get().writes(1))] - pub fn suspend_xcm_execution(origin: OriginFor) -> DispatchResult { - T::ControllerOrigin::ensure_origin(origin)?; - - QueueSuspended::::put(true); - - Ok(()) - } - - /// Resumes all XCM executions for the DMP queue. - /// - /// Note that this function doesn't change the status of the in/out bound channels. - /// - /// - `origin`: Must pass `ControllerOrigin`. - #[pallet::weight(T::DbWeight::get().writes(1))] - pub fn resume_xcm_execution(origin: OriginFor) -> DispatchResult { - T::ControllerOrigin::ensure_origin(origin)?; - - QueueSuspended::::put(false); - - Ok(()) - } } #[pallet::event] @@ -218,11 +185,6 @@ pub mod pallet { /// /// Returns the weight consumed by executing messages in the queue. fn service_queue(limit: Weight) -> Weight { - let suspended = QueueSuspended::::get(); - if suspended { - return 0 - } - PageIndex::::mutate(|page_index| Self::do_service_queue(limit, page_index)) } @@ -302,11 +264,6 @@ pub mod pallet { iter: impl Iterator)>, limit: Weight, ) -> Weight { - let suspended = QueueSuspended::::get(); - if suspended { - return 0 - } - let mut page_index = PageIndex::::get(); let config = Configuration::::get(); @@ -491,7 +448,6 @@ mod tests { type Event = Event; type XcmExecutor = MockExec; type ExecuteOverweightOrigin = frame_system::EnsureRoot; - type ControllerOrigin = frame_system::EnsureRoot; } pub(crate) fn new_test_ext() -> sp_io::TestExternalities { @@ -831,20 +787,4 @@ mod tests { assert_eq!(pages_queued(), 1); }); } - - #[test] - fn suspend_xcm_execution_works() { - new_test_ext().execute_with(|| { - QueueSuspended::::put(true); - - let incoming = [msg(1000), msg(1001)]; - enqueue(&incoming[..]); - - let weight_used = handle_messages(&incoming, 5000); - - assert_eq!(weight_used, 0); - assert_eq!(take_trace(), Vec::new()); - assert_eq!(pages_queued(), 1); - }); - } } diff --git a/parachain-template/runtime/src/lib.rs b/parachain-template/runtime/src/lib.rs index 501798f22a7..2412e5995c8 100644 --- a/parachain-template/runtime/src/lib.rs +++ b/parachain-template/runtime/src/lib.rs @@ -533,7 +533,6 @@ impl cumulus_pallet_dmp_queue::Config for Runtime { type Event = Event; type XcmExecutor = XcmExecutor; type ExecuteOverweightOrigin = EnsureRoot; - type ControllerOrigin = EnsureRoot; } parameter_types! { diff --git a/polkadot-parachains/rococo-parachain/src/lib.rs b/polkadot-parachains/rococo-parachain/src/lib.rs index 3eeb2248818..218078a4658 100644 --- a/polkadot-parachains/rococo-parachain/src/lib.rs +++ b/polkadot-parachains/rococo-parachain/src/lib.rs @@ -461,8 +461,7 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { impl cumulus_pallet_dmp_queue::Config for Runtime { type Event = Event; type XcmExecutor = XcmExecutor; - type ExecuteOverweightOrigin = EnsureRoot; - type ControllerOrigin = EnsureRoot; + type ExecuteOverweightOrigin = frame_system::EnsureRoot; } impl cumulus_ping::Config for Runtime { diff --git a/polkadot-parachains/statemine/src/lib.rs b/polkadot-parachains/statemine/src/lib.rs index 39d5c845c51..e2c37d533c0 100644 --- a/polkadot-parachains/statemine/src/lib.rs +++ b/polkadot-parachains/statemine/src/lib.rs @@ -610,14 +610,12 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type VersionWrapper = PolkadotXcm; type OriginConverter = XcmOriginToTransactDispatchOrigin; type ExecuteOverweightOrigin = EnsureRoot; - type ControllerOrigin = EnsureRoot; } impl cumulus_pallet_dmp_queue::Config for Runtime { type Event = Event; type XcmExecutor = XcmExecutor; type ExecuteOverweightOrigin = EnsureRoot; - type ControllerOrigin = EnsureRoot; } parameter_types! { diff --git a/polkadot-parachains/statemint/src/lib.rs b/polkadot-parachains/statemint/src/lib.rs index e26b87e7fcf..4a33d80bf09 100644 --- a/polkadot-parachains/statemint/src/lib.rs +++ b/polkadot-parachains/statemint/src/lib.rs @@ -630,7 +630,6 @@ impl cumulus_pallet_dmp_queue::Config for Runtime { type Event = Event; type XcmExecutor = XcmExecutor; type ExecuteOverweightOrigin = EnsureRoot; - type ControllerOrigin = EnsureRoot; } parameter_types! { diff --git a/polkadot-parachains/westmint/src/lib.rs b/polkadot-parachains/westmint/src/lib.rs index a961976811b..3463f1f8f7c 100644 --- a/polkadot-parachains/westmint/src/lib.rs +++ b/polkadot-parachains/westmint/src/lib.rs @@ -604,7 +604,6 @@ impl cumulus_pallet_dmp_queue::Config for Runtime { type Event = Event; type XcmExecutor = XcmExecutor; type ExecuteOverweightOrigin = EnsureRoot; - type ControllerOrigin = EnsureRoot; } parameter_types! { From 138169ecaa824ba72494ce297a4c78f56da0b803 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Mon, 24 Jan 2022 11:01:44 -0800 Subject: [PATCH 7/8] Change controller origin to either root or council-issued origin --- polkadot-parachains/statemine/src/lib.rs | 2 ++ polkadot-parachains/statemint/src/lib.rs | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/polkadot-parachains/statemine/src/lib.rs b/polkadot-parachains/statemine/src/lib.rs index e2c37d533c0..526b566b5a3 100644 --- a/polkadot-parachains/statemine/src/lib.rs +++ b/polkadot-parachains/statemine/src/lib.rs @@ -608,6 +608,8 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type XcmExecutor = XcmExecutor; type ChannelInfo = ParachainSystem; type VersionWrapper = PolkadotXcm; + type ControllerOrigin = + EnsureOneOf, EnsureXcm>>; type OriginConverter = XcmOriginToTransactDispatchOrigin; type ExecuteOverweightOrigin = EnsureRoot; } diff --git a/polkadot-parachains/statemint/src/lib.rs b/polkadot-parachains/statemint/src/lib.rs index 4a33d80bf09..21548886315 100644 --- a/polkadot-parachains/statemint/src/lib.rs +++ b/polkadot-parachains/statemint/src/lib.rs @@ -621,9 +621,10 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type XcmExecutor = XcmExecutor; type ChannelInfo = ParachainSystem; type VersionWrapper = PolkadotXcm; + type ControllerOrigin = + EnsureOneOf, EnsureXcm>>; type OriginConverter = XcmOriginToTransactDispatchOrigin; type ExecuteOverweightOrigin = EnsureRoot; - type ControllerOrigin = EnsureRoot; } impl cumulus_pallet_dmp_queue::Config for Runtime { From b60139f4b70adc26f3a88b6597e8a35010c2993d Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Mon, 24 Jan 2022 11:14:45 -0800 Subject: [PATCH 8/8] Rename to ControllerOriginConverter --- pallets/xcmp-queue/src/lib.rs | 8 +++++--- pallets/xcmp-queue/src/mock.rs | 2 +- parachain-template/runtime/src/lib.rs | 2 +- polkadot-parachains/rococo-parachain/src/lib.rs | 2 +- polkadot-parachains/statemine/src/lib.rs | 4 ++-- polkadot-parachains/statemint/src/lib.rs | 4 ++-- polkadot-parachains/westmint/src/lib.rs | 2 +- 7 files changed, 13 insertions(+), 11 deletions(-) diff --git a/pallets/xcmp-queue/src/lib.rs b/pallets/xcmp-queue/src/lib.rs index c0ec4cafa1f..39e972d6ebe 100644 --- a/pallets/xcmp-queue/src/lib.rs +++ b/pallets/xcmp-queue/src/lib.rs @@ -84,13 +84,15 @@ pub mod pallet { /// Means of converting an `Xcm` into a `VersionedXcm`. type VersionWrapper: WrapVersion; - type OriginConverter: ConvertOrigin; - /// The origin that is allowed to execute overweight messages. type ExecuteOverweightOrigin: EnsureOrigin; /// The origin that is allowed to resume or suspend the XCMP queue. type ControllerOrigin: EnsureOrigin; + + /// The conversion function used to attempt to convert an XCM `MultiLocation` origin to a + /// superuser origin. + type ControllerOriginConverter: ConvertOrigin; } #[pallet::hooks] @@ -690,7 +692,7 @@ impl Pallet { { let index = shuffled[shuffle_index]; let sender = status[index].sender; - let sender_origin = T::OriginConverter::convert_origin( + let sender_origin = T::ControllerOriginConverter::convert_origin( (1, Parachain(sender.into())), OriginKind::Superuser, ); diff --git a/pallets/xcmp-queue/src/mock.rs b/pallets/xcmp-queue/src/mock.rs index 4a5e9508dad..b783ddf11f4 100644 --- a/pallets/xcmp-queue/src/mock.rs +++ b/pallets/xcmp-queue/src/mock.rs @@ -185,9 +185,9 @@ impl Config for Test { type XcmExecutor = xcm_executor::XcmExecutor; type ChannelInfo = ParachainSystem; type VersionWrapper = (); - type OriginConverter = SystemParachainAsSuperuser; type ExecuteOverweightOrigin = EnsureRoot; type ControllerOrigin = EnsureRoot; + type ControllerOriginConverter = SystemParachainAsSuperuser; } pub fn new_test_ext() -> sp_io::TestExternalities { diff --git a/parachain-template/runtime/src/lib.rs b/parachain-template/runtime/src/lib.rs index 2412e5995c8..e04bbfbc04e 100644 --- a/parachain-template/runtime/src/lib.rs +++ b/parachain-template/runtime/src/lib.rs @@ -524,9 +524,9 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type XcmExecutor = XcmExecutor; type ChannelInfo = ParachainSystem; type VersionWrapper = (); - type OriginConverter = XcmOriginToTransactDispatchOrigin; type ExecuteOverweightOrigin = EnsureRoot; type ControllerOrigin = EnsureRoot; + type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; } impl cumulus_pallet_dmp_queue::Config for Runtime { diff --git a/polkadot-parachains/rococo-parachain/src/lib.rs b/polkadot-parachains/rococo-parachain/src/lib.rs index 218078a4658..fdef68a3da3 100644 --- a/polkadot-parachains/rococo-parachain/src/lib.rs +++ b/polkadot-parachains/rococo-parachain/src/lib.rs @@ -453,9 +453,9 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type XcmExecutor = XcmExecutor; type ChannelInfo = ParachainSystem; type VersionWrapper = (); - type OriginConverter = XcmOriginToTransactDispatchOrigin; type ExecuteOverweightOrigin = EnsureRoot; type ControllerOrigin = EnsureRoot; + type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; } impl cumulus_pallet_dmp_queue::Config for Runtime { diff --git a/polkadot-parachains/statemine/src/lib.rs b/polkadot-parachains/statemine/src/lib.rs index 526b566b5a3..de27fa64745 100644 --- a/polkadot-parachains/statemine/src/lib.rs +++ b/polkadot-parachains/statemine/src/lib.rs @@ -608,10 +608,10 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type XcmExecutor = XcmExecutor; type ChannelInfo = ParachainSystem; type VersionWrapper = PolkadotXcm; + type ExecuteOverweightOrigin = EnsureRoot; type ControllerOrigin = EnsureOneOf, EnsureXcm>>; - type OriginConverter = XcmOriginToTransactDispatchOrigin; - type ExecuteOverweightOrigin = EnsureRoot; + type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; } impl cumulus_pallet_dmp_queue::Config for Runtime { diff --git a/polkadot-parachains/statemint/src/lib.rs b/polkadot-parachains/statemint/src/lib.rs index 21548886315..22d5ac64022 100644 --- a/polkadot-parachains/statemint/src/lib.rs +++ b/polkadot-parachains/statemint/src/lib.rs @@ -621,10 +621,10 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type XcmExecutor = XcmExecutor; type ChannelInfo = ParachainSystem; type VersionWrapper = PolkadotXcm; + type ExecuteOverweightOrigin = EnsureRoot; type ControllerOrigin = EnsureOneOf, EnsureXcm>>; - type OriginConverter = XcmOriginToTransactDispatchOrigin; - type ExecuteOverweightOrigin = EnsureRoot; + type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; } impl cumulus_pallet_dmp_queue::Config for Runtime { diff --git a/polkadot-parachains/westmint/src/lib.rs b/polkadot-parachains/westmint/src/lib.rs index 3463f1f8f7c..04046e63a60 100644 --- a/polkadot-parachains/westmint/src/lib.rs +++ b/polkadot-parachains/westmint/src/lib.rs @@ -595,9 +595,9 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type XcmExecutor = XcmExecutor; type ChannelInfo = ParachainSystem; type VersionWrapper = PolkadotXcm; - type OriginConverter = XcmOriginToTransactDispatchOrigin; type ExecuteOverweightOrigin = EnsureRoot; type ControllerOrigin = EnsureRoot; + type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; } impl cumulus_pallet_dmp_queue::Config for Runtime {