pallet-balances: Fix inactive funds migration (#12840)

* pallet-balances: Fix inactive funds migration

Fixes the inactive funds migration. It was missing to set the `storage_version` attribute for the
`Pallet` struct. Besides that it also removes the old `StorageVersion` representation and adds support
for instances of pallet-balances.

* Fix test
This commit is contained in:
Bastian Köcher
2022-12-05 14:57:03 +01:00
committed by GitHub
parent 2a0e53d11a
commit 4be3ddaa71
3 changed files with 51 additions and 63 deletions
+5 -24
View File
@@ -246,8 +246,13 @@ pub mod pallet {
type ReserveIdentifier: Parameter + Member + MaxEncodedLen + Ord + Copy;
}
/// The current storage version.
const STORAGE_VERSION: frame_support::traits::StorageVersion =
frame_support::traits::StorageVersion::new(1);
#[pallet::pallet]
#[pallet::generate_store(pub(super) trait Store)]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T, I = ()>(PhantomData<(T, I)>);
#[pallet::call]
@@ -556,13 +561,6 @@ pub mod pallet {
ValueQuery,
>;
/// Storage version of the pallet.
///
/// This is set to v2.0.0 for new networks.
#[pallet::storage]
pub(super) type StorageVersion<T: Config<I>, I: 'static = ()> =
StorageValue<_, Releases, ValueQuery>;
#[pallet::genesis_config]
pub struct GenesisConfig<T: Config<I>, I: 'static = ()> {
pub balances: Vec<(T::AccountId, T::Balance)>,
@@ -581,8 +579,6 @@ pub mod pallet {
let total = self.balances.iter().fold(Zero::zero(), |acc: T::Balance, &(_, n)| acc + n);
<TotalIssuance<T, I>>::put(total);
<StorageVersion<T, I>>::put(Releases::V2_0_0);
for (_, balance) in &self.balances {
assert!(
*balance >= <T as Config<I>>::ExistentialDeposit::get(),
@@ -727,21 +723,6 @@ impl<Balance: Saturating + Copy + Ord> AccountData<Balance> {
}
}
// A value placed in storage that represents the current version of the Balances storage.
// This value is used by the `on_runtime_upgrade` logic to determine whether we run
// storage migration logic. This should match directly with the semantic versions of the Rust crate.
#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, RuntimeDebug, MaxEncodedLen, TypeInfo)]
enum Releases {
V1_0_0,
V2_0_0,
}
impl Default for Releases {
fn default() -> Self {
Releases::V1_0_0
}
}
pub struct DustCleaner<T: Config<I>, I: 'static = ()>(
Option<(T::AccountId, NegativeImbalance<T, I>)>,
);