This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[Feature] Add a migration that drains and refunds stored calls #12313
Merged
ruseinov
merged 11 commits into
gav-rm-multisig-calls
from
ru/feature/migrate-storage-calls
Sep 29, 2022
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7bb5e13
[Feature] Add a migration that drains and refunds stored calls
ruseinov 8234539
migration fixes
ruseinov 35a4c77
fixes
ruseinov 9c0ad6d
address review comments
ruseinov 1e8a954
consume the whole block weight
ruseinov a4c139d
fix assertions
ruseinov fab3fc4
Merge remote-tracking branch 'origin/gav-rm-multisig-calls' into ru/f…
73d5643
Merge branch 'ru/feature/migrate-storage-calls' of github.com:parityt…
ruseinov dbb2cd2
license header
ruseinov 5377978
fix interface
ruseinov e140d00
Merge remote-tracking branch 'origin/gav-rm-multisig-calls' into ru/f…
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
Next
Next commit
[Feature] Add a migration that drains and refunds stored calls
- Loading branch information
commit 7bb5e1360b16e87f3e07be3b2c7fbccd27c3a152
There are no files selected for viewing
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,56 @@ | ||
| use super::*; | ||
ggwpez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| use frame_support::{ | ||
| traits::{OnRuntimeUpgrade, WrapperKeepOpaque}, | ||
| Blake2_256, | ||
| }; | ||
|
|
||
| #[cfg(feature = "try-runtime")] | ||
| use frame_support::ensure; | ||
|
|
||
| pub mod v1 { | ||
| use super::*; | ||
|
|
||
| type OpaqueCall<T> = WrapperKeepOpaque<<T as Config>::RuntimeCall>; | ||
|
|
||
| #[frame_support::storage_alias] | ||
| type Calls<T: Config> = StorageMap< | ||
| crate::Pallet<T>, | ||
| Blake2_256, | ||
| [u8; 32], | ||
| (OpaqueCall<T>, T::AccountId, BalanceOf<T>), | ||
| >; | ||
|
|
||
| pub struct MigrateToV1<T>(sp_std::marker::PhantomData<T>); | ||
| impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> { | ||
| #[cfg(feature = "try-runtime")] | ||
| fn pre_upgrade() -> Result<(), &'static str> { | ||
ggwpez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let current = Pallet::<T>::current_storage_version(); | ||
| let onchain = Pallet::<T>::on_chain_storage_version(); | ||
|
|
||
| ensure!(onchain < 1, "this migration can be deleted"); | ||
|
|
||
| log!(info, "Number of calls to refund and delete: {}", Calls<T>::count()); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| fn on_runtime_upgrade() -> Weight { | ||
| let onchain = Pallet::<T>::on_chain_storage_version(); | ||
|
|
||
| ensure!(onchain > 0, "this migration can be deleted"); | ||
|
|
||
| let calls = Calls::<T>::drain().for_each(|call_hash, (_data, caller, deposit)| { | ||
| T::Currency::unreserve(&caller, deposit)?; | ||
| }); | ||
| } | ||
|
|
||
| #[cfg(feature = "try-runtime")] | ||
| fn post_upgrade() -> Result<(), &'static str> { | ||
| let onchain = Pallet::<T>::on_chain_storage_version(); | ||
|
|
||
|
||
| ensure!(onchain > 0, "this migration needs to be run"); | ||
| ensure!(Calls<T>::count() == 0, | ||
| "there are some dangling calls that need to be destroyed and refunded"); | ||
| } | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this in here if you only use it in the migration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I'd rather define logging macro for the whole package and have the opportunity to use it when/if needed. It's also consistent with other pallets which define logging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ruseinov's point is fair to me, I had to do the same in the past.
@ggwpez what I challenge you about is a way so we won't need to define this log macro per-pallet? wdyt?