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

WeightInfo for System, Timestamp, and Utility #6868

Merged
15 commits merged into from
Aug 17, 2020
Prev Previous commit
Next Next commit
utility weight
  • Loading branch information
shawntabrizi committed Aug 10, 2020
commit 792a216d06329454e59adfd8f56e2c01d3e7cc16
2 changes: 1 addition & 1 deletion bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl frame_system::Trait for Runtime {
impl pallet_utility::Trait for Runtime {
type Event = Event;
type Call = Call;
type WeightInfo = ();
type WeightInfo = weights::pallet_utility::WeightInfo;
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions bin/node/runtime/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ pub mod frame_system;
pub mod pallet_balances;
pub mod pallet_democracy;
pub mod pallet_timestamp;
pub mod pallet_utility;
35 changes: 35 additions & 0 deletions bin/node/runtime/src/weights/pallet_utility.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// This file is part of Substrate.

// Copyright (C) 2017-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};

pub struct WeightInfo;
impl pallet_utility::WeightInfo for WeightInfo {
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)
}
}
34 changes: 34 additions & 0 deletions frame/utility/src/default_weights.rs
Original file line number Diff line number Diff line change
@@ -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)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is fine to add this to all files as well for now to make it easier.


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)
}
}
19 changes: 6 additions & 13 deletions frame/utility/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)),
.sum::<Weight>()
shawntabrizi marked this conversation as resolved.
Show resolved Hide resolved
.saturating_add(T::WeightInfo::batch(calls.len() as u32)),
{
let all_operational = calls.iter()
.map(|call| call.get_dispatch_info().class)
Expand Down Expand Up @@ -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 {
Expand Down