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

Commit

Permalink
fix compile for benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
shawntabrizi committed Nov 20, 2020
1 parent 0f014c4 commit 4581de9
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 73 deletions.
5 changes: 3 additions & 2 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ impl pallet_treasury::Trait for Runtime {
type Burn = Burn;
type MaximumReasonLength = MaximumReasonLength;
type BurnDestination = ();
type SpendFunds = Bounties;
type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>;
}

Expand Down Expand Up @@ -937,8 +938,8 @@ construct_runtime!(
Scheduler: pallet_scheduler::{Module, Call, Storage, Event<T>},
Proxy: pallet_proxy::{Module, Call, Storage, Event<T>},
Multisig: pallet_multisig::{Module, Call, Storage, Event<T>},
Bounties: pallet_bounties::{Module, Call, Storage, Config, Event<T>},
Tips: pallet_tips::{Module, Call, Storage, Config, Event<T>},
Bounties: pallet_bounties::{Module, Call, Storage, Event<T>},
Tips: pallet_tips::{Module, Call, Storage, Event<T>},
}
);

Expand Down
98 changes: 49 additions & 49 deletions frame/bounties/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use super::*;

use frame_system::RawOrigin;
use frame_benchmarking::{benchmarks_instance, account, whitelisted_caller};
use frame_benchmarking::{benchmarks, account, whitelisted_caller};
use frame_support::traits::OnInitialize;

use crate::Module as Bounties;
Expand All @@ -34,10 +34,10 @@ const SEED: u32 = 0;
// for i in 0 .. n {
// let (caller, _curator, _fee, value, reason) = setup_bounty::<T>(i, MAX_BYTES);
// Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
// let bounty_id = BountyCount::<I>::get() - 1;
// let bounty_id = BountyCount::get() - 1;
// Bounties::<T>::approve_bounty(RawOrigin::Root.into(), bounty_id)?;
// }
// ensure!(BountyApprovals::<I>::get().len() == n as usize, "Not all bounty approved");
// ensure!(BountyApprovals::get().len() == n as usize, "Not all bounty approved");
// Ok(())
// }

Expand All @@ -60,120 +60,120 @@ fn setup_bounty<T: Trait>(u: u32, d: u32) -> (
(caller, curator, fee, value, reason)
}

fn create_bounty<T: Trait<I>, I: Instance>() -> Result<(
fn create_bounty<T: Trait>() -> Result<(
<T::Lookup as StaticLookup>::Source,
BountyIndex,
), &'static str> {
let (caller, curator, fee, value, reason) = setup_bounty::<T>(0, MAX_BYTES);
let curator_lookup = T::Lookup::unlookup(curator.clone());
Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
let bounty_id = BountyCount::<I>::get() - 1;
let bounty_id = BountyCount::get() - 1;
Bounties::<T>::approve_bounty(RawOrigin::Root.into(), bounty_id)?;
// Bounties::<T>::on_initialize(T::BlockNumber::zero());
Bounties::<T>::propose_curator(RawOrigin::Root.into(), bounty_id, curator_lookup.clone(), fee)?;
Bounties::<T>::accept_curator(RawOrigin::Signed(curator).into(), bounty_id)?;
Ok((curator_lookup, bounty_id))
}

