mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 09:21:04 +00:00
Add Setter for XCMP QueueConfigData (#931)
* add QueueConfigData setter * update weights * syntax change * add test case * fix Result error * cargo fmt * Apply suggestions from code review Co-authored-by: Alexander Popiak <alexander.popiak@gmail.com> * update * one call per set * cargo fmt * cargo fmt * mutate method * cargo fmt Co-authored-by: Alexander Popiak <alexander.popiak@gmail.com>
This commit is contained in:
@@ -167,6 +167,86 @@ pub mod pallet {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Overwrites the number of pages of messages which must be in the queue for the other side to be told to
|
||||||
|
/// suspend their sending.
|
||||||
|
///
|
||||||
|
/// - `origin`: Must pass `Root`.
|
||||||
|
/// - `new`: Desired value for `QueueConfigData.suspend_value`
|
||||||
|
#[pallet::weight(10_000_000 as Weight + T::DbWeight::get().reads_writes(1, 1))]
|
||||||
|
pub fn update_suspend_threshold(origin: OriginFor<T>, new: u32) -> DispatchResult {
|
||||||
|
ensure_root(origin)?;
|
||||||
|
QueueConfig::<T>::mutate(|data| data.suspend_threshold = new);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Overwrites the number of pages of messages which must be in the queue after which we drop any further
|
||||||
|
/// messages from the channel.
|
||||||
|
///
|
||||||
|
/// - `origin`: Must pass `Root`.
|
||||||
|
/// - `new`: Desired value for `QueueConfigData.drop_threshold`
|
||||||
|
#[pallet::weight(10_000_000 as Weight + T::DbWeight::get().reads_writes(1, 1))]
|
||||||
|
pub fn update_drop_threshold(origin: OriginFor<T>, new: u32) -> DispatchResult {
|
||||||
|
ensure_root(origin)?;
|
||||||
|
QueueConfig::<T>::mutate(|data| data.drop_threshold = new);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Overwrites the number of pages of messages which the queue must be reduced to before it signals that
|
||||||
|
/// message sending may recommence after it has been suspended.
|
||||||
|
///
|
||||||
|
/// - `origin`: Must pass `Root`.
|
||||||
|
/// - `new`: Desired value for `QueueConfigData.resume_threshold`
|
||||||
|
#[pallet::weight(10_000_000 as Weight + T::DbWeight::get().reads_writes(1, 1))]
|
||||||
|
pub fn update_resume_threshold(origin: OriginFor<T>, new: u32) -> DispatchResult {
|
||||||
|
ensure_root(origin)?;
|
||||||
|
QueueConfig::<T>::mutate(|data| data.resume_threshold = new);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Overwrites the amount of remaining weight under which we stop processing messages.
|
||||||
|
///
|
||||||
|
/// - `origin`: Must pass `Root`.
|
||||||
|
/// - `new`: Desired value for `QueueConfigData.threshold_weight`
|
||||||
|
#[pallet::weight(10_000_000 as Weight + T::DbWeight::get().reads_writes(1, 1))]
|
||||||
|
pub fn update_threshold_weight(origin: OriginFor<T>, new: Weight) -> DispatchResult {
|
||||||
|
ensure_root(origin)?;
|
||||||
|
QueueConfig::<T>::mutate(|data| data.threshold_weight = new);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Overwrites the speed to which the available weight approaches the maximum weight.
|
||||||
|
/// A lower number results in a faster progression. A value of 1 makes the entire weight available initially.
|
||||||
|
///
|
||||||
|
/// - `origin`: Must pass `Root`.
|
||||||
|
/// - `new`: Desired value for `QueueConfigData.weight_restrict_decay`.
|
||||||
|
#[pallet::weight(10_000_000 as Weight + T::DbWeight::get().reads_writes(1, 1))]
|
||||||
|
pub fn update_weight_restrict_decay(origin: OriginFor<T>, new: Weight) -> DispatchResult {
|
||||||
|
ensure_root(origin)?;
|
||||||
|
QueueConfig::<T>::mutate(|data| data.weight_restrict_decay = new);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Overwrite the maximum amount of weight any individual message may consume.
|
||||||
|
/// Messages above this weight go into the overweight queue and may only be serviced explicitly.
|
||||||
|
///
|
||||||
|
/// - `origin`: Must pass `Root`.
|
||||||
|
/// - `new`: Desired value for `QueueConfigData.xcmp_max_individual_weight`.
|
||||||
|
#[pallet::weight(10_000_000 as Weight + T::DbWeight::get().reads_writes(1, 1))]
|
||||||
|
pub fn update_xcmp_max_individual_weight(
|
||||||
|
origin: OriginFor<T>,
|
||||||
|
new: Weight,
|
||||||
|
) -> DispatchResult {
|
||||||
|
ensure_root(origin)?;
|
||||||
|
QueueConfig::<T>::mutate(|data| data.xcmp_max_individual_weight = new);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pallet::event]
|
#[pallet::event]
|
||||||
|
|||||||
@@ -15,8 +15,9 @@
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use cumulus_primitives_core::XcmpMessageHandler;
|
use cumulus_primitives_core::XcmpMessageHandler;
|
||||||
use frame_support::assert_noop;
|
use frame_support::{assert_noop, assert_ok};
|
||||||
use mock::{new_test_ext, Call, Origin, Test, XcmpQueue};
|
use mock::{new_test_ext, Call, Origin, Test, XcmpQueue};
|
||||||
|
use sp_runtime::traits::BadOrigin;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn one_message_does_not_panic() {
|
fn one_message_does_not_panic() {
|
||||||
@@ -109,3 +110,87 @@ fn suspend_xcm_execution_works() {
|
|||||||
assert_eq!(queued_xcm, xcm);
|
assert_eq!(queued_xcm, xcm);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn update_suspend_threshold_works() {
|
||||||
|
new_test_ext().execute_with(|| {
|
||||||
|
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||||
|
assert_eq!(data.suspend_threshold, 2);
|
||||||
|
assert_ok!(XcmpQueue::update_suspend_threshold(Origin::root(), 3));
|
||||||
|
assert_noop!(XcmpQueue::update_suspend_threshold(Origin::signed(2), 5), BadOrigin);
|
||||||
|
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||||
|
|
||||||
|
assert_eq!(data.suspend_threshold, 3);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn update_drop_threshold_works() {
|
||||||
|
new_test_ext().execute_with(|| {
|
||||||
|
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||||
|
assert_eq!(data.drop_threshold, 5);
|
||||||
|
assert_ok!(XcmpQueue::update_drop_threshold(Origin::root(), 6));
|
||||||
|
assert_noop!(XcmpQueue::update_drop_threshold(Origin::signed(2), 7), BadOrigin);
|
||||||
|
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||||
|
|
||||||
|
assert_eq!(data.drop_threshold, 6);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn update_resume_threshold_works() {
|
||||||
|
new_test_ext().execute_with(|| {
|
||||||
|
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||||
|
assert_eq!(data.resume_threshold, 1);
|
||||||
|
assert_ok!(XcmpQueue::update_resume_threshold(Origin::root(), 2));
|
||||||
|
assert_noop!(XcmpQueue::update_resume_threshold(Origin::signed(7), 3), BadOrigin);
|
||||||
|
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||||
|
|
||||||
|
assert_eq!(data.resume_threshold, 2);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn update_threshold_weight_works() {
|
||||||
|
new_test_ext().execute_with(|| {
|
||||||
|
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||||
|
assert_eq!(data.threshold_weight, 100_000);
|
||||||
|
assert_ok!(XcmpQueue::update_threshold_weight(Origin::root(), 10_000));
|
||||||
|
assert_noop!(XcmpQueue::update_threshold_weight(Origin::signed(5), 10_000_000), BadOrigin);
|
||||||
|
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||||
|
|
||||||
|
assert_eq!(data.threshold_weight, 10_000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn update_weight_restrict_decay_works() {
|
||||||
|
new_test_ext().execute_with(|| {
|
||||||
|
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||||
|
assert_eq!(data.weight_restrict_decay, 2);
|
||||||
|
assert_ok!(XcmpQueue::update_weight_restrict_decay(Origin::root(), 5));
|
||||||
|
assert_noop!(XcmpQueue::update_weight_restrict_decay(Origin::signed(6), 4), BadOrigin);
|
||||||
|
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||||
|
|
||||||
|
assert_eq!(data.weight_restrict_decay, 5);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn update_xcmp_max_individual_weight() {
|
||||||
|
new_test_ext().execute_with(|| {
|
||||||
|
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||||
|
assert_eq!(data.xcmp_max_individual_weight, 20 * WEIGHT_PER_MILLIS);
|
||||||
|
assert_ok!(XcmpQueue::update_xcmp_max_individual_weight(
|
||||||
|
Origin::root(),
|
||||||
|
30 * WEIGHT_PER_MILLIS
|
||||||
|
));
|
||||||
|
assert_noop!(
|
||||||
|
XcmpQueue::update_xcmp_max_individual_weight(Origin::signed(3), 10 * WEIGHT_PER_MILLIS),
|
||||||
|
BadOrigin
|
||||||
|
);
|
||||||
|
let data: QueueConfigData = <QueueConfig<Test>>::get();
|
||||||
|
|
||||||
|
assert_eq!(data.xcmp_max_individual_weight, 30 * WEIGHT_PER_MILLIS);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user