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

add generated weight info for pallet-collective #6789

Merged
17 commits merged into from
Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ impl pallet_collective::Trait<CouncilCollective> for Runtime {
type Event = Event;
type MotionDuration = CouncilMotionDuration;
type MaxProposals = CouncilMaxProposals;
type WeightInfo = ();
type WeightInfo = weights::pallet_collective::WeightInfo;
}

parameter_types! {
Expand Down
1 change: 1 addition & 0 deletions bin/node/runtime/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
//! A list of the different weight modules for our runtime.

pub mod pallet_balances;
pub mod pallet_collective;
pub mod pallet_democracy;
96 changes: 96 additions & 0 deletions bin/node/runtime/src/weights/pallet_collective.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// Copyright (C) 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-rc5

use frame_support::weights::{Weight, constants::RocksDbWeight as DbWeight};

pub struct WeightInfo;
impl pallet_collective::WeightInfo for WeightInfo {
fn set_members(m: u32, n: u32, p: u32, ) -> Weight {
(0 as Weight)
.saturating_add((20267000 as Weight).saturating_mul(m as Weight))
.saturating_add((176000 as Weight).saturating_mul(n as Weight))
.saturating_add((26230000 as Weight).saturating_mul(p as Weight))
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().reads((1 as Weight).saturating_mul(p as Weight)))
.saturating_add(DbWeight::get().writes(2 as Weight))
.saturating_add(DbWeight::get().writes((1 as Weight).saturating_mul(p as Weight)))
}
fn execute(b: u32, m: u32, ) -> Weight {
(26278000 as Weight)
.saturating_add((111000 as Weight).saturating_mul(m as Weight))
.saturating_add((4000 as Weight).saturating_mul(b as Weight))
.saturating_add(DbWeight::get().reads(1 as Weight))
}
fn propose_execute(b: u32, m: u32, ) -> Weight {
(31972000 as Weight)
.saturating_add((218000 as Weight).saturating_mul(m as Weight))
.saturating_add((4000 as Weight).saturating_mul(b as Weight))
.saturating_add(DbWeight::get().reads(2 as Weight))
}
fn propose_proposed(b: u32, m: u32, p: u32, ) -> Weight {
(53435000 as Weight)
.saturating_add((158000 as Weight).saturating_mul(m as Weight))
.saturating_add((476000 as Weight).saturating_mul(p as Weight))
.saturating_add((2000 as Weight).saturating_mul(b as Weight))
.saturating_add(DbWeight::get().reads(4 as Weight))
.saturating_add(DbWeight::get().writes(4 as Weight))
}
fn vote(m: u32, ) -> Weight {
(46165000 as Weight)
.saturating_add((264000 as Weight).saturating_mul(m as Weight))
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().writes(1 as Weight))
}
// WARNING! Some components were not used: ["b"]
apopiak marked this conversation as resolved.
Show resolved Hide resolved
fn close_early_disapproved(m: u32, p: u32, ) -> Weight {
(52896000 as Weight)
.saturating_add((242000 as Weight).saturating_mul(m as Weight))
.saturating_add((450000 as Weight).saturating_mul(p as Weight))
.saturating_add(DbWeight::get().reads(3 as Weight))
.saturating_add(DbWeight::get().writes(3 as Weight))
}
fn close_early_approved(b: u32, m: u32, p: u32, ) -> Weight {
(73235000 as Weight)
.saturating_add((247000 as Weight).saturating_mul(m as Weight))
.saturating_add((456000 as Weight).saturating_mul(p as Weight))
.saturating_add((1000 as Weight).saturating_mul(b as Weight))
.saturating_add(DbWeight::get().reads(4 as Weight))
.saturating_add(DbWeight::get().writes(3 as Weight))
}
// WARNING! Some components were not used: ["b"]
fn close_disapproved(m: u32, p: u32, ) -> Weight {
(56171000 as Weight)
.saturating_add((250000 as Weight).saturating_mul(m as Weight))
.saturating_add((462000 as Weight).saturating_mul(p as Weight))
.saturating_add(DbWeight::get().reads(4 as Weight))
.saturating_add(DbWeight::get().writes(3 as Weight))
}
fn close_approved(b: u32, m: u32, p: u32, ) -> Weight {
(77594000 as Weight)
.saturating_add((246000 as Weight).saturating_mul(m as Weight))
.saturating_add((453000 as Weight).saturating_mul(p as Weight))
.saturating_add((2000 as Weight).saturating_mul(b as Weight))
.saturating_add(DbWeight::get().reads(5 as Weight))
.saturating_add(DbWeight::get().writes(3 as Weight))
}
fn disapprove_proposal(p: u32, ) -> Weight {
(0 as Weight)
.saturating_add((490000 as Weight).saturating_mul(p as Weight))
.saturating_add(DbWeight::get().reads(1 as Weight))
.saturating_add(DbWeight::get().writes(3 as Weight))
}
}
77 changes: 66 additions & 11 deletions frame/collective/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ benchmarks_instance! {
}

