Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit f778556

Browse files
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>
1 parent 93b2c36 commit f778556

File tree

6 files changed

+316
-158
lines changed

6 files changed

+316
-158
lines changed

bin/node/runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl pallet_multisig::Trait for Runtime {
207207
type DepositBase = DepositBase;
208208
type DepositFactor = DepositFactor;
209209
type MaxSignatories = MaxSignatories;
210-
type WeightInfo = ();
210+
type WeightInfo = weights::pallet_multisig::WeightInfo;
211211
}
212212

213213
parameter_types! {

bin/node/runtime/src/weights/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub mod pallet_democracy;
2323
pub mod pallet_identity;
2424
pub mod pallet_indices;
2525
pub mod pallet_im_online;
26+
pub mod pallet_multisig;
2627
pub mod pallet_proxy;
2728
pub mod pallet_scheduler;
2829
pub mod pallet_session;
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// This file is part of Substrate.
2+
3+
// Copyright (C) 2019-2020 Parity Technologies (UK) Ltd.
4+
// SPDX-License-Identifier: Apache-2.0
5+
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 2.0.0-rc6
19+
20+
#![allow(unused_parens)]
21+
#![allow(unused_imports)]
22+
23+
use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight};
24+
25+
pub struct WeightInfo;
26+
impl pallet_multisig::WeightInfo for WeightInfo {
27+
fn as_multi_threshold_1(z: u32, ) -> Weight {
28+
(17_161_000 as Weight)
29+
.saturating_add((1_000 as Weight).saturating_mul(z as Weight))
30+
}
31+
fn as_multi_create(s: u32, z: u32, ) -> Weight {
32+
(79_857_000 as Weight)
33+
.saturating_add((131_000 as Weight).saturating_mul(s as Weight))
34+
.saturating_add((1_000 as Weight).saturating_mul(z as Weight))
35+
.saturating_add(DbWeight::get().reads(2 as Weight))
36+
.saturating_add(DbWeight::get().writes(1 as Weight))
37+
}
38+
fn as_multi_create_store(s: u32, z: u32, ) -> Weight {
39+
(90_218_000 as Weight)
40+
.saturating_add((129_000 as Weight).saturating_mul(s as Weight))
41+
.saturating_add((3_000 as Weight).saturating_mul(z as Weight))
42+
.saturating_add(DbWeight::get().reads(3 as Weight))
43+
.saturating_add(DbWeight::get().writes(2 as Weight))
44+
}
45+
fn as_multi_approve(s: u32, z: u32, ) -> Weight {
46+
(48_402_000 as Weight)
47+
.saturating_add((132_000 as Weight).saturating_mul(s as Weight))
48+
.saturating_add((1_000 as Weight).saturating_mul(z as Weight))
49+
.saturating_add(DbWeight::get().reads(1 as Weight))
50+
.saturating_add(DbWeight::get().writes(1 as Weight))
51+
}
52+
fn as_multi_approve_store(s: u32, z: u32, ) -> Weight {
53+
(88_390_000 as Weight)
54+
.saturating_add((120_000 as Weight).saturating_mul(s as Weight))
55+
.saturating_add((3_000 as Weight).saturating_mul(z as Weight))
56+
.saturating_add(DbWeight::get().reads(2 as Weight))
57+
.saturating_add(DbWeight::get().writes(2 as Weight))
58+
}
59+
fn as_multi_complete(s: u32, z: u32, ) -> Weight {
60+
(98_960_000 as Weight)
61+
.saturating_add((276_000 as Weight).saturating_mul(s as Weight))
62+
.saturating_add((6_000 as Weight).saturating_mul(z as Weight))
63+
.saturating_add(DbWeight::get().reads(3 as Weight))
64+
.saturating_add(DbWeight::get().writes(3 as Weight))
65+
}
66+
fn approve_as_multi_create(s: u32, ) -> Weight {
67+
(80_185_000 as Weight)
68+
.saturating_add((121_000 as Weight).saturating_mul(s as Weight))
69+
.saturating_add(DbWeight::get().reads(2 as Weight))
70+
.saturating_add(DbWeight::get().writes(1 as Weight))
71+
}
72+
fn approve_as_multi_approve(s: u32, ) -> Weight {
73+
(48_386_000 as Weight)
74+
.saturating_add((143_000 as Weight).saturating_mul(s as Weight))
75+
.saturating_add(DbWeight::get().reads(1 as Weight))
76+
.saturating_add(DbWeight::get().writes(1 as Weight))
77+
}
78+
fn approve_as_multi_complete(s: u32, ) -> Weight {
79+
(177_181_000 as Weight)
80+
.saturating_add((273_000 as Weight).saturating_mul(s as Weight))
81+
.saturating_add(DbWeight::get().reads(3 as Weight))
82+
.saturating_add(DbWeight::get().writes(3 as Weight))
83+
}
84+
fn cancel_as_multi(s: u32, ) -> Weight {
85+
(126_334_000 as Weight)
86+
.saturating_add((124_000 as Weight).saturating_mul(s as Weight))
87+
.saturating_add(DbWeight::get().reads(2 as Weight))
88+
.saturating_add(DbWeight::get().writes(2 as Weight))
89+
}
90+
}

