Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Companion for Weight v1.5 Follow Up #1584

Merged
merged 12 commits into from
Sep 1, 2022
26 changes: 10 additions & 16 deletions pallets/collator-selection/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
Weight::from_ref_time(18_563_000 as RefTimeWeight)
// Standard Error: 0
.saturating_add(
Weight::from_ref_time(68_000 as RefTimeWeight)
.scalar_saturating_mul(b as RefTimeWeight),
Weight::from_ref_time(68_000 as RefTimeWeight).saturating_mul(b as RefTimeWeight),
)
.saturating_add(T::DbWeight::get().writes(1 as RefTimeWeight))
}
Expand All @@ -59,8 +58,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
Weight::from_ref_time(71_196_000 as RefTimeWeight)
// Standard Error: 0
.saturating_add(
Weight::from_ref_time(198_000 as RefTimeWeight)
.scalar_saturating_mul(c as RefTimeWeight),
Weight::from_ref_time(198_000 as RefTimeWeight).saturating_mul(c as RefTimeWeight),
)
.saturating_add(T::DbWeight::get().reads(4 as RefTimeWeight))
.saturating_add(T::DbWeight::get().writes(2 as RefTimeWeight))
Expand All @@ -69,8 +67,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
Weight::from_ref_time(55_336_000 as RefTimeWeight)
// Standard Error: 0
.saturating_add(
Weight::from_ref_time(151_000 as RefTimeWeight)
.scalar_saturating_mul(c as RefTimeWeight),
Weight::from_ref_time(151_000 as RefTimeWeight).saturating_mul(c as RefTimeWeight),
)
.saturating_add(T::DbWeight::get().reads(1 as RefTimeWeight))
.saturating_add(T::DbWeight::get().writes(2 as RefTimeWeight))
Expand All @@ -85,12 +82,12 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Standard Error: 1_010_000
.saturating_add(
Weight::from_ref_time(109_961_000 as RefTimeWeight)
.scalar_saturating_mul(r as RefTimeWeight),
.saturating_mul(r as RefTimeWeight),
)
// Standard Error: 1_010_000
.saturating_add(
Weight::from_ref_time(151_952_000 as RefTimeWeight)
.scalar_saturating_mul(c as RefTimeWeight),
.saturating_mul(c as RefTimeWeight),
)
.saturating_add(
T::DbWeight::get().reads((1 as RefTimeWeight).saturating_mul(r as RefTimeWeight)),
Expand All @@ -113,8 +110,7 @@ impl WeightInfo for () {
Weight::from_ref_time(18_563_000 as RefTimeWeight)
// Standard Error: 0
.saturating_add(
Weight::from_ref_time(68_000 as RefTimeWeight)
.scalar_saturating_mul(b as RefTimeWeight),
Weight::from_ref_time(68_000 as RefTimeWeight).saturating_mul(b as RefTimeWeight),
)
.saturating_add(RocksDbWeight::get().writes(1 as RefTimeWeight))
}
Expand All @@ -130,8 +126,7 @@ impl WeightInfo for () {
Weight::from_ref_time(71_196_000 as RefTimeWeight)
// Standard Error: 0
.saturating_add(
Weight::from_ref_time(198_000 as RefTimeWeight)
.scalar_saturating_mul(c as RefTimeWeight),
Weight::from_ref_time(198_000 as RefTimeWeight).saturating_mul(c as RefTimeWeight),
)
.saturating_add(RocksDbWeight::get().reads(4 as RefTimeWeight))
.saturating_add(RocksDbWeight::get().writes(2 as RefTimeWeight))
Expand All @@ -140,8 +135,7 @@ impl WeightInfo for () {
Weight::from_ref_time(55_336_000 as RefTimeWeight)
// Standard Error: 0
.saturating_add(
Weight::from_ref_time(151_000 as RefTimeWeight)
.scalar_saturating_mul(c as RefTimeWeight),
Weight::from_ref_time(151_000 as RefTimeWeight).saturating_mul(c as RefTimeWeight),
)
.saturating_add(RocksDbWeight::get().reads(1 as RefTimeWeight))
.saturating_add(RocksDbWeight::get().writes(2 as RefTimeWeight))
Expand All @@ -156,12 +150,12 @@ impl WeightInfo for () {
// Standard Error: 1_010_000
.saturating_add(
Weight::from_ref_time(109_961_000 as RefTimeWeight)
.scalar_saturating_mul(r as RefTimeWeight),
.saturating_mul(r as RefTimeWeight),
)
// Standard Error: 1_010_000
.saturating_add(
Weight::from_ref_time(151_952_000 as RefTimeWeight)
.scalar_saturating_mul(c as RefTimeWeight),
.saturating_mul(c as RefTimeWeight),
)
.saturating_add(
RocksDbWeight::get().reads((1 as RefTimeWeight).saturating_mul(r as RefTimeWeight)),
Expand Down
4 changes: 2 additions & 2 deletions pallets/dmp-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct ConfigData {
impl Default for ConfigData {
fn default() -> Self {
Self {
max_individual: 10 * WEIGHT_PER_MILLIS, // 10 ms of execution time maximum by default
max_individual: 10u64 * WEIGHT_PER_MILLIS, // 10 ms of execution time maximum by default
}
}
}
Expand Down Expand Up @@ -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 = Weight::new();
let mut used = Weight::zero();
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() {
Expand Down
4 changes: 2 additions & 2 deletions pallets/parachain-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ pub mod pallet {
}

fn on_initialize(_n: T::BlockNumber) -> Weight {
let mut weight = Weight::new();
let mut weight = Weight::zero();

// 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
Expand Down Expand Up @@ -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 = Weight::new();
let mut weight_used = Weight::zero();
if dm_count != 0 {
Self::deposit_event(Event::DownwardMessagesReceived { count: dm_count });
let max_weight =
Expand Down
2 changes: 1 addition & 1 deletion pallets/parachain-system/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = Weight::new();
let mut weight: Weight = Weight::zero();

if StorageVersion::get::<Pallet<T>>() == 0 {
weight = weight
Expand Down
4 changes: 2 additions & 2 deletions pallets/xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<T: Config> DmpMessageHandler for UnlimitedDmpExecution<T> {
iter: impl Iterator<Item = (RelayBlockNumber, Vec<u8>)>,
limit: Weight,
) -> Weight {
let mut used = Weight::new();
let mut used = Weight::zero();
for (_sent_at, data) in iter {
let id = sp_io::hashing::twox_64(&data[..]);
let msg = VersionedXcm::<T::Call>::decode_all_with_depth_limit(
Expand Down Expand Up @@ -144,7 +144,7 @@ impl<T: Config> DmpMessageHandler for LimitAndDropDmpExecution<T> {
iter: impl Iterator<Item = (RelayBlockNumber, Vec<u8>)>,
limit: Weight,
) -> Weight {
let mut used = Weight::new();
let mut used = Weight::zero();
for (_sent_at, data) in iter {
let id = sp_io::hashing::twox_64(&data[..]);
let msg = VersionedXcm::<T::Call>::decode_all_with_depth_limit(
Expand Down
6 changes: 3 additions & 3 deletions pallets/xcmp-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ impl Default for QueueConfigData {
resume_threshold: 1,
threshold_weight: Weight::from_ref_time(100_000),
weight_restrict_decay: Weight::from_ref_time(2),
xcmp_max_individual_weight: 20 * WEIGHT_PER_MILLIS,
xcmp_max_individual_weight: 20u64 * WEIGHT_PER_MILLIS,
}
}
}
Expand Down Expand Up @@ -795,8 +795,8 @@ impl<T: Config> Pallet<T> {
} = <QueueConfig<T>>::get();

let mut shuffled = Self::create_shuffle(status.len());
let mut weight_used = Weight::new();
let mut weight_available = Weight::new();
let mut weight_used = Weight::zero();
let mut weight_available = Weight::zero();

// 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
Expand Down
4 changes: 2 additions & 2 deletions pallets/xcmp-queue/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = Weight::new();
let mut weight = Weight::zero();

if StorageVersion::get::<Pallet<T>>() == 0 {
weight += migrate_to_v1::<T>();
Expand Down Expand Up @@ -103,7 +103,7 @@ mod tests {
drop_threshold: 12,
resume_threshold: 3,
threshold_weight: Weight::from_ref_time(333_333),
weight_restrict_decay: Weight::one(),
weight_restrict_decay: Weight::from_ref_time(1),
};

new_test_ext().execute_with(|| {
Expand Down
11 changes: 7 additions & 4 deletions pallets/xcmp-queue/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,20 @@ fn update_weight_restrict_decay_works() {
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_eq!(data.xcmp_max_individual_weight, 20u64 * WEIGHT_PER_MILLIS);
assert_ok!(XcmpQueue::update_xcmp_max_individual_weight(
Origin::root(),
30 * WEIGHT_PER_MILLIS
30u64 * WEIGHT_PER_MILLIS
));
assert_noop!(
XcmpQueue::update_xcmp_max_individual_weight(Origin::signed(3), 10 * WEIGHT_PER_MILLIS),
XcmpQueue::update_xcmp_max_individual_weight(
Origin::signed(3),
10u64 * WEIGHT_PER_MILLIS
),
BadOrigin
);
let data: QueueConfigData = <QueueConfig<Test>>::get();

assert_eq!(data.xcmp_max_individual_weight, 30 * WEIGHT_PER_MILLIS);
assert_eq!(data.xcmp_max_individual_weight, 30u64 * WEIGHT_PER_MILLIS);
});
}
6 changes: 3 additions & 3 deletions parachain-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5);
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);

/// We allow for 0.5 of a second of compute with a 12 second average block time.
const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.scalar_div(2);
const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.saturating_div(2);

/// The version information used to identify this runtime when compiled natively.
#[cfg(feature = "std")]
Expand Down Expand Up @@ -363,8 +363,8 @@ impl pallet_transaction_payment::Config for Runtime {
}

parameter_types! {
pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.scalar_div(4);
pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.scalar_div(4);
pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
}

impl cumulus_pallet_parachain_system::Config for Runtime {
Expand Down
9 changes: 6 additions & 3 deletions parachain-template/runtime/src/weights/block_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub mod constants {

parameter_types! {
/// Importing a block with 0 Extrinsics.
pub const BlockExecutionWeight: Weight = constants::WEIGHT_PER_NANOS.scalar_saturating_mul(5_000_000);
pub const BlockExecutionWeight: Weight = constants::WEIGHT_PER_NANOS.saturating_mul(5_000_000);
}

#[cfg(test)]
Expand All @@ -38,9 +38,12 @@ pub mod constants {
let w = super::constants::BlockExecutionWeight::get();

// At least 100 µs.
assert!(w >= 100 * constants::WEIGHT_PER_MICROS, "Weight should be at least 100 µs.");
assert!(
w >= 100u64 * constants::WEIGHT_PER_MICROS,
"Weight should be at least 100 µs."
);
// At most 50 ms.
assert!(w <= 50 * constants::WEIGHT_PER_MILLIS, "Weight should be at most 50 ms.");
assert!(w <= 50u64 * constants::WEIGHT_PER_MILLIS, "Weight should be at most 50 ms.");
}
}
}
4 changes: 2 additions & 2 deletions parachain-template/runtime/src/weights/extrinsic_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub mod constants {

parameter_types! {
/// Executing a NO-OP `System::remarks` Extrinsic.
pub const ExtrinsicBaseWeight: Weight = constants::WEIGHT_PER_NANOS.scalar_saturating_mul(125_000);
pub const ExtrinsicBaseWeight: Weight = constants::WEIGHT_PER_NANOS.saturating_mul(125_000);
}

#[cfg(test)]
Expand All @@ -38,7 +38,7 @@ pub mod constants {
let w = super::constants::ExtrinsicBaseWeight::get();

// At least 10 µs.
assert!(w >= 10 * constants::WEIGHT_PER_MICROS, "Weight should be at least 10 µs.");
assert!(w >= 10u64 * constants::WEIGHT_PER_MICROS, "Weight should be at least 10 µs.");
// At most 1 ms.
assert!(w <= constants::WEIGHT_PER_MILLIS, "Weight should be at most 1 ms.");
}
Expand Down
2 changes: 1 addition & 1 deletion parachains/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ mod constants {
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);

/// We allow for 0.5 seconds of compute with a 6 second average block time.
pub const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.scalar_div(2);
pub const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.saturating_div(2);
}

/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
Expand Down
4 changes: 2 additions & 2 deletions parachains/runtimes/assets/statemine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@ impl pallet_proxy::Config for Runtime {
}

parameter_types! {
pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.scalar_div(4);
pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.scalar_div(4);
pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
}

impl cumulus_pallet_parachain_system::Config for Runtime {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub mod constants {

parameter_types! {
/// Importing a block with 0 Extrinsics.
pub const BlockExecutionWeight: Weight = constants::WEIGHT_PER_NANOS.scalar_saturating_mul(5_000_000);
pub const BlockExecutionWeight: Weight = constants::WEIGHT_PER_NANOS.saturating_mul(5_000_000);
}

#[cfg(test)]
Expand All @@ -38,9 +38,12 @@ pub mod constants {
let w = super::constants::BlockExecutionWeight::get();

// At least 100 µs.
assert!(w >= 100 * constants::WEIGHT_PER_MICROS, "Weight should be at least 100 µs.");
assert!(
w >= 100u64 * constants::WEIGHT_PER_MICROS,
"Weight should be at least 100 µs."
);
// At most 50 ms.
assert!(w <= 50 * constants::WEIGHT_PER_MILLIS, "Weight should be at most 50 ms.");
assert!(w <= 50u64 * constants::WEIGHT_PER_MILLIS, "Weight should be at most 50 ms.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub mod constants {

parameter_types! {
/// Executing a NO-OP `System::remarks` Extrinsic.
pub const ExtrinsicBaseWeight: Weight = constants::WEIGHT_PER_NANOS.scalar_saturating_mul(125_000);
pub const ExtrinsicBaseWeight: Weight = constants::WEIGHT_PER_NANOS.saturating_mul(125_000);
}

#[cfg(test)]
Expand All @@ -38,7 +38,7 @@ pub mod constants {
let w = super::constants::ExtrinsicBaseWeight::get();

// At least 10 µs.
assert!(w >= 10 * constants::WEIGHT_PER_MICROS, "Weight should be at least 10 µs.");
assert!(w >= 10u64 * constants::WEIGHT_PER_MICROS, "Weight should be at least 10 µs.");
// At most 1 ms.
assert!(w <= constants::WEIGHT_PER_MILLIS, "Weight should be at most 1 ms.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<T: frame_system::Config> frame_system::WeightInfo for WeightInfo<T> {
fn remark_with_event(b: u32, ) -> Weight {
Weight::from_ref_time(0 as RefTimeWeight)
// Standard Error: 0
.saturating_add(Weight::from_ref_time(2_000 as RefTimeWeight).scalar_saturating_mul(b as RefTimeWeight))
.saturating_add(Weight::from_ref_time(2_000 as RefTimeWeight).saturating_mul(b as RefTimeWeight))
}
// Storage: System Digest (r:1 w:1)
// Storage: unknown [0x3a686561707061676573] (r:0 w:1)
Expand All @@ -68,23 +68,23 @@ impl<T: frame_system::Config> frame_system::WeightInfo for WeightInfo<T> {
fn set_storage(i: u32, ) -> Weight {
Weight::from_ref_time(0 as RefTimeWeight)
// Standard Error: 1_000
.saturating_add(Weight::from_ref_time(622_000 as RefTimeWeight).scalar_saturating_mul(i as RefTimeWeight))
.saturating_add(Weight::from_ref_time(622_000 as RefTimeWeight).saturating_mul(i as RefTimeWeight))
.saturating_add(T::DbWeight::get().writes((1 as RefTimeWeight).saturating_mul(i as RefTimeWeight)))
}
// Storage: Skipped Metadata (r:0 w:0)
/// The range of component `i` is `[1, 1000]`.
fn kill_storage(i: u32, ) -> Weight {
Weight::from_ref_time(351_000 as RefTimeWeight)
// Standard Error: 1_000
.saturating_add(Weight::from_ref_time(513_000 as RefTimeWeight).scalar_saturating_mul(i as RefTimeWeight))
.saturating_add(Weight::from_ref_time(513_000 as RefTimeWeight).saturating_mul(i as RefTimeWeight))
.saturating_add(T::DbWeight::get().writes((1 as RefTimeWeight).saturating_mul(i as RefTimeWeight)))
}
// Storage: Skipped Metadata (r:0 w:0)
/// The range of component `p` is `[1, 1000]`.
fn kill_prefix(p: u32, ) -> Weight {
Weight::from_ref_time(0 as RefTimeWeight)
// Standard Error: 1_000
.saturating_add(Weight::from_ref_time(1_054_000 as RefTimeWeight).scalar_saturating_mul(p as RefTimeWeight))
.saturating_add(Weight::from_ref_time(1_054_000 as RefTimeWeight).saturating_mul(p as RefTimeWeight))
.saturating_add(T::DbWeight::get().writes((1 as RefTimeWeight).saturating_mul(p as RefTimeWeight)))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ impl<T: frame_system::Config> pallet_assets::WeightInfo for WeightInfo<T> {
fn destroy(c: u32, s: u32, a: u32, ) -> Weight {
Weight::from_ref_time(0 as RefTimeWeight)
// Standard Error: 46_000
.saturating_add(Weight::from_ref_time(16_382_000 as RefTimeWeight).scalar_saturating_mul(c as RefTimeWeight))
.saturating_add(Weight::from_ref_time(16_382_000 as RefTimeWeight).saturating_mul(c as RefTimeWeight))
// Standard Error: 46_000
.saturating_add(Weight::from_ref_time(19_187_000 as RefTimeWeight).scalar_saturating_mul(s as RefTimeWeight))
.saturating_add(Weight::from_ref_time(19_187_000 as RefTimeWeight).saturating_mul(s as RefTimeWeight))
// Standard Error: 465_000
.saturating_add(Weight::from_ref_time(16_818_000 as RefTimeWeight).scalar_saturating_mul(a as RefTimeWeight))
.saturating_add(Weight::from_ref_time(16_818_000 as RefTimeWeight).saturating_mul(a as RefTimeWeight))
.saturating_add(T::DbWeight::get().reads(5 as RefTimeWeight))
.saturating_add(T::DbWeight::get().reads((2 as RefTimeWeight).saturating_mul(c as RefTimeWeight)))
.saturating_add(T::DbWeight::get().reads((2 as RefTimeWeight).saturating_mul(s as RefTimeWeight)))
Expand Down
Loading