Skip to content

Commit

Permalink
Add SimpleStorageUpdate to migrate balances without any additional in…
Browse files Browse the repository at this point in the history
…active tracks
  • Loading branch information
dmitrylavrenov committed Oct 31, 2024
1 parent 935eeb5 commit ac9609d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions substrate/frame/balances/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,24 @@ impl<T: Config<I>, I: 'static> OnRuntimeUpgrade for ResetInactive<T, I> {
}
}
}

pub struct SimpleStorageUpdate<T, I = ()>(PhantomData<(T, I)>);
impl<T: Config<I>, I: 'static> OnRuntimeUpgrade for SimpleStorageUpdate<T, I> {
fn on_runtime_upgrade() -> Weight {
let current_storage_version = <Pallet<T>>::current_storage_version();
let on_chain_version = Pallet::<T, I>::on_chain_storage_version();

if onchain_storage_version == 0 && current_storage_version != 0 {
current_storage_version.put::<Pallet<T>>();

log::info!(target: LOG_TARGET, "Storage to version {current_storage_version}");
T::DbWeight::get().reads_writes(2 + accounts.len() as u64, 3)
} else {
log::info!(
target: LOG_TARGET,
"Migration did not execute. This probably should be removed"
);
T::DbWeight::get().reads(1)
}
}
}

0 comments on commit ac9609d

Please sign in to comment.