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

Commit b4bf2f5

Browse files
committed
address review comments
1 parent 6223a77 commit b4bf2f5

File tree

2 files changed

+17
-32
lines changed

2 files changed

+17
-32
lines changed

frame/collective/src/benchmarking.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,12 @@ benchmarks_instance! {
287287
}
288288

289289
close_early_disapproved {
290-
let b in 1 .. MAX_BYTES;
291290
// We choose 4 as a minimum so we always trigger a vote in the voting loop (`for j in ...`)
292291
let m in 4 .. MAX_MEMBERS;
293292
let p in 1 .. T::MaxProposals::get();
294293

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

297297
// Construct `members`.
298298
let mut members = vec![];
@@ -313,7 +313,7 @@ benchmarks_instance! {
313313
let mut last_hash = T::Hash::default();
314314
for i in 0 .. p {
315315
// Proposals should be different so that different proposal hashes are generated
316-
let proposal: T::Proposal = SystemCall::<T>::remark(vec![i as u8; b as usize]).into();
316+
let proposal: T::Proposal = SystemCall::<T>::remark(vec![i as u8; bytes as usize]).into();
317317
Collective::<T, _>::propose(
318318
SystemOrigin::Signed(proposer.clone()).into(),
319319
threshold,
@@ -445,12 +445,12 @@ benchmarks_instance! {
445445
}
446446

447447
close_disapproved {
448-
let b in 1 .. MAX_BYTES;
449448
// We choose 4 as a minimum so we always trigger a vote in the voting loop (`for j in ...`)
450449
let m in 4 .. MAX_MEMBERS;
451450
let p in 1 .. T::MaxProposals::get();
452451

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

455455
// Construct `members`.
456456
let mut members = vec![];
@@ -474,7 +474,7 @@ benchmarks_instance! {
474474
let mut last_hash = T::Hash::default();
475475
for i in 0 .. p {
476476
// Proposals should be different so that different proposal hashes are generated
477-
let proposal: T::Proposal = SystemCall::<T>::remark(vec![i as u8; b as usize]).into();
477+
let proposal: T::Proposal = SystemCall::<T>::remark(vec![i as u8; bytes as usize]).into();
478478
Collective::<T, _>::propose(
479479
SystemOrigin::Signed(caller.clone()).into(),
480480
threshold,

frame/collective/src/lib.rs

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -235,26 +235,6 @@ decl_error! {
235235
}
236236
}
237237

238-
/// Functions for calcuating the weight of dispatchables.
239-
mod weight_for {
240-
use frame_support::weights::Weight;
241-
use super::{Trait, Instance, WeightInfo};
242-
243-
/// Calculate the weight for `close`.
244-
pub(crate) fn close<T: Trait<I>, I: Instance>(
245-
length: u32, // B
246-
members: u32, // M
247-
proposal_weight: Weight, // P1
248-
proposals: u32, // P2
249-
) -> Weight {
250-
T::WeightInfo::close_early_approved(length, members, proposals)
251-
.max(T::WeightInfo::close_early_disapproved(members, proposals))
252-
.max(T::WeightInfo::close_approved(length, members, proposals))
253-
.max(T::WeightInfo::close_disapproved(members, proposals))
254-
.saturating_add(proposal_weight)
255-
}
256-
}
257-
258238
/// Return the weight of a dispatch call result as an `Option`.
259239
///
260240
/// Will return the weight regardless of what the state of the result is.
@@ -572,12 +552,17 @@ decl_module! {
572552
// disapproved: B * 0.003 vs 0 * b
573553
// approved: 65.95 vs 77.033
574554
#[weight = (
575-
weight_for::close::<T, I>(
576-
*length_bound, // B
577-
MAX_MEMBERS, // `M`
578-
*proposal_weight_bound, // `P1`
579-
T::MaxProposals::get(), // `P2`
580-
),
555+
{
556+
let b = *length_bound;
557+
let m = MAX_MEMBERS;
558+
let p1 = *proposal_weight_bound;
559+
let p2 = T::MaxProposals::get();
560+
T::WeightInfo::close_early_approved(b, m, p2)
561+
.max(T::WeightInfo::close_early_disapproved(m, p2))
562+
.max(T::WeightInfo::close_approved(b, m, p2))
563+
.max(T::WeightInfo::close_disapproved(m, p2))
564+
.saturating_add(p1)
565+
},
581566
DispatchClass::Operational
582567
)]
583568
fn close(origin,

0 commit comments

Comments
 (0)