mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 22:01:04 +00:00
WeightInfo for System, Timestamp, and Utility (#6868)
* initial updates to system * fix compile * Update writer.rs * update weights * finish system weights * timestamp weights * utility weight * Fix overflow in weight calculations * add back weight notes * Update for whitelisted benchmarks * add trait bounds * Revert "add trait bounds" This reverts commit 12b08b7189aa3969f96fa19b211a370860fdb240. * Update weights for unaccounted for read
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) 2019-2020 Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc5
|
||||
|
||||
#![allow(unused_parens)]
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight};
|
||||
|
||||
impl crate::WeightInfo for () {
|
||||
fn batch(c: u32, ) -> Weight {
|
||||
(16461000 as Weight)
|
||||
.saturating_add((1982000 as Weight).saturating_mul(c as Weight))
|
||||
}
|
||||
// WARNING! Some components were not used: ["u"]
|
||||
fn as_derivative() -> Weight {
|
||||
(4086000 as Weight)
|
||||
}
|
||||
}
|
||||
@@ -69,15 +69,11 @@ use sp_runtime::{DispatchError, DispatchResult, traits::Dispatchable};
|
||||
|
||||
mod tests;
|
||||
mod benchmarking;
|
||||
mod default_weights;
|
||||
|
||||
pub trait WeightInfo {
|
||||
fn batch(c: u32, ) -> Weight;
|
||||
fn as_derivative(u: u32, ) -> Weight;
|
||||
}
|
||||
|
||||
impl WeightInfo for () {
|
||||
fn batch(_c: u32, ) -> Weight { 1_000_000_000 }
|
||||
fn as_derivative(_u: u32, ) -> Weight { 1_000_000_000 }
|
||||
fn as_derivative() -> Weight;
|
||||
}
|
||||
|
||||
/// Configuration trait.
|
||||
@@ -145,7 +141,8 @@ decl_module! {
|
||||
#[weight = (
|
||||
calls.iter()
|
||||
.map(|call| call.get_dispatch_info().weight)
|
||||
.fold(15_000_000, |a: Weight, n| a.saturating_add(n).saturating_add(1_000_000)),
|
||||
.fold(0, |total: Weight, weight: Weight| total.saturating_add(weight))
|
||||
.saturating_add(T::WeightInfo::batch(calls.len() as u32)),
|
||||
{
|
||||
let all_operational = calls.iter()
|
||||
.map(|call| call.get_dispatch_info().class)
|
||||
@@ -186,13 +183,9 @@ decl_module! {
|
||||
/// NOTE: Prior to version *12, this was called `as_limited_sub`.
|
||||
///
|
||||
/// The dispatch origin for this call must be _Signed_.
|
||||
///
|
||||
/// # <weight>
|
||||
/// - Base weight: 2.861 µs
|
||||
/// - Plus the weight of the `call`
|
||||
/// # </weight>
|
||||
#[weight = (
|
||||
call.get_dispatch_info().weight.saturating_add(3_000_000),
|
||||
T::WeightInfo::as_derivative()
|
||||
.saturating_add(call.get_dispatch_info().weight),
|
||||
call.get_dispatch_info().class,
|
||||
)]
|
||||
fn as_derivative(origin, index: u16, call: Box<<T as Trait>::Call>) -> DispatchResult {
|
||||
|
||||
@@ -54,7 +54,7 @@ impl_outer_dispatch! {
|
||||
pub struct Test;
|
||||
parameter_types! {
|
||||
pub const BlockHashCount: u64 = 250;
|
||||
pub const MaximumBlockWeight: Weight = 1024;
|
||||
pub const MaximumBlockWeight: Weight = Weight::max_value();
|
||||
pub const MaximumBlockLength: u32 = 2 * 1024;
|
||||
pub const AvailableBlockRatio: Perbill = Perbill::one();
|
||||
}
|
||||
@@ -121,6 +121,7 @@ type System = frame_system::Module<Test>;
|
||||
type Balances = pallet_balances::Module<Test>;
|
||||
type Utility = Module<Test>;
|
||||
|
||||
use frame_system::Call as SystemCall;
|
||||
use pallet_balances::Call as BalancesCall;
|
||||
use pallet_balances::Error as BalancesError;
|
||||
|
||||
@@ -236,3 +237,20 @@ fn batch_early_exit_works() {
|
||||
assert_eq!(Balances::free_balance(2), 15);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn batch_weight_calculation_doesnt_overflow() {
|
||||
new_test_ext().execute_with(|| {
|
||||
let big_call = Call::System(SystemCall::fill_block(Perbill::from_percent(50)));
|
||||
assert_eq!(big_call.get_dispatch_info().weight, Weight::max_value() / 2);
|
||||
|
||||
// 3 * 50% saturates to 100%
|
||||
let batch_call = Call::Utility(crate::Call::batch(vec![
|
||||
big_call.clone(),
|
||||
big_call.clone(),
|
||||
big_call.clone(),
|
||||
]));
|
||||
|
||||
assert_eq!(batch_call.get_dispatch_info().weight, Weight::max_value());
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user