Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use some macros
  • Loading branch information
shawntabrizi committed Aug 31, 2022
commit 0c4722b665499f139d7fd64c0fb4544dc57e10fc
4 changes: 2 additions & 2 deletions frame/support/src/weights/block_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ mod test_weights {
let w = super::BlockExecutionWeight::get();

// At least 100 µs.
assert!(w >= 100 * constants::WEIGHT_PER_MICROS, "Weight should be at least 100 µs.");
assert!(w >= 100u32 * 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 <= 50u32 * constants::WEIGHT_PER_MILLIS, "Weight should be at most 50 ms.");
}
}
2 changes: 1 addition & 1 deletion frame/support/src/weights/extrinsic_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ mod test_weights {
let w = super::ExtrinsicBaseWeight::get();

// At least 10 µs.
assert!(w >= 10 * constants::WEIGHT_PER_MICROS, "Weight should be at least 10 µs.");
assert!(w >= 10u32 * 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
52 changes: 29 additions & 23 deletions frame/support/src/weights/weight_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
use codec::{CompactAs, Decode, Encode, MaxEncodedLen};
use core::ops::{Add, AddAssign, Div, Mul, Sub, SubAssign};
use sp_runtime::{
traits::{Bounded, CheckedAdd, CheckedSub, Zero},
Perquintill, RuntimeDebug,
traits::{Bounded, CheckedAdd, CheckedSub, Zero}, RuntimeDebug,
};

use super::*;
Expand Down Expand Up @@ -195,13 +194,6 @@ impl Sub for Weight {
}
}

impl Mul for Weight {
type Output = Self;
fn mul(self, b: Self) -> Self {
Self { ref_time: b.ref_time * self.ref_time }
}
}

impl<T> Mul<T> for Weight
where
T: Mul<u64, Output = u64> + Copy,
Expand All @@ -212,26 +204,40 @@ where
}
}

impl Mul<Weight> for Perbill {
type Output = Weight;
fn mul(self, b: Weight) -> Weight {
Weight { ref_time: self * b.ref_time }
macro_rules! weight_mul_per_impl {
($($t:ty),* $(,)?) => {
$(
impl Mul<Weight> for $t {
type Output = Weight;
fn mul(self, b: Weight) -> Weight {
Weight { ref_time: self * b.ref_time }
}
}
)*
}
}
weight_mul_per_impl!(sp_runtime::Percent, sp_runtime::Permill, sp_runtime::Perbill, sp_runtime::Perquintill);

impl Mul<Weight> for Perquintill {
type Output = Weight;
fn mul(self, b: Weight) -> Weight {
Weight { ref_time: self * b.ref_time }
}
}
macro_rules! weight_mul_div_primitive_impl {
($($t:ty),* $(,)?) => {
$(
impl Mul<Weight> for $t {
type Output = Weight;
fn mul(self, b: Weight) -> Weight {
Weight { ref_time: b.ref_time * u64::from(self) }
}
}

impl Mul<Weight> for u64 {
type Output = Weight;
fn mul(self, b: Weight) -> Weight {
Weight { ref_time: self * b.ref_time }
impl Div<Weight> for $t {
type Output = Weight;
fn div(self, b: Weight) -> Weight {
Weight { ref_time: b.ref_time / u64::from(self) }
}
}
)*
}
}
weight_mul_div_primitive_impl!(u8, u16, u32, u64);

impl<T> Div<T> for Weight
where
Expand Down
2 changes: 1 addition & 1 deletion frame/system/src/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ pub struct BlockWeights {

impl Default for BlockWeights {
fn default() -> Self {
Self::with_sensible_defaults(1 * constants::WEIGHT_PER_SECOND, DEFAULT_NORMAL_RATIO)
Self::with_sensible_defaults(1u32 * constants::WEIGHT_PER_SECOND, DEFAULT_NORMAL_RATIO)
}
}

Expand Down