Skip to content

Commit

Permalink
Deprecate Gov_v1 flow components inside treasury pallet
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidK committed Oct 23, 2024
1 parent 21b3a46 commit 061d27f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
12 changes: 12 additions & 0 deletions prdoc/pr_6169.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
title: Deprecate Gov_v1 treasury spend flow in `treasury` pallet

doc:
- audience: Runtime Dev
description: |
Deprecates items from treasury pallet used in Gov_v1 flow.
Items deprecated: `spend_local`, `remove_approval`, `proposal_count`, `proposals`, `approvals`, `MaxApprovals`, `ProposalCount`, `Proposals`, `Approvals`.
To replace `spend_local` functionality configure `Paymaster` pallet configuration to be `PayFromAccount` and configure `AssetKind` to be `()`.

crates:
- name: pallet-treasury
bump: major
41 changes: 41 additions & 0 deletions substrate/frame/treasury/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
#![cfg_attr(not(feature = "std"), no_std)]

// not all specific usages can be marked as deprecated
#![allow(deprecated)]

mod benchmarking;
pub mod migration;
#[cfg(test)]
Expand Down Expand Up @@ -240,6 +243,9 @@ pub mod pallet {
///
/// NOTE: This parameter is also used within the Bounties Pallet extension if enabled.
#[pallet::constant]
#[deprecated(
note = "Gov v1 type used for spend_local, configure pallet to use PayFromAccount for Paymaster type instead"
)]
type MaxApprovals: Get<u32>;

/// The origin required for approving spends from the treasury outside of the proposal
Expand Down Expand Up @@ -279,10 +285,17 @@ pub mod pallet {

/// Number of proposals that have been made.
#[pallet::storage]
#[deprecated(
note = "Gov v1 type used for spend_local, configure pallet to use PayFromAccount for Paymaster type instead"
)]
pub type ProposalCount<T, I = ()> = StorageValue<_, ProposalIndex, ValueQuery>;

/// Proposals that have been made.
#[pallet::storage]
#[deprecated(
note = "Gov v1 type used for spend_local, configure pallet to use PayFromAccount for Paymaster type instead"
)]
#[allow(deprecated)]
pub type Proposals<T: Config<I>, I: 'static = ()> = StorageMap<
_,
Twox64Concat,
Expand All @@ -298,6 +311,10 @@ pub mod pallet {

/// Proposal indices that have been approved but not yet awarded.
#[pallet::storage]
#[deprecated(
note = "Gov v1 type used for spend_local, configure pallet to use PayFromAccount for Paymaster type instead"
)]
#[allow(deprecated)]
pub type Approvals<T: Config<I>, I: 'static = ()> =
StorageValue<_, BoundedVec<ProposalIndex, T::MaxApprovals>, ValueQuery>;

Expand Down Expand Up @@ -470,6 +487,8 @@ pub mod pallet {
/// Emits [`Event::SpendApproved`] if successful.
#[pallet::call_index(3)]
#[pallet::weight(T::WeightInfo::spend_local())]
#[deprecated(note = "This call will be removed by May 2025. Configure pallet to use PayFromAccount for Paymaster type instead")]
#[allow(deprecated)]
pub fn spend_local(
origin: OriginFor<T>,
#[pallet::compact] amount: BalanceOf<T, I>,
Expand Down Expand Up @@ -499,7 +518,9 @@ pub mod pallet {
.unwrap_or(Ok(()))?;

let beneficiary = T::Lookup::lookup(beneficiary)?;
#[allow(deprecated)]
let proposal_index = ProposalCount::<T, I>::get();
#[allow(deprecated)]
Approvals::<T, I>::try_append(proposal_index)
.map_err(|_| Error::<T, I>::TooManyApprovals)?;
let proposal = Proposal {
Expand All @@ -508,7 +529,9 @@ pub mod pallet {
beneficiary: beneficiary.clone(),
bond: Default::default(),
};
#[allow(deprecated)]
Proposals::<T, I>::insert(proposal_index, proposal);
#[allow(deprecated)]
ProposalCount::<T, I>::put(proposal_index + 1);

Self::deposit_event(Event::SpendApproved { proposal_index, amount, beneficiary });
Expand Down Expand Up @@ -538,12 +561,17 @@ pub mod pallet {
/// in the first place.
#[pallet::call_index(4)]
#[pallet::weight((T::WeightInfo::remove_approval(), DispatchClass::Operational))]
#[deprecated(
note = "This call will be removed by May 2025. Configure pallet to use PayFromAccount for Paymaster type instead"
)]
#[allow(deprecated)]
pub fn remove_approval(
origin: OriginFor<T>,
#[pallet::compact] proposal_id: ProposalIndex,
) -> DispatchResult {
T::RejectOrigin::ensure_origin(origin)?;

#[allow(deprecated)]
Approvals::<T, I>::try_mutate(|v| -> DispatchResult {
if let Some(index) = v.iter().position(|x| x == &proposal_id) {
v.remove(index);
Expand Down Expand Up @@ -793,16 +821,28 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
}

/// Public function to proposal_count storage.
#[deprecated(
note = "This function will be removed by May 2025. Configure pallet to use PayFromAccount for Paymaster type instead"
)]
pub fn proposal_count() -> ProposalIndex {
#[allow(deprecated)]
ProposalCount::<T, I>::get()
}

/// Public function to proposals storage.
#[deprecated(
note = "This function will be removed by May 2025. Configure pallet to use PayFromAccount for Paymaster type instead"
)]
pub fn proposals(index: ProposalIndex) -> Option<Proposal<T::AccountId, BalanceOf<T, I>>> {
#[allow(deprecated)]
Proposals::<T, I>::get(index)
}

/// Public function to approvals storage.
#[deprecated(
note = "This function will be removed by May 2025. Configure pallet to use PayFromAccount for Paymaster type instead"
)]
#[allow(deprecated)]
pub fn approvals() -> BoundedVec<ProposalIndex, T::MaxApprovals> {
Approvals::<T, I>::get()
}
Expand All @@ -817,6 +857,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {

let mut missed_any = false;
let mut imbalance = PositiveImbalanceOf::<T, I>::zero();
#[allow(deprecated)]
let proposals_len = Approvals::<T, I>::mutate(|v| {
let proposals_approvals_len = v.len() as u32;
v.retain(|&index| {
Expand Down
2 changes: 2 additions & 0 deletions substrate/frame/treasury/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ pub mod cleanup_proposals {
{
fn on_runtime_upgrade() -> frame_support::weights::Weight {
let mut approval_index = BTreeSet::new();
#[allow(deprecated)]
for approval in Approvals::<T, I>::get().iter() {
approval_index.insert(*approval);
}

let mut proposals_processed = 0;
#[allow(deprecated)]
for (proposal_index, p) in Proposals::<T, I>::iter() {
if !approval_index.contains(&proposal_index) {
let err_amount = T::Currency::unreserve(&p.proposer, p.bond);
Expand Down

0 comments on commit 061d27f

Please sign in to comment.