Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
547fc0d
Add function to clear unapproved proposals treasury from pallet
Oct 1, 2024
766c3a9
Write migration to release bonds to proposers
Oct 2, 2024
41d1ad7
Add treasury migration to rococo runtime
Oct 2, 2024
a78afec
Fix compilation with try-runtime feature flag
Oct 2, 2024
917bd84
Address Muharem's comments
Oct 3, 2024
a3c7ad2
Rename to CleanupProposals
Oct 3, 2024
4fd8531
Update prdoc/pr_5892.prdoc
davidk-pt Oct 4, 2024
202fa68
Added miration to westend
Oct 4, 2024
7a027c3
Fix prdoc
Oct 4, 2024
d45feab
Add log/std feature propogation
Oct 4, 2024
47bf1d3
Taplo format log/std
Oct 4, 2024
438aec0
Update substrate/frame/treasury/src/migration.rs
davidk-pt Oct 4, 2024
6e29f9a
Update substrate/frame/treasury/src/migration.rs
davidk-pt Oct 4, 2024
3765bb4
Add changed runtimes to prdoc
Oct 4, 2024
ff8ce16
Address more comments
Oct 4, 2024
34fcbfa
Remove westend treasury pallet migration
Oct 4, 2024
ac22408
Update prdoc
Oct 4, 2024
6e3b7b3
Decrease rococo runtime version
Oct 4, 2024
5110d7e
Comment formatting fixes
Oct 4, 2024
39ac640
Merge branch 'master' into davidk/remove-proposals-storage-item-from-…
davidk-pt Oct 5, 2024
9b78bfa
Merge branch 'master' into davidk/remove-proposals-storage-item-from-…
shawntabrizi Oct 5, 2024
b8abc12
Remove pallet_balances::Config trait bound for migration
Oct 6, 2024
2b7097e
Merge branch 'master' into davidk/remove-proposals-storage-item-from-…
davidk-pt Oct 6, 2024
c80a395
Formatting fixes
Oct 6, 2024
49e1e34
Update prdoc/pr_5892.prdoc
davidk-pt Oct 8, 2024
dfe7e1f
Update prdoc/pr_5892.prdoc
davidk-pt Oct 8, 2024
4158d19
Merge branch 'master' into davidk/remove-proposals-storage-item-from-…
seadanda Oct 8, 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
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.

Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,8 @@ type Migrations = (
pallet_core_fellowship::migration::MigrateV0ToV1<Runtime, FellowshipCoreInstance>,
// unreleased
pallet_core_fellowship::migration::MigrateV0ToV1<Runtime, AmbassadorCoreInstance>,
// unreleased
pallet_treasury::migration::MigrateV0ToV1<Runtime, FellowshipCoreInstance>,
);

/// Executive: handles dispatch to the various modules.
Expand Down
3 changes: 3 additions & 0 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1677,6 +1677,9 @@ pub mod migrations {
// permanent
pallet_xcm::migration::MigrateToLatestXcmVersion<Runtime>,
parachains_inclusion::migration::MigrateToV1<Runtime>,

// Release bonds stuck in proposals
pallet_treasury::migration::MigrateV0ToV1<Runtime, ()>,
);
}

Expand Down
15 changes: 15 additions & 0 deletions prdoc/pr_5892.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 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: Add migration to clear unapproved proposals treasury from pallet

doc:
- audience: Runtime Dev
description: |
It is no longer possible to create Proposals in this pallet but there
are some Proposals whose bonds are stuck. Purpose of this migration is to
clear those and return bonds to the proposers.

crates:
- name: pallet-treasury
bump: patch
1 change: 1 addition & 0 deletions substrate/frame/treasury/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ frame-system = { workspace = true }
pallet-balances = { workspace = true }
sp-runtime = { workspace = true }
sp-core = { optional = true, workspace = true }
log = { workspace = true }

[dev-dependencies]
sp-io = { workspace = true, default-features = true }
Expand Down
4 changes: 4 additions & 0 deletions substrate/frame/treasury/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
#![cfg_attr(not(feature = "std"), no_std)]

mod benchmarking;
pub mod migration;
#[cfg(test)]
mod tests;
pub mod weights;
Expand Down Expand Up @@ -199,7 +200,10 @@ pub mod pallet {
};
use frame_system::pallet_prelude::*;

const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T, I = ()>(PhantomData<(T, I)>);

#[pallet::config]
Expand Down
74 changes: 74 additions & 0 deletions substrate/frame/treasury/src/migration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use super::*;
use alloc::collections::BTreeSet;
use core::marker::PhantomData;
use frame_support::traits::UncheckedOnRuntimeUpgrade;

/// The log target for this pallet.
const LOG_TARGET: &str = "runtime::treasury";

mod v1 {
use super::*;
pub struct MigrateToV1Impl<T, I>(PhantomData<(T, I)>);

impl<T: Config<I>, I: 'static> UncheckedOnRuntimeUpgrade for MigrateToV1Impl<T, I> {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
let mut approval_index = BTreeSet::new();
for approval in Approvals::<T, I>::get().iter() {
approval_index.insert(*approval);
}

let mut proposals_released = 0;
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);
debug_assert!(err_amount.is_zero());
Proposals::<T, I>::remove(proposal_index);
log::info!(
target: LOG_TARGET,
"Released bond amount of {:?} to proposer {:?}",
p.bond,
p.proposer,
);
proposals_released += 1;
}
}

log::info!(
target: LOG_TARGET,
"Storage migration v1 for pallet-treasury finished, released {} proposal bonds.",
proposals_released,
);

// calculate and return migration weights
let approvals_read = 1;
T::DbWeight::get()
.reads_writes(proposals_released as u64 + approvals_read, proposals_released as u64)
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
Ok((Proposals::<T, I>::iter_values().count() as u32).encode())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(state: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
let old_count = u32::decode(&mut &state[..]).expect("Known good");
let new_count = Proposals::<T, I>::iter_values().count() as u32;

ensure!(
old_count <= new_count,
"Proposals after migration should be less or equal to old proposals"
);
Ok(())
}
}
}

/// Migrate the pallet storage from `0` to `1`.
pub type MigrateV0ToV1<T, I> = frame_support::migrations::VersionedMigration<
0,
1,
v1::MigrateToV1Impl<T, I>,
Pallet<T, I>,
<T as frame_system::Config>::DbWeight,
>;