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

Bounties #5715

Merged
116 commits merged into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
1f31ad9
add some compact annotation
xlc Apr 21, 2020
f3e7230
implement bounties for treasury
xlc Apr 21, 2020
8c16d4f
fix test build
xlc Apr 22, 2020
3efc22a
remove some duplicated code
xlc Apr 22, 2020
817770d
fix build
xlc Apr 22, 2020
a1b30c1
add tests
xlc Apr 22, 2020
5fce0d8
Merge remote-tracking branch 'origin/master' into bounty
xlc Apr 22, 2020
d143080
fix build
xlc Apr 22, 2020
3f5d446
Merge remote-tracking branch 'origin/master' into bounty
xlc Apr 23, 2020
829dc20
fix tests
xlc Apr 23, 2020
b4f86f1
Merge branch 'master' into bounty
xlc May 20, 2020
45b7717
rename
xlc May 20, 2020
d079500
merge deposit byte fee
xlc May 20, 2020
ce0bc02
add comments
xlc May 20, 2020
19f3bc3
Merge branch 'master' into bounty
xlc May 28, 2020
2e9697e
refactor storage
xlc May 28, 2020
92e8050
Merge remote-tracking branch 'origin/master' into bounty
xlc Jun 6, 2020
a5c26bb
support sub bounty
xlc Jun 6, 2020
18c9bab
emit BountyBecameActive when sub bounty is created
xlc Jun 6, 2020
e7fa5e3
able to contribute bounty
xlc Jun 6, 2020
4968e3b
allow curator to cancel bounty
xlc Jun 7, 2020
ee57848
remove bounty contribution
xlc Jun 8, 2020
0fb4ff2
implement bounty expiry
xlc Jun 8, 2020
f9901a0
Able to extend bounty
xlc Jun 8, 2020
8129646
Merge remote-tracking branch 'origin/master' into bounty
xlc Jun 21, 2020
d58794c
fix build and update tests
xlc Jun 21, 2020
d432a7a
create sub bounty test
xlc Jun 21, 2020
8141f62
add more tests
xlc Jun 21, 2020
4b1ea01
Merge remote-tracking branch 'origin/master' into bounty
xlc Jun 25, 2020
a63680c
add benchmarks for bounties
xlc Jun 28, 2020
ecb3893
Merge remote-tracking branch 'origin/master' into bounty
xlc Jun 28, 2020
b1d8d2f
fix build
xlc Jun 28, 2020
749c66b
Merge branch 'master' into bounty
xlc Jun 29, 2020
b6786e8
line width
xlc Jul 1, 2020
88c2046
fix benchmarking test
xlc Jul 1, 2020
fbc12f0
Merge remote-tracking branch 'origin/master' into bounty
xlc Jul 1, 2020
e174c98
update trait
xlc Jul 1, 2020
697c1e3
fix typo
xlc Jul 5, 2020
1bd7fc0
Merge remote-tracking branch 'origin/master' into bounty
xlc Jul 5, 2020
e1e01ee
Update lib.rs
Jul 6, 2020
afe301b
Merge remote-tracking branch 'origin/master' into bounty
xlc Jul 7, 2020
24f58bf
Merge pull request #1 from rrtti/patch-1
xlc Jul 8, 2020
dd7739b
update docs
xlc Jul 8, 2020
e8ffa3b
Merge remote-tracking branch 'origin/master' into bounty
xlc Jul 9, 2020
08065ac
add MaximumSubBountyDepth
xlc Jul 9, 2020
aacd9af
put BountyValueMinimum into storage
xlc Jul 10, 2020
c1f9900
rework bount depth
xlc Jul 11, 2020
705775d
Merge remote-tracking branch 'origin/master' into bounty
xlc Jul 14, 2020
2b8ecaa
Merge remote-tracking branch 'origin/master' into bounty
xlc Jul 21, 2020
bfae64b
split on_initialize benchmarks
shawntabrizi Jul 21, 2020
d605cb0
remove components from constant functions
shawntabrizi Jul 21, 2020
e175bc0
Update weight integration into treasury
shawntabrizi Jul 21, 2020
2ff28ee
Update reject proposal read/writes
shawntabrizi Jul 21, 2020
6a0cc13
fix weight calculation
xlc Jul 21, 2020
c222128
Ignore weights with 0 factor
shawntabrizi Jul 21, 2020
a5c897e
Remove 0 multipliers
shawntabrizi Jul 21, 2020
be92d1f
Merge remote-tracking branch 'origin/master' into bounty
xlc Jul 27, 2020
4441cdc
add some docs
xlc Jul 27, 2020
5927720
allow unused for generated code
xlc Jul 27, 2020
4b6f6e7
line width
xlc Jul 27, 2020
8a73200
allow RejectOrigin to cancel a pending payout bounty
xlc Jul 29, 2020
2ecd9f3
require BountyValueMinimum > ED
xlc Jul 29, 2020
06a305e
make BountyValueMinimum configurable by chain spec
xlc Jul 29, 2020
e86b63d
Merge remote-tracking branch 'origin/master' into bounty
xlc Aug 3, 2020
72a7a4c
remove sub-bounty features
xlc Aug 4, 2020
3c1a020
update curator
xlc Aug 4, 2020
dc8b295
accept curator
xlc Aug 7, 2020
e9b34be
unassign and cancel
xlc Aug 9, 2020
14b758a
fix tests
xlc Aug 9, 2020
ef05e56
new tests
xlc Aug 10, 2020
c32c3ca
Merge remote-tracking branch 'origin/master' into bounty
xlc Aug 10, 2020
9f87045
Update lib.rs
Aug 10, 2020
901b915
fix test
xlc Aug 10, 2020
af3931a
Merge remote-tracking branch 'origin/master' into bounty
xlc Aug 10, 2020
e3798eb
Merge pull request #4 from rrtti/patch-2
xlc Aug 10, 2020
6f40541
update extend_bounty_expiry
xlc Aug 11, 2020
6a14ec0
fix benchmarking
xlc Aug 11, 2020
3012300
add new benchmarking code
xlc Aug 11, 2020
343eb1c
add docs
xlc Aug 11, 2020
f724898
fix tests
xlc Aug 11, 2020
1f0c809
Update benchmarking.rs
shawntabrizi Aug 11, 2020
664f6e8
Make BountyValueMinimum a trait config instead of stroage value
xlc Aug 11, 2020
571059a
fix runtime build
xlc Aug 11, 2020
858a838
Update weights
shawntabrizi Aug 11, 2020
be0967e
Merge branch 'bounty' of https://github.com/laminar-protocol/substrat…
shawntabrizi Aug 12, 2020
e4dd5ff
Update default_weights.rs
shawntabrizi Aug 12, 2020
c2ee191
update weights
shawntabrizi Aug 12, 2020
a2e6306
update
xlc Aug 12, 2020
c49981c
update comments
xlc Aug 16, 2020
465aaf3
unreserve curator fee
xlc Aug 16, 2020
2d2b1a4
update tests
xlc Aug 16, 2020
363bdec
update benchmarks
xlc Aug 18, 2020
7482e59
fix curator deposit handling
xlc Aug 18, 2020
ca54bfc
Merge remote-tracking branch 'origin/master' into bounty
xlc Aug 18, 2020
58ce671
trigger CI
xlc Aug 18, 2020
31491d3
fix benchmarking
xlc Aug 19, 2020
a81e017
use append instead of mutate push
xlc Aug 19, 2020
e0d0daf
additional noop tests
shawntabrizi Aug 19, 2020
1dec474
improve fee hanlding. update event docs
xlc Aug 19, 2020
27cd80c
RejectOrigin to unassign
xlc Aug 19, 2020
85baba7
update bounty cancel logic
xlc Aug 19, 2020
05478ba
use Zero::zero() over 0.into()
xlc Aug 23, 2020
8033517
Merge remote-tracking branch 'origin/master' into bounty
xlc Aug 23, 2020
c70d864
fix tests
xlc Aug 23, 2020
76657c7
Merge remote-tracking branch 'origin/master' into bounty
xlc Sep 9, 2020
0db424e
Merge branch 'master' into bounty
xlc Sep 16, 2020
54d0bbc
fix benchmarks
xlc Sep 16, 2020
3795109
proposed fixes to bounties
shawntabrizi Sep 17, 2020
e833a53
fix tests
shawntabrizi Sep 17, 2020
e6f95c6
fix benchmarks
shawntabrizi Sep 17, 2020
0982f46
update weightinfo
shawntabrizi Sep 17, 2020
784a69a
use closure
shawntabrizi Sep 17, 2020
f645aca
Merge pull request #5 from paritytech/shawntabrizi-bounty-fixes
xlc Sep 17, 2020
7372444
fix compile
shawntabrizi Sep 18, 2020
8015965
update weights
shawntabrizi Sep 18, 2020
bb2a86f
Merge branch 'master' into pr/5715
shawntabrizi Sep 18, 2020
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
14 changes: 12 additions & 2 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,13 @@ parameter_types! {
pub const TipCountdown: BlockNumber = 1 * DAYS;
pub const TipFindersFee: Percent = Percent::from_percent(20);
pub const TipReportDepositBase: Balance = 1 * DOLLARS;
pub const TipReportDepositPerByte: Balance = 1 * CENTS;
pub const DataDepositPerByte: Balance = 1 * CENTS;
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 MaximumReasonLength: u32 = 16384;
pub const MaximumSubBountyDepth: u8 = 2;
}

