Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pallet-emergency para-xcm should not wrap XcmpMessageHandler #53

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading