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

Commit

Permalink
crowdloan: Fix migration. (#6397)
Browse files Browse the repository at this point in the history
The migration would not have been run because of the `current_version ==
1` check.
  • Loading branch information
bkchr authored Dec 6, 2022
1 parent 7e0fcfa commit 75979e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
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

0 comments on commit 75979e4

Please sign in to comment.