impl pallet_treasury::Trait for Runtime {
Expand All @@ -594,13 +599,18 @@ impl pallet_treasury::Trait for Runtime {
type TipCountdown = TipCountdown;
type TipFindersFee = TipFindersFee;
type TipReportDepositBase = TipReportDepositBase;
type TipReportDepositPerByte = TipReportDepositPerByte;
type DataDepositPerByte = DataDepositPerByte;
type Event = Event;
type ProposalRejection = ();
type ProposalBond = ProposalBond;
type ProposalBondMinimum = ProposalBondMinimum;
type SpendPeriod = SpendPeriod;
type Burn = Burn;
type BountyDepositBase = BountyDepositBase;
type BountyDepositPayoutDelay = BountyDepositPayoutDelay;
type BountyDuration = BountyDuration;
type MaximumReasonLength = MaximumReasonLength;
type MaximumSubBountyDepth = MaximumSubBountyDepth;
type WeightInfo = ();
}

Expand Down
1 change: 1 addition & 0 deletions frame/treasury/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ std = [
runtime-benchmarks = [
"frame-benchmarking",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
179 changes: 172 additions & 7 deletions frame/treasury/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn setup_proposal<T: Trait>(u: u32) -> (
fn setup_awesome<T: Trait>(length: u32) -> (T::AccountId, Vec<u8>, T::AccountId) {
let caller = account("caller", 0, SEED);
let value = T::TipReportDepositBase::get()
+ T::TipReportDepositPerByte::get() * length.into()
+ T::DataDepositPerByte::get() * length.into()
+ T::Currency::minimum_balance();
let _ = T::Currency::make_free_balance_be(&caller, value);
let reason = vec![0; length as usize];
Expand Down Expand Up @@ -107,6 +107,77 @@ fn create_approved_proposals<T: Trait>(n: u32) -> Result<(), &'static str> {
Ok(())
}

// Create bounties that are approved for use in `on_initialize`.
fn create_approved_bounties<T: Trait>(n: u32) -> Result<(), &'static str> {
for i in 0 .. n {
let (caller, curator_lookup, fee, value, reason) = setup_bounty::<T>(i, MAX_BYTES);
Treasury::<T>::propose_bounty(RawOrigin::Signed(caller).into(), curator_lookup.clone(), fee, value, reason)?;
let bounty_id = BountyCount::get() - 1;
Treasury::<T>::approve_bounty(RawOrigin::Root.into(), bounty_id)?;
}
ensure!(BountyApprovals::get().len() == n as usize, "Not all bounty approved");
Ok(())
}

// Create the pre-requisite information needed to create a treasury `propose_bounty`.
fn setup_bounty<T: Trait>(u: u32, r: u32) -> (
T::AccountId,
<T::Lookup as StaticLookup>::Source,
BalanceOf<T>,
BalanceOf<T>,
Vec<u8>,
) {
let caller = account("caller", u, SEED);
let value: BalanceOf<T> = T::Currency::minimum_balance().saturating_mul(100.into());
let fee = T::Currency::minimum_balance().saturating_mul(2.into());
let deposit = T::BountyDepositBase::get() + T::DataDepositPerByte::get() * MAX_BYTES.into();
let _ = T::Currency::make_free_balance_be(&caller, deposit);
let curator = account("curator", u, SEED);
let curator_lookup = T::Lookup::unlookup(curator);
let reason = vec![0; r as usize];
(caller, curator_lookup, fee, value, reason)
}

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

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

fn setup_sub_bounty<T: Trait>(u: u32, r: u32) -> Result<(
T::AccountId,
<T::Lookup as StaticLookup>::Source,
BalanceOf<T>,
BalanceOf<T>,
Vec<u8>,
), &'static str> {
create_bounty::<T>(u)?;
setup_pod_account::<T>();
Treasury::<T>::on_initialize(T::BlockNumber::zero());

let caller = account("curator", u, SEED);
let value: BalanceOf<T> = T::Currency::minimum_balance().saturating_mul(50.into());
let fee = T::Currency::minimum_balance();
let deposit = T::BountyDepositBase::get() + T::DataDepositPerByte::get() * MAX_BYTES.into();
let _ = T::Currency::make_free_balance_be(&caller, deposit);
let curator = account("curator2", u, SEED);
let curator_lookup = T::Lookup::unlookup(curator);
let reason = vec![0; r as usize];
Ok((caller, curator_lookup, fee, value, reason))
}

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

Expand Down Expand Up @@ -185,9 +256,7 @@ benchmarks! {
let t in 1 .. MAX_TIPPERS;

// Make sure pot is funded
let pot_account = Treasury::<T>::account_id();
let value = T::Currency::minimum_balance().saturating_mul(1_000_000_000.into());
let _ = T::Currency::make_free_balance_be(&pot_account, value);
setup_pod_account::<T>();

// Set up a new tip proposal
let (member, reason, beneficiary, value) = setup_tip::<T>(0, t)?;
Expand All @@ -208,12 +277,99 @@ benchmarks! {
let caller = account("caller", t, SEED);
}: _(RawOrigin::Signed(caller), hash)

propose_bounty {
let u in 0 .. 1000;
let r in 0 .. MAX_BYTES;

let (caller, curator_lookup, fee, value, reason) = setup_bounty::<T>(u, r);
}: _(RawOrigin::Signed(caller), curator_lookup, fee, value, reason)

create_sub_bounty {
let u in 0 .. 1000;
let r in 0 .. MAX_BYTES;

let (caller, curator_lookup, fee, value, reason) = setup_sub_bounty::<T>(u, r)?;
let bounty_id = BountyCount::get() - 1;

}: _(RawOrigin::Signed(caller), bounty_id, curator_lookup, fee, value, reason)

approve_bounty {
let u in 0 .. 1000;

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

reject_bounty {
let u in 0 .. 1000;

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

award_bounty {
let u in 0 .. 1000;

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

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

claim_bounty {
let u in 0 .. 1000;

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

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

let beneficiary = T::Lookup::unlookup(account("beneficiary", u, SEED));
Treasury::<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)

cancel_bounty {
let u in 0 .. 1000;

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

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

extend_bounty_expiry {
let u in 0 .. 1000;

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

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

update_bounty_value_minimum {

}: _(RawOrigin::Root, 100.into())

on_initialize {
let p in 0 .. 100;
let pot_account = Treasury::<T>::account_id();
let value = T::Currency::minimum_balance().saturating_mul(1_000_000_000.into());
let _ = T::Currency::make_free_balance_be(&pot_account, value);
let q in 0 .. 100;
setup_pod_account::<T>();
create_approved_proposals::<T>(p)?;
create_approved_bounties::<T>(q)?;
}: {
Treasury::<T>::on_initialize(T::BlockNumber::zero());
}
Expand All @@ -236,6 +392,15 @@ mod tests {
assert_ok!(test_benchmark_tip_new::<Test>());
assert_ok!(test_benchmark_tip::<Test>());
assert_ok!(test_benchmark_close_tip::<Test>());
assert_ok!(test_benchmark_propose_bounty::<Test>());
assert_ok!(test_benchmark_create_sub_bounty::<Test>());
assert_ok!(test_benchmark_approve_bounty::<Test>());
assert_ok!(test_benchmark_reject_bounty::<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_extend_bounty_expiry::<Test>());
assert_ok!(test_benchmark_update_bounty_value_minimum::<Test>());
assert_ok!(test_benchmark_on_initialize::<Test>());
});
}
Expand Down
Loading