frame/multisig/src/benchmarking.rs

Lines changed: 65 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ benchmarks! {
5959
let call_hash = call.using_encoded(blake2_256);
6060
let multi_account_id = Multisig::<T>::multi_account_id(&signatories, 1);
6161
let caller = signatories.pop().ok_or("signatories should have len 2 or more")?;
62+
// Whitelist caller account from further DB operations.
63+
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller);
64+
frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into());
6265
}: _(RawOrigin::Signed(caller.clone()), signatories, Box::new(call))
6366
verify {
6467
// If the benchmark resolves, then the call was dispatched successfully.
@@ -73,9 +76,13 @@ benchmarks! {
7376
let call_hash = blake2_256(&call);
7477
let multi_account_id = Multisig::<T>::multi_account_id(&signatories, s.try_into().unwrap());
7578
let caller = signatories.pop().ok_or("signatories should have len 2 or more")?;
79+
// Whitelist caller account from further DB operations.
80+
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller);
81+
frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into());
7682
}: as_multi(RawOrigin::Signed(caller), s as u16, signatories, None, call, false, 0)
7783
verify {
7884
assert!(Multisigs::<T>::contains_key(multi_account_id, call_hash));
85+
assert!(!Calls::<T>::contains_key(call_hash));
7986
}
8087

8188
as_multi_create_store {
@@ -88,6 +95,9 @@ benchmarks! {
8895
let multi_account_id = Multisig::<T>::multi_account_id(&signatories, s.try_into().unwrap());
8996
let caller = signatories.pop().ok_or("signatories should have len 2 or more")?;
9097
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
98+
// Whitelist caller account from further DB operations.
99+
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller);
100+
frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into());
91101
}: as_multi(RawOrigin::Signed(caller), s as u16, signatories, None, call, true, 0)
92102
verify {
93103
assert!(Multisigs::<T>::contains_key(multi_account_id, call_hash));
@@ -108,13 +118,43 @@ benchmarks! {
108118
let timepoint = Multisig::<T>::timepoint();
109119
// Create the multi, storing for worst case
110120
Multisig::<T>::as_multi(RawOrigin::Signed(caller).into(), s as u16, signatories, None, call.clone(), true, 0)?;
121+
assert!(Calls::<T>::contains_key(call_hash));
111122
let caller2 = signatories2.remove(0);
123+
// Whitelist caller account from further DB operations.
124+
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller2);
125+
frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into());
112126
}: as_multi(RawOrigin::Signed(caller2), s as u16, signatories2, Some(timepoint), call, false, 0)
113127
verify {
114128
let multisig = Multisigs::<T>::get(multi_account_id, call_hash).ok_or("multisig not created")?;
115129
assert_eq!(multisig.approvals.len(), 2);
116130
}
117131

