Skip to content

Commit

Permalink
Integrate pallet_bounties into runtime with configuration and depen…
Browse files Browse the repository at this point in the history
…dencies (#908)

* added config bounties

* added pallet bounties

* set timing

* Bounties can spend treasury

* only root can spend directly

* fix version and metadata

* Replace EnsureWithSuccess + EnsureRoot with EnsureRootWithSuccess

* Add block delay for bounty claim

* CouncilMajority is SpendOrigin in pallet treasury

* Solving EnsureWithSuccess compile issue

* Fix metadata golden

* Add bounties to benchmark

* use substrate weights in pallet bounties because of ED bug

---------

Co-authored-by: Tomás Senovilla Polo <tspscgs@gmail.com>
Co-authored-by: luispdm <17044119+luispdm@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 24, 2024
1 parent 35a4be1 commit 3c729b5
Show file tree
Hide file tree
Showing 9 changed files with 2,834 additions and 1,708 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ pallet-elections-phragmen = { git = "https://github.com/paritytech/polkadot-sdk"
pallet-treasury = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
pallet-collective = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
pallet-membership = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
pallet-bounties = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
pallet-transaction-payment = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
pallet-preimage = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2407", default-features = false }
Expand Down
4 changes: 4 additions & 0 deletions runtime/laos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pallet-transaction-payment-rpc-runtime-api = { workspace = true }
pallet-vesting = { workspace = true }
pallet-proxy = { workspace = true }
pallet-utility = { workspace = true }
pallet-bounties = { workspace = true }
pallet-treasury-funding = { workspace = true }
sp-api = { workspace = true }
sp-io = { workspace = true }
Expand Down Expand Up @@ -162,6 +163,7 @@ std = [
"pallet-multisig/std",
"pallet-timestamp/std",
"pallet-identity/std",
"pallet-bounties/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-vesting/std",
"pallet-precompiles-benchmark/std",
Expand Down Expand Up @@ -232,6 +234,7 @@ runtime-benchmarks = [
"pallet-multisig/runtime-benchmarks",
"pallet-democracy/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"pallet-bounties/runtime-benchmarks",
"pallet-treasury-funding/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-elections-phragmen/runtime-benchmarks",
Expand Down Expand Up @@ -276,6 +279,7 @@ try-runtime = [
"pallet-collective/try-runtime",
"pallet-membership/try-runtime",
"pallet-preimage/try-runtime",
"pallet-bounties/try-runtime",
"pallet-democracy/try-runtime",
"pallet-laos-evolution/try-runtime",
"pallet-multisig/try-runtime",
Expand Down
1 change: 1 addition & 0 deletions runtime/laos/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ frame_benchmarking::define_benchmarks!(
[pallet_democracy, Democracy]
[pallet_membership, TechnicalCommitteeMembership]
[pallet_treasury_funding, TreasuryFunding]
[pallet_bounties, Bounties]
// TODO pallet_xcm?
);
39 changes: 39 additions & 0 deletions runtime/laos/src/configs/bounties.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use crate::{
currency::{MILLIUNIT, UNIT},
Balance, BlockNumber, Runtime, RuntimeEvent, Treasury,
};
use frame_support::parameter_types;
use parachains_common::{DAYS, MINUTES};
use polkadot_runtime_common::prod_or_fast;
use sp_runtime::Permill;

parameter_types! {
pub const BountyDepositBase: Balance = UNIT;
pub const BountyDepositPayoutDelay: BlockNumber = prod_or_fast!(7 * DAYS, 5 * MINUTES);
pub const BountyUpdatePeriod: BlockNumber = prod_or_fast!(7 * DAYS, 5 * MINUTES);
pub const MaximumReasonLength: u32 = 16384;
pub const CuratorDepositMultiplier: Permill = Permill::from_percent(50);
pub const CuratorDepositMin: Balance = 10 * UNIT;
pub const CuratorDepositMax: Balance = 200 * UNIT;
pub const BountyValueMinimum: Balance = 10 * UNIT;
pub const DataDepositPerByte: Balance = 10 * MILLIUNIT;
}

impl pallet_bounties::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type BountyDepositBase = BountyDepositBase;
type BountyDepositPayoutDelay = BountyDepositPayoutDelay;
type BountyUpdatePeriod = BountyUpdatePeriod;
type CuratorDepositMultiplier = CuratorDepositMultiplier;
type CuratorDepositMin = CuratorDepositMin;
type CuratorDepositMax = CuratorDepositMax;
type BountyValueMinimum = BountyValueMinimum;
type ChildBountyManager = ();
type DataDepositPerByte = DataDepositPerByte;
type MaximumReasonLength = MaximumReasonLength;
type OnSlash = Treasury;
// TODO the benchmarks fail as they try to fund the treasury by calling:
// "Currency::minimum_balance().saturating_mul(1_000_000_000u32.into())"
// Currency::minimum_balance() returns the ED, which is 0 in our runtime
type WeightInfo = pallet_bounties::weights::SubstrateWeight<Runtime>;
}
1 change: 1 addition & 0 deletions runtime/laos/src/configs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod authorship;
mod balances;
mod base_fee;
mod benchmark;
mod bounties;
mod collective;
pub mod cumulus_parachain_system;
mod cumulus_xcmp_queue;
Expand Down
19 changes: 6 additions & 13 deletions runtime/laos/src/configs/treasury.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::collective::CouncilMajority;
use crate::{
weights, AccountId, Balance, Balances, BlockNumber, Permill, Runtime, RuntimeEvent, Treasury,
weights, AccountId, Balance, Balances, BlockNumber, Bounties, Permill, Runtime, RuntimeEvent,
Treasury,
};
use frame_support::{
parameter_types,
Expand All @@ -10,17 +11,13 @@ use frame_support::{
},
PalletId,
};
use frame_system::EnsureRoot;
use frame_system::{EnsureRoot, EnsureWithSuccess};
use parachains_common::{DAYS, MINUTES};
use polkadot_runtime_common::prod_or_fast;
use sp_runtime::traits::IdentityLookup;

#[cfg(feature = "runtime-benchmarks")]
parameter_types! {
pub const MaxBalance: Balance = Balance::MAX;
}

parameter_types! {
pub const Burn: Permill = Permill::zero();
pub const SpendPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 5 * MINUTES);
pub const MaxApprovals: u32 = 100;
Expand All @@ -30,6 +27,7 @@ parameter_types! {
}

type RejectOrigin = EitherOfDiverse<EnsureRoot<AccountId>, CouncilMajority>;
type SpendOrigin = EnsureWithSuccess<CouncilMajority, AccountId, MaxBalance>;

impl pallet_treasury::Config for Runtime {
type AssetKind = ();
Expand All @@ -45,14 +43,9 @@ impl pallet_treasury::Config for Runtime {
type PayoutPeriod = PayoutPeriod;
type RejectOrigin = RejectOrigin;
type RuntimeEvent = RuntimeEvent;
type SpendFunds = ();
type SpendFunds = Bounties;
type SpendPeriod = SpendPeriod;
// Disabled, no spending allowed.
#[cfg(not(feature = "runtime-benchmarks"))]
type SpendOrigin = frame_support::traits::NeverEnsureOrigin<Balance>;
#[cfg(feature = "runtime-benchmarks")]
type SpendOrigin =
frame_system::EnsureWithSuccess<frame_system::EnsureRoot<AccountId>, AccountId, MaxBalance>;
type SpendOrigin = SpendOrigin;
type WeightInfo = weights::pallet_treasury::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = TreasuryBenchmarkHelper;
Expand Down
1 change: 1 addition & 0 deletions runtime/laos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ construct_runtime!(
Scheduler: pallet_scheduler = 45,
Democracy: pallet_democracy = 46,
TechnicalCommitteeMembership: pallet_membership::<Instance2> = 47,
Bounties: pallet_bounties = 48,

// Frontier
Ethereum: pallet_ethereum = 50,
Expand Down
Loading

0 comments on commit 3c729b5

Please sign in to comment.