mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 22:11:02 +00:00
Improve inactive fund tracking (#6471)
* Improve inactive fund tracking * Docs * Introduce the re-migration code * Bump * Update runtime/kusama/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update runtime/common/src/crowdloan/migration.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Update runtime/common/src/crowdloan/migration.rs Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> * Grumbles * Apply comments suggestions from code review Co-authored-by: Bastian Köcher <info@kchr.de> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io> Co-authored-by: muharem <ismailov.m.h@gmail.com> Co-authored-by: Bastian Köcher <info@kchr.de> Co-authored-by: parity-processbot <>
This commit is contained in:
@@ -22,20 +22,21 @@ use frame_support::{
|
|||||||
Twox64Concat,
|
Twox64Concat,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct MigrateToTrackInactive<T>(sp_std::marker::PhantomData<T>);
|
pub struct MigrateToTrackInactiveV2<T>(sp_std::marker::PhantomData<T>);
|
||||||
impl<T: Config> OnRuntimeUpgrade for MigrateToTrackInactive<T> {
|
impl<T: Config> OnRuntimeUpgrade for MigrateToTrackInactiveV2<T> {
|
||||||
fn on_runtime_upgrade() -> Weight {
|
fn on_runtime_upgrade() -> Weight {
|
||||||
let onchain_version = Pallet::<T>::on_chain_storage_version();
|
let onchain_version = Pallet::<T>::on_chain_storage_version();
|
||||||
|
|
||||||
if onchain_version == 0 {
|
if onchain_version == 1 {
|
||||||
let mut translated = 0u64;
|
let mut translated = 0u64;
|
||||||
for index in Funds::<T>::iter_keys() {
|
for item in Funds::<T>::iter_values() {
|
||||||
let b = CurrencyOf::<T>::total_balance(&Pallet::<T>::fund_account_id(index.into()));
|
let b =
|
||||||
|
CurrencyOf::<T>::total_balance(&Pallet::<T>::fund_account_id(item.fund_index));
|
||||||
CurrencyOf::<T>::deactivate(b);
|
CurrencyOf::<T>::deactivate(b);
|
||||||
translated.saturating_inc();
|
translated.saturating_inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
StorageVersion::new(1).put::<Pallet<T>>();
|
StorageVersion::new(2).put::<Pallet<T>>();
|
||||||
log::info!(target: "runtime::crowdloan", "Summed {} funds, storage to version 1", translated);
|
log::info!(target: "runtime::crowdloan", "Summed {} funds, storage to version 1", translated);
|
||||||
T::DbWeight::get().reads_writes(translated * 2 + 1, translated * 2 + 1)
|
T::DbWeight::get().reads_writes(translated * 2 + 1, translated * 2 + 1)
|
||||||
} else {
|
} else {
|
||||||
@@ -46,9 +47,9 @@ impl<T: Config> OnRuntimeUpgrade for MigrateToTrackInactive<T> {
|
|||||||
|
|
||||||
#[cfg(feature = "try-runtime")]
|
#[cfg(feature = "try-runtime")]
|
||||||
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
|
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
|
||||||
let total = Funds::<T>::iter_keys()
|
let total = Funds::<T>::iter_values()
|
||||||
.map(|index| {
|
.map(|item| {
|
||||||
CurrencyOf::<T>::total_balance(&Pallet::<T>::fund_account_id(index.into()))
|
CurrencyOf::<T>::total_balance(&Pallet::<T>::fund_account_id(item.fund_index))
|
||||||
})
|
})
|
||||||
.fold(BalanceOf::<T>::zero(), |a, i| a.saturating_add(i));
|
.fold(BalanceOf::<T>::zero(), |a, i| a.saturating_add(i));
|
||||||
Ok((total, CurrencyOf::<T>::active_issuance()).encode())
|
Ok((total, CurrencyOf::<T>::active_issuance()).encode())
|
||||||
|
|||||||
@@ -51,8 +51,6 @@
|
|||||||
|
|
||||||
pub mod migration;
|
pub mod migration;
|
||||||
|
|
||||||
// TODO: Expose the total amount held.
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
slot_range::SlotRange,
|
slot_range::SlotRange,
|
||||||
traits::{Auctioneer, Registrar},
|
traits::{Auctioneer, Registrar},
|
||||||
|
|||||||
@@ -1484,8 +1484,10 @@ impl Get<&'static str> for StakingMigrationV11OldPallet {
|
|||||||
///
|
///
|
||||||
/// Should be cleared after every release.
|
/// Should be cleared after every release.
|
||||||
pub type Migrations = (
|
pub type Migrations = (
|
||||||
|
pallet_balances::migration::ResetInactive<Runtime>,
|
||||||
|
// We need to apply this migration again, because `ResetInactive` resets the state again.
|
||||||
pallet_balances::migration::MigrateToTrackInactive<Runtime, CheckAccount>,
|
pallet_balances::migration::MigrateToTrackInactive<Runtime, CheckAccount>,
|
||||||
crowdloan::migration::MigrateToTrackInactive<Runtime>,
|
crowdloan::migration::MigrateToTrackInactiveV2<Runtime>,
|
||||||
pallet_referenda::migration::v1::MigrateV0ToV1<Runtime>,
|
pallet_referenda::migration::v1::MigrateV0ToV1<Runtime>,
|
||||||
pallet_referenda::migration::v1::MigrateV0ToV1<
|
pallet_referenda::migration::v1::MigrateV0ToV1<
|
||||||
Runtime,
|
Runtime,
|
||||||
|
|||||||
@@ -1601,8 +1601,10 @@ impl Get<&'static str> for StakingMigrationV11OldPallet {
|
|||||||
///
|
///
|
||||||
/// Should be cleared after every release.
|
/// Should be cleared after every release.
|
||||||
pub type Migrations = (
|
pub type Migrations = (
|
||||||
|
pallet_balances::migration::ResetInactive<Runtime>,
|
||||||
|
// We need to apply this migration again, because `ResetInactive` resets the state again.
|
||||||
pallet_balances::migration::MigrateToTrackInactive<Runtime, xcm_config::CheckAccount>,
|
pallet_balances::migration::MigrateToTrackInactive<Runtime, xcm_config::CheckAccount>,
|
||||||
crowdloan::migration::MigrateToTrackInactive<Runtime>,
|
crowdloan::migration::MigrateToTrackInactiveV2<Runtime>,
|
||||||
pallet_scheduler::migration::v4::CleanupAgendas<Runtime>,
|
pallet_scheduler::migration::v4::CleanupAgendas<Runtime>,
|
||||||
pallet_staking::migrations::v13::MigrateToV13<Runtime>,
|
pallet_staking::migrations::v13::MigrateToV13<Runtime>,
|
||||||
parachains_disputes::migration::v1::MigrateToV1<Runtime>,
|
parachains_disputes::migration::v1::MigrateToV1<Runtime>,
|
||||||
|
|||||||
@@ -1481,8 +1481,10 @@ pub type UncheckedExtrinsic =
|
|||||||
///
|
///
|
||||||
/// Should be cleared after every release.
|
/// Should be cleared after every release.
|
||||||
pub type Migrations = (
|
pub type Migrations = (
|
||||||
|
pallet_balances::migration::ResetInactive<Runtime>,
|
||||||
|
// We need to apply this migration again, because `ResetInactive` resets the state again.
|
||||||
pallet_balances::migration::MigrateToTrackInactive<Runtime, xcm_config::CheckAccount>,
|
pallet_balances::migration::MigrateToTrackInactive<Runtime, xcm_config::CheckAccount>,
|
||||||
crowdloan::migration::MigrateToTrackInactive<Runtime>,
|
crowdloan::migration::MigrateToTrackInactiveV2<Runtime>,
|
||||||
pallet_scheduler::migration::v4::CleanupAgendas<Runtime>,
|
pallet_scheduler::migration::v4::CleanupAgendas<Runtime>,
|
||||||
parachains_disputes::migration::v1::MigrateToV1<Runtime>,
|
parachains_disputes::migration::v1::MigrateToV1<Runtime>,
|
||||||
parachains_configuration::migration::v4::MigrateToV4<Runtime>,
|
parachains_configuration::migration::v4::MigrateToV4<Runtime>,
|
||||||
|
|||||||
@@ -1215,8 +1215,10 @@ impl Get<&'static str> for StakingMigrationV11OldPallet {
|
|||||||
///
|
///
|
||||||
/// Should be cleared after every release.
|
/// Should be cleared after every release.
|
||||||
pub type Migrations = (
|
pub type Migrations = (
|
||||||
|
pallet_balances::migration::ResetInactive<Runtime>,
|
||||||
|
// We need to apply this migration again, because `ResetInactive` resets the state again.
|
||||||
pallet_balances::migration::MigrateToTrackInactive<Runtime, xcm_config::CheckAccount>,
|
pallet_balances::migration::MigrateToTrackInactive<Runtime, xcm_config::CheckAccount>,
|
||||||
crowdloan::migration::MigrateToTrackInactive<Runtime>,
|
crowdloan::migration::MigrateToTrackInactiveV2<Runtime>,
|
||||||
pallet_scheduler::migration::v4::CleanupAgendas<Runtime>,
|
pallet_scheduler::migration::v4::CleanupAgendas<Runtime>,
|
||||||
pallet_staking::migrations::v13::MigrateToV13<Runtime>,
|
pallet_staking::migrations::v13::MigrateToV13<Runtime>,
|
||||||
parachains_disputes::migration::v1::MigrateToV1<Runtime>,
|
parachains_disputes::migration::v1::MigrateToV1<Runtime>,
|
||||||
|
|||||||
Reference in New Issue
Block a user