contracts: Add automated weights for wasm instructions (#7361)

* pallet_contracts: Inline benchmark helper that is only used once

* Move all max_* Schedule items into a new struct

* Limit the number of globals a module can declare

* The current limits are too high for wasmi to even execute

* Limit the amount of parameters any wasm function is allowed to have

* Limit the size the BrTable's immediate value

* Add instruction benchmarks

* Add new benchmarks to the schedule and make use of it

* Add Benchmark Results generated by the bench bot

* Add proc macro that implements `Debug` for `Schedule`

* Add missing imports necessary for no_std build

* Make the WeightDebug macro available for no_std

In this case a dummy implementation is derived in order to not
blow up the code size akin to the RuntimeDebug macro.

* Rework instr_memory_grow benchmark to use only the maximum amount of pages allowed

* Add maximum amount of memory when benching (seal_)call/instantiate

* cargo run --release --features runtime-benchmarks --manifest-path bin/node/cli/Cargo.toml -- benchmark --chain dev --steps 50 --repeat 20 --extrinsic * --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output ./bin/node/runtime/src/weights --header ./HEADER --pallet pallet_contracts

* Added utility benchmark that allows pretty printing of the real schedule

* review: Add missing header to the proc-macro lib.rs

* review: Clarify why #[allow(dead_code)] attribute is there

* review: Fix pwasm-utils line

* review: Fixup rand usage

* review: Fix typo

* review: Imported -> Exported

* cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_contracts --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/contracts/src/weights.rs --template=./.maintain/frame-weight-template.hbs

* contracts: Adapt to new weight structure

* contracts: Fixup runtime WeightInfo

* contracts: Remove unneeded fullpath of WeightInfo type

* Apply suggestions from code review

Co-authored-by: Andrew Jones <ascjones@gmail.com>

* Fix typo in schedule.rs

Co-authored-by: Andrew Jones <ascjones@gmail.com>

* Fix docs in schedule.rs

* Apply suggestions from code review

Co-authored-by: Nikolay Volf <nikvolf@gmail.com>

* Don't publish proc-macro crate until 3.0.0 is ready

* Optimize imports for less repetition

* Break overlong line

Co-authored-by: Parity Benchmarking Bot <admin@parity.io>
Co-authored-by: Andrew Jones <ascjones@gmail.com>
Co-authored-by: Nikolay Volf <nikvolf@gmail.com>
This commit is contained in:
Alexander Theißen
2020-11-09 15:32:14 +01:00
committed by GitHub
parent 9704c204e6
commit 51c67fe881
17 changed files with 3152 additions and 843 deletions
+1 -4
View File
@@ -87,9 +87,6 @@ pub mod constants;
use constants::{time::*, currency::*};
use sp_runtime::generic::Era;
/// Weights for pallets used in the runtime.
mod weights;
// Make the WASM binary available.
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
@@ -697,7 +694,7 @@ impl pallet_contracts::Trait for Runtime {
type MaxDepth = pallet_contracts::DefaultMaxDepth;
type MaxValueSize = pallet_contracts::DefaultMaxValueSize;
type WeightPrice = pallet_transaction_payment::Module<Self>;
type WeightInfo = weights::pallet_contracts::WeightInfo<Self>;
type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
}
impl pallet_sudo::Trait for Runtime {
@@ -1,18 +0,0 @@
// Copyright (C) 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.
//! A list of the different weight modules for our runtime.
pub mod pallet_contracts;
@@ -1,294 +0,0 @@
// This file is part of Substrate.
// Copyright (C) 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.
//! Weights for pallet_contracts
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0
//! DATE: 2020-10-06, STEPS: [50], REPEAT: 20, LOW RANGE: [], HIGH RANGE: []
#![allow(unused_parens)]
#![allow(unused_imports)]
use frame_support::{traits::Get, weights::Weight};
use sp_std::marker::PhantomData;
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Trait> pallet_contracts::WeightInfo for WeightInfo<T> {
fn update_schedule() -> Weight {
(33_207_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
fn put_code(n: u32, ) -> Weight {
(0 as Weight)
.saturating_add((144_833_000 as Weight).saturating_mul(n as Weight))
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
fn instantiate(n: u32, ) -> Weight {
(223_974_000 as Weight)
.saturating_add((1_007_000 as Weight).saturating_mul(n as Weight))
.saturating_add(T::DbWeight::get().reads(6 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
fn call() -> Weight {
(210_638_000 as Weight)
.saturating_add(T::DbWeight::get().reads(5 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
fn claim_surcharge() -> Weight {
(508_079_000 as Weight)
.saturating_add(T::DbWeight::get().reads(3 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
fn seal_caller(r: u32, ) -> Weight {
(143_336_000 as Weight)
.saturating_add((397_788_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
}
fn seal_address(r: u32, ) -> Weight {
(147_296_000 as Weight)
.saturating_add((396_962_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
}
fn seal_gas_left(r: u32, ) -> Weight {
(141_677_000 as Weight)
.saturating_add((393_308_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
}
fn seal_balance(r: u32, ) -> Weight {
(157_556_000 as Weight)
.saturating_add((879_861_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(5 as Weight))
}
fn seal_value_transferred(r: u32, ) -> Weight {
(148_867_000 as Weight)
.saturating_add((391_678_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
}
fn seal_minimum_balance(r: u32, ) -> Weight {
(147_252_000 as Weight)
.saturating_add((393_977_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
}
fn seal_tombstone_deposit(r: u32, ) -> Weight {
(144_208_000 as Weight)
.saturating_add((394_625_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
}
fn seal_rent_allowance(r: u32, ) -> Weight {
(135_320_000 as Weight)
.saturating_add((925_541_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
}
fn seal_block_number(r: u32, ) -> Weight {
(145_849_000 as Weight)
.saturating_add((390_065_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
}
fn seal_now(r: u32, ) -> Weight {
(146_363_000 as Weight)
.saturating_add((391_772_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
}
fn seal_weight_to_fee(r: u32, ) -> Weight {
(129_872_000 as Weight)
.saturating_add((670_744_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(5 as Weight))
}
fn seal_gas(r: u32, ) -> Weight {
(130_985_000 as Weight)
.saturating_add((198_427_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
}
fn seal_input(r: u32, ) -> Weight {
(138_647_000 as Weight)
.saturating_add((8_363_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
}
fn seal_input_per_kb(n: u32, ) -> Weight {
(149_418_000 as Weight)
.saturating_add((272_000 as Weight).saturating_mul(n as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
}
fn seal_return(r: u32, ) -> Weight {
(129_116_000 as Weight)
.saturating_add((5_745_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
}
fn seal_return_per_kb(n: u32, ) -> Weight {
(139_601_000 as Weight)
.saturating_add((680_000 as Weight).saturating_mul(n as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
}
fn seal_terminate(r: u32, ) -> Weight {
(138_548_000 as Weight)
.saturating_add((355_473_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(r as Weight)))
.saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(r as Weight)))
}
fn seal_restore_to(r: u32, ) -> Weight {
(239_880_000 as Weight)
.saturating_add((138_305_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(5 as Weight))
.saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(r as Weight)))
.saturating_add(T::DbWeight::get().writes((4 as Weight).saturating_mul(r as Weight)))
}
fn seal_restore_to_per_delta(d: u32, ) -> Weight {
(40_572_000 as Weight)
.saturating_add((3_748_632_000 as Weight).saturating_mul(d as Weight))
.saturating_add(T::DbWeight::get().reads(7 as Weight))
.saturating_add(T::DbWeight::get().reads((100 as Weight).saturating_mul(d as Weight)))
.saturating_add(T::DbWeight::get().writes(5 as Weight))
.saturating_add(T::DbWeight::get().writes((100 as Weight).saturating_mul(d as Weight)))
}
fn seal_random(r: u32, ) -> Weight {
(148_156_000 as Weight)
.saturating_add((1_036_452_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(5 as Weight))
}
fn seal_deposit_event(r: u32, ) -> Weight {
(176_039_000 as Weight)
.saturating_add((1_497_705_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
}
fn seal_deposit_event_per_topic_and_kb(t: u32, n: u32, ) -> Weight {
(1_923_547_000 as Weight)
.saturating_add((783_354_000 as Weight).saturating_mul(t as Weight))
.saturating_add((240_600_000 as Weight).saturating_mul(n as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().reads((100 as Weight).saturating_mul(t as Weight)))
.saturating_add(T::DbWeight::get().writes((100 as Weight).saturating_mul(t as Weight)))
}
fn seal_set_rent_allowance(r: u32, ) -> Weight {
(151_095_000 as Weight)
.saturating_add((1_104_696_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
fn seal_set_storage(r: u32, ) -> Weight {
(0 as Weight)
.saturating_add((14_975_467_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().reads((100 as Weight).saturating_mul(r as Weight)))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
.saturating_add(T::DbWeight::get().writes((100 as Weight).saturating_mul(r as Weight)))
}
fn seal_set_storage_per_kb(n: u32, ) -> Weight {
(2_465_724_000 as Weight)
.saturating_add((203_125_000 as Weight).saturating_mul(n as Weight))
.saturating_add(T::DbWeight::get().reads(5 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
fn seal_clear_storage(r: u32, ) -> Weight {
(0 as Weight)
.saturating_add((5_254_595_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().reads((100 as Weight).saturating_mul(r as Weight)))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
.saturating_add(T::DbWeight::get().writes((100 as Weight).saturating_mul(r as Weight)))
}
fn seal_get_storage(r: u32, ) -> Weight {
(60_303_000 as Weight)
.saturating_add((1_135_486_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().reads((100 as Weight).saturating_mul(r as Weight)))
}
fn seal_get_storage_per_kb(n: u32, ) -> Weight {
(931_900_000 as Weight)
.saturating_add((144_572_000 as Weight).saturating_mul(n as Weight))
.saturating_add(T::DbWeight::get().reads(5 as Weight))
}
fn seal_transfer(r: u32, ) -> Weight {
(50_722_000 as Weight)
.saturating_add((6_701_164_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(5 as Weight))
.saturating_add(T::DbWeight::get().reads((100 as Weight).saturating_mul(r as Weight)))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
.saturating_add(T::DbWeight::get().writes((100 as Weight).saturating_mul(r as Weight)))
}
fn seal_call(r: u32, ) -> Weight {
(0 as Weight)
.saturating_add((10_589_747_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(5 as Weight))
.saturating_add(T::DbWeight::get().reads((100 as Weight).saturating_mul(r as Weight)))
}
fn seal_call_per_transfer_input_output_kb(t: u32, i: u32, o: u32, ) -> Weight {
(11_223_388_000 as Weight)
.saturating_add((4_965_182_000 as Weight).saturating_mul(t as Weight))
.saturating_add((50_603_000 as Weight).saturating_mul(i as Weight))
.saturating_add((72_972_000 as Weight).saturating_mul(o as Weight))
.saturating_add(T::DbWeight::get().reads(105 as Weight))
.saturating_add(T::DbWeight::get().reads((101 as Weight).saturating_mul(t as Weight)))
.saturating_add(T::DbWeight::get().writes((101 as Weight).saturating_mul(t as Weight)))
}
fn seal_instantiate(r: u32, ) -> Weight {
(0 as Weight)
.saturating_add((22_933_938_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(6 as Weight))
.saturating_add(T::DbWeight::get().reads((300 as Weight).saturating_mul(r as Weight)))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
.saturating_add(T::DbWeight::get().writes((200 as Weight).saturating_mul(r as Weight)))
}
fn seal_instantiate_per_input_output_kb(i: u32, o: u32, ) -> Weight {
(20_986_307_000 as Weight)
.saturating_add((152_611_000 as Weight).saturating_mul(i as Weight))
.saturating_add((73_457_000 as Weight).saturating_mul(o as Weight))
.saturating_add(T::DbWeight::get().reads(207 as Weight))
.saturating_add(T::DbWeight::get().writes(202 as Weight))
}
fn seal_hash_sha2_256(r: u32, ) -> Weight {
(145_988_000 as Weight)
.saturating_add((343_540_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
}
fn seal_hash_sha2_256_per_kb(n: u32, ) -> Weight {
(719_758_000 as Weight)
.saturating_add((420_306_000 as Weight).saturating_mul(n as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
}
fn seal_hash_keccak_256(r: u32, ) -> Weight {
(116_261_000 as Weight)
.saturating_add((360_601_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
}
fn seal_hash_keccak_256_per_kb(n: u32, ) -> Weight {
(583_726_000 as Weight)
.saturating_add((333_091_000 as Weight).saturating_mul(n as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
}
fn seal_hash_blake2_256(r: u32, ) -> Weight {
(144_609_000 as Weight)
.saturating_add((332_388_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
}
fn seal_hash_blake2_256_per_kb(n: u32, ) -> Weight {
(612_987_000 as Weight)
.saturating_add((150_030_000 as Weight).saturating_mul(n as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
}
fn seal_hash_blake2_128(r: u32, ) -> Weight {
(142_085_000 as Weight)
.saturating_add((329_426_000 as Weight).saturating_mul(r as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
}
fn seal_hash_blake2_128_per_kb(n: u32, ) -> Weight {
(632_517_000 as Weight)
.saturating_add((149_974_000 as Weight).saturating_mul(n as Weight))
.saturating_add(T::DbWeight::get().reads(4 as Weight))
}
}