diff --git a/polkadot/runtime/common/src/crowdloan/migration.rs b/polkadot/runtime/common/src/crowdloan/migration.rs index 468c2a572b518ba8189e394f16170205a09d891b..a46e72cc1a5172b6967f758246a8afb40a5f5bdb 100644 --- a/polkadot/runtime/common/src/crowdloan/migration.rs +++ b/polkadot/runtime/common/src/crowdloan/migration.rs @@ -22,20 +22,21 @@ use frame_support::{ Twox64Concat, }; -pub struct MigrateToTrackInactive<T>(sp_std::marker::PhantomData<T>); -impl<T: Config> OnRuntimeUpgrade for MigrateToTrackInactive<T> { +pub struct MigrateToTrackInactiveV2<T>(sp_std::marker::PhantomData<T>); +impl<T: Config> OnRuntimeUpgrade for MigrateToTrackInactiveV2<T> { fn on_runtime_upgrade() -> Weight { let onchain_version = Pallet::<T>::on_chain_storage_version(); - if onchain_version == 0 { + if onchain_version == 1 { let mut translated = 0u64; - for index in Funds::<T>::iter_keys() { - let b = CurrencyOf::<T>::total_balance(&Pallet::<T>::fund_account_id(index.into())); + for item in Funds::<T>::iter_values() { + let b = + CurrencyOf::<T>::total_balance(&Pallet::<T>::fund_account_id(item.fund_index)); CurrencyOf::<T>::deactivate(b); translated.saturating_inc(); } - StorageVersion::new(1).put::<Pallet<T>>(); + StorageVersion::new(2).put::<Pallet<T>>(); log::info!(target: "runtime::crowdloan", "Summed {} funds, storage to version 1", translated); T::DbWeight::get().reads_writes(translated * 2 + 1, translated * 2 + 1) } else { @@ -46,9 +47,9 @@ impl<T: Config> OnRuntimeUpgrade for MigrateToTrackInactive<T> { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result<Vec<u8>, &'static str> { - let total = Funds::<T>::iter_keys() - .map(|index| { - CurrencyOf::<T>::total_balance(&Pallet::<T>::fund_account_id(index.into())) + let total = Funds::<T>::iter_values() + .map(|item| { + CurrencyOf::<T>::total_balance(&Pallet::<T>::fund_account_id(item.fund_index)) }) .fold(BalanceOf::<T>::zero(), |a, i| a.saturating_add(i)); Ok((total, CurrencyOf::<T>::active_issuance()).encode()) diff --git a/polkadot/runtime/common/src/crowdloan/mod.rs b/polkadot/runtime/common/src/crowdloan/mod.rs index 711bf0b7b33b5ba1cf2195a93fa79ffffb63675a..57b8f27f507ac2427f1b57ce8e764c58e6b0d2ee 100644 --- a/polkadot/runtime/common/src/crowdloan/mod.rs +++ b/polkadot/runtime/common/src/crowdloan/mod.rs @@ -51,8 +51,6 @@ pub mod migration; -// TODO: Expose the total amount held. - use crate::{ slot_range::SlotRange, traits::{Auctioneer, Registrar}, diff --git a/polkadot/runtime/kusama/src/lib.rs b/polkadot/runtime/kusama/src/lib.rs index 8cf3e95f79bb5427d78102819295741e0238c8ac..ba6bc86bf9c2e3cbcdd1a3f87147ef97c5e1823e 100644 --- a/polkadot/runtime/kusama/src/lib.rs +++ b/polkadot/runtime/kusama/src/lib.rs @@ -1484,8 +1484,10 @@ impl Get<&'static str> for StakingMigrationV11OldPallet { /// /// Should be cleared after every release. pub type Migrations = ( + pallet_balances::migration::ResetInactive<Runtime>, + // We need to apply this migration again, because `ResetInactive` resets the state again. pallet_balances::migration::MigrateToTrackInactive<Runtime, CheckAccount>, - crowdloan::migration::MigrateToTrackInactive<Runtime>, + crowdloan::migration::MigrateToTrackInactiveV2<Runtime>, pallet_referenda::migration::v1::MigrateV0ToV1<Runtime>, pallet_referenda::migration::v1::MigrateV0ToV1< Runtime, diff --git a/polkadot/runtime/polkadot/src/lib.rs b/polkadot/runtime/polkadot/src/lib.rs index dc32a91c7aceaccfb894ac717b2ac29f6b427463..81a7a35159575220c0d5ab9e06db884818698e1d 100644 --- a/polkadot/runtime/polkadot/src/lib.rs +++ b/polkadot/runtime/polkadot/src/lib.rs @@ -1601,8 +1601,10 @@ impl Get<&'static str> for StakingMigrationV11OldPallet { /// /// Should be cleared after every release. pub type Migrations = ( + pallet_balances::migration::ResetInactive<Runtime>, + // We need to apply this migration again, because `ResetInactive` resets the state again. pallet_balances::migration::MigrateToTrackInactive<Runtime, xcm_config::CheckAccount>, - crowdloan::migration::MigrateToTrackInactive<Runtime>, + crowdloan::migration::MigrateToTrackInactiveV2<Runtime>, pallet_scheduler::migration::v4::CleanupAgendas<Runtime>, pallet_staking::migrations::v13::MigrateToV13<Runtime>, parachains_disputes::migration::v1::MigrateToV1<Runtime>, diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 38d5ce28d16751defe4842915a09e24e1a3d2ead..4424b473052b7ced3444a4165059b8d572c249b0 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1481,8 +1481,10 @@ pub type UncheckedExtrinsic = /// /// Should be cleared after every release. pub type Migrations = ( + pallet_balances::migration::ResetInactive<Runtime>, + // We need to apply this migration again, because `ResetInactive` resets the state again. pallet_balances::migration::MigrateToTrackInactive<Runtime, xcm_config::CheckAccount>, - crowdloan::migration::MigrateToTrackInactive<Runtime>, + crowdloan::migration::MigrateToTrackInactiveV2<Runtime>, pallet_scheduler::migration::v4::CleanupAgendas<Runtime>, parachains_disputes::migration::v1::MigrateToV1<Runtime>, parachains_configuration::migration::v4::MigrateToV4<Runtime>, diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index b10f76a2700dcd44274f8db374f9ee9dddeaae9d..c71b5238c58059abefbefa7b18be9b88e1c4d9ce 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -1215,8 +1215,10 @@ impl Get<&'static str> for StakingMigrationV11OldPallet { /// /// Should be cleared after every release. pub type Migrations = ( + pallet_balances::migration::ResetInactive<Runtime>, + // We need to apply this migration again, because `ResetInactive` resets the state again. pallet_balances::migration::MigrateToTrackInactive<Runtime, xcm_config::CheckAccount>, - crowdloan::migration::MigrateToTrackInactive<Runtime>, + crowdloan::migration::MigrateToTrackInactiveV2<Runtime>, pallet_scheduler::migration::v4::CleanupAgendas<Runtime>, pallet_staking::migrations::v13::MigrateToV13<Runtime>, parachains_disputes::migration::v1::MigrateToV1<Runtime>,