mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 10:31:03 +00:00
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:
@@ -20,7 +20,7 @@
|
||||
|
||||
use frame_support::{
|
||||
traits::Get,
|
||||
weights::{constants::RocksDbWeight, Weight},
|
||||
weights::{constants::RocksDbWeight, RefTimeWeight, Weight},
|
||||
};
|
||||
use sp_std::marker::PhantomData;
|
||||
|
||||
@@ -39,91 +39,143 @@ pub trait WeightInfo {
|
||||
pub struct SubstrateWeight<T>(PhantomData<T>);
|
||||
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
|
||||
fn set_invulnerables(b: u32) -> Weight {
|
||||
(18_563_000 as Weight)
|
||||
Weight::from_ref_time(18_563_000 as RefTimeWeight)
|
||||
// Standard Error: 0
|
||||
.saturating_add((68_000 as Weight).saturating_mul(b as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
.saturating_add(
|
||||
Weight::from_ref_time(68_000 as RefTimeWeight)
|
||||
.scalar_saturating_mul(b as RefTimeWeight),
|
||||
)
|
||||
.saturating_add(T::DbWeight::get().writes(1 as RefTimeWeight))
|
||||
}
|
||||
fn set_desired_candidates() -> Weight {
|
||||
(16_363_000 as Weight).saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
Weight::from_ref_time(16_363_000 as RefTimeWeight)
|
||||
.saturating_add(T::DbWeight::get().writes(1 as RefTimeWeight))
|
||||
}
|
||||
fn set_candidacy_bond() -> Weight {
|
||||
(16_840_000 as Weight).saturating_add(T::DbWeight::get().writes(1 as Weight))
|
||||
Weight::from_ref_time(16_840_000 as RefTimeWeight)
|
||||
.saturating_add(T::DbWeight::get().writes(1 as RefTimeWeight))
|
||||
}
|
||||
fn register_as_candidate(c: u32) -> Weight {
|
||||
(71_196_000 as Weight)
|
||||
Weight::from_ref_time(71_196_000 as RefTimeWeight)
|
||||
// Standard Error: 0
|
||||
.saturating_add((198_000 as Weight).saturating_mul(c as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(4 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
||||
.saturating_add(
|
||||
Weight::from_ref_time(198_000 as RefTimeWeight)
|
||||
.scalar_saturating_mul(c as RefTimeWeight),
|
||||
)
|
||||
.saturating_add(T::DbWeight::get().reads(4 as RefTimeWeight))
|
||||
.saturating_add(T::DbWeight::get().writes(2 as RefTimeWeight))
|
||||
}
|
||||
fn leave_intent(c: u32) -> Weight {
|
||||
(55_336_000 as Weight)
|
||||
Weight::from_ref_time(55_336_000 as RefTimeWeight)
|
||||
// Standard Error: 0
|
||||
.saturating_add((151_000 as Weight).saturating_mul(c as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(2 as Weight))
|
||||
.saturating_add(
|
||||
Weight::from_ref_time(151_000 as RefTimeWeight)
|
||||
.scalar_saturating_mul(c as RefTimeWeight),
|
||||
)
|
||||
.saturating_add(T::DbWeight::get().reads(1 as RefTimeWeight))
|
||||
.saturating_add(T::DbWeight::get().writes(2 as RefTimeWeight))
|
||||
}
|
||||
fn note_author() -> Weight {
|
||||
(71_461_000 as Weight)
|
||||
.saturating_add(T::DbWeight::get().reads(3 as Weight))
|
||||
.saturating_add(T::DbWeight::get().writes(4 as Weight))
|
||||
Weight::from_ref_time(71_461_000 as RefTimeWeight)
|
||||
.saturating_add(T::DbWeight::get().reads(3 as RefTimeWeight))
|
||||
.saturating_add(T::DbWeight::get().writes(4 as RefTimeWeight))
|
||||
}
|
||||
fn new_session(r: u32, c: u32) -> Weight {
|
||||
(0 as Weight)
|
||||
Weight::from_ref_time(0 as RefTimeWeight)
|
||||
// Standard Error: 1_010_000
|
||||
.saturating_add((109_961_000 as Weight).saturating_mul(r as Weight))
|
||||
.saturating_add(
|
||||
Weight::from_ref_time(109_961_000 as RefTimeWeight)
|
||||
.scalar_saturating_mul(r as RefTimeWeight),
|
||||
)
|
||||
// Standard Error: 1_010_000
|
||||
.saturating_add((151_952_000 as Weight).saturating_mul(c as Weight))
|
||||
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(r as Weight)))
|
||||
.saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(c as Weight)))
|
||||
.saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(r as Weight)))
|
||||
.saturating_add(T::DbWeight::get().writes((2 as Weight).saturating_mul(c as Weight)))
|
||||
.saturating_add(
|
||||
Weight::from_ref_time(151_952_000 as RefTimeWeight)
|
||||
.scalar_saturating_mul(c as RefTimeWeight),
|
||||
)
|
||||
.saturating_add(
|
||||
T::DbWeight::get().reads((1 as RefTimeWeight).saturating_mul(r as RefTimeWeight)),
|
||||
)
|
||||
.saturating_add(
|
||||
T::DbWeight::get().reads((2 as RefTimeWeight).saturating_mul(c as RefTimeWeight)),
|
||||
)
|
||||
.saturating_add(
|
||||
T::DbWeight::get().writes((2 as RefTimeWeight).saturating_mul(r as RefTimeWeight)),
|
||||
)
|
||||
.saturating_add(
|
||||
T::DbWeight::get().writes((2 as RefTimeWeight).saturating_mul(c as RefTimeWeight)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// For backwards compatibility and tests
|
||||
impl WeightInfo for () {
|
||||
fn set_invulnerables(b: u32) -> Weight {
|
||||
(18_563_000 as Weight)
|
||||
Weight::from_ref_time(18_563_000 as RefTimeWeight)
|
||||
// Standard Error: 0
|
||||
.saturating_add((68_000 as Weight).saturating_mul(b as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
.saturating_add(
|
||||
Weight::from_ref_time(68_000 as RefTimeWeight)
|
||||
.scalar_saturating_mul(b as RefTimeWeight),
|
||||
)
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as RefTimeWeight))
|
||||
}
|
||||
fn set_desired_candidates() -> Weight {
|
||||
(16_363_000 as Weight).saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
Weight::from_ref_time(16_363_000 as RefTimeWeight)
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as RefTimeWeight))
|
||||
}
|
||||
fn set_candidacy_bond() -> Weight {
|
||||
(16_840_000 as Weight).saturating_add(RocksDbWeight::get().writes(1 as Weight))
|
||||
Weight::from_ref_time(16_840_000 as RefTimeWeight)
|
||||
.saturating_add(RocksDbWeight::get().writes(1 as RefTimeWeight))
|
||||
}
|
||||
fn register_as_candidate(c: u32) -> Weight {
|
||||
(71_196_000 as Weight)
|
||||
Weight::from_ref_time(71_196_000 as RefTimeWeight)
|
||||
// Standard Error: 0
|
||||
.saturating_add((198_000 as Weight).saturating_mul(c as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
|
||||
.saturating_add(
|
||||
Weight::from_ref_time(198_000 as RefTimeWeight)
|
||||
.scalar_saturating_mul(c as RefTimeWeight),
|
||||
)
|
||||
.saturating_add(RocksDbWeight::get().reads(4 as RefTimeWeight))
|
||||
.saturating_add(RocksDbWeight::get().writes(2 as RefTimeWeight))
|
||||
}
|
||||
fn leave_intent(c: u32) -> Weight {
|
||||
(55_336_000 as Weight)
|
||||
Weight::from_ref_time(55_336_000 as RefTimeWeight)
|
||||
// Standard Error: 0
|
||||
.saturating_add((151_000 as Weight).saturating_mul(c as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(2 as Weight))
|
||||
.saturating_add(
|
||||
Weight::from_ref_time(151_000 as RefTimeWeight)
|
||||
.scalar_saturating_mul(c as RefTimeWeight),
|
||||
)
|
||||
.saturating_add(RocksDbWeight::get().reads(1 as RefTimeWeight))
|
||||
.saturating_add(RocksDbWeight::get().writes(2 as RefTimeWeight))
|
||||
}
|
||||
fn note_author() -> Weight {
|
||||
(71_461_000 as Weight)
|
||||
.saturating_add(RocksDbWeight::get().reads(3 as Weight))
|
||||
.saturating_add(RocksDbWeight::get().writes(4 as Weight))
|
||||
Weight::from_ref_time(71_461_000 as RefTimeWeight)
|
||||
.saturating_add(RocksDbWeight::get().reads(3 as RefTimeWeight))
|
||||
.saturating_add(RocksDbWeight::get().writes(4 as RefTimeWeight))
|
||||
}
|
||||
fn new_session(r: u32, c: u32) -> Weight {
|
||||
(0 as Weight)
|
||||
Weight::from_ref_time(0 as RefTimeWeight)
|
||||
// Standard Error: 1_010_000
|
||||
.saturating_add((109_961_000 as Weight).saturating_mul(r as Weight))
|
||||
.saturating_add(
|
||||
Weight::from_ref_time(109_961_000 as RefTimeWeight)
|
||||
.scalar_saturating_mul(r as RefTimeWeight),
|
||||
)
|
||||
// Standard Error: 1_010_000
|
||||
.saturating_add((151_952_000 as Weight).saturating_mul(c as Weight))
|
||||
.saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(r as Weight)))
|
||||
.saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(c as Weight)))
|
||||
.saturating_add(RocksDbWeight::get().writes((2 as Weight).saturating_mul(r as Weight)))
|
||||
.saturating_add(RocksDbWeight::get().writes((2 as Weight).saturating_mul(c as Weight)))
|
||||
.saturating_add(
|
||||
Weight::from_ref_time(151_952_000 as RefTimeWeight)
|
||||
.scalar_saturating_mul(c as RefTimeWeight),
|
||||
)
|
||||
.saturating_add(
|
||||
RocksDbWeight::get().reads((1 as RefTimeWeight).saturating_mul(r as RefTimeWeight)),
|
||||
)
|
||||
.saturating_add(
|
||||
RocksDbWeight::get().reads((2 as RefTimeWeight).saturating_mul(c as RefTimeWeight)),
|
||||
)
|
||||
.saturating_add(
|
||||
RocksDbWeight::get()
|
||||
.writes((2 as RefTimeWeight).saturating_mul(r as RefTimeWeight)),
|
||||
)
|
||||
.saturating_add(
|
||||
RocksDbWeight::get()
|
||||
.writes((2 as RefTimeWeight).saturating_mul(c as RefTimeWeight)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ pub mod pallet {
|
||||
///
|
||||
/// Events:
|
||||
/// - `OverweightServiced`: On success.
|
||||
#[pallet::weight(weight_limit.saturating_add(1_000_000))]
|
||||
#[pallet::weight(weight_limit.saturating_add(Weight::from_ref_time(1_000_000)))]
|
||||
pub fn service_overweight(
|
||||
origin: OriginFor<T>,
|
||||
index: OverweightIndex,
|
||||
@@ -153,7 +153,7 @@ pub mod pallet {
|
||||
.map_err(|_| Error::<T>::OverLimit)?;
|
||||
Overweight::<T>::remove(index);
|
||||
Self::deposit_event(Event::OverweightServiced { overweight_index: index, weight_used });
|
||||
Ok(Some(weight_used.saturating_add(1_000_000)).into())
|
||||
Ok(Some(weight_used.saturating_add(Weight::from_ref_time(1_000_000))).into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ pub mod pallet {
|
||||
/// Exactly equivalent to `service_queue` but expects a mutable `page_index` to be passed
|
||||
/// in and any changes stored.
|
||||
fn do_service_queue(limit: Weight, page_index: &mut PageIndexData) -> Weight {
|
||||
let mut used = 0;
|
||||
let mut used = Weight::new();
|
||||
while page_index.begin_used < page_index.end_used {
|
||||
let page = Pages::<T>::take(page_index.begin_used);
|
||||
for (i, &(sent_at, ref data)) in page.iter().enumerate() {
|
||||
@@ -232,19 +232,19 @@ pub mod pallet {
|
||||
match maybe_msg {
|
||||
Err(_) => {
|
||||
Self::deposit_event(Event::InvalidFormat { message_id });
|
||||
Ok(0)
|
||||
Ok(Weight::zero())
|
||||
},
|
||||
Ok(Err(())) => {
|
||||
Self::deposit_event(Event::UnsupportedVersion { message_id });
|
||||
Ok(0)
|
||||
Ok(Weight::zero())
|
||||
},
|
||||
Ok(Ok(x)) => {
|
||||
let outcome = T::XcmExecutor::execute_xcm(Parent, x, limit);
|
||||
let outcome = T::XcmExecutor::execute_xcm(Parent, x, limit.ref_time());
|
||||
match outcome {
|
||||
Outcome::Error(XcmError::WeightLimitReached(required)) =>
|
||||
Err((message_id, required)),
|
||||
Err((message_id, Weight::from_ref_time(required))),
|
||||
outcome => {
|
||||
let weight_used = outcome.weight_used();
|
||||
let weight_used = Weight::from_ref_time(outcome.weight_used());
|
||||
Self::deposit_event(Event::ExecutedDownward { message_id, outcome });
|
||||
Ok(weight_used)
|
||||
},
|
||||
@@ -349,7 +349,7 @@ mod tests {
|
||||
};
|
||||
use sp_version::RuntimeVersion;
|
||||
use std::cell::RefCell;
|
||||
use xcm::latest::{MultiLocation, OriginKind};
|
||||
use xcm::latest::{MultiLocation, OriginKind, Weight as XCMWeight};
|
||||
|
||||
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
|
||||
type Block = frame_system::mocking::MockBlock<Test>;
|
||||
@@ -379,8 +379,8 @@ mod tests {
|
||||
state_version: 1,
|
||||
};
|
||||
pub const ParachainId: ParaId = ParaId::new(200);
|
||||
pub const ReservedXcmpWeight: Weight = 0;
|
||||
pub const ReservedDmpWeight: Weight = 0;
|
||||
pub const ReservedXcmpWeight: Weight = Weight::zero();
|
||||
pub const ReservedDmpWeight: Weight = Weight::zero();
|
||||
}
|
||||
|
||||
type AccountId = u64;
|
||||
@@ -429,8 +429,8 @@ mod tests {
|
||||
fn execute_xcm_in_credit(
|
||||
_origin: impl Into<MultiLocation>,
|
||||
message: Xcm,
|
||||
weight_limit: Weight,
|
||||
_credit: Weight,
|
||||
weight_limit: XCMWeight,
|
||||
_credit: XCMWeight,
|
||||
) -> Outcome {
|
||||
let o = match (message.0.len(), &message.0.first()) {
|
||||
(1, Some(Transact { require_weight_at_most, .. })) => {
|
||||
@@ -478,7 +478,7 @@ mod tests {
|
||||
DmpQueue::handle_dmp_messages(iter, limit)
|
||||
}
|
||||
|
||||
fn msg(weight: Weight) -> Xcm {
|
||||
fn msg(weight: XCMWeight) -> Xcm {
|
||||
Xcm(vec![Transact {
|
||||
origin_type: OriginKind::Native,
|
||||
require_weight_at_most: weight,
|
||||
@@ -486,11 +486,11 @@ mod tests {
|
||||
}])
|
||||
}
|
||||
|
||||
fn msg_complete(weight: Weight) -> (Xcm, Outcome) {
|
||||
fn msg_complete(weight: XCMWeight) -> (Xcm, Outcome) {
|
||||
(msg(weight), Outcome::Complete(weight))
|
||||
}
|
||||
|
||||
fn msg_limit_reached(weight: Weight) -> (Xcm, Outcome) {
|
||||
fn msg_limit_reached(weight: XCMWeight) -> (Xcm, Outcome) {
|
||||
(msg(weight), Outcome::Error(XcmError::WeightLimitReached(weight)))
|
||||
}
|
||||
|
||||
@@ -511,8 +511,8 @@ mod tests {
|
||||
#[test]
|
||||
fn basic_setup_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let weight_used = handle_messages(&[], 1000);
|
||||
assert_eq!(weight_used, 0);
|
||||
let weight_used = handle_messages(&[], Weight::from_ref_time(1000));
|
||||
assert_eq!(weight_used, Weight::zero());
|
||||
assert_eq!(take_trace(), Vec::new());
|
||||
assert!(queue_is_empty());
|
||||
});
|
||||
@@ -522,8 +522,8 @@ mod tests {
|
||||
fn service_inline_complete_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let incoming = vec![msg(1000), msg(1001)];
|
||||
let weight_used = handle_messages(&incoming, 2500);
|
||||
assert_eq!(weight_used, 2001);
|
||||
let weight_used = handle_messages(&incoming, Weight::from_ref_time(2500));
|
||||
assert_eq!(weight_used, Weight::from_ref_time(2001));
|
||||
assert_eq!(take_trace(), vec![msg_complete(1000), msg_complete(1001)]);
|
||||
assert!(queue_is_empty());
|
||||
});
|
||||
@@ -534,8 +534,8 @@ mod tests {
|
||||
new_test_ext().execute_with(|| {
|
||||
let enqueued = vec![msg(1000), msg(1001), msg(1002)];
|
||||
enqueue(&enqueued);
|
||||
let weight_used = handle_messages(&[], 2500);
|
||||
assert_eq!(weight_used, 2001);
|
||||
let weight_used = handle_messages(&[], Weight::from_ref_time(2500));
|
||||
assert_eq!(weight_used, Weight::from_ref_time(2001));
|
||||
assert_eq!(
|
||||
take_trace(),
|
||||
vec![msg_complete(1000), msg_complete(1001), msg_limit_reached(1002),]
|
||||
@@ -547,8 +547,8 @@ mod tests {
|
||||
fn enqueue_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let incoming = vec![msg(1000), msg(1001), msg(1002)];
|
||||
let weight_used = handle_messages(&incoming, 999);
|
||||
assert_eq!(weight_used, 0);
|
||||
let weight_used = handle_messages(&incoming, Weight::from_ref_time(999));
|
||||
assert_eq!(weight_used, Weight::zero());
|
||||
assert_eq!(
|
||||
PageIndex::<Test>::get(),
|
||||
PageIndexData { begin_used: 0, end_used: 1, overweight_count: 0 }
|
||||
@@ -556,15 +556,15 @@ mod tests {
|
||||
assert_eq!(Pages::<Test>::get(0).len(), 3);
|
||||
assert_eq!(take_trace(), vec![msg_limit_reached(1000)]);
|
||||
|
||||
let weight_used = handle_messages(&[], 2500);
|
||||
assert_eq!(weight_used, 2001);
|
||||
let weight_used = handle_messages(&[], Weight::from_ref_time(2500));
|
||||
assert_eq!(weight_used, Weight::from_ref_time(2001));
|
||||
assert_eq!(
|
||||
take_trace(),
|
||||
vec![msg_complete(1000), msg_complete(1001), msg_limit_reached(1002),]
|
||||
);
|
||||
|
||||
let weight_used = handle_messages(&[], 2500);
|
||||
assert_eq!(weight_used, 1002);
|
||||
let weight_used = handle_messages(&[], Weight::from_ref_time(2500));
|
||||
assert_eq!(weight_used, Weight::from_ref_time(1002));
|
||||
assert_eq!(take_trace(), vec![msg_complete(1002),]);
|
||||
assert!(queue_is_empty());
|
||||
});
|
||||
@@ -574,14 +574,14 @@ mod tests {
|
||||
fn service_inline_then_enqueue_works() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let incoming = vec![msg(1000), msg(1001), msg(1002)];
|
||||
let weight_used = handle_messages(&incoming, 1500);
|
||||
assert_eq!(weight_used, 1000);
|
||||
let weight_used = handle_messages(&incoming, Weight::from_ref_time(1500));
|
||||
assert_eq!(weight_used, Weight::from_ref_time(1000));
|
||||
assert_eq!(pages_queued(), 1);
|
||||
assert_eq!(Pages::<Test>::get(0).len(), 2);
|
||||
assert_eq!(take_trace(), vec![msg_complete(1000), msg_limit_reached(1001),]);
|
||||
|
||||
let weight_used = handle_messages(&[], 2500);
|
||||
assert_eq!(weight_used, 2003);
|
||||
let weight_used = handle_messages(&[], Weight::from_ref_time(2500));
|
||||
assert_eq!(weight_used, Weight::from_ref_time(2003));
|
||||
assert_eq!(take_trace(), vec![msg_complete(1001), msg_complete(1002),]);
|
||||
assert!(queue_is_empty());
|
||||
});
|
||||
@@ -593,8 +593,8 @@ mod tests {
|
||||
let enqueued = vec![msg(1000), msg(1001)];
|
||||
let incoming = vec![msg(1002), msg(1003)];
|
||||
enqueue(&enqueued);
|
||||
let weight_used = handle_messages(&incoming, 5000);
|
||||
assert_eq!(weight_used, 4006);
|
||||
let weight_used = handle_messages(&incoming, Weight::from_ref_time(5000));
|
||||
assert_eq!(weight_used, Weight::from_ref_time(4006));
|
||||
assert_eq!(
|
||||
take_trace(),
|
||||
vec![
|
||||
@@ -614,19 +614,19 @@ mod tests {
|
||||
let enqueued = vec![msg(1000), msg(10001)];
|
||||
let incoming = vec![msg(1002), msg(1003)];
|
||||
enqueue(&enqueued);
|
||||
let weight_used = handle_messages(&incoming, 5000);
|
||||
assert_eq!(weight_used, 1000);
|
||||
let weight_used = handle_messages(&incoming, Weight::from_ref_time(5000));
|
||||
assert_eq!(weight_used, Weight::from_ref_time(1000));
|
||||
assert_eq!(take_trace(), vec![msg_complete(1000), msg_limit_reached(10001),]);
|
||||
assert_eq!(pages_queued(), 2);
|
||||
|
||||
// 5000 is not enough to process the 10001 blocker, so nothing happens.
|
||||
let weight_used = handle_messages(&[], 5000);
|
||||
assert_eq!(weight_used, 0);
|
||||
let weight_used = handle_messages(&[], Weight::from_ref_time(5000));
|
||||
assert_eq!(weight_used, Weight::zero());
|
||||
assert_eq!(take_trace(), vec![msg_limit_reached(10001),]);
|
||||
|
||||
// 20000 is now enough to process everything.
|
||||
let weight_used = handle_messages(&[], 20000);
|
||||
assert_eq!(weight_used, 12006);
|
||||
let weight_used = handle_messages(&[], Weight::from_ref_time(20000));
|
||||
assert_eq!(weight_used, Weight::from_ref_time(12006));
|
||||
assert_eq!(
|
||||
take_trace(),
|
||||
vec![msg_complete(10001), msg_complete(1002), msg_complete(1003),]
|
||||
@@ -641,8 +641,8 @@ mod tests {
|
||||
let enqueued = vec![msg(1000), msg(1001)];
|
||||
let incoming = vec![msg(10002), msg(1003)];
|
||||
enqueue(&enqueued);
|
||||
let weight_used = handle_messages(&incoming, 5000);
|
||||
assert_eq!(weight_used, 2001);
|
||||
let weight_used = handle_messages(&incoming, Weight::from_ref_time(5000));
|
||||
assert_eq!(weight_used, Weight::from_ref_time(2001));
|
||||
assert_eq!(
|
||||
take_trace(),
|
||||
vec![msg_complete(1000), msg_complete(1001), msg_limit_reached(10002),]
|
||||
@@ -650,8 +650,8 @@ mod tests {
|
||||
assert_eq!(pages_queued(), 1);
|
||||
|
||||
// 20000 is now enough to process everything.
|
||||
let weight_used = handle_messages(&[], 20000);
|
||||
assert_eq!(weight_used, 11005);
|
||||
let weight_used = handle_messages(&[], Weight::from_ref_time(20000));
|
||||
assert_eq!(weight_used, Weight::from_ref_time(11005));
|
||||
assert_eq!(take_trace(), vec![msg_complete(10002), msg_complete(1003),]);
|
||||
assert!(queue_is_empty());
|
||||
});
|
||||
@@ -663,8 +663,8 @@ mod tests {
|
||||
let enqueued = vec![msg(1000), msg(1001)];
|
||||
let incoming = vec![msg(1002), msg(10003)];
|
||||
enqueue(&enqueued);
|
||||
let weight_used = handle_messages(&incoming, 5000);
|
||||
assert_eq!(weight_used, 3003);
|
||||
let weight_used = handle_messages(&incoming, Weight::from_ref_time(5000));
|
||||
assert_eq!(weight_used, Weight::from_ref_time(3003));
|
||||
assert_eq!(
|
||||
take_trace(),
|
||||
vec![
|
||||
@@ -677,8 +677,8 @@ mod tests {
|
||||
assert_eq!(pages_queued(), 1);
|
||||
|
||||
// 20000 is now enough to process everything.
|
||||
let weight_used = handle_messages(&[], 20000);
|
||||
assert_eq!(weight_used, 10003);
|
||||
let weight_used = handle_messages(&[], Weight::from_ref_time(20000));
|
||||
assert_eq!(weight_used, Weight::from_ref_time(10003));
|
||||
assert_eq!(take_trace(), vec![msg_complete(10003),]);
|
||||
assert!(queue_is_empty());
|
||||
});
|
||||
@@ -689,20 +689,20 @@ mod tests {
|
||||
new_test_ext().execute_with(|| {
|
||||
let enqueued = vec![msg(1000), msg(1001)];
|
||||
enqueue(&enqueued);
|
||||
let weight_used = handle_messages(&vec![msg(1002)], 1500);
|
||||
assert_eq!(weight_used, 1000);
|
||||
let weight_used = handle_messages(&vec![msg(1002)], Weight::from_ref_time(1500));
|
||||
assert_eq!(weight_used, Weight::from_ref_time(1000));
|
||||
assert_eq!(take_trace(), vec![msg_complete(1000), msg_limit_reached(1001),]);
|
||||
assert_eq!(pages_queued(), 2);
|
||||
assert_eq!(PageIndex::<Test>::get().begin_used, 0);
|
||||
|
||||
let weight_used = handle_messages(&vec![msg(1003)], 1500);
|
||||
assert_eq!(weight_used, 1001);
|
||||
let weight_used = handle_messages(&vec![msg(1003)], Weight::from_ref_time(1500));
|
||||
assert_eq!(weight_used, Weight::from_ref_time(1001));
|
||||
assert_eq!(take_trace(), vec![msg_complete(1001), msg_limit_reached(1002),]);
|
||||
assert_eq!(pages_queued(), 2);
|
||||
assert_eq!(PageIndex::<Test>::get().begin_used, 1);
|
||||
|
||||
let weight_used = handle_messages(&vec![msg(1004)], 1500);
|
||||
assert_eq!(weight_used, 1002);
|
||||
let weight_used = handle_messages(&vec![msg(1004)], Weight::from_ref_time(1500));
|
||||
assert_eq!(weight_used, Weight::from_ref_time(1002));
|
||||
assert_eq!(take_trace(), vec![msg_complete(1002), msg_limit_reached(1003),]);
|
||||
assert_eq!(pages_queued(), 2);
|
||||
assert_eq!(PageIndex::<Test>::get().begin_used, 2);
|
||||
@@ -713,11 +713,11 @@ mod tests {
|
||||
fn overweight_should_not_block_queue() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// Set the overweight threshold to 9999.
|
||||
Configuration::<Test>::put(ConfigData { max_individual: 9999 });
|
||||
Configuration::<Test>::put(ConfigData { max_individual: Weight::from_ref_time(9999) });
|
||||
|
||||
let incoming = vec![msg(1000), msg(10001), msg(1002)];
|
||||
let weight_used = handle_messages(&incoming, 2500);
|
||||
assert_eq!(weight_used, 2002);
|
||||
let weight_used = handle_messages(&incoming, Weight::from_ref_time(2500));
|
||||
assert_eq!(weight_used, Weight::from_ref_time(2002));
|
||||
assert!(queue_is_empty());
|
||||
assert_eq!(
|
||||
take_trace(),
|
||||
@@ -732,37 +732,43 @@ mod tests {
|
||||
fn overweights_should_be_manually_executable() {
|
||||
new_test_ext().execute_with(|| {
|
||||
// Set the overweight threshold to 9999.
|
||||
Configuration::<Test>::put(ConfigData { max_individual: 9999 });
|
||||
Configuration::<Test>::put(ConfigData { max_individual: Weight::from_ref_time(9999) });
|
||||
|
||||
let incoming = vec![msg(10000)];
|
||||
let weight_used = handle_messages(&incoming, 2500);
|
||||
assert_eq!(weight_used, 0);
|
||||
let weight_used = handle_messages(&incoming, Weight::from_ref_time(2500));
|
||||
assert_eq!(weight_used, Weight::zero());
|
||||
assert_eq!(take_trace(), vec![msg_limit_reached(10000)]);
|
||||
assert_eq!(overweights(), vec![0]);
|
||||
|
||||
assert_noop!(DmpQueue::service_overweight(Origin::signed(1), 0, 20000), BadOrigin);
|
||||
assert_noop!(
|
||||
DmpQueue::service_overweight(Origin::root(), 1, 20000),
|
||||
DmpQueue::service_overweight(Origin::signed(1), 0, Weight::from_ref_time(20000)),
|
||||
BadOrigin
|
||||
);
|
||||
assert_noop!(
|
||||
DmpQueue::service_overweight(Origin::root(), 1, Weight::from_ref_time(20000)),
|
||||
Error::<Test>::Unknown
|
||||
);
|
||||
assert_noop!(
|
||||
DmpQueue::service_overweight(Origin::root(), 0, 9999),
|
||||
DmpQueue::service_overweight(Origin::root(), 0, Weight::from_ref_time(9999)),
|
||||
Error::<Test>::OverLimit
|
||||
);
|
||||
assert_eq!(take_trace(), vec![msg_limit_reached(10000)]);
|
||||
|
||||
let base_weight = super::Call::<Test>::service_overweight { index: 0, weight_limit: 0 }
|
||||
.get_dispatch_info()
|
||||
.weight;
|
||||
let base_weight =
|
||||
super::Call::<Test>::service_overweight { index: 0, weight_limit: Weight::zero() }
|
||||
.get_dispatch_info()
|
||||
.weight;
|
||||
use frame_support::weights::GetDispatchInfo;
|
||||
let info = DmpQueue::service_overweight(Origin::root(), 0, 20000).unwrap();
|
||||
let info =
|
||||
DmpQueue::service_overweight(Origin::root(), 0, Weight::from_ref_time(20000))
|
||||
.unwrap();
|
||||
let actual_weight = info.actual_weight.unwrap();
|
||||
assert_eq!(actual_weight, base_weight + 10000);
|
||||
assert_eq!(actual_weight, base_weight + Weight::from_ref_time(10000));
|
||||
assert_eq!(take_trace(), vec![msg_complete(10000)]);
|
||||
assert!(overweights().is_empty());
|
||||
|
||||
assert_noop!(
|
||||
DmpQueue::service_overweight(Origin::root(), 0, 20000),
|
||||
DmpQueue::service_overweight(Origin::root(), 0, Weight::from_ref_time(20000)),
|
||||
Error::<Test>::Unknown
|
||||
);
|
||||
});
|
||||
@@ -775,8 +781,8 @@ mod tests {
|
||||
enqueue(&vec![msg(1002), msg(1003)]);
|
||||
enqueue(&vec![msg(1004), msg(1005)]);
|
||||
|
||||
let weight_used = DmpQueue::on_idle(1, 6000);
|
||||
assert_eq!(weight_used, 5010);
|
||||
let weight_used = DmpQueue::on_idle(1, Weight::from_ref_time(6000));
|
||||
assert_eq!(weight_used, Weight::from_ref_time(5010));
|
||||
assert_eq!(
|
||||
take_trace(),
|
||||
vec![
|
||||
|
||||
@@ -269,7 +269,7 @@ pub mod pallet {
|
||||
}
|
||||
|
||||
fn on_initialize(_n: T::BlockNumber) -> Weight {
|
||||
let mut weight = 0;
|
||||
let mut weight = Weight::new();
|
||||
|
||||
// To prevent removing `NewValidationCode` that was set by another `on_initialize`
|
||||
// like for example from scheduler, we only kill the storage entry if it was not yet
|
||||
@@ -416,7 +416,7 @@ pub mod pallet {
|
||||
<T::OnSystemEvent as OnSystemEvent>::on_validation_data(&vfp);
|
||||
|
||||
// TODO: This is more than zero, but will need benchmarking to figure out what.
|
||||
let mut total_weight = 0;
|
||||
let mut total_weight = Weight::zero();
|
||||
total_weight += Self::process_inbound_downward_messages(
|
||||
relevant_messaging_state.dmq_mqc_head,
|
||||
downward_messages,
|
||||
@@ -808,7 +808,7 @@ impl<T: Config> Pallet<T> {
|
||||
let dm_count = downward_messages.len() as u32;
|
||||
let mut dmq_head = <LastDmqMqcHead<T>>::get();
|
||||
|
||||
let mut weight_used = 0;
|
||||
let mut weight_used = Weight::new();
|
||||
if dm_count != 0 {
|
||||
Self::deposit_event(Event::DownwardMessagesReceived { count: dm_count });
|
||||
let max_weight =
|
||||
|
||||
@@ -25,7 +25,7 @@ pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
|
||||
|
||||
/// Call this during the next runtime upgrade for this module.
|
||||
pub fn on_runtime_upgrade<T: Config>() -> Weight {
|
||||
let mut weight: Weight = 0;
|
||||
let mut weight: Weight = Weight::new();
|
||||
|
||||
if StorageVersion::get::<Pallet<T>>() == 0 {
|
||||
weight = weight
|
||||
|
||||
@@ -69,8 +69,8 @@ parameter_types! {
|
||||
state_version: 1,
|
||||
};
|
||||
pub const ParachainId: ParaId = ParaId::new(200);
|
||||
pub const ReservedXcmpWeight: Weight = 0;
|
||||
pub const ReservedDmpWeight: Weight = 0;
|
||||
pub const ReservedXcmpWeight: Weight = Weight::zero();
|
||||
pub const ReservedDmpWeight: Weight = Weight::zero();
|
||||
}
|
||||
impl frame_system::Config for Test {
|
||||
type Origin = Origin;
|
||||
@@ -155,7 +155,7 @@ impl DmpMessageHandler for SaveIntoThreadLocal {
|
||||
for i in iter {
|
||||
m.borrow_mut().push(i);
|
||||
}
|
||||
0
|
||||
Weight::zero()
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -169,7 +169,7 @@ impl XcmpMessageHandler for SaveIntoThreadLocal {
|
||||
for (sender, sent_at, message) in iter {
|
||||
m.borrow_mut().push((sender, sent_at, message.to_vec()));
|
||||
}
|
||||
0
|
||||
Weight::zero()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ pub mod pallet {
|
||||
|
||||
if *who == root_account {
|
||||
Ok(ValidTransaction {
|
||||
priority: info.weight as TransactionPriority,
|
||||
priority: info.weight.ref_time() as TransactionPriority,
|
||||
longevity: TransactionLongevity::max_value(),
|
||||
propagate: true,
|
||||
..Default::default()
|
||||
|
||||
@@ -111,7 +111,7 @@ impl<T: Config> DmpMessageHandler for UnlimitedDmpExecution<T> {
|
||||
iter: impl Iterator<Item = (RelayBlockNumber, Vec<u8>)>,
|
||||
limit: Weight,
|
||||
) -> Weight {
|
||||
let mut used = 0;
|
||||
let mut used = Weight::new();
|
||||
for (_sent_at, data) in iter {
|
||||
let id = sp_io::hashing::twox_64(&data[..]);
|
||||
let msg = VersionedXcm::<T::Call>::decode_all_with_depth_limit(
|
||||
@@ -123,8 +123,8 @@ impl<T: Config> DmpMessageHandler for UnlimitedDmpExecution<T> {
|
||||
Err(_) => Pallet::<T>::deposit_event(Event::InvalidFormat(id)),
|
||||
Ok(Err(())) => Pallet::<T>::deposit_event(Event::UnsupportedVersion(id)),
|
||||
Ok(Ok(x)) => {
|
||||
let outcome = T::XcmExecutor::execute_xcm(Parent, x, limit);
|
||||
used += outcome.weight_used();
|
||||
let outcome = T::XcmExecutor::execute_xcm(Parent, x, limit.ref_time());
|
||||
used += Weight::from_ref_time(outcome.weight_used());
|
||||
Pallet::<T>::deposit_event(Event::ExecutedDownward(id, outcome));
|
||||
},
|
||||
}
|
||||
@@ -144,7 +144,7 @@ impl<T: Config> DmpMessageHandler for LimitAndDropDmpExecution<T> {
|
||||
iter: impl Iterator<Item = (RelayBlockNumber, Vec<u8>)>,
|
||||
limit: Weight,
|
||||
) -> Weight {
|
||||
let mut used = 0;
|
||||
let mut used = Weight::new();
|
||||
for (_sent_at, data) in iter {
|
||||
let id = sp_io::hashing::twox_64(&data[..]);
|
||||
let msg = VersionedXcm::<T::Call>::decode_all_with_depth_limit(
|
||||
@@ -157,8 +157,8 @@ impl<T: Config> DmpMessageHandler for LimitAndDropDmpExecution<T> {
|
||||
Ok(Err(())) => Pallet::<T>::deposit_event(Event::UnsupportedVersion(id)),
|
||||
Ok(Ok(x)) => {
|
||||
let weight_limit = limit.saturating_sub(used);
|
||||
let outcome = T::XcmExecutor::execute_xcm(Parent, x, weight_limit);
|
||||
used += outcome.weight_used();
|
||||
let outcome = T::XcmExecutor::execute_xcm(Parent, x, weight_limit.ref_time());
|
||||
used += Weight::from_ref_time(outcome.weight_used());
|
||||
Pallet::<T>::deposit_event(Event::ExecutedDownward(id, outcome));
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user