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

Introduce sensible weight constants #12868

Merged
merged 6 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ pub use frame_support::{
ConstU128, ConstU32, ConstU64, ConstU8, KeyOwnerProofSystem, Randomness, StorageInfo,
},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
constants::{
BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND,
},
IdentityFee, Weight,
},
StorageValue,
Expand Down Expand Up @@ -141,7 +143,7 @@ parameter_types! {
/// We allow for 2 seconds of compute with a 6 second average block time.
pub BlockWeights: frame_system::limits::BlockWeights =
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,
);
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
Expand Down
7 changes: 5 additions & 2 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ use frame_support::{
WithdrawReasons,
},
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
constants::{
BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND,
},
ConstantMultiplier, IdentityFee, Weight,
},
PalletId, RuntimeDebug,
Expand Down Expand Up @@ -173,7 +175,8 @@ const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
/// by Operational extrinsics.
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.
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! {
pub const BlockHashCount: BlockNumber = 2400;
Expand Down
4 changes: 2 additions & 2 deletions docs/Upgrading-2.0-to-3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ And update the overall definition for weights on frame and a few related types a
+/// by Operational extrinsics.
+const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
+/// 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! {
pub const BlockHashCount: BlockNumber = 2400;
- /// 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);
- /// Assume 10% of weight for average on_initialize calls.
- pub MaximumExtrinsicWeight: Weight =
Expand Down
21 changes: 12 additions & 9 deletions frame/babe/src/default_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! This file was not auto-generated.

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,
};

Expand All @@ -38,17 +38,20 @@ impl crate::WeightInfo for () {
const MAX_NOMINATORS: u64 = 200;

// checking membership proof
let ref_time_weight = (35u64 * WEIGHT_PER_MICROS)
.saturating_add((175u64 * WEIGHT_PER_NANOS).saturating_mul(validator_count))
Weight::from_ref_time(35u64 * WEIGHT_REF_TIME_PER_MICROS)
.saturating_add(
Weight::from_ref_time(175u64 * WEIGHT_REF_TIME_PER_NANOS)
.saturating_mul(validator_count),
)
.saturating_add(DbWeight::get().reads(5))
// check equivocation proof
.saturating_add(110u64 * WEIGHT_PER_MICROS)
.saturating_add(Weight::from_ref_time(110u64 * WEIGHT_REF_TIME_PER_MICROS))
// report offence
.saturating_add(110u64 * WEIGHT_PER_MICROS)
.saturating_add(25u64 * WEIGHT_PER_MICROS * MAX_NOMINATORS)
.saturating_add(Weight::from_ref_time(110u64 * WEIGHT_REF_TIME_PER_MICROS))
.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().writes(10 + 3 * MAX_NOMINATORS));

ref_time_weight
.saturating_add(DbWeight::get().writes(10 + 3 * MAX_NOMINATORS))
}
}
4 changes: 2 additions & 2 deletions frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use frame_support::{
BalanceStatus, ConstU32, ConstU64, Contains, Currency, Get, LockableCurrency, OnIdle,
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 pretty_assertions::{assert_eq, assert_ne};
Expand Down Expand Up @@ -285,7 +285,7 @@ impl RegisteredChainExtension<Test> for TempStorageExtension {
parameter_types! {
pub BlockWeights: frame_system::limits::BlockWeights =
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;
}
Expand Down
4 changes: 3 additions & 1 deletion frame/democracy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ impl Contains<RuntimeCall> for BaseFilter {

parameter_types! {
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 {
type BaseCallFilter = BaseFilter;
Expand Down
2 changes: 1 addition & 1 deletion frame/election-provider-multi-phase/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ parameter_types! {
pub const ExistentialDeposit: u64 = 1;
pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights
::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,
);
}
Expand Down
4 changes: 2 additions & 2 deletions frame/fast-unstake/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use frame_support::{
pallet_prelude::*,
parameter_types,
traits::{ConstU64, Currency},
weights::constants::WEIGHT_PER_SECOND,
weights::constants::WEIGHT_REF_TIME_PER_SECOND,
};
use sp_runtime::traits::{Convert, IdentityLookup};

Expand All @@ -37,7 +37,7 @@ pub type T = Runtime;
parameter_types! {
pub BlockWeights: frame_system::limits::BlockWeights =
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),
);
}

Expand Down
20 changes: 13 additions & 7 deletions frame/grandpa/src/default_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! This file was not auto-generated.

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,
};

Expand All @@ -34,21 +34,27 @@ impl crate::WeightInfo for () {
const MAX_NOMINATORS: u64 = 200;

// checking membership proof
(35u64 * WEIGHT_PER_MICROS)
.saturating_add((175u64 * WEIGHT_PER_NANOS).saturating_mul(validator_count))
Weight::from_ref_time(35u64 * WEIGHT_REF_TIME_PER_MICROS)
.saturating_add(
Weight::from_ref_time(175u64 * WEIGHT_REF_TIME_PER_NANOS)
.saturating_mul(validator_count),
)
.saturating_add(DbWeight::get().reads(5))
// check equivocation proof
.saturating_add(95u64 * WEIGHT_PER_MICROS)
.saturating_add(Weight::from_ref_time(95u64 * WEIGHT_REF_TIME_PER_MICROS))
// report offence
.saturating_add(110u64 * WEIGHT_PER_MICROS)
.saturating_add(25u64 * WEIGHT_PER_MICROS * MAX_NOMINATORS)
.saturating_add(Weight::from_ref_time(110u64 * WEIGHT_REF_TIME_PER_MICROS))
.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().writes(10 + 3 * MAX_NOMINATORS))
// fetching set id -> session index mappings
.saturating_add(DbWeight::get().reads(2))
}

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))
}
}
58 changes: 29 additions & 29 deletions frame/lottery/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! Autogenerated weights for pallet_lottery
//!
//! 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`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024

