Skip to content

Commit

Permalink
Collective: Benchmark with greater MaxProposals (paritytech#12454)
Browse files Browse the repository at this point in the history
* Collective: Benchmark with greated

* fix

* remove bs

* id_to_remark_data

* fix

* remove hardcoded

* clean up

* simplify

* questionable renaming

* better variable name

* better solution

* no need for large length

* better solution

* Update frame/collective/src/benchmarking.rs

Co-authored-by: Oliver Tale-Yazdi <[email protected]>

* fix

* test

* remove test

Co-authored-by: Oliver Tale-Yazdi <[email protected]>
  • Loading branch information
2 people authored and ark0f committed Feb 27, 2023
1 parent 5e88eb4 commit 0fd5a17
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
42 changes: 20 additions & 22 deletions frame/collective/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ fn assert_last_event<T: Config<I>, I: 'static>(generic_event: <T as Config<I>>::
frame_system::Pallet::<T>::assert_last_event(generic_event.into());
}

fn id_to_remark_data(id: u32, length: usize) -> Vec<u8> {
id.to_le_bytes().into_iter().cycle().take(length).collect()
}

benchmarks_instance_pallet! {
set_members {
let m in 0 .. T::MaxMembers::get();
Expand Down Expand Up @@ -64,9 +68,7 @@ benchmarks_instance_pallet! {
let length = 100;
for i in 0 .. p {
// Proposals should be different so that different proposal hashes are generated
let proposal: T::Proposal = SystemCall::<T>::remark {
remark: vec![i as u8; length]
}.into();
let proposal: T::Proposal = SystemCall::<T>::remark { remark: id_to_remark_data(i, length) }.into();
Collective::<T, I>::propose(
SystemOrigin::Signed(old_members.last().unwrap().clone()).into(),
threshold,
Expand Down Expand Up @@ -105,7 +107,7 @@ benchmarks_instance_pallet! {
}

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

let bytes_in_storage = b + size_of::<u32>() as u32;
Expand All @@ -122,7 +124,7 @@ benchmarks_instance_pallet! {

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

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

}: _(SystemOrigin::Signed(caller), Box::new(proposal.clone()), bytes_in_storage)
verify {
Expand All @@ -135,7 +137,7 @@ benchmarks_instance_pallet! {

// This tests when execution would happen immediately after proposal
propose_execute {
let b in 1 .. MAX_BYTES;
let b in 2 .. MAX_BYTES;
let m in 1 .. T::MaxMembers::get();

let bytes_in_storage = b + size_of::<u32>() as u32;
Expand All @@ -152,7 +154,7 @@ benchmarks_instance_pallet! {

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

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

}: propose(SystemOrigin::Signed(caller), threshold, Box::new(proposal.clone()), bytes_in_storage)
Expand All @@ -166,7 +168,7 @@ benchmarks_instance_pallet! {

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

Expand All @@ -186,7 +188,7 @@ benchmarks_instance_pallet! {
// Add previous proposals.
for i in 0 .. p - 1 {
// Proposals should be different so that different proposal hashes are generated
let proposal: T::Proposal = SystemCall::<T>::remark { remark: vec![i as u8; b as usize] }.into();
let proposal: T::Proposal = SystemCall::<T>::remark { remark: id_to_remark_data(i, b as usize) }.into();
Collective::<T, I>::propose(
SystemOrigin::Signed(caller.clone()).into(),
threshold,
Expand All @@ -197,7 +199,7 @@ benchmarks_instance_pallet! {

assert_eq!(Collective::<T, I>::proposals().len(), (p - 1) as usize);

let proposal: T::Proposal = SystemCall::<T>::remark { remark: vec![p as u8; b as usize] }.into();
let proposal: T::Proposal = SystemCall::<T>::remark { remark: id_to_remark_data(p, b as usize) }.into();

}: propose(SystemOrigin::Signed(caller.clone()), threshold, Box::new(proposal.clone()), bytes_in_storage)
verify {
Expand Down Expand Up @@ -234,7 +236,7 @@ benchmarks_instance_pallet! {
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 { remark: vec![i as u8; b as usize] }.into();
let proposal: T::Proposal = SystemCall::<T>::remark { remark: id_to_remark_data(i, b as usize) }.into();
Collective::<T, I>::propose(
SystemOrigin::Signed(proposer.clone()).into(),
threshold,
Expand Down Expand Up @@ -309,9 +311,7 @@ benchmarks_instance_pallet! {
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 {
remark: vec![i as u8; bytes as usize]
}.into();
let proposal: T::Proposal = SystemCall::<T>::remark { remark: id_to_remark_data(i, bytes as usize) }.into();
Collective::<T, I>::propose(
SystemOrigin::Signed(proposer.clone()).into(),
threshold,
Expand Down Expand Up @@ -364,7 +364,7 @@ benchmarks_instance_pallet! {
}

close_early_approved {
let b in 1 .. MAX_BYTES;
let b in 2 .. 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 .. T::MaxMembers::get();
let p in 1 .. T::MaxProposals::get();
Expand All @@ -388,7 +388,7 @@ benchmarks_instance_pallet! {
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 { remark: vec![i as u8; b as usize] }.into();
let proposal: T::Proposal = SystemCall::<T>::remark { remark: id_to_remark_data(i, b as usize) }.into();
Collective::<T, I>::propose(
SystemOrigin::Signed(caller.clone()).into(),
threshold,
Expand Down Expand Up @@ -474,9 +474,7 @@ benchmarks_instance_pallet! {
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 {
remark: vec![i as u8; bytes as usize]
}.into();
let proposal: T::Proposal = SystemCall::<T>::remark { remark: id_to_remark_data(i, bytes as usize) }.into();
Collective::<T, I>::propose(
SystemOrigin::Signed(caller.clone()).into(),
threshold,
Expand Down Expand Up @@ -529,7 +527,7 @@ benchmarks_instance_pallet! {
}

close_approved {
let b in 1 .. MAX_BYTES;
let b in 2 .. 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 .. T::MaxMembers::get();
let p in 1 .. T::MaxProposals::get();
Expand Down Expand Up @@ -558,7 +556,7 @@ benchmarks_instance_pallet! {
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 { remark: vec![i as u8; b as usize] }.into();
let proposal: T::Proposal = SystemCall::<T>::remark { remark: id_to_remark_data(i, b as usize) }.into();
Collective::<T, I>::propose(
SystemOrigin::Signed(caller.clone()).into(),
threshold,
Expand Down Expand Up @@ -629,7 +627,7 @@ benchmarks_instance_pallet! {
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 { remark: vec![i as u8; b as usize] }.into();
let proposal: T::Proposal = SystemCall::<T>::remark { remark: id_to_remark_data(i, b as usize) }.into();
Collective::<T, I>::propose(
SystemOrigin::Signed(caller.clone()).into(),
threshold,
Expand Down
2 changes: 1 addition & 1 deletion frame/collective/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub type MaxMembers = ConstU32<100>;

parameter_types! {
pub const MotionDuration: u64 = 3;
pub const MaxProposals: u32 = 100;
pub const MaxProposals: u32 = 257;
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(frame_support::weights::Weight::from_ref_time(1024));
}
Expand Down

0 comments on commit 0fd5a17

Please sign in to comment.