Deprecate Weight::from_{ref_time, proof_size} (#13475)

* Deprecate Weight::from_{ref_time, proof_size}

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update templates

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use from_parts

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Use from_parts

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Dont revert comment 🤦

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_balances

* Update weight files

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* More fixes

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Adapt to Master changes

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: command-bot <>
This commit is contained in:
Oliver Tale-Yazdi
2023-03-02 22:28:17 +01:00
committed by GitHub
parent 7981d4aa59
commit 9e56e1acdd
101 changed files with 2695 additions and 2857 deletions
+12 -12
View File
@@ -82,17 +82,17 @@ pub struct RuntimeDbWeight {
impl RuntimeDbWeight {
pub fn reads(self, r: u64) -> Weight {
Weight::from_ref_time(self.read.saturating_mul(r))
Weight::from_parts(self.read.saturating_mul(r), 0)
}
pub fn writes(self, w: u64) -> Weight {
Weight::from_ref_time(self.write.saturating_mul(w))
Weight::from_parts(self.write.saturating_mul(w), 0)
}
pub fn reads_writes(self, r: u64, w: u64) -> Weight {
let read_weight = self.read.saturating_mul(r);
let write_weight = self.write.saturating_mul(w);
Weight::from_ref_time(read_weight.saturating_add(write_weight))
Weight::from_parts(read_weight.saturating_add(write_weight), 0)
}
}
@@ -264,15 +264,15 @@ mod tests {
#[test]
fn polynomial_works() {
// 100^3/2=500000 100^2*(2+1/3)=23333 700 -10000
assert_eq!(Poly::weight_to_fee(&Weight::from_ref_time(100)), 514033);
assert_eq!(Poly::weight_to_fee(&Weight::from_parts(100, 0)), 514033);
// 10123^3/2=518677865433 10123^2*(2+1/3)=239108634 70861 -10000
assert_eq!(Poly::weight_to_fee(&Weight::from_ref_time(10_123)), 518917034928);
assert_eq!(Poly::weight_to_fee(&Weight::from_parts(10_123, 0)), 518917034928);
}
#[test]
fn polynomial_does_not_underflow() {
assert_eq!(Poly::weight_to_fee(&Weight::zero()), 0);
assert_eq!(Poly::weight_to_fee(&Weight::from_ref_time(10)), 0);
assert_eq!(Poly::weight_to_fee(&Weight::from_parts(10, 0)), 0);
}
#[test]
@@ -283,7 +283,7 @@ mod tests {
#[test]
fn identity_fee_works() {
assert_eq!(IdentityFee::<Balance>::weight_to_fee(&Weight::zero()), 0);
assert_eq!(IdentityFee::<Balance>::weight_to_fee(&Weight::from_ref_time(50)), 50);
assert_eq!(IdentityFee::<Balance>::weight_to_fee(&Weight::from_parts(50, 0)), 50);
assert_eq!(IdentityFee::<Balance>::weight_to_fee(&Weight::MAX), Balance::max_value());
}
@@ -295,20 +295,20 @@ mod tests {
0
);
assert_eq!(
ConstantMultiplier::<u128, ConstU128<10u128>>::weight_to_fee(&Weight::from_ref_time(
50
ConstantMultiplier::<u128, ConstU128<10u128>>::weight_to_fee(&Weight::from_parts(
50, 0
)),
500
);
assert_eq!(
ConstantMultiplier::<u128, ConstU128<1024u128>>::weight_to_fee(&Weight::from_ref_time(
16
ConstantMultiplier::<u128, ConstU128<1024u128>>::weight_to_fee(&Weight::from_parts(
16, 0
)),
16384
);
assert_eq!(
ConstantMultiplier::<u128, ConstU128<{ u128::MAX }>>::weight_to_fee(
&Weight::from_ref_time(2)
&Weight::from_parts(2, 0)
),
u128::MAX
);
@@ -37,7 +37,7 @@ pub struct Weight {
impl From<OldWeight> for Weight {
fn from(old: OldWeight) -> Self {
Weight::from_ref_time(old.0)
Weight::from_parts(old.0, 0)
}
}
@@ -103,11 +103,13 @@ impl Weight {
}
/// Construct [`Weight`] with reference time weight and 0 storage size weight.
#[deprecated = "Will be removed soon; use `from_parts` instead."]
pub const fn from_ref_time(ref_time: u64) -> Self {
Self { ref_time, proof_size: 0 }
}
/// Construct [`Weight`] with storage size weight and 0 reference time weight.
#[deprecated = "Will be removed soon; use `from_parts` instead."]
pub const fn from_proof_size(proof_size: u64) -> Self {
Self { ref_time: 0, proof_size }
}
@@ -238,7 +240,7 @@ impl Weight {
/// of all those divisions. Returns `None` in case **all** components of `other` are zero.
///
/// This returns `Some` even if some components of `other` are zero as long as there is at least
/// one non-zero component in `other`. The devision for this particular component will then
/// one non-zero component in `other`. The division for this particular component will then
/// yield the maximum value (e.g u64::MAX). This is because we assume not every operation and
/// hence each `Weight` will necessarily use each resource.
pub const fn checked_div_per_component(self, other: &Self) -> Option<u64> {