Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Tweak to active total migrations #12832

Merged
merged 4 commits into from
Dec 3, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
41 changes: 37 additions & 4 deletions frame/balances/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ use frame_support::{pallet_prelude::*, traits::OnRuntimeUpgrade, weights::Weight

// NOTE: This must be used alongside the account whose balance is expected to be inactive.
// Generally this will be used for the XCM teleport checking account.
pub struct MigrateToTrackInactive<T: Config, A: Get<T::AccountId>>(
sp_std::marker::PhantomData<(T, A)>,
);
pub struct MigrateToTrackInactive<T, A>(PhantomData<(T, A)>);
impl<T: Config, A: Get<T::AccountId>> OnRuntimeUpgrade for MigrateToTrackInactive<T, A> {
fn on_runtime_upgrade() -> Weight {
let current_version = Pallet::<T>::current_storage_version();
Expand All @@ -32,7 +30,42 @@ impl<T: Config, A: Get<T::AccountId>> OnRuntimeUpgrade for MigrateToTrackInactiv
Pallet::<T>::deactivate(b);
current_version.put::<Pallet<T>>();
log::info!(target: "runtime::balances", "Storage to version {:?}", current_version);
T::DbWeight::get().reads_writes(3, 3)
T::DbWeight::get().reads_writes(4, 3)
} else {
log::info!(target: "runtime::balances", "Migration did not execute. This probably should be removed");
T::DbWeight::get().reads(2)
}
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
Ok(vec![])
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(total: Vec<u8>) -> Result<(), &'static str> {
Ok(())
}
}

// NOTE: This must be used alongside the account whose balance is expected to be inactive.
// Generally this will be used for the XCM teleport checking account.
pub struct MigrateManyToTrackInactive<T, A>(PhantomData<(T, A)>);
impl<T: Config, A: Get<Vec<T::AccountId>>> OnRuntimeUpgrade for MigrateManyToTrackInactive<T, A> {
fn on_runtime_upgrade() -> Weight {
let current_version = Pallet::<T>::current_storage_version();
let onchain_version = Pallet::<T>::on_chain_storage_version();

if onchain_version == 0 && current_version == 1 {
let accounts = A::get();
let total = accounts
.iter()
.map(|a| Pallet::<T>::total_balance(a))
.fold(T::Balance::zero(), |a, e| a.saturating_add(e));
Pallet::<T>::deactivate(total);
current_version.put::<Pallet<T>>();
log::info!(target: "runtime::balances", "Storage to version {:?}", current_version);
T::DbWeight::get().reads_writes(3 + accounts.len() as u64, 3)
} else {
log::info!(target: "runtime::balances", "Migration did not execute. This probably should be removed");
T::DbWeight::get().reads(2)
Expand Down
4 changes: 2 additions & 2 deletions frame/support/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
pub mod tokens;
pub use tokens::{
currency::{
Currency, LockIdentifier, LockableCurrency, NamedReservableCurrency, ReservableCurrency,
TotalIssuanceOf, VestingSchedule,
ActiveIssuanceOf, Currency, LockIdentifier, LockableCurrency, NamedReservableCurrency,
ReservableCurrency, TotalIssuanceOf, VestingSchedule,
},
fungible, fungibles,
imbalance::{Imbalance, OnUnbalanced, SignedImbalance},
Expand Down