fn setup_pod_account<T: Trait<I>, I: Instance>() {
fn setup_pod_account<T: Trait>() {
let pot_account = Bounties::<T>::account_id();
let value = T::Currency::minimum_balance().saturating_mul(1_000_000_000u32.into());
let _ = T::Currency::make_free_balance_be(&pot_account, value);
}

const MAX_BYTES: u32 = 16384;

benchmarks_instance! {
benchmarks! {
_ { }

propose_bounty {
let d in 0 .. MAX_BYTES;

let (caller, curator, fee, value, description) = setup_bounty::<T, _>(0, d);
let (caller, curator, fee, value, description) = setup_bounty::<T>(0, d);
}: _(RawOrigin::Signed(caller), value, description)

approve_bounty {
let (caller, curator, fee, value, reason) = setup_bounty::<T, _>(0, MAX_BYTES);
Bounties::<T, _>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
let bounty_id = BountyCount::<I>::get() - 1;
let (caller, curator, fee, value, reason) = setup_bounty::<T>(0, MAX_BYTES);
Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
let bounty_id = BountyCount::get() - 1;
}: _(RawOrigin::Root, bounty_id)

propose_curator {
setup_pod_account::<T, _>();
let (caller, curator, fee, value, reason) = setup_bounty::<T, _>(0, MAX_BYTES);
setup_pod_account::<T>();
let (caller, curator, fee, value, reason) = setup_bounty::<T>(0, MAX_BYTES);
let curator_lookup = T::Lookup::unlookup(curator.clone());
Bounties::<T, _>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
let bounty_id = BountyCount::<I>::get() - 1;
Bounties::<T, _>::approve_bounty(RawOrigin::Root.into(), bounty_id)?;
Bounties::<T, _>::on_initialize(T::BlockNumber::zero());
Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
let bounty_id = BountyCount::get() - 1;
Bounties::<T>::approve_bounty(RawOrigin::Root.into(), bounty_id)?;
Bounties::<T>::on_initialize(T::BlockNumber::zero());
}: _(RawOrigin::Root, bounty_id, curator_lookup, fee)

// Worst case when curator is inactive and any sender unassigns the curator.
unassign_curator {
setup_pod_account::<T, _>();
let (curator_lookup, bounty_id) = create_bounty::<T, _>()?;
Bounties::<T, _>::on_initialize(T::BlockNumber::zero());
let bounty_id = BountyCount::<I>::get() - 1;
setup_pod_account::<T>();
let (curator_lookup, bounty_id) = create_bounty::<T>()?;
Bounties::<T>::on_initialize(T::BlockNumber::zero());
let bounty_id = BountyCount::get() - 1;
frame_system::Module::<T>::set_block_number(T::BountyUpdatePeriod::get() + 1u32.into());
let caller = whitelisted_caller();
}: _(RawOrigin::Signed(caller), bounty_id)

accept_curator {
setup_pod_account::<T, _>();
let (caller, curator, fee, value, reason) = setup_bounty::<T, _>(0, MAX_BYTES);
setup_pod_account::<T>();
let (caller, curator, fee, value, reason) = setup_bounty::<T>(0, MAX_BYTES);
let curator_lookup = T::Lookup::unlookup(curator.clone());
Bounties::<T, _>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
let bounty_id = BountyCount::<I>::get() - 1;
Bounties::<T, _>::approve_bounty(RawOrigin::Root.into(), bounty_id)?;
Bounties::<T, _>::on_initialize(T::BlockNumber::zero());
Bounties::<T, _>::propose_curator(RawOrigin::Root.into(), bounty_id, curator_lookup, fee)?;
Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
let bounty_id = BountyCount::get() - 1;
Bounties::<T>::approve_bounty(RawOrigin::Root.into(), bounty_id)?;
Bounties::<T>::on_initialize(T::BlockNumber::zero());
Bounties::<T>::propose_curator(RawOrigin::Root.into(), bounty_id, curator_lookup, fee)?;
}: _(RawOrigin::Signed(curator), bounty_id)

award_bounty {
setup_pod_account::<T, _>();
let (curator_lookup, bounty_id) = create_bounty::<T, _>()?;
Bounties::<T, _>::on_initialize(T::BlockNumber::zero());
setup_pod_account::<T>();
let (curator_lookup, bounty_id) = create_bounty::<T>()?;
Bounties::<T>::on_initialize(T::BlockNumber::zero());

let bounty_id = BountyCount::<I>::get() - 1;
let bounty_id = BountyCount::get() - 1;
let curator = T::Lookup::lookup(curator_lookup)?;
let beneficiary = T::Lookup::unlookup(account("beneficiary", 0, SEED));
}: _(RawOrigin::Signed(curator), bounty_id, beneficiary)

claim_bounty {
setup_pod_account::<T, _>();
let (curator_lookup, bounty_id) = create_bounty::<T, _>()?;
Bounties::<T, _>::on_initialize(T::BlockNumber::zero());
setup_pod_account::<T>();
let (curator_lookup, bounty_id) = create_bounty::<T>()?;
Bounties::<T>::on_initialize(T::BlockNumber::zero());

let bounty_id = BountyCount::<I>::get() - 1;
let bounty_id = BountyCount::get() - 1;
let curator = T::Lookup::lookup(curator_lookup)?;

let beneficiary = T::Lookup::unlookup(account("beneficiary", 0, SEED));
Bounties::<T, _>::award_bounty(RawOrigin::Signed(curator.clone()).into(), bounty_id, beneficiary)?;
Bounties::<T>::award_bounty(RawOrigin::Signed(curator.clone()).into(), bounty_id, beneficiary)?;

frame_system::Module::<T>::set_block_number(T::BountyDepositPayoutDelay::get());

}: _(RawOrigin::Signed(curator), bounty_id)

close_bounty_proposed {
setup_pod_account::<T, _>();
let (caller, curator, fee, value, reason) = setup_bounty::<T, _>(0, 0);
Bounties::<T, _>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
let bounty_id = BountyCount::<I>::get() - 1;
setup_pod_account::<T>();
let (caller, curator, fee, value, reason) = setup_bounty::<T>(0, 0);
Bounties::<T>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
let bounty_id = BountyCount::get() - 1;
}: close_bounty(RawOrigin::Root, bounty_id)

close_bounty_active {
setup_pod_account::<T, _>();
let (curator_lookup, bounty_id) = create_bounty::<T, _>()?;
Bounties::<T, _>::on_initialize(T::BlockNumber::zero());
let bounty_id = BountyCount::<I>::get() - 1;
setup_pod_account::<T>();
let (curator_lookup, bounty_id) = create_bounty::<T>()?;
Bounties::<T>::on_initialize(T::BlockNumber::zero());
let bounty_id = BountyCount::get() - 1;
}: close_bounty(RawOrigin::Root, bounty_id)

extend_bounty_expiry {
setup_pod_account::<T, _>();
let (curator_lookup, bounty_id) = create_bounty::<T, _>()?;
Bounties::<T, _>::on_initialize(T::BlockNumber::zero());
setup_pod_account::<T>();
let (curator_lookup, bounty_id) = create_bounty::<T>()?;
Bounties::<T>::on_initialize(T::BlockNumber::zero());

let bounty_id = BountyCount::<I>::get() - 1;
let bounty_id = BountyCount::get() - 1;
let curator = T::Lookup::lookup(curator_lookup)?;
}: _(RawOrigin::Signed(curator), bounty_id, Vec::new())

Expand Down
44 changes: 22 additions & 22 deletions frame/tips/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
use super::*;

use frame_system::RawOrigin;
use frame_benchmarking::{benchmarks_instance, account, whitelisted_caller};
use frame_benchmarking::{benchmarks, account, whitelisted_caller};
use sp_runtime::{traits::{Saturating}};

use crate::Module as TipsMod;

const SEED: u32 = 0;

// Create the pre-requisite information needed to create a `report_awesome`.
fn setup_awesome<T: Trait<I>, I: Instance>(length: u32) -> (T::AccountId, Vec<u8>, T::AccountId) {
fn setup_awesome<T: Trait>(length: u32) -> (T::AccountId, Vec<u8>, T::AccountId) {
let caller = whitelisted_caller();
let value = T::TipReportDepositBase::get()
+ T::DataDepositPerByte::get() * length.into()
Expand All @@ -42,7 +42,7 @@ fn setup_awesome<T: Trait<I>, I: Instance>(length: u32) -> (T::AccountId, Vec<u8
}

// Create the pre-requisite information needed to call `tip_new`.
fn setup_tip<T: Trait<I>, I: Instance>(r: u32, t: u32) ->
fn setup_tip<T: Trait>(r: u32, t: u32) ->
Result<(T::AccountId, Vec<u8>, T::AccountId, BalanceOf<T>), &'static str>
{
let tippers_count = T::Tippers::count();
Expand All @@ -63,46 +63,46 @@ fn setup_tip<T: Trait<I>, I: Instance>(r: u32, t: u32) ->

// Create `t` new tips for the tip proposal with `hash`.
// This function automatically makes the tip able to close.
fn create_tips<T: Trait<I>, I: Instance>(t: u32, hash: T::Hash, value: BalanceOf<T>) ->
fn create_tips<T: Trait>(t: u32, hash: T::Hash, value: BalanceOf<T>) ->
Result<(), &'static str>
{
for i in 0 .. t {
let caller = account("member", i, SEED);
ensure!(T::Tippers::contains(&caller), "caller is not a tipper");
TipsMod::<T, I>::tip(RawOrigin::Signed(caller).into(), hash, value)?;
TipsMod::<T>::tip(RawOrigin::Signed(caller).into(), hash, value)?;
}
Tips::<T, I>::mutate(hash, |maybe_tip| {
Tips::<T>::mutate(hash, |maybe_tip| {
if let Some(open_tip) = maybe_tip {
open_tip.closes = Some(T::BlockNumber::zero());
}
});
Ok(())
}

fn setup_pod_account<T: Trait<I>, I: Instance>() {
let pot_account = TipsMod::<T, I>::account_id();
fn setup_pod_account<T: Trait>() {
let pot_account = TipsMod::<T>::account_id();
let value = T::Currency::minimum_balance().saturating_mul(1_000_000_000u32.into());
let _ = T::Currency::make_free_balance_be(&pot_account, value);
}

const MAX_BYTES: u32 = 16384;
const MAX_TIPPERS: u32 = 100;

benchmarks_instance! {
benchmarks! {
_ { }

report_awesome {
let r in 0 .. MAX_BYTES;
let (caller, reason, awesome_person) = setup_awesome::<T, _>(r);
let (caller, reason, awesome_person) = setup_awesome::<T>(r);
// Whitelist caller account from further DB operations.
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller);
frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into());
}: _(RawOrigin::Signed(caller), reason, awesome_person)

retract_tip {
let r = MAX_BYTES;
let (caller, reason, awesome_person) = setup_awesome::<T, _>(r);
TipsMod::<T, _>::report_awesome(
let (caller, reason, awesome_person) = setup_awesome::<T>(r);
TipsMod::<T>::report_awesome(
RawOrigin::Signed(caller.clone()).into(),
reason.clone(),
awesome_person.clone()
Expand All @@ -118,26 +118,26 @@ benchmarks_instance! {
let r in 0 .. MAX_BYTES;
let t in 1 .. MAX_TIPPERS;

let (caller, reason, beneficiary, value) = setup_tip::<T, _>(r, t)?;
let (caller, reason, beneficiary, value) = setup_tip::<T>(r, t)?;
// Whitelist caller account from further DB operations.
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller);
frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into());
}: _(RawOrigin::Signed(caller), reason, beneficiary, value)

tip {
let t in 1 .. MAX_TIPPERS;
let (member, reason, beneficiary, value) = setup_tip::<T, _>(0, t)?;
let (member, reason, beneficiary, value) = setup_tip::<T>(0, t)?;
let value = T::Currency::minimum_balance().saturating_mul(100u32.into());
TipsMod::<T, _>::tip_new(
TipsMod::<T>::tip_new(
RawOrigin::Signed(member).into(),
reason.clone(),
beneficiary.clone(),
value
)?;
let reason_hash = T::Hashing::hash(&reason[..]);
let hash = T::Hashing::hash_of(&(&reason_hash, &beneficiary));
ensure!(Tips::<T, _>::contains_key(hash), "tip does not exist");
create_tips::<T, _>(t - 1, hash.clone(), value)?;
ensure!(Tips::<T>::contains_key(hash), "tip does not exist");
create_tips::<T>(t - 1, hash.clone(), value)?;
let caller = account("member", t - 1, SEED);
// Whitelist caller account from further DB operations.
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller);
Expand All @@ -148,12 +148,12 @@ benchmarks_instance! {
let t in 1 .. MAX_TIPPERS;

// Make sure pot is funded
setup_pod_account::<T, _>();
setup_pod_account::<T>();

// Set up a new tip proposal
let (member, reason, beneficiary, value) = setup_tip::<T, _>(0, t)?;
let (member, reason, beneficiary, value) = setup_tip::<T>(0, t)?;
let value = T::Currency::minimum_balance().saturating_mul(100u32.into());
TipsMod::<T, _>::tip_new(
TipsMod::<T>::tip_new(
RawOrigin::Signed(member).into(),
reason.clone(),
beneficiary.clone(),
Expand All @@ -163,8 +163,8 @@ benchmarks_instance! {
// Create a bunch of tips
let reason_hash = T::Hashing::hash(&reason[..]);
let hash = T::Hashing::hash_of(&(&reason_hash, &beneficiary));
ensure!(Tips::<T, _>::contains_key(hash), "tip does not exist");
create_tips::<T, _>(t, hash.clone(), value)?;
ensure!(Tips::<T>::contains_key(hash), "tip does not exist");
create_tips::<T>(t, hash.clone(), value)?;

let caller = account("caller", t, SEED);
// Whitelist caller account from further DB operations.
Expand Down

0 comments on commit 4581de9

Please sign in to comment.