Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shawntabrizi bounty fixes #5

Merged
merged 5 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ parameter_types! {
pub const BountyDepositBase: Balance = 1 * DOLLARS;
pub const BountyDepositPayoutDelay: BlockNumber = 1 * DAYS;
pub const TreasuryModuleId: ModuleId = ModuleId(*b"py/trsry");
pub const BountyDuration: BlockNumber = 14 * DAYS;
pub const BountyUpdatePeriod: BlockNumber = 14 * DAYS;
pub const MaximumReasonLength: u32 = 16384;
pub const BountyCuratorDeposit: Permill = Permill::from_percent(50);
pub const BountyValueMinimum: Balance = 5 * DOLLARS;
Expand Down Expand Up @@ -634,7 +634,7 @@ impl pallet_treasury::Trait for Runtime {
type Burn = Burn;
type BountyDepositBase = BountyDepositBase;
type BountyDepositPayoutDelay = BountyDepositPayoutDelay;
type BountyDuration = BountyDuration;
type BountyUpdatePeriod = BountyUpdatePeriod;
type BountyCuratorDeposit = BountyCuratorDeposit;
type BountyValueMinimum = BountyValueMinimum;
type MaximumReasonLength = MaximumReasonLength;
Expand Down
44 changes: 21 additions & 23 deletions frame/treasury/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ fn create_bounty<T: Trait<I>, I: Instance>() -> Result<(
let bounty_id = BountyCount::<I>::get() - 1;
Treasury::<T, I>::approve_bounty(RawOrigin::Root.into(), bounty_id)?;
Treasury::<T, I>::on_initialize(T::BlockNumber::zero());
Treasury::<T, I>::assign_curator(RawOrigin::Root.into(), bounty_id, curator_lookup.clone(), fee)?;
Treasury::<T, I>::propose_curator(RawOrigin::Root.into(), bounty_id, curator_lookup.clone(), fee)?;
Treasury::<T, I>::accept_curator(RawOrigin::Signed(curator).into(), bounty_id)?;
Ok((curator_lookup, bounty_id))
}
Expand Down Expand Up @@ -284,19 +284,13 @@ benchmarks_instance! {
let (caller, curator, fee, value, description) = setup_bounty::<T, _>(0, d);
}: _(RawOrigin::Signed(caller), value, description)

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

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

assign_curator {
propose_curator {
setup_pod_account::<T, _>();
let (caller, curator, fee, value, reason) = setup_bounty::<T, _>(0, MAX_BYTES);
let curator_lookup = T::Lookup::unlookup(curator.clone());
Expand All @@ -306,16 +300,15 @@ benchmarks_instance! {
Treasury::<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 (caller, curator, fee, value, reason) = setup_bounty::<T, _>(0, MAX_BYTES);
let curator_lookup = T::Lookup::unlookup(curator.clone());
Treasury::<T, _>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
let bounty_id = BountyCount::<I>::get() - 1;
Treasury::<T, _>::approve_bounty(RawOrigin::Root.into(), bounty_id)?;
let (curator_lookup, bounty_id) = create_bounty::<T, _>()?;
Treasury::<T, _>::on_initialize(T::BlockNumber::zero());
Treasury::<T, _>::assign_curator(RawOrigin::Root.into(), bounty_id, curator_lookup, fee)?;
}: _(RawOrigin::Root, bounty_id)
let bounty_id = BountyCount::<I>::get() - 1;
frame_system::Module::<T>::set_block_number(T::BountyUpdatePeriod::get() + 1.into());
let caller = whitelisted_caller();
}: _(RawOrigin::Signed(caller), bounty_id)

accept_curator {
setup_pod_account::<T, _>();
Expand All @@ -325,7 +318,7 @@ benchmarks_instance! {
let bounty_id = BountyCount::<I>::get() - 1;
Treasury::<T, _>::approve_bounty(RawOrigin::Root.into(), bounty_id)?;
Treasury::<T, _>::on_initialize(T::BlockNumber::zero());
Treasury::<T, _>::assign_curator(RawOrigin::Root.into(), bounty_id, curator_lookup, fee)?;
Treasury::<T, _>::propose_curator(RawOrigin::Root.into(), bounty_id, curator_lookup, fee)?;
}: _(RawOrigin::Signed(curator), bounty_id)

award_bounty {
Expand Down Expand Up @@ -353,14 +346,19 @@ benchmarks_instance! {

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

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

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

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

extend_bounty_expiry {
setup_pod_account::<T, _>();
Expand Down Expand Up @@ -407,13 +405,13 @@ mod tests {
assert_ok!(test_benchmark_close_tip::<Test>());
assert_ok!(test_benchmark_propose_bounty::<Test>());
assert_ok!(test_benchmark_approve_bounty::<Test>());
assert_ok!(test_benchmark_reject_bounty::<Test>());
assert_ok!(test_benchmark_assign_curator::<Test>());
assert_ok!(test_benchmark_propose_curator::<Test>());
assert_ok!(test_benchmark_unassign_curator::<Test>());
assert_ok!(test_benchmark_accept_curator::<Test>());
assert_ok!(test_benchmark_award_bounty::<Test>());
assert_ok!(test_benchmark_claim_bounty::<Test>());
assert_ok!(test_benchmark_cancel_bounty::<Test>());
assert_ok!(test_benchmark_close_bounty_proposed::<Test>());
assert_ok!(test_benchmark_close_bounty_active::<Test>());
assert_ok!(test_benchmark_extend_bounty_expiry::<Test>());
assert_ok!(test_benchmark_on_initialize_proposals::<Test>());
assert_ok!(test_benchmark_on_initialize_bounties::<Test>());
Expand Down
14 changes: 7 additions & 7 deletions frame/treasury/src/default_weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,12 @@ impl crate::WeightInfo for () {
.saturating_add(DbWeight::get().reads(1 as Weight))
.saturating_add(DbWeight::get().writes(3 as Weight))
}
fn reject_bounty() -> Weight {
(47109000 as Weight)
.saturating_add(DbWeight::get().reads(1 as Weight))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
fn approve_bounty() -> Weight {
(14829000 as Weight)
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().writes(2 as Weight))
}
fn assign_curator() -> Weight {
fn propose_curator() -> Weight {
(11392000 as Weight)
.saturating_add(DbWeight::get().reads(1 as Weight))
.saturating_add(DbWeight::get().writes(1 as Weight))
Expand All @@ -107,7 +102,12 @@ impl crate::WeightInfo for () {
.saturating_add(DbWeight::get().reads(4 as Weight))
.saturating_add(DbWeight::get().writes(5 as Weight))
}
fn cancel_bounty() -> Weight {
fn close_bounty_proposed() -> Weight {
(70335000 as Weight)
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().writes(3 as Weight))
}
fn close_bounty_active() -> Weight {
(70335000 as Weight)
.saturating_add(DbWeight::get().reads(2 as Weight))
.saturating_add(DbWeight::get().writes(3 as Weight))
Expand Down
Loading