Introduce sensible weight constants (#12868)

* Introduce sensible weight constants

* cargo fmt

* Remove unused import

* Add missing import

* ".git/.scripts/bench-bot.sh" pallet dev pallet_lottery

Co-authored-by: command-bot <>
This commit is contained in:
Keith Yeung
2022-12-09 01:18:51 +09:00
committed by GitHub
parent 200f49d66d
commit 51db8c77a7
26 changed files with 140 additions and 113 deletions
@@ -32,7 +32,9 @@ pub use frame_support::{
ConstU128, ConstU32, ConstU64, ConstU8, KeyOwnerProofSystem, Randomness, StorageInfo, ConstU128, ConstU32, ConstU64, ConstU8, KeyOwnerProofSystem, Randomness, StorageInfo,
}, },
weights::{ weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND}, constants::{
BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND,
},
IdentityFee, Weight, IdentityFee, Weight,
}, },
StorageValue, StorageValue,
@@ -141,7 +143,7 @@ parameter_types! {
/// We allow for 2 seconds of compute with a 6 second average block time. /// We allow for 2 seconds of compute with a 6 second average block time.
pub BlockWeights: frame_system::limits::BlockWeights = pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::with_sensible_defaults( frame_system::limits::BlockWeights::with_sensible_defaults(
(2u64 * WEIGHT_PER_SECOND).set_proof_size(u64::MAX), Weight::from_parts(2u64 * WEIGHT_REF_TIME_PER_SECOND, u64::MAX),
NORMAL_DISPATCH_RATIO, NORMAL_DISPATCH_RATIO,
); );
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
+5 -2
View File
@@ -38,7 +38,9 @@ use frame_support::{
WithdrawReasons, WithdrawReasons,
}, },
weights::{ weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND}, constants::{
BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND,
},
ConstantMultiplier, IdentityFee, Weight, ConstantMultiplier, IdentityFee, Weight,
}, },
PalletId, RuntimeDebug, PalletId, RuntimeDebug,
@@ -173,7 +175,8 @@ const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
/// by Operational extrinsics. /// by Operational extrinsics.
const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
/// We allow for 2 seconds of compute with a 6 second average block time, with maximum proof size. /// We allow for 2 seconds of compute with a 6 second average block time, with maximum proof size.
const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.saturating_mul(2).set_proof_size(u64::MAX); const MAXIMUM_BLOCK_WEIGHT: Weight =
Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2), u64::MAX);
parameter_types! { parameter_types! {
pub const BlockHashCount: BlockNumber = 2400; pub const BlockHashCount: BlockNumber = 2400;
+2 -2
View File
@@ -100,12 +100,12 @@ And update the overall definition for weights on frame and a few related types a
+/// by Operational extrinsics. +/// by Operational extrinsics.
+const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); +const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
+/// We allow for 2 seconds of compute with a 6 second average block time. +/// We allow for 2 seconds of compute with a 6 second average block time.
+const MAXIMUM_BLOCK_WEIGHT: Weight = 2u64 * WEIGHT_PER_SECOND; +const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(2u64 * WEIGHT_REF_TIME_PER_SECOND, u64::MAX);
+ +
parameter_types! { parameter_types! {
pub const BlockHashCount: BlockNumber = 2400; pub const BlockHashCount: BlockNumber = 2400;
- /// We allow for 2 seconds of compute with a 6 second average block time. - /// We allow for 2 seconds of compute with a 6 second average block time.
- pub const MaximumBlockWeight: Weight = 2u64 * WEIGHT_PER_SECOND; - pub const MaximumBlockWeight: Weight = Weight::from_parts(2u64 * WEIGHT_REF_TIME_PER_SECOND, u64::MAX);
- pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75); - pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
- /// Assume 10% of weight for average on_initialize calls. - /// Assume 10% of weight for average on_initialize calls.
- pub MaximumExtrinsicWeight: Weight = - pub MaximumExtrinsicWeight: Weight =
+12 -9
View File
@@ -19,7 +19,7 @@
//! This file was not auto-generated. //! This file was not auto-generated.
use frame_support::weights::{ use frame_support::weights::{
constants::{RocksDbWeight as DbWeight, WEIGHT_PER_MICROS, WEIGHT_PER_NANOS}, constants::{RocksDbWeight as DbWeight, WEIGHT_REF_TIME_PER_MICROS, WEIGHT_REF_TIME_PER_NANOS},
Weight, Weight,
}; };
@@ -38,17 +38,20 @@ impl crate::WeightInfo for () {
const MAX_NOMINATORS: u64 = 200; const MAX_NOMINATORS: u64 = 200;
// checking membership proof // checking membership proof
let ref_time_weight = (35u64 * WEIGHT_PER_MICROS) Weight::from_ref_time(35u64 * WEIGHT_REF_TIME_PER_MICROS)
.saturating_add((175u64 * WEIGHT_PER_NANOS).saturating_mul(validator_count)) .saturating_add(
Weight::from_ref_time(175u64 * WEIGHT_REF_TIME_PER_NANOS)
.saturating_mul(validator_count),
)
.saturating_add(DbWeight::get().reads(5)) .saturating_add(DbWeight::get().reads(5))
// check equivocation proof // check equivocation proof
.saturating_add(110u64 * WEIGHT_PER_MICROS) .saturating_add(Weight::from_ref_time(110u64 * WEIGHT_REF_TIME_PER_MICROS))
// report offence // report offence
.saturating_add(110u64 * WEIGHT_PER_MICROS) .saturating_add(Weight::from_ref_time(110u64 * WEIGHT_REF_TIME_PER_MICROS))
.saturating_add(25u64 * WEIGHT_PER_MICROS * MAX_NOMINATORS) .saturating_add(Weight::from_ref_time(
25u64 * WEIGHT_REF_TIME_PER_MICROS * MAX_NOMINATORS,
))
.saturating_add(DbWeight::get().reads(14 + 3 * MAX_NOMINATORS)) .saturating_add(DbWeight::get().reads(14 + 3 * MAX_NOMINATORS))
.saturating_add(DbWeight::get().writes(10 + 3 * MAX_NOMINATORS)); .saturating_add(DbWeight::get().writes(10 + 3 * MAX_NOMINATORS))
ref_time_weight
} }
} }
+2 -2
View File
@@ -40,7 +40,7 @@ use frame_support::{
fungibles::Lockable, BalanceStatus, ConstU32, ConstU64, Contains, Currency, Get, OnIdle, fungibles::Lockable, BalanceStatus, ConstU32, ConstU64, Contains, Currency, Get, OnIdle,
OnInitialize, ReservableCurrency, WithdrawReasons, OnInitialize, ReservableCurrency, WithdrawReasons,
}, },
weights::{constants::WEIGHT_PER_SECOND, Weight}, weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
}; };
use frame_system::{self as system, EventRecord, Phase}; use frame_system::{self as system, EventRecord, Phase};
use pretty_assertions::{assert_eq, assert_ne}; use pretty_assertions::{assert_eq, assert_ne};
@@ -285,7 +285,7 @@ impl RegisteredChainExtension<Test> for TempStorageExtension {
parameter_types! { parameter_types! {
pub BlockWeights: frame_system::limits::BlockWeights = pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max( frame_system::limits::BlockWeights::simple_max(
(2u64 * WEIGHT_PER_SECOND).set_proof_size(u64::MAX), Weight::from_parts(2u64 * WEIGHT_REF_TIME_PER_SECOND, u64::MAX),
); );
pub static ExistentialDeposit: u64 = 1; pub static ExistentialDeposit: u64 = 1;
} }
+3 -1
View File
@@ -77,7 +77,9 @@ impl Contains<RuntimeCall> for BaseFilter {
parameter_types! { parameter_types! {
pub BlockWeights: frame_system::limits::BlockWeights = pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(frame_support::weights::constants::WEIGHT_PER_SECOND.set_proof_size(u64::MAX)); frame_system::limits::BlockWeights::simple_max(
Weight::from_parts(frame_support::weights::constants::WEIGHT_REF_TIME_PER_SECOND, u64::MAX),
);
} }
impl frame_system::Config for Test { impl frame_system::Config for Test {
type BaseCallFilter = BaseFilter; type BaseCallFilter = BaseFilter;
@@ -239,7 +239,7 @@ parameter_types! {
pub const ExistentialDeposit: u64 = 1; pub const ExistentialDeposit: u64 = 1;
pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights
::with_sensible_defaults( ::with_sensible_defaults(
Weight::from_parts(2u64 * constants::WEIGHT_PER_SECOND.ref_time(), u64::MAX), Weight::from_parts(2u64 * constants::WEIGHT_REF_TIME_PER_SECOND, u64::MAX),
NORMAL_DISPATCH_RATIO, NORMAL_DISPATCH_RATIO,
); );
} }
+2 -2
View File
@@ -21,7 +21,7 @@ use frame_support::{
pallet_prelude::*, pallet_prelude::*,
parameter_types, parameter_types,
traits::{ConstU64, Currency}, traits::{ConstU64, Currency},
weights::constants::WEIGHT_PER_SECOND, weights::constants::WEIGHT_REF_TIME_PER_SECOND,
}; };
use sp_runtime::traits::{Convert, IdentityLookup}; use sp_runtime::traits::{Convert, IdentityLookup};
@@ -37,7 +37,7 @@ pub type T = Runtime;
parameter_types! { parameter_types! {
pub BlockWeights: frame_system::limits::BlockWeights = pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max( frame_system::limits::BlockWeights::simple_max(
(2u64 * WEIGHT_PER_SECOND).set_proof_size(u64::MAX), Weight::from_parts(2u64 * WEIGHT_REF_TIME_PER_SECOND, u64::MAX),
); );
} }
+13 -7
View File
@@ -19,7 +19,7 @@
//! This file was not auto-generated. //! This file was not auto-generated.
use frame_support::weights::{ use frame_support::weights::{
constants::{RocksDbWeight as DbWeight, WEIGHT_PER_MICROS, WEIGHT_PER_NANOS}, constants::{RocksDbWeight as DbWeight, WEIGHT_REF_TIME_PER_MICROS, WEIGHT_REF_TIME_PER_NANOS},
Weight, Weight,
}; };
@@ -34,14 +34,19 @@ impl crate::WeightInfo for () {
const MAX_NOMINATORS: u64 = 200; const MAX_NOMINATORS: u64 = 200;
// checking membership proof // checking membership proof
(35u64 * WEIGHT_PER_MICROS) Weight::from_ref_time(35u64 * WEIGHT_REF_TIME_PER_MICROS)
.saturating_add((175u64 * WEIGHT_PER_NANOS).saturating_mul(validator_count)) .saturating_add(
Weight::from_ref_time(175u64 * WEIGHT_REF_TIME_PER_NANOS)
.saturating_mul(validator_count),
)
.saturating_add(DbWeight::get().reads(5)) .saturating_add(DbWeight::get().reads(5))
// check equivocation proof // check equivocation proof
.saturating_add(95u64 * WEIGHT_PER_MICROS) .saturating_add(Weight::from_ref_time(95u64 * WEIGHT_REF_TIME_PER_MICROS))
// report offence // report offence
.saturating_add(110u64 * WEIGHT_PER_MICROS) .saturating_add(Weight::from_ref_time(110u64 * WEIGHT_REF_TIME_PER_MICROS))
.saturating_add(25u64 * WEIGHT_PER_MICROS * MAX_NOMINATORS) .saturating_add(Weight::from_ref_time(
25u64 * WEIGHT_REF_TIME_PER_MICROS * MAX_NOMINATORS,
))
.saturating_add(DbWeight::get().reads(14 + 3 * MAX_NOMINATORS)) .saturating_add(DbWeight::get().reads(14 + 3 * MAX_NOMINATORS))
.saturating_add(DbWeight::get().writes(10 + 3 * MAX_NOMINATORS)) .saturating_add(DbWeight::get().writes(10 + 3 * MAX_NOMINATORS))
// fetching set id -> session index mappings // fetching set id -> session index mappings
@@ -49,6 +54,7 @@ impl crate::WeightInfo for () {
} }
fn note_stalled() -> Weight { fn note_stalled() -> Weight {
(3u64 * WEIGHT_PER_MICROS).saturating_add(DbWeight::get().writes(1)) Weight::from_ref_time(3u64 * WEIGHT_REF_TIME_PER_MICROS)
.saturating_add(DbWeight::get().writes(1))
} }
} }
+29 -29
View File
@@ -18,7 +18,7 @@
//! Autogenerated weights for pallet_lottery //! Autogenerated weights for pallet_lottery
//! //!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2022-11-18, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! DATE: 2022-12-08, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` //! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
@@ -67,33 +67,33 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: System Account (r:1 w:1) // Storage: System Account (r:1 w:1)
// Storage: Lottery Tickets (r:0 w:1) // Storage: Lottery Tickets (r:0 w:1)
fn buy_ticket() -> Weight { fn buy_ticket() -> Weight {
// Minimum execution time: 53_735 nanoseconds. // Minimum execution time: 52_479 nanoseconds.
Weight::from_ref_time(54_235_000) Weight::from_ref_time(53_225_000)
.saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().writes(4)) .saturating_add(T::DbWeight::get().writes(4))
} }
// Storage: Lottery CallIndices (r:0 w:1) // Storage: Lottery CallIndices (r:0 w:1)
/// The range of component `n` is `[0, 10]`. /// The range of component `n` is `[0, 10]`.
fn set_calls(n: u32, ) -> Weight { fn set_calls(n: u32, ) -> Weight {
// Minimum execution time: 15_065 nanoseconds. // Minimum execution time: 14_433 nanoseconds.
Weight::from_ref_time(16_467_398) Weight::from_ref_time(15_660_780)
// Standard Error: 5_392 // Standard Error: 5_894
.saturating_add(Weight::from_ref_time(294_914).saturating_mul(n.into())) .saturating_add(Weight::from_ref_time(290_482).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().writes(1)) .saturating_add(T::DbWeight::get().writes(1))
} }
// Storage: Lottery Lottery (r:1 w:1) // Storage: Lottery Lottery (r:1 w:1)
// Storage: Lottery LotteryIndex (r:1 w:1) // Storage: Lottery LotteryIndex (r:1 w:1)
// Storage: System Account (r:1 w:1) // Storage: System Account (r:1 w:1)
fn start_lottery() -> Weight { fn start_lottery() -> Weight {
// Minimum execution time: 45_990 nanoseconds. // Minimum execution time: 43_683 nanoseconds.
Weight::from_ref_time(46_789_000) Weight::from_ref_time(44_580_000)
.saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(3)) .saturating_add(T::DbWeight::get().writes(3))
} }
// Storage: Lottery Lottery (r:1 w:1) // Storage: Lottery Lottery (r:1 w:1)
fn stop_repeat() -> Weight { fn stop_repeat() -> Weight {
// Minimum execution time: 10_783 nanoseconds. // Minimum execution time: 10_514 nanoseconds.
Weight::from_ref_time(11_180_000) Weight::from_ref_time(10_821_000)
.saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1)) .saturating_add(T::DbWeight::get().writes(1))
} }
@@ -103,8 +103,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Lottery TicketsCount (r:1 w:1) // Storage: Lottery TicketsCount (r:1 w:1)
// Storage: Lottery Tickets (r:1 w:0) // Storage: Lottery Tickets (r:1 w:0)
fn on_initialize_end() -> Weight { fn on_initialize_end() -> Weight {
// Minimum execution time: 62_088 nanoseconds. // Minimum execution time: 60_254 nanoseconds.
Weight::from_ref_time(63_670_000) Weight::from_ref_time(61_924_000)
.saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().writes(4)) .saturating_add(T::DbWeight::get().writes(4))
} }
@@ -115,8 +115,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Lottery Tickets (r:1 w:0) // Storage: Lottery Tickets (r:1 w:0)
// Storage: Lottery LotteryIndex (r:1 w:1) // Storage: Lottery LotteryIndex (r:1 w:1)
fn on_initialize_repeat() -> Weight { fn on_initialize_repeat() -> Weight {
// Minimum execution time: 64_953 nanoseconds. // Minimum execution time: 61_552 nanoseconds.
Weight::from_ref_time(65_465_000) Weight::from_ref_time(62_152_000)
.saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().reads(7))
.saturating_add(T::DbWeight::get().writes(5)) .saturating_add(T::DbWeight::get().writes(5))
} }
@@ -132,33 +132,33 @@ impl WeightInfo for () {
// Storage: System Account (r:1 w:1) // Storage: System Account (r:1 w:1)
// Storage: Lottery Tickets (r:0 w:1) // Storage: Lottery Tickets (r:0 w:1)
fn buy_ticket() -> Weight { fn buy_ticket() -> Weight {
// Minimum execution time: 53_735 nanoseconds. // Minimum execution time: 52_479 nanoseconds.
Weight::from_ref_time(54_235_000) Weight::from_ref_time(53_225_000)
.saturating_add(RocksDbWeight::get().reads(6)) .saturating_add(RocksDbWeight::get().reads(6))
.saturating_add(RocksDbWeight::get().writes(4)) .saturating_add(RocksDbWeight::get().writes(4))
} }
// Storage: Lottery CallIndices (r:0 w:1) // Storage: Lottery CallIndices (r:0 w:1)
/// The range of component `n` is `[0, 10]`. /// The range of component `n` is `[0, 10]`.
fn set_calls(n: u32, ) -> Weight { fn set_calls(n: u32, ) -> Weight {
// Minimum execution time: 15_065 nanoseconds. // Minimum execution time: 14_433 nanoseconds.
Weight::from_ref_time(16_467_398) Weight::from_ref_time(15_660_780)
// Standard Error: 5_392 // Standard Error: 5_894
.saturating_add(Weight::from_ref_time(294_914).saturating_mul(n.into())) .saturating_add(Weight::from_ref_time(290_482).saturating_mul(n.into()))
.saturating_add(RocksDbWeight::get().writes(1)) .saturating_add(RocksDbWeight::get().writes(1))
} }
// Storage: Lottery Lottery (r:1 w:1) // Storage: Lottery Lottery (r:1 w:1)
// Storage: Lottery LotteryIndex (r:1 w:1) // Storage: Lottery LotteryIndex (r:1 w:1)
// Storage: System Account (r:1 w:1) // Storage: System Account (r:1 w:1)
fn start_lottery() -> Weight { fn start_lottery() -> Weight {
// Minimum execution time: 45_990 nanoseconds. // Minimum execution time: 43_683 nanoseconds.
Weight::from_ref_time(46_789_000) Weight::from_ref_time(44_580_000)
.saturating_add(RocksDbWeight::get().reads(3)) .saturating_add(RocksDbWeight::get().reads(3))
.saturating_add(RocksDbWeight::get().writes(3)) .saturating_add(RocksDbWeight::get().writes(3))
} }
// Storage: Lottery Lottery (r:1 w:1) // Storage: Lottery Lottery (r:1 w:1)
fn stop_repeat() -> Weight { fn stop_repeat() -> Weight {
// Minimum execution time: 10_783 nanoseconds. // Minimum execution time: 10_514 nanoseconds.
Weight::from_ref_time(11_180_000) Weight::from_ref_time(10_821_000)
.saturating_add(RocksDbWeight::get().reads(1)) .saturating_add(RocksDbWeight::get().reads(1))
.saturating_add(RocksDbWeight::get().writes(1)) .saturating_add(RocksDbWeight::get().writes(1))
} }
@@ -168,8 +168,8 @@ impl WeightInfo for () {
// Storage: Lottery TicketsCount (r:1 w:1) // Storage: Lottery TicketsCount (r:1 w:1)
// Storage: Lottery Tickets (r:1 w:0) // Storage: Lottery Tickets (r:1 w:0)
fn on_initialize_end() -> Weight { fn on_initialize_end() -> Weight {
// Minimum execution time: 62_088 nanoseconds. // Minimum execution time: 60_254 nanoseconds.
Weight::from_ref_time(63_670_000) Weight::from_ref_time(61_924_000)
.saturating_add(RocksDbWeight::get().reads(6)) .saturating_add(RocksDbWeight::get().reads(6))
.saturating_add(RocksDbWeight::get().writes(4)) .saturating_add(RocksDbWeight::get().writes(4))
} }
@@ -180,8 +180,8 @@ impl WeightInfo for () {
// Storage: Lottery Tickets (r:1 w:0) // Storage: Lottery Tickets (r:1 w:0)
// Storage: Lottery LotteryIndex (r:1 w:1) // Storage: Lottery LotteryIndex (r:1 w:1)
fn on_initialize_repeat() -> Weight { fn on_initialize_repeat() -> Weight {
// Minimum execution time: 64_953 nanoseconds. // Minimum execution time: 61_552 nanoseconds.
Weight::from_ref_time(65_465_000) Weight::from_ref_time(62_152_000)
.saturating_add(RocksDbWeight::get().reads(7)) .saturating_add(RocksDbWeight::get().reads(7))
.saturating_add(RocksDbWeight::get().writes(5)) .saturating_add(RocksDbWeight::get().writes(5))
} }
@@ -19,7 +19,7 @@
//! This file was not auto-generated. //! This file was not auto-generated.
use frame_support::weights::{ use frame_support::weights::{
constants::{RocksDbWeight as DbWeight, WEIGHT_PER_NANOS}, constants::{RocksDbWeight as DbWeight, WEIGHT_REF_TIME_PER_NANOS},
Weight, Weight,
}; };
@@ -28,7 +28,7 @@ impl crate::WeightInfo for () {
// Reading the parent hash. // Reading the parent hash.
let leaf_weight = DbWeight::get().reads(1); let leaf_weight = DbWeight::get().reads(1);
// Blake2 hash cost. // Blake2 hash cost.
let hash_weight = 2u64 * WEIGHT_PER_NANOS; let hash_weight = Weight::from_ref_time(2u64 * WEIGHT_REF_TIME_PER_NANOS);
// No-op hook. // No-op hook.
let hook_weight = Weight::zero(); let hook_weight = Weight::zero();
@@ -24,7 +24,7 @@ use frame_election_provider_support::{onchain, SequentialPhragmen};
use frame_support::{ use frame_support::{
parameter_types, parameter_types,
traits::{ConstU32, ConstU64}, traits::{ConstU32, ConstU64},
weights::constants::WEIGHT_PER_SECOND, weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
}; };
use frame_system as system; use frame_system as system;
use pallet_session::historical as pallet_session_historical; use pallet_session::historical as pallet_session_historical;
@@ -41,7 +41,7 @@ type Balance = u64;
parameter_types! { parameter_types! {
pub BlockWeights: frame_system::limits::BlockWeights = pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max( frame_system::limits::BlockWeights::simple_max(
2u64 * WEIGHT_PER_SECOND Weight::from_parts(2u64 * WEIGHT_REF_TIME_PER_SECOND, u64::MAX)
); );
} }
+4 -2
View File
@@ -26,7 +26,7 @@ use frame_support::{
parameter_types, parameter_types,
traits::{ConstU32, ConstU64}, traits::{ConstU32, ConstU64},
weights::{ weights::{
constants::{RocksDbWeight, WEIGHT_PER_SECOND}, constants::{RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND},
Weight, Weight,
}, },
}; };
@@ -85,7 +85,9 @@ frame_support::construct_runtime!(
parameter_types! { parameter_types! {
pub BlockWeights: frame_system::limits::BlockWeights = pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(2u64 * WEIGHT_PER_SECOND); frame_system::limits::BlockWeights::simple_max(
Weight::from_parts(2u64 * WEIGHT_REF_TIME_PER_SECOND, u64::MAX),
);
} }
impl frame_system::Config for Runtime { impl frame_system::Config for Runtime {
type BaseCallFilter = frame_support::traits::Everything; type BaseCallFilter = frame_support::traits::Everything;
+1 -1
View File
@@ -115,7 +115,7 @@ impl FindAuthor<AccountId> for Author11 {
parameter_types! { parameter_types! {
pub BlockWeights: frame_system::limits::BlockWeights = pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max( frame_system::limits::BlockWeights::simple_max(
frame_support::weights::constants::WEIGHT_PER_SECOND * 2 Weight::from_parts(frame_support::weights::constants::WEIGHT_REF_TIME_PER_SECOND * 2, u64::MAX),
); );
pub static SessionsPerEra: SessionIndex = 3; pub static SessionsPerEra: SessionIndex = 3;
pub static ExistentialDeposit: Balance = 1; pub static ExistentialDeposit: Balance = 1;
+8 -5
View File
@@ -4365,9 +4365,10 @@ mod election_data_provider {
#[test] #[test]
fn targets_2sec_block() { fn targets_2sec_block() {
let mut validators = 1000; let mut validators = 1000;
while <Test as Config>::WeightInfo::get_npos_targets(validators) while <Test as Config>::WeightInfo::get_npos_targets(validators).all_lt(Weight::from_parts(
.all_lt(2u64 * frame_support::weights::constants::WEIGHT_PER_SECOND) 2u64 * frame_support::weights::constants::WEIGHT_REF_TIME_PER_SECOND,
{ u64::MAX,
)) {
validators += 1; validators += 1;
} }
@@ -4384,8 +4385,10 @@ mod election_data_provider {
let mut nominators = 1000; let mut nominators = 1000;
while <Test as Config>::WeightInfo::get_npos_voters(validators, nominators, slashing_spans) while <Test as Config>::WeightInfo::get_npos_voters(validators, nominators, slashing_spans)
.all_lt(2u64 * frame_support::weights::constants::WEIGHT_PER_SECOND) .all_lt(Weight::from_parts(
{ 2u64 * frame_support::weights::constants::WEIGHT_REF_TIME_PER_SECOND,
u64::MAX,
)) {
nominators += 1; nominators += 1;
} }
@@ -37,7 +37,7 @@
// --repeat=100 // --repeat=100
use sp_core::parameter_types; 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! { parameter_types! {
/// Time to execute an empty block. /// Time to execute an empty block.
@@ -53,7 +53,8 @@ parameter_types! {
/// 99th: 390_723 /// 99th: 390_723
/// 95th: 365_799 /// 95th: 365_799
/// 75th: 361_582 /// 75th: 361_582
pub const BlockExecutionWeight: Weight = WEIGHT_PER_NANOS.saturating_mul(358_523); pub const BlockExecutionWeight: Weight =
Weight::from_ref_time(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(358_523));
} }
#[cfg(test)] #[cfg(test)]
@@ -69,12 +70,12 @@ mod test_weights {
// At least 100 µs. // At least 100 µs.
assert!( 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." "Weight should be at least 100 µs."
); );
// At most 50 ms. // At most 50 ms.
assert!( 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." "Weight should be at most 50 ms."
); );
} }
@@ -37,7 +37,7 @@
// --repeat=100 // --repeat=100
use sp_core::parameter_types; 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! { parameter_types! {
/// Time to execute a NO-OP extrinsic, for example `System::remark`. /// Time to execute a NO-OP extrinsic, for example `System::remark`.
@@ -53,7 +53,8 @@ parameter_types! {
/// 99th: 99_202 /// 99th: 99_202
/// 95th: 99_163 /// 95th: 99_163
/// 75th: 99_030 /// 75th: 99_030
pub const ExtrinsicBaseWeight: Weight = WEIGHT_PER_NANOS.saturating_mul(98_974); pub const ExtrinsicBaseWeight: Weight =
Weight::from_ref_time(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(98_974));
} }
#[cfg(test)] #[cfg(test)]
@@ -69,12 +70,12 @@ mod test_weights {
// At least 10 µs. // At least 10 µs.
assert!( 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." "Weight should be at least 10 µs."
); );
// At most 1 ms. // At most 1 ms.
assert!( 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." "Weight should be at most 1 ms."
); );
} }
@@ -24,8 +24,8 @@ pub mod constants {
/// ParityDB can be enabled with a feature flag, but is still experimental. These weights /// 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. /// are available for brave runtime engineers who may want to try this out as default.
pub const ParityDbWeight: RuntimeDbWeight = RuntimeDbWeight { pub const ParityDbWeight: RuntimeDbWeight = RuntimeDbWeight {
read: 8_000 * constants::WEIGHT_PER_NANOS.ref_time(), read: 8_000 * constants::WEIGHT_REF_TIME_PER_NANOS,
write: 50_000 * constants::WEIGHT_PER_NANOS.ref_time(), write: 50_000 * constants::WEIGHT_REF_TIME_PER_NANOS,
}; };
} }
@@ -41,20 +41,20 @@ pub mod constants {
fn sane() { fn sane() {
// At least 1 µs. // At least 1 µs.
assert!( 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." "Read weight should be at least 1 µs."
); );
assert!( 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." "Write weight should be at least 1 µs."
); );
// At most 1 ms. // At most 1 ms.
assert!( 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." "Read weight should be at most 1 ms."
); );
assert!( 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." "Write weight should be at most 1 ms."
); );
} }
@@ -24,8 +24,8 @@ pub mod constants {
/// By default, Substrate uses RocksDB, so this will be the weight used throughout /// By default, Substrate uses RocksDB, so this will be the weight used throughout
/// the runtime. /// the runtime.
pub const RocksDbWeight: RuntimeDbWeight = RuntimeDbWeight { pub const RocksDbWeight: RuntimeDbWeight = RuntimeDbWeight {
read: 25_000 * constants::WEIGHT_PER_NANOS.ref_time(), read: 25_000 * constants::WEIGHT_REF_TIME_PER_NANOS,
write: 100_000 * constants::WEIGHT_PER_NANOS.ref_time(), write: 100_000 * constants::WEIGHT_REF_TIME_PER_NANOS,
}; };
} }
@@ -41,20 +41,20 @@ pub mod constants {
fn sane() { fn sane() {
// At least 1 µs. // At least 1 µs.
assert!( 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." "Read weight should be at least 1 µs."
); );
assert!( 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." "Write weight should be at least 1 µs."
); );
// At most 1 ms. // At most 1 ms.
assert!( 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." "Read weight should be at most 1 ms."
); );
assert!( 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." "Write weight should be at most 1 ms."
); );
} }
+1 -1
View File
@@ -208,7 +208,7 @@ pub struct BlockWeights {
impl Default for BlockWeights { impl Default for BlockWeights {
fn default() -> Self { fn default() -> Self {
Self::with_sensible_defaults( Self::with_sensible_defaults(
Weight::from_parts(constants::WEIGHT_PER_SECOND.ref_time(), u64::MAX), Weight::from_parts(constants::WEIGHT_REF_TIME_PER_SECOND, u64::MAX),
DEFAULT_NORMAL_RATIO, DEFAULT_NORMAL_RATIO,
) )
} }
+6 -5
View File
@@ -47,12 +47,13 @@ pub use weight_meter::*;
pub use weight_v2::*; pub use weight_v2::*;
pub mod constants { pub mod constants {
use super::Weight; pub const WEIGHT_REF_TIME_PER_SECOND: u64 = 1_000_000_000_000;
pub const WEIGHT_REF_TIME_PER_MILLIS: u64 = 1_000_000_000;
pub const WEIGHT_REF_TIME_PER_MICROS: u64 = 1_000_000;
pub const WEIGHT_REF_TIME_PER_NANOS: u64 = 1_000;
pub const WEIGHT_PER_SECOND: Weight = Weight::from_ref_time(1_000_000_000_000); pub const WEIGHT_PROOF_SIZE_PER_MB: u64 = 1024 * 1024;
pub const WEIGHT_PER_MILLIS: Weight = Weight::from_ref_time(1_000_000_000); pub const WEIGHT_PROOF_SIZE_PER_KB: u64 = 1024;
pub const WEIGHT_PER_MICROS: Weight = Weight::from_ref_time(1_000_000);
pub const WEIGHT_PER_NANOS: Weight = Weight::from_ref_time(1_000);
} }
/// The old weight type. /// The old weight type.
@@ -18,7 +18,7 @@
//! Contains the core benchmarking logic. //! Contains the core benchmarking logic.
use codec::DecodeAll; use codec::DecodeAll;
use frame_support::weights::constants::WEIGHT_PER_NANOS; use frame_support::weights::constants::WEIGHT_REF_TIME_PER_NANOS;
use frame_system::ConsumedWeight; use frame_system::ConsumedWeight;
use sc_block_builder::{BlockBuilderApi, BlockBuilderProvider}; use sc_block_builder::{BlockBuilderApi, BlockBuilderProvider};
use sc_cli::{Error, Result}; use sc_cli::{Error, Result};
@@ -148,7 +148,7 @@ where
let weight = ConsumedWeight::decode_all(&mut raw_weight)?; let weight = ConsumedWeight::decode_all(&mut raw_weight)?;
// Should be divisible, but still use floats in case we ever change that. // Should be divisible, but still use floats in case we ever change that.
Ok((weight.total().ref_time() as f64 / WEIGHT_PER_NANOS.ref_time() as f64).floor() Ok((weight.total().ref_time() as f64 / WEIGHT_REF_TIME_PER_NANOS as f64).floor()
as NanoSeconds) as NanoSeconds)
} }
@@ -30,7 +30,8 @@ The file will contain the concrete weight value and various statistics about the
/// 99th: 3_631_863 /// 99th: 3_631_863
/// 95th: 3_595_674 /// 95th: 3_595_674
/// 75th: 3_526_435 /// 75th: 3_526_435
pub const BlockExecutionWeight: Weight = WEIGHT_PER_NANOS.saturating_mul(3_532_484); pub const BlockExecutionWeight: Weight =
Weight::from_ref_time(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(3_532_484));
``` ```
In this example it takes 3.5 ms to execute an empty block. That means that it always takes at least 3.5 ms to execute *any* block. In this example it takes 3.5 ms to execute an empty block. That means that it always takes at least 3.5 ms to execute *any* block.
@@ -59,7 +60,8 @@ The relevant section in the output file looks like this:
/// 99th: 68_758 /// 99th: 68_758
/// 95th: 67_843 /// 95th: 67_843
/// 75th: 67_749 /// 75th: 67_749
pub const ExtrinsicBaseWeight: Weight = WEIGHT_PER_NANOS.saturating_mul(67_745); pub const ExtrinsicBaseWeight: Weight =
Weight::from_ref_time(WEIGHT_REF_TIME_PER_NANOS.saturating_mul(67_745));
``` ```
In this example it takes 67.7 µs to execute a NO-OP extrinsic. That means that it always takes at least 67.7 µs to execute *any* extrinsic. In this example it takes 67.7 µs to execute a NO-OP extrinsic. That means that it always takes at least 67.7 µs to execute *any* extrinsic.
@@ -14,7 +14,7 @@
{{/each}} {{/each}}
use sp_core::parameter_types; 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! { parameter_types! {
{{#if (eq short_name "block")}} {{#if (eq short_name "block")}}
@@ -34,7 +34,8 @@ parameter_types! {
/// 99th: {{underscore stats.p99}} /// 99th: {{underscore stats.p99}}
/// 95th: {{underscore stats.p95}} /// 95th: {{underscore stats.p95}}
/// 75th: {{underscore stats.p75}} /// 75th: {{underscore stats.p75}}
pub const {{long_name}}Weight: Weight = WEIGHT_PER_NANOS.saturating_mul({{underscore weight}}); pub const {{long_name}}Weight: Weight =
Weight::from_ref_time(WEIGHT_REF_TIME_PER_NANOS.saturating_mul({{underscore weight}}));
} }
#[cfg(test)] #[cfg(test)]
@@ -51,23 +52,23 @@ mod test_weights {
{{#if (eq short_name "block")}} {{#if (eq short_name "block")}}
// At least 100 µs. // At least 100 µs.
assert!( 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." "Weight should be at least 100 µs."
); );
// At most 50 ms. // At most 50 ms.
assert!( 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." "Weight should be at most 50 ms."
); );
{{else}} {{else}}
// At least 10 µs. // At least 10 µs.
assert!( 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." "Weight should be at least 10 µs."
); );
// At most 1 ms. // At most 1 ms.
assert!( 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." "Weight should be at most 1 ms."
); );
{{/if}} {{/if}}
@@ -69,7 +69,7 @@ The interesting part in the generated weight file tells us the weight constants
/// 99th: 18_270 /// 99th: 18_270
/// 95th: 16_190 /// 95th: 16_190
/// 75th: 14_819 /// 75th: 14_819
read: 14_262 * constants::WEIGHT_PER_NANOS, read: 14_262 * constants::WEIGHT_REF_TIME_PER_NANOS,
/// Time to write one storage item. /// Time to write one storage item.
/// Calculated by multiplying the *Average* of all values with `1.1` and adding `0`. /// Calculated by multiplying the *Average* of all values with `1.1` and adding `0`.
@@ -84,7 +84,7 @@ read: 14_262 * constants::WEIGHT_PER_NANOS,
/// 99th: 135_839 /// 99th: 135_839
/// 95th: 106_129 /// 95th: 106_129
/// 75th: 79_239 /// 75th: 79_239
write: 71_347 * constants::WEIGHT_PER_NANOS, write: 71_347 * constants::WEIGHT_REF_TIME_PER_NANOS,
``` ```
## Arguments ## Arguments
@@ -43,7 +43,7 @@ pub mod constants {
/// 99th: {{underscore read.0.p99}} /// 99th: {{underscore read.0.p99}}
/// 95th: {{underscore read.0.p95}} /// 95th: {{underscore read.0.p95}}
/// 75th: {{underscore read.0.p75}} /// 75th: {{underscore read.0.p75}}
read: {{underscore read_weight}} * constants::WEIGHT_PER_NANOS, read: {{underscore read_weight}} * constants::WEIGHT_REF_TIME_PER_NANOS,
/// Time to write one storage item. /// Time to write one storage item.
/// Calculated by multiplying the *{{params.weight_params.weight_metric}}* of all values with `{{params.weight_params.weight_mul}}` and adding `{{params.weight_params.weight_add}}`. /// Calculated by multiplying the *{{params.weight_params.weight_metric}}* of all values with `{{params.weight_params.weight_mul}}` and adding `{{params.weight_params.weight_add}}`.
@@ -58,7 +58,7 @@ pub mod constants {
/// 99th: {{underscore write.0.p99}} /// 99th: {{underscore write.0.p99}}
/// 95th: {{underscore write.0.p95}} /// 95th: {{underscore write.0.p95}}
/// 75th: {{underscore write.0.p75}} /// 75th: {{underscore write.0.p75}}
write: {{underscore write_weight}} * constants::WEIGHT_PER_NANOS, write: {{underscore write_weight}} * constants::WEIGHT_REF_TIME_PER_NANOS,
}; };
} }
@@ -74,20 +74,20 @@ pub mod constants {
fn bound() { fn bound() {
// At least 1 µs. // At least 1 µs.
assert!( 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." "Read weight should be at least 1 µs."
); );
assert!( 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." "Write weight should be at least 1 µs."
); );
// At most 1 ms. // At most 1 ms.
assert!( 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." "Read weight should be at most 1 ms."
); );
assert!( 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." "Write weight should be at most 1 ms."
); );
} }