Expand Down Expand Up @@ -67,33 +67,33 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: System Account (r:1 w:1)
// Storage: Lottery Tickets (r:0 w:1)
fn buy_ticket() -> Weight {
// Minimum execution time: 53_735 nanoseconds.
Weight::from_ref_time(54_235_000)
// Minimum execution time: 52_479 nanoseconds.
Weight::from_ref_time(53_225_000)
.saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().writes(4))
}
// Storage: Lottery CallIndices (r:0 w:1)
/// The range of component `n` is `[0, 10]`.
fn set_calls(n: u32, ) -> Weight {
// Minimum execution time: 15_065 nanoseconds.
Weight::from_ref_time(16_467_398)
// Standard Error: 5_392
.saturating_add(Weight::from_ref_time(294_914).saturating_mul(n.into()))
// Minimum execution time: 14_433 nanoseconds.
Weight::from_ref_time(15_660_780)
// Standard Error: 5_894
.saturating_add(Weight::from_ref_time(290_482).saturating_mul(n.into()))
.saturating_add(T::DbWeight::get().writes(1))
}
// Storage: Lottery Lottery (r:1 w:1)
// Storage: Lottery LotteryIndex (r:1 w:1)
// Storage: System Account (r:1 w:1)
fn start_lottery() -> Weight {
// Minimum execution time: 45_990 nanoseconds.
Weight::from_ref_time(46_789_000)
// Minimum execution time: 43_683 nanoseconds.
Weight::from_ref_time(44_580_000)
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(3))
}
// Storage: Lottery Lottery (r:1 w:1)
fn stop_repeat() -> Weight {
// Minimum execution time: 10_783 nanoseconds.
Weight::from_ref_time(11_180_000)
// Minimum execution time: 10_514 nanoseconds.
Weight::from_ref_time(10_821_000)
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
Expand All @@ -103,8 +103,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Lottery TicketsCount (r:1 w:1)
// Storage: Lottery Tickets (r:1 w:0)
fn on_initialize_end() -> Weight {
// Minimum execution time: 62_088 nanoseconds.
Weight::from_ref_time(63_670_000)
// Minimum execution time: 60_254 nanoseconds.
Weight::from_ref_time(61_924_000)
.saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().writes(4))
}
Expand All @@ -115,8 +115,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
// Storage: Lottery Tickets (r:1 w:0)
// Storage: Lottery LotteryIndex (r:1 w:1)
fn on_initialize_repeat() -> Weight {
// Minimum execution time: 64_953 nanoseconds.
Weight::from_ref_time(65_465_000)
// Minimum execution time: 61_552 nanoseconds.
Weight::from_ref_time(62_152_000)
.saturating_add(T::DbWeight::get().reads(7))
.saturating_add(T::DbWeight::get().writes(5))
}
Expand All @@ -132,33 +132,33 @@ impl WeightInfo for () {
// Storage: System Account (r:1 w:1)
// Storage: Lottery Tickets (r:0 w:1)
fn buy_ticket() -> Weight {
// Minimum execution time: 53_735 nanoseconds.
Weight::from_ref_time(54_235_000)
// Minimum execution time: 52_479 nanoseconds.
Weight::from_ref_time(53_225_000)
.saturating_add(RocksDbWeight::get().reads(6))
.saturating_add(RocksDbWeight::get().writes(4))
}
// Storage: Lottery CallIndices (r:0 w:1)
/// The range of component `n` is `[0, 10]`.
fn set_calls(n: u32, ) -> Weight {
// Minimum execution time: 15_065 nanoseconds.
Weight::from_ref_time(16_467_398)
// Standard Error: 5_392
.saturating_add(Weight::from_ref_time(294_914).saturating_mul(n.into()))
// Minimum execution time: 14_433 nanoseconds.
Weight::from_ref_time(15_660_780)
// Standard Error: 5_894
.saturating_add(Weight::from_ref_time(290_482).saturating_mul(n.into()))
.saturating_add(RocksDbWeight::get().writes(1))
}
// Storage: Lottery Lottery (r:1 w:1)
// Storage: Lottery LotteryIndex (r:1 w:1)
// Storage: System Account (r:1 w:1)
fn start_lottery() -> Weight {
// Minimum execution time: 45_990 nanoseconds.
Weight::from_ref_time(46_789_000)
// Minimum execution time: 43_683 nanoseconds.
Weight::from_ref_time(44_580_000)
.saturating_add(RocksDbWeight::get().reads(3))
.saturating_add(RocksDbWeight::get().writes(3))
}
// Storage: Lottery Lottery (r:1 w:1)
fn stop_repeat() -> Weight {
// Minimum execution time: 10_783 nanoseconds.
Weight::from_ref_time(11_180_000)
// Minimum execution time: 10_514 nanoseconds.
Weight::from_ref_time(10_821_000)
.saturating_add(RocksDbWeight::get().reads(1))
.saturating_add(RocksDbWeight::get().writes(1))
}
Expand All @@ -168,8 +168,8 @@ impl WeightInfo for () {
// Storage: Lottery TicketsCount (r:1 w:1)
// Storage: Lottery Tickets (r:1 w:0)
fn on_initialize_end() -> Weight {
// Minimum execution time: 62_088 nanoseconds.
Weight::from_ref_time(63_670_000)
// Minimum execution time: 60_254 nanoseconds.
Weight::from_ref_time(61_924_000)
.saturating_add(RocksDbWeight::get().reads(6))
.saturating_add(RocksDbWeight::get().writes(4))
}
Expand All @@ -180,8 +180,8 @@ impl WeightInfo for () {
// Storage: Lottery Tickets (r:1 w:0)
// Storage: Lottery LotteryIndex (r:1 w:1)
fn on_initialize_repeat() -> Weight {
// Minimum execution time: 64_953 nanoseconds.
Weight::from_ref_time(65_465_000)
// Minimum execution time: 61_552 nanoseconds.
Weight::from_ref_time(62_152_000)
.saturating_add(RocksDbWeight::get().reads(7))
.saturating_add(RocksDbWeight::get().writes(5))
}
Expand Down
4 changes: 2 additions & 2 deletions frame/merkle-mountain-range/src/default_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! This file was not auto-generated.

use frame_support::weights::{
constants::{RocksDbWeight as DbWeight, WEIGHT_PER_NANOS},
constants::{RocksDbWeight as DbWeight, WEIGHT_REF_TIME_PER_NANOS},
Weight,
};

Expand All @@ -28,7 +28,7 @@ impl crate::WeightInfo for () {
// Reading the parent hash.
let leaf_weight = DbWeight::get().reads(1);
// 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.
let hook_weight = Weight::zero();

Expand Down
4 changes: 2 additions & 2 deletions frame/offences/benchmarking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use frame_election_provider_support::{onchain, SequentialPhragmen};
use frame_support::{
parameter_types,
traits::{ConstU32, ConstU64},
weights::constants::WEIGHT_PER_SECOND,
weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight},
};
use frame_system as system;
use pallet_session::historical as pallet_session_historical;
Expand All @@ -41,7 +41,7 @@ type Balance = u64;
parameter_types! {
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(
2u64 * WEIGHT_PER_SECOND
Weight::from_parts(2u64 * WEIGHT_REF_TIME_PER_SECOND, u64::MAX)
);
}

Expand Down
6 changes: 4 additions & 2 deletions frame/offences/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use frame_support::{
parameter_types,
traits::{ConstU32, ConstU64},
weights::{
constants::{RocksDbWeight, WEIGHT_PER_SECOND},
constants::{RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND},
Weight,
},
};
Expand Down Expand Up @@ -85,7 +85,9 @@ frame_support::construct_runtime!(

parameter_types! {
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 {
type BaseCallFilter = frame_support::traits::Everything;
Expand Down
2 changes: 1 addition & 1 deletion frame/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl FindAuthor<AccountId> for Author11 {
parameter_types! {
pub BlockWeights: frame_system::limits::BlockWeights =
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 ExistentialDeposit: Balance = 1;
Expand Down
Loading