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 4 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))
}
}
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
13 changes: 8 additions & 5 deletions frame/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4365,9 +4365,10 @@ mod election_data_provider {
#[test]
fn targets_2sec_block() {
let mut validators = 1000;
while <Test as Config>::WeightInfo::get_npos_targets(validators)
.all_lt(2u64 * frame_support::weights::constants::WEIGHT_PER_SECOND)
{
while <Test as Config>::WeightInfo::get_npos_targets(validators).all_lt(Weight::from_parts(
2u64 * frame_support::weights::constants::WEIGHT_REF_TIME_PER_SECOND,
u64::MAX,
)) {
validators += 1;
}

Expand All @@ -4384,8 +4385,10 @@ mod election_data_provider {
let mut nominators = 1000;

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

Expand Down
9 changes: 5 additions & 4 deletions frame/support/src/weights/block_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
// --repeat=100

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 @@ -53,7 +53,8 @@ parameter_types! {
/// 99th: 390_723
/// 95th: 365_799
/// 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)]
Expand All @@ -69,12 +70,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 frame/support/src/weights/extrinsic_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
// --repeat=100

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 @@ -53,7 +53,8 @@ parameter_types! {
/// 99th: 99_202
/// 95th: 99_163
/// 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)]
Expand All @@ -69,12 +70,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 frame/support/src/weights/paritydb_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,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 @@ -41,20 +41,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
Loading