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

Companion for Weight v1.5 #5943

Merged
merged 22 commits into from
Aug 31, 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
342 changes: 172 additions & 170 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions node/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ sc-authority-discovery = { git = "https://github.com/paritytech/substrate", bran
babe = { package = "sc-consensus-babe", git = "https://github.com/paritytech/substrate", branch = "master" }
beefy-primitives = { git = "https://github.com/paritytech/substrate", branch = "master" }
beefy-gadget = { git = "https://github.com/paritytech/substrate", branch = "master" }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "master" }
grandpa = { package = "sc-finality-grandpa", git = "https://github.com/paritytech/substrate", branch = "master" }
sc-block-builder = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "master" }
Expand Down
3 changes: 2 additions & 1 deletion node/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//! Polkadot chain configurations.

use beefy_primitives::crypto::AuthorityId as BeefyId;
use frame_support::weights::Weight;
use grandpa::AuthorityId as GrandpaId;
#[cfg(feature = "kusama-native")]
use kusama_runtime as kusama;
Expand Down Expand Up @@ -189,7 +190,7 @@ fn default_parachains_host_configuration(
max_upward_queue_count: 8,
max_upward_queue_size: 1024 * 1024,
max_downward_message_size: 1024 * 1024,
ump_service_total_weight: 100_000_000_000,
ump_service_total_weight: Weight::from_ref_time(100_000_000_000),
max_upward_message_size: 50 * 1024,
max_upward_message_num_per_candidate: 5,
hrmp_sender_deposit: 0,
Expand Down
4 changes: 2 additions & 2 deletions parachain/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl DmpMessageHandler for () {
_max_weight: Weight,
) -> Weight {
iter.for_each(drop);
0
Weight::zero()
}
}

Expand Down Expand Up @@ -349,7 +349,7 @@ impl XcmpMessageHandler for () {
_max_weight: Weight,
) -> Weight {
for _ in iter {}
0
Weight::zero()
}
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/common/src/assigned_slots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub mod pallet {
}

// We didn't return early above, so we didn't do anything.
0
Weight::zero()
}
}

