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

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
apopiak committed Aug 7, 2020
1 parent 199a630 commit 768a363
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 32 deletions.
12 changes: 6 additions & 6 deletions frame/collective/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,12 @@ benchmarks_instance! {
}

close_early_disapproved {
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 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 @@ -445,12 +445,12 @@ benchmarks_instance! {
}

close_disapproved {
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 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
37 changes: 11 additions & 26 deletions frame/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,26 +235,6 @@ decl_error! {
}
}

/// Functions for calcuating the weight of dispatchables.
mod weight_for {
use frame_support::weights::Weight;
use super::{Trait, Instance, WeightInfo};

/// Calculate the weight for `close`.
pub(crate) fn close<T: Trait<I>, I: Instance>(
length: u32, // B
members: u32, // M
proposal_weight: Weight, // P1
proposals: u32, // P2
) -> Weight {
T::WeightInfo::close_early_approved(length, members, proposals)
.max(T::WeightInfo::close_early_disapproved(members, proposals))
.max(T::WeightInfo::close_approved(length, members, proposals))
.max(T::WeightInfo::close_disapproved(members, proposals))
.saturating_add(proposal_weight)
}
}

/// Return the weight of a dispatch call result as an `Option`.
///
/// Will return the weight regardless of what the state of the result is.
Expand Down Expand Up @@ -572,12 +552,17 @@ decl_module! {
// disapproved: B * 0.003 vs 0 * b
// approved: 65.95 vs 77.033
#[weight = (
weight_for::close::<T, I>(
*length_bound, // B
MAX_MEMBERS, // `M`
*proposal_weight_bound, // `P1`
T::MaxProposals::get(), // `P2`
),
{
let b = *length_bound;
let m = MAX_MEMBERS;
let p1 = *proposal_weight_bound;
let p2 = T::MaxProposals::get();
T::WeightInfo::close_early_approved(b, m, p2)
.max(T::WeightInfo::close_early_disapproved(m, p2))
.max(T::WeightInfo::close_approved(b, m, p2))
.max(T::WeightInfo::close_disapproved(m, p2))
.saturating_add(p1)
},
DispatchClass::Operational
)]
fn close(origin,
Expand Down

0 comments on commit 768a363

Please sign in to comment.