132+
as_multi_approve_store {
133+
// Signatories, need at least 3 people (so we don't complete the multisig)
134+
let s in 3 .. T::MaxSignatories::get() as u32;
135+
// Transaction Length
136+
let z in 0 .. 10_000;
137+
let (mut signatories, call) = setup_multi::<T>(s, z)?;
138+
let call_hash = blake2_256(&call);
139+
let multi_account_id = Multisig::<T>::multi_account_id(&signatories, s.try_into().unwrap());
140+
let mut signatories2 = signatories.clone();
141+
let caller = signatories.pop().ok_or("signatories should have len 2 or more")?;
142+
// before the call, get the timepoint
143+
let timepoint = Multisig::<T>::timepoint();
144+
// Create the multi, not storing
145+
Multisig::<T>::as_multi(RawOrigin::Signed(caller).into(), s as u16, signatories, None, call.clone(), false, 0)?;
146+
assert!(!Calls::<T>::contains_key(call_hash));
147+
let caller2 = signatories2.remove(0);
148+
// Whitelist caller account from further DB operations.
149+
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller2);
150+
frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into());
151+
}: as_multi(RawOrigin::Signed(caller2), s as u16, signatories2, Some(timepoint), call, true, 0)
152+
verify {
153+
let multisig = Multisigs::<T>::get(multi_account_id, call_hash).ok_or("multisig not created")?;
154+
assert_eq!(multisig.approvals.len(), 2);
155+
assert!(Calls::<T>::contains_key(call_hash));
156+
}
157+
118158
as_multi_complete {
119159
// Signatories, need at least 2 people
120160
let s in 2 .. T::MaxSignatories::get() as u32;
@@ -138,6 +178,9 @@ benchmarks! {
138178
}
139179
let caller2 = signatories2.remove(0);
140180
assert!(Multisigs::<T>::contains_key(&multi_account_id, call_hash));
181+
// Whitelist caller account from further DB operations.
182+
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller2);
183+
frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into());
141184
}: as_multi(RawOrigin::Signed(caller2), s as u16, signatories2, Some(timepoint), call, false, Weight::max_value())
142185
verify {
143186
assert!(!Multisigs::<T>::contains_key(&multi_account_id, call_hash));
@@ -146,12 +189,15 @@ benchmarks! {
146189
approve_as_multi_create {
147190
// Signatories, need at least 2 people
148191
let s in 2 .. T::MaxSignatories::get() as u32;
149-
// Transaction Length
150-
let z in 0 .. 10_000;
192+
// Transaction Length, not a component
193+
let z = 10_000;
151194
let (mut signatories, call) = setup_multi::<T>(s, z)?;
152195
let multi_account_id = Multisig::<T>::multi_account_id(&signatories, s.try_into().unwrap());
153196
let caller = signatories.pop().ok_or("signatories should have len 2 or more")?;
154197
let call_hash = blake2_256(&call);
198+
// Whitelist caller account from further DB operations.
199+
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller);
200+
frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into());
155201
// Create the multi
156202
}: approve_as_multi(RawOrigin::Signed(caller), s as u16, signatories, None, call_hash, 0)
157203
verify {
@@ -161,8 +207,8 @@ benchmarks! {
161207
approve_as_multi_approve {
162208
// Signatories, need at least 2 people
163209
let s in 2 .. T::MaxSignatories::get() as u32;
164-
// Transaction Length
165-
let z in 0 .. 10_000;
210+
// Transaction Length, not a component
211+
let z = 10_000;
166212
let (mut signatories, call) = setup_multi::<T>(s, z)?;
167213
let mut signatories2 = signatories.clone();
168214
let multi_account_id = Multisig::<T>::multi_account_id(&signatories, s.try_into().unwrap());
@@ -181,6 +227,9 @@ benchmarks! {
181227
0
182228
)?;
183229
let caller2 = signatories2.remove(0);
230+
// Whitelist caller account from further DB operations.
231+
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller2);
232+
frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into());
184233
}: approve_as_multi(RawOrigin::Signed(caller2), s as u16, signatories2, Some(timepoint), call_hash, 0)
185234
verify {
186235
let multisig = Multisigs::<T>::get(multi_account_id, call_hash).ok_or("multisig not created")?;
@@ -190,8 +239,8 @@ benchmarks! {
190239
approve_as_multi_complete {
191240
// Signatories, need at least 2 people
192241
let s in 2 .. T::MaxSignatories::get() as u32;
193-
// Transaction Length
194-
let z in 0 .. 10_000;
242+
// Transaction Length, not a component
243+
let z = 10_000;
195244
let (mut signatories, call) = setup_multi::<T>(s, z)?;
196245
let multi_account_id = Multisig::<T>::multi_account_id(&signatories, s.try_into().unwrap());
197246
let mut signatories2 = signatories.clone();
@@ -211,6 +260,9 @@ benchmarks! {
211260
}
212261
let caller2 = signatories2.remove(0);
213262
assert!(Multisigs::<T>::contains_key(&multi_account_id, call_hash));
263+
// Whitelist caller account from further DB operations.
264+
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller2);
265+
frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into());
214266
}: approve_as_multi(
215267
RawOrigin::Signed(caller2),
216268
s as u16,
@@ -226,8 +278,8 @@ benchmarks! {
226278
cancel_as_multi {
227279
// Signatories, need at least 2 people
228280
let s in 2 .. T::MaxSignatories::get() as u32;
229-
// Transaction Length
230-
let z in 0 .. 10_000;
281+
// Transaction Length, not a component
282+
let z = 10_000;
231283
let (mut signatories, call) = setup_multi::<T>(s, z)?;
232284
let multi_account_id = Multisig::<T>::multi_account_id(&signatories, s.try_into().unwrap());
233285
let caller = signatories.pop().ok_or("signatories should have len 2 or more")?;
@@ -237,30 +289,13 @@ benchmarks! {
237289
let o = RawOrigin::Signed(caller.clone()).into();
238290
Multisig::<T>::as_multi(o, s as u16, signatories.clone(), None, call.clone(), true, 0)?;
239291
assert!(Multisigs::<T>::contains_key(&multi_account_id, call_hash));
292+
assert!(Calls::<T>::contains_key(call_hash));
293+
// Whitelist caller account from further DB operations.
294+
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller);
295+
frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into());
240296
}: _(RawOrigin::Signed(caller), s as u16, signatories, timepoint, call_hash)
241297
verify {
242298
assert!(!Multisigs::<T>::contains_key(multi_account_id, call_hash));
243-
}
244-
245-
cancel_as_multi_store {
246-
// Signatories, need at least 2 people
247-
let s in 2 .. T::MaxSignatories::get() as u32;
248-
// Transaction Length
249-
let z in 0 .. 10_000;
250-
let (mut signatories, call) = setup_multi::<T>(s, z)?;
251-
let multi_account_id = Multisig::<T>::multi_account_id(&signatories, s.try_into().unwrap());
252-
let caller = signatories.pop().ok_or("signatories should have len 2 or more")?;
253-
T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value());
254-
let call_hash = blake2_256(&call);
255-
let timepoint = Multisig::<T>::timepoint();
256-
// Create the multi
257-
let o = RawOrigin::Signed(caller.clone()).into();
258-
Multisig::<T>::as_multi(o, s as u16, signatories.clone(), None, call.clone(), true, 0)?;
259-
assert!(Multisigs::<T>::contains_key(&multi_account_id, call_hash));
260-
assert!(Calls::<T>::contains_key(call_hash));
261-
}: cancel_as_multi(RawOrigin::Signed(caller), s as u16, signatories, timepoint, call_hash)
262-
verify {
263-
assert!(!Multisigs::<T>::contains_key(&multi_account_id, call_hash));
264299
assert!(!Calls::<T>::contains_key(call_hash));
265300
}
266301
}
@@ -278,12 +313,12 @@ mod tests {
278313
assert_ok!(test_benchmark_as_multi_create::<Test>());
279314
assert_ok!(test_benchmark_as_multi_create_store::<Test>());
280315
assert_ok!(test_benchmark_as_multi_approve::<Test>());
316+
assert_ok!(test_benchmark_as_multi_approve_store::<Test>());
281317
assert_ok!(test_benchmark_as_multi_complete::<Test>());
282318
assert_ok!(test_benchmark_approve_as_multi_create::<Test>());
283319
assert_ok!(test_benchmark_approve_as_multi_approve::<Test>());
284320
assert_ok!(test_benchmark_approve_as_multi_complete::<Test>());
285321
assert_ok!(test_benchmark_cancel_as_multi::<Test>());
286-
assert_ok!(test_benchmark_cancel_as_multi_store::<Test>());
287322
});
288323
}
289324
}

0 commit comments

Comments
 (0)