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

Introduces account existence providers reference counting #7363

Merged
merged 64 commits into from
Jan 16, 2021

Conversation

gavofyork
Copy link
Member

@gavofyork gavofyork commented Oct 20, 2020

Fixes #7343

Polkadot companion: paritytech/polkadot#2152

@gavofyork gavofyork added A3-in_progress Pull request is in progress. No review needed at this stage. B3-apinoteworthy C1-low PR touches the given topic and has a low impact on builders. labels Oct 20, 2020
/// An abstraction of a value stored within storage, but possibly as part of a larger composite
/// item.
pub trait StoredMap<K, T> {
pub trait StoredMap<K, T: Default> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it really necessary to have T: Default?

Copy link
Member Author

@gavofyork gavofyork Nov 9, 2020

Choose a reason for hiding this comment

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

Basically there must be a way to determine whether the value is set or not, since the account item can now exist without the data being set (via some external existential provider, unlike before). Two other options are to make it require an IsProvided trait or to store the data under an Option. The latter would require an additional migration (😕). And I generally try to avoid introducing extra traits.

Copy link
Contributor

Choose a reason for hiding this comment

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

afaik, change storage from non option type to option type does not require migration. Option wrapping is handled by the decl_storage macro.

Copy link
Member

Choose a reason for hiding this comment

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

+1 that option should not change the underlying storage

Copy link
Member Author

Choose a reason for hiding this comment

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

The option would not be for a storage item itself, but rather an inner component of a storage item's structure. Concretely, it would be the data field of the frame_system::AccountInfo (i.e. T::AccountData) which would need to become an Option, which would require a migration.

/// Maybe mutate the item only if an `Ok` value is returned from `f`. Do nothing if an `Err` is
/// returned. It is removed or reset to default value if it has been mutated to `None`
fn try_mutate_exists<R, E>(k: &K, f: impl FnOnce(&mut Option<T>) -> Result<R, E>) -> Result<R, E>;
fn try_mutate_exists<R, E: From<StoredMapError>>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe should add associated type type Error to avoid hard dependency on StoredMapError here? Otherwise it feels bit too coupled with the frame system implementation.

Copy link
Member Author

Choose a reason for hiding this comment

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

No - need to be like this otherwise it cannot support this error assimilation API.

frame/support/src/traits.rs Show resolved Hide resolved
frame/support/src/traits.rs Show resolved Hide resolved
frame/support/src/traits.rs Show resolved Hide resolved
frame/support/src/traits.rs Show resolved Hide resolved
@@ -461,6 +464,10 @@ decl_storage! {
/// True if we have upgraded so that `type RefCount` is `u32`. False (default) if not.
UpgradedToU32RefCount build(|_| true): bool;

/// True if we have upgraded so that AccountInfo contains two types of `RefCount`. False
/// (default) if not.
UpgradedToDualRefCount build(|_| true): bool;
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: you can use the pallet storage version now.

Copy link
Contributor

@gui1117 gui1117 Dec 17, 2020

Choose a reason for hiding this comment

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

IMHO best would be to have an isolated function which does this migration, and we can also do a version bump.
the isolated function wouldn't depend on system so that there is no burden to maintain it.

Similarly to https://github.com/paritytech/substrate/pull/7040/files#diff-3acd0cb73093b0cc01acfd0dc5646b31a309e57526f18d67d7e9d8708c325dbb

I understand it is less handy for polkadot so I'm ok to have it as it is now. But from a substrate perspective having an isolated code anyone can pickup is better, than a inline migration which will be removed after polkadot runtime upgrades, or removed when it start being annoying to maintain.

Copy link
Member Author

Choose a reason for hiding this comment

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

Isolated function is done.

@xlc
Copy link
Contributor

xlc commented Nov 26, 2020

Any updates on this? We would love this use this feature as soon as possible.

Copy link

@smisty smisty left a comment

Choose a reason for hiding this comment

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

What's go in on

@gavofyork gavofyork added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Dec 9, 2020
@gavofyork gavofyork marked this pull request as ready for review December 9, 2020 13:55
@gui1117 gui1117 mentioned this pull request Jan 4, 2021
5 tasks
frame/system/src/lib.rs Outdated Show resolved Hide resolved
gavofyork and others added 3 commits January 9, 2021 16:06
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.

Had one last brief look and LGTM.

@gavofyork gavofyork merged commit 7a79f54 into master Jan 16, 2021
@gavofyork gavofyork deleted the gav-account-provider-refs branch January 16, 2021 17:47
@s3krit s3krit added the D1-audited 👍 PR contains changes to fund-managing logic that has been properly reviewed and externally audited label Feb 2, 2021
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. C1-low PR touches the given topic and has a low impact on builders. D1-audited 👍 PR contains changes to fund-managing logic that has been properly reviewed and externally audited
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provider ref count
9 participants