Skip to content

Commit

Permalink
Add bounties pallet to runtime (#776)
Browse files Browse the repository at this point in the history
* Add bounties pallet to runtime

* Add weights for pallet_bounties.

* Fix clippy issues

* Add pallet_bounties in scripts/benchmarks/configuration.sh
  • Loading branch information
vivekvpandya committed Oct 6, 2022
1 parent cb21725 commit b1c5143
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions runtime/battery-station/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ orml-currencies = { branch = "2022-06-v0.9.19", default-features = false, git =
orml-tokens = { branch = "2022-06-v0.9.19", default-features = false, git = "https://github.com/zeitgeistpm/open-runtime-module-library" }
orml-traits = { branch = "2022-06-v0.9.19", default-features = false, git = "https://github.com/zeitgeistpm/open-runtime-module-library" }
pallet-balances = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/substrate" }
pallet-bounties = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/substrate" }
pallet-collective = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/substrate" }
pallet-democracy = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/substrate" }
pallet-identity = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/substrate" }
Expand Down Expand Up @@ -155,6 +156,7 @@ runtime-benchmarks = [
"pallet-author-mapping/runtime-benchmarks",
"pallet-author-slot-filter/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-bounties/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
"pallet-crowdloan-rewards/runtime-benchmarks",
"pallet-democracy/runtime-benchmarks",
Expand Down Expand Up @@ -193,6 +195,7 @@ std = [
"orml-tokens/std",
"orml-traits/std",
"pallet-balances/std",
"pallet-bounties/std",
"pallet-collective/std",
"pallet-democracy/std",
"pallet-identity/std",
Expand Down Expand Up @@ -294,6 +297,7 @@ try-runtime = [

# Money runtime pallets
"pallet-balances/try-runtime",
"pallet-bounties/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-treasury/try-runtime",
"pallet-vesting/try-runtime",
Expand Down
29 changes: 29 additions & 0 deletions runtime/battery-station/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,35 @@ parameter_types! {
/// Pallet identifier, mainly used for named balance reserves.
pub const TreasuryPalletId: PalletId = PalletId(*b"zge/tsry");

// Bounties
/// The amount held on deposit for placing a bounty proposal.
pub const BountyDepositBase: Balance = 100 * BASE;
/// The delay period that a bounty beneficiary needs to wait before being able to claim the payout.
pub const BountyDepositPayoutDelay: BlockNumber = 3 * BLOCKS_PER_DAY;

/// Bounty duration in blocks.
pub const BountyUpdatePeriod: BlockNumber = 35 * BLOCKS_PER_DAY;

/// The curator deposit is calculated as a percentage of the curator fee.
///
/// This deposit has optional upper and lower bounds with `CuratorDepositMax` and
/// `CuratorDepositMin`.
pub const CuratorDepositMultiplier: Permill = Permill::from_percent(50);

/// Maximum amount of funds that should be placed in a deposit for making a proposal.
pub const CuratorDepositMax: Balance = 500 * BASE;
/// Minimum amount of funds that should be placed in a deposit for making a proposal.
pub const CuratorDepositMin: Balance = 10 * BASE;
/// Minimum value for a bounty.
pub const BountyValueMinimum: Balance = 50 * BASE;

/// The amount held on deposit per byte within the tip report reason or bounty description.
pub DataDepositPerByte: Balance = BASE;
/// Maximum acceptable reason length.
///
/// Benchmarks depend on this value, be sure to update weights file when changing this value
pub MaximumReasonLength: u32 = 8192;

// Vesting
pub const MinVestedTransfer: Balance = ExistentialDeposit::get();
}
Expand Down
1 change: 1 addition & 0 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ orml-tokens = { branch = "2022-06-v0.9.19", default-features = false, git = "htt
pallet-author-mapping = { rev = "78db06c0203f61b35059304f7194ed5c10dcfda8", default-features = false, git = "https://github.com/purestake/moonbeam", optional = true }
pallet-author-slot-filter = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/nimbus", optional = true }
pallet-balances = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/substrate" }
pallet-bounties = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/substrate" }
pallet-collective = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/substrate" }
pallet-democracy = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/substrate" }
pallet-identity = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/substrate" }
Expand Down
20 changes: 19 additions & 1 deletion runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ macro_rules! create_runtime {
Treasury: pallet_treasury::{Call, Config, Event<T>, Pallet, Storage} = 12,
Vesting: pallet_vesting::{Call, Config<T>, Event<T>, Pallet, Storage} = 13,
MultiSig: pallet_multisig::{Call, Event<T>, Pallet, Storage} = 14,
Bounties: pallet_bounties::{Call, Event<T>, Pallet, Storage} = 15,

// Governance
Democracy: pallet_democracy::{Pallet, Call, Storage, Config<T>, Event<T>} = 20,
Expand Down Expand Up @@ -809,11 +810,26 @@ macro_rules! impl_config_traits {
type ProposalBondMinimum = ProposalBondMinimum;
type ProposalBondMaximum = ProposalBondMaximum;
type RejectOrigin = EnsureRootOrTwoThirdsCouncil;
type SpendFunds = ();
type SpendFunds = Bounties;
type SpendPeriod = SpendPeriod;
type WeightInfo = weights::pallet_treasury::WeightInfo<Runtime>;
}

impl pallet_bounties::Config for Runtime {
type BountyDepositBase = BountyDepositBase;
type BountyDepositPayoutDelay = BountyDepositPayoutDelay;
type BountyUpdatePeriod = BountyUpdatePeriod;
type BountyValueMinimum = BountyValueMinimum;
type ChildBountyManager = ();
type CuratorDepositMax = CuratorDepositMax;
type CuratorDepositMin = CuratorDepositMin;
type CuratorDepositMultiplier = CuratorDepositMultiplier;
type DataDepositPerByte = DataDepositPerByte;
type Event = Event;
type MaximumReasonLength = MaximumReasonLength;
type WeightInfo = weights::pallet_bounties::WeightInfo<Runtime>;
}

impl pallet_utility::Config for Runtime {
type Event = Event;
type Call = Call;
Expand Down Expand Up @@ -1081,6 +1097,7 @@ macro_rules! create_runtime_api {
orml_list_benchmark!(list, extra, orml_currencies, crate::benchmarks::currencies);
orml_list_benchmark!(list, extra, orml_tokens, crate::benchmarks::tokens);
list_benchmark!(list, extra, pallet_balances, Balances);
list_benchmark!(list, extra, pallet_bounties, Bounties);
list_benchmark!(list, extra, pallet_collective, AdvisoryCommittee);
list_benchmark!(list, extra, pallet_democracy, Democracy);
list_benchmark!(list, extra, pallet_identity, Identity);
Expand Down Expand Up @@ -1155,6 +1172,7 @@ macro_rules! create_runtime_api {
orml_add_benchmark!(params, batches, orml_currencies, crate::benchmarks::currencies);
orml_add_benchmark!(params, batches, orml_tokens, crate::benchmarks::tokens);
add_benchmark!(params, batches, pallet_balances, Balances);
add_benchmark!(params, batches, pallet_bounties, Bounties);
add_benchmark!(params, batches, pallet_collective, AdvisoryCommittee);
add_benchmark!(params, batches, pallet_democracy, Democracy);
add_benchmark!(params, batches, pallet_identity, Identity);
Expand Down
1 change: 1 addition & 0 deletions runtime/common/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub mod frame_system;
pub mod orml_currencies;
pub mod orml_tokens;
pub mod pallet_balances;
pub mod pallet_bounties;
pub mod pallet_collective;
pub mod pallet_democracy;
pub mod pallet_identity;
Expand Down
116 changes: 116 additions & 0 deletions runtime/common/src/weights/pallet_bounties.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
//! Autogenerated weights for pallet_bounties
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2022-08-31, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024

// Executed Command:
// ./target/release/zeitgeist
// benchmark
// pallet
// --chain=dev
// --steps=50
// --repeat=20
// --pallet=pallet_bounties
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
// --heap-pages=4096
// --template=./misc/frame_weight_template.hbs
// --output=./runtime/common/src/weights/

#![allow(unused_parens)]
#![allow(unused_imports)]

use core::marker::PhantomData;
use frame_support::{
traits::Get,
weights::{constants::RocksDbWeight, Weight},
};

/// Weight functions for pallet_bounties (automatically generated)
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_bounties::weights::WeightInfo for WeightInfo<T> {
// Storage: Bounties BountyCount (r:1 w:1)
// Storage: Bounties BountyDescriptions (r:0 w:1)
// Storage: Bounties Bounties (r:0 w:1)
fn propose_bounty(d: u32) -> Weight {
(20_068_000 as Weight)
// Standard Error: 0
.saturating_add((1_000 as Weight).saturating_mul(d as Weight))
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(3 as Weight))
}
// Storage: Bounties Bounties (r:1 w:1)
// Storage: Bounties BountyApprovals (r:1 w:1)
fn approve_bounty() -> Weight {
(5_712_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: Bounties Bounties (r:1 w:1)
fn propose_curator() -> Weight {
(4_147_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Bounties Bounties (r:1 w:1)
// Storage: System Account (r:1 w:1)
fn unassign_curator() -> Weight {
(23_050_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: Bounties Bounties (r:1 w:1)
// Storage: System Account (r:1 w:1)
fn accept_curator() -> Weight {
(17_347_000 as Weight)
.saturating_add(T::DbWeight::get().reads(2 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: Bounties Bounties (r:1 w:1)
fn award_bounty() -> Weight {
(12_240_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Bounties Bounties (r:1 w:1)
// Storage: System Account (r:3 w:3)
// Storage: Bounties BountyDescriptions (r:0 w:1)
fn claim_bounty() -> Weight {
(54_625_000 as Weight)
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(5 as Weight))
}
// Storage: Bounties Bounties (r:1 w:1)
// Storage: Bounties BountyDescriptions (r:0 w:1)
fn close_bounty_proposed() -> Weight {
(22_075_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
// Storage: Bounties Bounties (r:1 w:1)
// Storage: System Account (r:3 w:3)
// Storage: Bounties BountyDescriptions (r:0 w:1)
fn close_bounty_active() -> Weight {
(39_006_000 as Weight)
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(5 as Weight))
}
// Storage: Bounties Bounties (r:1 w:1)
fn extend_bounty_expiry() -> Weight {
(11_908_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: Bounties BountyApprovals (r:1 w:1)
// Storage: Bounties Bounties (r:1 w:1)
// Storage: System Account (r:1 w:1)
fn spend_funds(b: u32) -> Weight {
(6_737_000 as Weight)
// Standard Error: 12_000
.saturating_add((26_347_000 as Weight).saturating_mul(b as Weight))
.saturating_add(T::DbWeight::get().reads((3 as Weight).saturating_mul(b as Weight)))
.saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(b as Weight)))
}
}
4 changes: 4 additions & 0 deletions runtime/zeitgeist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ orml-currencies = { branch = "2022-06-v0.9.19", default-features = false, git =
orml-tokens = { branch = "2022-06-v0.9.19", default-features = false, git = "https://github.com/zeitgeistpm/open-runtime-module-library" }
orml-traits = { branch = "2022-06-v0.9.19", default-features = false, git = "https://github.com/zeitgeistpm/open-runtime-module-library" }
pallet-balances = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/substrate" }
pallet-bounties = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/substrate" }
pallet-collective = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/substrate" }
pallet-democracy = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/substrate" }
pallet-identity = { branch = "moonbeam-polkadot-v0.9.19", default-features = false, git = "https://github.com/purestake/substrate" }
Expand Down Expand Up @@ -154,6 +155,7 @@ runtime-benchmarks = [
"pallet-author-mapping/runtime-benchmarks",
"pallet-author-slot-filter/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-bounties/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
"pallet-crowdloan-rewards/runtime-benchmarks",
"pallet-democracy/runtime-benchmarks",
Expand Down Expand Up @@ -192,6 +194,7 @@ std = [
"orml-tokens/std",
"orml-traits/std",
"pallet-balances/std",
"pallet-bounties/std",
"pallet-collective/std",
"pallet-democracy/std",
"pallet-identity/std",
Expand Down Expand Up @@ -292,6 +295,7 @@ try-runtime = [

# Money runtime pallets
"pallet-balances/try-runtime",
"pallet-bounties/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-treasury/try-runtime",
"pallet-vesting/try-runtime",
Expand Down
29 changes: 29 additions & 0 deletions runtime/zeitgeist/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,35 @@ parameter_types! {
/// Pallet identifier, mainly used for named balance reserves. DO NOT CHANGE.
pub const TreasuryPalletId: PalletId = PalletId(*b"zge/tsry");

// Bounties
/// The amount held on deposit for placing a bounty proposal.
pub const BountyDepositBase: Balance = 100 * BASE;
/// The delay period that a bounty beneficiary needs to wait before being able to claim the payout.
pub const BountyDepositPayoutDelay: BlockNumber = 3 * BLOCKS_PER_DAY;

/// Bounty duration in blocks.
pub const BountyUpdatePeriod: BlockNumber = 35 * BLOCKS_PER_DAY;

/// The curator deposit is calculated as a percentage of the curator fee.
///
/// This deposit has optional upper and lower bounds with `CuratorDepositMax` and
/// `CuratorDepositMin`.
pub const CuratorDepositMultiplier: Permill = Permill::from_percent(50);

/// Maximum amount of funds that should be placed in a deposit for making a proposal.
pub const CuratorDepositMax: Balance = 500 * BASE;
/// Minimum amount of funds that should be placed in a deposit for making a proposal.
pub const CuratorDepositMin: Balance = 10 * BASE;
/// Minimum value for a bounty.
pub const BountyValueMinimum: Balance = 50 * BASE;

/// The amount held on deposit per byte within the tip report reason or bounty description.
pub DataDepositPerByte: Balance = BASE;
/// Maximum acceptable reason length.
///
/// Benchmarks depend on this value, be sure to update weights file when changing this value
pub MaximumReasonLength: u32 = 8192;

// Vesting
pub const MinVestedTransfer: Balance = ExistentialDeposit::get();
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/benchmarks/configuration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
EXTERNAL_WEIGHTS_PATH="./runtime/common/src/weights/"

# This script contains the configuration for other benchmarking scripts.
export FRAME_PALLETS=( frame_system pallet_balances pallet_democracy \
export FRAME_PALLETS=( frame_system pallet_balances pallet_bounties pallet_democracy \
pallet_identity pallet_membership pallet_multisig pallet_preimage \
pallet_proxy pallet_scheduler pallet_timestamp pallet_treasury \
pallet_utility pallet_vesting \
Expand All @@ -26,4 +26,4 @@ export ORML_WEIGHT_TEMPLATE="./misc/orml_weight_template.hbs"
export ZEITGEIST_PALLETS=( zrml_authorized zrml_court zrml_liquidity_mining zrml_prediction_markets zrml_swaps zrml_styx )
export ZEITGEIST_PALLETS_RUNS=1000
export ZEITGEIST_PALLETS_STEPS=10
export ZEITGEIST_WEIGHT_TEMPLATE="./misc/weight_template.hbs"
export ZEITGEIST_WEIGHT_TEMPLATE="./misc/weight_template.hbs"

0 comments on commit b1c5143

Please sign in to comment.