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

Remove RefTimeWeight #12157

Merged
merged 22 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from 18 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
26 changes: 13 additions & 13 deletions .maintain/frame-weight-template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#![allow(unused_parens)]
#![allow(unused_imports)]

use frame_support::{traits::Get, weights::{RefTimeWeight, Weight, constants::RocksDbWeight}};
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use sp_std::marker::PhantomData;

/// Weight functions needed for {{pallet}}.
Expand Down Expand Up @@ -64,22 +64,22 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
{{~#each benchmark.components as |c| ~}}
{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
) -> Weight {
Weight::from_ref_time({{underscore benchmark.base_weight}} as RefTimeWeight)
Weight::from_ref_time({{underscore benchmark.base_weight}} as u64)
{{#each benchmark.component_weight as |cw|}}
// Standard Error: {{underscore cw.error}}
.saturating_add(Weight::from_ref_time({{underscore cw.slope}} as RefTimeWeight).scalar_saturating_mul({{cw.name}} as RefTimeWeight))
.saturating_add(Weight::from_ref_time({{underscore cw.slope}} as u64).saturating_mul({{cw.name}} as u64))
{{/each}}
{{#if (ne benchmark.base_reads "0")}}
.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}} as RefTimeWeight))
.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}} as u64))
{{/if}}
{{#each benchmark.component_reads as |cr|}}
.saturating_add(T::DbWeight::get().reads(({{cr.slope}} as RefTimeWeight).saturating_mul({{cr.name}} as RefTimeWeight)))
.saturating_add(T::DbWeight::get().reads(({{cr.slope}} as u64).saturating_mul({{cr.name}} as u64)))
{{/each}}
{{#if (ne benchmark.base_writes "0")}}
.saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}} as RefTimeWeight))
.saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}} as u64))
{{/if}}
{{#each benchmark.component_writes as |cw|}}
.saturating_add(T::DbWeight::get().writes(({{cw.slope}} as RefTimeWeight).saturating_mul({{cw.name}} as RefTimeWeight)))
.saturating_add(T::DbWeight::get().writes(({{cw.slope}} as u64).saturating_mul({{cw.name}} as u64)))
{{/each}}
}
{{/each}}
Expand All @@ -99,22 +99,22 @@ impl WeightInfo for () {
{{~#each benchmark.components as |c| ~}}
{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
) -> Weight {
Weight::from_ref_time({{underscore benchmark.base_weight}} as RefTimeWeight)
Weight::from_ref_time({{underscore benchmark.base_weight}} as u64)
{{#each benchmark.component_weight as |cw|}}
// Standard Error: {{underscore cw.error}}
.saturating_add(Weight::from_ref_time({{underscore cw.slope}} as RefTimeWeight).scalar_saturating_mul({{cw.name}} as RefTimeWeight))
.saturating_add(Weight::from_ref_time({{underscore cw.slope}} as u64).saturating_mul({{cw.name}} as u64))
{{/each}}
{{#if (ne benchmark.base_reads "0")}}
.saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}} as RefTimeWeight))
.saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}} as u64))
{{/if}}
{{#each benchmark.component_reads as |cr|}}
.saturating_add(RocksDbWeight::get().reads(({{cr.slope}} as RefTimeWeight).saturating_mul({{cr.name}} as RefTimeWeight)))
.saturating_add(RocksDbWeight::get().reads(({{cr.slope}} as u64).saturating_mul({{cr.name}} as u64)))
{{/each}}
{{#if (ne benchmark.base_writes "0")}}
.saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}} as RefTimeWeight))
.saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}} as u64))
{{/if}}
{{#each benchmark.component_writes as |cw|}}
.saturating_add(RocksDbWeight::get().writes(({{cw.slope}} as RefTimeWeight).saturating_mul({{cw.name}} as RefTimeWeight)))
.saturating_add(RocksDbWeight::get().writes(({{cw.slope}} as u64).saturating_mul({{cw.name}} as u64)))
{{/each}}
}
{{/each}}
Expand Down
2 changes: 1 addition & 1 deletion bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ parameter_types! {
pub const Version: RuntimeVersion = VERSION;
/// 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(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
::with_sensible_defaults(2u64 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
pub const SS58Prefix: u8 = 42;
Expand Down
14 changes: 7 additions & 7 deletions bin/node/runtime/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ mod multiplier_tests {
#[test]
fn multiplier_cannot_go_below_limit() {
// will not go any further below even if block is empty.
run_with_system_weight(Weight::new(), || {
run_with_system_weight(Weight::zero(), || {
let next = runtime_multiplier_update(min_multiplier());
assert_eq!(next, min_multiplier());
})
Expand All @@ -247,7 +247,7 @@ mod multiplier_tests {
// 1 < 0.00001 * k * 0.1875
// 10^9 / 1875 < k
// k > 533_333 ~ 18,5 days.
run_with_system_weight(Weight::new(), || {
run_with_system_weight(Weight::zero(), || {
// start from 1, the default.
let mut fm = Multiplier::one();
let mut iterations: u64 = 0;
Expand Down Expand Up @@ -409,20 +409,20 @@ mod multiplier_tests {
#[test]
fn weight_to_fee_should_not_overflow_on_large_weights() {
let kb = Weight::from_ref_time(1024);
let mb = kb * kb;
let mb = 1024u64 * kb;
let max_fm = Multiplier::saturating_from_integer(i128::MAX);

// check that for all values it can compute, correctly.
vec![
Weight::zero(),
Weight::one(),
Weight::from_ref_time(1),
Weight::from_ref_time(10),
Weight::from_ref_time(1000),
kb,
10 * kb,
100 * kb,
10u64 * kb,
100u64 * kb,
mb,
10 * mb,
10u64 * mb,
Weight::from_ref_time(2147483647),
Weight::from_ref_time(4294967295),
BlockWeights::get().max_block / 2,
Expand Down
2 changes: 1 addition & 1 deletion bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ 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.
const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.scalar_saturating_mul(2);
const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND.saturating_mul(2);

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 = 2 * WEIGHT_PER_SECOND;
+const MAXIMUM_BLOCK_WEIGHT: Weight = 2u64 * WEIGHT_PER_SECOND;
+
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 = 2 * WEIGHT_PER_SECOND;
- pub const MaximumBlockWeight: Weight = 2u64 * WEIGHT_PER_SECOND;
- pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
- /// Assume 10% of weight for average on_initialize calls.
- pub MaximumExtrinsicWeight: Weight =
Expand Down
2 changes: 1 addition & 1 deletion frame/alliance/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
/// Wrapper for all migrations of this pallet.
pub fn migrate<T: Config<I>, I: 'static>() -> Weight {
let onchain_version = Pallet::<T, I>::on_chain_storage_version();
let mut weight: Weight = Weight::new();
let mut weight: Weight = Weight::zero();

if onchain_version < 1 {
weight = weight.saturating_add(v0_to_v1::migrate::<T, I>());
Expand Down
Loading