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

crowdloan: Fix migration. #6397

Merged
merged 1 commit into from
Dec 6, 2022
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
13 changes: 8 additions & 5 deletions runtime/common/src/crowdloan/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,27 @@

use super::*;
use frame_support::{
dispatch::GetStorageVersion, storage_alias, traits::OnRuntimeUpgrade, Twox64Concat,
dispatch::GetStorageVersion,
storage_alias,
traits::{OnRuntimeUpgrade, StorageVersion},
Twox64Concat,
};

pub struct MigrateToTrackInactive<T>(sp_std::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for MigrateToTrackInactive<T> {
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 {
if onchain_version == 0 {
let mut translated = 0u64;
for index in Funds::<T>::iter_keys() {
let b = CurrencyOf::<T>::total_balance(&Pallet::<T>::fund_account_id(index.into()));
CurrencyOf::<T>::deactivate(b);
translated.saturating_inc();
}
current_version.put::<Pallet<T>>();
log::info!(target: "runtime::crowdloan", "Summed {} funds, storage to version {:?}", translated, current_version);

StorageVersion::new(1).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 {
log::info!(target: "runtime::crowdloan", "Migration did not execute. This probably should be removed");
Expand Down
4 changes: 4 additions & 0 deletions runtime/common/src/crowdloan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,13 @@ pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::{ensure_root, ensure_signed, pallet_prelude::*};

/// The current storage version.
const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);

#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::without_storage_info]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T>(_);

#[pallet::config]
Expand Down