From ad5f551549943a04a7ed9583fa33739b01f05174 Mon Sep 17 00:00:00 2001 From: Ermal Kaleci Date: Thu, 16 Sep 2021 01:35:31 +0200 Subject: [PATCH] Authority benchmark new methods (#1411) * add benchmarks for new methods * update orml commit * update orml * sweep_dust benchmark * add weight method * add missing authority weights * fix weights * update bench * cargo run --release --color=never --bin=acala --features=runtime-benchmarks --features=with-mandala-runtime -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=orml_authority --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --template=./templates/runtime-weight-template.hbs --output=./runtime/mandala/src/weights/ * update bench * cargo run --release --color=never --bin=acala --features=runtime-benchmarks --features=with-mandala-runtime -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=orml_authority --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --template=./templates/runtime-weight-template.hbs --output=./runtime/mandala/src/weights/ * cargo run --release --color=never --bin=acala --features=runtime-benchmarks --features=with-karura-runtime -- benchmark --chain=karura-dev --steps=50 --repeat=20 --pallet=orml_authority --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --template=./templates/runtime-weight-template.hbs --output=./runtime/karura/src/weights/ * fix Co-authored-by: Acala Benchmarking Bot Co-authored-by: Bryan Chen --- runtime/karura/src/weights/orml_authority.rs | 16 +++---- runtime/mandala/src/benchmarking/authority.rs | 45 +++++++++++++++++-- runtime/mandala/src/weights/orml_authority.rs | 18 ++++---- 3 files changed, 58 insertions(+), 21 deletions(-) diff --git a/runtime/karura/src/weights/orml_authority.rs b/runtime/karura/src/weights/orml_authority.rs index 85dddbb46..3237170a4 100644 --- a/runtime/karura/src/weights/orml_authority.rs +++ b/runtime/karura/src/weights/orml_authority.rs @@ -19,7 +19,7 @@ //! Autogenerated weights for orml_authority //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2021-08-31, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2021-09-15, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("karura-dev"), DB CACHE: 128 // Executed Command: @@ -28,7 +28,7 @@ // --chain=karura-dev // --steps=50 // --repeat=20 -// --pallet=* +// --pallet=orml_authority // --extrinsic=* // --execution=wasm // --wasm-execution=compiled @@ -48,30 +48,30 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl orml_authority::WeightInfo for WeightInfo { fn dispatch_as() -> Weight { - (21_199_000 as Weight) + (20_621_000 as Weight) } fn schedule_dispatch_without_delay() -> Weight { - (55_898_000 as Weight) + (54_460_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn schedule_dispatch_with_delay() -> Weight { - (59_215_000 as Weight) + (57_119_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn fast_track_scheduled_dispatch() -> Weight { - (74_569_000 as Weight) + (73_397_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn delay_scheduled_dispatch() -> Weight { - (74_564_000 as Weight) + (72_988_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn cancel_scheduled_dispatch() -> Weight { - (51_614_000 as Weight) + (50_467_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) } diff --git a/runtime/mandala/src/benchmarking/authority.rs b/runtime/mandala/src/benchmarking/authority.rs index 547394ea3..749c9b4de 100644 --- a/runtime/mandala/src/benchmarking/authority.rs +++ b/runtime/mandala/src/benchmarking/authority.rs @@ -16,14 +16,17 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::{Authority, AuthoritysOriginId, BlockNumber, Call, Origin, Runtime, System}; +use crate::{AccountId, Authority, AuthoritysOriginId, BlockNumber, Call, Origin, Runtime, System}; -use sp_runtime::Perbill; +use sp_runtime::{traits::Hash, Perbill}; use sp_std::prelude::*; -use frame_support::traits::{schedule::DispatchTime, OriginTrait}; +use frame_support::{ + traits::{schedule::DispatchTime, OriginTrait}, + weights::GetDispatchInfo, +}; use frame_system::RawOrigin; -use orml_benchmarking::runtime_benchmarks; +use orml_benchmarking::{runtime_benchmarks, whitelisted_caller}; runtime_benchmarks! { { Runtime, orml_authority } @@ -135,6 +138,40 @@ runtime_benchmarks! { let pallets_origin = schedule_origin.caller().clone(); }: _(RawOrigin::Root, Box::new(pallets_origin), 0) + + // authorize a call that can be triggered later + authorize_call { + let caller: AccountId = whitelisted_caller(); + let call = Call::System(frame_system::Call::fill_block(Perbill::from_percent(1))); + let hash = ::Hashing::hash_of(&call); + System::set_block_number(1u32); + }: _(RawOrigin::Root, Box::new(call.clone()), Some(caller.clone())) + verify { + assert_eq!(Authority::saved_calls(&hash), Some((call, Some(caller)))); + } + + remove_authorized_call { + let caller: AccountId = whitelisted_caller(); + let call = Call::System(frame_system::Call::fill_block(Perbill::from_percent(1))); + let hash = ::Hashing::hash_of(&call); + System::set_block_number(1u32); + Authority::authorize_call(Origin::root(), Box::new(call.clone()), Some(caller.clone()))?; + }: _(RawOrigin::Signed(caller), hash) + verify { + assert_eq!(Authority::saved_calls(&hash), None); + } + + trigger_call { + let caller: AccountId = whitelisted_caller(); + let call = Call::System(frame_system::Call::fill_block(Perbill::from_percent(1))); + let hash = ::Hashing::hash_of(&call); + let call_weight_bound = call.get_dispatch_info().weight; + System::set_block_number(1u32); + Authority::authorize_call(Origin::root(), Box::new(call.clone()), Some(caller.clone()))?; + }: _(RawOrigin::Signed(caller), hash, call_weight_bound) + verify { + assert_eq!(Authority::saved_calls(&hash), None); + } } #[cfg(test)] diff --git a/runtime/mandala/src/weights/orml_authority.rs b/runtime/mandala/src/weights/orml_authority.rs index d5b803de9..82eb7a31c 100644 --- a/runtime/mandala/src/weights/orml_authority.rs +++ b/runtime/mandala/src/weights/orml_authority.rs @@ -18,8 +18,8 @@ //! Autogenerated weights for orml_authority //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-07-19, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2021-09-15, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: @@ -28,7 +28,7 @@ // --chain=dev // --steps=50 // --repeat=20 -// --pallet=* +// --pallet=orml_authority // --extrinsic=* // --execution=wasm // --wasm-execution=compiled @@ -48,30 +48,30 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl orml_authority::WeightInfo for WeightInfo { fn dispatch_as() -> Weight { - (29_595_000 as Weight) + (20_989_000 as Weight) } fn schedule_dispatch_without_delay() -> Weight { - (71_028_000 as Weight) + (55_153_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn schedule_dispatch_with_delay() -> Weight { - (75_115_000 as Weight) + (57_754_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn fast_track_scheduled_dispatch() -> Weight { - (111_745_000 as Weight) + (74_949_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn delay_scheduled_dispatch() -> Weight { - (111_217_000 as Weight) + (74_280_000 as Weight) .saturating_add(T::DbWeight::get().reads(3 as Weight)) .saturating_add(T::DbWeight::get().writes(3 as Weight)) } fn cancel_scheduled_dispatch() -> Weight { - (80_254_000 as Weight) + (51_250_000 as Weight) .saturating_add(T::DbWeight::get().reads(2 as Weight)) .saturating_add(T::DbWeight::get().writes(2 as Weight)) }