-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add migration to clear unapproved proposals from treasury pallet #5892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
davidk-pt
merged 27 commits into
master
from
davidk/remove-proposals-storage-item-from-treasury
Oct 8, 2024
Merged
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
766c3a9
Write migration to release bonds to proposers
41d1ad7
Add treasury migration to rococo runtime
a78afec
Fix compilation with try-runtime feature flag
917bd84
Address Muharem's comments
a3c7ad2
Rename to CleanupProposals
4fd8531
Update prdoc/pr_5892.prdoc
davidk-pt 202fa68
Added miration to westend
7a027c3
Fix prdoc
d45feab
Add log/std feature propogation
47bf1d3
Taplo format log/std
438aec0
Update substrate/frame/treasury/src/migration.rs
davidk-pt 6e29f9a
Update substrate/frame/treasury/src/migration.rs
davidk-pt 3765bb4
Add changed runtimes to prdoc
ff8ce16
Address more comments
34fcbfa
Remove westend treasury pallet migration
ac22408
Update prdoc
6e3b7b3
Decrease rococo runtime version
5110d7e
Comment formatting fixes
39ac640
Merge branch 'master' into davidk/remove-proposals-storage-item-from-…
davidk-pt 9b78bfa
Merge branch 'master' into davidk/remove-proposals-storage-item-from-…
shawntabrizi b8abc12
Remove pallet_balances::Config trait bound for migration
2b7097e
Merge branch 'master' into davidk/remove-proposals-storage-item-from-…
davidk-pt c80a395
Formatting fixes
49e1e34
Update prdoc/pr_5892.prdoc
davidk-pt dfe7e1f
Update prdoc/pr_5892.prdoc
davidk-pt 4158d19
Merge branch 'master' into davidk/remove-proposals-storage-item-from-…
seadanda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { | ||
davidk-pt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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()); | ||
davidk-pt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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) | ||
davidk-pt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| #[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, | ||
davidk-pt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "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< | ||
davidk-pt marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 0, | ||
| 1, | ||
| v1::MigrateToV1Impl<T, I>, | ||
| Pallet<T, I>, | ||
| <T as frame_system::Config>::DbWeight, | ||
| >; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.