-
Notifications
You must be signed in to change notification settings - Fork 2.7k
[Feature] Add a migration that drains and refunds stored calls #12313
Changes from 1 commit
7bb5e13
8234539
35a4c77
9c0ad6d
1e8a954
a4c139d
fab3fc4
73d5643
dbb2cd2
5377978
e140d00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
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 |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| use super::*; | ||
| use frame_support::{ | ||
| dispatch::GetStorageVersion, | ||
| traits::{OnRuntimeUpgrade, WrapperKeepOpaque}, | ||
| Blake2_256, | ||
| Identity, | ||
| }; | ||
|
|
||
| #[cfg(feature = "try-runtime")] | ||
|
|
@@ -14,10 +15,10 @@ pub mod v1 { | |
|
|
||
| #[frame_support::storage_alias] | ||
| type Calls<T: Config> = StorageMap< | ||
| crate::Pallet<T>, | ||
| Blake2_256, | ||
| Pallet<T>, | ||
| Identity, | ||
| [u8; 32], | ||
| (OpaqueCall<T>, T::AccountId, BalanceOf<T>), | ||
| (OpaqueCall<T>, <T as frame_system::Config>::AccountId, BalanceOf<T>), | ||
| >; | ||
|
|
||
| pub struct MigrateToV1<T>(sp_std::marker::PhantomData<T>); | ||
|
|
@@ -35,13 +36,26 @@ pub mod v1 { | |
| } | ||
|
|
||
| fn on_runtime_upgrade() -> Weight { | ||
| let current = Pallet::<T>::current_storage_version(); | ||
| let onchain = Pallet::<T>::on_chain_storage_version(); | ||
|
|
||
| ensure!(onchain > 0, "this migration can be deleted"); | ||
| if onchain > 0 { | ||
| log!(info, "MigrateToV1 should be removed"); | ||
| return T::DbWeight::get().reads(1) | ||
| } | ||
|
|
||
| // TODO: Assuming this is one read | ||
| let calls_read = Calls::<T>::iter().count() as u64; | ||
|
||
|
|
||
| let calls = Calls::<T>::drain().for_each(|call_hash, (_data, caller, deposit)| { | ||
| T::Currency::unreserve(&caller, deposit)?; | ||
| // TODO: Assuming this is one write and a read per record | ||
|
||
| Calls::<T>::drain().for_each(|(_call_hash, (_data, caller, deposit))| { | ||
| //TODO: What's the weight of one unreserve? | ||
|
||
| T::Currency::unreserve(&caller, deposit); | ||
| }); | ||
|
|
||
| current.put::<Pallet<T>>(); | ||
|
|
||
| T::DbWeight::get().reads_writes(calls_read + 1, 2) | ||
| } | ||
|
|
||
| #[cfg(feature = "try-runtime")] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.