Expand Down
8 changes: 4 additions & 4 deletions runtime/common/src/auctions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ pub trait WeightInfo {
pub struct TestWeightInfo;
impl WeightInfo for TestWeightInfo {
fn new_auction() -> Weight {
0
Weight::zero()
}
fn bid() -> Weight {
0
Weight::zero()
}
fn cancel_auction() -> Weight {
0
Weight::zero()
}
fn on_initialize() -> Weight {
0
Weight::zero()
}
}

Expand Down
10 changes: 5 additions & 5 deletions runtime/common/src/claims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ pub trait WeightInfo {
pub struct TestWeightInfo;
impl WeightInfo for TestWeightInfo {
fn claim() -> Weight {
0
Weight::zero()
}
fn mint_claim() -> Weight {
0
Weight::zero()
}
fn claim_attest() -> Weight {
0
Weight::zero()
}
fn attest() -> Weight {
0
Weight::zero()
}
fn move_claim() -> Weight {
0
Weight::zero()
}
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/common/src/crowdloan/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub mod crowdloan_index_migration {
/// This migration converts crowdloans to use a crowdloan index rather than the parachain id as a
/// unique identifier. This makes it easier to swap two crowdloans between parachains.
pub fn migrate<T: Config>() -> frame_support::weights::Weight {
let mut weight = 0;
let mut weight = Weight::new();

// First migrate `NextTrieIndex` counter to `NextFundIndex`.

Expand Down
18 changes: 9 additions & 9 deletions runtime/common/src/crowdloan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,31 +106,31 @@ pub trait WeightInfo {
pub struct TestWeightInfo;
impl WeightInfo for TestWeightInfo {
fn create() -> Weight {
0
Weight::zero()
}
fn contribute() -> Weight {
0
Weight::zero()
}
fn withdraw() -> Weight {
0
Weight::zero()
}
fn refund(_k: u32) -> Weight {
0
Weight::zero()
}
fn dissolve() -> Weight {
0
Weight::zero()
}
fn edit() -> Weight {
0
Weight::zero()
}
fn add_memo() -> Weight {
0
Weight::zero()
}
fn on_initialize(_n: u32) -> Weight {
0
Weight::zero()
}
fn poke() -> Weight {
0
Weight::zero()
}
}

Expand Down
13 changes: 9 additions & 4 deletions runtime/common/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ where
#[cfg(test)]
mod tests {
use super::*;
use frame_support::{parameter_types, traits::FindAuthor, weights::DispatchClass, PalletId};
use frame_support::{
parameter_types,
traits::FindAuthor,
weights::{DispatchClass, Weight},
PalletId,
};
use frame_system::limits;
use primitives::v2::AccountId;
use sp_core::H256;
Expand Down Expand Up @@ -90,12 +95,12 @@ mod tests {
parameter_types! {
pub const BlockHashCount: u64 = 250;
pub BlockWeights: limits::BlockWeights = limits::BlockWeights::builder()
.base_block(10)
.base_block(Weight::from_ref_time(10))
.for_class(DispatchClass::all(), |weight| {
weight.base_extrinsic = 100;
weight.base_extrinsic = Weight::from_ref_time(100);
})
.for_class(DispatchClass::non_mandatory(), |weight| {
weight.max_total = Some(1024);
weight.max_total = Some(Weight::from_ref_time(1024));
})
.build_or_panic();
pub BlockLength: limits::BlockLength = limits::BlockLength::max(2 * 1024);
Expand Down
3 changes: 2 additions & 1 deletion runtime/common/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::{
use frame_support::{
assert_noop, assert_ok, parameter_types,
traits::{Currency, GenesisBuild, KeyOwnerProofSystem, OnFinalize, OnInitialize},
weights::Weight,
PalletId,
};
use frame_support_test::TestRandomness;
Expand Down Expand Up @@ -103,7 +104,7 @@ use crate::{auctions::Error as AuctionsError, crowdloan::Error as CrowdloanError
parameter_types! {
pub const BlockHashCount: u32 = 250;
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(4 * 1024 * 1024);
frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(4 * 1024 * 1024));
}

impl frame_system::Config for Test {
Expand Down
2 changes: 1 addition & 1 deletion runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(1);
/// by Operational extrinsics.
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);
/// We allow for 2 seconds of compute with a 6 second average block time.
pub const MAXIMUM_BLOCK_WEIGHT: Weight = 2 * WEIGHT_PER_SECOND;
pub const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.scalar_saturating_mul(2);

const_assert!(NORMAL_DISPATCH_RATIO.deconstruct() >= AVERAGE_ON_INITIALIZE_RATIO.deconstruct());

Expand Down
4 changes: 2 additions & 2 deletions runtime/common/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ impl frame_support::traits::EstimateNextSessionRotation<u32> for TestNextSession
}

fn estimate_current_session_progress(_now: u32) -> (Option<Permill>, Weight) {
(None, 0)
(None, Weight::zero())
}

fn estimate_next_session_rotation(_now: u32) -> (Option<u32>, Weight) {
(None, 0)
(None, Weight::zero())
}
}
12 changes: 6 additions & 6 deletions runtime/common/src/paras_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ pub trait WeightInfo {
pub struct TestWeightInfo;
impl WeightInfo for TestWeightInfo {
fn reserve() -> Weight {
0
Weight::zero()
}
fn register() -> Weight {
0
Weight::zero()
}
fn force_register() -> Weight {
0
Weight::zero()
}
fn deregister() -> Weight {
0
Weight::zero()
}
fn swap() -> Weight {
0
Weight::zero()
}
}

Expand Down Expand Up @@ -641,7 +641,7 @@ mod tests {
parameter_types! {
pub const BlockHashCount: u32 = 250;
pub BlockWeights: limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(1024);
frame_system::limits::BlockWeights::simple_max(Weight::from_ref_time(1024));
pub BlockLength: limits::BlockLength =
limits::BlockLength::max_with_normal_ratio(4 * 1024 * 1024, NORMAL_RATIO);
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/common/src/purchase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ pub mod pallet {
/// We check that the account does not exist at this stage.
///
/// Origin must match the `ValidityOrigin`.
#[pallet::weight(200_000_000 + T::DbWeight::get().reads_writes(4, 1))]
#[pallet::weight(Weight::from_ref_time(200_000_000) + T::DbWeight::get().reads_writes(4, 1))]
pub fn create_account(
origin: OriginFor<T>,
who: T::AccountId,
Expand Down
2 changes: 1 addition & 1 deletion runtime/common/src/slots/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub mod slots_crowdloan_index_migration {
}

pub fn migrate<T: Config + crowdloan::Config>() -> frame_support::weights::Weight {
let mut weight = 0;
let mut weight = Weight::new();

for (para_id, mut leases) in Leases::<T>::iter() {
weight = weight.saturating_add(T::DbWeight::get().reads(2));
Expand Down
10 changes: 5 additions & 5 deletions runtime/common/src/slots/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ pub trait WeightInfo {
pub struct TestWeightInfo;
impl WeightInfo for TestWeightInfo {
fn force_lease() -> Weight {
0
Weight::zero()
}
fn manage_lease_period_start(_c: u32, _t: u32) -> Weight {
0
Weight::zero()
}
fn clear_all_leases() -> Weight {
0
Weight::zero()
}
fn trigger_onboard() -> Weight {
0
Weight::zero()
}
}

Expand Down Expand Up @@ -155,7 +155,7 @@ pub mod pallet {
}

// We didn't return early above, so we didn't do anything.
0
Weight::zero()
}
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/kusama/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub mod fee {
fn polynomial() -> WeightToFeeCoefficients<Self::Balance> {
// in Kusama, extrinsic base weight (smallest non-zero weight) is mapped to 1/10 CENT:
let p = super::currency::CENTS;
let q = 10 * Balance::from(ExtrinsicBaseWeight::get());
let q = 10 * Balance::from(ExtrinsicBaseWeight::get().ref_time());
smallvec![WeightToFeeCoefficient {
degree: 1,
negative: false,
Expand Down
2 changes: 1 addition & 1 deletion runtime/kusama/constants/src/weights/block_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ parameter_types! {
/// 99th: 6_332_047
/// 95th: 6_308_225
/// 75th: 6_236_204
pub const BlockExecutionWeight: Weight = 6_192_341 * WEIGHT_PER_NANOS;
pub const BlockExecutionWeight: Weight = WEIGHT_PER_NANOS.scalar_saturating_mul(6_192_341);
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion runtime/kusama/constants/src/weights/extrinsic_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ parameter_types! {
/// 99th: 87_527
/// 95th: 86_901
/// 75th: 86_308
pub const ExtrinsicBaseWeight: Weight = 86_309 * WEIGHT_PER_NANOS;
pub const ExtrinsicBaseWeight: Weight = WEIGHT_PER_NANOS.scalar_saturating_mul(86_309);
}

#[cfg(test)]
Expand Down
4 changes: 2 additions & 2 deletions runtime/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,
write: 50_000 * constants::WEIGHT_PER_NANOS,
read: 8_000 * constants::WEIGHT_PER_NANOS.ref_time(),
write: 50_000 * constants::WEIGHT_PER_NANOS.ref_time(),
};
}

Expand Down
4 changes: 2 additions & 2 deletions runtime/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,
write: 100_000 * constants::WEIGHT_PER_NANOS,
read: 25_000 * constants::WEIGHT_PER_NANOS.ref_time(),
write: 100_000 * constants::WEIGHT_PER_NANOS.ref_time(),
};
}

Expand Down
6 changes: 3 additions & 3 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ impl parachains_paras::Config for Runtime {
}

parameter_types! {
pub const FirstMessageFactorPercent: u64 = 100;
pub const FirstMessageFactorPercent: Weight = Weight::from_ref_time(100);
}

impl parachains_ump::Config for Runtime {
Expand Down Expand Up @@ -2089,8 +2089,8 @@ mod multiplier_tests {

let call = frame_system::Call::<Runtime>::fill_block {
ratio: Perbill::from_rational(
block_weight,
BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap(),
block_weight.ref_time(),
BlockWeights::get().get(DispatchClass::Normal).max_total.unwrap().ref_time(),
),
};
println!("calling {:?}", call);
Expand Down
12 changes: 7 additions & 5 deletions runtime/kusama/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ fn sample_size_is_sensible() {
#[test]
fn payout_weight_portion() {
use pallet_staking::WeightInfo;
let payout_weight = <Runtime as pallet_staking::Config>::WeightInfo::payout_stakers_alive_staked(
MaxNominatorRewardedPerValidator::get(),
) as f64;
let block_weight = BlockWeights::get().max_block as f64;
let payout_weight =
<Runtime as pallet_staking::Config>::WeightInfo::payout_stakers_alive_staked(
MaxNominatorRewardedPerValidator::get(),
)
.ref_time() as f64;
let block_weight = BlockWeights::get().max_block.ref_time() as f64;

println!(
"a full payout takes {:.2} of the block weight [{} / {}]",
Expand Down Expand Up @@ -97,7 +99,7 @@ fn transfer_cost_min_multiplier() {
let fee = TransactionPayment::compute_fee(len, &info, 0);
println!(
"weight = {:?} // multiplier = {:?} // full transfer fee = {:?}",
info.weight.separated_string(),
info.weight.ref_time().separated_string(),
pallet_transaction_payment::NextFeeMultiplier::<Runtime>::get(),
fee.separated_string(),
);
Expand Down
Loading