-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Improve inactive fund tracking #13009
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,3 +69,29 @@ impl<T: Config<I>, A: Get<Vec<T::AccountId>>, I: 'static> OnRuntimeUpgrade | |
migrate_v0_to_v1::<T, I>(&A::get()) | ||
} | ||
} | ||
|
||
pub struct ResetInactive<T, I = ()>(PhantomData<(T, I)>); | ||
impl<T: Config<I>, I: 'static> OnRuntimeUpgrade for ResetInactive<T, I> { | ||
fn on_runtime_upgrade() -> Weight { | ||
let onchain_version = Pallet::<T, I>::on_chain_storage_version(); | ||
|
||
if onchain_version == 1 { | ||
// Remove the old `StorageVersion` type. | ||
frame_support::storage::unhashed::kill(&frame_support::storage::storage_prefix( | ||
Pallet::<T, I>::name().as_bytes(), | ||
"StorageVersion".as_bytes(), | ||
)); | ||
|
||
InactiveIssuance::<T, I>::kill(); | ||
|
||
// Set storage version to `0`. | ||
StorageVersion::new(0).put::<Pallet<T, I>>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ggwpez If we're at version 1 now, then it doesn't quite make sense to regress and go back to version 0? Or are we really treating this all as a revert? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a trick so that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we not just write a proper migration for this? And introduce storage Version 2? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 0 is defined as "not tracking There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, from the PoV of Polkadot/Kusama this makes sense. However, we should write these migrations in a generic way so that other downstream users (e.g. parachain teams) can use them as well. There could at least have been some docs on what this migration does and that it should be executed before the other migration. |
||
|
||
log::info!(target: "runtime::balances", "Storage to version 0"); | ||
T::DbWeight::get().reads_writes(1, 2) | ||
} else { | ||
log::info!(target: "runtime::balances", "Migration did not execute. This probably should be removed"); | ||
T::DbWeight::get().reads(1) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -225,7 +225,8 @@ pub mod pallet { | |
|
||
/// The amount which has been reported as inactive to Currency. | ||
#[pallet::storage] | ||
pub type Inactive<T: Config<I>, I: 'static = ()> = StorageValue<_, BalanceOf<T, I>, ValueQuery>; | ||
pub type Deactivated<T: Config<I>, I: 'static = ()> = | ||
StorageValue<_, BalanceOf<T, I>, ValueQuery>; | ||
|
||
/// Proposal indices that have been approved but not yet awarded. | ||
#[pallet::storage] | ||
|
@@ -292,6 +293,8 @@ pub mod pallet { | |
amount: BalanceOf<T, I>, | ||
beneficiary: T::AccountId, | ||
}, | ||
/// The inactive funds of the pallet have been updated. | ||
UpdatedInactive { reactivated: BalanceOf<T, I>, deactivated: BalanceOf<T, I> }, | ||
} | ||
|
||
/// Error for the treasury pallet. | ||
|
@@ -321,13 +324,15 @@ pub mod pallet { | |
/// # </weight> | ||
fn on_initialize(n: T::BlockNumber) -> Weight { | ||
let pot = Self::pot(); | ||
let deactivated = Inactive::<T, I>::get(); | ||
let deactivated = Deactivated::<T, I>::get(); | ||
if pot != deactivated { | ||
match (pot > deactivated, pot.max(deactivated) - pot.min(deactivated)) { | ||
(true, delta) => T::Currency::deactivate(delta), | ||
(false, delta) => T::Currency::reactivate(delta), | ||
} | ||
Inactive::<T, I>::put(&pot); | ||
T::Currency::reactivate(deactivated); | ||
T::Currency::deactivate(pot); | ||
Deactivated::<T, I>::put(&pot); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also kill the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm actually unsure what the implications are for changing the logic here. Is it simply just reverting code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its undoing and fixing the fund-deactivation since it was faultily implemented the first time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Let's delete it in a migration so that it happens once, not in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
What's the case case where the old logic was wrong? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect logic was in crowdloan where a datatype was being misused. See paritytech/polkadot#6471 |
||
Self::deposit_event(Event::<T, I>::UpdatedInactive { | ||
reactivated: deactivated, | ||
deactivated: pot, | ||
}); | ||
} | ||
|
||
// Check to see if we should spend some funds! | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have a proper storage version now since it is at version
1
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also wrong. The key is not StorageVersion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was old code. AFAIK it should do no harm.