Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Identity] Decouple usernames from identities #5554

Open
wants to merge 51 commits into
base: master
Choose a base branch
from

Conversation

georgepisaltu
Copy link
Contributor

This PR refactors pallet-identity to decouple usernames from identities.

Main changes in this PR:

  • Separate usernames from identities in storage, allowing for correct deposit accounting
  • Introduce the option for username authorities to put up a deposit to issue a username
  • Allow authorities to remove usernames by declaring the intent to do so, then removing the username after the grace period expires
  • Refactor the authority storage to be keyed by suffix rather than owner account.
  • Introduce the concept of a system provider for a username, different from a governance allocation, allowing for usernames set by the system and not a specific authority
  • Implement multi-block migration to enable all of the changes described above

Signed-off-by: georgepisaltu <[email protected]>
Signed-off-by: georgepisaltu <[email protected]>
Signed-off-by: georgepisaltu <[email protected]>
Signed-off-by: georgepisaltu <[email protected]>
Signed-off-by: georgepisaltu <[email protected]>
Signed-off-by: georgepisaltu <[email protected]>
Signed-off-by: georgepisaltu <[email protected]>
Signed-off-by: georgepisaltu <[email protected]>
Signed-off-by: georgepisaltu <[email protected]>
Signed-off-by: georgepisaltu <[email protected]>
Signed-off-by: georgepisaltu <[email protected]>
Signed-off-by: georgepisaltu <[email protected]>
Signed-off-by: georgepisaltu <[email protected]>
Signed-off-by: georgepisaltu <[email protected]>
Signed-off-by: georgepisaltu <[email protected]>
Signed-off-by: georgepisaltu <[email protected]>
Signed-off-by: georgepisaltu <[email protected]>
Signed-off-by: georgepisaltu <[email protected]>
@georgepisaltu georgepisaltu added the T2-pallets This PR/Issue is related to a particular pallet. label Sep 2, 2024
@georgepisaltu georgepisaltu self-assigned this Sep 2, 2024
@georgepisaltu georgepisaltu requested a review from a team as a code owner September 2, 2024 16:46
@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: test-linux-stable-int
Logs: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7222927

@paritytech-review-bot paritytech-review-bot bot requested a review from a team September 10, 2024 16:03
@paritytech-review-bot paritytech-review-bot bot requested a review from a team September 11, 2024 09:38
Signed-off-by: georgepisaltu <[email protected]>
Signed-off-by: georgepisaltu <[email protected]>
Signed-off-by: georgepisaltu <[email protected]>
substrate/frame/identity/README.md Outdated Show resolved Hide resolved
polkadot/runtime/westend/src/lib.rs Show resolved Hide resolved
},
Provider::Allocation => {
// We don't refund the allocation, it is lost, but we refund some weight.
T::WeightInfo::remove_expired_approval(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe having some const or enum instead of 0 and 1 would make it more readable.

But it is good to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could just pass the Provider Enum? Similarly in other places.

@@ -265,33 +297,47 @@ pub mod pallet {

/// A map of the accounts who are authorized to grant usernames.
#[pallet::storage]
pub type UsernameAuthorities<T: Config> =
StorageMap<_, Twox64Concat, T::AccountId, AuthorityPropertiesOf<T>, OptionQuery>;
pub type AuthorityOf<T: Config> =
Copy link
Contributor

Choose a reason for hiding this comment

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

This implies for a given suffix, there can be only one authority? Wasn't clear from the docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, one authority per suffix. I will update the docs.

/// A username has been removed.
UsernameRemoved { username: Username<T> },
/// A username has been killed.
UsernameKilled { username: Username<T> },
Copy link
Contributor

Choose a reason for hiding this comment

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

UsernameRemoved and UsernameKilled sounds very synonymous. May be should call it as ForceUsernameRemoved?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From pallet terminology in docs, "removed" and "killed" are different things. I'd prefer to stick to even naming convention of 2 word events and defer to call documentation. I could write more comprehensive docs for the event enum variants.

Comment on lines 1075 to 1076
// The authority may already exist, but we don't need to check. They might be changing
// their suffix or adding allocation, so we just want to overwrite whatever was there.
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment needs to be updated.
Do we still don't need to check for overwrite? This might be overwriting authority for a given suffix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll rethink this section.

@@ -1041,11 +1087,15 @@ pub mod pallet {
#[pallet::weight(T::WeightInfo::remove_username_authority())]
pub fn remove_username_authority(
origin: OriginFor<T>,
suffix: Vec<u8>,
authority: AccountIdLookupOf<T>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't strictly need authority as input anymore. But fine either way.

pub fn set_username_for(
origin: OriginFor<T>,
who: AccountIdLookupOf<T>,
username: Vec<u8>,
signature: Option<T::OffchainSignature>,
use_allocation: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

Update fn rustdoc about use_allocation flag? Currently it only says authority must have an allocation.

},
Provider::Allocation => {
// We don't refund the allocation, it is lost, but we refund some weight.
T::WeightInfo::remove_expired_approval(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could just pass the Provider Enum? Similarly in other places.

Signed-off-by: georgepisaltu <[email protected]>
Copy link
Contributor

@gui1117 gui1117 left a comment

Choose a reason for hiding this comment

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

Looks good to me

substrate/frame/identity/src/lib.rs Outdated Show resolved Hide resolved
@georgepisaltu
Copy link
Contributor Author

I implemented the try-runtime checks.

There is a unit test for the migration and I manually tested the try-runtime checks with the changes in paritytech/try-runtime-cli#90. They probably don't pass in the CI here but they passed for me locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T2-pallets This PR/Issue is related to a particular pallet.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants