From a9a35f87174cce4b62dea745c07ef80a5d8923d0 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Fri, 18 Sep 2020 03:35:09 +0200 Subject: [PATCH 01/13] as multi threshold 1 --- frame/multisig/src/default_weights.rs | 93 +++++++++++++++++++++++++++ frame/multisig/src/lib.rs | 32 +++------ 2 files changed, 101 insertions(+), 24 deletions(-) create mode 100644 frame/multisig/src/default_weights.rs diff --git a/frame/multisig/src/default_weights.rs b/frame/multisig/src/default_weights.rs new file mode 100644 index 0000000000000..3972e0d5938f6 --- /dev/null +++ b/frame/multisig/src/default_weights.rs @@ -0,0 +1,93 @@ +// 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-rc6 + +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; + +impl crate::WeightInfo for () { + fn as_multi_threshold_1(z: u32, ) -> Weight { + (15_121_000 as Weight) + .saturating_add((1_000 as Weight).saturating_mul(z as Weight)) + } + fn as_multi_create(s: u32, z: u32, ) -> Weight { + (74_501_000 as Weight) + .saturating_add((91_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((1_000 as Weight).saturating_mul(z as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn as_multi_create_store(s: u32, z: u32, ) -> Weight { + (84_462_000 as Weight) + .saturating_add((90_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((3_000 as Weight).saturating_mul(z as Weight)) + .saturating_add(DbWeight::get().reads(4 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } + fn as_multi_approve(s: u32, z: u32, ) -> Weight { + (46_228_000 as Weight) + .saturating_add((131_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((1_000 as Weight).saturating_mul(z as Weight)) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn as_multi_complete(s: u32, z: u32, ) -> Weight { + (91_531_000 as Weight) + .saturating_add((272_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((5_000 as Weight).saturating_mul(z as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } + // WARNING! Some components were not used: ["z"] + fn approve_as_multi_create(s: u32, ) -> Weight { + (80_316_000 as Weight) + .saturating_add((130_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + // WARNING! Some components were not used: ["z"] + fn approve_as_multi_approve(s: u32, ) -> Weight { + (44_096_000 as Weight) + .saturating_add((162_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn approve_as_multi_complete(s: u32, z: u32, ) -> Weight { + (95_746_000 as Weight) + .saturating_add((266_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((7_000 as Weight).saturating_mul(z as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } + fn cancel_as_multi(s: u32, z: u32, ) -> Weight { + (88_526_000 as Weight) + .saturating_add((120_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((3_000 as Weight).saturating_mul(z as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } + fn cancel_as_multi_store(s: u32, z: u32, ) -> Weight { + (88_534_000 as Weight) + .saturating_add((117_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((3_000 as Weight).saturating_mul(z as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } +} diff --git a/frame/multisig/src/lib.rs b/frame/multisig/src/lib.rs index 06f91f8d0fd7b..ae9c254846f76 100644 --- a/frame/multisig/src/lib.rs +++ b/frame/multisig/src/lib.rs @@ -212,18 +212,6 @@ decl_event! { mod weight_of { use super::*; - /// - Base Weight: 33.72 + 0.002 * Z µs - /// - DB Weight: None - /// - Plus Call Weight - pub fn as_multi_threshold_1( - call_len: usize, - call_weight: Weight, - ) -> Weight { - (34 * WEIGHT_PER_MICROS) - .saturating_add((2 * WEIGHT_PER_NANOS).saturating_mul(call_len as Weight)) - .saturating_add(call_weight) - } - /// - Base Weight: /// - Create: 38.82 + 0.121 * S + .001 * Z µs /// - Create w/ Store: 54.22 + 0.120 * S + .003 * Z µs @@ -291,9 +279,8 @@ decl_module! { /// - Plus Call Weight /// # #[weight = ( - weight_of::as_multi_threshold_1::( - call.using_encoded(|c| c.len()), - call.get_dispatch_info().weight + T::WeightInfo::as_multi_threshold_1(call.using_encoded(|c| c.len() as u32)) + .saturating_add(call.get_dispatch_info().weight ), call.get_dispatch_info().class, )] @@ -314,17 +301,14 @@ decl_module! { let result = call.dispatch(RawOrigin::Signed(id).into()); result.map(|post_dispatch_info| post_dispatch_info.actual_weight - .map(|actual_weight| weight_of::as_multi_threshold_1::( - call_len, - actual_weight, - )) - .into() + .map(|actual_weight| + T::WeightInfo::as_multi_threshold_1(call_len as u32) + .saturating_add(actual_weight) + ).into() ).map_err(|err| match err.post_info.actual_weight { Some(actual_weight) => { - let weight_used = weight_of::as_multi_threshold_1::( - call_len, - actual_weight, - ); + let weight_used = T::WeightInfo::as_multi_threshold_1(call_len as u32) + .saturating_add(actual_weight); let post_info = Some(weight_used).into(); let error = err.error.into(); DispatchErrorWithPostInfo { post_info, error } From 0af48ca54b380ab7263470536fe5d113a90a63b1 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 21 Sep 2020 02:01:26 +0200 Subject: [PATCH 02/13] add `as_multi_approve_store` benchmark --- frame/multisig/src/benchmarking.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/frame/multisig/src/benchmarking.rs b/frame/multisig/src/benchmarking.rs index 8113d179cd157..c39a96e470ef5 100644 --- a/frame/multisig/src/benchmarking.rs +++ b/frame/multisig/src/benchmarking.rs @@ -76,6 +76,7 @@ benchmarks! { }: as_multi(RawOrigin::Signed(caller), s as u16, signatories, None, call, false, 0) verify { assert!(Multisigs::::contains_key(multi_account_id, call_hash)); + assert!(!Calls::::contains_key(call_hash)); } as_multi_create_store { @@ -108,6 +109,7 @@ benchmarks! { let timepoint = Multisig::::timepoint(); // Create the multi, storing for worst case Multisig::::as_multi(RawOrigin::Signed(caller).into(), s as u16, signatories, None, call.clone(), true, 0)?; + assert!(Calls::::contains_key(call_hash)); let caller2 = signatories2.remove(0); }: as_multi(RawOrigin::Signed(caller2), s as u16, signatories2, Some(timepoint), call, false, 0) verify { @@ -115,6 +117,29 @@ benchmarks! { assert_eq!(multisig.approvals.len(), 2); } + as_multi_approve_store { + // Signatories, need at least 3 people (so we don't complete the multisig) + let s in 3 .. T::MaxSignatories::get() as u32; + // Transaction Length + let z in 0 .. 10_000; + let (mut signatories, call) = setup_multi::(s, z)?; + let call_hash = blake2_256(&call); + let multi_account_id = Multisig::::multi_account_id(&signatories, s.try_into().unwrap()); + let mut signatories2 = signatories.clone(); + let caller = signatories.pop().ok_or("signatories should have len 2 or more")?; + // before the call, get the timepoint + let timepoint = Multisig::::timepoint(); + // Create the multi, not storing + Multisig::::as_multi(RawOrigin::Signed(caller).into(), s as u16, signatories, None, call.clone(), false, 0)?; + assert!(!Calls::::contains_key(call_hash)); + let caller2 = signatories2.remove(0); + }: as_multi(RawOrigin::Signed(caller2), s as u16, signatories2, Some(timepoint), call, true, 0) + verify { + let multisig = Multisigs::::get(multi_account_id, call_hash).ok_or("multisig not created")?; + assert_eq!(multisig.approvals.len(), 2); + assert!(Calls::::contains_key(call_hash)); + } + as_multi_complete { // Signatories, need at least 2 people let s in 2 .. T::MaxSignatories::get() as u32; @@ -278,6 +303,7 @@ mod tests { assert_ok!(test_benchmark_as_multi_create::()); assert_ok!(test_benchmark_as_multi_create_store::()); assert_ok!(test_benchmark_as_multi_approve::()); + assert_ok!(test_benchmark_as_multi_approve_store::()); assert_ok!(test_benchmark_as_multi_complete::()); assert_ok!(test_benchmark_approve_as_multi_create::()); assert_ok!(test_benchmark_approve_as_multi_approve::()); From 6d3230dc419aff00b77d18c2ca0f1140cebfa6e5 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 21 Sep 2020 03:15:36 +0200 Subject: [PATCH 03/13] finish update --- frame/multisig/src/benchmarking.rs | 39 ++----- frame/multisig/src/default_weights.rs | 54 +++++---- frame/multisig/src/lib.rs | 154 +++++++++++--------------- 3 files changed, 100 insertions(+), 147 deletions(-) diff --git a/frame/multisig/src/benchmarking.rs b/frame/multisig/src/benchmarking.rs index c39a96e470ef5..70ddecff277c6 100644 --- a/frame/multisig/src/benchmarking.rs +++ b/frame/multisig/src/benchmarking.rs @@ -171,8 +171,8 @@ benchmarks! { approve_as_multi_create { // Signatories, need at least 2 people let s in 2 .. T::MaxSignatories::get() as u32; - // Transaction Length - let z in 0 .. 10_000; + // Transaction Length, not a component + let z = 10_000; let (mut signatories, call) = setup_multi::(s, z)?; let multi_account_id = Multisig::::multi_account_id(&signatories, s.try_into().unwrap()); let caller = signatories.pop().ok_or("signatories should have len 2 or more")?; @@ -186,8 +186,8 @@ benchmarks! { approve_as_multi_approve { // Signatories, need at least 2 people let s in 2 .. T::MaxSignatories::get() as u32; - // Transaction Length - let z in 0 .. 10_000; + // Transaction Length not a component + let z = 10_000; let (mut signatories, call) = setup_multi::(s, z)?; let mut signatories2 = signatories.clone(); let multi_account_id = Multisig::::multi_account_id(&signatories, s.try_into().unwrap()); @@ -215,8 +215,8 @@ benchmarks! { approve_as_multi_complete { // Signatories, need at least 2 people let s in 2 .. T::MaxSignatories::get() as u32; - // Transaction Length - let z in 0 .. 10_000; + // Transaction Length, not a component + let z = 10_000; let (mut signatories, call) = setup_multi::(s, z)?; let multi_account_id = Multisig::::multi_account_id(&signatories, s.try_into().unwrap()); let mut signatories2 = signatories.clone(); @@ -251,8 +251,8 @@ benchmarks! { cancel_as_multi { // Signatories, need at least 2 people let s in 2 .. T::MaxSignatories::get() as u32; - // Transaction Length - let z in 0 .. 10_000; + // Transaction Length, not a component + let z = 10_000; let (mut signatories, call) = setup_multi::(s, z)?; let multi_account_id = Multisig::::multi_account_id(&signatories, s.try_into().unwrap()); let caller = signatories.pop().ok_or("signatories should have len 2 or more")?; @@ -262,30 +262,10 @@ benchmarks! { let o = RawOrigin::Signed(caller.clone()).into(); Multisig::::as_multi(o, s as u16, signatories.clone(), None, call.clone(), true, 0)?; assert!(Multisigs::::contains_key(&multi_account_id, call_hash)); + assert!(Calls::::contains_key(call_hash)); }: _(RawOrigin::Signed(caller), s as u16, signatories, timepoint, call_hash) verify { assert!(!Multisigs::::contains_key(multi_account_id, call_hash)); - } - - cancel_as_multi_store { - // Signatories, need at least 2 people - let s in 2 .. T::MaxSignatories::get() as u32; - // Transaction Length - let z in 0 .. 10_000; - let (mut signatories, call) = setup_multi::(s, z)?; - let multi_account_id = Multisig::::multi_account_id(&signatories, s.try_into().unwrap()); - let caller = signatories.pop().ok_or("signatories should have len 2 or more")?; - T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); - let call_hash = blake2_256(&call); - let timepoint = Multisig::::timepoint(); - // Create the multi - let o = RawOrigin::Signed(caller.clone()).into(); - Multisig::::as_multi(o, s as u16, signatories.clone(), None, call.clone(), true, 0)?; - assert!(Multisigs::::contains_key(&multi_account_id, call_hash)); - assert!(Calls::::contains_key(call_hash)); - }: cancel_as_multi(RawOrigin::Signed(caller), s as u16, signatories, timepoint, call_hash) - verify { - assert!(!Multisigs::::contains_key(&multi_account_id, call_hash)); assert!(!Calls::::contains_key(call_hash)); } } @@ -309,7 +289,6 @@ mod tests { assert_ok!(test_benchmark_approve_as_multi_approve::()); assert_ok!(test_benchmark_approve_as_multi_complete::()); assert_ok!(test_benchmark_cancel_as_multi::()); - assert_ok!(test_benchmark_cancel_as_multi_store::()); }); } } diff --git a/frame/multisig/src/default_weights.rs b/frame/multisig/src/default_weights.rs index 3972e0d5938f6..0b8d3f23e35d0 100644 --- a/frame/multisig/src/default_weights.rs +++ b/frame/multisig/src/default_weights.rs @@ -24,69 +24,67 @@ use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; impl crate::WeightInfo for () { fn as_multi_threshold_1(z: u32, ) -> Weight { - (15_121_000 as Weight) + (16_663_000 as Weight) .saturating_add((1_000 as Weight).saturating_mul(z as Weight)) } fn as_multi_create(s: u32, z: u32, ) -> Weight { - (74_501_000 as Weight) - .saturating_add((91_000 as Weight).saturating_mul(s as Weight)) + (80_524_000 as Weight) + .saturating_add((95_000 as Weight).saturating_mul(s as Weight)) .saturating_add((1_000 as Weight).saturating_mul(z as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } fn as_multi_create_store(s: u32, z: u32, ) -> Weight { - (84_462_000 as Weight) - .saturating_add((90_000 as Weight).saturating_mul(s as Weight)) + (91_837_000 as Weight) + .saturating_add((87_000 as Weight).saturating_mul(s as Weight)) .saturating_add((3_000 as Weight).saturating_mul(z as Weight)) .saturating_add(DbWeight::get().reads(4 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } fn as_multi_approve(s: u32, z: u32, ) -> Weight { - (46_228_000 as Weight) - .saturating_add((131_000 as Weight).saturating_mul(s as Weight)) + (49_536_000 as Weight) + .saturating_add((158_000 as Weight).saturating_mul(s as Weight)) .saturating_add((1_000 as Weight).saturating_mul(z as Weight)) .saturating_add(DbWeight::get().reads(1 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } + fn as_multi_approve_store(s: u32, z: u32, ) -> Weight { + (89_275_000 as Weight) + .saturating_add((172_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((3_000 as Weight).saturating_mul(z as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } fn as_multi_complete(s: u32, z: u32, ) -> Weight { - (91_531_000 as Weight) - .saturating_add((272_000 as Weight).saturating_mul(s as Weight)) + (102_536_000 as Weight) + .saturating_add((285_000 as Weight).saturating_mul(s as Weight)) .saturating_add((5_000 as Weight).saturating_mul(z as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } // WARNING! Some components were not used: ["z"] fn approve_as_multi_create(s: u32, ) -> Weight { - (80_316_000 as Weight) - .saturating_add((130_000 as Weight).saturating_mul(s as Weight)) + (79_991_000 as Weight) + .saturating_add((136_000 as Weight).saturating_mul(s as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } // WARNING! Some components were not used: ["z"] fn approve_as_multi_approve(s: u32, ) -> Weight { - (44_096_000 as Weight) - .saturating_add((162_000 as Weight).saturating_mul(s as Weight)) + (48_513_000 as Weight) + .saturating_add((161_000 as Weight).saturating_mul(s as Weight)) .saturating_add(DbWeight::get().reads(1 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } - fn approve_as_multi_complete(s: u32, z: u32, ) -> Weight { - (95_746_000 as Weight) - .saturating_add((266_000 as Weight).saturating_mul(s as Weight)) - .saturating_add((7_000 as Weight).saturating_mul(z as Weight)) + fn approve_as_multi_complete(s: u32, ) -> Weight { + (106_934_000 as Weight) + .saturating_add((284_000 as Weight).saturating_mul(s as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } - fn cancel_as_multi(s: u32, z: u32, ) -> Weight { - (88_526_000 as Weight) - .saturating_add((120_000 as Weight).saturating_mul(s as Weight)) - .saturating_add((3_000 as Weight).saturating_mul(z as Weight)) - .saturating_add(DbWeight::get().reads(3 as Weight)) - .saturating_add(DbWeight::get().writes(3 as Weight)) - } - fn cancel_as_multi_store(s: u32, z: u32, ) -> Weight { - (88_534_000 as Weight) - .saturating_add((117_000 as Weight).saturating_mul(s as Weight)) - .saturating_add((3_000 as Weight).saturating_mul(z as Weight)) + fn cancel_as_multi(s: u32, ) -> Weight { + (99_028_000 as Weight) + .saturating_add((129_000 as Weight).saturating_mul(s as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } diff --git a/frame/multisig/src/lib.rs b/frame/multisig/src/lib.rs index ae9c254846f76..d62bba6545d2c 100644 --- a/frame/multisig/src/lib.rs +++ b/frame/multisig/src/lib.rs @@ -51,7 +51,7 @@ use codec::{Encode, Decode}; use sp_io::hashing::blake2_256; use frame_support::{decl_module, decl_event, decl_error, decl_storage, Parameter, ensure, RuntimeDebug}; use frame_support::{traits::{Get, ReservableCurrency, Currency}, - weights::{Weight, GetDispatchInfo, constants::{WEIGHT_PER_NANOS, WEIGHT_PER_MICROS}}, + weights::{Weight, GetDispatchInfo}, dispatch::{DispatchResultWithPostInfo, DispatchErrorWithPostInfo, PostDispatchInfo}, }; use frame_system::{self as system, ensure_signed, RawOrigin}; @@ -59,6 +59,7 @@ use sp_runtime::{DispatchError, DispatchResult, traits::{Dispatchable, Zero}}; mod tests; mod benchmarking; +mod default_weights; type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; /// Just a bunch of bytes, but they should decode to a valid `Call`. @@ -69,25 +70,12 @@ pub trait WeightInfo { fn as_multi_create(s: u32, z: u32, ) -> Weight; fn as_multi_create_store(s: u32, z: u32, ) -> Weight; fn as_multi_approve(s: u32, z: u32, ) -> Weight; + fn as_multi_approve_store(s: u32, z: u32, ) -> Weight; fn as_multi_complete(s: u32, z: u32, ) -> Weight; - fn approve_as_multi_create(s: u32, z: u32, ) -> Weight; - fn approve_as_multi_approve(s: u32, z: u32, ) -> Weight; - fn approve_as_multi_complete(s: u32, z: u32, ) -> Weight; - fn cancel_as_multi(s: u32, z: u32, ) -> Weight; - fn cancel_as_multi_store(s: u32, z: u32, ) -> Weight; -} - -impl WeightInfo for () { - fn as_multi_threshold_1(_z: u32, ) -> Weight { 1_000_000_000 } - fn as_multi_create(_s: u32, _z: u32, ) -> Weight { 1_000_000_000 } - fn as_multi_create_store(_s: u32, _z: u32, ) -> Weight { 1_000_000_000 } - fn as_multi_approve(_s: u32, _z: u32, ) -> Weight { 1_000_000_000 } - fn as_multi_complete(_s: u32, _z: u32, ) -> Weight { 1_000_000_000 } - fn approve_as_multi_create(_s: u32, _z: u32, ) -> Weight { 1_000_000_000 } - fn approve_as_multi_approve(_s: u32, _z: u32, ) -> Weight { 1_000_000_000 } - fn approve_as_multi_complete(_s: u32, _z: u32, ) -> Weight { 1_000_000_000 } - fn cancel_as_multi(_s: u32, _z: u32, ) -> Weight { 1_000_000_000 } - fn cancel_as_multi_store(_s: u32, _z: u32, ) -> Weight { 1_000_000_000 } + fn approve_as_multi_create(s: u32, ) -> Weight; + fn approve_as_multi_approve(s: u32, ) -> Weight; + fn approve_as_multi_complete(s: u32, ) -> Weight; + fn cancel_as_multi(s: u32, ) -> Weight; } /// Configuration trait. @@ -209,36 +197,6 @@ decl_event! { } } -mod weight_of { - use super::*; - - /// - Base Weight: - /// - Create: 38.82 + 0.121 * S + .001 * Z µs - /// - Create w/ Store: 54.22 + 0.120 * S + .003 * Z µs - /// - Approve: 29.86 + 0.143 * S + .001 * Z µs - /// - Complete: 39.55 + 0.267 * S + .002 * Z µs - /// - DB Weight: - /// - Reads: Multisig Storage, [Caller Account], Calls, Depositor Account - /// - Writes: Multisig Storage, [Caller Account], Calls, Depositor Account - /// - Plus Call Weight - pub fn as_multi( - sig_len: usize, - call_len: usize, - call_weight: Weight, - calls_write: bool, - refunded: bool, - ) -> Weight { - call_weight - .saturating_add(55 * WEIGHT_PER_MICROS) - .saturating_add((250 * WEIGHT_PER_NANOS).saturating_mul(sig_len as Weight)) - .saturating_add((3 * WEIGHT_PER_NANOS).saturating_mul(call_len as Weight)) - .saturating_add(T::DbWeight::get().reads_writes(1, 1)) // Multisig read/write - .saturating_add(T::DbWeight::get().reads(1)) // Calls read - .saturating_add(T::DbWeight::get().writes(calls_write.into())) // Calls write - .saturating_add(T::DbWeight::get().reads_writes(refunded.into(), refunded.into())) // Deposit refunded - } -} - enum CallOrHash { Call(OpaqueCall, bool), Hash([u8; 32]), @@ -368,13 +326,23 @@ decl_module! { /// - Writes: Multisig Storage, [Caller Account], Calls (if `store_call`) /// - Plus Call Weight /// # - #[weight = weight_of::as_multi::( - other_signatories.len(), - call.len(), - *max_weight, - true, // assume worst case: calls write - true, // assume worst case: refunded - )] + // #[weight = weight_of::as_multi::( + // other_signatories.len(), + // call.len(), + // *max_weight, + // true, // assume worst case: calls write + // true, // assume worst case: refunded + // )] + #[weight = { + let s = other_signatories.len() as u32; + let z = call.len() as u32; + + T::WeightInfo::as_multi_create(s, z) + .max(T::WeightInfo::as_multi_create_store(s, z)) + .max(T::WeightInfo::as_multi_approve(s, z)) + .max(T::WeightInfo::as_multi_complete(s, z)) + .saturating_add(*max_weight) + }] fn as_multi(origin, threshold: u16, other_signatories: Vec, @@ -426,13 +394,14 @@ decl_module! { /// - Read: Multisig Storage, [Caller Account] /// - Write: Multisig Storage, [Caller Account] /// # - #[weight = weight_of::as_multi::( - other_signatories.len(), - 0, // call_len is zero in this case - *max_weight, - true, // assume worst case: calls write - true, // assume worst case: refunded - )] + #[weight = { + let s = other_signatories.len() as u32; + + T::WeightInfo::approve_as_multi_create(s) + .max(T::WeightInfo::approve_as_multi_approve(s)) + .max(T::WeightInfo::approve_as_multi_complete(s)) + .saturating_add(*max_weight) + }] fn approve_as_multi(origin, threshold: u16, other_signatories: Vec, @@ -471,10 +440,7 @@ decl_module! { /// - Read: Multisig Storage, [Caller Account], Refund Account, Calls /// - Write: Multisig Storage, [Caller Account], Refund Account, Calls /// # - #[weight = T::DbWeight::get().reads_writes(3, 3) - .saturating_add(36 * WEIGHT_PER_MICROS) - .saturating_add((other_signatories.len() as Weight).saturating_mul(100 * WEIGHT_PER_NANOS)) - ] + #[weight = T::WeightInfo::cancel_as_multi(other_signatories.len() as u32)] fn cancel_as_multi(origin, threshold: u16, other_signatories: Vec, @@ -574,13 +540,12 @@ impl Module { Self::deposit_event(RawEvent::MultisigExecuted( who, timepoint, id, call_hash, result.map(|_| ()).map_err(|e| e.error) )); - Ok(get_result_weight(result).map(|actual_weight| weight_of::as_multi::( - other_signatories_len, - call_len, - actual_weight, - true, // Call is removed - true, // User is refunded - )).into()) + Ok(get_result_weight(result).map(|actual_weight| + T::WeightInfo::as_multi_complete( + other_signatories_len as u32, + call_len as u32 + ).saturating_add(actual_weight) + ).into()) } else { // We cannot dispatch the call now; either it isn't available, or it is, but we // don't have threshold approvals even with our signature. @@ -604,14 +569,19 @@ impl Module { ensure!(stored, Error::::AlreadyApproved); } + let final_weight = if stored { + T::WeightInfo::as_multi_approve_store( + other_signatories_len as u32, + call_len as u32, + ) + } else { + T::WeightInfo::as_multi_approve( + other_signatories_len as u32, + call_len as u32, + ) + }; // Call is not made, so the actual weight does not include call - Ok(Some(weight_of::as_multi::( - other_signatories_len, - call_len, - 0, - stored, // Call stored? - false, // No refund - )).into()) + Ok(Some(final_weight).into()) } } else { // Not yet started; there should be no timepoint given. @@ -636,14 +606,20 @@ impl Module { approvals: vec![who.clone()], }); Self::deposit_event(RawEvent::NewMultisig(who, id, call_hash)); - // Call is not made, so we can return that weight - return Ok(Some(weight_of::as_multi::( - other_signatories_len, - call_len, - 0, - stored, // Call stored? - false, // No refund - )).into()) + + let final_weight = if stored { + T::WeightInfo::as_multi_create_store( + other_signatories_len as u32, + call_len as u32, + ) + } else { + T::WeightInfo::as_multi_create( + other_signatories_len as u32, + call_len as u32, + ) + }; + // Call is not made, so the actual weight does not include call + Ok(Some(final_weight).into()) } } From fb243f57056609f6edbddaff60cf01eec527e9f1 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 21 Sep 2020 03:21:35 +0200 Subject: [PATCH 04/13] final weights --- frame/multisig/src/default_weights.rs | 40 +++++++++++++-------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/frame/multisig/src/default_weights.rs b/frame/multisig/src/default_weights.rs index 0b8d3f23e35d0..70b68a84066b9 100644 --- a/frame/multisig/src/default_weights.rs +++ b/frame/multisig/src/default_weights.rs @@ -24,67 +24,65 @@ use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; impl crate::WeightInfo for () { fn as_multi_threshold_1(z: u32, ) -> Weight { - (16_663_000 as Weight) + (14_749_000 as Weight) .saturating_add((1_000 as Weight).saturating_mul(z as Weight)) } fn as_multi_create(s: u32, z: u32, ) -> Weight { - (80_524_000 as Weight) - .saturating_add((95_000 as Weight).saturating_mul(s as Weight)) + (74_556_000 as Weight) + .saturating_add((135_000 as Weight).saturating_mul(s as Weight)) .saturating_add((1_000 as Weight).saturating_mul(z as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } fn as_multi_create_store(s: u32, z: u32, ) -> Weight { - (91_837_000 as Weight) - .saturating_add((87_000 as Weight).saturating_mul(s as Weight)) + (84_401_000 as Weight) + .saturating_add((132_000 as Weight).saturating_mul(s as Weight)) .saturating_add((3_000 as Weight).saturating_mul(z as Weight)) .saturating_add(DbWeight::get().reads(4 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } fn as_multi_approve(s: u32, z: u32, ) -> Weight { - (49_536_000 as Weight) - .saturating_add((158_000 as Weight).saturating_mul(s as Weight)) + (45_680_000 as Weight) + .saturating_add((137_000 as Weight).saturating_mul(s as Weight)) .saturating_add((1_000 as Weight).saturating_mul(z as Weight)) .saturating_add(DbWeight::get().reads(1 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn as_multi_approve_store(s: u32, z: u32, ) -> Weight { - (89_275_000 as Weight) + (80_718_000 as Weight) .saturating_add((172_000 as Weight).saturating_mul(s as Weight)) .saturating_add((3_000 as Weight).saturating_mul(z as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } fn as_multi_complete(s: u32, z: u32, ) -> Weight { - (102_536_000 as Weight) - .saturating_add((285_000 as Weight).saturating_mul(s as Weight)) - .saturating_add((5_000 as Weight).saturating_mul(z as Weight)) + (91_869_000 as Weight) + .saturating_add((274_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((6_000 as Weight).saturating_mul(z as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } - // WARNING! Some components were not used: ["z"] fn approve_as_multi_create(s: u32, ) -> Weight { - (79_991_000 as Weight) - .saturating_add((136_000 as Weight).saturating_mul(s as Weight)) + (74_413_000 as Weight) + .saturating_add((143_000 as Weight).saturating_mul(s as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(2 as Weight)) } - // WARNING! Some components were not used: ["z"] fn approve_as_multi_approve(s: u32, ) -> Weight { - (48_513_000 as Weight) - .saturating_add((161_000 as Weight).saturating_mul(s as Weight)) + (44_624_000 as Weight) + .saturating_add((165_000 as Weight).saturating_mul(s as Weight)) .saturating_add(DbWeight::get().reads(1 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn approve_as_multi_complete(s: u32, ) -> Weight { - (106_934_000 as Weight) - .saturating_add((284_000 as Weight).saturating_mul(s as Weight)) + (169_412_000 as Weight) + .saturating_add((283_000 as Weight).saturating_mul(s as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } fn cancel_as_multi(s: u32, ) -> Weight { - (99_028_000 as Weight) - .saturating_add((129_000 as Weight).saturating_mul(s as Weight)) + (120_213_000 as Weight) + .saturating_add((122_000 as Weight).saturating_mul(s as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } From e6fa0e9b0a37a64836b47d38d59a1a817ea71f98 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 21 Sep 2020 03:25:11 +0200 Subject: [PATCH 05/13] integrate into runtime --- bin/node/runtime/src/lib.rs | 2 +- bin/node/runtime/src/weights/mod.rs | 1 + .../runtime/src/weights/pallet_multisig.rs | 90 +++++++++++++++++++ 3 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 bin/node/runtime/src/weights/pallet_multisig.rs diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 0de78464bddec..c16511fbdac5b 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -207,7 +207,7 @@ impl pallet_multisig::Trait for Runtime { type DepositBase = DepositBase; type DepositFactor = DepositFactor; type MaxSignatories = MaxSignatories; - type WeightInfo = (); + type WeightInfo = weights::pallet_multisig::WeightInfo; } parameter_types! { diff --git a/bin/node/runtime/src/weights/mod.rs b/bin/node/runtime/src/weights/mod.rs index 668b9462a7d6a..7a8b17dde0983 100644 --- a/bin/node/runtime/src/weights/mod.rs +++ b/bin/node/runtime/src/weights/mod.rs @@ -23,6 +23,7 @@ pub mod pallet_democracy; pub mod pallet_identity; pub mod pallet_indices; pub mod pallet_im_online; +pub mod pallet_multisig; pub mod pallet_proxy; pub mod pallet_scheduler; pub mod pallet_staking; diff --git a/bin/node/runtime/src/weights/pallet_multisig.rs b/bin/node/runtime/src/weights/pallet_multisig.rs new file mode 100644 index 0000000000000..316b715163478 --- /dev/null +++ b/bin/node/runtime/src/weights/pallet_multisig.rs @@ -0,0 +1,90 @@ +// 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-rc6 + +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; + +pub struct WeightInfo; +impl pallet_multisig::WeightInfo for WeightInfo { + fn as_multi_threshold_1(z: u32, ) -> Weight { + (14_749_000 as Weight) + .saturating_add((1_000 as Weight).saturating_mul(z as Weight)) + } + fn as_multi_create(s: u32, z: u32, ) -> Weight { + (74_556_000 as Weight) + .saturating_add((135_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((1_000 as Weight).saturating_mul(z as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn as_multi_create_store(s: u32, z: u32, ) -> Weight { + (84_401_000 as Weight) + .saturating_add((132_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((3_000 as Weight).saturating_mul(z as Weight)) + .saturating_add(DbWeight::get().reads(4 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } + fn as_multi_approve(s: u32, z: u32, ) -> Weight { + (45_680_000 as Weight) + .saturating_add((137_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((1_000 as Weight).saturating_mul(z as Weight)) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn as_multi_approve_store(s: u32, z: u32, ) -> Weight { + (80_718_000 as Weight) + .saturating_add((172_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((3_000 as Weight).saturating_mul(z as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } + fn as_multi_complete(s: u32, z: u32, ) -> Weight { + (91_869_000 as Weight) + .saturating_add((274_000 as Weight).saturating_mul(s as Weight)) + .saturating_add((6_000 as Weight).saturating_mul(z as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } + fn approve_as_multi_create(s: u32, ) -> Weight { + (74_413_000 as Weight) + .saturating_add((143_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) + } + fn approve_as_multi_approve(s: u32, ) -> Weight { + (44_624_000 as Weight) + .saturating_add((165_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(DbWeight::get().reads(1 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) + } + fn approve_as_multi_complete(s: u32, ) -> Weight { + (169_412_000 as Weight) + .saturating_add((283_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } + fn cancel_as_multi(s: u32, ) -> Weight { + (120_213_000 as Weight) + .saturating_add((122_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(3 as Weight)) + } +} From caf23bbccbb1ba9756e2905c788215d9c6ffdb0d Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 21 Sep 2020 03:45:49 +0200 Subject: [PATCH 06/13] whitelist accounts --- frame/multisig/src/benchmarking.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/frame/multisig/src/benchmarking.rs b/frame/multisig/src/benchmarking.rs index 70ddecff277c6..5003f6d0dc62e 100644 --- a/frame/multisig/src/benchmarking.rs +++ b/frame/multisig/src/benchmarking.rs @@ -59,6 +59,9 @@ benchmarks! { let call_hash = call.using_encoded(blake2_256); let multi_account_id = Multisig::::multi_account_id(&signatories, 1); let caller = signatories.pop().ok_or("signatories should have len 2 or more")?; + // Whitelist caller account from further DB operations. + let caller_key = frame_system::Account::::hashed_key_for(&caller); + frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into()); }: _(RawOrigin::Signed(caller.clone()), signatories, Box::new(call)) verify { // If the benchmark resolves, then the call was dispatched successfully. @@ -73,6 +76,9 @@ benchmarks! { let call_hash = blake2_256(&call); let multi_account_id = Multisig::::multi_account_id(&signatories, s.try_into().unwrap()); let caller = signatories.pop().ok_or("signatories should have len 2 or more")?; + // Whitelist caller account from further DB operations. + let caller_key = frame_system::Account::::hashed_key_for(&caller); + frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into()); }: as_multi(RawOrigin::Signed(caller), s as u16, signatories, None, call, false, 0) verify { assert!(Multisigs::::contains_key(multi_account_id, call_hash)); @@ -89,6 +95,9 @@ benchmarks! { let multi_account_id = Multisig::::multi_account_id(&signatories, s.try_into().unwrap()); let caller = signatories.pop().ok_or("signatories should have len 2 or more")?; T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); + // Whitelist caller account from further DB operations. + let caller_key = frame_system::Account::::hashed_key_for(&caller); + frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into()); }: as_multi(RawOrigin::Signed(caller), s as u16, signatories, None, call, true, 0) verify { assert!(Multisigs::::contains_key(multi_account_id, call_hash)); @@ -111,6 +120,9 @@ benchmarks! { Multisig::::as_multi(RawOrigin::Signed(caller).into(), s as u16, signatories, None, call.clone(), true, 0)?; assert!(Calls::::contains_key(call_hash)); let caller2 = signatories2.remove(0); + // Whitelist caller account from further DB operations. + let caller_key = frame_system::Account::::hashed_key_for(&caller2); + frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into()); }: as_multi(RawOrigin::Signed(caller2), s as u16, signatories2, Some(timepoint), call, false, 0) verify { let multisig = Multisigs::::get(multi_account_id, call_hash).ok_or("multisig not created")?; @@ -133,6 +145,9 @@ benchmarks! { Multisig::::as_multi(RawOrigin::Signed(caller).into(), s as u16, signatories, None, call.clone(), false, 0)?; assert!(!Calls::::contains_key(call_hash)); let caller2 = signatories2.remove(0); + // Whitelist caller account from further DB operations. + let caller_key = frame_system::Account::::hashed_key_for(&caller2); + frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into()); }: as_multi(RawOrigin::Signed(caller2), s as u16, signatories2, Some(timepoint), call, true, 0) verify { let multisig = Multisigs::::get(multi_account_id, call_hash).ok_or("multisig not created")?; @@ -163,6 +178,9 @@ benchmarks! { } let caller2 = signatories2.remove(0); assert!(Multisigs::::contains_key(&multi_account_id, call_hash)); + // Whitelist caller account from further DB operations. + let caller_key = frame_system::Account::::hashed_key_for(&caller2); + frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into()); }: as_multi(RawOrigin::Signed(caller2), s as u16, signatories2, Some(timepoint), call, false, Weight::max_value()) verify { assert!(!Multisigs::::contains_key(&multi_account_id, call_hash)); @@ -177,6 +195,9 @@ benchmarks! { let multi_account_id = Multisig::::multi_account_id(&signatories, s.try_into().unwrap()); let caller = signatories.pop().ok_or("signatories should have len 2 or more")?; let call_hash = blake2_256(&call); + // Whitelist caller account from further DB operations. + let caller_key = frame_system::Account::::hashed_key_for(&caller); + frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into()); // Create the multi }: approve_as_multi(RawOrigin::Signed(caller), s as u16, signatories, None, call_hash, 0) verify { @@ -206,6 +227,9 @@ benchmarks! { 0 )?; let caller2 = signatories2.remove(0); + // Whitelist caller account from further DB operations. + let caller_key = frame_system::Account::::hashed_key_for(&caller2); + frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into()); }: approve_as_multi(RawOrigin::Signed(caller2), s as u16, signatories2, Some(timepoint), call_hash, 0) verify { let multisig = Multisigs::::get(multi_account_id, call_hash).ok_or("multisig not created")?; @@ -236,6 +260,9 @@ benchmarks! { } let caller2 = signatories2.remove(0); assert!(Multisigs::::contains_key(&multi_account_id, call_hash)); + // Whitelist caller account from further DB operations. + let caller_key = frame_system::Account::::hashed_key_for(&caller2); + frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into()); }: approve_as_multi( RawOrigin::Signed(caller2), s as u16, @@ -263,6 +290,9 @@ benchmarks! { Multisig::::as_multi(o, s as u16, signatories.clone(), None, call.clone(), true, 0)?; assert!(Multisigs::::contains_key(&multi_account_id, call_hash)); assert!(Calls::::contains_key(call_hash)); + // Whitelist caller account from further DB operations. + let caller_key = frame_system::Account::::hashed_key_for(&caller); + frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into()); }: _(RawOrigin::Signed(caller), s as u16, signatories, timepoint, call_hash) verify { assert!(!Multisigs::::contains_key(multi_account_id, call_hash)); From 94e7042c02c7f44262ce4b11af2cc3c7841a1126 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 21 Sep 2020 03:52:46 +0200 Subject: [PATCH 07/13] whitelisted caller weights --- .../runtime/src/weights/pallet_multisig.rs | 58 +++++++++---------- frame/multisig/src/default_weights.rs | 58 +++++++++---------- 2 files changed, 58 insertions(+), 58 deletions(-) diff --git a/bin/node/runtime/src/weights/pallet_multisig.rs b/bin/node/runtime/src/weights/pallet_multisig.rs index 316b715163478..1de1d9a67f441 100644 --- a/bin/node/runtime/src/weights/pallet_multisig.rs +++ b/bin/node/runtime/src/weights/pallet_multisig.rs @@ -25,66 +25,66 @@ use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; pub struct WeightInfo; impl pallet_multisig::WeightInfo for WeightInfo { fn as_multi_threshold_1(z: u32, ) -> Weight { - (14_749_000 as Weight) + (17_161_000 as Weight) .saturating_add((1_000 as Weight).saturating_mul(z as Weight)) } fn as_multi_create(s: u32, z: u32, ) -> Weight { - (74_556_000 as Weight) - .saturating_add((135_000 as Weight).saturating_mul(s as Weight)) + (79_857_000 as Weight) + .saturating_add((131_000 as Weight).saturating_mul(s as Weight)) .saturating_add((1_000 as Weight).saturating_mul(z as Weight)) - .saturating_add(DbWeight::get().reads(3 as Weight)) - .saturating_add(DbWeight::get().writes(2 as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) } fn as_multi_create_store(s: u32, z: u32, ) -> Weight { - (84_401_000 as Weight) - .saturating_add((132_000 as Weight).saturating_mul(s as Weight)) + (90_218_000 as Weight) + .saturating_add((129_000 as Weight).saturating_mul(s as Weight)) .saturating_add((3_000 as Weight).saturating_mul(z as Weight)) - .saturating_add(DbWeight::get().reads(4 as Weight)) - .saturating_add(DbWeight::get().writes(3 as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) } fn as_multi_approve(s: u32, z: u32, ) -> Weight { - (45_680_000 as Weight) - .saturating_add((137_000 as Weight).saturating_mul(s as Weight)) + (48_402_000 as Weight) + .saturating_add((132_000 as Weight).saturating_mul(s as Weight)) .saturating_add((1_000 as Weight).saturating_mul(z as Weight)) .saturating_add(DbWeight::get().reads(1 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn as_multi_approve_store(s: u32, z: u32, ) -> Weight { - (80_718_000 as Weight) - .saturating_add((172_000 as Weight).saturating_mul(s as Weight)) + (88_390_000 as Weight) + .saturating_add((120_000 as Weight).saturating_mul(s as Weight)) .saturating_add((3_000 as Weight).saturating_mul(z as Weight)) - .saturating_add(DbWeight::get().reads(3 as Weight)) - .saturating_add(DbWeight::get().writes(3 as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) } fn as_multi_complete(s: u32, z: u32, ) -> Weight { - (91_869_000 as Weight) - .saturating_add((274_000 as Weight).saturating_mul(s as Weight)) + (98_960_000 as Weight) + .saturating_add((276_000 as Weight).saturating_mul(s as Weight)) .saturating_add((6_000 as Weight).saturating_mul(z as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } fn approve_as_multi_create(s: u32, ) -> Weight { - (74_413_000 as Weight) - .saturating_add((143_000 as Weight).saturating_mul(s as Weight)) - .saturating_add(DbWeight::get().reads(3 as Weight)) - .saturating_add(DbWeight::get().writes(2 as Weight)) + (80_185_000 as Weight) + .saturating_add((121_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) } fn approve_as_multi_approve(s: u32, ) -> Weight { - (44_624_000 as Weight) - .saturating_add((165_000 as Weight).saturating_mul(s as Weight)) + (48_386_000 as Weight) + .saturating_add((143_000 as Weight).saturating_mul(s as Weight)) .saturating_add(DbWeight::get().reads(1 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn approve_as_multi_complete(s: u32, ) -> Weight { - (169_412_000 as Weight) - .saturating_add((283_000 as Weight).saturating_mul(s as Weight)) + (177_181_000 as Weight) + .saturating_add((273_000 as Weight).saturating_mul(s as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } fn cancel_as_multi(s: u32, ) -> Weight { - (120_213_000 as Weight) - .saturating_add((122_000 as Weight).saturating_mul(s as Weight)) - .saturating_add(DbWeight::get().reads(3 as Weight)) - .saturating_add(DbWeight::get().writes(3 as Weight)) + (126_334_000 as Weight) + .saturating_add((124_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) } } diff --git a/frame/multisig/src/default_weights.rs b/frame/multisig/src/default_weights.rs index 70b68a84066b9..19d1528d9aaa6 100644 --- a/frame/multisig/src/default_weights.rs +++ b/frame/multisig/src/default_weights.rs @@ -24,66 +24,66 @@ use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight}; impl crate::WeightInfo for () { fn as_multi_threshold_1(z: u32, ) -> Weight { - (14_749_000 as Weight) + (17_161_000 as Weight) .saturating_add((1_000 as Weight).saturating_mul(z as Weight)) } fn as_multi_create(s: u32, z: u32, ) -> Weight { - (74_556_000 as Weight) - .saturating_add((135_000 as Weight).saturating_mul(s as Weight)) + (79_857_000 as Weight) + .saturating_add((131_000 as Weight).saturating_mul(s as Weight)) .saturating_add((1_000 as Weight).saturating_mul(z as Weight)) - .saturating_add(DbWeight::get().reads(3 as Weight)) - .saturating_add(DbWeight::get().writes(2 as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) } fn as_multi_create_store(s: u32, z: u32, ) -> Weight { - (84_401_000 as Weight) - .saturating_add((132_000 as Weight).saturating_mul(s as Weight)) + (90_218_000 as Weight) + .saturating_add((129_000 as Weight).saturating_mul(s as Weight)) .saturating_add((3_000 as Weight).saturating_mul(z as Weight)) - .saturating_add(DbWeight::get().reads(4 as Weight)) - .saturating_add(DbWeight::get().writes(3 as Weight)) + .saturating_add(DbWeight::get().reads(3 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) } fn as_multi_approve(s: u32, z: u32, ) -> Weight { - (45_680_000 as Weight) - .saturating_add((137_000 as Weight).saturating_mul(s as Weight)) + (48_402_000 as Weight) + .saturating_add((132_000 as Weight).saturating_mul(s as Weight)) .saturating_add((1_000 as Weight).saturating_mul(z as Weight)) .saturating_add(DbWeight::get().reads(1 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn as_multi_approve_store(s: u32, z: u32, ) -> Weight { - (80_718_000 as Weight) - .saturating_add((172_000 as Weight).saturating_mul(s as Weight)) + (88_390_000 as Weight) + .saturating_add((120_000 as Weight).saturating_mul(s as Weight)) .saturating_add((3_000 as Weight).saturating_mul(z as Weight)) - .saturating_add(DbWeight::get().reads(3 as Weight)) - .saturating_add(DbWeight::get().writes(3 as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) } fn as_multi_complete(s: u32, z: u32, ) -> Weight { - (91_869_000 as Weight) - .saturating_add((274_000 as Weight).saturating_mul(s as Weight)) + (98_960_000 as Weight) + .saturating_add((276_000 as Weight).saturating_mul(s as Weight)) .saturating_add((6_000 as Weight).saturating_mul(z as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } fn approve_as_multi_create(s: u32, ) -> Weight { - (74_413_000 as Weight) - .saturating_add((143_000 as Weight).saturating_mul(s as Weight)) - .saturating_add(DbWeight::get().reads(3 as Weight)) - .saturating_add(DbWeight::get().writes(2 as Weight)) + (80_185_000 as Weight) + .saturating_add((121_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(1 as Weight)) } fn approve_as_multi_approve(s: u32, ) -> Weight { - (44_624_000 as Weight) - .saturating_add((165_000 as Weight).saturating_mul(s as Weight)) + (48_386_000 as Weight) + .saturating_add((143_000 as Weight).saturating_mul(s as Weight)) .saturating_add(DbWeight::get().reads(1 as Weight)) .saturating_add(DbWeight::get().writes(1 as Weight)) } fn approve_as_multi_complete(s: u32, ) -> Weight { - (169_412_000 as Weight) - .saturating_add((283_000 as Weight).saturating_mul(s as Weight)) + (177_181_000 as Weight) + .saturating_add((273_000 as Weight).saturating_mul(s as Weight)) .saturating_add(DbWeight::get().reads(3 as Weight)) .saturating_add(DbWeight::get().writes(3 as Weight)) } fn cancel_as_multi(s: u32, ) -> Weight { - (120_213_000 as Weight) - .saturating_add((122_000 as Weight).saturating_mul(s as Weight)) - .saturating_add(DbWeight::get().reads(3 as Weight)) - .saturating_add(DbWeight::get().writes(3 as Weight)) + (126_334_000 as Weight) + .saturating_add((124_000 as Weight).saturating_mul(s as Weight)) + .saturating_add(DbWeight::get().reads(2 as Weight)) + .saturating_add(DbWeight::get().writes(2 as Weight)) } } From 8c666d1696ed389c1d5a6d9c165d5922a07963db Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 21 Sep 2020 04:09:42 +0200 Subject: [PATCH 08/13] clean up comments --- frame/multisig/src/lib.rs | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/frame/multisig/src/lib.rs b/frame/multisig/src/lib.rs index d62bba6545d2c..a284d08e9a2ab 100644 --- a/frame/multisig/src/lib.rs +++ b/frame/multisig/src/lib.rs @@ -232,7 +232,6 @@ decl_module! { /// # /// O(Z + C) where Z is the length of the call and C its execution weight. /// ------------------------------- - /// - Base Weight: 33.72 + 0.002 * Z µs /// - DB Weight: None /// - Plus Call Weight /// # @@ -316,23 +315,11 @@ decl_module! { /// deposit taken for its lifetime of /// `DepositBase + threshold * DepositFactor`. /// ------------------------------- - /// - Base Weight: - /// - Create: 41.89 + 0.118 * S + .002 * Z µs - /// - Create w/ Store: 53.57 + 0.119 * S + .003 * Z µs - /// - Approve: 31.39 + 0.136 * S + .002 * Z µs - /// - Complete: 39.94 + 0.26 * S + .002 * Z µs /// - DB Weight: /// - Reads: Multisig Storage, [Caller Account], Calls (if `store_call`) /// - Writes: Multisig Storage, [Caller Account], Calls (if `store_call`) /// - Plus Call Weight /// # - // #[weight = weight_of::as_multi::( - // other_signatories.len(), - // call.len(), - // *max_weight, - // true, // assume worst case: calls write - // true, // assume worst case: refunded - // )] #[weight = { let s = other_signatories.len() as u32; let z = call.len() as u32; @@ -387,9 +374,6 @@ decl_module! { /// deposit taken for its lifetime of /// `DepositBase + threshold * DepositFactor`. /// ---------------------------------- - /// - Base Weight: - /// - Create: 44.71 + 0.088 * S - /// - Approve: 31.48 + 0.116 * S /// - DB Weight: /// - Read: Multisig Storage, [Caller Account] /// - Write: Multisig Storage, [Caller Account] @@ -435,7 +419,6 @@ decl_module! { /// - I/O: 1 read `O(S)`, one remove. /// - Storage: removes one item. /// ---------------------------------- - /// - Base Weight: 36.07 + 0.124 * S /// - DB Weight: /// - Read: Multisig Storage, [Caller Account], Refund Account, Calls /// - Write: Multisig Storage, [Caller Account], Refund Account, Calls From 71dc96999a46f9e37b7e8b4b9f6c8fb17d64b358 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 21 Sep 2020 13:48:10 +0200 Subject: [PATCH 09/13] Get up to date `call_len` --- frame/multisig/src/lib.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/frame/multisig/src/lib.rs b/frame/multisig/src/lib.rs index a284d08e9a2ab..1ee1735848dfb 100644 --- a/frame/multisig/src/lib.rs +++ b/frame/multisig/src/lib.rs @@ -505,9 +505,9 @@ impl Module { if maybe_pos.is_some() { approvals += 1; } // We only bother fetching/decoding call if we know that we're ready to execute. - let maybe_approved_call = if approvals >= threshold { + let (maybe_approved_call, call_len) = if approvals >= threshold { Self::get_call(&call_hash, maybe_call.as_ref().map(|c| c.as_ref())) - } else { None }; + } else { (None, 0) }; if let Some(call) = maybe_approved_call { // verify weight @@ -626,14 +626,19 @@ impl Module { } /// Attempt to decode and return the call, provided by the user or from storage. - fn get_call(hash: &[u8; 32], maybe_known: Option<&[u8]>) -> Option<::Call> { - maybe_known.map_or_else(|| { + fn get_call(hash: &[u8; 32], maybe_known: Option<&[u8]>) -> (Option<::Call>, usize) { + let maybe_data = maybe_known.map_or_else(|| { Calls::::get(hash).and_then(|(data, ..)| { - Decode::decode(&mut &data[..]).ok() + Some(data) }) - }, |data| { - Decode::decode(&mut &data[..]).ok() - }) + }, |v| Some(v.to_vec())); + + if let Some(data) = maybe_data { + let call = Decode::decode(&mut &data[..]).ok(); + return (call, data.len()) + } else { + (None, 0) + } } /// Attempt to remove a call from storage, returning any deposit on it to the owner. From df407f0176fb8a1de960952a902af999e32c7517 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 21 Sep 2020 13:56:58 +0200 Subject: [PATCH 10/13] better implementation --- frame/multisig/src/lib.rs | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/frame/multisig/src/lib.rs b/frame/multisig/src/lib.rs index 1ee1735848dfb..bc1e7cfdcfa24 100644 --- a/frame/multisig/src/lib.rs +++ b/frame/multisig/src/lib.rs @@ -505,11 +505,11 @@ impl Module { if maybe_pos.is_some() { approvals += 1; } // We only bother fetching/decoding call if we know that we're ready to execute. - let (maybe_approved_call, call_len) = if approvals >= threshold { + let maybe_approved_call = if approvals >= threshold { Self::get_call(&call_hash, maybe_call.as_ref().map(|c| c.as_ref())) - } else { (None, 0) }; + } else { None }; - if let Some(call) = maybe_approved_call { + if let Some((call, call_len)) = maybe_approved_call { // verify weight ensure!(call.get_dispatch_info().weight <= max_weight, Error::::WeightTooLow); @@ -626,19 +626,14 @@ impl Module { } /// Attempt to decode and return the call, provided by the user or from storage. - fn get_call(hash: &[u8; 32], maybe_known: Option<&[u8]>) -> (Option<::Call>, usize) { - let maybe_data = maybe_known.map_or_else(|| { - Calls::::get(hash).and_then(|(data, ..)| { - Some(data) + fn get_call(hash: &[u8; 32], maybe_known: Option<&[u8]>) -> Option<(::Call, usize)> { + maybe_known.map_or_else(|| { + Calls::::get(hash).and_then(|(data, ..)| { + Decode::decode(&mut &data[..]).ok().map(|d| (d, data.len())) + }) + }, |data| { + Decode::decode(&mut &data[..]).ok().map(|d| (d, data.len())) }) - }, |v| Some(v.to_vec())); - - if let Some(data) = maybe_data { - let call = Decode::decode(&mut &data[..]).ok(); - return (call, data.len()) - } else { - (None, 0) - } } /// Attempt to remove a call from storage, returning any deposit on it to the owner. From be54467a7eaa0af92b14a6c6814a7799ee0715f2 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 21 Sep 2020 13:58:16 +0200 Subject: [PATCH 11/13] fix spacing --- frame/multisig/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/frame/multisig/src/lib.rs b/frame/multisig/src/lib.rs index bc1e7cfdcfa24..9a68a7a9cd651 100644 --- a/frame/multisig/src/lib.rs +++ b/frame/multisig/src/lib.rs @@ -627,13 +627,13 @@ impl Module { /// Attempt to decode and return the call, provided by the user or from storage. fn get_call(hash: &[u8; 32], maybe_known: Option<&[u8]>) -> Option<(::Call, usize)> { - maybe_known.map_or_else(|| { - Calls::::get(hash).and_then(|(data, ..)| { - Decode::decode(&mut &data[..]).ok().map(|d| (d, data.len())) - }) - }, |data| { + maybe_known.map_or_else(|| { + Calls::::get(hash).and_then(|(data, ..)| { Decode::decode(&mut &data[..]).ok().map(|d| (d, data.len())) }) + }, |data| { + Decode::decode(&mut &data[..]).ok().map(|d| (d, data.len())) + }) } /// Attempt to remove a call from storage, returning any deposit on it to the owner. From 564972e72619ced6ceb4df13bc3fb918b27ce1e4 Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 21 Sep 2020 13:58:39 +0200 Subject: [PATCH 12/13] spacing --- frame/multisig/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/multisig/src/lib.rs b/frame/multisig/src/lib.rs index 9a68a7a9cd651..1ce4e06a6e118 100644 --- a/frame/multisig/src/lib.rs +++ b/frame/multisig/src/lib.rs @@ -629,7 +629,7 @@ impl Module { fn get_call(hash: &[u8; 32], maybe_known: Option<&[u8]>) -> Option<(::Call, usize)> { maybe_known.map_or_else(|| { Calls::::get(hash).and_then(|(data, ..)| { - Decode::decode(&mut &data[..]).ok().map(|d| (d, data.len())) + Decode::decode(&mut &data[..]).ok().map(|d| (d, data.len())) }) }, |data| { Decode::decode(&mut &data[..]).ok().map(|d| (d, data.len())) From 8b3423213e2c6722c383986d577a6dd044510aad Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 21 Sep 2020 16:06:35 +0200 Subject: [PATCH 13/13] Update frame/multisig/src/benchmarking.rs Co-authored-by: Alexander Popiak --- frame/multisig/src/benchmarking.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/multisig/src/benchmarking.rs b/frame/multisig/src/benchmarking.rs index 5003f6d0dc62e..bf89ec8b09bd4 100644 --- a/frame/multisig/src/benchmarking.rs +++ b/frame/multisig/src/benchmarking.rs @@ -207,7 +207,7 @@ benchmarks! { approve_as_multi_approve { // Signatories, need at least 2 people let s in 2 .. T::MaxSignatories::get() as u32; - // Transaction Length not a component + // Transaction Length, not a component let z = 10_000; let (mut signatories, call) = setup_multi::(s, z)?; let mut signatories2 = signatories.clone();