mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 23:51:05 +00:00
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:
@@ -15,50 +15,57 @@
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use super::*;
|
||||
use frame_support::{pallet_prelude::*, traits::OnRuntimeUpgrade, weights::Weight};
|
||||
use frame_support::{
|
||||
pallet_prelude::*,
|
||||
traits::{OnRuntimeUpgrade, PalletInfoAccess},
|
||||
weights::Weight,
|
||||
};
|
||||
|
||||
// NOTE: This must be used alongside the account whose balance is expected to be inactive.
|
||||
// Generally this will be used for the XCM teleport checking account.
|
||||
pub struct MigrateToTrackInactive<T, A>(PhantomData<(T, A)>);
|
||||
impl<T: Config, A: Get<T::AccountId>> OnRuntimeUpgrade for MigrateToTrackInactive<T, A> {
|
||||
fn on_runtime_upgrade() -> Weight {
|
||||
let current_version = Pallet::<T>::current_storage_version();
|
||||
let onchain_version = Pallet::<T>::on_chain_storage_version();
|
||||
fn migrate_v0_to_v1<T: Config<I>, I: 'static>(accounts: &[T::AccountId]) -> Weight {
|
||||
let onchain_version = Pallet::<T, I>::on_chain_storage_version();
|
||||
|
||||
if onchain_version == 0 && current_version == 1 {
|
||||
let b = Pallet::<T>::total_balance(&A::get());
|
||||
Pallet::<T>::deactivate(b);
|
||||
current_version.put::<Pallet<T>>();
|
||||
log::info!(target: "runtime::balances", "Storage to version {:?}", current_version);
|
||||
T::DbWeight::get().reads_writes(4, 3)
|
||||
} else {
|
||||
log::info!(target: "runtime::balances", "Migration did not execute. This probably should be removed");
|
||||
T::DbWeight::get().reads(2)
|
||||
}
|
||||
if onchain_version == 0 {
|
||||
let total = accounts
|
||||
.iter()
|
||||
.map(|a| Pallet::<T, I>::total_balance(a))
|
||||
.fold(T::Balance::zero(), |a, e| a.saturating_add(e));
|
||||
Pallet::<T, I>::deactivate(total);
|
||||
|
||||
// Remove the old `StorageVersion` type.
|
||||
frame_support::storage::unhashed::kill(&frame_support::storage::storage_prefix(
|
||||
Pallet::<T, I>::name().as_bytes(),
|
||||
"StorageVersion".as_bytes(),
|
||||
));
|
||||
|
||||
// Set storage version to `1`.
|
||||
StorageVersion::new(1).put::<Pallet<T, I>>();
|
||||
|
||||
log::info!(target: "runtime::balances", "Storage to version 1");
|
||||
T::DbWeight::get().reads_writes(2 + accounts.len() as u64, 3)
|
||||
} else {
|
||||
log::info!(target: "runtime::balances", "Migration did not execute. This probably should be removed");
|
||||
T::DbWeight::get().reads(1)
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: This must be used alongside the account whose balance is expected to be inactive.
|
||||
// Generally this will be used for the XCM teleport checking account.
|
||||
pub struct MigrateManyToTrackInactive<T, A>(PhantomData<(T, A)>);
|
||||
impl<T: Config, A: Get<Vec<T::AccountId>>> OnRuntimeUpgrade for MigrateManyToTrackInactive<T, A> {
|
||||
pub struct MigrateToTrackInactive<T, A, I = ()>(PhantomData<(T, A, I)>);
|
||||
impl<T: Config<I>, A: Get<T::AccountId>, I: 'static> OnRuntimeUpgrade
|
||||
for MigrateToTrackInactive<T, A, I>
|
||||
{
|
||||
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 {
|
||||
let accounts = A::get();
|
||||
let total = accounts
|
||||
.iter()
|
||||
.map(|a| Pallet::<T>::total_balance(a))
|
||||
.fold(T::Balance::zero(), |a, e| a.saturating_add(e));
|
||||
Pallet::<T>::deactivate(total);
|
||||
current_version.put::<Pallet<T>>();
|
||||
log::info!(target: "runtime::balances", "Storage to version {:?}", current_version);
|
||||
T::DbWeight::get().reads_writes(3 + accounts.len() as u64, 3)
|
||||
} else {
|
||||
log::info!(target: "runtime::balances", "Migration did not execute. This probably should be removed");
|
||||
T::DbWeight::get().reads(2)
|
||||
}
|
||||
migrate_v0_to_v1::<T, I>(&[A::get()])
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: This must be used alongside the accounts whose balance is expected to be inactive.
|
||||
// Generally this will be used for the XCM teleport checking accounts.
|
||||
pub struct MigrateManyToTrackInactive<T, A, I = ()>(PhantomData<(T, A, I)>);
|
||||
impl<T: Config<I>, A: Get<Vec<T::AccountId>>, I: 'static> OnRuntimeUpgrade
|
||||
for MigrateManyToTrackInactive<T, A, I>
|
||||
{
|
||||
fn on_runtime_upgrade() -> Weight {
|
||||
migrate_v0_to_v1::<T, I>(&A::get())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user