Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 10 additions & 9 deletions runtime/common/src/crowdloan/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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())
Expand Down
2 changes: 0 additions & 2 deletions runtime/common/src/crowdloan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@

pub mod migration;

// TODO: Expose the total amount held.

use crate::{
slot_range::SlotRange,
traits::{Auctioneer, Registrar},
Expand Down
4 changes: 3 additions & 1 deletion runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
4 changes: 3 additions & 1 deletion runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
4 changes: 3 additions & 1 deletion runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down