From ddc8eca8bca651377e724cf8cc5fb098bea2e334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Tue, 27 Aug 2024 13:11:56 +0200 Subject: [PATCH] fix: pallet-emergency para-xcm should not wrap XcmpMessageHandler (#53) --- pallets/emergency-para-xcm/src/lib.rs | 27 ++++--------------------- pallets/emergency-para-xcm/src/mock.rs | 3 +-- pallets/emergency-para-xcm/src/tests.rs | 19 ----------------- 3 files changed, 5 insertions(+), 44 deletions(-) diff --git a/pallets/emergency-para-xcm/src/lib.rs b/pallets/emergency-para-xcm/src/lib.rs index 0a113d6..7230e1b 100644 --- a/pallets/emergency-para-xcm/src/lib.rs +++ b/pallets/emergency-para-xcm/src/lib.rs @@ -33,7 +33,7 @@ //! In particular: //! * `CheckAssociatedRelayNumber` is used to check the relay chain block diff and //! enter emergency mode when appropriate. -//! * `QueuePausedQuery` and `XcmpMessageHandler` are used to pause XCM execution +//! * `QueuePausedQuery` is used to pause XCM execution #![allow(non_camel_case_types)] #![cfg_attr(not(feature = "std"), no_std)] @@ -52,7 +52,7 @@ use frame_support::traits::{ProcessMessage, QueuePausedQuery}; use frame_system::pallet_prelude::*; use frame_system::{RawOrigin, WeightInfo}; use parity_scale_codec::{Decode, Encode}; -use polkadot_parachain_primitives::primitives::{Id, RelayChainBlockNumber, XcmpMessageHandler}; +use polkadot_parachain_primitives::primitives::RelayChainBlockNumber; #[derive(Decode, Default, Encode, PartialEq, TypeInfo)] /// XCM Execution mode @@ -77,10 +77,8 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config - + cumulus_pallet_parachain_system::Config< - CheckAssociatedRelayNumber = Pallet, - XcmpMessageHandler = Pallet, - > + pallet_message_queue::Config> + + cumulus_pallet_parachain_system::Config> + + pallet_message_queue::Config> { /// Overarching event type type RuntimeEvent: From + IsType<::RuntimeEvent>; @@ -93,9 +91,6 @@ pub mod pallet { /// what would be passed to `pallet_message_queue` if this pallet was not being used. type QueuePausedQuery: QueuePausedQuery<::Origin>; - /// The XCMP handler to be used in normal operating mode - type XcmpMessageHandler: XcmpMessageHandler; - /// Maximum number of relay block to skip before trigering the Paused mode. type PausedThreshold: Get; @@ -183,20 +178,6 @@ impl CheckAssociatedRelayNumber for Pallet { } } -impl XcmpMessageHandler for Pallet { - fn handle_xcmp_messages<'a, I: Iterator>( - iter: I, - limit: Weight, - ) -> Weight { - match Mode::::get() { - XcmMode::Normal => ::XcmpMessageHandler::handle_xcmp_messages(iter, limit), - XcmMode::Paused => { - ::XcmpMessageHandler::handle_xcmp_messages(iter, Weight::zero()) - } - } - } -} - impl QueuePausedQuery<::Origin> for Pallet where T: Config, diff --git a/pallets/emergency-para-xcm/src/mock.rs b/pallets/emergency-para-xcm/src/mock.rs index 7c4c029..f742961 100644 --- a/pallets/emergency-para-xcm/src/mock.rs +++ b/pallets/emergency-para-xcm/src/mock.rs @@ -89,7 +89,7 @@ impl cumulus_pallet_parachain_system::Config for Test { type SelfParaId = ParachainId; type OnSystemEvent = (); type OutboundXcmpMessageSource = (); - type XcmpMessageHandler = EmergencyParaXcm; + type XcmpMessageHandler = JustConsumeAllWeight; type ReservedXcmpWeight = (); type DmpQueue = frame_support::traits::EnqueueWithOrigin; type ReservedDmpWeight = (); @@ -124,7 +124,6 @@ impl Config for Test { type RuntimeEvent = RuntimeEvent; type CheckAssociatedRelayNumber = cumulus_pallet_parachain_system::AnyRelayNumber; type QueuePausedQuery = (); - type XcmpMessageHandler = JustConsumeAllWeight; type PausedThreshold = ConstU32; type FastAuthorizeUpgradeOrigin = EnsureRoot; type PausedToNormalOrigin = EnsureRoot; diff --git a/pallets/emergency-para-xcm/src/tests.rs b/pallets/emergency-para-xcm/src/tests.rs index d80bbbf..d013493 100644 --- a/pallets/emergency-para-xcm/src/tests.rs +++ b/pallets/emergency-para-xcm/src/tests.rs @@ -106,25 +106,6 @@ fn pauses_queue_on_paused_mode() { }); } -#[test] -fn uses_all_xcmp_weight_on_normal_mode() { - new_test_ext().execute_with(|| { - let msgs = vec![(100.into(), 1, [8_u8].as_slice())]; - let assigned_weight = EmergencyParaXcm::handle_xcmp_messages(msgs.into_iter(), Weight::MAX); - assert_eq!(assigned_weight, Weight::MAX); - }); -} - -#[test] -fn uses_no_xcmp_weight_on_paused_mode() { - new_test_ext().execute_with(|| { - Mode::::set(XcmMode::Paused); - let msgs = vec![(100.into(), 1, [8_u8].as_slice())]; - let assigned_weight = EmergencyParaXcm::handle_xcmp_messages(msgs.into_iter(), Weight::MAX); - assert_eq!(assigned_weight, Weight::zero()); - }); -} - #[test] fn cannot_authorize_upgrade_with_wrong_origin() { new_test_ext().execute_with(|| {