Skip to content

Commit

Permalink
fix: pallet-emergency para-xcm should not wrap XcmpMessageHandler (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
librelois authored Aug 27, 2024
1 parent c4f6184 commit ddc8eca
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 44 deletions.
27 changes: 4 additions & 23 deletions pallets/emergency-para-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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
Expand All @@ -77,10 +77,8 @@ pub mod pallet {
#[pallet::config]
pub trait Config:
frame_system::Config
+ cumulus_pallet_parachain_system::Config<
CheckAssociatedRelayNumber = Pallet<Self>,
XcmpMessageHandler = Pallet<Self>,
> + pallet_message_queue::Config<QueuePausedQuery = Pallet<Self>>
+ cumulus_pallet_parachain_system::Config<CheckAssociatedRelayNumber = Pallet<Self>>
+ pallet_message_queue::Config<QueuePausedQuery = Pallet<Self>>
{
/// Overarching event type
type RuntimeEvent: From<Event> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
Expand All @@ -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<<Self::MessageProcessor as ProcessMessage>::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<RelayChainBlockNumber>;

Expand Down Expand Up @@ -183,20 +178,6 @@ impl<T: Config> CheckAssociatedRelayNumber for Pallet<T> {
}
}

impl<T: Config> XcmpMessageHandler for Pallet<T> {
fn handle_xcmp_messages<'a, I: Iterator<Item = (Id, RelayChainBlockNumber, &'a [u8])>>(
iter: I,
limit: Weight,
) -> Weight {
match Mode::<T>::get() {
XcmMode::Normal => <T as Config>::XcmpMessageHandler::handle_xcmp_messages(iter, limit),
XcmMode::Paused => {
<T as Config>::XcmpMessageHandler::handle_xcmp_messages(iter, Weight::zero())
}
}
}
}

impl<T> QueuePausedQuery<<T::MessageProcessor as ProcessMessage>::Origin> for Pallet<T>
where
T: Config,
Expand Down
3 changes: 1 addition & 2 deletions pallets/emergency-para-xcm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MessageQueue, RelayOrigin>;
type ReservedDmpWeight = ();
Expand Down Expand Up @@ -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<PAUSED_THRESHOLD>;
type FastAuthorizeUpgradeOrigin = EnsureRoot<AccountId>;
type PausedToNormalOrigin = EnsureRoot<AccountId>;
Expand Down
19 changes: 0 additions & 19 deletions pallets/emergency-para-xcm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Test>::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(|| {
Expand Down

0 comments on commit ddc8eca

Please sign in to comment.