diff --git a/frame/balances/src/migration.rs b/frame/balances/src/migration.rs index e27efc217407a..1dd3e6f51f1be 100644 --- a/frame/balances/src/migration.rs +++ b/frame/balances/src/migration.rs @@ -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>( - sp_std::marker::PhantomData<(T, A)>, -); +pub struct MigrateToTrackInactive(PhantomData<(T, A)>); impl> OnRuntimeUpgrade for MigrateToTrackInactive { fn on_runtime_upgrade() -> Weight { let current_version = Pallet::::current_storage_version(); @@ -32,20 +30,35 @@ impl> OnRuntimeUpgrade for MigrateToTrackInactiv Pallet::::deactivate(b); current_version.put::>(); 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, &'static str> { - Ok(vec![]) - } +// 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(PhantomData<(T, A)>); +impl>> OnRuntimeUpgrade for MigrateManyToTrackInactive { + fn on_runtime_upgrade() -> Weight { + let current_version = Pallet::::current_storage_version(); + let onchain_version = Pallet::::on_chain_storage_version(); - #[cfg(feature = "try-runtime")] - fn post_upgrade(total: Vec) -> Result<(), &'static str> { - Ok(()) + if onchain_version == 0 && current_version == 1 { + let accounts = A::get(); + let total = accounts + .iter() + .map(|a| Pallet::::total_balance(a)) + .fold(T::Balance::zero(), |a, e| a.saturating_add(e)); + Pallet::::deactivate(total); + current_version.put::>(); + 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) + } } } diff --git a/frame/support/src/traits.rs b/frame/support/src/traits.rs index f09b715a970ad..9b5300dfc5739 100644 --- a/frame/support/src/traits.rs +++ b/frame/support/src/traits.rs @@ -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},