execute {
let m in 1 .. MAX_MEMBERS;
let b in 1 .. MAX_BYTES;
let m in 1 .. MAX_MEMBERS;

let bytes_in_storage = b + size_of::<u32>() as u32;

Expand Down Expand Up @@ -141,8 +141,8 @@ benchmarks_instance! {

// This tests when execution would happen immediately after proposal
propose_execute {
let m in 1 .. MAX_MEMBERS;
let b in 1 .. MAX_BYTES;
let m in 1 .. MAX_MEMBERS;

let bytes_in_storage = b + size_of::<u32>() as u32;

Expand Down Expand Up @@ -172,9 +172,9 @@ benchmarks_instance! {

// This tests when proposal is created and queued as "proposed"
propose_proposed {
let b in 1 .. MAX_BYTES;
let m in 2 .. MAX_MEMBERS;
let p in 1 .. T::MaxProposals::get();
let b in 1 .. MAX_BYTES;

let bytes_in_storage = b + size_of::<u32>() as u32;

Expand Down Expand Up @@ -290,9 +290,9 @@ benchmarks_instance! {
// We choose 4 as a minimum so we always trigger a vote in the voting loop (`for j in ...`)
let m in 4 .. MAX_MEMBERS;
let p in 1 .. T::MaxProposals::get();
let b in 1 .. MAX_BYTES;

let bytes_in_storage = b + size_of::<u32>() as u32;
let bytes = 100;
let bytes_in_storage = bytes + size_of::<u32>() as u32;

// Construct `members`.
let mut members = vec![];
Expand All @@ -313,7 +313,7 @@ benchmarks_instance! {
let mut last_hash = T::Hash::default();
for i in 0 .. p {
// Proposals should be different so that different proposal hashes are generated
let proposal: T::Proposal = SystemCall::<T>::remark(vec![i as u8; b as usize]).into();
let proposal: T::Proposal = SystemCall::<T>::remark(vec![i as u8; bytes as usize]).into();
Collective::<T, _>::propose(
SystemOrigin::Signed(proposer.clone()).into(),
threshold,
Expand Down Expand Up @@ -364,10 +364,10 @@ benchmarks_instance! {
}

close_early_approved {
let b in 1 .. MAX_BYTES;
// We choose 4 as a minimum so we always trigger a vote in the voting loop (`for j in ...`)
let m in 4 .. MAX_MEMBERS;
let p in 1 .. T::MaxProposals::get();
let b in 1 .. MAX_BYTES;

let bytes_in_storage = b + size_of::<u32>() as u32;

Expand Down Expand Up @@ -448,9 +448,9 @@ benchmarks_instance! {
// We choose 4 as a minimum so we always trigger a vote in the voting loop (`for j in ...`)
let m in 4 .. MAX_MEMBERS;
let p in 1 .. T::MaxProposals::get();
let b in 1 .. MAX_BYTES;

let bytes_in_storage = b + size_of::<u32>() as u32;
let bytes = 100;
let bytes_in_storage = bytes + size_of::<u32>() as u32;

// Construct `members`.
let mut members = vec![];
Expand All @@ -474,7 +474,7 @@ benchmarks_instance! {
let mut last_hash = T::Hash::default();
for i in 0 .. p {
// Proposals should be different so that different proposal hashes are generated
let proposal: T::Proposal = SystemCall::<T>::remark(vec![i as u8; b as usize]).into();
let proposal: T::Proposal = SystemCall::<T>::remark(vec![i as u8; bytes as usize]).into();
Collective::<T, _>::propose(
SystemOrigin::Signed(caller.clone()).into(),
threshold,
Expand Down Expand Up @@ -517,10 +517,10 @@ benchmarks_instance! {
}

close_approved {
let b in 1 .. MAX_BYTES;
// We choose 4 as a minimum so we always trigger a vote in the voting loop (`for j in ...`)
let m in 4 .. MAX_MEMBERS;
let p in 1 .. T::MaxProposals::get();
let b in 1 .. MAX_BYTES;

let bytes_in_storage = b + size_of::<u32>() as u32;

Expand Down Expand Up @@ -579,6 +579,54 @@ benchmarks_instance! {
assert_eq!(Collective::<T, _>::proposals().len(), (p - 1) as usize);
assert_last_event::<T, I>(RawEvent::Executed(last_hash, Err(DispatchError::BadOrigin)).into());
}

disapprove_proposal {
let p in 1 .. T::MaxProposals::get();

let m = 3;
let b = MAX_BYTES;
let bytes_in_storage = b + size_of::<u32>() as u32;

// Construct `members`.
let mut members = vec![];
for i in 0 .. m - 1 {
let member = account("member", i, SEED);
members.push(member);
}
let caller: T::AccountId = account("caller", 0, SEED);
members.push(caller.clone());
Collective::<T, _>::set_members(
SystemOrigin::Root.into(),
members.clone(),
Some(caller.clone()),
MAX_MEMBERS,
)?;

// Threshold is one less than total members so that two nays will disapprove the vote
let threshold = m - 1;

// Add proposals
let mut last_hash = T::Hash::default();
for i in 0 .. p {
// Proposals should be different so that different proposal hashes are generated
let proposal: T::Proposal = SystemCall::<T>::remark(vec![i as u8; b as usize]).into();
Collective::<T, _>::propose(
SystemOrigin::Signed(caller.clone()).into(),
threshold,
Box::new(proposal.clone()),
bytes_in_storage,
)?;
last_hash = T::Hashing::hash_of(&proposal);
}

System::<T>::set_block_number(T::BlockNumber::max_value());
assert_eq!(Collective::<T, _>::proposals().len(), p as usize);

}: _(SystemOrigin::Root, last_hash)
verify {
assert_eq!(Collective::<T, _>::proposals().len(), (p - 1) as usize);
assert_last_event::<T, I>(RawEvent::Disapproved(last_hash).into());
}
}

#[cfg(test)]
Expand Down Expand Up @@ -649,4 +697,11 @@ mod tests {
assert_ok!(test_benchmark_close_approved::<Test>());
});
}

#[test]
fn disapprove_proposal() {
new_test_ext().execute_with(|| {
assert_ok!(test_benchmark_disapprove_proposal::<Test>());
});
}
}
Loading