Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 12 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
10 changes: 7 additions & 3 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ impl pallet_democracy::Trait for Runtime {
parameter_types! {
pub const CouncilMotionDuration: BlockNumber = 5 * DAYS;
pub const CouncilMaxProposals: u32 = 100;
pub const CouncilMaxMembers: u32 = 100;
}

type CouncilCollective = pallet_collective::Instance1;
Expand All @@ -518,6 +519,7 @@ impl pallet_collective::Trait<CouncilCollective> for Runtime {
type Event = Event;
type MotionDuration = CouncilMotionDuration;
type MaxProposals = CouncilMaxProposals;
type MaxMembers = CouncilMaxMembers;
type WeightInfo = weights::pallet_collective::WeightInfo;
}

Expand All @@ -530,8 +532,8 @@ parameter_types! {
pub const ElectionsPhragmenModuleId: LockIdentifier = *b"phrelect";
}

// Make sure that there are no more than `MAX_MEMBERS` members elected via elections-phragmen.
const_assert!(DesiredMembers::get() <= pallet_collective::MAX_MEMBERS);
// Make sure that there are no more than `MaxMembers` members elected via elections-phragmen.
const_assert!(DesiredMembers::get() <= CouncilMaxMembers::get());

impl pallet_elections_phragmen::Trait for Runtime {
type Event = Event;
Expand All @@ -556,6 +558,7 @@ impl pallet_elections_phragmen::Trait for Runtime {
parameter_types! {
pub const TechnicalMotionDuration: BlockNumber = 5 * DAYS;
pub const TechnicalMaxProposals: u32 = 100;
pub const TechnicalMaxMembers: u32 = 100;
}

type TechnicalCollective = pallet_collective::Instance2;
Expand All @@ -565,7 +568,8 @@ impl pallet_collective::Trait<TechnicalCollective> for Runtime {
type Event = Event;
type MotionDuration = TechnicalMotionDuration;
type MaxProposals = TechnicalMaxProposals;
type WeightInfo = ();
type MaxMembers = TechnicalMaxMembers;
type WeightInfo = weights::pallet_collective::WeightInfo;
}

type EnsureRootOrHalfCouncil = EnsureOneOf<
Expand Down
63 changes: 32 additions & 31 deletions bin/node/runtime/src/weights/pallet_collective.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,83 +13,84 @@
// 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
//! 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_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((21040000 as Weight).saturating_mul(m as Weight))
.saturating_add((173000 as Weight).saturating_mul(n as Weight))
.saturating_add((31595000 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))
(43359000 as Weight)
.saturating_add((4000 as Weight).saturating_mul(b as Weight))
.saturating_add((123000 as Weight).saturating_mul(m 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))
(54134000 as Weight)
.saturating_add((4000 as Weight).saturating_mul(b as Weight))
.saturating_add((239000 as Weight).saturating_mul(m 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))
(90650000 as Weight)
.saturating_add((5000 as Weight).saturating_mul(b as Weight))
.saturating_add((152000 as Weight).saturating_mul(m as Weight))
.saturating_add((970000 as Weight).saturating_mul(p 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))
(74460000 as Weight)
.saturating_add((290000 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"]
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))
(86360000 as Weight)
.saturating_add((232000 as Weight).saturating_mul(m as Weight))
.saturating_add((954000 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))
(123653000 as Weight)
.saturating_add((1000 as Weight).saturating_mul(b as Weight))
.saturating_add((287000 as Weight).saturating_mul(m as Weight))
.saturating_add((920000 as Weight).saturating_mul(p 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))
(95395000 as Weight)
.saturating_add((236000 as Weight).saturating_mul(m as Weight))
.saturating_add((965000 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))
(135284000 as Weight)
.saturating_add((4000 as Weight).saturating_mul(b as Weight))
.saturating_add((218000 as Weight).saturating_mul(m as Weight))
.saturating_add((951000 as Weight).saturating_mul(p 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))
(50500000 as Weight)
.saturating_add((966000 as Weight).saturating_mul(p as Weight))
Comment on lines +92 to +93
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a lot more weight than I expected, what do you think where it comes from?

.saturating_add(DbWeight::get().reads(1 as Weight))
.saturating_add(DbWeight::get().writes(3 as Weight))
}
Expand Down
48 changes: 27 additions & 21 deletions frame/collective/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ benchmarks_instance! {
_{ }

set_members {
let m in 1 .. MAX_MEMBERS;
let n in 1 .. MAX_MEMBERS;
let m in 1 .. T::MaxMembers::get();
let n in 1 .. T::MaxMembers::get();
let p in 1 .. T::MaxProposals::get();

// Set old members.
Expand All @@ -63,7 +63,7 @@ benchmarks_instance! {
SystemOrigin::Root.into(),
old_members.clone(),
Some(last_old_member.clone()),
MAX_MEMBERS,
T::MaxMembers::get(),
)?;

// Set a high threshold for proposals passing so that they stay around.
Expand Down Expand Up @@ -104,15 +104,15 @@ benchmarks_instance! {
new_members.push(last_member.clone());
}

}: _(SystemOrigin::Root, new_members.clone(), Some(last_member), MAX_MEMBERS)
}: _(SystemOrigin::Root, new_members.clone(), Some(last_member), T::MaxMembers::get())
verify {
new_members.sort();
assert_eq!(Collective::<T, _>::members(), new_members);
}

execute {
let b in 1 .. MAX_BYTES;
let m in 1 .. MAX_MEMBERS;
let m in 1 .. T::MaxMembers::get();

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

Expand All @@ -126,7 +126,7 @@ benchmarks_instance! {
let caller: T::AccountId = whitelisted_caller();
members.push(caller.clone());

Collective::<T, _>::set_members(SystemOrigin::Root.into(), members, None, MAX_MEMBERS)?;
Collective::<T, _>::set_members(SystemOrigin::Root.into(), members, None, T::MaxMembers::get())?;

let proposal: T::Proposal = SystemCall::<T>::remark(vec![1; b as usize]).into();

Expand All @@ -142,7 +142,7 @@ benchmarks_instance! {
// This tests when execution would happen immediately after proposal
propose_execute {
let b in 1 .. MAX_BYTES;
let m in 1 .. MAX_MEMBERS;
let m in 1 .. T::MaxMembers::get();

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

Expand All @@ -156,7 +156,7 @@ benchmarks_instance! {
let caller: T::AccountId = whitelisted_caller();
members.push(caller.clone());

Collective::<T, _>::set_members(SystemOrigin::Root.into(), members, None, MAX_MEMBERS)?;
Collective::<T, _>::set_members(SystemOrigin::Root.into(), members, None, T::MaxMembers::get())?;

let proposal: T::Proposal = SystemCall::<T>::remark(vec![1; b as usize]).into();
let threshold = 1;
Expand All @@ -173,7 +173,7 @@ 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 m in 2 .. T::MaxMembers::get();
let p in 1 .. T::MaxProposals::get();

let bytes_in_storage = b + size_of::<u32>() as u32;
Expand All @@ -186,7 +186,7 @@ benchmarks_instance! {
}
let caller: T::AccountId = whitelisted_caller();
members.push(caller.clone());
Collective::<T, _>::set_members(SystemOrigin::Root.into(), members, None, MAX_MEMBERS)?;
Collective::<T, _>::set_members(SystemOrigin::Root.into(), members, None, T::MaxMembers::get())?;

let threshold = m;
// Add previous proposals.
Expand Down Expand Up @@ -215,7 +215,7 @@ benchmarks_instance! {

vote {
// We choose 5 as a minimum so we always trigger a vote in the voting loop (`for j in ...`)
let m in 5 .. MAX_MEMBERS;
let m in 5 .. T::MaxMembers::get();

let p = T::MaxProposals::get();
let b = MAX_BYTES;
Expand All @@ -231,7 +231,7 @@ benchmarks_instance! {
}
let voter: T::AccountId = account("voter", 0, SEED);
members.push(voter.clone());
Collective::<T, _>::set_members(SystemOrigin::Root.into(), members.clone(), None, MAX_MEMBERS)?;
Collective::<T, _>::set_members(SystemOrigin::Root.into(), members.clone(), None, T::MaxMembers::get())?;

// Threshold is 1 less than the number of members so that one person can vote nay
let threshold = m - 1;
Expand Down Expand Up @@ -277,6 +277,9 @@ benchmarks_instance! {
// Voter switches vote to nay, but does not kill the vote, just updates + inserts
let approve = false;

// Whitelist voter account from further DB operations.
let voter_key = frame_system::Account::<T>::hashed_key_for(&voter);
frame_benchmarking::benchmarking::add_to_whitelist(voter_key.into());
}: _(SystemOrigin::Signed(voter), last_hash.clone(), index, approve)
verify {
// All proposals exist and the last proposal has just been updated.
Expand All @@ -288,7 +291,7 @@ benchmarks_instance! {

close_early_disapproved {
// 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 m in 4 .. T::MaxMembers::get();
let p in 1 .. T::MaxProposals::get();

let bytes = 100;
Expand All @@ -304,7 +307,7 @@ benchmarks_instance! {
}
let voter: T::AccountId = account("voter", 0, SEED);
members.push(voter.clone());
Collective::<T, _>::set_members(SystemOrigin::Root.into(), members.clone(), None, MAX_MEMBERS)?;
Collective::<T, _>::set_members(SystemOrigin::Root.into(), members.clone(), None, T::MaxMembers::get())?;

// Threshold is total members so that one nay will disapprove the vote
let threshold = m;
Expand Down Expand Up @@ -356,6 +359,9 @@ benchmarks_instance! {
approve,
)?;

// Whitelist voter account from further DB operations.
let voter_key = frame_system::Account::<T>::hashed_key_for(&voter);
frame_benchmarking::benchmarking::add_to_whitelist(voter_key.into());
}: close(SystemOrigin::Signed(voter), last_hash.clone(), index, Weight::max_value(), bytes_in_storage)
verify {
// The last proposal is removed.
Expand All @@ -366,7 +372,7 @@ 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 m in 4 .. T::MaxMembers::get();
let p in 1 .. T::MaxProposals::get();

let bytes_in_storage = b + size_of::<u32>() as u32;
Expand All @@ -379,7 +385,7 @@ benchmarks_instance! {
}
let caller: T::AccountId = whitelisted_caller();
members.push(caller.clone());
Collective::<T, _>::set_members(SystemOrigin::Root.into(), members.clone(), None, MAX_MEMBERS)?;
Collective::<T, _>::set_members(SystemOrigin::Root.into(), members.clone(), None, T::MaxMembers::get())?;

// Threshold is 2 so any two ayes will approve the vote
let threshold = 2;
Expand Down Expand Up @@ -446,7 +452,7 @@ benchmarks_instance! {

close_disapproved {
// 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 m in 4 .. T::MaxMembers::get();
let p in 1 .. T::MaxProposals::get();

let bytes = 100;
Expand All @@ -464,7 +470,7 @@ benchmarks_instance! {
SystemOrigin::Root.into(),
members.clone(),
Some(caller.clone()),
MAX_MEMBERS,
T::MaxMembers::get(),
)?;

// Threshold is one less than total members so that two nays will disapprove the vote
Expand Down Expand Up @@ -519,7 +525,7 @@ 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 m in 4 .. T::MaxMembers::get();
let p in 1 .. T::MaxProposals::get();

let bytes_in_storage = b + size_of::<u32>() as u32;
Expand All @@ -536,7 +542,7 @@ benchmarks_instance! {
SystemOrigin::Root.into(),
members.clone(),
Some(caller.clone()),
MAX_MEMBERS,
T::MaxMembers::get(),
)?;

// Threshold is two, so any two ayes will pass the vote
Expand Down Expand Up @@ -599,7 +605,7 @@ benchmarks_instance! {
SystemOrigin::Root.into(),
members.clone(),
Some(caller.clone()),
MAX_MEMBERS,
T::MaxMembers::get(),
)?;

// Threshold is one less than total members so that two nays will disapprove the vote
Expand Down
Loading