Skip to content

Commit

Permalink
Companion for paritytech/substrate#12868 (#6406)
Browse files Browse the repository at this point in the history
* Replace WEIGHT_PER_* with WEIGHT_REF_TIME_PER_*

* cargo fmt

* Update substrate
  • Loading branch information
KiChjang authored Dec 8, 2022
1 parent ee9c4f0 commit 3b05b99
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 40 deletions.
9 changes: 5 additions & 4 deletions relay/kusama/constants/src/weights/block_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
// --header=./file_header.txt

use sp_core::parameter_types;
use sp_weights::{constants::WEIGHT_PER_NANOS, Weight};
use sp_weights::{constants::WEIGHT_REF_TIME_PER_NANOS, Weight};

parameter_types! {
/// Time to execute an empty block.
Expand All @@ -51,7 +51,8 @@ parameter_types! {
/// 99th: 6_876_251
/// 95th: 6_811_463
/// 75th: 6_751_221
pub const BlockExecutionWeight: Weight = WEIGHT_PER_NANOS.saturating_mul(6_731_894);
pub const BlockExecutionWeight: Weight =
Weight::from_ref_time(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(6_731_894));
}

#[cfg(test)]
Expand All @@ -67,12 +68,12 @@ mod test_weights {

// At least 100 µs.
assert!(
w.ref_time() >= 100u64 * constants::WEIGHT_PER_MICROS.ref_time(),
w.ref_time() >= 100u64 * constants::WEIGHT_REF_TIME_PER_MICROS,
"Weight should be at least 100 µs."
);
// At most 50 ms.
assert!(
w.ref_time() <= 50u64 * constants::WEIGHT_PER_MILLIS.ref_time(),
w.ref_time() <= 50u64 * constants::WEIGHT_REF_TIME_PER_MILLIS,
"Weight should be at most 50 ms."
);
}
Expand Down
9 changes: 5 additions & 4 deletions relay/kusama/constants/src/weights/extrinsic_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
// --header=./file_header.txt

use sp_core::parameter_types;
use sp_weights::{constants::WEIGHT_PER_NANOS, Weight};
use sp_weights::{constants::WEIGHT_REF_TIME_PER_NANOS, Weight};

parameter_types! {
/// Time to execute a NO-OP extrinsic, for example `System::remark`.
Expand All @@ -51,7 +51,8 @@ parameter_types! {
/// 99th: 96_279
/// 95th: 95_584
/// 75th: 95_005
pub const ExtrinsicBaseWeight: Weight = WEIGHT_PER_NANOS.saturating_mul(94_889);
pub const ExtrinsicBaseWeight: Weight =
Weight::from_ref_time(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(94_889));
}

#[cfg(test)]
Expand All @@ -67,12 +68,12 @@ mod test_weights {

// At least 10 µs.
assert!(
w.ref_time() >= 10u64 * constants::WEIGHT_PER_MICROS.ref_time(),
w.ref_time() >= 10u64 * constants::WEIGHT_REF_TIME_PER_MICROS,
"Weight should be at least 10 µs."
);
// At most 1 ms.
assert!(
w.ref_time() <= constants::WEIGHT_PER_MILLIS.ref_time(),
w.ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
"Weight should be at most 1 ms."
);
}
Expand Down
12 changes: 6 additions & 6 deletions relay/kusama/constants/src/weights/paritydb_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pub mod constants {
/// `ParityDB` can be enabled with a feature flag, but is still experimental. These weights
/// are available for brave runtime engineers who may want to try this out as default.
pub const ParityDbWeight: RuntimeDbWeight = RuntimeDbWeight {
read: 8_000 * constants::WEIGHT_PER_NANOS.ref_time(),
write: 50_000 * constants::WEIGHT_PER_NANOS.ref_time(),
read: 8_000 * constants::WEIGHT_REF_TIME_PER_NANOS,
write: 50_000 * constants::WEIGHT_REF_TIME_PER_NANOS,
};
}

Expand All @@ -42,20 +42,20 @@ pub mod constants {
fn sane() {
// At least 1 µs.
assert!(
W::get().reads(1).ref_time() >= constants::WEIGHT_PER_MICROS.ref_time(),
W::get().reads(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
"Read weight should be at least 1 µs."
);
assert!(
W::get().writes(1).ref_time() >= constants::WEIGHT_PER_MICROS.ref_time(),
W::get().writes(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
"Write weight should be at least 1 µs."
);
// At most 1 ms.
assert!(
W::get().reads(1).ref_time() <= constants::WEIGHT_PER_MILLIS.ref_time(),
W::get().reads(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
"Read weight should be at most 1 ms."
);
assert!(
W::get().writes(1).ref_time() <= constants::WEIGHT_PER_MILLIS.ref_time(),
W::get().writes(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
"Write weight should be at most 1 ms."
);
}
Expand Down
12 changes: 6 additions & 6 deletions relay/kusama/constants/src/weights/rocksdb_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pub mod constants {
/// By default, Substrate uses `RocksDB`, so this will be the weight used throughout
/// the runtime.
pub const RocksDbWeight: RuntimeDbWeight = RuntimeDbWeight {
read: 25_000 * constants::WEIGHT_PER_NANOS.ref_time(),
write: 100_000 * constants::WEIGHT_PER_NANOS.ref_time(),
read: 25_000 * constants::WEIGHT_REF_TIME_PER_NANOS,
write: 100_000 * constants::WEIGHT_REF_TIME_PER_NANOS,
};
}

Expand All @@ -42,20 +42,20 @@ pub mod constants {
fn sane() {
// At least 1 µs.
assert!(
W::get().reads(1).ref_time() >= constants::WEIGHT_PER_MICROS.ref_time(),
W::get().reads(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
"Read weight should be at least 1 µs."
);
assert!(
W::get().writes(1).ref_time() >= constants::WEIGHT_PER_MICROS.ref_time(),
W::get().writes(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
"Write weight should be at least 1 µs."
);
// At most 1 ms.
assert!(
W::get().reads(1).ref_time() <= constants::WEIGHT_PER_MILLIS.ref_time(),
W::get().reads(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
"Read weight should be at most 1 ms."
);
assert!(
W::get().writes(1).ref_time() <= constants::WEIGHT_PER_MILLIS.ref_time(),
W::get().writes(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
"Write weight should be at most 1 ms."
);
}
Expand Down
9 changes: 5 additions & 4 deletions relay/polkadot/constants/src/weights/block_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
// --header=./file_header.txt

use sp_core::parameter_types;
use sp_weights::{constants::WEIGHT_PER_NANOS, Weight};
use sp_weights::{constants::WEIGHT_REF_TIME_PER_NANOS, Weight};

parameter_types! {
/// Time to execute an empty block.
Expand All @@ -51,7 +51,8 @@ parameter_types! {
/// 99th: 6_239_600
/// 95th: 6_178_734
/// 75th: 6_145_812
pub const BlockExecutionWeight: Weight = WEIGHT_PER_NANOS.saturating_mul(6_103_588);
pub const BlockExecutionWeight: Weight =
Weight::from_ref_time(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(6_103_588));
}

#[cfg(test)]
Expand All @@ -67,12 +68,12 @@ mod test_weights {

// At least 100 µs.
assert!(
w.ref_time() >= 100u64 * constants::WEIGHT_PER_MICROS.ref_time(),
w.ref_time() >= 100u64 * constants::WEIGHT_REF_TIME_PER_MICROS,
"Weight should be at least 100 µs."
);
// At most 50 ms.
assert!(
w.ref_time() <= 50u64 * constants::WEIGHT_PER_MILLIS.ref_time(),
w.ref_time() <= 50u64 * constants::WEIGHT_REF_TIME_PER_MILLIS,
"Weight should be at most 50 ms."
);
}
Expand Down
9 changes: 5 additions & 4 deletions relay/polkadot/constants/src/weights/extrinsic_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
// --header=./file_header.txt

use sp_core::parameter_types;
use sp_weights::{constants::WEIGHT_PER_NANOS, Weight};
use sp_weights::{constants::WEIGHT_REF_TIME_PER_NANOS, Weight};

parameter_types! {
/// Time to execute a NO-OP extrinsic, for example `System::remark`.
Expand All @@ -51,7 +51,8 @@ parameter_types! {
/// 99th: 96_351
/// 95th: 96_116
/// 75th: 95_639
pub const ExtrinsicBaseWeight: Weight = WEIGHT_PER_NANOS.saturating_mul(95_479);
pub const ExtrinsicBaseWeight: Weight =
Weight::from_ref_time(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(95_479));
}

#[cfg(test)]
Expand All @@ -67,12 +68,12 @@ mod test_weights {

// At least 10 µs.
assert!(
w.ref_time() >= 10u64 * constants::WEIGHT_PER_MICROS.ref_time(),
w.ref_time() >= 10u64 * constants::WEIGHT_REF_TIME_PER_MICROS,
"Weight should be at least 10 µs."
);
// At most 1 ms.
assert!(
w.ref_time() <= constants::WEIGHT_PER_MILLIS.ref_time(),
w.ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
"Weight should be at most 1 ms."
);
}
Expand Down
12 changes: 6 additions & 6 deletions relay/polkadot/constants/src/weights/paritydb_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub mod constants {
/// 99th: 14_451
/// 95th: 12_588
/// 75th: 11_200
read: 11_826 * constants::WEIGHT_PER_NANOS.ref_time(),
read: 11_826 * constants::WEIGHT_REF_TIME_PER_NANOS,

/// Time to write one storage item.
/// Calculated by multiplying the *Average* of all values with `1.1` and adding `0`.
Expand All @@ -72,7 +72,7 @@ pub mod constants {
/// 99th: 69_379
/// 95th: 47_168
/// 75th: 35_252
write: 38_052 * constants::WEIGHT_PER_NANOS.ref_time(),
write: 38_052 * constants::WEIGHT_REF_TIME_PER_NANOS,
};
}

Expand All @@ -88,20 +88,20 @@ pub mod constants {
fn bound() {
// At least 1 µs.
assert!(
W::get().reads(1).ref_time() >= constants::WEIGHT_PER_MICROS.ref_time(),
W::get().reads(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
"Read weight should be at least 1 µs."
);
assert!(
W::get().writes(1).ref_time() >= constants::WEIGHT_PER_MICROS.ref_time(),
W::get().writes(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
"Write weight should be at least 1 µs."
);
// At most 1 ms.
assert!(
W::get().reads(1).ref_time() <= constants::WEIGHT_PER_MILLIS.ref_time(),
W::get().reads(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
"Read weight should be at most 1 ms."
);
assert!(
W::get().writes(1).ref_time() <= constants::WEIGHT_PER_MILLIS.ref_time(),
W::get().writes(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
"Write weight should be at most 1 ms."
);
}
Expand Down
12 changes: 6 additions & 6 deletions relay/polkadot/constants/src/weights/rocksdb_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub mod constants {
/// 99th: 32_074
/// 95th: 26_658
/// 75th: 19_363
read: 20_499 * constants::WEIGHT_PER_NANOS.ref_time(),
read: 20_499 * constants::WEIGHT_REF_TIME_PER_NANOS,

/// Time to write one storage item.
/// Calculated by multiplying the *Average* of all values with `1.1` and adding `0`.
Expand All @@ -71,7 +71,7 @@ pub mod constants {
/// 99th: 111_151
/// 95th: 92_666
/// 75th: 80_297
write: 83_471 * constants::WEIGHT_PER_NANOS.ref_time(),
write: 83_471 * constants::WEIGHT_REF_TIME_PER_NANOS,
};
}

Expand All @@ -87,20 +87,20 @@ pub mod constants {
fn bound() {
// At least 1 µs.
assert!(
W::get().reads(1).ref_time() >= constants::WEIGHT_PER_MICROS.ref_time(),
W::get().reads(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
"Read weight should be at least 1 µs."
);
assert!(
W::get().writes(1).ref_time() >= constants::WEIGHT_PER_MICROS.ref_time(),
W::get().writes(1).ref_time() >= constants::WEIGHT_REF_TIME_PER_MICROS,
"Write weight should be at least 1 µs."
);
// At most 1 ms.
assert!(
W::get().reads(1).ref_time() <= constants::WEIGHT_PER_MILLIS.ref_time(),
W::get().reads(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
"Read weight should be at most 1 ms."
);
assert!(
W::get().writes(1).ref_time() <= constants::WEIGHT_PER_MILLIS.ref_time(),
W::get().writes(1).ref_time() <= constants::WEIGHT_REF_TIME_PER_MILLIS,
"Write weight should be at most 1 ms."
);
}
Expand Down

0 comments on commit 3b05b99

Please sign in to comment.