Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d579b67
Remove deprecated treasury pallet calls
chungquantin Mar 25, 2024
1a3d5f1
Update benchmarking.rs
chungquantin Mar 25, 2024
3d26a92
Remove unused ProposalBond parameter
chungquantin Mar 25, 2024
2f1c632
Remove OnSlash parameter
chungquantin Mar 25, 2024
2243192
Update proposal invariant tests
chungquantin Mar 26, 2024
903b620
Code explicit indexes to event and error enum
chungquantin Mar 26, 2024
2e8b334
Hotfix codec indexes
chungquantin Mar 26, 2024
f9b82de
Remove explicit coded indexes
chungquantin Mar 26, 2024
8f74134
Remove deprecated weight functions
chungquantin Mar 27, 2024
496d034
Merge branch 'master' into chungquantin/remove_treasury_deprecated_calls
chungquantin Mar 29, 2024
4a9d17a
Merge branch 'master' into chungquantin/remove_treasury_deprecated_calls
chungquantin Apr 15, 2024
3632701
Update prdoc message
chungquantin Apr 15, 2024
062d1f3
Merge branch 'chungquantin/remove_treasury_deprecated_calls' of https…
chungquantin Apr 15, 2024
c368de8
Update deprecated treasury pallet code in the
chungquantin Apr 17, 2024
f42fd02
Move ApproveOrigin from treasury to bounty config
chungquantin Apr 17, 2024
ea5ba72
Update child bounties and tip pallet
chungquantin Apr 17, 2024
a03e77d
Merge branch 'master' into chungquantin/remove_treasury_deprecated_calls
chungquantin Apr 18, 2024
4031443
Fix wording
chungquantin Apr 18, 2024
40518af
Merge branch 'master' into chungquantin/remove_treasury_deprecated_calls
chungquantin May 19, 2024
fb2afc2
Revert the type parameter changes of treasury
chungquantin May 19, 2024
1837fdd
Merge pull request #3 from openguild-labs/chungquantin/deprecated_tre…
chungquantin May 19, 2024
3995795
Remove ProposalBond related parameters
chungquantin May 27, 2024
cd6e092
Merge branch 'master' into chungquantin/remove_treasury_deprecated_calls
chungquantin May 27, 2024
f692eaf
Reformat
chungquantin May 27, 2024
1bdc38d
Update pr_3820.prdoc
chungquantin May 27, 2024
5622161
Remove unused variables in westend runtime benchmarks
chungquantin Jun 3, 2024
f2e04f8
Merge branch 'master' into chungquantin/remove_treasury_deprecated_calls
chungquantin Jun 3, 2024
432a110
Update bump attribute for updated pallet crates
chungquantin Jun 14, 2024
ca49d52
Refromat prdoc
chungquantin Jun 14, 2024
e911eb6
update prdoc bump for relevant crates
chungquantin Jun 14, 2024
4eb538c
Revert doc changes and update setup_proposal
chungquantin Jun 16, 2024
ee8bdb2
fix prdoc
chungquantin Jun 16, 2024
3b2ae66
revert missing doc
chungquantin Jun 17, 2024
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
12 changes: 12 additions & 0 deletions prdoc/pr_3800.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Remove deprecated calls from treasury pallet

doc:
- audience: Runtime Dev
description: |
This PR remove deprecated calls, relevant tests from `pallet-treasury`

crates:
- name: pallet-treasury
14 changes: 11 additions & 3 deletions substrate/frame/treasury/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ and use the funds to pay developers.
### Dispatchable Functions

General spending/proposal protocol:
- `propose_spend` - Make a spending proposal and stake the required deposit.
- `reject_proposal` - Reject a proposal, slashing the deposit.
- `approve_proposal` - Accept the proposal, returning the deposit.
- `spend_local` - Propose and approve a spend of treasury funds, enables the
creation of spends using the native currency of the chain, utilizing the funds
stored in the pot
- `spend` - Propose and approve a spend of treasury funds, allows spending any
asset kind managed by the treasury
- `remove_approval` - Force a previously approved proposal to be removed from
the approval queue
- `payout` - Claim a spend
- `check_status` - Check the status of the spend and remove it from the storage
if processed
- `void_spend` - Void previously approved spend
78 changes: 9 additions & 69 deletions substrate/frame/treasury/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ where

const SEED: u32 = 0;

