Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add separate suspension flag specific to deferred queue
  • Loading branch information
apopiak committed Oct 3, 2023
commit 0f24a0a9b14886967096787e453ec331fe129f34
36 changes: 34 additions & 2 deletions pallets/xcmp-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,34 @@ pub mod pallet {
})?;
Ok(())
}

/// Suspends execution of deferred XCM for the XCMP queue, regardless of the sender's origin.
///
/// - `origin`: Must pass `ControllerOrigin`.
#[pallet::call_index(12)]
#[pallet::weight((T::DbWeight::get().writes(1), DispatchClass::Operational,))]
pub fn suspend_deferred_execution(origin: OriginFor<T>) -> DispatchResult {
T::ControllerOrigin::ensure_origin(origin)?;

DeferredQueueSuspended::<T>::put(true);

Ok(())
}

/// Resumes execution of deferred XCM for the XCMP queue.
///
/// Note that this function doesn't change the status of the in/out bound channels.
///
/// - `origin`: Must pass `ControllerOrigin`.
#[pallet::call_index(13)]
#[pallet::weight((T::DbWeight::get().writes(1), DispatchClass::Operational,))]
pub fn resume_deferred_execution(origin: OriginFor<T>) -> DispatchResult {
T::ControllerOrigin::ensure_origin(origin)?;

DeferredQueueSuspended::<T>::put(false);

Ok(())
}
}

#[pallet::event]
Expand Down Expand Up @@ -567,6 +595,10 @@ pub mod pallet {
/// Whether or not the XCMP queue is suspended from executing incoming XCMs or not.
#[pallet::storage]
pub(super) type QueueSuspended<T: Config> = StorageValue<_, bool, ValueQuery>;

/// Whether or not the Deferred queue is suspended from executing XCMs or not.
#[pallet::storage]
pub(super) type DeferredQueueSuspended<T: Config> = StorageValue<_, bool, ValueQuery>;
}

#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug, TypeInfo)]
Expand Down Expand Up @@ -1175,7 +1207,7 @@ impl<T: Config> Pallet<T> {
max_individual_weight: Weight,
) -> Weight {
let mut weight_used = Weight::zero();
if QueueSuspended::<T>::get() {
if QueueSuspended::<T>::get() || DeferredQueueSuspended::<T>::get() {
return weight_used;
}
let mut keys = DeferredIndices::<T>::iter_keys();
Expand Down Expand Up @@ -1204,7 +1236,7 @@ impl<T: Config> Pallet<T> {
max_individual_weight: Weight,
) -> Weight {
let mut weight_used = Weight::zero();
if QueueSuspended::<T>::get() {
if QueueSuspended::<T>::get() || DeferredQueueSuspended::<T>::get() {
return weight_used;
}

Expand Down
36 changes: 36 additions & 0 deletions pallets/xcmp-queue/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,42 @@ fn suspend_xcm_execution_works() {
});
}

#[test]
fn suspend_deferred_flag_suspends_deferred_execution() {
new_test_ext().execute_with(|| {
//Arrange
let versioned_xcm = create_versioned_reserve_asset_deposited();
let para_id = ParaId::from(999);
let mut xcmp_message = Vec::new();
let messages =
vec![(para_id, 1u32.into(), format_message(&mut xcmp_message, versioned_xcm.encode()))];

RelayBlockNumberProviderMock::set(1);
XcmpQueue::handle_xcmp_messages(messages.clone().into_iter(), Weight::MAX);
let deferred_message = DeferredMessage {
sent_at: 1u32.into(),
sender: para_id,
xcm: versioned_xcm.clone(),
deferred_to: 6,
};
assert_eq!(
DeferredMessageBuckets::<Test>::get(para_id, (6, 0)),
create_bounded_vec(vec![Some(deferred_message.clone())])
);

let QueueConfigData { xcmp_max_individual_weight, .. } = <QueueConfig<Test>>::get();

//Act
DeferredQueueSuspended::<Test>::put(true);
XcmpQueue::service_deferred_queues(Weight::MAX, 7, xcmp_max_individual_weight);

assert_eq!(
DeferredMessageBuckets::<Test>::get(para_id, (6, 0)),
create_bounded_vec(vec![Some(deferred_message)])
);
});
}

#[test]
fn suspend_also_suspends_deferred_execution() {
new_test_ext().execute_with(|| {
Expand Down