Skip to content

Commit

Permalink
treasury pallet: remove unused config parameters (#4831)
Browse files Browse the repository at this point in the history
Remove unused config parameters `ApproveOrigin` and `OnSlash` from the
treasury pallet. Add `OnSlash` config parameter to the bounties and tips
pallets.

part of #3800
  • Loading branch information
muharem authored Jun 24, 2024
1 parent 10b68db commit 5e62782
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use frame_support::{
parameter_types,
traits::{
tokens::UnityOrOuterConversion, EitherOf, EitherOfDiverse, FromContains, MapSuccess,
NeverEnsureOrigin, OriginTrait, TryWithMorphedArg,
OriginTrait, TryWithMorphedArg,
},
PalletId,
};
Expand Down Expand Up @@ -284,14 +284,6 @@ pub type FellowshipTreasuryPaymaster = PayOverXcm<
pub type FellowshipTreasuryInstance = pallet_treasury::Instance1;

impl pallet_treasury::Config<FellowshipTreasuryInstance> for Runtime {
// The creation of proposals via the treasury pallet is deprecated and should not be utilized.
// Instead, public or fellowship referenda should be used to propose and command the treasury
// spend or spend_local dispatchables. The parameters below have been configured accordingly to
// discourage its use.
// TODO: replace with `NeverEnsure` once polkadot-sdk 1.5 is released.
type ApproveOrigin = NeverEnsureOrigin<()>;
type OnSlash = ();

type WeightInfo = weights::pallet_treasury::WeightInfo<Runtime>;
type PalletId = FellowshipTreasuryPalletId;
type Currency = Balances;
Expand Down
2 changes: 0 additions & 2 deletions polkadot/runtime/common/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,8 @@ mod tests {

impl pallet_treasury::Config for Test {
type Currency = pallet_balances::Pallet<Test>;
type ApproveOrigin = frame_system::EnsureRoot<AccountId>;
type RejectOrigin = frame_system::EnsureRoot<AccountId>;
type RuntimeEvent = RuntimeEvent;
type OnSlash = ();
type SpendPeriod = ();
type Burn = ();
type BurnDestination = ();
Expand Down
3 changes: 1 addition & 2 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,10 +498,8 @@ parameter_types! {
impl pallet_treasury::Config for Runtime {
type PalletId = TreasuryPalletId;
type Currency = Balances;
type ApproveOrigin = EitherOfDiverse<EnsureRoot<AccountId>, Treasurer>;
type RejectOrigin = EitherOfDiverse<EnsureRoot<AccountId>, Treasurer>;
type RuntimeEvent = RuntimeEvent;
type OnSlash = Treasury;
type SpendPeriod = SpendPeriod;
type Burn = Burn;
type BurnDestination = Society;
Expand Down Expand Up @@ -560,6 +558,7 @@ impl pallet_bounties::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type MaximumReasonLength = MaximumReasonLength;
type WeightInfo = weights::pallet_bounties::WeightInfo<Runtime>;
type OnSlash = Treasury;
}

parameter_types! {
Expand Down
2 changes: 0 additions & 2 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,10 +683,8 @@ parameter_types! {
impl pallet_treasury::Config for Runtime {
type PalletId = TreasuryPalletId;
type Currency = Balances;
type ApproveOrigin = EitherOfDiverse<EnsureRoot<AccountId>, Treasurer>;
type RejectOrigin = EitherOfDiverse<EnsureRoot<AccountId>, Treasurer>;
type RuntimeEvent = RuntimeEvent;
type OnSlash = Treasury;
type SpendPeriod = SpendPeriod;
type Burn = Burn;
type BurnDestination = ();
Expand Down
25 changes: 25 additions & 0 deletions prdoc/pr_4831.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
title: "treasury pallet: - remove unused config parameters"

doc:
- audience: Runtime Dev
description: |
Remove unused config parameters `ApproveOrigin` and `OnSlash` from the treasury pallet.
Add `OnSlash` config parameter to the bounties and tips pallets.

crates:
- name: pallet-treasury
bump: major
- name: pallet-bounties
bump: major
- name: pallet-tips
bump: major
- name: collectives-westend-runtime
bump: patch
- name: polkadot-runtime-common
bump: patch
- name: rococo-runtime
bump: patch
- name: westend-runtime
bump: patch
- name: kitchensink-runtime
bump: patch
7 changes: 2 additions & 5 deletions substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1229,16 +1229,11 @@ parameter_types! {
impl pallet_treasury::Config for Runtime {
type PalletId = TreasuryPalletId;
type Currency = Balances;
type ApproveOrigin = EitherOfDiverse<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionAtLeast<AccountId, CouncilCollective, 3, 5>,
>;
type RejectOrigin = EitherOfDiverse<
EnsureRoot<AccountId>,
pallet_collective::EnsureProportionMoreThan<AccountId, CouncilCollective, 1, 2>,
>;
type RuntimeEvent = RuntimeEvent;
type OnSlash = ();
type SpendPeriod = SpendPeriod;
type Burn = Burn;
type BurnDestination = ();
Expand Down Expand Up @@ -1292,6 +1287,7 @@ impl pallet_bounties::Config for Runtime {
type MaximumReasonLength = MaximumReasonLength;
type WeightInfo = pallet_bounties::weights::SubstrateWeight<Runtime>;
type ChildBountyManager = ChildBounties;
type OnSlash = Treasury;
}

parameter_types! {
Expand Down Expand Up @@ -1336,6 +1332,7 @@ impl pallet_tips::Config for Runtime {
type TipReportDepositBase = TipReportDepositBase;
type MaxTipAmount = ConstU128<{ 500 * DOLLARS }>;
type WeightInfo = pallet_tips::weights::SubstrateWeight<Runtime>;
type OnSlash = Treasury;
}

parameter_types! {
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/bounties/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ benchmarks_instance_pallet! {
Bounties::<T, I>::propose_bounty(RawOrigin::Signed(caller).into(), value, reason)?;
let bounty_id = BountyCount::<T, I>::get() - 1;
let approve_origin =
T::ApproveOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
T::RejectOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
}: close_bounty<T::RuntimeOrigin>(approve_origin, bounty_id)

close_bounty_active {
Expand All @@ -186,7 +186,7 @@ benchmarks_instance_pallet! {
Treasury::<T, I>::on_initialize(BlockNumberFor::<T>::zero());
let bounty_id = BountyCount::<T, I>::get() - 1;
let approve_origin =
T::ApproveOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
T::RejectOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
}: close_bounty<T::RuntimeOrigin>(approve_origin, bounty_id)
verify {
assert_last_event::<T, I>(Event::BountyCanceled { index: bounty_id }.into())
Expand Down
3 changes: 3 additions & 0 deletions substrate/frame/bounties/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ pub mod pallet {

/// The child bounty manager.
type ChildBountyManager: ChildBountyManager<BalanceOf<Self, I>>;

/// Handler for the unbalanced decrease when slashing for a rejected bounty.
type OnSlash: OnUnbalanced<pallet_treasury::NegativeImbalanceOf<Self, I>>;
}

#[pallet::error]
Expand Down
6 changes: 2 additions & 4 deletions substrate/frame/bounties/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ parameter_types! {
impl pallet_treasury::Config for Test {
type PalletId = TreasuryPalletId;
type Currency = pallet_balances::Pallet<Test>;
type ApproveOrigin = frame_system::EnsureRoot<u128>;
type RejectOrigin = frame_system::EnsureRoot<u128>;
type RuntimeEvent = RuntimeEvent;
type OnSlash = ();
type SpendPeriod = ConstU64<2>;
type Burn = Burn;
type BurnDestination = (); // Just gets burned.
Expand All @@ -107,10 +105,8 @@ impl pallet_treasury::Config for Test {
impl pallet_treasury::Config<Instance1> for Test {
type PalletId = TreasuryPalletId2;
type Currency = pallet_balances::Pallet<Test>;
type ApproveOrigin = frame_system::EnsureRoot<u128>;
type RejectOrigin = frame_system::EnsureRoot<u128>;
type RuntimeEvent = RuntimeEvent;
type OnSlash = ();
type SpendPeriod = ConstU64<2>;
type Burn = Burn;
type BurnDestination = (); // Just gets burned.
Expand Down Expand Up @@ -149,6 +145,7 @@ impl Config for Test {
type MaximumReasonLength = ConstU32<16384>;
type WeightInfo = ();
type ChildBountyManager = ();
type OnSlash = ();
}

impl Config<Instance1> for Test {
Expand All @@ -164,6 +161,7 @@ impl Config<Instance1> for Test {
type MaximumReasonLength = ConstU32<16384>;
type WeightInfo = ();
type ChildBountyManager = ();
type OnSlash = ();
}

type TreasuryError = pallet_treasury::Error<Test>;
Expand Down
3 changes: 1 addition & 2 deletions substrate/frame/child-bounties/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ parameter_types! {
impl pallet_treasury::Config for Test {
type PalletId = TreasuryPalletId;
type Currency = pallet_balances::Pallet<Test>;
type ApproveOrigin = frame_system::EnsureRoot<u128>;
type RejectOrigin = frame_system::EnsureRoot<u128>;
type RuntimeEvent = RuntimeEvent;
type OnSlash = ();
type SpendPeriod = ConstU64<2>;
type Burn = Burn;
type BurnDestination = ();
Expand Down Expand Up @@ -123,6 +121,7 @@ impl pallet_bounties::Config for Test {
type MaximumReasonLength = ConstU32<300>;
type WeightInfo = ();
type ChildBountyManager = ChildBounties;
type OnSlash = ();
}
impl pallet_child_bounties::Config for Test {
type RuntimeEvent = RuntimeEvent;
Expand Down
3 changes: 3 additions & 0 deletions substrate/frame/tips/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ pub mod pallet {
/// update weights file when altering this method.
type Tippers: SortedMembers<Self::AccountId> + ContainsLengthBound;

/// Handler for the unbalanced decrease when slashing for a removed tip.
type OnSlash: OnUnbalanced<NegativeImbalanceOf<Self, I>>;

/// Weight information for extrinsics in this pallet.
type WeightInfo: WeightInfo;
}
Expand Down
6 changes: 2 additions & 4 deletions substrate/frame/tips/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,8 @@ parameter_types! {
impl pallet_treasury::Config for Test {
type PalletId = TreasuryPalletId;
type Currency = pallet_balances::Pallet<Test>;
type ApproveOrigin = frame_system::EnsureRoot<u128>;
type RejectOrigin = frame_system::EnsureRoot<u128>;
type RuntimeEvent = RuntimeEvent;
type OnSlash = ();
type SpendPeriod = ConstU64<2>;
type Burn = Burn;
type BurnDestination = (); // Just gets burned.
Expand All @@ -128,10 +126,8 @@ impl pallet_treasury::Config for Test {
impl pallet_treasury::Config<Instance1> for Test {
type PalletId = TreasuryPalletId2;
type Currency = pallet_balances::Pallet<Test>;
type ApproveOrigin = frame_system::EnsureRoot<u128>;
type RejectOrigin = frame_system::EnsureRoot<u128>;
type RuntimeEvent = RuntimeEvent;
type OnSlash = ();
type SpendPeriod = ConstU64<2>;
type Burn = Burn;
type BurnDestination = (); // Just gets burned.
Expand Down Expand Up @@ -162,6 +158,7 @@ impl Config for Test {
type DataDepositPerByte = ConstU64<1>;
type MaxTipAmount = ConstU64<10_000_000>;
type RuntimeEvent = RuntimeEvent;
type OnSlash = ();
type WeightInfo = ();
}

Expand All @@ -174,6 +171,7 @@ impl Config<Instance1> for Test {
type DataDepositPerByte = ConstU64<1>;
type MaxTipAmount = ConstU64<10_000_000>;
type RuntimeEvent = RuntimeEvent;
type OnSlash = ();
type WeightInfo = ();
}

Expand Down
6 changes: 0 additions & 6 deletions substrate/frame/treasury/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,13 @@ pub mod pallet {
/// The staking balance.
type Currency: Currency<Self::AccountId> + ReservableCurrency<Self::AccountId>;

/// Origin from which approvals must come.
type ApproveOrigin: EnsureOrigin<Self::RuntimeOrigin>;

/// Origin from which rejections must come.
type RejectOrigin: EnsureOrigin<Self::RuntimeOrigin>;

/// The overarching event type.
type RuntimeEvent: From<Event<Self, I>>
+ IsType<<Self as frame_system::Config>::RuntimeEvent>;

/// Handler for the unbalanced decrease when slashing for a rejected proposal or bounty.
type OnSlash: OnUnbalanced<NegativeImbalanceOf<Self, I>>;

/// Period between successive spends.
#[pallet::constant]
type SpendPeriod: Get<BlockNumberFor<Self>>;
Expand Down
2 changes: 0 additions & 2 deletions substrate/frame/treasury/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,8 @@ impl<N: Get<u64>> ConversionFromAssetBalance<u64, u32, u64> for MulBy<N> {
impl Config for Test {
type PalletId = TreasuryPalletId;
type Currency = pallet_balances::Pallet<Test>;
type ApproveOrigin = frame_system::EnsureRoot<u128>;
type RejectOrigin = frame_system::EnsureRoot<u128>;
type RuntimeEvent = RuntimeEvent;
type OnSlash = ();
type SpendPeriod = ConstU64<2>;
type Burn = Burn;
type BurnDestination = (); // Just gets burned.
Expand Down

0 comments on commit 5e62782

Please sign in to comment.