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

Commit

Permalink
Weight v1.5 Follow Ups (#12155)
Browse files Browse the repository at this point in the history
* update api

* update

* remove unused

* remove `one` api

* fix unused

* fmt

* add saturating accrue

* remove `Weight::new()`

* use some macros

* div makes no sense

* Update weight_v2.rs

* missed some

* more patch

* fixes

* more fixes

* more fix

* more fix

* Update frame/support/src/weights/weight_v2.rs

* not needed

* fix weight file
  • Loading branch information
shawntabrizi authored Sep 1, 2022
1 parent 6bd6b31 commit ed12e60
Show file tree
Hide file tree
Showing 80 changed files with 965 additions and 960 deletions.
4 changes: 2 additions & 2 deletions .maintain/frame-weight-template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
Weight::from_ref_time({{underscore benchmark.base_weight}} as RefTimeWeight)
{{#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 RefTimeWeight).saturating_mul({{cw.name}} as RefTimeWeight))
{{/each}}
{{#if (ne benchmark.base_reads "0")}}
.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}} as RefTimeWeight))
Expand Down Expand Up @@ -102,7 +102,7 @@ impl WeightInfo for () {
Weight::from_ref_time({{underscore benchmark.base_weight}} as RefTimeWeight)
{{#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 RefTimeWeight).saturating_mul({{cw.name}} as RefTimeWeight))
{{/each}}
{{#if (ne benchmark.base_reads "0")}}
.saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}} as RefTimeWeight))
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 @@ -239,7 +239,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 @@ -257,7 +257,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 @@ -419,20 +419,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

0 comments on commit ed12e60

Please sign in to comment.