// Create the pre-requisite information needed to create a treasury `propose_spend`.
// Create the pre-requisite information needed to create a treasury `spend_local`.
fn setup_proposal<T: Config<I>, I: 'static>(
u: u32,
) -> (T::AccountId, BalanceOf<T, I>, AccountIdLookupOf<T>) {
let caller = account("caller", u, SEED);
let value: BalanceOf<T, I> = T::ProposalBondMinimum::get().saturating_mul(100u32.into());
let value: BalanceOf<T, I> = 100u32.try_into().ok().unwrap();
let _ = T::Currency::make_free_balance_be(&caller, value);
let beneficiary = account("beneficiary", u, SEED);
let beneficiary_lookup = T::Lookup::unlookup(beneficiary);
Expand All @@ -73,12 +73,10 @@ fn setup_proposal<T: Config<I>, I: 'static>(

// Create proposals that are approved for use in `on_initialize`.
fn create_approved_proposals<T: Config<I>, I: 'static>(n: u32) -> Result<(), &'static str> {
let origin = T::SpendOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
for i in 0..n {
let (caller, value, lookup) = setup_proposal::<T, I>(i);
#[allow(deprecated)]
Treasury::<T, I>::propose_spend(RawOrigin::Signed(caller).into(), value, lookup)?;
let proposal_id = <ProposalCount<T, I>>::get() - 1;
Approvals::<T, I>::try_append(proposal_id).unwrap();
let (_, value, lookup) = setup_proposal::<T, I>(i);
Treasury::<T, I>::spend_local(origin.clone(), value, lookup)?;
}
ensure!(<Approvals<T, I>>::get().len() == n as usize, "Not all approved");
Ok(())
Expand Down Expand Up @@ -126,71 +124,13 @@ mod benchmarks {
Ok(())
}

#[benchmark]
fn propose_spend() -> Result<(), BenchmarkError> {
let (caller, value, beneficiary_lookup) = setup_proposal::<T, _>(SEED);
// Whitelist caller account from further DB operations.
let caller_key = frame_system::Account::<T>::hashed_key_for(&caller);
frame_benchmarking::benchmarking::add_to_whitelist(caller_key.into());

#[extrinsic_call]
_(RawOrigin::Signed(caller), value, beneficiary_lookup);

Ok(())
}

#[benchmark]
fn reject_proposal() -> Result<(), BenchmarkError> {
let (caller, value, beneficiary_lookup) = setup_proposal::<T, _>(SEED);
#[allow(deprecated)]
Treasury::<T, _>::propose_spend(
RawOrigin::Signed(caller).into(),
value,
beneficiary_lookup,
)?;
let proposal_id = Treasury::<T, _>::proposal_count() - 1;
let reject_origin =
T::RejectOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;

#[extrinsic_call]
_(reject_origin as T::RuntimeOrigin, proposal_id);

Ok(())
}

#[benchmark]
fn approve_proposal(
p: Linear<0, { T::MaxApprovals::get() - 1 }>,
) -> Result<(), BenchmarkError> {
let approve_origin =
T::ApproveOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
create_approved_proposals::<T, _>(p)?;
let (caller, value, beneficiary_lookup) = setup_proposal::<T, _>(SEED);
#[allow(deprecated)]
Treasury::<T, _>::propose_spend(
RawOrigin::Signed(caller).into(),
value,
beneficiary_lookup,
)?;
let proposal_id = Treasury::<T, _>::proposal_count() - 1;

#[extrinsic_call]
_(approve_origin as T::RuntimeOrigin, proposal_id);

Ok(())
}

#[benchmark]
fn remove_approval() -> Result<(), BenchmarkError> {
let (caller, value, beneficiary_lookup) = setup_proposal::<T, _>(SEED);
#[allow(deprecated)]
Treasury::<T, _>::propose_spend(
RawOrigin::Signed(caller).into(),
value,
beneficiary_lookup,
)?;
let origin =
T::SpendOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let (_, value, beneficiary_lookup) = setup_proposal::<T, _>(SEED);
Treasury::<T, _>::spend_local(origin, value, beneficiary_lookup)?;
let proposal_id = Treasury::<T, _>::proposal_count() - 1;
Approvals::<T, _>::try_append(proposal_id).unwrap();
let reject_origin =
T::RejectOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;

Expand Down
151 changes: 0 additions & 151 deletions substrate/frame/treasury/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,32 +203,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>>;

/// Fraction of a proposal's value that should be bonded in order to place the proposal.
/// An accepted proposal gets these back. A rejected proposal does not.
#[pallet::constant]
type ProposalBond: Get<Permill>;

/// Minimum amount of funds that should be placed in a deposit for making a proposal.
#[pallet::constant]
type ProposalBondMinimum: Get<BalanceOf<Self, I>>;

/// Maximum amount of funds that should be placed in a deposit for making a proposal.
#[pallet::constant]
type ProposalBondMaximum: Get<Option<BalanceOf<Self, I>>>;

/// Period between successive spends.
#[pallet::constant]
type SpendPeriod: Get<BlockNumberFor<Self>>;
Expand Down Expand Up @@ -361,14 +342,10 @@ pub mod pallet {
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config<I>, I: 'static = ()> {
/// New proposal.
Proposed { proposal_index: ProposalIndex },
/// We have ended a spend period and will now allocate funds.
Spending { budget_remaining: BalanceOf<T, I> },
/// Some funds have been allocated.
Awarded { proposal_index: ProposalIndex, award: BalanceOf<T, I>, account: T::AccountId },
/// A proposal was rejected; funds were slashed.
Rejected { proposal_index: ProposalIndex, slashed: BalanceOf<T, I> },
/// Some of our funds have been burnt.
Burnt { burnt_funds: BalanceOf<T, I> },
/// Spending has finished; this is the amount that rolls over until next spend.
Expand Down Expand Up @@ -406,8 +383,6 @@ pub mod pallet {
/// Error for the treasury pallet.
#[pallet::error]
pub enum Error<T, I = ()> {
/// Proposer's balance is too low.
InsufficientProposersBalance,
/// No proposal, bounty or spend at that index.
InvalidIndex,
/// Too many approvals in the queue.
Expand Down Expand Up @@ -474,123 +449,6 @@ pub mod pallet {

#[pallet::call]
impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Put forward a suggestion for spending.
///
/// ## Dispatch Origin
///
/// Must be signed.
///
/// ## Details
/// A deposit proportional to the value is reserved and slashed if the proposal is rejected.
/// It is returned once the proposal is awarded.
///
/// ### Complexity
/// - O(1)
///
/// ## Events
///
/// Emits [`Event::Proposed`] if successful.
#[pallet::call_index(0)]
#[pallet::weight(T::WeightInfo::propose_spend())]
#[allow(deprecated)]
#[deprecated(
note = "`propose_spend` will be removed in February 2024. Use `spend` instead."
)]
pub fn propose_spend(
origin: OriginFor<T>,
#[pallet::compact] value: BalanceOf<T, I>,
beneficiary: AccountIdLookupOf<T>,
) -> DispatchResult {
let proposer = ensure_signed(origin)?;
let beneficiary = T::Lookup::lookup(beneficiary)?;

let bond = Self::calculate_bond(value);
T::Currency::reserve(&proposer, bond)
.map_err(|_| Error::<T, I>::InsufficientProposersBalance)?;

let c = Self::proposal_count();
<ProposalCount<T, I>>::put(c + 1);
<Proposals<T, I>>::insert(c, Proposal { proposer, value, beneficiary, bond });

Self::deposit_event(Event::Proposed { proposal_index: c });
Ok(())
}

/// Reject a proposed spend.
///
/// ## Dispatch Origin
///
/// Must be [`Config::RejectOrigin`].
///
/// ## Details
/// The original deposit will be slashed.
///
/// ### Complexity
/// - O(1)
///
/// ## Events
///
/// Emits [`Event::Rejected`] if successful.
#[pallet::call_index(1)]
#[pallet::weight((T::WeightInfo::reject_proposal(), DispatchClass::Operational))]
#[allow(deprecated)]
#[deprecated(
note = "`reject_proposal` will be removed in February 2024. Use `spend` instead."
)]
pub fn reject_proposal(
origin: OriginFor<T>,
#[pallet::compact] proposal_id: ProposalIndex,
) -> DispatchResult {
T::RejectOrigin::ensure_origin(origin)?;

let proposal =
<Proposals<T, I>>::take(&proposal_id).ok_or(Error::<T, I>::InvalidIndex)?;
let value = proposal.bond;
let imbalance = T::Currency::slash_reserved(&proposal.proposer, value).0;
T::OnSlash::on_unbalanced(imbalance);

Self::deposit_event(Event::<T, I>::Rejected {
proposal_index: proposal_id,
slashed: value,
});
Ok(())
}

/// Approve a proposal.
///
/// ## Dispatch Origin
///
/// Must be [`Config::ApproveOrigin`].
///
/// ## Details
///
/// At a later time, the proposal will be allocated to the beneficiary and the original
/// deposit will be returned.
///
/// ### Complexity
/// - O(1).
///
/// ## Events
///
/// No events are emitted from this dispatch.
#[pallet::call_index(2)]
#[pallet::weight((T::WeightInfo::approve_proposal(T::MaxApprovals::get()), DispatchClass::Operational))]
#[allow(deprecated)]
#[deprecated(
note = "`approve_proposal` will be removed in February 2024. Use `spend` instead."
)]
pub fn approve_proposal(
origin: OriginFor<T>,
#[pallet::compact] proposal_id: ProposalIndex,
) -> DispatchResult {
T::ApproveOrigin::ensure_origin(origin)?;

ensure!(<Proposals<T, I>>::contains_key(proposal_id), Error::<T, I>::InvalidIndex);
Approvals::<T, I>::try_append(proposal_id)
.map_err(|_| Error::<T, I>::TooManyApprovals)?;
Ok(())
}

/// Propose and approve a spend of treasury funds.
///
/// ## Dispatch Origin
Expand Down Expand Up @@ -932,15 +790,6 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
T::PalletId::get().into_account_truncating()
}

/// The needed bond for a proposal whose spend is `value`.
fn calculate_bond(value: BalanceOf<T, I>) -> BalanceOf<T, I> {
let mut r = T::ProposalBondMinimum::get().max(T::ProposalBond::get() * value);
if let Some(m) = T::ProposalBondMaximum::get() {
r = r.min(m);
}
r
}

/// Spend some money! returns number of approvals before spend.
pub fn spend_funds() -> Weight {
let mut total_weight = Weight::zero();
Expand Down
Loading