From 4b9fc6460e6c931ff01a6a52d2373b549ce65af7 Mon Sep 17 00:00:00 2001 From: Falco Hirschenberger Date: Wed, 6 Oct 2021 12:15:19 +0200 Subject: [PATCH] Add call-decoding weight to benchmarks (#3866) * Add add call-decoding weight to benchmarks fixes #3864 * Change order as suggested by @thiolliere * More reordering as @KiChjang suggested * cargo run --quiet --release --features=runtime-benchmarks -- benchmark --chain=kusama-dev --steps=50 --repeat=20 --pallet=runtime_common::claims --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/kusama/src/weights/runtime_common_claims.rs * cargo run --quiet --release --features=runtime-benchmarks -- benchmark --chain=polkadot-dev --steps=50 --repeat=20 --pallet=runtime_common::claims --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --header=./file_header.txt --output=./runtime/polkadot/src/weights/runtime_common_claims.rs Co-authored-by: Parity Bot --- polkadot/runtime/common/src/claims.rs | 27 +++++++--- .../src/weights/runtime_common_claims.rs | 50 +++++++++++++++---- .../src/weights/runtime_common_claims.rs | 50 +++++++++++++++---- 3 files changed, 103 insertions(+), 24 deletions(-) diff --git a/polkadot/runtime/common/src/claims.rs b/polkadot/runtime/common/src/claims.rs index cd62e20485..66a9e12d71 100644 --- a/polkadot/runtime/common/src/claims.rs +++ b/polkadot/runtime/common/src/claims.rs @@ -1388,6 +1388,7 @@ mod benchmarking { use super::*; use crate::claims::Call; use frame_benchmarking::{account, benchmarks}; + use frame_support::dispatch::UnfilteredDispatchable; use frame_system::RawOrigin; use secp_utils::*; use sp_runtime::{traits::ValidateUnsigned, DispatchResult}; @@ -1443,10 +1444,15 @@ mod benchmarking { super::Pallet::::mint_claim(RawOrigin::Root.into(), eth_address, VALUE.into(), vesting, None)?; assert_eq!(Claims::::get(eth_address), Some(VALUE.into())); let source = sp_runtime::transaction_validity::TransactionSource::External; - let call = Call::::claim { dest: account.clone(), ethereum_signature: signature.clone() }; + let call_enc = Call::::claim { + dest: account.clone(), + ethereum_signature: signature.clone() + }.encode(); }: { + let call = as Decode>::decode(&mut &*call_enc) + .expect("call is encoded above, encoding must be correct"); super::Pallet::::validate_unsigned(source, &call).map_err(|e| -> &'static str { e.into() })?; - super::Pallet::::claim(RawOrigin::None.into(), account, signature)?; + call.dispatch_bypass_filter(RawOrigin::None.into())?; } verify { assert_eq!(Claims::::get(eth_address), None); @@ -1488,11 +1494,17 @@ mod benchmarking { let signature = sig::(&secret_key, &account.encode(), statement.to_text()); super::Pallet::::mint_claim(RawOrigin::Root.into(), eth_address, VALUE.into(), vesting, Some(statement))?; assert_eq!(Claims::::get(eth_address), Some(VALUE.into())); - let call = Call::::claim_attest { dest: account.clone(), ethereum_signature: signature.clone(), statement: StatementKind::Regular.to_text().to_vec() }; + let call_enc = Call::::claim_attest { + dest: account.clone(), + ethereum_signature: signature.clone(), + statement: StatementKind::Regular.to_text().to_vec() + }.encode(); let source = sp_runtime::transaction_validity::TransactionSource::External; }: { + let call = as Decode>::decode(&mut &*call_enc) + .expect("call is encoded above, encoding must be correct"); super::Pallet::::validate_unsigned(source, &call).map_err(|e| -> &'static str { e.into() })?; - super::Pallet::::claim_attest(RawOrigin::None.into(), account, signature, statement.to_text().to_vec())?; + call.dispatch_bypass_filter(RawOrigin::None.into())?; } verify { assert_eq!(Claims::::get(eth_address), None); @@ -1518,7 +1530,7 @@ mod benchmarking { Preclaims::::insert(&account, eth_address); assert_eq!(Claims::::get(eth_address), Some(VALUE.into())); - let call = super::Call::attest { statement: StatementKind::Regular.to_text().to_vec() }; + let call = super::Call::::attest { statement: StatementKind::Regular.to_text().to_vec() }; // We have to copy the validate statement here because of trait issues... :( let validate = |who: &T::AccountId, call: &super::Call| -> DispatchResult { if let Call::attest{ statement: attested_statement } = call { @@ -1529,9 +1541,12 @@ mod benchmarking { } Ok(()) }; + let call_enc = call.encode(); }: { + let call = as Decode>::decode(&mut &*call_enc) + .expect("call is encoded above, encoding must be correct"); validate(&account, &call)?; - super::Pallet::::attest(RawOrigin::Signed(account).into(), statement.to_text().to_vec())?; + call.dispatch_bypass_filter(RawOrigin::Signed(account).into())?; } verify { assert_eq!(Claims::::get(eth_address), None); diff --git a/polkadot/runtime/kusama/src/weights/runtime_common_claims.rs b/polkadot/runtime/kusama/src/weights/runtime_common_claims.rs index 9b2ea68299..26e37dcf27 100644 --- a/polkadot/runtime/kusama/src/weights/runtime_common_claims.rs +++ b/polkadot/runtime/kusama/src/weights/runtime_common_claims.rs @@ -1,4 +1,4 @@ -// Copyright 2017-2020 Parity Technologies (UK) Ltd. +// Copyright 2017-2021 Parity Technologies (UK) Ltd. // This file is part of Polkadot. // Polkadot is free software: you can redistribute it and/or modify @@ -15,8 +15,8 @@ // along with Polkadot. If not, see . //! Autogenerated weights for `runtime_common::claims` //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-07-01, 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-10-06, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kusama-dev"), DB CACHE: 128 // Executed Command: @@ -31,8 +31,10 @@ // --wasm-execution=compiled // --heap-pages=4096 // --header=./file_header.txt -// --output=./runtime/kusama/src/weights/ +// --output=./runtime/kusama/src/weights/runtime_common_claims.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] @@ -42,28 +44,58 @@ use sp_std::marker::PhantomData; /// Weight functions for `runtime_common::claims`. pub struct WeightInfo(PhantomData); impl runtime_common::claims::WeightInfo for WeightInfo { + // Storage: Claims Claims (r:1 w:1) + // Storage: Claims Signing (r:1 w:1) + // Storage: Claims Total (r:1 w:1) + // Storage: Claims Vesting (r:1 w:1) + // Storage: Vesting Vesting (r:1 w:1) + // Storage: System Account (r:1 w:0) + // Storage: Balances Locks (r:1 w:1) fn claim() -> Weight { - (438_457_000 as Weight) + (442_992_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } + // Storage: Claims Total (r:1 w:1) + // Storage: Claims Vesting (r:0 w:1) + // Storage: Claims Claims (r:0 w:1) + // Storage: Claims Signing (r:0 w:1) fn mint_claim() -> Weight { - (13_035_000 as Weight) + (12_098_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } + // Storage: Claims Claims (r:1 w:1) + // Storage: Claims Signing (r:1 w:1) + // Storage: Claims Total (r:1 w:1) + // Storage: Claims Vesting (r:1 w:1) + // Storage: Vesting Vesting (r:1 w:1) + // Storage: System Account (r:1 w:0) + // Storage: Balances Locks (r:1 w:1) fn claim_attest() -> Weight { - (439_894_000 as Weight) + (442_328_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } + // Storage: Claims Preclaims (r:1 w:1) + // Storage: Claims Signing (r:1 w:1) + // Storage: Claims Claims (r:1 w:1) + // Storage: Claims Total (r:1 w:1) + // Storage: Claims Vesting (r:1 w:1) + // Storage: Vesting Vesting (r:1 w:1) + // Storage: System Account (r:1 w:0) + // Storage: Balances Locks (r:1 w:1) fn attest() -> Weight { - (132_760_000 as Weight) + (126_506_000 as Weight) .saturating_add(T::DbWeight::get().reads(8 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } + // Storage: Claims Claims (r:1 w:2) + // Storage: Claims Vesting (r:1 w:2) + // Storage: Claims Signing (r:1 w:2) + // Storage: Claims Preclaims (r:1 w:1) fn move_claim() -> Weight { - (28_459_000 as Weight) + (26_618_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } diff --git a/polkadot/runtime/polkadot/src/weights/runtime_common_claims.rs b/polkadot/runtime/polkadot/src/weights/runtime_common_claims.rs index 1086ebdee5..7f352a3661 100644 --- a/polkadot/runtime/polkadot/src/weights/runtime_common_claims.rs +++ b/polkadot/runtime/polkadot/src/weights/runtime_common_claims.rs @@ -1,4 +1,4 @@ -// Copyright 2017-2020 Parity Technologies (UK) Ltd. +// Copyright 2017-2021 Parity Technologies (UK) Ltd. // This file is part of Polkadot. // Polkadot is free software: you can redistribute it and/or modify @@ -15,8 +15,8 @@ // along with Polkadot. If not, see . //! Autogenerated weights for `runtime_common::claims` //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-07-01, 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-10-06, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("polkadot-dev"), DB CACHE: 128 // Executed Command: @@ -31,8 +31,10 @@ // --wasm-execution=compiled // --heap-pages=4096 // --header=./file_header.txt -// --output=./runtime/polkadot/src/weights/ +// --output=./runtime/polkadot/src/weights/runtime_common_claims.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] @@ -42,28 +44,58 @@ use sp_std::marker::PhantomData; /// Weight functions for `runtime_common::claims`. pub struct WeightInfo(PhantomData); impl runtime_common::claims::WeightInfo for WeightInfo { + // Storage: Claims Claims (r:1 w:1) + // Storage: Claims Signing (r:1 w:1) + // Storage: Claims Total (r:1 w:1) + // Storage: Claims Vesting (r:1 w:1) + // Storage: Vesting Vesting (r:1 w:1) + // Storage: System Account (r:1 w:0) + // Storage: Balances Locks (r:1 w:1) fn claim() -> Weight { - (447_705_000 as Weight) + (440_159_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } + // Storage: Claims Total (r:1 w:1) + // Storage: Claims Vesting (r:0 w:1) + // Storage: Claims Claims (r:0 w:1) + // Storage: Claims Signing (r:0 w:1) fn mint_claim() -> Weight { - (11_995_000 as Weight) + (11_988_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(4 as Weight)) } + // Storage: Claims Claims (r:1 w:1) + // Storage: Claims Signing (r:1 w:1) + // Storage: Claims Total (r:1 w:1) + // Storage: Claims Vesting (r:1 w:1) + // Storage: Vesting Vesting (r:1 w:1) + // Storage: System Account (r:1 w:0) + // Storage: Balances Locks (r:1 w:1) fn claim_attest() -> Weight { - (439_703_000 as Weight) + (443_037_000 as Weight) .saturating_add(T::DbWeight::get().reads(7 as Weight)) .saturating_add(T::DbWeight::get().writes(6 as Weight)) } + // Storage: Claims Preclaims (r:1 w:1) + // Storage: Claims Signing (r:1 w:1) + // Storage: Claims Claims (r:1 w:1) + // Storage: Claims Total (r:1 w:1) + // Storage: Claims Vesting (r:1 w:1) + // Storage: Vesting Vesting (r:1 w:1) + // Storage: System Account (r:1 w:0) + // Storage: Balances Locks (r:1 w:1) fn attest() -> Weight { - (128_588_000 as Weight) + (125_350_000 as Weight) .saturating_add(T::DbWeight::get().reads(8 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) } + // Storage: Claims Claims (r:1 w:2) + // Storage: Claims Vesting (r:1 w:2) + // Storage: Claims Signing (r:1 w:2) + // Storage: Claims Preclaims (r:1 w:1) fn move_claim() -> Weight { - (26_297_000 as Weight) + (26_261_000 as Weight) .saturating_add(T::DbWeight::get().reads(4 as Weight)) .saturating_add(T::DbWeight::get().writes(7 as Weight)) }