Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Improve inactive fund tracking #13009

Merged
merged 4 commits into from
Dec 27, 2022
Merged

Improve inactive fund tracking #13009

merged 4 commits into from
Dec 27, 2022

Conversation

gavofyork
Copy link
Member

@gavofyork gavofyork commented Dec 22, 2022

TODO

  • Introduce migration to set total inactive balance to zero.
  • Introduce migration to set treasury inactive balance to zero.

@github-actions github-actions bot added the A0-please_review Pull request needs code review. label Dec 22, 2022
@gavofyork gavofyork added B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit A0-please_review Pull request needs code review. and removed A0-please_review Pull request needs code review. labels Dec 22, 2022
Comment on lines +79 to +83
// Remove the old `StorageVersion` type.
frame_support::storage::unhashed::kill(&frame_support::storage::storage_prefix(
Pallet::<T, I>::name().as_bytes(),
"StorageVersion".as_bytes(),
));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Remove the old `StorageVersion` type.
frame_support::storage::unhashed::kill(&frame_support::storage::storage_prefix(
Pallet::<T, I>::name().as_bytes(),
"StorageVersion".as_bytes(),
));

Should have a proper storage version now since it is at version 1.

Copy link
Member

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

Copy link
Member Author

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.

Inactive::<T, I>::put(&pot);
T::Currency::reactivate(deactivated);
T::Currency::deactivate(pot);
Deactivated::<T, I>::put(&pot);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also kill the Inactive here as cleanup?

Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The 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.
IIUC on the next run the Deactivated will be zero, so the whole pot will be deactivated, which is fine since the foregoing balances migration will reset all deactivated funds.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also kill the Inactive here as cleanup?

Let's delete it in a migration so that it happens once, not in on_init.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since it was faultily implemented the first time.

What's the case case where the old logic was wrong?

Copy link
Member Author

Choose a reason for hiding this comment

The 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

InactiveIssuance::<T, I>::kill();

// Set storage version to `0`.
StorageVersion::new(0).put::<Pallet<T, I>>();
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Member

@ggwpez ggwpez Dec 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a trick so that the MigrateToTrackInactive v0 -> v1 migration can run again.

Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 is defined as "not tracking InactiveIssuance", 1 is defined as "tracking InactiveIssuance". In Polkadot/Kusama mainnet (which are already at version 1), we are migrating back to 0 and thus no longer tracking InactiveIssuance, and then migrating back to 1 (and thus tracking it, this time correctly). There are no new alterations to storage formats or indeed state transition semantics, and thus it makes no sense to introduce new StorageVersions which would in all manner be exactly equivalent to the existing StorageVersions. The only thing we are doing is mending state.

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a little questions, but looks good!

@gavofyork gavofyork merged commit d2ef4b0 into master Dec 27, 2022
@gavofyork gavofyork deleted the gav-better-fund-tracking branch December 27, 2022 13:48
rossbulat pushed a commit that referenced this pull request Dec 28, 2022
* Improve inactive fund tracking

* Resetting migration

* Fix

* Update frame/balances/src/migration.rs
@Polkadot-Forum
Copy link

This pull request has been mentioned on Polkadot Forum. There might be relevant details there:

https://forum.polkadot.network/t/polkadot-release-analysis-v0-9-37/1736/1

ltfschoen pushed a commit to ltfschoen/substrate that referenced this pull request Feb 22, 2023
* Improve inactive fund tracking

* Resetting migration

* Fix

* Update frame/balances/src/migration.rs
ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
* Improve inactive fund tracking

* Resetting migration

* Fix

* Update frame/balances/src/migration.rs
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants