WeightInfo for Multisig Pallet (#7154)

* as multi threshold 1

* add `as_multi_approve_store` benchmark

* finish update

* final weights

* integrate into runtime

* whitelist accounts

* whitelisted caller weights

* clean up comments

* Get up to date `call_len`

* better implementation

* fix spacing

* spacing

* Update frame/multisig/src/benchmarking.rs

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
This commit is contained in:
Shawn Tabrizi
2020-09-21 16:39:19 +02:00
committed by GitHub
parent 42a4c2eef0
commit 91b170656c
6 changed files with 317 additions and 159 deletions
+1 -1
View File
@@ -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! {
@@ -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_session;
@@ -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 {
(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 {
(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(2 as Weight))
.saturating_add(DbWeight::get().writes(1 as Weight))
}
fn as_multi_create_store(s: u32, z: u32, ) -> 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(3 as Weight))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
fn as_multi_approve(s: u32, z: u32, ) -> 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 {
(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(2 as Weight))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
fn as_multi_complete(s: u32, z: u32, ) -> 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 {
(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 {
(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 {
(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 {
(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))
}
}
+66 -31
View File
@@ -59,6 +59,9 @@ benchmarks! {
let call_hash = call.using_encoded(blake2_256);
let multi_account_id = Multisig::<T>::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::<T>::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,9 +76,13 @@ benchmarks! {
let call_hash = blake2_256(&call);
let multi_account_id = Multisig::<T>::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::<T>::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::<T>::contains_key(multi_account_id, call_hash));
assert!(!Calls::<T>::contains_key(call_hash));
}
as_multi_create_store {
@@ -88,6 +95,9 @@ benchmarks! {
let multi_account_id = Multisig::<T>::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::<T>::max_value());
// Whitelist caller account from further DB operations.
let caller_key = frame_system::Account::<T>::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::<T>::contains_key(multi_account_id, call_hash));
@@ -108,13 +118,43 @@ benchmarks! {
let timepoint = Multisig::<T>::timepoint();
// Create the multi, storing for worst case
Multisig::<T>::as_multi(RawOrigin::Signed(caller).into(), s as u16, signatories, None, call.clone(), true, 0)?;
assert!(Calls::<T>::contains_key(call_hash));
let caller2 = signatories2.remove(0);
// Whitelist caller account from further DB operations.
let caller_key = frame_system::Account::<T>::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::<T>::get(multi_account_id, call_hash).ok_or("multisig not created")?;
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::<T>(s, z)?;
let call_hash = blake2_256(&call);
let multi_account_id = Multisig::<T>::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::<T>::timepoint();
// Create the multi, not storing
Multisig::<T>::as_multi(RawOrigin::Signed(caller).into(), s as u16, signatories, None, call.clone(), false, 0)?;
assert!(!Calls::<T>::contains_key(call_hash));
let caller2 = signatories2.remove(0);
// Whitelist caller account from further DB operations.
let caller_key = frame_system::Account::<T>::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::<T>::get(multi_account_id, call_hash).ok_or("multisig not created")?;
assert_eq!(multisig.approvals.len(), 2);
assert!(Calls::<T>::contains_key(call_hash));
}
as_multi_complete {
// Signatories, need at least 2 people
let s in 2 .. T::MaxSignatories::get() as u32;
@@ -138,6 +178,9 @@ benchmarks! {
}
let caller2 = signatories2.remove(0);
assert!(Multisigs::<T>::contains_key(&multi_account_id, call_hash));
// Whitelist caller account from further DB operations.
let caller_key = frame_system::Account::<T>::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::<T>::contains_key(&multi_account_id, call_hash));
@@ -146,12 +189,15 @@ 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::<T>(s, z)?;
let multi_account_id = Multisig::<T>::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::<T>::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 {
@@ -161,8 +207,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::<T>(s, z)?;
let mut signatories2 = signatories.clone();
let multi_account_id = Multisig::<T>::multi_account_id(&signatories, s.try_into().unwrap());
@@ -181,6 +227,9 @@ benchmarks! {
0
)?;
let caller2 = signatories2.remove(0);
// Whitelist caller account from further DB operations.
let caller_key = frame_system::Account::<T>::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::<T>::get(multi_account_id, call_hash).ok_or("multisig not created")?;
@@ -190,8 +239,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::<T>(s, z)?;
let multi_account_id = Multisig::<T>::multi_account_id(&signatories, s.try_into().unwrap());
let mut signatories2 = signatories.clone();
@@ -211,6 +260,9 @@ benchmarks! {
}
let caller2 = signatories2.remove(0);
assert!(Multisigs::<T>::contains_key(&multi_account_id, call_hash));
// Whitelist caller account from further DB operations.
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller2);
frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into());
}: approve_as_multi(
RawOrigin::Signed(caller2),
s as u16,
@@ -226,8 +278,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::<T>(s, z)?;
let multi_account_id = Multisig::<T>::multi_account_id(&signatories, s.try_into().unwrap());
let caller = signatories.pop().ok_or("signatories should have len 2 or more")?;
@@ -237,30 +289,13 @@ benchmarks! {
let o = RawOrigin::Signed(caller.clone()).into();
Multisig::<T>::as_multi(o, s as u16, signatories.clone(), None, call.clone(), true, 0)?;
assert!(Multisigs::<T>::contains_key(&multi_account_id, call_hash));
}: _(RawOrigin::Signed(caller), s as u16, signatories, timepoint, call_hash)
verify {
assert!(!Multisigs::<T>::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::<T>(s, z)?;
let multi_account_id = Multisig::<T>::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::<T>::max_value());
let call_hash = blake2_256(&call);
let timepoint = Multisig::<T>::timepoint();
// Create the multi
let o = RawOrigin::Signed(caller.clone()).into();
Multisig::<T>::as_multi(o, s as u16, signatories.clone(), None, call.clone(), true, 0)?;
assert!(Multisigs::<T>::contains_key(&multi_account_id, call_hash));
assert!(Calls::<T>::contains_key(call_hash));
}: cancel_as_multi(RawOrigin::Signed(caller), s as u16, signatories, timepoint, call_hash)
// Whitelist caller account from further DB operations.
let caller_key = frame_system::Account::<T>::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::<T>::contains_key(&multi_account_id, call_hash));
assert!(!Multisigs::<T>::contains_key(multi_account_id, call_hash));
assert!(!Calls::<T>::contains_key(call_hash));
}
}
@@ -278,12 +313,12 @@ mod tests {
assert_ok!(test_benchmark_as_multi_create::<Test>());
assert_ok!(test_benchmark_as_multi_create_store::<Test>());
assert_ok!(test_benchmark_as_multi_approve::<Test>());
assert_ok!(test_benchmark_as_multi_approve_store::<Test>());
assert_ok!(test_benchmark_as_multi_complete::<Test>());
assert_ok!(test_benchmark_approve_as_multi_create::<Test>());
assert_ok!(test_benchmark_approve_as_multi_approve::<Test>());
assert_ok!(test_benchmark_approve_as_multi_complete::<Test>());
assert_ok!(test_benchmark_cancel_as_multi::<Test>());
assert_ok!(test_benchmark_cancel_as_multi_store::<Test>());
});
}
}
@@ -0,0 +1,89 @@
// 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 {
(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 {
(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(2 as Weight))
.saturating_add(DbWeight::get().writes(1 as Weight))
}
fn as_multi_create_store(s: u32, z: u32, ) -> 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(3 as Weight))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
fn as_multi_approve(s: u32, z: u32, ) -> 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 {
(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(2 as Weight))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
fn as_multi_complete(s: u32, z: u32, ) -> 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 {
(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 {
(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 {
(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 {
(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))
}
}
+70 -127
View File
@@ -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<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::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,48 +197,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<T: Trait>(
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
/// - 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<T: Trait>(
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]),
@@ -286,14 +232,12 @@ decl_module! {
/// # <weight>
/// 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
/// # </weight>
#[weight = (
weight_of::as_multi_threshold_1::<T>(
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 +258,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::<T>(
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::<T>(
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 }
@@ -374,23 +315,21 @@ 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 = weight_of::as_multi::<T>(
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<T::AccountId>,
@@ -435,20 +374,18 @@ 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]
/// # </weight>
#[weight = weight_of::as_multi::<T>(
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<T::AccountId>,
@@ -482,15 +419,11 @@ 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
/// # </weight>
#[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<T::AccountId>,
@@ -576,7 +509,7 @@ impl<T: Trait> Module<T> {
Self::get_call(&call_hash, maybe_call.as_ref().map(|c| c.as_ref()))
} 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::<T>::WeightTooLow);
@@ -590,13 +523,12 @@ impl<T: Trait> Module<T> {
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::<T>(
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.
@@ -620,14 +552,19 @@ impl<T: Trait> Module<T> {
ensure!(stored, Error::<T>::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::<T>(
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.
@@ -652,14 +589,20 @@ impl<T: Trait> Module<T> {
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::<T>(
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())
}
}
@@ -683,13 +626,13 @@ impl<T: Trait> Module<T> {
}
/// 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<<T as Trait>::Call> {
fn get_call(hash: &[u8; 32], maybe_known: Option<&[u8]>) -> Option<(<T as Trait>::Call, usize)> {
maybe_known.map_or_else(|| {
Calls::<T>::get(hash).and_then(|(data, ..)| {
Decode::decode(&mut &data[..]).ok()
Decode::decode(&mut &data[..]).ok().map(|d| (d, data.len()))
})
}, |data| {
Decode::decode(&mut &data[..]).ok()
Decode::decode(&mut &data[..]).ok().map(|d| (d, data.len()))
})
}