Companion for Weight v1.5 (#1581)

* cargo test -p cumulus-primitives-utility

* cargo test -p cumulus-pallet-xcmp-queue

* cargo test -p cumulus-pallet-xcm

* cargo test -p cumulus-pallet-dmp-queue

* cargo test -p pallet-template

* cargo test -p cumulus-test-runtime

* fix weights

* fix more weights

* cargo test -p parachains-common

* cargo test -p parachain-template-runtime

* fix weights import

* cargo test -p collectives-polkadot-runtime

* cargo test -p contracts-rococo-runtime

* more

* unused

* fixes

* Update benchmarking.rs

* Update lib.rs

* Update lib.rs

* fix

* fix bug in conversion

* update lockfile for {"polkadot", "substrate"}

Co-authored-by: parity-processbot <>
This commit is contained in:
Shawn Tabrizi
2022-08-31 13:24:42 +01:00
committed by GitHub
parent 1ab196df49
commit 3fb9c8a7be
118 changed files with 2005 additions and 1885 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ use frame_system::RawOrigin;
benchmarks! {
set_config_with_u32 {}: update_resume_threshold(RawOrigin::Root, 100)
set_config_with_weight {}: update_weight_restrict_decay(RawOrigin::Root, 3_000_000 as Weight)
set_config_with_weight {}: update_weight_restrict_decay(RawOrigin::Root, Weight::from_ref_time(3_000_000))
}
impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
+39 -22
View File
@@ -130,7 +130,7 @@ pub mod pallet {
///
/// Events:
/// - `OverweightServiced`: On success.
#[pallet::weight((weight_limit.saturating_add(1_000_000), DispatchClass::Operational,))]
#[pallet::weight((weight_limit.saturating_add(Weight::from_ref_time(1_000_000)), DispatchClass::Operational,))]
pub fn service_overweight(
origin: OriginFor<T>,
index: OverweightIndex,
@@ -149,7 +149,7 @@ pub mod pallet {
.map_err(|_| Error::<T>::WeightOverLimit)?;
Overweight::<T>::remove(index);
Self::deposit_event(Event::OverweightServiced { index, used });
Ok(Some(used.saturating_add(1_000_000)).into())
Ok(Some(used.saturating_add(Weight::from_ref_time(1_000_000))).into())
}
/// Suspends all XCM executions for the XCMP queue, regardless of the sender's origin.
@@ -449,8 +449,8 @@ impl Default for QueueConfigData {
suspend_threshold: 2,
drop_threshold: 5,
resume_threshold: 1,
threshold_weight: 100_000,
weight_restrict_decay: 2,
threshold_weight: Weight::from_ref_time(100_000),
weight_restrict_decay: Weight::from_ref_time(2),
xcmp_max_individual_weight: 20 * WEIGHT_PER_MILLIS,
}
}
@@ -605,15 +605,28 @@ impl<T: Config> Pallet<T> {
Ok(xcm) => {
let location = (1, Parachain(sender.into()));
match T::XcmExecutor::execute_xcm(location, xcm, max_weight) {
Outcome::Error(e) =>
(Err(e), Event::Fail { message_hash: Some(hash), error: e, weight: 0 }),
Outcome::Complete(w) =>
(Ok(w), Event::Success { message_hash: Some(hash), weight: w }),
match T::XcmExecutor::execute_xcm(location, xcm, max_weight.ref_time()) {
Outcome::Error(e) => (
Err(e),
Event::Fail { message_hash: Some(hash), error: e, weight: Weight::zero() },
),
Outcome::Complete(w) => (
Ok(Weight::from_ref_time(w)),
Event::Success {
message_hash: Some(hash),
weight: Weight::from_ref_time(w),
},
),
// As far as the caller is concerned, this was dispatched without error, so
// we just report the weight used.
Outcome::Incomplete(w, e) =>
(Ok(w), Event::Fail { message_hash: Some(hash), error: e, weight: w }),
Outcome::Incomplete(w, e) => (
Ok(Weight::from_ref_time(w)),
Event::Fail {
message_hash: Some(hash),
error: e,
weight: Weight::from_ref_time(w),
},
),
}
},
Err(()) =>
@@ -632,7 +645,7 @@ impl<T: Config> Pallet<T> {
let data = <InboundXcmpMessages<T>>::get(sender, sent_at);
let mut last_remaining_fragments;
let mut remaining_fragments = &data[..];
let mut weight_used = 0;
let mut weight_used = Weight::zero();
match format {
XcmpMessageFormat::ConcatenatedVersionedXcm => {
while !remaining_fragments.is_empty() {
@@ -645,7 +658,7 @@ impl<T: Config> Pallet<T> {
match Self::handle_xcm_message(sender, sent_at, xcm, weight) {
Ok(used) => weight_used = weight_used.saturating_add(used),
Err(XcmError::WeightLimitReached(required))
if required > max_individual_weight =>
if required > max_individual_weight.ref_time() =>
{
// overweight - add to overweight queue and continue with message
// execution consuming the message.
@@ -654,12 +667,16 @@ impl<T: Config> Pallet<T> {
.saturating_sub(remaining_fragments.len());
let overweight_xcm = last_remaining_fragments[..msg_len].to_vec();
let index = Self::stash_overweight(sender, sent_at, overweight_xcm);
let e =
Event::OverweightEnqueued { sender, sent_at, index, required };
let e = Event::OverweightEnqueued {
sender,
sent_at,
index,
required: Weight::from_ref_time(required),
};
Self::deposit_event(e);
},
Err(XcmError::WeightLimitReached(required))
if required <= max_weight =>
if required <= max_weight.ref_time() =>
{
// That message didn't get processed this time because of being
// too heavy. We leave it around for next time and bail.
@@ -766,7 +783,7 @@ impl<T: Config> Pallet<T> {
let mut status = <InboundXcmpStatus<T>>::get(); // <- sorted.
if status.is_empty() {
return 0
return Weight::zero()
}
let QueueConfigData {
@@ -778,8 +795,8 @@ impl<T: Config> Pallet<T> {
} = <QueueConfig<T>>::get();
let mut shuffled = Self::create_shuffle(status.len());
let mut weight_used = 0;
let mut weight_available = 0;
let mut weight_used = Weight::new();
let mut weight_available = Weight::new();
// We don't want the possibility of a chain sending a series of really heavy messages and
// tying up the block's execution time from other chains. Therefore we execute any remaining
@@ -813,7 +830,7 @@ impl<T: Config> Pallet<T> {
// on the first round to unlocking everything, then we do so.
if shuffle_index < status.len() {
weight_available +=
(max_weight - weight_available) / (weight_restrict_decay + 1);
(max_weight - weight_available) / (weight_restrict_decay.ref_time() + 1);
if weight_available + threshold_weight > max_weight {
weight_available = max_weight;
}
@@ -824,7 +841,7 @@ impl<T: Config> Pallet<T> {
let weight_processed = if status[index].message_metadata.is_empty() {
debug_assert!(false, "channel exists in status; there must be messages; qed");
0
Weight::zero()
} else {
// Process up to one block's worth for now.
let weight_remaining = weight_available.saturating_sub(weight_used);
@@ -854,7 +871,7 @@ impl<T: Config> Pallet<T> {
// other channels a look in. If we've still not unlocked all weight, then we set them
// up for processing a second time anyway.
if !status[index].message_metadata.is_empty() &&
(weight_processed > 0 || weight_available != max_weight)
(weight_processed > Weight::zero() || weight_available != max_weight)
{
if shuffle_index + 1 == shuffled.len() {
// Only this queue left. Just run around this loop once more.
+6 -6
View File
@@ -25,7 +25,7 @@ pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
/// Migrates the pallet storage to the most recent version, checking and setting the
/// `StorageVersion`.
pub fn migrate_to_latest<T: Config>() -> Weight {
let mut weight = 0;
let mut weight = Weight::new();
if StorageVersion::get::<Pallet<T>>() == 0 {
weight += migrate_to_v1::<T>();
@@ -54,8 +54,8 @@ mod v0 {
suspend_threshold: 2,
drop_threshold: 5,
resume_threshold: 1,
threshold_weight: 100_000,
weight_restrict_decay: 2,
threshold_weight: Weight::from_ref_time(100_000),
weight_restrict_decay: Weight::from_ref_time(2),
}
}
}
@@ -102,8 +102,8 @@ mod tests {
suspend_threshold: 5,
drop_threshold: 12,
resume_threshold: 3,
threshold_weight: 333_333,
weight_restrict_decay: 1,
threshold_weight: Weight::from_ref_time(333_333),
weight_restrict_decay: Weight::one(),
};
new_test_ext().execute_with(|| {
@@ -122,7 +122,7 @@ mod tests {
assert_eq!(v0.resume_threshold, v1.resume_threshold);
assert_eq!(v0.threshold_weight, v1.threshold_weight);
assert_eq!(v0.weight_restrict_decay, v1.weight_restrict_decay);
assert_eq!(v1.xcmp_max_individual_weight, 20_000_000_000);
assert_eq!(v1.xcmp_max_individual_weight, Weight::from_ref_time(20_000_000_000));
});
}
}
+1 -1
View File
@@ -116,7 +116,7 @@ impl cumulus_pallet_parachain_system::Config for Test {
parameter_types! {
pub const RelayChain: MultiLocation = MultiLocation::parent();
pub Ancestry: MultiLocation = X1(Parachain(1u32.into())).into();
pub UnitWeightCost: Weight = 1_000_000;
pub UnitWeightCost: u64 = 1_000_000;
pub const MaxInstructions: u32 = 100;
}
+49 -16
View File
@@ -26,7 +26,7 @@ fn one_message_does_not_panic() {
let messages = vec![(Default::default(), 1u32.into(), message_format.as_slice())];
// This shouldn't cause a panic
XcmpQueue::handle_xcmp_messages(messages.into_iter(), Weight::max_value());
XcmpQueue::handle_xcmp_messages(messages.into_iter(), Weight::MAX);
})
}
@@ -43,7 +43,12 @@ fn bad_message_is_handled() {
InboundXcmpMessages::<Test>::insert(ParaId::from(1000), 1, bad_data);
let format = XcmpMessageFormat::ConcatenatedEncodedBlob;
// This should exit with an error.
XcmpQueue::process_xcmp_message(1000.into(), (1, format), 10_000_000_000, 10_000_000_000);
XcmpQueue::process_xcmp_message(
1000.into(),
(1, format),
Weight::from_ref_time(10_000_000_000),
Weight::from_ref_time(10_000_000_000),
);
});
}
@@ -61,7 +66,12 @@ fn handle_blob_message() {
];
InboundXcmpMessages::<Test>::insert(ParaId::from(1000), 1, bad_data);
let format = XcmpMessageFormat::ConcatenatedEncodedBlob;
XcmpQueue::process_xcmp_message(1000.into(), (1, format), 10_000_000_000, 10_000_000_000);
XcmpQueue::process_xcmp_message(
1000.into(),
(1, format),
Weight::from_ref_time(10_000_000_000),
Weight::from_ref_time(10_000_000_000),
);
});
}
@@ -73,7 +83,12 @@ fn handle_invalid_data() {
let data = Xcm::<Test>(vec![]).encode();
InboundXcmpMessages::<Test>::insert(ParaId::from(1000), 1, data);
let format = XcmpMessageFormat::ConcatenatedVersionedXcm;
XcmpQueue::process_xcmp_message(1000.into(), (1, format), 10_000_000_000, 10_000_000_000);
XcmpQueue::process_xcmp_message(
1000.into(),
(1, format),
Weight::from_ref_time(10_000_000_000),
Weight::from_ref_time(10_000_000_000),
);
});
}
@@ -81,7 +96,7 @@ fn handle_invalid_data() {
fn service_overweight_unknown() {
new_test_ext().execute_with(|| {
assert_noop!(
XcmpQueue::service_overweight(Origin::root(), 0, 1000),
XcmpQueue::service_overweight(Origin::root(), 0, Weight::from_ref_time(1000)),
Error::<Test>::BadOverweightIndex,
);
});
@@ -93,7 +108,10 @@ fn service_overweight_bad_xcm_format() {
let bad_xcm = vec![255];
Overweight::<Test>::insert(0, (ParaId::from(1000), 0, bad_xcm));
assert_noop!(XcmpQueue::service_overweight(Origin::root(), 0, 1000), Error::<Test>::BadXcm);
assert_noop!(
XcmpQueue::service_overweight(Origin::root(), 0, Weight::from_ref_time(1000)),
Error::<Test>::BadXcm
);
});
}
@@ -108,7 +126,7 @@ fn suspend_xcm_execution_works() {
let messages = vec![(ParaId::from(999), 1u32.into(), message_format.as_slice())];
// This should have executed the incoming XCM, because it came from a system parachain
XcmpQueue::handle_xcmp_messages(messages.into_iter(), Weight::max_value());
XcmpQueue::handle_xcmp_messages(messages.into_iter(), Weight::MAX);
let queued_xcm = InboundXcmpMessages::<Test>::get(ParaId::from(999), 1u32);
assert!(queued_xcm.is_empty());
@@ -116,7 +134,7 @@ fn suspend_xcm_execution_works() {
let messages = vec![(ParaId::from(2000), 1u32.into(), message_format.as_slice())];
// This shouldn't have executed the incoming XCM
XcmpQueue::handle_xcmp_messages(messages.into_iter(), Weight::max_value());
XcmpQueue::handle_xcmp_messages(messages.into_iter(), Weight::MAX);
let queued_xcm = InboundXcmpMessages::<Test>::get(ParaId::from(2000), 1u32);
assert_eq!(queued_xcm, xcm);
@@ -166,12 +184,21 @@ fn update_resume_threshold_works() {
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);
assert_eq!(data.threshold_weight, Weight::from_ref_time(100_000));
assert_ok!(XcmpQueue::update_threshold_weight(
Origin::root(),
Weight::from_ref_time(10_000)
));
assert_noop!(
XcmpQueue::update_threshold_weight(
Origin::signed(5),
Weight::from_ref_time(10_000_000)
),
BadOrigin
);
let data: QueueConfigData = <QueueConfig<Test>>::get();
assert_eq!(data.threshold_weight, 10_000);
assert_eq!(data.threshold_weight, Weight::from_ref_time(10_000));
});
}
@@ -179,12 +206,18 @@ fn update_threshold_weight_works() {
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);
assert_eq!(data.weight_restrict_decay, Weight::from_ref_time(2));
assert_ok!(XcmpQueue::update_weight_restrict_decay(
Origin::root(),
Weight::from_ref_time(5)
));
assert_noop!(
XcmpQueue::update_weight_restrict_decay(Origin::signed(6), Weight::from_ref_time(4)),
BadOrigin
);
let data: QueueConfigData = <QueueConfig<Test>>::get();
assert_eq!(data.weight_restrict_decay, 5);
assert_eq!(data.weight_restrict_decay, Weight::from_ref_time(5));
});
}
+13 -13
View File
@@ -3,7 +3,7 @@
use frame_support::{
traits::Get,
weights::{constants::RocksDbWeight, Weight},
weights::{constants::RocksDbWeight, RefTimeWeight, Weight},
};
use sp_std::marker::PhantomData;
@@ -18,31 +18,31 @@ pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: XcmpQueue QueueConfig (r:1 w:1)
fn set_config_with_u32() -> Weight {
(2_717_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
Weight::from_ref_time(2_717_000 as RefTimeWeight)
.saturating_add(T::DbWeight::get().reads(1 as RefTimeWeight))
.saturating_add(T::DbWeight::get().writes(1 as RefTimeWeight))
}
// Storage: XcmpQueue QueueConfig (r:1 w:1)
fn set_config_with_weight() -> Weight {
(2_717_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
Weight::from_ref_time(2_717_000 as RefTimeWeight)
.saturating_add(T::DbWeight::get().reads(1 as RefTimeWeight))
.saturating_add(T::DbWeight::get().writes(1 as RefTimeWeight))
}
}
impl WeightInfo for () {
// Storage: XcmpQueue QueueConfig (r:1 w:1)
fn set_config_with_u32() -> Weight {
(2_717_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
Weight::from_ref_time(2_717_000 as RefTimeWeight)
.saturating_add(RocksDbWeight::get().reads(1 as RefTimeWeight))
.saturating_add(RocksDbWeight::get().writes(1 as RefTimeWeight))
}
// Storage: XcmpQueue QueueConfig (r:1 w:1)
fn set_config_with_weight() -> Weight {
(2_717_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
Weight::from_ref_time(2_717_000 as RefTimeWeight)
.saturating_add(RocksDbWeight::get().reads(1 as RefTimeWeight))
.saturating_add(RocksDbWeight::get().writes(1 as RefTimeWeight))
}
}