From 683e44bb8618d65405e2322b3fa0dafa020a9657 Mon Sep 17 00:00:00 2001 From: georgepisaltu <george.pisaltu@parity.io> Date: Fri, 15 Sep 2023 18:06:58 +0300 Subject: [PATCH 01/14] Make identity info generic in pallet config Signed-off-by: georgepisaltu <george.pisaltu@parity.io> --- substrate/frame/identity/src/lib.rs | 95 +++++----- substrate/frame/identity/src/simple.rs | 124 +++++++++++++ substrate/frame/identity/src/types.rs | 229 +++++++------------------ 3 files changed, 229 insertions(+), 219 deletions(-) create mode 100644 substrate/frame/identity/src/simple.rs diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index f192ee2b461b3..e005bfafed22a 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -73,6 +73,7 @@ #![cfg_attr(not(feature = "std"), no_std)] mod benchmarking; +mod simple; #[cfg(test)] mod tests; mod types; @@ -81,13 +82,11 @@ pub mod weights; use frame_support::traits::{BalanceStatus, Currency, OnUnbalanced, ReservableCurrency}; use sp_runtime::traits::{AppendZerosInput, Hash, Saturating, StaticLookup, Zero}; use sp_std::prelude::*; +use types::IdentityInformationProvider; pub use weights::WeightInfo; pub use pallet::*; -pub use types::{ - Data, IdentityField, IdentityFields, IdentityInfo, Judgement, RegistrarIndex, RegistrarInfo, - Registration, -}; +pub use types::{Data, IdentityFields, Judgement, RegistrarIndex, RegistrarInfo, Registration}; type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance; @@ -98,6 +97,8 @@ type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup #[frame_support::pallet] pub mod pallet { + use crate::types::{IdentityFieldProvider, IdentityInformationProvider}; + use super::*; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; @@ -114,10 +115,6 @@ pub mod pallet { #[pallet::constant] type BasicDeposit: Get<BalanceOf<Self>>; - /// The amount held on deposit per additional field for a registered identity. - #[pallet::constant] - type FieldDeposit: Get<BalanceOf<Self>>; - /// The amount held on deposit for a registered subaccount. This should account for the fact /// that one storage item's value will increase by the size of an account ID, and there will /// be another trie item whose value is the size of an account ID plus 32 bytes. @@ -130,8 +127,10 @@ pub mod pallet { /// Maximum number of additional fields that may be stored in an ID. Needed to bound the I/O /// required to access an identity, but can be pretty high. - #[pallet::constant] - type MaxAdditionalFields: Get<u32>; + type IdentityInformation: IdentityInformationProvider; + + /// TODO + type IdentityField: IdentityFieldProvider; /// Maxmimum number of registrars allowed in the system. Needed to bound the complexity /// of, e.g., updating judgements. @@ -163,7 +162,7 @@ pub mod pallet { _, Twox64Concat, T::AccountId, - Registration<BalanceOf<T>, T::MaxRegistrars, T::MaxAdditionalFields>, + Registration<BalanceOf<T>, T::MaxRegistrars, T::IdentityInformation>, OptionQuery, >; @@ -197,7 +196,10 @@ pub mod pallet { #[pallet::getter(fn registrars)] pub(super) type Registrars<T: Config> = StorageValue< _, - BoundedVec<Option<RegistrarInfo<BalanceOf<T>, T::AccountId>>, T::MaxRegistrars>, + BoundedVec< + Option<RegistrarInfo<BalanceOf<T>, T::AccountId, T::IdentityField>>, + T::MaxRegistrars, + >, ValueQuery, >; @@ -325,48 +327,34 @@ pub mod pallet { #[pallet::call_index(1)] #[pallet::weight( T::WeightInfo::set_identity( T::MaxRegistrars::get(), // R - T::MaxAdditionalFields::get(), // X + 0, // X ))] pub fn set_identity( origin: OriginFor<T>, - info: Box<IdentityInfo<T::MaxAdditionalFields>>, + info: Box<T::IdentityInformation>, ) -> DispatchResultWithPostInfo { let sender = ensure_signed(origin)?; - let extra_fields = info.additional.len() as u32; - ensure!(extra_fields <= T::MaxAdditionalFields::get(), Error::<T>::TooManyFields); - let fd = <BalanceOf<T>>::from(extra_fields) * T::FieldDeposit::get(); - let mut id = match <IdentityOf<T>>::get(&sender) { + let id = match <IdentityOf<T>>::get(&sender) { Some(mut id) => { // Only keep non-positive judgements. id.judgements.retain(|j| j.1.is_sticky()); id.info = *info; id }, - None => Registration { - info: *info, - judgements: BoundedVec::default(), - deposit: Zero::zero(), + None => { + T::Currency::reserve(&sender, T::BasicDeposit::get())?; + Registration { info: *info, judgements: BoundedVec::default() } }, }; - let old_deposit = id.deposit; - id.deposit = T::BasicDeposit::get() + fd; - if id.deposit > old_deposit { - T::Currency::reserve(&sender, id.deposit - old_deposit)?; - } - if old_deposit > id.deposit { - let err_amount = T::Currency::unreserve(&sender, old_deposit - id.deposit); - debug_assert!(err_amount.is_zero()); - } - let judgements = id.judgements.len(); <IdentityOf<T>>::insert(&sender, id); Self::deposit_event(Event::IdentitySet { who: sender }); Ok(Some(T::WeightInfo::set_identity( judgements as u32, // R - extra_fields, // X + 0, // X )) .into()) } @@ -463,14 +451,14 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::clear_identity( T::MaxRegistrars::get(), // R T::MaxSubAccounts::get(), // S - T::MaxAdditionalFields::get(), // X + 0, // X ))] pub fn clear_identity(origin: OriginFor<T>) -> DispatchResultWithPostInfo { let sender = ensure_signed(origin)?; let (subs_deposit, sub_ids) = <SubsOf<T>>::take(&sender); let id = <IdentityOf<T>>::take(&sender).ok_or(Error::<T>::NotNamed)?; - let deposit = id.total_deposit() + subs_deposit; + let deposit = T::BasicDeposit::get() + subs_deposit; for sub in sub_ids.iter() { <SuperOf<T>>::remove(sub); } @@ -481,9 +469,9 @@ pub mod pallet { Self::deposit_event(Event::IdentityCleared { who: sender, deposit }); Ok(Some(T::WeightInfo::clear_identity( - id.judgements.len() as u32, // R - sub_ids.len() as u32, // S - id.info.additional.len() as u32, // X + id.judgements.len() as u32, // R + sub_ids.len() as u32, // S + 0, // X )) .into()) } @@ -512,7 +500,7 @@ pub mod pallet { #[pallet::call_index(4)] #[pallet::weight(T::WeightInfo::request_judgement( T::MaxRegistrars::get(), // R - T::MaxAdditionalFields::get(), // X + 0, // X ))] pub fn request_judgement( origin: OriginFor<T>, @@ -543,7 +531,6 @@ pub mod pallet { T::Currency::reserve(&sender, registrar.fee)?; let judgements = id.judgements.len(); - let extra_fields = id.info.additional.len(); <IdentityOf<T>>::insert(&sender, id); Self::deposit_event(Event::JudgementRequested { @@ -551,8 +538,7 @@ pub mod pallet { registrar_index: reg_index, }); - Ok(Some(T::WeightInfo::request_judgement(judgements as u32, extra_fields as u32)) - .into()) + Ok(Some(T::WeightInfo::request_judgement(judgements as u32, 0)).into()) } /// Cancel a previous request. @@ -573,7 +559,7 @@ pub mod pallet { #[pallet::call_index(5)] #[pallet::weight(T::WeightInfo::cancel_request( T::MaxRegistrars::get(), // R - T::MaxAdditionalFields::get(), // X + 0, // X ))] pub fn cancel_request( origin: OriginFor<T>, @@ -595,7 +581,6 @@ pub mod pallet { let err_amount = T::Currency::unreserve(&sender, fee); debug_assert!(err_amount.is_zero()); let judgements = id.judgements.len(); - let extra_fields = id.info.additional.len(); <IdentityOf<T>>::insert(&sender, id); Self::deposit_event(Event::JudgementUnrequested { @@ -603,7 +588,7 @@ pub mod pallet { registrar_index: reg_index, }); - Ok(Some(T::WeightInfo::cancel_request(judgements as u32, extra_fields as u32)).into()) + Ok(Some(T::WeightInfo::cancel_request(judgements as u32, 0)).into()) } /// Set the fee required for a judgement to be requested from a registrar. @@ -697,7 +682,7 @@ pub mod pallet { pub fn set_fields( origin: OriginFor<T>, #[pallet::compact] index: RegistrarIndex, - fields: IdentityFields, + fields: IdentityFields<T::IdentityField>, ) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; @@ -741,7 +726,7 @@ pub mod pallet { #[pallet::call_index(9)] #[pallet::weight(T::WeightInfo::provide_judgement( T::MaxRegistrars::get(), // R - T::MaxAdditionalFields::get(), // X + 0, // X ))] pub fn provide_judgement( origin: OriginFor<T>, @@ -785,12 +770,10 @@ pub mod pallet { } let judgements = id.judgements.len(); - let extra_fields = id.info.additional.len(); <IdentityOf<T>>::insert(&target, id); Self::deposit_event(Event::JudgementGiven { target, registrar_index: reg_index }); - Ok(Some(T::WeightInfo::provide_judgement(judgements as u32, extra_fields as u32)) - .into()) + Ok(Some(T::WeightInfo::provide_judgement(judgements as u32, 0)).into()) } /// Remove an account's identity and sub-account information and slash the deposits. @@ -815,7 +798,7 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::kill_identity( T::MaxRegistrars::get(), // R T::MaxSubAccounts::get(), // S - T::MaxAdditionalFields::get(), // X + 0, // X ))] pub fn kill_identity( origin: OriginFor<T>, @@ -828,7 +811,7 @@ pub mod pallet { // Grab their deposit (and check that they have one). let (subs_deposit, sub_ids) = <SubsOf<T>>::take(&target); let id = <IdentityOf<T>>::take(&target).ok_or(Error::<T>::NotNamed)?; - let deposit = id.total_deposit() + subs_deposit; + let deposit = T::BasicDeposit::get() + subs_deposit; for sub in sub_ids.iter() { <SuperOf<T>>::remove(sub); } @@ -838,9 +821,9 @@ pub mod pallet { Self::deposit_event(Event::IdentityKilled { who: target, deposit }); Ok(Some(T::WeightInfo::kill_identity( - id.judgements.len() as u32, // R - sub_ids.len() as u32, // S - id.info.additional.len() as u32, // X + id.judgements.len() as u32, // R + sub_ids.len() as u32, // S + 0, // X )) .into()) } @@ -975,6 +958,6 @@ impl<T: Config> Pallet<T> { /// Check if the account has corresponding identity information by the identity field. pub fn has_identity(who: &T::AccountId, fields: u64) -> bool { IdentityOf::<T>::get(who) - .map_or(false, |registration| (registration.info.fields().0.bits() & fields) == fields) + .map_or(false, |registration| (registration.info.has_identity(fields))) } } diff --git a/substrate/frame/identity/src/simple.rs b/substrate/frame/identity/src/simple.rs new file mode 100644 index 0000000000000..393156319f4a0 --- /dev/null +++ b/substrate/frame/identity/src/simple.rs @@ -0,0 +1,124 @@ +// This file is part of Substrate. + +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use codec::{Decode, Encode, MaxEncodedLen}; +use enumflags2::{bitflags, BitFlags}; +use scale_info::TypeInfo; +use sp_runtime::RuntimeDebug; +use sp_std::prelude::*; + +use crate::types::{Data, IdentityFieldProvider, IdentityFields, U64BitFlag}; + +/// The fields that we use to identify the owner of an account with. Each corresponds to a field +/// in the `IdentityInfo` struct. +#[bitflags] +#[repr(u64)] +#[derive(Encode, Decode, MaxEncodedLen, Clone, Copy, PartialEq, Eq, RuntimeDebug, TypeInfo)] +pub enum IdentityField { + Display = 0b0000000000000000000000000000000000000000000000000000000000000001, + Legal = 0b0000000000000000000000000000000000000000000000000000000000000010, + Web = 0b0000000000000000000000000000000000000000000000000000000000000100, + Riot = 0b0000000000000000000000000000000000000000000000000000000000001000, + Email = 0b0000000000000000000000000000000000000000000000000000000000010000, + PgpFingerprint = 0b0000000000000000000000000000000000000000000000000000000000100000, + Image = 0b0000000000000000000000000000000000000000000000000000000001000000, + Twitter = 0b0000000000000000000000000000000000000000000000000000000010000000, +} + +impl U64BitFlag for IdentityField {} +impl IdentityFieldProvider for IdentityField {} + +/// Information concerning the identity of the controller of an account. +/// +/// NOTE: This should be stored at the end of the storage item to facilitate the addition of extra +/// fields in a backwards compatible way through a specialized `Decode` impl. +#[derive(Clone, Encode, Decode, Eq, MaxEncodedLen, PartialEq, RuntimeDebug, TypeInfo)] +#[codec(mel_bound())] +#[cfg_attr(test, derive(frame_support::Default))] +pub struct IdentityInfo { + /// A reasonable display name for the controller of the account. This should be whatever it is + /// that it is typically known as and should not be confusable with other entities, given + /// reasonable context. + /// + /// Stored as UTF-8. + pub display: Data, + + /// The full legal name in the local jurisdiction of the entity. This might be a bit + /// long-winded. + /// + /// Stored as UTF-8. + pub legal: Data, + + /// A representative website held by the controller of the account. + /// + /// NOTE: `https://` is automatically prepended. + /// + /// Stored as UTF-8. + pub web: Data, + + /// The Riot/Matrix handle held by the controller of the account. + /// + /// Stored as UTF-8. + pub riot: Data, + + /// The email address of the controller of the account. + /// + /// Stored as UTF-8. + pub email: Data, + + /// The PGP/GPG public key of the controller of the account. + pub pgp_fingerprint: Option<[u8; 20]>, + + /// A graphic image representing the controller of the account. Should be a company, + /// organization or project logo or a headshot in the case of a human. + pub image: Data, + + /// The Twitter identity. The leading `@` character may be elided. + pub twitter: Data, +} + +impl IdentityInfo { + #[allow(unused)] + pub(crate) fn fields(&self) -> IdentityFields<IdentityField> { + let mut res = <BitFlags<IdentityField>>::empty(); + if !self.display.is_none() { + res.insert(IdentityField::Display); + } + if !self.legal.is_none() { + res.insert(IdentityField::Legal); + } + if !self.web.is_none() { + res.insert(IdentityField::Web); + } + if !self.riot.is_none() { + res.insert(IdentityField::Riot); + } + if !self.email.is_none() { + res.insert(IdentityField::Email); + } + if self.pgp_fingerprint.is_some() { + res.insert(IdentityField::PgpFingerprint); + } + if !self.image.is_none() { + res.insert(IdentityField::Image); + } + if !self.twitter.is_none() { + res.insert(IdentityField::Twitter); + } + IdentityFields(res) + } +} diff --git a/substrate/frame/identity/src/types.rs b/substrate/frame/identity/src/types.rs index 1837b30b027f9..ab8034c73c492 100644 --- a/substrate/frame/identity/src/types.rs +++ b/substrate/frame/identity/src/types.rs @@ -17,7 +17,7 @@ use super::*; use codec::{Decode, Encode, MaxEncodedLen}; -use enumflags2::{bitflags, BitFlags}; +use enumflags2::{BitFlag, BitFlags, _internal::RawBitFlags}; use frame_support::{ traits::{ConstU32, Get}, BoundedVec, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, @@ -26,8 +26,13 @@ use scale_info::{ build::{Fields, Variants}, meta_type, Path, Type, TypeInfo, TypeParameter, }; -use sp_runtime::{traits::Zero, RuntimeDebug}; -use sp_std::{fmt::Debug, iter::once, ops::Add, prelude::*}; +use sp_runtime::RuntimeDebug; +use sp_std::{fmt::Debug, iter::once, prelude::*}; + +/// An identifier for a single name registrar/identity verification service. +pub type RegistrarIndex = u32; + +pub trait U64BitFlag: BitFlag + RawBitFlags<Numeric = u64> {} /// Either underlying data blob if it is at most 32 bytes, or a hash of it. If the data is greater /// than 32-bytes then it will be truncated when encoding. @@ -180,9 +185,6 @@ impl Default for Data { } } -/// An identifier for a single name registrar/identity verification service. -pub type RegistrarIndex = u32; - /// An attestation of a registrar over how accurate some `IdentityInfo` is in describing an account. /// /// NOTE: Registrars may pay little attention to some fields. Registrars may want to make clear @@ -228,140 +230,15 @@ impl<Balance: Encode + Decode + MaxEncodedLen + Copy + Clone + Debug + Eq + Part } } -/// The fields that we use to identify the owner of an account with. Each corresponds to a field -/// in the `IdentityInfo` struct. -#[bitflags] -#[repr(u64)] -#[derive(Clone, Copy, PartialEq, Eq, RuntimeDebug, TypeInfo)] -pub enum IdentityField { - Display = 0b0000000000000000000000000000000000000000000000000000000000000001, - Legal = 0b0000000000000000000000000000000000000000000000000000000000000010, - Web = 0b0000000000000000000000000000000000000000000000000000000000000100, - Riot = 0b0000000000000000000000000000000000000000000000000000000000001000, - Email = 0b0000000000000000000000000000000000000000000000000000000000010000, - PgpFingerprint = 0b0000000000000000000000000000000000000000000000000000000000100000, - Image = 0b0000000000000000000000000000000000000000000000000000000001000000, - Twitter = 0b0000000000000000000000000000000000000000000000000000000010000000, -} - -/// Wrapper type for `BitFlags<IdentityField>` that implements `Codec`. -#[derive(Clone, Copy, PartialEq, Default, RuntimeDebug)] -pub struct IdentityFields(pub BitFlags<IdentityField>); - -impl MaxEncodedLen for IdentityFields { - fn max_encoded_len() -> usize { - u64::max_encoded_len() - } -} - -impl Eq for IdentityFields {} -impl Encode for IdentityFields { - fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R { - self.0.bits().using_encoded(f) - } -} -impl Decode for IdentityFields { - fn decode<I: codec::Input>(input: &mut I) -> sp_std::result::Result<Self, codec::Error> { - let field = u64::decode(input)?; - Ok(Self(<BitFlags<IdentityField>>::from_bits(field as u64).map_err(|_| "invalid value")?)) - } -} -impl TypeInfo for IdentityFields { - type Identity = Self; - - fn type_info() -> Type { - Type::builder() - .path(Path::new("BitFlags", module_path!())) - .type_params(vec![TypeParameter::new("T", Some(meta_type::<IdentityField>()))]) - .composite(Fields::unnamed().field(|f| f.ty::<u64>().type_name("IdentityField"))) - } -} - -/// Information concerning the identity of the controller of an account. -/// -/// NOTE: This should be stored at the end of the storage item to facilitate the addition of extra -/// fields in a backwards compatible way through a specialized `Decode` impl. -#[derive( - CloneNoBound, Encode, Decode, Eq, MaxEncodedLen, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, -)] -#[codec(mel_bound())] -#[cfg_attr(test, derive(frame_support::DefaultNoBound))] -#[scale_info(skip_type_params(FieldLimit))] -pub struct IdentityInfo<FieldLimit: Get<u32>> { - /// Additional fields of the identity that are not catered for with the struct's explicit - /// fields. - pub additional: BoundedVec<(Data, Data), FieldLimit>, - - /// A reasonable display name for the controller of the account. This should be whatever it is - /// that it is typically known as and should not be confusable with other entities, given - /// reasonable context. - /// - /// Stored as UTF-8. - pub display: Data, - - /// The full legal name in the local jurisdiction of the entity. This might be a bit - /// long-winded. - /// - /// Stored as UTF-8. - pub legal: Data, - - /// A representative website held by the controller of the account. - /// - /// NOTE: `https://` is automatically prepended. - /// - /// Stored as UTF-8. - pub web: Data, - - /// The Riot/Matrix handle held by the controller of the account. - /// - /// Stored as UTF-8. - pub riot: Data, - - /// The email address of the controller of the account. - /// - /// Stored as UTF-8. - pub email: Data, - - /// The PGP/GPG public key of the controller of the account. - pub pgp_fingerprint: Option<[u8; 20]>, - - /// A graphic image representing the controller of the account. Should be a company, - /// organization or project logo or a headshot in the case of a human. - pub image: Data, - - /// The Twitter identity. The leading `@` character may be elided. - pub twitter: Data, +pub trait IdentityInformationProvider: + Encode + Decode + MaxEncodedLen + Clone + Debug + Eq + PartialEq + TypeInfo +{ + fn has_identity(&self, fields: u64) -> bool; } -impl<FieldLimit: Get<u32>> IdentityInfo<FieldLimit> { - pub(crate) fn fields(&self) -> IdentityFields { - let mut res = <BitFlags<IdentityField>>::empty(); - if !self.display.is_none() { - res.insert(IdentityField::Display); - } - if !self.legal.is_none() { - res.insert(IdentityField::Legal); - } - if !self.web.is_none() { - res.insert(IdentityField::Web); - } - if !self.riot.is_none() { - res.insert(IdentityField::Riot); - } - if !self.email.is_none() { - res.insert(IdentityField::Email); - } - if self.pgp_fingerprint.is_some() { - res.insert(IdentityField::PgpFingerprint); - } - if !self.image.is_none() { - res.insert(IdentityField::Image); - } - if !self.twitter.is_none() { - res.insert(IdentityField::Twitter); - } - IdentityFields(res) - } +pub trait IdentityFieldProvider: + Encode + Decode + MaxEncodedLen + Clone + Debug + Eq + PartialEq + TypeInfo + U64BitFlag +{ } /// Information concerning the identity of the controller of an account. @@ -376,43 +253,25 @@ impl<FieldLimit: Get<u32>> IdentityInfo<FieldLimit> { pub struct Registration< Balance: Encode + Decode + MaxEncodedLen + Copy + Clone + Debug + Eq + PartialEq, MaxJudgements: Get<u32>, - MaxAdditionalFields: Get<u32>, + II: IdentityInformationProvider, > { /// Judgements from the registrars on this identity. Stored ordered by `RegistrarIndex`. There /// may be only a single judgement from each registrar. pub judgements: BoundedVec<(RegistrarIndex, Judgement<Balance>), MaxJudgements>, - /// Amount held on deposit for this information. - pub deposit: Balance, - /// Information on the identity. - pub info: IdentityInfo<MaxAdditionalFields>, -} - -impl< - Balance: Encode + Decode + MaxEncodedLen + Copy + Clone + Debug + Eq + PartialEq + Zero + Add, - MaxJudgements: Get<u32>, - MaxAdditionalFields: Get<u32>, - > Registration<Balance, MaxJudgements, MaxAdditionalFields> -{ - pub(crate) fn total_deposit(&self) -> Balance { - self.deposit + - self.judgements - .iter() - .map(|(_, ref j)| if let Judgement::FeePaid(fee) = j { *fee } else { Zero::zero() }) - .fold(Zero::zero(), |a, i| a + i) - } + pub info: II, } impl< Balance: Encode + Decode + MaxEncodedLen + Copy + Clone + Debug + Eq + PartialEq, MaxJudgements: Get<u32>, - MaxAdditionalFields: Get<u32>, - > Decode for Registration<Balance, MaxJudgements, MaxAdditionalFields> + II: IdentityInformationProvider, + > Decode for Registration<Balance, MaxJudgements, II> { fn decode<I: codec::Input>(input: &mut I) -> sp_std::result::Result<Self, codec::Error> { - let (judgements, deposit, info) = Decode::decode(&mut AppendZerosInput::new(input))?; - Ok(Self { judgements, deposit, info }) + let (judgements, info) = Decode::decode(&mut AppendZerosInput::new(input))?; + Ok(Self { judgements, info }) } } @@ -421,6 +280,7 @@ impl< pub struct RegistrarInfo< Balance: Encode + Decode + Clone + Debug + Eq + PartialEq, AccountId: Encode + Decode + Clone + Debug + Eq + PartialEq, + IdField: IdentityFieldProvider, > { /// The account of the registrar. pub account: AccountId, @@ -430,7 +290,50 @@ pub struct RegistrarInfo< /// Relevant fields for this registrar. Registrar judgements are limited to attestations on /// these fields. - pub fields: IdentityFields, + pub fields: IdentityFields<IdField>, +} + +/// Wrapper type for `BitFlags<IdentityField>` that implements `Codec`. +#[derive(Clone, Copy, PartialEq, RuntimeDebug)] +pub struct IdentityFields<IdField: BitFlag>(pub BitFlags<IdField>); + +impl<IdField: U64BitFlag> Default for IdentityFields<IdField> { + fn default() -> Self { + Self(Default::default()) + } +} + +impl<IdField: U64BitFlag> MaxEncodedLen for IdentityFields<IdField> +where + IdentityFields<IdField>: Encode, +{ + fn max_encoded_len() -> usize { + u64::max_encoded_len() + } +} + +impl<IdField: U64BitFlag + PartialEq> Eq for IdentityFields<IdField> {} +impl<IdField: Encode + Decode + U64BitFlag> Encode for IdentityFields<IdField> { + fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R { + let bits: u64 = self.0.bits(); + bits.using_encoded(f) + } +} +impl<IdField: Encode + Decode + U64BitFlag> Decode for IdentityFields<IdField> { + fn decode<I: codec::Input>(input: &mut I) -> sp_std::result::Result<Self, codec::Error> { + let field = u64::decode(input)?; + Ok(Self(<BitFlags<IdField>>::from_bits(field).map_err(|_| "invalid value")?)) + } +} +impl<IdField: IdentityFieldProvider> TypeInfo for IdentityFields<IdField> { + type Identity = Self; + + fn type_info() -> Type { + Type::builder() + .path(Path::new("BitFlags", module_path!())) + .type_params(vec![TypeParameter::new("T", Some(meta_type::<IdField>()))]) + .composite(Fields::unnamed().field(|f| f.ty::<u64>().type_name("IdentityField"))) + } } #[cfg(test)] From 0105cc0396b7a53d0b290f48b1225847f6d17321 Mon Sep 17 00:00:00 2001 From: georgepisaltu <george.pisaltu@parity.io> Date: Tue, 19 Sep 2023 16:44:24 +0300 Subject: [PATCH 02/14] Fix `IdentityField` representation Signed-off-by: georgepisaltu <george.pisaltu@parity.io> --- substrate/frame/identity/src/simple.rs | 70 ++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 10 deletions(-) diff --git a/substrate/frame/identity/src/simple.rs b/substrate/frame/identity/src/simple.rs index 393156319f4a0..4c0de61dea07d 100644 --- a/substrate/frame/identity/src/simple.rs +++ b/substrate/frame/identity/src/simple.rs @@ -17,7 +17,7 @@ use codec::{Decode, Encode, MaxEncodedLen}; use enumflags2::{bitflags, BitFlags}; -use scale_info::TypeInfo; +use scale_info::{build::Variants, Path, Type, TypeInfo}; use sp_runtime::RuntimeDebug; use sp_std::prelude::*; @@ -27,16 +27,66 @@ use crate::types::{Data, IdentityFieldProvider, IdentityFields, U64BitFlag}; /// in the `IdentityInfo` struct. #[bitflags] #[repr(u64)] -#[derive(Encode, Decode, MaxEncodedLen, Clone, Copy, PartialEq, Eq, RuntimeDebug, TypeInfo)] +#[derive(MaxEncodedLen, Clone, Copy, PartialEq, Eq, RuntimeDebug)] pub enum IdentityField { - Display = 0b0000000000000000000000000000000000000000000000000000000000000001, - Legal = 0b0000000000000000000000000000000000000000000000000000000000000010, - Web = 0b0000000000000000000000000000000000000000000000000000000000000100, - Riot = 0b0000000000000000000000000000000000000000000000000000000000001000, - Email = 0b0000000000000000000000000000000000000000000000000000000000010000, - PgpFingerprint = 0b0000000000000000000000000000000000000000000000000000000000100000, - Image = 0b0000000000000000000000000000000000000000000000000000000001000000, - Twitter = 0b0000000000000000000000000000000000000000000000000000000010000000, + Display = 1u64 << 0, + Legal = 1u64 << 1, + Web = 1u64 << 2, + Riot = 1u64 << 3, + Email = 1u64 << 4, + PgpFingerprint = 1u64 << 5, + Image = 1u64 << 6, + Twitter = 1u64 << 7, +} + +impl TypeInfo for IdentityField { + type Identity = Self; + + fn type_info() -> scale_info::Type { + Type::builder().path(Path::new("IdentityField", module_path!())).variant( + Variants::new() + .variant("Display", |v| v.index(0)) + .variant("Legal", |v| v.index(1)) + .variant("Web", |v| v.index(2)) + .variant("Riot", |v| v.index(3)) + .variant("Email", |v| v.index(4)) + .variant("PgpFingerprint", |v| v.index(5)) + .variant("Image", |v| v.index(6)) + .variant("Twitter", |v| v.index(7)), + ) + } +} + +impl Encode for IdentityField { + fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R { + let x: u8 = match self { + IdentityField::Display => 0, + IdentityField::Legal => 1, + IdentityField::Web => 2, + IdentityField::Riot => 3, + IdentityField::Email => 4, + IdentityField::PgpFingerprint => 5, + IdentityField::Image => 6, + IdentityField::Twitter => 7, + }; + f(&x.encode()) + } +} + +impl Decode for IdentityField { + fn decode<I: codec::Input>(input: &mut I) -> Result<Self, codec::Error> { + match u8::decode(input) { + Ok(0) => Ok(IdentityField::Display), + Ok(1) => Ok(IdentityField::Legal), + Ok(2) => Ok(IdentityField::Web), + Ok(3) => Ok(IdentityField::Riot), + Ok(4) => Ok(IdentityField::Email), + Ok(5) => Ok(IdentityField::PgpFingerprint), + Ok(6) => Ok(IdentityField::Image), + Ok(7) => Ok(IdentityField::Twitter), + _ => Err("Invalid IdentityField representation".into()), + } + } } impl U64BitFlag for IdentityField {} From c79531d81ad67689aa9c9d2a06bfbd84d93c2bfd Mon Sep 17 00:00:00 2001 From: georgepisaltu <george.pisaltu@parity.io> Date: Tue, 19 Sep 2023 18:37:51 +0300 Subject: [PATCH 03/14] Fix UTs and benches Signed-off-by: georgepisaltu <george.pisaltu@parity.io> --- substrate/frame/identity/src/benchmarking.rs | 73 +++++------------- substrate/frame/identity/src/lib.rs | 66 +++++----------- substrate/frame/identity/src/simple.rs | 28 ++++++- substrate/frame/identity/src/tests.rs | 56 ++++---------- substrate/frame/identity/src/types.rs | 2 + substrate/frame/identity/src/weights.rs | 79 ++++++-------------- 6 files changed, 104 insertions(+), 200 deletions(-) diff --git a/substrate/frame/identity/src/benchmarking.rs b/substrate/frame/identity/src/benchmarking.rs index 4b51d23f6b34f..5e22d48e8f900 100644 --- a/substrate/frame/identity/src/benchmarking.rs +++ b/substrate/frame/identity/src/benchmarking.rs @@ -22,6 +22,7 @@ use super::*; use crate::Pallet as Identity; +use enumflags2::BitFlag; use frame_benchmarking::v1::{account, benchmarks, whitelisted_caller, BenchmarkError}; use frame_support::{ ensure, @@ -46,14 +47,7 @@ fn add_registrars<T: Config>(r: u32) -> Result<(), &'static str> { .expect("RegistrarOrigin has no successful origin required for the benchmark"); Identity::<T>::add_registrar(registrar_origin, registrar_lookup)?; Identity::<T>::set_fee(RawOrigin::Signed(registrar.clone()).into(), i, 10u32.into())?; - let fields = - IdentityFields( - IdentityField::Display | - IdentityField::Legal | IdentityField::Web | - IdentityField::Riot | IdentityField::Email | - IdentityField::PgpFingerprint | - IdentityField::Image | IdentityField::Twitter, - ); + let fields = Default::default(); Identity::<T>::set_fields(RawOrigin::Signed(registrar.clone()).into(), i, fields)?; } @@ -79,7 +73,7 @@ fn create_sub_accounts<T: Config>( // Set identity so `set_subs` does not fail. if IdentityOf::<T>::get(who).is_none() { let _ = T::Currency::make_free_balance_be(who, BalanceOf::<T>::max_value() / 2u32.into()); - let info = create_identity_info::<T>(1); + let info = T::IdentityInformation::create_identity_info(); Identity::<T>::set_identity(who_origin.into(), Box::new(info))?; } @@ -100,24 +94,6 @@ fn add_sub_accounts<T: Config>( Ok(subs) } -// This creates an `IdentityInfo` object with `num_fields` extra fields. -// All data is pre-populated with some arbitrary bytes. -fn create_identity_info<T: Config>(num_fields: u32) -> IdentityInfo<T::MaxAdditionalFields> { - let data = Data::Raw(vec![0; 32].try_into().unwrap()); - - IdentityInfo { - additional: vec![(data.clone(), data.clone()); num_fields as usize].try_into().unwrap(), - display: data.clone(), - legal: data.clone(), - web: data.clone(), - riot: data.clone(), - email: data.clone(), - pgp_fingerprint: Some([0; 20]), - image: data.clone(), - twitter: data, - } -} - benchmarks! { add_registrar { let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?; @@ -132,7 +108,6 @@ benchmarks! { set_identity { let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?; - let x in 0 .. T::MaxAdditionalFields::get(); let caller = { // The target user let caller: T::AccountId = whitelisted_caller(); @@ -141,7 +116,7 @@ benchmarks! { let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value()); // Add an initial identity - let initial_info = create_identity_info::<T>(1); + let initial_info = T::IdentityInformation::create_identity_info(); Identity::<T>::set_identity(caller_origin.clone(), Box::new(initial_info.clone()))?; // User requests judgement from all the registrars, and they approve @@ -162,7 +137,7 @@ benchmarks! { } caller }; - }: _(RawOrigin::Signed(caller.clone()), Box::new(create_identity_info::<T>(x))) + }: _(RawOrigin::Signed(caller.clone()), Box::new(T::IdentityInformation::create_identity_info())) verify { assert_last_event::<T>(Event::<T>::IdentitySet { who: caller }.into()); } @@ -210,10 +185,9 @@ benchmarks! { let caller: T::AccountId = whitelisted_caller(); let _ = add_sub_accounts::<T>(&caller, s)?; }; - let x in 0 .. T::MaxAdditionalFields::get(); - // Create their main identity with x additional fields - let info = create_identity_info::<T>(x); + // Create their main identity + let info = T::IdentityInformation::create_identity_info(); let caller: T::AccountId = whitelisted_caller(); let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); Identity::<T>::set_identity(caller_origin.clone(), Box::new(info.clone()))?; @@ -244,13 +218,11 @@ benchmarks! { let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value()); let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?; - let x in 0 .. T::MaxAdditionalFields::get() => { - // Create their main identity with x additional fields - let info = create_identity_info::<T>(x); - let caller: T::AccountId = whitelisted_caller(); - let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller)); - Identity::<T>::set_identity(caller_origin, Box::new(info))?; - }; + // Create their main identity + let info = T::IdentityInformation::create_identity_info(); + let caller: T::AccountId = whitelisted_caller(); + let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); + Identity::<T>::set_identity(caller_origin, Box::new(info))?; }: _(RawOrigin::Signed(caller.clone()), r - 1, 10u32.into()) verify { assert_last_event::<T>(Event::<T>::JudgementRequested { who: caller, registrar_index: r-1 }.into()); @@ -262,13 +234,11 @@ benchmarks! { let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value()); let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?; - let x in 0 .. T::MaxAdditionalFields::get() => { - // Create their main identity with x additional fields - let info = create_identity_info::<T>(x); - let caller: T::AccountId = whitelisted_caller(); - let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller)); - Identity::<T>::set_identity(caller_origin, Box::new(info))?; - }; + // Create their main identity with + let info = T::IdentityInformation::create_identity_info(); + let caller: T::AccountId = whitelisted_caller(); + let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); + Identity::<T>::set_identity(caller_origin.clone(), Box::new(info))?; Identity::<T>::request_judgement(caller_origin, r - 1, 10u32.into())?; }: _(RawOrigin::Signed(caller.clone()), r - 1) @@ -323,8 +293,7 @@ benchmarks! { .expect("RegistrarOrigin has no successful origin required for the benchmark"); Identity::<T>::add_registrar(registrar_origin, caller_lookup)?; let fields = IdentityFields( - IdentityField::Display | IdentityField::Legal | IdentityField::Web | IdentityField::Riot - | IdentityField::Email | IdentityField::PgpFingerprint | IdentityField::Image | IdentityField::Twitter + T::IdentityField::all() ); let registrars = Registrars::<T>::get(); ensure!(registrars[r as usize].as_ref().unwrap().fields == Default::default(), "fields already set."); @@ -346,9 +315,8 @@ benchmarks! { let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value()); let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?; - let x in 0 .. T::MaxAdditionalFields::get(); - let info = create_identity_info::<T>(x); + let info = T::IdentityInformation::create_identity_info(); let info_hash = T::Hashing::hash_of(&info); Identity::<T>::set_identity(user_origin.clone(), Box::new(info))?; @@ -364,14 +332,13 @@ benchmarks! { kill_identity { let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?; let s in 0 .. T::MaxSubAccounts::get(); - let x in 0 .. T::MaxAdditionalFields::get(); let target: T::AccountId = account("target", 0, SEED); let target_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(target.clone()).into(); let target_lookup = T::Lookup::unlookup(target.clone()); let _ = T::Currency::make_free_balance_be(&target, BalanceOf::<T>::max_value()); - let info = create_identity_info::<T>(x); + let info = T::IdentityInformation::create_identity_info(); Identity::<T>::set_identity(target_origin.clone(), Box::new(info.clone()))?; let _ = add_sub_accounts::<T>(&target, s)?; diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index e005bfafed22a..367a4d8d2a60e 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -125,11 +125,10 @@ pub mod pallet { #[pallet::constant] type MaxSubAccounts: Get<u32>; - /// Maximum number of additional fields that may be stored in an ID. Needed to bound the I/O - /// required to access an identity, but can be pretty high. + /// Structure holding information about an identity. type IdentityInformation: IdentityInformationProvider; - /// TODO + /// All fields in `IdentityInformation`, representable as bit flags. type IdentityField: IdentityFieldProvider; /// Maxmimum number of registrars allowed in the system. Needed to bound the complexity @@ -227,8 +226,6 @@ pub mod pallet { InvalidIndex, /// The target is invalid. InvalidTarget, - /// Too many additional fields. - TooManyFields, /// Maximum amount of registrars reached. Cannot add any more. TooManyRegistrars, /// Account ID is already named. @@ -321,14 +318,10 @@ pub mod pallet { /// Emits `IdentitySet` if successful. /// /// ## Complexity - /// - `O(X + X' + R)` - /// - where `X` additional-field-count (deposit-bounded and code-bounded) + /// - `O(R)` /// - where `R` judgements-count (registrar-count-bounded) #[pallet::call_index(1)] - #[pallet::weight( T::WeightInfo::set_identity( - T::MaxRegistrars::get(), // R - 0, // X - ))] + #[pallet::weight(T::WeightInfo::set_identity(T::MaxRegistrars::get()))] pub fn set_identity( origin: OriginFor<T>, info: Box<T::IdentityInformation>, @@ -352,11 +345,7 @@ pub mod pallet { <IdentityOf<T>>::insert(&sender, id); Self::deposit_event(Event::IdentitySet { who: sender }); - Ok(Some(T::WeightInfo::set_identity( - judgements as u32, // R - 0, // X - )) - .into()) + Ok(Some(T::WeightInfo::set_identity(judgements as u32)).into()) // R } /// Set the sub-accounts of the sender. @@ -443,15 +432,13 @@ pub mod pallet { /// Emits `IdentityCleared` if successful. /// /// ## Complexity - /// - `O(R + S + X)` + /// - `O(R + S)` /// - where `R` registrar-count (governance-bounded). /// - where `S` subs-count (hard- and deposit-bounded). - /// - where `X` additional-field-count (deposit-bounded and code-bounded). #[pallet::call_index(3)] #[pallet::weight(T::WeightInfo::clear_identity( T::MaxRegistrars::get(), // R T::MaxSubAccounts::get(), // S - 0, // X ))] pub fn clear_identity(origin: OriginFor<T>) -> DispatchResultWithPostInfo { let sender = ensure_signed(origin)?; @@ -471,7 +458,6 @@ pub mod pallet { Ok(Some(T::WeightInfo::clear_identity( id.judgements.len() as u32, // R sub_ids.len() as u32, // S - 0, // X )) .into()) } @@ -494,14 +480,10 @@ pub mod pallet { /// Emits `JudgementRequested` if successful. /// /// ## Complexity - /// - `O(R + X)`. + /// - `O(R)`. /// - where `R` registrar-count (governance-bounded). - /// - where `X` additional-field-count (deposit-bounded and code-bounded). #[pallet::call_index(4)] - #[pallet::weight(T::WeightInfo::request_judgement( - T::MaxRegistrars::get(), // R - 0, // X - ))] + #[pallet::weight(T::WeightInfo::request_judgement(T::MaxRegistrars::get()))] pub fn request_judgement( origin: OriginFor<T>, #[pallet::compact] reg_index: RegistrarIndex, @@ -538,7 +520,7 @@ pub mod pallet { registrar_index: reg_index, }); - Ok(Some(T::WeightInfo::request_judgement(judgements as u32, 0)).into()) + Ok(Some(T::WeightInfo::request_judgement(judgements as u32)).into()) // R } /// Cancel a previous request. @@ -553,14 +535,10 @@ pub mod pallet { /// Emits `JudgementUnrequested` if successful. /// /// ## Complexity - /// - `O(R + X)`. + /// - `O(R)`. /// - where `R` registrar-count (governance-bounded). - /// - where `X` additional-field-count (deposit-bounded and code-bounded). #[pallet::call_index(5)] - #[pallet::weight(T::WeightInfo::cancel_request( - T::MaxRegistrars::get(), // R - 0, // X - ))] + #[pallet::weight(T::WeightInfo::cancel_request(T::MaxRegistrars::get()))] pub fn cancel_request( origin: OriginFor<T>, reg_index: RegistrarIndex, @@ -588,7 +566,7 @@ pub mod pallet { registrar_index: reg_index, }); - Ok(Some(T::WeightInfo::cancel_request(judgements as u32, 0)).into()) + Ok(Some(T::WeightInfo::cancel_request(judgements as u32)).into()) // R } /// Set the fee required for a judgement to be requested from a registrar. @@ -700,10 +678,7 @@ pub mod pallet { .ok_or_else(|| DispatchError::from(Error::<T>::InvalidIndex))?; Ok(rs.len()) })?; - Ok(Some(T::WeightInfo::set_fields( - registrars as u32, // R - )) - .into()) + Ok(Some(T::WeightInfo::set_fields(registrars as u32)).into()) // R } /// Provide a judgement for an account's identity. @@ -720,14 +695,10 @@ pub mod pallet { /// Emits `JudgementGiven` if successful. /// /// ## Complexity - /// - `O(R + X)`. + /// - `O(R)`. /// - where `R` registrar-count (governance-bounded). - /// - where `X` additional-field-count (deposit-bounded and code-bounded). #[pallet::call_index(9)] - #[pallet::weight(T::WeightInfo::provide_judgement( - T::MaxRegistrars::get(), // R - 0, // X - ))] + #[pallet::weight(T::WeightInfo::provide_judgement(T::MaxRegistrars::get()))] // R pub fn provide_judgement( origin: OriginFor<T>, #[pallet::compact] reg_index: RegistrarIndex, @@ -773,7 +744,7 @@ pub mod pallet { <IdentityOf<T>>::insert(&target, id); Self::deposit_event(Event::JudgementGiven { target, registrar_index: reg_index }); - Ok(Some(T::WeightInfo::provide_judgement(judgements as u32, 0)).into()) + Ok(Some(T::WeightInfo::provide_judgement(judgements as u32)).into()) // R } /// Remove an account's identity and sub-account information and slash the deposits. @@ -790,15 +761,13 @@ pub mod pallet { /// Emits `IdentityKilled` if successful. /// /// ## Complexity - /// - `O(R + S + X)` + /// - `O(R + S)` /// - where `R` registrar-count (governance-bounded). /// - where `S` subs-count (hard- and deposit-bounded). - /// - where `X` additional-field-count (deposit-bounded and code-bounded). #[pallet::call_index(10)] #[pallet::weight(T::WeightInfo::kill_identity( T::MaxRegistrars::get(), // R T::MaxSubAccounts::get(), // S - 0, // X ))] pub fn kill_identity( origin: OriginFor<T>, @@ -823,7 +792,6 @@ pub mod pallet { Ok(Some(T::WeightInfo::kill_identity( id.judgements.len() as u32, // R sub_ids.len() as u32, // S - 0, // X )) .into()) } diff --git a/substrate/frame/identity/src/simple.rs b/substrate/frame/identity/src/simple.rs index 4c0de61dea07d..263ef6b47bc8d 100644 --- a/substrate/frame/identity/src/simple.rs +++ b/substrate/frame/identity/src/simple.rs @@ -21,7 +21,9 @@ use scale_info::{build::Variants, Path, Type, TypeInfo}; use sp_runtime::RuntimeDebug; use sp_std::prelude::*; -use crate::types::{Data, IdentityFieldProvider, IdentityFields, U64BitFlag}; +use crate::types::{ + Data, IdentityFieldProvider, IdentityFields, IdentityInformationProvider, U64BitFlag, +}; /// The fields that we use to identify the owner of an account with. Each corresponds to a field /// in the `IdentityInfo` struct. @@ -98,7 +100,7 @@ impl IdentityFieldProvider for IdentityField {} /// fields in a backwards compatible way through a specialized `Decode` impl. #[derive(Clone, Encode, Decode, Eq, MaxEncodedLen, PartialEq, RuntimeDebug, TypeInfo)] #[codec(mel_bound())] -#[cfg_attr(test, derive(frame_support::Default))] +#[cfg_attr(test, derive(Default))] pub struct IdentityInfo { /// A reasonable display name for the controller of the account. This should be whatever it is /// that it is typically known as and should not be confusable with other entities, given @@ -141,6 +143,28 @@ pub struct IdentityInfo { pub twitter: Data, } +impl IdentityInformationProvider for IdentityInfo { + fn has_identity(&self, fields: u64) -> bool { + self.fields().0.bits() & fields == fields + } + + #[cfg(feature = "runtime-benchmarks")] + fn create_identity_info() -> Self { + let data = Data::Raw(vec![0; 32].try_into().unwrap()); + + IdentityInfo { + display: data.clone(), + legal: data.clone(), + web: data.clone(), + riot: data.clone(), + email: data.clone(), + pgp_fingerprint: Some([0; 20]), + image: data.clone(), + twitter: data, + } + } +} + impl IdentityInfo { #[allow(unused)] pub(crate) fn fields(&self) -> IdentityFields<IdentityField> { diff --git a/substrate/frame/identity/src/tests.rs b/substrate/frame/identity/src/tests.rs index 1532980574c2a..e2dcc1aff202d 100644 --- a/substrate/frame/identity/src/tests.rs +++ b/substrate/frame/identity/src/tests.rs @@ -18,7 +18,10 @@ // Tests for Identity Pallet use super::*; -use crate as pallet_identity; +use crate::{ + self as pallet_identity, + simple::{IdentityField as SimpleIdentityField, IdentityInfo}, +}; use codec::{Decode, Encode}; use frame_support::{ @@ -102,10 +105,10 @@ impl pallet_identity::Config for Test { type Currency = Balances; type Slashed = (); type BasicDeposit = ConstU64<10>; - type FieldDeposit = ConstU64<10>; type SubAccountDeposit = ConstU64<10>; type MaxSubAccounts = ConstU32<2>; - type MaxAdditionalFields = MaxAdditionalFields; + type IdentityInformation = IdentityInfo; + type IdentityField = SimpleIdentityField; type MaxRegistrars = MaxRegistrars; type RegistrarOrigin = EnsureOneOrRoot; type ForceOrigin = EnsureTwoOrRoot; @@ -122,7 +125,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { t.into() } -fn ten() -> IdentityInfo<MaxAdditionalFields> { +fn ten() -> IdentityInfo { IdentityInfo { display: Data::Raw(b"ten".to_vec().try_into().unwrap()), legal: Data::Raw(b"The Right Ordinal Ten, Esq.".to_vec().try_into().unwrap()), @@ -130,7 +133,7 @@ fn ten() -> IdentityInfo<MaxAdditionalFields> { } } -fn twenty() -> IdentityInfo<MaxAdditionalFields> { +fn twenty() -> IdentityInfo { IdentityInfo { display: Data::Raw(b"twenty".to_vec().try_into().unwrap()), legal: Data::Raw(b"The Right Ordinal Twenty, Esq.".to_vec().try_into().unwrap()), @@ -232,7 +235,7 @@ fn adding_registrar_should_work() { new_test_ext().execute_with(|| { assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3)); assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10)); - let fields = IdentityFields(IdentityField::Display | IdentityField::Legal); + let fields = IdentityFields(SimpleIdentityField::Display | SimpleIdentityField::Legal); assert_ok!(Identity::set_fields(RuntimeOrigin::signed(3), 0, fields)); assert_eq!( Identity::registrars(), @@ -260,10 +263,6 @@ fn registration_should_work() { new_test_ext().execute_with(|| { assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3)); assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10)); - let mut three_fields = ten(); - three_fields.additional.try_push(Default::default()).unwrap(); - three_fields.additional.try_push(Default::default()).unwrap(); - assert!(three_fields.additional.try_push(Default::default()).is_err()); assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten()))); assert_eq!(Identity::identity(10).unwrap().info, ten()); assert_eq!(Balances::free_balance(10), 90); @@ -560,33 +559,6 @@ fn provide_judgement_should_return_judgement_payment_failed_error() { }); } -#[test] -fn field_deposit_should_work() { - new_test_ext().execute_with(|| { - assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3)); - assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10)); - assert_ok!(Identity::set_identity( - RuntimeOrigin::signed(10), - Box::new(IdentityInfo { - additional: vec![ - ( - Data::Raw(b"number".to_vec().try_into().unwrap()), - Data::Raw(10u32.encode().try_into().unwrap()) - ), - ( - Data::Raw(b"text".to_vec().try_into().unwrap()), - Data::Raw(b"10".to_vec().try_into().unwrap()) - ), - ] - .try_into() - .unwrap(), - ..Default::default() - }) - )); - assert_eq!(Balances::free_balance(10), 70); - }); -} - #[test] fn setting_account_id_should_work() { new_test_ext().execute_with(|| { @@ -607,15 +579,17 @@ fn setting_account_id_should_work() { fn test_has_identity() { new_test_ext().execute_with(|| { assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten()))); - assert!(Identity::has_identity(&10, IdentityField::Display as u64)); - assert!(Identity::has_identity(&10, IdentityField::Legal as u64)); + assert!(Identity::has_identity(&10, SimpleIdentityField::Display as u64)); + assert!(Identity::has_identity(&10, SimpleIdentityField::Legal as u64)); assert!(Identity::has_identity( &10, - IdentityField::Display as u64 | IdentityField::Legal as u64 + SimpleIdentityField::Display as u64 | SimpleIdentityField::Legal as u64 )); assert!(!Identity::has_identity( &10, - IdentityField::Display as u64 | IdentityField::Legal as u64 | IdentityField::Web as u64 + SimpleIdentityField::Display as u64 | + SimpleIdentityField::Legal as u64 | + SimpleIdentityField::Web as u64 )); }); } diff --git a/substrate/frame/identity/src/types.rs b/substrate/frame/identity/src/types.rs index ab8034c73c492..ecd4e0b8566e6 100644 --- a/substrate/frame/identity/src/types.rs +++ b/substrate/frame/identity/src/types.rs @@ -234,6 +234,8 @@ pub trait IdentityInformationProvider: Encode + Decode + MaxEncodedLen + Clone + Debug + Eq + PartialEq + TypeInfo { fn has_identity(&self, fields: u64) -> bool; + #[cfg(feature = "runtime-benchmarks")] + fn create_identity_info() -> Self; } pub trait IdentityFieldProvider: diff --git a/substrate/frame/identity/src/weights.rs b/substrate/frame/identity/src/weights.rs index 02fcd7db3c953..04ac0f26996d3 100644 --- a/substrate/frame/identity/src/weights.rs +++ b/substrate/frame/identity/src/weights.rs @@ -53,17 +53,17 @@ use core::marker::PhantomData; /// Weight functions needed for pallet_identity. pub trait WeightInfo { fn add_registrar(r: u32, ) -> Weight; - fn set_identity(r: u32, x: u32, ) -> Weight; + fn set_identity(r: u32, ) -> Weight; fn set_subs_new(s: u32, ) -> Weight; fn set_subs_old(p: u32, ) -> Weight; - fn clear_identity(r: u32, s: u32, x: u32, ) -> Weight; - fn request_judgement(r: u32, x: u32, ) -> Weight; - fn cancel_request(r: u32, x: u32, ) -> Weight; + fn clear_identity(r: u32, s: u32, ) -> Weight; + fn request_judgement(r: u32, ) -> Weight; + fn cancel_request(r: u32, ) -> Weight; fn set_fee(r: u32, ) -> Weight; fn set_account_id(r: u32, ) -> Weight; fn set_fields(r: u32, ) -> Weight; - fn provide_judgement(r: u32, x: u32, ) -> Weight; - fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight; + fn provide_judgement(r: u32, ) -> Weight; + fn kill_identity(r: u32, s: u32, ) -> Weight; fn add_sub(s: u32, ) -> Weight; fn rename_sub(s: u32, ) -> Weight; fn remove_sub(s: u32, ) -> Weight; @@ -90,8 +90,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. - /// The range of component `x` is `[0, 100]`. - fn set_identity(r: u32, x: u32, ) -> Weight { + fn set_identity(r: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `442 + r * (5 ±0)` // Estimated: `11003` @@ -99,8 +98,6 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { Weight::from_parts(31_329_634, 11003) // Standard Error: 4_496 .saturating_add(Weight::from_parts(203_570, 0).saturating_mul(r.into())) - // Standard Error: 877 - .saturating_add(Weight::from_parts(429_346, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -153,9 +150,9 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { /// The range of component `r` is `[1, 20]`. /// The range of component `s` is `[0, 100]`. /// The range of component `x` is `[0, 100]`. - fn clear_identity(r: u32, s: u32, x: u32, ) -> Weight { + fn clear_identity(r: u32, s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `469 + r * (5 ±0) + s * (32 ±0) + x * (66 ±0)` + // Measured: `469 + r * (5 ±0) + s * (32 ±0)` // Estimated: `11003` // Minimum execution time: 55_687_000 picoseconds. Weight::from_parts(30_695_182, 11003) @@ -163,8 +160,6 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { .saturating_add(Weight::from_parts(162_357, 0).saturating_mul(r.into())) // Standard Error: 1_937 .saturating_add(Weight::from_parts(1_427_998, 0).saturating_mul(s.into())) - // Standard Error: 1_937 - .saturating_add(Weight::from_parts(247_578, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) @@ -174,17 +169,14 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. - /// The range of component `x` is `[0, 100]`. - fn request_judgement(r: u32, x: u32, ) -> Weight { + fn request_judgement(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `367 + r * (57 ±0) + x * (66 ±0)` + // Measured: `367 + r * (57 ±0)` // Estimated: `11003` // Minimum execution time: 34_876_000 picoseconds. Weight::from_parts(32_207_018, 11003) // Standard Error: 5_247 .saturating_add(Weight::from_parts(249_156, 0).saturating_mul(r.into())) - // Standard Error: 1_023 - .saturating_add(Weight::from_parts(458_329, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -192,16 +184,14 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. /// The range of component `x` is `[0, 100]`. - fn cancel_request(r: u32, x: u32, ) -> Weight { + fn cancel_request(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `398 + x * (66 ±0)` + // Measured: `398` // Estimated: `11003` // Minimum execution time: 30_689_000 picoseconds. Weight::from_parts(31_967_170, 11003) // Standard Error: 5_387 .saturating_add(Weight::from_parts(42_676, 0).saturating_mul(r.into())) - // Standard Error: 1_051 - .saturating_add(Weight::from_parts(446_213, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -253,16 +243,14 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 19]`. /// The range of component `x` is `[0, 100]`. - fn provide_judgement(r: u32, x: u32, ) -> Weight { + fn provide_judgement(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `445 + r * (57 ±0) + x * (66 ±0)` + // Measured: `445 + r * (57 ±0)` // Estimated: `11003` // Minimum execution time: 24_073_000 picoseconds. Weight::from_parts(17_817_684, 11003) // Standard Error: 8_612 .saturating_add(Weight::from_parts(406_251, 0).saturating_mul(r.into())) - // Standard Error: 1_593 - .saturating_add(Weight::from_parts(755_225, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -277,9 +265,9 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { /// The range of component `r` is `[1, 20]`. /// The range of component `s` is `[0, 100]`. /// The range of component `x` is `[0, 100]`. - fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight { + fn kill_identity(r: u32, s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `676 + r * (5 ±0) + s * (32 ±0) + x * (66 ±0)` + // Measured: `676 + r * (5 ±0) + s * (32 ±0)` // Estimated: `11003` // Minimum execution time: 73_981_000 picoseconds. Weight::from_parts(51_684_057, 11003) @@ -287,8 +275,6 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { .saturating_add(Weight::from_parts(145_285, 0).saturating_mul(r.into())) // Standard Error: 2_472 .saturating_add(Weight::from_parts(1_421_039, 0).saturating_mul(s.into())) - // Standard Error: 2_472 - .saturating_add(Weight::from_parts(240_907, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) @@ -385,7 +371,7 @@ impl WeightInfo for () { /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. /// The range of component `x` is `[0, 100]`. - fn set_identity(r: u32, x: u32, ) -> Weight { + fn set_identity(r: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `442 + r * (5 ±0)` // Estimated: `11003` @@ -393,8 +379,6 @@ impl WeightInfo for () { Weight::from_parts(31_329_634, 11003) // Standard Error: 4_496 .saturating_add(Weight::from_parts(203_570, 0).saturating_mul(r.into())) - // Standard Error: 877 - .saturating_add(Weight::from_parts(429_346, 0).saturating_mul(x.into())) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -446,8 +430,7 @@ impl WeightInfo for () { /// Proof: Identity SuperOf (max_values: None, max_size: Some(114), added: 2589, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. /// The range of component `s` is `[0, 100]`. - /// The range of component `x` is `[0, 100]`. - fn clear_identity(r: u32, s: u32, x: u32, ) -> Weight { + fn clear_identity(r: u32, s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `469 + r * (5 ±0) + s * (32 ±0) + x * (66 ±0)` // Estimated: `11003` @@ -457,8 +440,6 @@ impl WeightInfo for () { .saturating_add(Weight::from_parts(162_357, 0).saturating_mul(r.into())) // Standard Error: 1_937 .saturating_add(Weight::from_parts(1_427_998, 0).saturating_mul(s.into())) - // Standard Error: 1_937 - .saturating_add(Weight::from_parts(247_578, 0).saturating_mul(x.into())) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(s.into()))) @@ -468,8 +449,7 @@ impl WeightInfo for () { /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. - /// The range of component `x` is `[0, 100]`. - fn request_judgement(r: u32, x: u32, ) -> Weight { + fn request_judgement(r: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `367 + r * (57 ±0) + x * (66 ±0)` // Estimated: `11003` @@ -477,25 +457,20 @@ impl WeightInfo for () { Weight::from_parts(32_207_018, 11003) // Standard Error: 5_247 .saturating_add(Weight::from_parts(249_156, 0).saturating_mul(r.into())) - // Standard Error: 1_023 - .saturating_add(Weight::from_parts(458_329, 0).saturating_mul(x.into())) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. - /// The range of component `x` is `[0, 100]`. - fn cancel_request(r: u32, x: u32, ) -> Weight { + fn cancel_request(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `398 + x * (66 ±0)` + // Measured: `398` // Estimated: `11003` // Minimum execution time: 30_689_000 picoseconds. Weight::from_parts(31_967_170, 11003) // Standard Error: 5_387 .saturating_add(Weight::from_parts(42_676, 0).saturating_mul(r.into())) - // Standard Error: 1_051 - .saturating_add(Weight::from_parts(446_213, 0).saturating_mul(x.into())) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -546,8 +521,7 @@ impl WeightInfo for () { /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 19]`. - /// The range of component `x` is `[0, 100]`. - fn provide_judgement(r: u32, x: u32, ) -> Weight { + fn provide_judgement(r: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `445 + r * (57 ±0) + x * (66 ±0)` // Estimated: `11003` @@ -555,8 +529,6 @@ impl WeightInfo for () { Weight::from_parts(17_817_684, 11003) // Standard Error: 8_612 .saturating_add(Weight::from_parts(406_251, 0).saturating_mul(r.into())) - // Standard Error: 1_593 - .saturating_add(Weight::from_parts(755_225, 0).saturating_mul(x.into())) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -570,8 +542,7 @@ impl WeightInfo for () { /// Proof: Identity SuperOf (max_values: None, max_size: Some(114), added: 2589, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. /// The range of component `s` is `[0, 100]`. - /// The range of component `x` is `[0, 100]`. - fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight { + fn kill_identity(r: u32, s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `676 + r * (5 ±0) + s * (32 ±0) + x * (66 ±0)` // Estimated: `11003` @@ -581,8 +552,6 @@ impl WeightInfo for () { .saturating_add(Weight::from_parts(145_285, 0).saturating_mul(r.into())) // Standard Error: 2_472 .saturating_add(Weight::from_parts(1_421_039, 0).saturating_mul(s.into())) - // Standard Error: 2_472 - .saturating_add(Weight::from_parts(240_907, 0).saturating_mul(x.into())) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(s.into()))) From 10f071e3e6d6b067804ceb886a6821fd1bd76c56 Mon Sep 17 00:00:00 2001 From: georgepisaltu <george.pisaltu@parity.io> Date: Wed, 20 Sep 2023 12:35:16 +0300 Subject: [PATCH 04/14] Make `pallet-alliance` work with changes Signed-off-by: georgepisaltu <george.pisaltu@parity.io> --- substrate/frame/alliance/src/lib.rs | 2 +- substrate/frame/alliance/src/mock.rs | 10 ++++++---- substrate/frame/identity/src/lib.rs | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/substrate/frame/alliance/src/lib.rs b/substrate/frame/alliance/src/lib.rs index 627399f805b31..f3ff03780f59a 100644 --- a/substrate/frame/alliance/src/lib.rs +++ b/substrate/frame/alliance/src/lib.rs @@ -112,7 +112,7 @@ use frame_support::{ }, weights::Weight, }; -use pallet_identity::IdentityField; +use pallet_identity::simple::IdentityField; use scale_info::TypeInfo; pub use pallet::*; diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index f04e7e414ed94..de0d081bb2d64 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -31,7 +31,10 @@ pub use frame_support::{ BoundedVec, }; use frame_system::{EnsureRoot, EnsureSignedBy}; -use pallet_identity::{Data, IdentityInfo, Judgement}; +use pallet_identity::{ + simple::{IdentityField, IdentityInfo}, + Data, Judgement, +}; pub use crate as pallet_alliance; @@ -135,10 +138,10 @@ impl pallet_identity::Config for Test { type RuntimeEvent = RuntimeEvent; type Currency = Balances; type BasicDeposit = BasicDeposit; - type FieldDeposit = FieldDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; - type MaxAdditionalFields = MaxAdditionalFields; + type IdentityInformation = IdentityInfo; + type IdentityField = IdentityField; type MaxRegistrars = MaxRegistrars; type Slashed = (); type RegistrarOrigin = EnsureOneOrRoot; @@ -281,7 +284,6 @@ pub fn new_test_ext() -> sp_io::TestExternalities { assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 1)); let info = IdentityInfo { - additional: BoundedVec::default(), display: Data::Raw(b"name".to_vec().try_into().unwrap()), legal: Data::default(), web: Data::Raw(b"website".to_vec().try_into().unwrap()), diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 367a4d8d2a60e..81f561908aa26 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -73,7 +73,7 @@ #![cfg_attr(not(feature = "std"), no_std)] mod benchmarking; -mod simple; +pub mod simple; #[cfg(test)] mod tests; mod types; From cbd49b397a51a201f876143887925d0462e5f7a5 Mon Sep 17 00:00:00 2001 From: georgepisaltu <george.pisaltu@parity.io> Date: Wed, 20 Sep 2023 12:54:52 +0300 Subject: [PATCH 05/14] Adjust runtimes using `identity` to changes Signed-off-by: georgepisaltu <george.pisaltu@parity.io> --- polkadot/runtime/kusama/src/lib.rs | 5 ++- .../kusama/src/weights/pallet_identity.rs | 38 +++++------------- polkadot/runtime/polkadot/src/lib.rs | 5 ++- .../polkadot/src/weights/pallet_identity.rs | 38 +++++------------- polkadot/runtime/rococo/src/lib.rs | 5 ++- .../rococo/src/weights/pallet_identity.rs | 40 +++++-------------- polkadot/runtime/westend/src/lib.rs | 5 ++- .../westend/src/weights/pallet_identity.rs | 39 +++++------------- substrate/bin/node/runtime/src/lib.rs | 5 ++- 9 files changed, 57 insertions(+), 123 deletions(-) diff --git a/polkadot/runtime/kusama/src/lib.rs b/polkadot/runtime/kusama/src/lib.rs index 8d8bd4baacf8e..f51d5dc3384c1 100644 --- a/polkadot/runtime/kusama/src/lib.rs +++ b/polkadot/runtime/kusama/src/lib.rs @@ -72,6 +72,7 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; +use pallet_identity::simple::{IdentityField, IdentityInfo}; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use pallet_session::historical as session_historical; use pallet_transaction_payment::{CurrencyAdapter, FeeDetails, RuntimeDispatchInfo}; @@ -937,10 +938,10 @@ impl pallet_identity::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; type BasicDeposit = BasicDeposit; - type FieldDeposit = FieldDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; - type MaxAdditionalFields = MaxAdditionalFields; + type IdentityInformation = IdentityInfo; + type IdentityField = IdentityField; type MaxRegistrars = MaxRegistrars; type Slashed = Treasury; type ForceOrigin = EitherOf<EnsureRoot<Self::AccountId>, GeneralAdmin>; diff --git a/polkadot/runtime/kusama/src/weights/pallet_identity.rs b/polkadot/runtime/kusama/src/weights/pallet_identity.rs index f4952db592b42..1b94901030a55 100644 --- a/polkadot/runtime/kusama/src/weights/pallet_identity.rs +++ b/polkadot/runtime/kusama/src/weights/pallet_identity.rs @@ -68,8 +68,7 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. - /// The range of component `x` is `[0, 100]`. - fn set_identity(r: u32, x: u32, ) -> Weight { + fn set_identity(r: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `442 + r * (5 ±0)` // Estimated: `11003` @@ -78,8 +77,6 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 12_190 .saturating_add(Weight::from_parts(261_969, 0).saturating_mul(r.into())) - // Standard Error: 2_378 - .saturating_add(Weight::from_parts(500_617, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -133,10 +130,9 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Proof: Identity SuperOf (max_values: None, max_size: Some(114), added: 2589, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. /// The range of component `s` is `[0, 100]`. - /// The range of component `x` is `[0, 100]`. - fn clear_identity(r: u32, s: u32, x: u32, ) -> Weight { + fn clear_identity(r: u32, s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `469 + r * (5 ±0) + s * (32 ±0) + x * (66 ±0)` + // Measured: `469 + r * (5 ±0) + s * (32 ±0)` // Estimated: `11003` // Minimum execution time: 60_331_000 picoseconds. Weight::from_parts(29_115_598, 0) @@ -145,8 +141,6 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { .saturating_add(Weight::from_parts(216_644, 0).saturating_mul(r.into())) // Standard Error: 4_272 .saturating_add(Weight::from_parts(1_420_433, 0).saturating_mul(s.into())) - // Standard Error: 4_272 - .saturating_add(Weight::from_parts(311_436, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) @@ -156,26 +150,22 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. - /// The range of component `x` is `[0, 100]`. - fn request_judgement(r: u32, x: u32, ) -> Weight { + fn request_judgement(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `367 + r * (57 ±0) + x * (66 ±0)` + // Measured: `367 + r * (57 ±0)` // Estimated: `11003` // Minimum execution time: 33_470_000 picoseconds. Weight::from_parts(32_277_730, 0) .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 4_577 .saturating_add(Weight::from_parts(121_062, 0).saturating_mul(r.into())) - // Standard Error: 893 - .saturating_add(Weight::from_parts(496_715, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. - /// The range of component `x` is `[0, 100]`. - fn cancel_request(r: u32, x: u32, ) -> Weight { + fn cancel_request(r: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `398 + x * (66 ±0)` // Estimated: `11003` @@ -184,8 +174,6 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 5_566 .saturating_add(Weight::from_parts(143_337, 0).saturating_mul(r.into())) - // Standard Error: 1_086 - .saturating_add(Weight::from_parts(487_332, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -239,18 +227,15 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 19]`. - /// The range of component `x` is `[0, 100]`. - fn provide_judgement(r: u32, x: u32, ) -> Weight { + fn provide_judgement(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `445 + r * (57 ±0) + x * (66 ±0)` + // Measured: `445 + r * (57 ±0)` // Estimated: `11003` // Minimum execution time: 23_125_000 picoseconds. Weight::from_parts(22_392_893, 0) .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 5_154 .saturating_add(Weight::from_parts(121_813, 0).saturating_mul(r.into())) - // Standard Error: 953 - .saturating_add(Weight::from_parts(806_355, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -264,10 +249,9 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Proof: Identity SuperOf (max_values: None, max_size: Some(114), added: 2589, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. /// The range of component `s` is `[0, 100]`. - /// The range of component `x` is `[0, 100]`. - fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight { + fn kill_identity(r: u32, s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `676 + r * (5 ±0) + s * (32 ±0) + x * (66 ±0)` + // Measured: `676 + r * (5 ±0) + s * (32 ±0)` // Estimated: `11003` // Minimum execution time: 76_226_000 picoseconds. Weight::from_parts(35_456_327, 0) @@ -276,8 +260,6 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { .saturating_add(Weight::from_parts(615_512, 0).saturating_mul(r.into())) // Standard Error: 3_677 .saturating_add(Weight::from_parts(1_462_016, 0).saturating_mul(s.into())) - // Standard Error: 3_677 - .saturating_add(Weight::from_parts(328_050, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(3)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) diff --git a/polkadot/runtime/polkadot/src/lib.rs b/polkadot/runtime/polkadot/src/lib.rs index 5956b0e155bb5..9efa43db6dde1 100644 --- a/polkadot/runtime/polkadot/src/lib.rs +++ b/polkadot/runtime/polkadot/src/lib.rs @@ -56,6 +56,7 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; +use pallet_identity::simple::{IdentityField, IdentityInfo}; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use pallet_session::historical as session_historical; use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo}; @@ -641,10 +642,10 @@ impl pallet_identity::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; type BasicDeposit = BasicDeposit; - type FieldDeposit = FieldDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; - type MaxAdditionalFields = MaxAdditionalFields; + type IdentityInformation = IdentityInfo; + type IdentityField = IdentityField; type MaxRegistrars = MaxRegistrars; type Slashed = Treasury; type ForceOrigin = EitherOf<EnsureRoot<Self::AccountId>, GeneralAdmin>; diff --git a/polkadot/runtime/polkadot/src/weights/pallet_identity.rs b/polkadot/runtime/polkadot/src/weights/pallet_identity.rs index 8ec244ea127c1..76c36087d47ac 100644 --- a/polkadot/runtime/polkadot/src/weights/pallet_identity.rs +++ b/polkadot/runtime/polkadot/src/weights/pallet_identity.rs @@ -68,8 +68,7 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. - /// The range of component `x` is `[0, 100]`. - fn set_identity(r: u32, x: u32, ) -> Weight { + fn set_identity(r: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `442 + r * (5 ±0)` // Estimated: `11003` @@ -78,8 +77,6 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 5_003 .saturating_add(Weight::from_parts(185_434, 0).saturating_mul(r.into())) - // Standard Error: 976 - .saturating_add(Weight::from_parts(470_886, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -133,10 +130,9 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Proof: Identity SuperOf (max_values: None, max_size: Some(114), added: 2589, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. /// The range of component `s` is `[0, 100]`. - /// The range of component `x` is `[0, 100]`. - fn clear_identity(r: u32, s: u32, x: u32, ) -> Weight { + fn clear_identity(r: u32, s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `469 + r * (5 ±0) + s * (32 ±0) + x * (66 ±0)` + // Measured: `469 + r * (5 ±0) + s * (32 ±0)` // Estimated: `11003` // Minimum execution time: 56_805_000 picoseconds. Weight::from_parts(32_595_150, 0) @@ -145,8 +141,6 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { .saturating_add(Weight::from_parts(148_154, 0).saturating_mul(r.into())) // Standard Error: 1_915 .saturating_add(Weight::from_parts(1_305_241, 0).saturating_mul(s.into())) - // Standard Error: 1_915 - .saturating_add(Weight::from_parts(253_271, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) @@ -156,26 +150,22 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. - /// The range of component `x` is `[0, 100]`. - fn request_judgement(r: u32, x: u32, ) -> Weight { + fn request_judgement(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `367 + r * (57 ±0) + x * (66 ±0)` + // Measured: `367 + r * (57 ±0)` // Estimated: `11003` // Minimum execution time: 32_747_000 picoseconds. Weight::from_parts(30_894_600, 0) .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 3_575 .saturating_add(Weight::from_parts(173_522, 0).saturating_mul(r.into())) - // Standard Error: 697 - .saturating_add(Weight::from_parts(484_893, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. - /// The range of component `x` is `[0, 100]`. - fn cancel_request(r: u32, x: u32, ) -> Weight { + fn cancel_request(r: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `398 + x * (66 ±0)` // Estimated: `11003` @@ -184,8 +174,6 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 4_460 .saturating_add(Weight::from_parts(120_240, 0).saturating_mul(r.into())) - // Standard Error: 870 - .saturating_add(Weight::from_parts(484_414, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -239,18 +227,15 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 19]`. - /// The range of component `x` is `[0, 100]`. - fn provide_judgement(r: u32, x: u32, ) -> Weight { + fn provide_judgement(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `445 + r * (57 ±0) + x * (66 ±0)` + // Measured: `445 + r * (57 ±0)` // Estimated: `11003` // Minimum execution time: 22_825_000 picoseconds. Weight::from_parts(21_046_708, 0) .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 5_012 .saturating_add(Weight::from_parts(180_118, 0).saturating_mul(r.into())) - // Standard Error: 927 - .saturating_add(Weight::from_parts(788_617, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -264,10 +249,9 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Proof: Identity SuperOf (max_values: None, max_size: Some(114), added: 2589, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. /// The range of component `s` is `[0, 100]`. - /// The range of component `x` is `[0, 100]`. - fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight { + fn kill_identity(r: u32, s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `676 + r * (5 ±0) + s * (32 ±0) + x * (66 ±0)` + // Measured: `676 + r * (5 ±0) + s * (32 ±0)` // Estimated: `11003` // Minimum execution time: 75_635_000 picoseconds. Weight::from_parts(47_274_783, 0) @@ -276,8 +260,6 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { .saturating_add(Weight::from_parts(230_554, 0).saturating_mul(r.into())) // Standard Error: 2_271 .saturating_add(Weight::from_parts(1_333_461, 0).saturating_mul(s.into())) - // Standard Error: 2_271 - .saturating_add(Weight::from_parts(276_612, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(3)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 7046c4640c040..54d0daf29fc96 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -69,6 +69,7 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; +use pallet_identity::simple::{IdentityField, IdentityInfo}; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use pallet_session::historical as session_historical; use pallet_transaction_payment::{CurrencyAdapter, FeeDetails, RuntimeDispatchInfo}; @@ -763,10 +764,10 @@ impl pallet_identity::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; type BasicDeposit = BasicDeposit; - type FieldDeposit = FieldDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; - type MaxAdditionalFields = MaxAdditionalFields; + type IdentityInformation = IdentityInfo; + type IdentityField = IdentityField; type MaxRegistrars = MaxRegistrars; type Slashed = Treasury; type ForceOrigin = MoreThanHalfCouncil; diff --git a/polkadot/runtime/rococo/src/weights/pallet_identity.rs b/polkadot/runtime/rococo/src/weights/pallet_identity.rs index e10c042dde6aa..7406ae6779e0c 100644 --- a/polkadot/runtime/rococo/src/weights/pallet_identity.rs +++ b/polkadot/runtime/rococo/src/weights/pallet_identity.rs @@ -65,8 +65,7 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. - /// The range of component `x` is `[0, 100]`. - fn set_identity(r: u32, x: u32, ) -> Weight { + fn set_identity(r: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `442 + r * (5 ±0)` // Estimated: `11003` @@ -75,8 +74,6 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 2_307 .saturating_add(Weight::from_parts(92_753, 0).saturating_mul(r.into())) - // Standard Error: 450 - .saturating_add(Weight::from_parts(449_529, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -130,18 +127,15 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Proof: Identity SuperOf (max_values: None, max_size: Some(114), added: 2589, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. /// The range of component `s` is `[0, 100]`. - /// The range of component `x` is `[0, 100]`. - fn clear_identity(_r: u32, s: u32, x: u32, ) -> Weight { + fn clear_identity(_r: u32, s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `469 + r * (5 ±0) + s * (32 ±0) + x * (66 ±0)` + // Measured: `469 + r * (5 ±0) + s * (32 ±0)` // Estimated: `11003` // Minimum execution time: 53_365_000 picoseconds. Weight::from_parts(35_391_422, 0) .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 1_353 .saturating_add(Weight::from_parts(1_074_019, 0).saturating_mul(s.into())) - // Standard Error: 1_353 - .saturating_add(Weight::from_parts(229_947, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) @@ -151,36 +145,30 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. - /// The range of component `x` is `[0, 100]`. - fn request_judgement(r: u32, x: u32, ) -> Weight { + fn request_judgement(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `367 + r * (57 ±0) + x * (66 ±0)` + // Measured: `367 + r * (57 ±0)` // Estimated: `11003` // Minimum execution time: 32_509_000 picoseconds. Weight::from_parts(31_745_585, 0) .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 2_214 .saturating_add(Weight::from_parts(83_822, 0).saturating_mul(r.into())) - // Standard Error: 432 - .saturating_add(Weight::from_parts(458_801, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. - /// The range of component `x` is `[0, 100]`. - fn cancel_request(r: u32, x: u32, ) -> Weight { + fn cancel_request(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `398 + x * (66 ±0)` + // Measured: `398` // Estimated: `11003` // Minimum execution time: 29_609_000 picoseconds. Weight::from_parts(28_572_602, 0) .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 2_528 .saturating_add(Weight::from_parts(85_593, 0).saturating_mul(r.into())) - // Standard Error: 493 - .saturating_add(Weight::from_parts(468_140, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -234,18 +222,15 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 19]`. - /// The range of component `x` is `[0, 100]`. - fn provide_judgement(r: u32, x: u32, ) -> Weight { + fn provide_judgement(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `445 + r * (57 ±0) + x * (66 ±0)` + // Measured: `445 + r * (57 ±0)` // Estimated: `11003` // Minimum execution time: 23_114_000 picoseconds. Weight::from_parts(22_076_548, 0) .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 2_881 .saturating_add(Weight::from_parts(109_812, 0).saturating_mul(r.into())) - // Standard Error: 533 - .saturating_add(Weight::from_parts(733_244, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -259,10 +244,9 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Proof: Identity SuperOf (max_values: None, max_size: Some(114), added: 2589, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. /// The range of component `s` is `[0, 100]`. - /// The range of component `x` is `[0, 100]`. - fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight { + fn kill_identity(r: u32, s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `676 + r * (5 ±0) + s * (32 ±0) + x * (66 ±0)` + // Measured: `676 + r * (5 ±0) + s * (32 ±0)` // Estimated: `11003` // Minimum execution time: 70_007_000 picoseconds. Weight::from_parts(50_186_495, 0) @@ -271,8 +255,6 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { .saturating_add(Weight::from_parts(15_486, 0).saturating_mul(r.into())) // Standard Error: 1_275 .saturating_add(Weight::from_parts(1_085_117, 0).saturating_mul(s.into())) - // Standard Error: 1_275 - .saturating_add(Weight::from_parts(228_226, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(3)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 9af18b5be2bbc..23e3618790c6b 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -38,6 +38,7 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; +use pallet_identity::simple::{IdentityField, IdentityInfo}; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use pallet_session::historical as session_historical; use pallet_transaction_payment::{CurrencyAdapter, FeeDetails, RuntimeDispatchInfo}; @@ -809,10 +810,10 @@ impl pallet_identity::Config for Runtime { type Currency = Balances; type Slashed = (); type BasicDeposit = BasicDeposit; - type FieldDeposit = FieldDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; - type MaxAdditionalFields = MaxAdditionalFields; + type IdentityInformation = IdentityInfo; + type IdentityField = IdentityField; type MaxRegistrars = MaxRegistrars; type RegistrarOrigin = frame_system::EnsureRoot<AccountId>; type ForceOrigin = frame_system::EnsureRoot<AccountId>; diff --git a/polkadot/runtime/westend/src/weights/pallet_identity.rs b/polkadot/runtime/westend/src/weights/pallet_identity.rs index 8c11482ebdc13..5edbe9d284ef3 100644 --- a/polkadot/runtime/westend/src/weights/pallet_identity.rs +++ b/polkadot/runtime/westend/src/weights/pallet_identity.rs @@ -68,8 +68,7 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. - /// The range of component `x` is `[0, 100]`. - fn set_identity(r: u32, x: u32, ) -> Weight { + fn set_identity(r: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `442 + r * (5 ±0)` // Estimated: `11003` @@ -78,8 +77,6 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 7_269 .saturating_add(Weight::from_parts(250_439, 0).saturating_mul(r.into())) - // Standard Error: 1_418 - .saturating_add(Weight::from_parts(483_981, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -133,10 +130,9 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Proof: Identity SuperOf (max_values: None, max_size: Some(114), added: 2589, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. /// The range of component `s` is `[0, 100]`. - /// The range of component `x` is `[0, 100]`. - fn clear_identity(r: u32, s: u32, x: u32, ) -> Weight { + fn clear_identity(r: u32, s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `469 + r * (5 ±0) + s * (32 ±0) + x * (66 ±0)` + // Measured: `469 + r * (5 ±0) + s * (32 ±0)` // Estimated: `11003` // Minimum execution time: 60_177_000 picoseconds. Weight::from_parts(26_533_717, 0) @@ -145,8 +141,6 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { .saturating_add(Weight::from_parts(475_120, 0).saturating_mul(r.into())) // Standard Error: 4_092 .saturating_add(Weight::from_parts(1_348_869, 0).saturating_mul(s.into())) - // Standard Error: 4_092 - .saturating_add(Weight::from_parts(314_033, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) @@ -157,35 +151,30 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. /// The range of component `x` is `[0, 100]`. - fn request_judgement(r: u32, x: u32, ) -> Weight { + fn request_judgement(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `367 + r * (57 ±0) + x * (66 ±0)` + // Measured: `367 + r * (57 ±0)` // Estimated: `11003` // Minimum execution time: 32_818_000 picoseconds. Weight::from_parts(32_253_281, 0) .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 7_973 .saturating_add(Weight::from_parts(124_283, 0).saturating_mul(r.into())) - // Standard Error: 1_555 - .saturating_add(Weight::from_parts(512_825, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. - /// The range of component `x` is `[0, 100]`. - fn cancel_request(r: u32, x: u32, ) -> Weight { + fn cancel_request(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `398 + x * (66 ±0)` + // Measured: `398` // Estimated: `11003` // Minimum execution time: 29_931_000 picoseconds. Weight::from_parts(28_643_196, 0) .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 5_154 .saturating_add(Weight::from_parts(147_560, 0).saturating_mul(r.into())) - // Standard Error: 1_005 - .saturating_add(Weight::from_parts(490_754, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -239,18 +228,15 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 19]`. - /// The range of component `x` is `[0, 100]`. - fn provide_judgement(r: u32, x: u32, ) -> Weight { + fn provide_judgement(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `445 + r * (57 ±0) + x * (66 ±0)` + // Measured: `445 + r * (57 ±0)` // Estimated: `11003` // Minimum execution time: 22_742_000 picoseconds. Weight::from_parts(21_879_281, 0) .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 10_027 .saturating_add(Weight::from_parts(154_816, 0).saturating_mul(r.into())) - // Standard Error: 1_855 - .saturating_add(Weight::from_parts(803_084, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -264,10 +250,9 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Proof: Identity SuperOf (max_values: None, max_size: Some(114), added: 2589, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. /// The range of component `s` is `[0, 100]`. - /// The range of component `x` is `[0, 100]`. - fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight { + fn kill_identity(r: u32, s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `676 + r * (5 ±0) + s * (32 ±0) + x * (66 ±0)` + // Measured: `676 + r * (5 ±0) + s * (32 ±0)` // Estimated: `11003` // Minimum execution time: 64_467_000 picoseconds. Weight::from_parts(27_806_692, 0) @@ -276,8 +261,6 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { .saturating_add(Weight::from_parts(666_376, 0).saturating_mul(r.into())) // Standard Error: 4_433 .saturating_add(Weight::from_parts(1_396_065, 0).saturating_mul(s.into())) - // Standard Error: 4_433 - .saturating_add(Weight::from_parts(300_762, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(3)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index df8fb06467d99..7628b2f2a3c28 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -59,6 +59,7 @@ use node_primitives::{AccountIndex, Balance, BlockNumber, Hash, Moment, Nonce}; use pallet_asset_conversion::{NativeOrAssetId, NativeOrAssetIdConverter}; use pallet_broker::{CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600}; use pallet_election_provider_multi_phase::{GeometricDepositBase, SolutionAccuracyOf}; +use pallet_identity::simple::{IdentityField, IdentityInfo}; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use pallet_nfts::PalletFeatures; use pallet_nis::WithMaximumOf; @@ -1456,10 +1457,10 @@ impl pallet_identity::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; type BasicDeposit = BasicDeposit; - type FieldDeposit = FieldDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; - type MaxAdditionalFields = MaxAdditionalFields; + type IdentityInformation = IdentityInfo; + type IdentityField = IdentityField; type MaxRegistrars = MaxRegistrars; type Slashed = Treasury; type ForceOrigin = EnsureRootOrHalfCouncil; From 4f97f9dbbc0cb3c061203ae5b686167f7c6fa66e Mon Sep 17 00:00:00 2001 From: georgepisaltu <george.pisaltu@parity.io> Date: Wed, 20 Sep 2023 14:16:55 +0300 Subject: [PATCH 06/14] Move `IdentityField` to associated type Signed-off-by: georgepisaltu <george.pisaltu@parity.io> --- polkadot/runtime/kusama/src/lib.rs | 3 +- polkadot/runtime/polkadot/src/lib.rs | 3 +- polkadot/runtime/rococo/src/lib.rs | 3 +- polkadot/runtime/westend/src/lib.rs | 3 +- substrate/bin/node/runtime/src/lib.rs | 3 +- substrate/frame/alliance/src/mock.rs | 1 - substrate/frame/identity/src/benchmarking.rs | 2 +- substrate/frame/identity/src/lib.rs | 17 ++++++----- substrate/frame/identity/src/simple.rs | 7 ++--- substrate/frame/identity/src/tests.rs | 1 - substrate/frame/identity/src/types.rs | 30 +++++++++++++------- 11 files changed, 38 insertions(+), 35 deletions(-) diff --git a/polkadot/runtime/kusama/src/lib.rs b/polkadot/runtime/kusama/src/lib.rs index f51d5dc3384c1..fb96911fb6db0 100644 --- a/polkadot/runtime/kusama/src/lib.rs +++ b/polkadot/runtime/kusama/src/lib.rs @@ -72,7 +72,7 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; -use pallet_identity::simple::{IdentityField, IdentityInfo}; +use pallet_identity::simple::IdentityInfo; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use pallet_session::historical as session_historical; use pallet_transaction_payment::{CurrencyAdapter, FeeDetails, RuntimeDispatchInfo}; @@ -941,7 +941,6 @@ impl pallet_identity::Config for Runtime { type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; type IdentityInformation = IdentityInfo; - type IdentityField = IdentityField; type MaxRegistrars = MaxRegistrars; type Slashed = Treasury; type ForceOrigin = EitherOf<EnsureRoot<Self::AccountId>, GeneralAdmin>; diff --git a/polkadot/runtime/polkadot/src/lib.rs b/polkadot/runtime/polkadot/src/lib.rs index 9efa43db6dde1..f34957d4b64ff 100644 --- a/polkadot/runtime/polkadot/src/lib.rs +++ b/polkadot/runtime/polkadot/src/lib.rs @@ -56,7 +56,7 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; -use pallet_identity::simple::{IdentityField, IdentityInfo}; +use pallet_identity::simple::IdentityInfo; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use pallet_session::historical as session_historical; use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo}; @@ -645,7 +645,6 @@ impl pallet_identity::Config for Runtime { type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; type IdentityInformation = IdentityInfo; - type IdentityField = IdentityField; type MaxRegistrars = MaxRegistrars; type Slashed = Treasury; type ForceOrigin = EitherOf<EnsureRoot<Self::AccountId>, GeneralAdmin>; diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 54d0daf29fc96..9ba41134cd324 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -69,7 +69,7 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; -use pallet_identity::simple::{IdentityField, IdentityInfo}; +use pallet_identity::simple::IdentityInfo; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use pallet_session::historical as session_historical; use pallet_transaction_payment::{CurrencyAdapter, FeeDetails, RuntimeDispatchInfo}; @@ -767,7 +767,6 @@ impl pallet_identity::Config for Runtime { type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; type IdentityInformation = IdentityInfo; - type IdentityField = IdentityField; type MaxRegistrars = MaxRegistrars; type Slashed = Treasury; type ForceOrigin = MoreThanHalfCouncil; diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 23e3618790c6b..529c4537806f6 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -38,7 +38,7 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; -use pallet_identity::simple::{IdentityField, IdentityInfo}; +use pallet_identity::simple::IdentityInfo; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use pallet_session::historical as session_historical; use pallet_transaction_payment::{CurrencyAdapter, FeeDetails, RuntimeDispatchInfo}; @@ -813,7 +813,6 @@ impl pallet_identity::Config for Runtime { type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; type IdentityInformation = IdentityInfo; - type IdentityField = IdentityField; type MaxRegistrars = MaxRegistrars; type RegistrarOrigin = frame_system::EnsureRoot<AccountId>; type ForceOrigin = frame_system::EnsureRoot<AccountId>; diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 7628b2f2a3c28..e31e3fc1b9cbc 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -59,7 +59,7 @@ use node_primitives::{AccountIndex, Balance, BlockNumber, Hash, Moment, Nonce}; use pallet_asset_conversion::{NativeOrAssetId, NativeOrAssetIdConverter}; use pallet_broker::{CoreAssignment, CoreIndex, CoretimeInterface, PartsOf57600}; use pallet_election_provider_multi_phase::{GeometricDepositBase, SolutionAccuracyOf}; -use pallet_identity::simple::{IdentityField, IdentityInfo}; +use pallet_identity::simple::IdentityInfo; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use pallet_nfts::PalletFeatures; use pallet_nis::WithMaximumOf; @@ -1460,7 +1460,6 @@ impl pallet_identity::Config for Runtime { type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; type IdentityInformation = IdentityInfo; - type IdentityField = IdentityField; type MaxRegistrars = MaxRegistrars; type Slashed = Treasury; type ForceOrigin = EnsureRootOrHalfCouncil; diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index de0d081bb2d64..273a16006cc2d 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -141,7 +141,6 @@ impl pallet_identity::Config for Test { type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; type IdentityInformation = IdentityInfo; - type IdentityField = IdentityField; type MaxRegistrars = MaxRegistrars; type Slashed = (); type RegistrarOrigin = EnsureOneOrRoot; diff --git a/substrate/frame/identity/src/benchmarking.rs b/substrate/frame/identity/src/benchmarking.rs index 5e22d48e8f900..315fd457eb59b 100644 --- a/substrate/frame/identity/src/benchmarking.rs +++ b/substrate/frame/identity/src/benchmarking.rs @@ -293,7 +293,7 @@ benchmarks! { .expect("RegistrarOrigin has no successful origin required for the benchmark"); Identity::<T>::add_registrar(registrar_origin, caller_lookup)?; let fields = IdentityFields( - T::IdentityField::all() + <T::IdentityInformation as IdentityInformationProvider>::IdentityField::all() ); let registrars = Registrars::<T>::get(); ensure!(registrars[r as usize].as_ref().unwrap().fields == Default::default(), "fields already set."); diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 81f561908aa26..06818b188c2cd 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -97,8 +97,6 @@ type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup #[frame_support::pallet] pub mod pallet { - use crate::types::{IdentityFieldProvider, IdentityInformationProvider}; - use super::*; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; @@ -128,9 +126,6 @@ pub mod pallet { /// Structure holding information about an identity. type IdentityInformation: IdentityInformationProvider; - /// All fields in `IdentityInformation`, representable as bit flags. - type IdentityField: IdentityFieldProvider; - /// Maxmimum number of registrars allowed in the system. Needed to bound the complexity /// of, e.g., updating judgements. #[pallet::constant] @@ -196,7 +191,13 @@ pub mod pallet { pub(super) type Registrars<T: Config> = StorageValue< _, BoundedVec< - Option<RegistrarInfo<BalanceOf<T>, T::AccountId, T::IdentityField>>, + Option< + RegistrarInfo< + BalanceOf<T>, + T::AccountId, + <T::IdentityInformation as IdentityInformationProvider>::IdentityField, + >, + >, T::MaxRegistrars, >, ValueQuery, @@ -660,7 +661,9 @@ pub mod pallet { pub fn set_fields( origin: OriginFor<T>, #[pallet::compact] index: RegistrarIndex, - fields: IdentityFields<T::IdentityField>, + fields: IdentityFields< + <T::IdentityInformation as IdentityInformationProvider>::IdentityField, + >, ) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; diff --git a/substrate/frame/identity/src/simple.rs b/substrate/frame/identity/src/simple.rs index 263ef6b47bc8d..d8c8563c46334 100644 --- a/substrate/frame/identity/src/simple.rs +++ b/substrate/frame/identity/src/simple.rs @@ -21,9 +21,7 @@ use scale_info::{build::Variants, Path, Type, TypeInfo}; use sp_runtime::RuntimeDebug; use sp_std::prelude::*; -use crate::types::{ - Data, IdentityFieldProvider, IdentityFields, IdentityInformationProvider, U64BitFlag, -}; +use crate::types::{Data, IdentityFields, IdentityInformationProvider, U64BitFlag}; /// The fields that we use to identify the owner of an account with. Each corresponds to a field /// in the `IdentityInfo` struct. @@ -92,7 +90,6 @@ impl Decode for IdentityField { } impl U64BitFlag for IdentityField {} -impl IdentityFieldProvider for IdentityField {} /// Information concerning the identity of the controller of an account. /// @@ -144,6 +141,8 @@ pub struct IdentityInfo { } impl IdentityInformationProvider for IdentityInfo { + type IdentityField = IdentityField; + fn has_identity(&self, fields: u64) -> bool { self.fields().0.bits() & fields == fields } diff --git a/substrate/frame/identity/src/tests.rs b/substrate/frame/identity/src/tests.rs index e2dcc1aff202d..a739ddeb690ab 100644 --- a/substrate/frame/identity/src/tests.rs +++ b/substrate/frame/identity/src/tests.rs @@ -108,7 +108,6 @@ impl pallet_identity::Config for Test { type SubAccountDeposit = ConstU64<10>; type MaxSubAccounts = ConstU32<2>; type IdentityInformation = IdentityInfo; - type IdentityField = SimpleIdentityField; type MaxRegistrars = MaxRegistrars; type RegistrarOrigin = EnsureOneOrRoot; type ForceOrigin = EnsureTwoOrRoot; diff --git a/substrate/frame/identity/src/types.rs b/substrate/frame/identity/src/types.rs index ecd4e0b8566e6..797a65b58c211 100644 --- a/substrate/frame/identity/src/types.rs +++ b/substrate/frame/identity/src/types.rs @@ -233,16 +233,21 @@ impl<Balance: Encode + Decode + MaxEncodedLen + Copy + Clone + Debug + Eq + Part pub trait IdentityInformationProvider: Encode + Decode + MaxEncodedLen + Clone + Debug + Eq + PartialEq + TypeInfo { + type IdentityField: Encode + + Decode + + MaxEncodedLen + + Clone + + Debug + + Eq + + PartialEq + + TypeInfo + + U64BitFlag; + fn has_identity(&self, fields: u64) -> bool; #[cfg(feature = "runtime-benchmarks")] fn create_identity_info() -> Self; } -pub trait IdentityFieldProvider: - Encode + Decode + MaxEncodedLen + Clone + Debug + Eq + PartialEq + TypeInfo + U64BitFlag -{ -} - /// Information concerning the identity of the controller of an account. /// /// NOTE: This is stored separately primarily to facilitate the addition of extra fields in a @@ -255,21 +260,21 @@ pub trait IdentityFieldProvider: pub struct Registration< Balance: Encode + Decode + MaxEncodedLen + Copy + Clone + Debug + Eq + PartialEq, MaxJudgements: Get<u32>, - II: IdentityInformationProvider, + IdentityInfo: IdentityInformationProvider, > { /// Judgements from the registrars on this identity. Stored ordered by `RegistrarIndex`. There /// may be only a single judgement from each registrar. pub judgements: BoundedVec<(RegistrarIndex, Judgement<Balance>), MaxJudgements>, /// Information on the identity. - pub info: II, + pub info: IdentityInfo, } impl< Balance: Encode + Decode + MaxEncodedLen + Copy + Clone + Debug + Eq + PartialEq, MaxJudgements: Get<u32>, - II: IdentityInformationProvider, - > Decode for Registration<Balance, MaxJudgements, II> + IdentityInfo: IdentityInformationProvider, + > Decode for Registration<Balance, MaxJudgements, IdentityInfo> { fn decode<I: codec::Input>(input: &mut I) -> sp_std::result::Result<Self, codec::Error> { let (judgements, info) = Decode::decode(&mut AppendZerosInput::new(input))?; @@ -282,7 +287,7 @@ impl< pub struct RegistrarInfo< Balance: Encode + Decode + Clone + Debug + Eq + PartialEq, AccountId: Encode + Decode + Clone + Debug + Eq + PartialEq, - IdField: IdentityFieldProvider, + IdField: Encode + Decode + MaxEncodedLen + Clone + Debug + Eq + PartialEq + TypeInfo + U64BitFlag, > { /// The account of the registrar. pub account: AccountId, @@ -327,7 +332,10 @@ impl<IdField: Encode + Decode + U64BitFlag> Decode for IdentityFields<IdField> { Ok(Self(<BitFlags<IdField>>::from_bits(field).map_err(|_| "invalid value")?)) } } -impl<IdField: IdentityFieldProvider> TypeInfo for IdentityFields<IdField> { +impl< + IdField: Encode + Decode + MaxEncodedLen + Clone + Debug + Eq + PartialEq + TypeInfo + U64BitFlag, + > TypeInfo for IdentityFields<IdField> +{ type Identity = Self; fn type_info() -> Type { From a1577adb3b6a40e66e620132bca8d95639bf9dcc Mon Sep 17 00:00:00 2001 From: georgepisaltu <george.pisaltu@parity.io> Date: Thu, 21 Sep 2023 13:39:51 +0300 Subject: [PATCH 07/14] Update documentation and prepare for migration Signed-off-by: georgepisaltu <george.pisaltu@parity.io> --- substrate/frame/identity/src/types.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/substrate/frame/identity/src/types.rs b/substrate/frame/identity/src/types.rs index 797a65b58c211..963923a9d1af0 100644 --- a/substrate/frame/identity/src/types.rs +++ b/substrate/frame/identity/src/types.rs @@ -230,9 +230,12 @@ impl<Balance: Encode + Decode + MaxEncodedLen + Copy + Clone + Debug + Eq + Part } } +/// Information concerning the identity of the controller of an account. pub trait IdentityInformationProvider: Encode + Decode + MaxEncodedLen + Clone + Debug + Eq + PartialEq + TypeInfo { + /// Type capable of representing all of the fields present in the identity information as bit + /// flags in `u64` format. type IdentityField: Encode + Decode + MaxEncodedLen @@ -248,10 +251,11 @@ pub trait IdentityInformationProvider: fn create_identity_info() -> Self; } -/// Information concerning the identity of the controller of an account. +/// Information on an identity along with judgements from registrars. /// /// NOTE: This is stored separately primarily to facilitate the addition of extra fields in a -/// backwards compatible way through a specialized `Decode` impl. +/// backwards compatible way through a specialized `Decode` impl. Is this still the case? We need to +/// do a migration if we removed the additional fields. #[derive( CloneNoBound, Encode, Eq, MaxEncodedLen, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, )] @@ -277,6 +281,7 @@ impl< > Decode for Registration<Balance, MaxJudgements, IdentityInfo> { fn decode<I: codec::Input>(input: &mut I) -> sp_std::result::Result<Self, codec::Error> { + // TODO consider removing this, will probably do migration let (judgements, info) = Decode::decode(&mut AppendZerosInput::new(input))?; Ok(Self { judgements, info }) } From a51abc45a6965c95359df60b668624f441c59615 Mon Sep 17 00:00:00 2001 From: georgepisaltu <george.pisaltu@parity.io> Date: Tue, 26 Sep 2023 14:38:53 +0300 Subject: [PATCH 08/14] Add `additional_fields` back to the impl Signed-off-by: georgepisaltu <george.pisaltu@parity.io> --- polkadot/runtime/kusama/src/lib.rs | 2 +- polkadot/runtime/polkadot/src/lib.rs | 2 +- polkadot/runtime/rococo/src/lib.rs | 2 +- polkadot/runtime/westend/src/lib.rs | 2 +- substrate/bin/node/runtime/src/lib.rs | 2 +- substrate/frame/alliance/src/mock.rs | 8 +++----- substrate/frame/identity/src/simple.rs | 28 ++++++++++++++++++++------ substrate/frame/identity/src/tests.rs | 10 ++++++--- 8 files changed, 37 insertions(+), 19 deletions(-) diff --git a/polkadot/runtime/kusama/src/lib.rs b/polkadot/runtime/kusama/src/lib.rs index fb96911fb6db0..3807c48413b0b 100644 --- a/polkadot/runtime/kusama/src/lib.rs +++ b/polkadot/runtime/kusama/src/lib.rs @@ -940,7 +940,7 @@ impl pallet_identity::Config for Runtime { type BasicDeposit = BasicDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; - type IdentityInformation = IdentityInfo; + type IdentityInformation = IdentityInfo<MaxAdditionalFields>; type MaxRegistrars = MaxRegistrars; type Slashed = Treasury; type ForceOrigin = EitherOf<EnsureRoot<Self::AccountId>, GeneralAdmin>; diff --git a/polkadot/runtime/polkadot/src/lib.rs b/polkadot/runtime/polkadot/src/lib.rs index f34957d4b64ff..0f162e89d59c5 100644 --- a/polkadot/runtime/polkadot/src/lib.rs +++ b/polkadot/runtime/polkadot/src/lib.rs @@ -644,7 +644,7 @@ impl pallet_identity::Config for Runtime { type BasicDeposit = BasicDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; - type IdentityInformation = IdentityInfo; + type IdentityInformation = IdentityInfo<MaxAdditionalFields>; type MaxRegistrars = MaxRegistrars; type Slashed = Treasury; type ForceOrigin = EitherOf<EnsureRoot<Self::AccountId>, GeneralAdmin>; diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 9ba41134cd324..c0076fc6626d9 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -766,7 +766,7 @@ impl pallet_identity::Config for Runtime { type BasicDeposit = BasicDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; - type IdentityInformation = IdentityInfo; + type IdentityInformation = IdentityInfo<MaxAdditionalFields>; type MaxRegistrars = MaxRegistrars; type Slashed = Treasury; type ForceOrigin = MoreThanHalfCouncil; diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 529c4537806f6..c8126c8754111 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -812,7 +812,7 @@ impl pallet_identity::Config for Runtime { type BasicDeposit = BasicDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; - type IdentityInformation = IdentityInfo; + type IdentityInformation = IdentityInfo<MaxAdditionalFields>; type MaxRegistrars = MaxRegistrars; type RegistrarOrigin = frame_system::EnsureRoot<AccountId>; type ForceOrigin = frame_system::EnsureRoot<AccountId>; diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index e31e3fc1b9cbc..3463787c065bb 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -1459,7 +1459,7 @@ impl pallet_identity::Config for Runtime { type BasicDeposit = BasicDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; - type IdentityInformation = IdentityInfo; + type IdentityInformation = IdentityInfo<MaxAdditionalFields>; type MaxRegistrars = MaxRegistrars; type Slashed = Treasury; type ForceOrigin = EnsureRootOrHalfCouncil; diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index 273a16006cc2d..033e1962ac41d 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -31,10 +31,7 @@ pub use frame_support::{ BoundedVec, }; use frame_system::{EnsureRoot, EnsureSignedBy}; -use pallet_identity::{ - simple::{IdentityField, IdentityInfo}, - Data, Judgement, -}; +use pallet_identity::{simple::IdentityInfo, Data, Judgement}; pub use crate as pallet_alliance; @@ -140,7 +137,7 @@ impl pallet_identity::Config for Test { type BasicDeposit = BasicDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; - type IdentityInformation = IdentityInfo; + type IdentityInformation = IdentityInfo<MaxAdditionalFields>; type MaxRegistrars = MaxRegistrars; type Slashed = (); type RegistrarOrigin = EnsureOneOrRoot; @@ -283,6 +280,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 1)); let info = IdentityInfo { + additional: Default::default(), display: Data::Raw(b"name".to_vec().try_into().unwrap()), legal: Data::default(), web: Data::Raw(b"website".to_vec().try_into().unwrap()), diff --git a/substrate/frame/identity/src/simple.rs b/substrate/frame/identity/src/simple.rs index d8c8563c46334..5ec8d05a29df0 100644 --- a/substrate/frame/identity/src/simple.rs +++ b/substrate/frame/identity/src/simple.rs @@ -17,8 +17,9 @@ use codec::{Decode, Encode, MaxEncodedLen}; use enumflags2::{bitflags, BitFlags}; +use frame_support::{traits::Get, CloneNoBound, EqNoBound, PartialEqNoBound, RuntimeDebugNoBound}; use scale_info::{build::Variants, Path, Type, TypeInfo}; -use sp_runtime::RuntimeDebug; +use sp_runtime::{BoundedVec, RuntimeDebug}; use sp_std::prelude::*; use crate::types::{Data, IdentityFields, IdentityInformationProvider, U64BitFlag}; @@ -95,10 +96,24 @@ impl U64BitFlag for IdentityField {} /// /// NOTE: This should be stored at the end of the storage item to facilitate the addition of extra /// fields in a backwards compatible way through a specialized `Decode` impl. -#[derive(Clone, Encode, Decode, Eq, MaxEncodedLen, PartialEq, RuntimeDebug, TypeInfo)] +#[derive( + CloneNoBound, + Encode, + Decode, + EqNoBound, + MaxEncodedLen, + PartialEqNoBound, + RuntimeDebugNoBound, + TypeInfo, +)] #[codec(mel_bound())] -#[cfg_attr(test, derive(Default))] -pub struct IdentityInfo { +#[cfg_attr(test, derive(frame_support::DefaultNoBound))] +#[scale_info(skip_type_params(FieldLimit))] +pub struct IdentityInfo<FieldLimit: Get<u32>> { + /// Additional fields of the identity that are not catered for with the struct's explicit + /// fields. + pub additional: BoundedVec<(Data, Data), FieldLimit>, + /// A reasonable display name for the controller of the account. This should be whatever it is /// that it is typically known as and should not be confusable with other entities, given /// reasonable context. @@ -140,7 +155,7 @@ pub struct IdentityInfo { pub twitter: Data, } -impl IdentityInformationProvider for IdentityInfo { +impl<FieldLimit: Get<u32> + 'static> IdentityInformationProvider for IdentityInfo<FieldLimit> { type IdentityField = IdentityField; fn has_identity(&self, fields: u64) -> bool { @@ -152,6 +167,7 @@ impl IdentityInformationProvider for IdentityInfo { let data = Data::Raw(vec![0; 32].try_into().unwrap()); IdentityInfo { + additional: Default::default(), display: data.clone(), legal: data.clone(), web: data.clone(), @@ -164,7 +180,7 @@ impl IdentityInformationProvider for IdentityInfo { } } -impl IdentityInfo { +impl<FieldLimit: Get<u32>> IdentityInfo<FieldLimit> { #[allow(unused)] pub(crate) fn fields(&self) -> IdentityFields<IdentityField> { let mut res = <BitFlags<IdentityField>>::empty(); diff --git a/substrate/frame/identity/src/tests.rs b/substrate/frame/identity/src/tests.rs index a739ddeb690ab..351bf54c1e13b 100644 --- a/substrate/frame/identity/src/tests.rs +++ b/substrate/frame/identity/src/tests.rs @@ -107,7 +107,7 @@ impl pallet_identity::Config for Test { type BasicDeposit = ConstU64<10>; type SubAccountDeposit = ConstU64<10>; type MaxSubAccounts = ConstU32<2>; - type IdentityInformation = IdentityInfo; + type IdentityInformation = IdentityInfo<MaxAdditionalFields>; type MaxRegistrars = MaxRegistrars; type RegistrarOrigin = EnsureOneOrRoot; type ForceOrigin = EnsureTwoOrRoot; @@ -124,7 +124,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { t.into() } -fn ten() -> IdentityInfo { +fn ten() -> IdentityInfo<MaxAdditionalFields> { IdentityInfo { display: Data::Raw(b"ten".to_vec().try_into().unwrap()), legal: Data::Raw(b"The Right Ordinal Ten, Esq.".to_vec().try_into().unwrap()), @@ -132,7 +132,7 @@ fn ten() -> IdentityInfo { } } -fn twenty() -> IdentityInfo { +fn twenty() -> IdentityInfo<MaxAdditionalFields> { IdentityInfo { display: Data::Raw(b"twenty".to_vec().try_into().unwrap()), legal: Data::Raw(b"The Right Ordinal Twenty, Esq.".to_vec().try_into().unwrap()), @@ -262,6 +262,10 @@ fn registration_should_work() { new_test_ext().execute_with(|| { assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3)); assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10)); + let mut three_fields = ten(); + three_fields.additional.try_push(Default::default()).unwrap(); + three_fields.additional.try_push(Default::default()).unwrap(); + assert!(three_fields.additional.try_push(Default::default()).is_err()); assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten()))); assert_eq!(Identity::identity(10).unwrap().info, ten()); assert_eq!(Balances::free_balance(10), 90); From 63dbc74a5a73b488e0995057d239708aa33cb2ad Mon Sep 17 00:00:00 2001 From: georgepisaltu <george.pisaltu@parity.io> Date: Wed, 27 Sep 2023 11:54:10 +0300 Subject: [PATCH 09/14] Remove unnecessary bounds on `IdentityField` Signed-off-by: georgepisaltu <george.pisaltu@parity.io> --- substrate/frame/identity/src/simple.rs | 34 +------------------------- substrate/frame/identity/src/types.rs | 21 +++++----------- 2 files changed, 7 insertions(+), 48 deletions(-) diff --git a/substrate/frame/identity/src/simple.rs b/substrate/frame/identity/src/simple.rs index 5ec8d05a29df0..8617dd94d022f 100644 --- a/substrate/frame/identity/src/simple.rs +++ b/substrate/frame/identity/src/simple.rs @@ -28,7 +28,7 @@ use crate::types::{Data, IdentityFields, IdentityInformationProvider, U64BitFlag /// in the `IdentityInfo` struct. #[bitflags] #[repr(u64)] -#[derive(MaxEncodedLen, Clone, Copy, PartialEq, Eq, RuntimeDebug)] +#[derive(Clone, Copy, PartialEq, Eq, RuntimeDebug)] pub enum IdentityField { Display = 1u64 << 0, Legal = 1u64 << 1, @@ -58,38 +58,6 @@ impl TypeInfo for IdentityField { } } -impl Encode for IdentityField { - fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R { - let x: u8 = match self { - IdentityField::Display => 0, - IdentityField::Legal => 1, - IdentityField::Web => 2, - IdentityField::Riot => 3, - IdentityField::Email => 4, - IdentityField::PgpFingerprint => 5, - IdentityField::Image => 6, - IdentityField::Twitter => 7, - }; - f(&x.encode()) - } -} - -impl Decode for IdentityField { - fn decode<I: codec::Input>(input: &mut I) -> Result<Self, codec::Error> { - match u8::decode(input) { - Ok(0) => Ok(IdentityField::Display), - Ok(1) => Ok(IdentityField::Legal), - Ok(2) => Ok(IdentityField::Web), - Ok(3) => Ok(IdentityField::Riot), - Ok(4) => Ok(IdentityField::Email), - Ok(5) => Ok(IdentityField::PgpFingerprint), - Ok(6) => Ok(IdentityField::Image), - Ok(7) => Ok(IdentityField::Twitter), - _ => Err("Invalid IdentityField representation".into()), - } - } -} - impl U64BitFlag for IdentityField {} /// Information concerning the identity of the controller of an account. diff --git a/substrate/frame/identity/src/types.rs b/substrate/frame/identity/src/types.rs index 963923a9d1af0..2431921dfa8e5 100644 --- a/substrate/frame/identity/src/types.rs +++ b/substrate/frame/identity/src/types.rs @@ -236,15 +236,7 @@ pub trait IdentityInformationProvider: { /// Type capable of representing all of the fields present in the identity information as bit /// flags in `u64` format. - type IdentityField: Encode - + Decode - + MaxEncodedLen - + Clone - + Debug - + Eq - + PartialEq - + TypeInfo - + U64BitFlag; + type IdentityField: Clone + Debug + Eq + PartialEq + TypeInfo + U64BitFlag; fn has_identity(&self, fields: u64) -> bool; #[cfg(feature = "runtime-benchmarks")] @@ -292,7 +284,7 @@ impl< pub struct RegistrarInfo< Balance: Encode + Decode + Clone + Debug + Eq + PartialEq, AccountId: Encode + Decode + Clone + Debug + Eq + PartialEq, - IdField: Encode + Decode + MaxEncodedLen + Clone + Debug + Eq + PartialEq + TypeInfo + U64BitFlag, + IdField: Clone + Debug + Eq + PartialEq + TypeInfo + U64BitFlag, > { /// The account of the registrar. pub account: AccountId, @@ -325,21 +317,20 @@ where } impl<IdField: U64BitFlag + PartialEq> Eq for IdentityFields<IdField> {} -impl<IdField: Encode + Decode + U64BitFlag> Encode for IdentityFields<IdField> { +impl<IdField: U64BitFlag> Encode for IdentityFields<IdField> { fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R { let bits: u64 = self.0.bits(); bits.using_encoded(f) } } -impl<IdField: Encode + Decode + U64BitFlag> Decode for IdentityFields<IdField> { +impl<IdField: U64BitFlag> Decode for IdentityFields<IdField> { fn decode<I: codec::Input>(input: &mut I) -> sp_std::result::Result<Self, codec::Error> { let field = u64::decode(input)?; Ok(Self(<BitFlags<IdField>>::from_bits(field).map_err(|_| "invalid value")?)) } } -impl< - IdField: Encode + Decode + MaxEncodedLen + Clone + Debug + Eq + PartialEq + TypeInfo + U64BitFlag, - > TypeInfo for IdentityFields<IdField> +impl<IdField: Clone + Debug + Eq + PartialEq + TypeInfo + U64BitFlag> TypeInfo + for IdentityFields<IdField> { type Identity = Self; From 8d3b22e92ab8918294fded18046aea061ddd1f36 Mon Sep 17 00:00:00 2001 From: georgepisaltu <george.pisaltu@parity.io> Date: Mon, 16 Oct 2023 18:09:08 +0300 Subject: [PATCH 10/14] Add additional field logic back into impl Signed-off-by: georgepisaltu <george.pisaltu@parity.io> --- polkadot/runtime/rococo/src/lib.rs | 2 + .../rococo/src/weights/pallet_identity.rs | 40 +++-- polkadot/runtime/westend/src/lib.rs | 2 + .../westend/src/weights/pallet_identity.rs | 39 +++-- substrate/bin/node/runtime/src/lib.rs | 2 + substrate/frame/alliance/src/mock.rs | 4 +- substrate/frame/identity/src/benchmarking.rs | 46 +++--- substrate/frame/identity/src/lib.rs | 138 ++++++++++-------- substrate/frame/identity/src/simple.rs | 8 +- substrate/frame/identity/src/tests.rs | 29 ++++ substrate/frame/identity/src/types.rs | 38 ++++- substrate/frame/identity/src/weights.rs | 79 +++++++--- 12 files changed, 295 insertions(+), 132 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index b7322bfaad816..e38488f5a2139 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -612,8 +612,10 @@ impl pallet_identity::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; type BasicDeposit = BasicDeposit; + type FieldDeposit = FieldDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; + type MaxAdditionalFields = MaxAdditionalFields; type IdentityInformation = IdentityInfo<MaxAdditionalFields>; type MaxRegistrars = MaxRegistrars; type Slashed = Treasury; diff --git a/polkadot/runtime/rococo/src/weights/pallet_identity.rs b/polkadot/runtime/rococo/src/weights/pallet_identity.rs index 7406ae6779e0c..e10c042dde6aa 100644 --- a/polkadot/runtime/rococo/src/weights/pallet_identity.rs +++ b/polkadot/runtime/rococo/src/weights/pallet_identity.rs @@ -65,7 +65,8 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. - fn set_identity(r: u32, ) -> Weight { + /// The range of component `x` is `[0, 100]`. + fn set_identity(r: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `442 + r * (5 ±0)` // Estimated: `11003` @@ -74,6 +75,8 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 2_307 .saturating_add(Weight::from_parts(92_753, 0).saturating_mul(r.into())) + // Standard Error: 450 + .saturating_add(Weight::from_parts(449_529, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -127,15 +130,18 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Proof: Identity SuperOf (max_values: None, max_size: Some(114), added: 2589, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. /// The range of component `s` is `[0, 100]`. - fn clear_identity(_r: u32, s: u32, ) -> Weight { + /// The range of component `x` is `[0, 100]`. + fn clear_identity(_r: u32, s: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `469 + r * (5 ±0) + s * (32 ±0)` + // Measured: `469 + r * (5 ±0) + s * (32 ±0) + x * (66 ±0)` // Estimated: `11003` // Minimum execution time: 53_365_000 picoseconds. Weight::from_parts(35_391_422, 0) .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 1_353 .saturating_add(Weight::from_parts(1_074_019, 0).saturating_mul(s.into())) + // Standard Error: 1_353 + .saturating_add(Weight::from_parts(229_947, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) @@ -145,30 +151,36 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. - fn request_judgement(r: u32, ) -> Weight { + /// The range of component `x` is `[0, 100]`. + fn request_judgement(r: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `367 + r * (57 ±0)` + // Measured: `367 + r * (57 ±0) + x * (66 ±0)` // Estimated: `11003` // Minimum execution time: 32_509_000 picoseconds. Weight::from_parts(31_745_585, 0) .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 2_214 .saturating_add(Weight::from_parts(83_822, 0).saturating_mul(r.into())) + // Standard Error: 432 + .saturating_add(Weight::from_parts(458_801, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. - fn cancel_request(r: u32, ) -> Weight { + /// The range of component `x` is `[0, 100]`. + fn cancel_request(r: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `398` + // Measured: `398 + x * (66 ±0)` // Estimated: `11003` // Minimum execution time: 29_609_000 picoseconds. Weight::from_parts(28_572_602, 0) .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 2_528 .saturating_add(Weight::from_parts(85_593, 0).saturating_mul(r.into())) + // Standard Error: 493 + .saturating_add(Weight::from_parts(468_140, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -222,15 +234,18 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 19]`. - fn provide_judgement(r: u32, ) -> Weight { + /// The range of component `x` is `[0, 100]`. + fn provide_judgement(r: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `445 + r * (57 ±0)` + // Measured: `445 + r * (57 ±0) + x * (66 ±0)` // Estimated: `11003` // Minimum execution time: 23_114_000 picoseconds. Weight::from_parts(22_076_548, 0) .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 2_881 .saturating_add(Weight::from_parts(109_812, 0).saturating_mul(r.into())) + // Standard Error: 533 + .saturating_add(Weight::from_parts(733_244, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -244,9 +259,10 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Proof: Identity SuperOf (max_values: None, max_size: Some(114), added: 2589, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. /// The range of component `s` is `[0, 100]`. - fn kill_identity(r: u32, s: u32, ) -> Weight { + /// The range of component `x` is `[0, 100]`. + fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `676 + r * (5 ±0) + s * (32 ±0)` + // Measured: `676 + r * (5 ±0) + s * (32 ±0) + x * (66 ±0)` // Estimated: `11003` // Minimum execution time: 70_007_000 picoseconds. Weight::from_parts(50_186_495, 0) @@ -255,6 +271,8 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { .saturating_add(Weight::from_parts(15_486, 0).saturating_mul(r.into())) // Standard Error: 1_275 .saturating_add(Weight::from_parts(1_085_117, 0).saturating_mul(s.into())) + // Standard Error: 1_275 + .saturating_add(Weight::from_parts(228_226, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(3)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index fb00a87daf48b..6faae25a00e9e 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -881,8 +881,10 @@ impl pallet_identity::Config for Runtime { type Currency = Balances; type Slashed = (); type BasicDeposit = BasicDeposit; + type FieldDeposit = FieldDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; + type MaxAdditionalFields = MaxAdditionalFields; type IdentityInformation = IdentityInfo<MaxAdditionalFields>; type MaxRegistrars = MaxRegistrars; type ForceOrigin = EitherOf<EnsureRoot<Self::AccountId>, GeneralAdmin>; diff --git a/polkadot/runtime/westend/src/weights/pallet_identity.rs b/polkadot/runtime/westend/src/weights/pallet_identity.rs index 5edbe9d284ef3..8c11482ebdc13 100644 --- a/polkadot/runtime/westend/src/weights/pallet_identity.rs +++ b/polkadot/runtime/westend/src/weights/pallet_identity.rs @@ -68,7 +68,8 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. - fn set_identity(r: u32, ) -> Weight { + /// The range of component `x` is `[0, 100]`. + fn set_identity(r: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `442 + r * (5 ±0)` // Estimated: `11003` @@ -77,6 +78,8 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 7_269 .saturating_add(Weight::from_parts(250_439, 0).saturating_mul(r.into())) + // Standard Error: 1_418 + .saturating_add(Weight::from_parts(483_981, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -130,9 +133,10 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Proof: Identity SuperOf (max_values: None, max_size: Some(114), added: 2589, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. /// The range of component `s` is `[0, 100]`. - fn clear_identity(r: u32, s: u32, ) -> Weight { + /// The range of component `x` is `[0, 100]`. + fn clear_identity(r: u32, s: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `469 + r * (5 ±0) + s * (32 ±0)` + // Measured: `469 + r * (5 ±0) + s * (32 ±0) + x * (66 ±0)` // Estimated: `11003` // Minimum execution time: 60_177_000 picoseconds. Weight::from_parts(26_533_717, 0) @@ -141,6 +145,8 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { .saturating_add(Weight::from_parts(475_120, 0).saturating_mul(r.into())) // Standard Error: 4_092 .saturating_add(Weight::from_parts(1_348_869, 0).saturating_mul(s.into())) + // Standard Error: 4_092 + .saturating_add(Weight::from_parts(314_033, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) @@ -151,30 +157,35 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. /// The range of component `x` is `[0, 100]`. - fn request_judgement(r: u32, ) -> Weight { + fn request_judgement(r: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `367 + r * (57 ±0)` + // Measured: `367 + r * (57 ±0) + x * (66 ±0)` // Estimated: `11003` // Minimum execution time: 32_818_000 picoseconds. Weight::from_parts(32_253_281, 0) .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 7_973 .saturating_add(Weight::from_parts(124_283, 0).saturating_mul(r.into())) + // Standard Error: 1_555 + .saturating_add(Weight::from_parts(512_825, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. - fn cancel_request(r: u32, ) -> Weight { + /// The range of component `x` is `[0, 100]`. + fn cancel_request(r: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `398` + // Measured: `398 + x * (66 ±0)` // Estimated: `11003` // Minimum execution time: 29_931_000 picoseconds. Weight::from_parts(28_643_196, 0) .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 5_154 .saturating_add(Weight::from_parts(147_560, 0).saturating_mul(r.into())) + // Standard Error: 1_005 + .saturating_add(Weight::from_parts(490_754, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -228,15 +239,18 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 19]`. - fn provide_judgement(r: u32, ) -> Weight { + /// The range of component `x` is `[0, 100]`. + fn provide_judgement(r: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `445 + r * (57 ±0)` + // Measured: `445 + r * (57 ±0) + x * (66 ±0)` // Estimated: `11003` // Minimum execution time: 22_742_000 picoseconds. Weight::from_parts(21_879_281, 0) .saturating_add(Weight::from_parts(0, 11003)) // Standard Error: 10_027 .saturating_add(Weight::from_parts(154_816, 0).saturating_mul(r.into())) + // Standard Error: 1_855 + .saturating_add(Weight::from_parts(803_084, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -250,9 +264,10 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { /// Proof: Identity SuperOf (max_values: None, max_size: Some(114), added: 2589, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. /// The range of component `s` is `[0, 100]`. - fn kill_identity(r: u32, s: u32, ) -> Weight { + /// The range of component `x` is `[0, 100]`. + fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `676 + r * (5 ±0) + s * (32 ±0)` + // Measured: `676 + r * (5 ±0) + s * (32 ±0) + x * (66 ±0)` // Estimated: `11003` // Minimum execution time: 64_467_000 picoseconds. Weight::from_parts(27_806_692, 0) @@ -261,6 +276,8 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> { .saturating_add(Weight::from_parts(666_376, 0).saturating_mul(r.into())) // Standard Error: 4_433 .saturating_add(Weight::from_parts(1_396_065, 0).saturating_mul(s.into())) + // Standard Error: 4_433 + .saturating_add(Weight::from_parts(300_762, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(3)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 12ea0f534ce1f..f49fa2c1f6f8b 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -1470,8 +1470,10 @@ impl pallet_identity::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; type BasicDeposit = BasicDeposit; + type FieldDeposit = FieldDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; + type MaxAdditionalFields = MaxAdditionalFields; type IdentityInformation = IdentityInfo<MaxAdditionalFields>; type MaxRegistrars = MaxRegistrars; type Slashed = Treasury; diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index e5fb9a47a4eb5..f8c1920bc72a7 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -116,8 +116,10 @@ impl pallet_identity::Config for Test { type RuntimeEvent = RuntimeEvent; type Currency = Balances; type BasicDeposit = BasicDeposit; + type FieldDeposit = FieldDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; + type MaxAdditionalFields = MaxAdditionalFields; type IdentityInformation = IdentityInfo<MaxAdditionalFields>; type MaxRegistrars = MaxRegistrars; type Slashed = (); @@ -261,7 +263,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 1)); let info = IdentityInfo { - additional: Default::default(), + additional: BoundedVec::default(), display: Data::Raw(b"name".to_vec().try_into().unwrap()), legal: Data::default(), web: Data::Raw(b"website".to_vec().try_into().unwrap()), diff --git a/substrate/frame/identity/src/benchmarking.rs b/substrate/frame/identity/src/benchmarking.rs index 315fd457eb59b..9568c3033589c 100644 --- a/substrate/frame/identity/src/benchmarking.rs +++ b/substrate/frame/identity/src/benchmarking.rs @@ -47,7 +47,9 @@ fn add_registrars<T: Config>(r: u32) -> Result<(), &'static str> { .expect("RegistrarOrigin has no successful origin required for the benchmark"); Identity::<T>::add_registrar(registrar_origin, registrar_lookup)?; Identity::<T>::set_fee(RawOrigin::Signed(registrar.clone()).into(), i, 10u32.into())?; - let fields = Default::default(); + let fields = IdentityFields( + <T::IdentityInformation as IdentityInformationProvider>::IdentityField::all(), + ); Identity::<T>::set_fields(RawOrigin::Signed(registrar.clone()).into(), i, fields)?; } @@ -73,7 +75,7 @@ fn create_sub_accounts<T: Config>( // Set identity so `set_subs` does not fail. if IdentityOf::<T>::get(who).is_none() { let _ = T::Currency::make_free_balance_be(who, BalanceOf::<T>::max_value() / 2u32.into()); - let info = T::IdentityInformation::create_identity_info(); + let info = T::IdentityInformation::create_identity_info(1); Identity::<T>::set_identity(who_origin.into(), Box::new(info))?; } @@ -108,6 +110,7 @@ benchmarks! { set_identity { let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?; + let x in 0 .. T::MaxAdditionalFields::get(); let caller = { // The target user let caller: T::AccountId = whitelisted_caller(); @@ -116,7 +119,7 @@ benchmarks! { let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value()); // Add an initial identity - let initial_info = T::IdentityInformation::create_identity_info(); + let initial_info = T::IdentityInformation::create_identity_info(1); Identity::<T>::set_identity(caller_origin.clone(), Box::new(initial_info.clone()))?; // User requests judgement from all the registrars, and they approve @@ -137,7 +140,7 @@ benchmarks! { } caller }; - }: _(RawOrigin::Signed(caller.clone()), Box::new(T::IdentityInformation::create_identity_info())) + }: _(RawOrigin::Signed(caller.clone()), Box::new(T::IdentityInformation::create_identity_info(x))) verify { assert_last_event::<T>(Event::<T>::IdentitySet { who: caller }.into()); } @@ -185,9 +188,10 @@ benchmarks! { let caller: T::AccountId = whitelisted_caller(); let _ = add_sub_accounts::<T>(&caller, s)?; }; + let x in 0 .. T::MaxAdditionalFields::get(); - // Create their main identity - let info = T::IdentityInformation::create_identity_info(); + // Create their main identity with x additional fields + let info = T::IdentityInformation::create_identity_info(x); let caller: T::AccountId = whitelisted_caller(); let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); Identity::<T>::set_identity(caller_origin.clone(), Box::new(info.clone()))?; @@ -218,11 +222,13 @@ benchmarks! { let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value()); let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?; - // Create their main identity - let info = T::IdentityInformation::create_identity_info(); - let caller: T::AccountId = whitelisted_caller(); - let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); - Identity::<T>::set_identity(caller_origin, Box::new(info))?; + let x in 0 .. T::MaxAdditionalFields::get() => { + // Create their main identity with x additional fields + let info = T::IdentityInformation::create_identity_info(x); + let caller: T::AccountId = whitelisted_caller(); + let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller)); + Identity::<T>::set_identity(caller_origin, Box::new(info))?; + }; }: _(RawOrigin::Signed(caller.clone()), r - 1, 10u32.into()) verify { assert_last_event::<T>(Event::<T>::JudgementRequested { who: caller, registrar_index: r-1 }.into()); @@ -234,11 +240,13 @@ benchmarks! { let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value()); let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?; - // Create their main identity with - let info = T::IdentityInformation::create_identity_info(); - let caller: T::AccountId = whitelisted_caller(); - let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); - Identity::<T>::set_identity(caller_origin.clone(), Box::new(info))?; + let x in 0 .. T::MaxAdditionalFields::get() => { + // Create their main identity with x additional fields + let info = T::IdentityInformation::create_identity_info(x); + let caller: T::AccountId = whitelisted_caller(); + let caller_origin = <T as frame_system::Config>::RuntimeOrigin::from(RawOrigin::Signed(caller)); + Identity::<T>::set_identity(caller_origin, Box::new(info))?; + }; Identity::<T>::request_judgement(caller_origin, r - 1, 10u32.into())?; }: _(RawOrigin::Signed(caller.clone()), r - 1) @@ -315,8 +323,9 @@ benchmarks! { let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::<T>::max_value()); let r in 1 .. T::MaxRegistrars::get() - 1 => add_registrars::<T>(r)?; + let x in 0 .. T::MaxAdditionalFields::get(); - let info = T::IdentityInformation::create_identity_info(); + let info = T::IdentityInformation::create_identity_info(x); let info_hash = T::Hashing::hash_of(&info); Identity::<T>::set_identity(user_origin.clone(), Box::new(info))?; @@ -332,13 +341,14 @@ benchmarks! { kill_identity { let r in 1 .. T::MaxRegistrars::get() => add_registrars::<T>(r)?; let s in 0 .. T::MaxSubAccounts::get(); + let x in 0 .. T::MaxAdditionalFields::get(); let target: T::AccountId = account("target", 0, SEED); let target_origin: <T as frame_system::Config>::RuntimeOrigin = RawOrigin::Signed(target.clone()).into(); let target_lookup = T::Lookup::unlookup(target.clone()); let _ = T::Currency::make_free_balance_be(&target, BalanceOf::<T>::max_value()); - let info = T::IdentityInformation::create_identity_info(); + let info = T::IdentityInformation::create_identity_info(x); Identity::<T>::set_identity(target_origin.clone(), Box::new(info.clone()))?; let _ = add_sub_accounts::<T>(&target, s)?; diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 06818b188c2cd..fad0008f9cfc8 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -113,6 +113,10 @@ pub mod pallet { #[pallet::constant] type BasicDeposit: Get<BalanceOf<Self>>; + /// The amount held on deposit per additional field for a registered identity. + #[pallet::constant] + type FieldDeposit: Get<BalanceOf<Self>>; + /// The amount held on deposit for a registered subaccount. This should account for the fact /// that one storage item's value will increase by the size of an account ID, and there will /// be another trie item whose value is the size of an account ID plus 32 bytes. @@ -123,6 +127,11 @@ pub mod pallet { #[pallet::constant] type MaxSubAccounts: Get<u32>; + /// Maximum number of additional fields that may be stored in an ID. Needed to bound the I/O + /// required to access an identity, but can be pretty high. + #[pallet::constant] + type MaxAdditionalFields: Get<u32>; + /// Structure holding information about an identity. type IdentityInformation: IdentityInformationProvider; @@ -227,6 +236,8 @@ pub mod pallet { InvalidIndex, /// The target is invalid. InvalidTarget, + /// Too many additional fields. + TooManyFields, /// Maximum amount of registrars reached. Cannot add any more. TooManyRegistrars, /// Account ID is already named. @@ -317,36 +328,50 @@ pub mod pallet { /// - `info`: The identity information. /// /// Emits `IdentitySet` if successful. - /// - /// ## Complexity - /// - `O(R)` - /// - where `R` judgements-count (registrar-count-bounded) #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::set_identity(T::MaxRegistrars::get()))] + #[pallet::weight(T::WeightInfo::set_identity( + T::MaxRegistrars::get(), + T::MaxAdditionalFields::get(), + ))] pub fn set_identity( origin: OriginFor<T>, info: Box<T::IdentityInformation>, ) -> DispatchResultWithPostInfo { let sender = ensure_signed(origin)?; + #[allow(deprecated)] + let extra_fields = info.additional() as u32; + ensure!(extra_fields <= T::MaxAdditionalFields::get(), Error::<T>::TooManyFields); + let fd = <BalanceOf<T>>::from(extra_fields) * T::FieldDeposit::get(); - let id = match <IdentityOf<T>>::get(&sender) { + let mut id = match <IdentityOf<T>>::get(&sender) { Some(mut id) => { // Only keep non-positive judgements. id.judgements.retain(|j| j.1.is_sticky()); id.info = *info; id }, - None => { - T::Currency::reserve(&sender, T::BasicDeposit::get())?; - Registration { info: *info, judgements: BoundedVec::default() } + None => Registration { + info: *info, + judgements: BoundedVec::default(), + deposit: Zero::zero(), }, }; + let old_deposit = id.deposit; + id.deposit = T::BasicDeposit::get() + fd; + if id.deposit > old_deposit { + T::Currency::reserve(&sender, id.deposit - old_deposit)?; + } + if old_deposit > id.deposit { + let err_amount = T::Currency::unreserve(&sender, old_deposit - id.deposit); + debug_assert!(err_amount.is_zero()); + } + let judgements = id.judgements.len(); <IdentityOf<T>>::insert(&sender, id); Self::deposit_event(Event::IdentitySet { who: sender }); - Ok(Some(T::WeightInfo::set_identity(judgements as u32)).into()) // R + Ok(Some(T::WeightInfo::set_identity(judgements as u32, extra_fields)).into()) // R } /// Set the sub-accounts of the sender. @@ -431,22 +456,18 @@ pub mod pallet { /// identity. /// /// Emits `IdentityCleared` if successful. - /// - /// ## Complexity - /// - `O(R + S)` - /// - where `R` registrar-count (governance-bounded). - /// - where `S` subs-count (hard- and deposit-bounded). #[pallet::call_index(3)] #[pallet::weight(T::WeightInfo::clear_identity( - T::MaxRegistrars::get(), // R - T::MaxSubAccounts::get(), // S + T::MaxRegistrars::get(), + T::MaxSubAccounts::get(), + T::MaxAdditionalFields::get(), ))] pub fn clear_identity(origin: OriginFor<T>) -> DispatchResultWithPostInfo { let sender = ensure_signed(origin)?; let (subs_deposit, sub_ids) = <SubsOf<T>>::take(&sender); let id = <IdentityOf<T>>::take(&sender).ok_or(Error::<T>::NotNamed)?; - let deposit = T::BasicDeposit::get() + subs_deposit; + let deposit = id.total_deposit() + subs_deposit; for sub in sub_ids.iter() { <SuperOf<T>>::remove(sub); } @@ -456,9 +477,11 @@ pub mod pallet { Self::deposit_event(Event::IdentityCleared { who: sender, deposit }); + #[allow(deprecated)] Ok(Some(T::WeightInfo::clear_identity( - id.judgements.len() as u32, // R - sub_ids.len() as u32, // S + id.judgements.len() as u32, + sub_ids.len() as u32, + id.info.additional() as u32, )) .into()) } @@ -479,12 +502,11 @@ pub mod pallet { /// ``` /// /// Emits `JudgementRequested` if successful. - /// - /// ## Complexity - /// - `O(R)`. - /// - where `R` registrar-count (governance-bounded). #[pallet::call_index(4)] - #[pallet::weight(T::WeightInfo::request_judgement(T::MaxRegistrars::get()))] + #[pallet::weight(T::WeightInfo::request_judgement( + T::MaxRegistrars::get(), + T::MaxAdditionalFields::get(), + ))] pub fn request_judgement( origin: OriginFor<T>, #[pallet::compact] reg_index: RegistrarIndex, @@ -514,6 +536,8 @@ pub mod pallet { T::Currency::reserve(&sender, registrar.fee)?; let judgements = id.judgements.len(); + #[allow(deprecated)] + let extra_fields = id.info.additional(); <IdentityOf<T>>::insert(&sender, id); Self::deposit_event(Event::JudgementRequested { @@ -521,7 +545,8 @@ pub mod pallet { registrar_index: reg_index, }); - Ok(Some(T::WeightInfo::request_judgement(judgements as u32)).into()) // R + Ok(Some(T::WeightInfo::request_judgement(judgements as u32, extra_fields as u32)) + .into()) } /// Cancel a previous request. @@ -534,12 +559,11 @@ pub mod pallet { /// - `reg_index`: The index of the registrar whose judgement is no longer requested. /// /// Emits `JudgementUnrequested` if successful. - /// - /// ## Complexity - /// - `O(R)`. - /// - where `R` registrar-count (governance-bounded). #[pallet::call_index(5)] - #[pallet::weight(T::WeightInfo::cancel_request(T::MaxRegistrars::get()))] + #[pallet::weight(T::WeightInfo::cancel_request( + T::MaxRegistrars::get(), + T::MaxAdditionalFields::get(), + ))] pub fn cancel_request( origin: OriginFor<T>, reg_index: RegistrarIndex, @@ -560,6 +584,8 @@ pub mod pallet { let err_amount = T::Currency::unreserve(&sender, fee); debug_assert!(err_amount.is_zero()); let judgements = id.judgements.len(); + #[allow(deprecated)] + let extra_fields = id.info.additional(); <IdentityOf<T>>::insert(&sender, id); Self::deposit_event(Event::JudgementUnrequested { @@ -567,7 +593,7 @@ pub mod pallet { registrar_index: reg_index, }); - Ok(Some(T::WeightInfo::cancel_request(judgements as u32)).into()) // R + Ok(Some(T::WeightInfo::cancel_request(judgements as u32, extra_fields as u32)).into()) } /// Set the fee required for a judgement to be requested from a registrar. @@ -577,10 +603,6 @@ pub mod pallet { /// /// - `index`: the index of the registrar whose fee is to be set. /// - `fee`: the new fee. - /// - /// ## Complexity - /// - `O(R)`. - /// - where `R` registrar-count (governance-bounded). #[pallet::call_index(6)] #[pallet::weight(T::WeightInfo::set_fee(T::MaxRegistrars::get()))] // R pub fn set_fee( @@ -604,7 +626,7 @@ pub mod pallet { .ok_or_else(|| DispatchError::from(Error::<T>::InvalidIndex))?; Ok(rs.len()) })?; - Ok(Some(T::WeightInfo::set_fee(registrars as u32)).into()) // R + Ok(Some(T::WeightInfo::set_fee(registrars as u32)).into()) } /// Change the account associated with a registrar. @@ -642,7 +664,7 @@ pub mod pallet { .ok_or_else(|| DispatchError::from(Error::<T>::InvalidIndex))?; Ok(rs.len()) })?; - Ok(Some(T::WeightInfo::set_account_id(registrars as u32)).into()) // R + Ok(Some(T::WeightInfo::set_account_id(registrars as u32)).into()) } /// Set the field information for a registrar. @@ -652,12 +674,8 @@ pub mod pallet { /// /// - `index`: the index of the registrar whose fee is to be set. /// - `fields`: the fields that the registrar concerns themselves with. - /// - /// ## Complexity - /// - `O(R)`. - /// - where `R` registrar-count (governance-bounded). #[pallet::call_index(8)] - #[pallet::weight(T::WeightInfo::set_fields(T::MaxRegistrars::get()))] // R + #[pallet::weight(T::WeightInfo::set_fields(T::MaxRegistrars::get()))] pub fn set_fields( origin: OriginFor<T>, #[pallet::compact] index: RegistrarIndex, @@ -681,7 +699,7 @@ pub mod pallet { .ok_or_else(|| DispatchError::from(Error::<T>::InvalidIndex))?; Ok(rs.len()) })?; - Ok(Some(T::WeightInfo::set_fields(registrars as u32)).into()) // R + Ok(Some(T::WeightInfo::set_fields(registrars as u32)).into()) } /// Provide a judgement for an account's identity. @@ -696,12 +714,11 @@ pub mod pallet { /// - `identity`: The hash of the [`IdentityInfo`] for that the judgement is provided. /// /// Emits `JudgementGiven` if successful. - /// - /// ## Complexity - /// - `O(R)`. - /// - where `R` registrar-count (governance-bounded). #[pallet::call_index(9)] - #[pallet::weight(T::WeightInfo::provide_judgement(T::MaxRegistrars::get()))] // R + #[pallet::weight(T::WeightInfo::provide_judgement( + T::MaxRegistrars::get(), + T::MaxAdditionalFields::get(), + ))] pub fn provide_judgement( origin: OriginFor<T>, #[pallet::compact] reg_index: RegistrarIndex, @@ -744,10 +761,13 @@ pub mod pallet { } let judgements = id.judgements.len(); + #[allow(deprecated)] + let extra_fields = id.info.additional(); <IdentityOf<T>>::insert(&target, id); Self::deposit_event(Event::JudgementGiven { target, registrar_index: reg_index }); - Ok(Some(T::WeightInfo::provide_judgement(judgements as u32)).into()) // R + Ok(Some(T::WeightInfo::provide_judgement(judgements as u32, extra_fields as u32)) + .into()) } /// Remove an account's identity and sub-account information and slash the deposits. @@ -762,15 +782,11 @@ pub mod pallet { /// with a registered identity. /// /// Emits `IdentityKilled` if successful. - /// - /// ## Complexity - /// - `O(R + S)` - /// - where `R` registrar-count (governance-bounded). - /// - where `S` subs-count (hard- and deposit-bounded). #[pallet::call_index(10)] #[pallet::weight(T::WeightInfo::kill_identity( - T::MaxRegistrars::get(), // R - T::MaxSubAccounts::get(), // S + T::MaxRegistrars::get(), + T::MaxSubAccounts::get(), + T::MaxAdditionalFields::get(), ))] pub fn kill_identity( origin: OriginFor<T>, @@ -783,7 +799,7 @@ pub mod pallet { // Grab their deposit (and check that they have one). let (subs_deposit, sub_ids) = <SubsOf<T>>::take(&target); let id = <IdentityOf<T>>::take(&target).ok_or(Error::<T>::NotNamed)?; - let deposit = T::BasicDeposit::get() + subs_deposit; + let deposit = id.total_deposit() + subs_deposit; for sub in sub_ids.iter() { <SuperOf<T>>::remove(sub); } @@ -792,9 +808,11 @@ pub mod pallet { Self::deposit_event(Event::IdentityKilled { who: target, deposit }); + #[allow(deprecated)] Ok(Some(T::WeightInfo::kill_identity( - id.judgements.len() as u32, // R - sub_ids.len() as u32, // S + id.judgements.len() as u32, + sub_ids.len() as u32, + id.info.additional() as u32, )) .into()) } diff --git a/substrate/frame/identity/src/simple.rs b/substrate/frame/identity/src/simple.rs index 8617dd94d022f..761e07e8158ba 100644 --- a/substrate/frame/identity/src/simple.rs +++ b/substrate/frame/identity/src/simple.rs @@ -130,12 +130,16 @@ impl<FieldLimit: Get<u32> + 'static> IdentityInformationProvider for IdentityInf self.fields().0.bits() & fields == fields } + fn additional(&self) -> usize { + self.additional.len() + } + #[cfg(feature = "runtime-benchmarks")] - fn create_identity_info() -> Self { + fn create_identity_info(num_fields: u32) -> Self { let data = Data::Raw(vec![0; 32].try_into().unwrap()); IdentityInfo { - additional: Default::default(), + additional: vec![(data.clone(), data.clone()); num_fields as usize].try_into().unwrap(), display: data.clone(), legal: data.clone(), web: data.clone(), diff --git a/substrate/frame/identity/src/tests.rs b/substrate/frame/identity/src/tests.rs index 351bf54c1e13b..aad35ec06db7a 100644 --- a/substrate/frame/identity/src/tests.rs +++ b/substrate/frame/identity/src/tests.rs @@ -105,8 +105,10 @@ impl pallet_identity::Config for Test { type Currency = Balances; type Slashed = (); type BasicDeposit = ConstU64<10>; + type FieldDeposit = ConstU64<10>; type SubAccountDeposit = ConstU64<10>; type MaxSubAccounts = ConstU32<2>; + type MaxAdditionalFields = MaxAdditionalFields; type IdentityInformation = IdentityInfo<MaxAdditionalFields>; type MaxRegistrars = MaxRegistrars; type RegistrarOrigin = EnsureOneOrRoot; @@ -562,6 +564,33 @@ fn provide_judgement_should_return_judgement_payment_failed_error() { }); } +#[test] +fn field_deposit_should_work() { + new_test_ext().execute_with(|| { + assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3)); + assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10)); + assert_ok!(Identity::set_identity( + RuntimeOrigin::signed(10), + Box::new(IdentityInfo { + additional: vec![ + ( + Data::Raw(b"number".to_vec().try_into().unwrap()), + Data::Raw(10u32.encode().try_into().unwrap()) + ), + ( + Data::Raw(b"text".to_vec().try_into().unwrap()), + Data::Raw(b"10".to_vec().try_into().unwrap()) + ), + ] + .try_into() + .unwrap(), + ..Default::default() + }) + )); + assert_eq!(Balances::free_balance(10), 70); + }); +} + #[test] fn setting_account_id_should_work() { new_test_ext().execute_with(|| { diff --git a/substrate/frame/identity/src/types.rs b/substrate/frame/identity/src/types.rs index 2431921dfa8e5..2cc36a78b8293 100644 --- a/substrate/frame/identity/src/types.rs +++ b/substrate/frame/identity/src/types.rs @@ -26,8 +26,8 @@ use scale_info::{ build::{Fields, Variants}, meta_type, Path, Type, TypeInfo, TypeParameter, }; -use sp_runtime::RuntimeDebug; -use sp_std::{fmt::Debug, iter::once, prelude::*}; +use sp_runtime::{traits::Zero, RuntimeDebug}; +use sp_std::{fmt::Debug, iter::once, ops::Add, prelude::*}; /// An identifier for a single name registrar/identity verification service. pub type RegistrarIndex = u32; @@ -239,8 +239,18 @@ pub trait IdentityInformationProvider: type IdentityField: Clone + Debug + Eq + PartialEq + TypeInfo + U64BitFlag; fn has_identity(&self, fields: u64) -> bool; + + /// Interface for providing the number of additional fields this identity information provider + /// holds, used to charge for additional storage and weight. This interface is present for + /// backwards compatibility reasons only and will be removed as soon as the reference identity + /// provider removes additional fields. + #[deprecated] + fn additional(&self) -> usize { + 0 + } + #[cfg(feature = "runtime-benchmarks")] - fn create_identity_info() -> Self; + fn create_identity_info(num_fields: u32) -> Self; } /// Information on an identity along with judgements from registrars. @@ -262,10 +272,28 @@ pub struct Registration< /// may be only a single judgement from each registrar. pub judgements: BoundedVec<(RegistrarIndex, Judgement<Balance>), MaxJudgements>, + /// Amount held on deposit for this information. + pub deposit: Balance, + /// Information on the identity. pub info: IdentityInfo, } +impl< + Balance: Encode + Decode + MaxEncodedLen + Copy + Clone + Debug + Eq + PartialEq + Zero + Add, + MaxJudgements: Get<u32>, + IdentityInfo: IdentityInformationProvider, + > Registration<Balance, MaxJudgements, IdentityInfo> +{ + pub(crate) fn total_deposit(&self) -> Balance { + self.deposit + + self.judgements + .iter() + .map(|(_, ref j)| if let Judgement::FeePaid(fee) = j { *fee } else { Zero::zero() }) + .fold(Zero::zero(), |a, i| a + i) + } +} + impl< Balance: Encode + Decode + MaxEncodedLen + Copy + Clone + Debug + Eq + PartialEq, MaxJudgements: Get<u32>, @@ -274,8 +302,8 @@ impl< { fn decode<I: codec::Input>(input: &mut I) -> sp_std::result::Result<Self, codec::Error> { // TODO consider removing this, will probably do migration - let (judgements, info) = Decode::decode(&mut AppendZerosInput::new(input))?; - Ok(Self { judgements, info }) + let (judgements, deposit, info) = Decode::decode(&mut AppendZerosInput::new(input))?; + Ok(Self { judgements, deposit, info }) } } diff --git a/substrate/frame/identity/src/weights.rs b/substrate/frame/identity/src/weights.rs index 04ac0f26996d3..02fcd7db3c953 100644 --- a/substrate/frame/identity/src/weights.rs +++ b/substrate/frame/identity/src/weights.rs @@ -53,17 +53,17 @@ use core::marker::PhantomData; /// Weight functions needed for pallet_identity. pub trait WeightInfo { fn add_registrar(r: u32, ) -> Weight; - fn set_identity(r: u32, ) -> Weight; + fn set_identity(r: u32, x: u32, ) -> Weight; fn set_subs_new(s: u32, ) -> Weight; fn set_subs_old(p: u32, ) -> Weight; - fn clear_identity(r: u32, s: u32, ) -> Weight; - fn request_judgement(r: u32, ) -> Weight; - fn cancel_request(r: u32, ) -> Weight; + fn clear_identity(r: u32, s: u32, x: u32, ) -> Weight; + fn request_judgement(r: u32, x: u32, ) -> Weight; + fn cancel_request(r: u32, x: u32, ) -> Weight; fn set_fee(r: u32, ) -> Weight; fn set_account_id(r: u32, ) -> Weight; fn set_fields(r: u32, ) -> Weight; - fn provide_judgement(r: u32, ) -> Weight; - fn kill_identity(r: u32, s: u32, ) -> Weight; + fn provide_judgement(r: u32, x: u32, ) -> Weight; + fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight; fn add_sub(s: u32, ) -> Weight; fn rename_sub(s: u32, ) -> Weight; fn remove_sub(s: u32, ) -> Weight; @@ -90,7 +90,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. - fn set_identity(r: u32, ) -> Weight { + /// The range of component `x` is `[0, 100]`. + fn set_identity(r: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `442 + r * (5 ±0)` // Estimated: `11003` @@ -98,6 +99,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { Weight::from_parts(31_329_634, 11003) // Standard Error: 4_496 .saturating_add(Weight::from_parts(203_570, 0).saturating_mul(r.into())) + // Standard Error: 877 + .saturating_add(Weight::from_parts(429_346, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -150,9 +153,9 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { /// The range of component `r` is `[1, 20]`. /// The range of component `s` is `[0, 100]`. /// The range of component `x` is `[0, 100]`. - fn clear_identity(r: u32, s: u32, ) -> Weight { + fn clear_identity(r: u32, s: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `469 + r * (5 ±0) + s * (32 ±0)` + // Measured: `469 + r * (5 ±0) + s * (32 ±0) + x * (66 ±0)` // Estimated: `11003` // Minimum execution time: 55_687_000 picoseconds. Weight::from_parts(30_695_182, 11003) @@ -160,6 +163,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { .saturating_add(Weight::from_parts(162_357, 0).saturating_mul(r.into())) // Standard Error: 1_937 .saturating_add(Weight::from_parts(1_427_998, 0).saturating_mul(s.into())) + // Standard Error: 1_937 + .saturating_add(Weight::from_parts(247_578, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) @@ -169,14 +174,17 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. - fn request_judgement(r: u32, ) -> Weight { + /// The range of component `x` is `[0, 100]`. + fn request_judgement(r: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `367 + r * (57 ±0)` + // Measured: `367 + r * (57 ±0) + x * (66 ±0)` // Estimated: `11003` // Minimum execution time: 34_876_000 picoseconds. Weight::from_parts(32_207_018, 11003) // Standard Error: 5_247 .saturating_add(Weight::from_parts(249_156, 0).saturating_mul(r.into())) + // Standard Error: 1_023 + .saturating_add(Weight::from_parts(458_329, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -184,14 +192,16 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. /// The range of component `x` is `[0, 100]`. - fn cancel_request(r: u32, ) -> Weight { + fn cancel_request(r: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `398` + // Measured: `398 + x * (66 ±0)` // Estimated: `11003` // Minimum execution time: 30_689_000 picoseconds. Weight::from_parts(31_967_170, 11003) // Standard Error: 5_387 .saturating_add(Weight::from_parts(42_676, 0).saturating_mul(r.into())) + // Standard Error: 1_051 + .saturating_add(Weight::from_parts(446_213, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(1_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -243,14 +253,16 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 19]`. /// The range of component `x` is `[0, 100]`. - fn provide_judgement(r: u32, ) -> Weight { + fn provide_judgement(r: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `445 + r * (57 ±0)` + // Measured: `445 + r * (57 ±0) + x * (66 ±0)` // Estimated: `11003` // Minimum execution time: 24_073_000 picoseconds. Weight::from_parts(17_817_684, 11003) // Standard Error: 8_612 .saturating_add(Weight::from_parts(406_251, 0).saturating_mul(r.into())) + // Standard Error: 1_593 + .saturating_add(Weight::from_parts(755_225, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2_u64)) .saturating_add(T::DbWeight::get().writes(1_u64)) } @@ -265,9 +277,9 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { /// The range of component `r` is `[1, 20]`. /// The range of component `s` is `[0, 100]`. /// The range of component `x` is `[0, 100]`. - fn kill_identity(r: u32, s: u32, ) -> Weight { + fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `676 + r * (5 ±0) + s * (32 ±0)` + // Measured: `676 + r * (5 ±0) + s * (32 ±0) + x * (66 ±0)` // Estimated: `11003` // Minimum execution time: 73_981_000 picoseconds. Weight::from_parts(51_684_057, 11003) @@ -275,6 +287,8 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { .saturating_add(Weight::from_parts(145_285, 0).saturating_mul(r.into())) // Standard Error: 2_472 .saturating_add(Weight::from_parts(1_421_039, 0).saturating_mul(s.into())) + // Standard Error: 2_472 + .saturating_add(Weight::from_parts(240_907, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(3_u64)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) @@ -371,7 +385,7 @@ impl WeightInfo for () { /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. /// The range of component `x` is `[0, 100]`. - fn set_identity(r: u32, ) -> Weight { + fn set_identity(r: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `442 + r * (5 ±0)` // Estimated: `11003` @@ -379,6 +393,8 @@ impl WeightInfo for () { Weight::from_parts(31_329_634, 11003) // Standard Error: 4_496 .saturating_add(Weight::from_parts(203_570, 0).saturating_mul(r.into())) + // Standard Error: 877 + .saturating_add(Weight::from_parts(429_346, 0).saturating_mul(x.into())) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -430,7 +446,8 @@ impl WeightInfo for () { /// Proof: Identity SuperOf (max_values: None, max_size: Some(114), added: 2589, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. /// The range of component `s` is `[0, 100]`. - fn clear_identity(r: u32, s: u32, ) -> Weight { + /// The range of component `x` is `[0, 100]`. + fn clear_identity(r: u32, s: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `469 + r * (5 ±0) + s * (32 ±0) + x * (66 ±0)` // Estimated: `11003` @@ -440,6 +457,8 @@ impl WeightInfo for () { .saturating_add(Weight::from_parts(162_357, 0).saturating_mul(r.into())) // Standard Error: 1_937 .saturating_add(Weight::from_parts(1_427_998, 0).saturating_mul(s.into())) + // Standard Error: 1_937 + .saturating_add(Weight::from_parts(247_578, 0).saturating_mul(x.into())) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(s.into()))) @@ -449,7 +468,8 @@ impl WeightInfo for () { /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. - fn request_judgement(r: u32, ) -> Weight { + /// The range of component `x` is `[0, 100]`. + fn request_judgement(r: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `367 + r * (57 ±0) + x * (66 ±0)` // Estimated: `11003` @@ -457,20 +477,25 @@ impl WeightInfo for () { Weight::from_parts(32_207_018, 11003) // Standard Error: 5_247 .saturating_add(Weight::from_parts(249_156, 0).saturating_mul(r.into())) + // Standard Error: 1_023 + .saturating_add(Weight::from_parts(458_329, 0).saturating_mul(x.into())) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. - fn cancel_request(r: u32, ) -> Weight { + /// The range of component `x` is `[0, 100]`. + fn cancel_request(r: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `398` + // Measured: `398 + x * (66 ±0)` // Estimated: `11003` // Minimum execution time: 30_689_000 picoseconds. Weight::from_parts(31_967_170, 11003) // Standard Error: 5_387 .saturating_add(Weight::from_parts(42_676, 0).saturating_mul(r.into())) + // Standard Error: 1_051 + .saturating_add(Weight::from_parts(446_213, 0).saturating_mul(x.into())) .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -521,7 +546,8 @@ impl WeightInfo for () { /// Storage: Identity IdentityOf (r:1 w:1) /// Proof: Identity IdentityOf (max_values: None, max_size: Some(7538), added: 10013, mode: MaxEncodedLen) /// The range of component `r` is `[1, 19]`. - fn provide_judgement(r: u32, ) -> Weight { + /// The range of component `x` is `[0, 100]`. + fn provide_judgement(r: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `445 + r * (57 ±0) + x * (66 ±0)` // Estimated: `11003` @@ -529,6 +555,8 @@ impl WeightInfo for () { Weight::from_parts(17_817_684, 11003) // Standard Error: 8_612 .saturating_add(Weight::from_parts(406_251, 0).saturating_mul(r.into())) + // Standard Error: 1_593 + .saturating_add(Weight::from_parts(755_225, 0).saturating_mul(x.into())) .saturating_add(RocksDbWeight::get().reads(2_u64)) .saturating_add(RocksDbWeight::get().writes(1_u64)) } @@ -542,7 +570,8 @@ impl WeightInfo for () { /// Proof: Identity SuperOf (max_values: None, max_size: Some(114), added: 2589, mode: MaxEncodedLen) /// The range of component `r` is `[1, 20]`. /// The range of component `s` is `[0, 100]`. - fn kill_identity(r: u32, s: u32, ) -> Weight { + /// The range of component `x` is `[0, 100]`. + fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `676 + r * (5 ±0) + s * (32 ±0) + x * (66 ±0)` // Estimated: `11003` @@ -552,6 +581,8 @@ impl WeightInfo for () { .saturating_add(Weight::from_parts(145_285, 0).saturating_mul(r.into())) // Standard Error: 2_472 .saturating_add(Weight::from_parts(1_421_039, 0).saturating_mul(s.into())) + // Standard Error: 2_472 + .saturating_add(Weight::from_parts(240_907, 0).saturating_mul(x.into())) .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) .saturating_add(RocksDbWeight::get().writes((1_u64).saturating_mul(s.into()))) From aa7d87d8b6227363d62ea0c2356dab6201b76a56 Mon Sep 17 00:00:00 2001 From: georgepisaltu <george.pisaltu@parity.io> Date: Mon, 16 Oct 2023 19:42:01 +0300 Subject: [PATCH 11/14] Simplify `IdentityField` impl Signed-off-by: georgepisaltu <george.pisaltu@parity.io> --- substrate/frame/identity/src/simple.rs | 16 +++++------ substrate/frame/identity/src/tests.rs | 37 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/substrate/frame/identity/src/simple.rs b/substrate/frame/identity/src/simple.rs index 761e07e8158ba..db5ecf3b1c97e 100644 --- a/substrate/frame/identity/src/simple.rs +++ b/substrate/frame/identity/src/simple.rs @@ -30,14 +30,14 @@ use crate::types::{Data, IdentityFields, IdentityInformationProvider, U64BitFlag #[repr(u64)] #[derive(Clone, Copy, PartialEq, Eq, RuntimeDebug)] pub enum IdentityField { - Display = 1u64 << 0, - Legal = 1u64 << 1, - Web = 1u64 << 2, - Riot = 1u64 << 3, - Email = 1u64 << 4, - PgpFingerprint = 1u64 << 5, - Image = 1u64 << 6, - Twitter = 1u64 << 7, + Display, + Legal, + Web, + Riot, + Email, + PgpFingerprint, + Image, + Twitter, } impl TypeInfo for IdentityField { diff --git a/substrate/frame/identity/src/tests.rs b/substrate/frame/identity/src/tests.rs index aad35ec06db7a..6f2c2580e7679 100644 --- a/substrate/frame/identity/src/tests.rs +++ b/substrate/frame/identity/src/tests.rs @@ -142,6 +142,43 @@ fn twenty() -> IdentityInfo<MaxAdditionalFields> { } } +#[test] +fn identity_fields_repr_works() { + // `SimpleIdentityField` sanity checks. + assert_eq!(SimpleIdentityField::Display as u64, 1 << 0); + assert_eq!(SimpleIdentityField::Legal as u64, 1 << 1); + assert_eq!(SimpleIdentityField::Web as u64, 1 << 2); + assert_eq!(SimpleIdentityField::Riot as u64, 1 << 3); + assert_eq!(SimpleIdentityField::Email as u64, 1 << 4); + assert_eq!(SimpleIdentityField::PgpFingerprint as u64, 1 << 5); + assert_eq!(SimpleIdentityField::Image as u64, 1 << 6); + assert_eq!(SimpleIdentityField::Twitter as u64, 1 << 7); + + let fields = IdentityFields( + SimpleIdentityField::Legal | + SimpleIdentityField::Web | + SimpleIdentityField::Riot | + SimpleIdentityField::PgpFingerprint | + SimpleIdentityField::Twitter, + ); + + assert!(!fields.0.contains(SimpleIdentityField::Display)); + assert!(fields.0.contains(SimpleIdentityField::Legal)); + assert!(fields.0.contains(SimpleIdentityField::Web)); + assert!(fields.0.contains(SimpleIdentityField::Riot)); + assert!(!fields.0.contains(SimpleIdentityField::Email)); + assert!(fields.0.contains(SimpleIdentityField::PgpFingerprint)); + assert!(!fields.0.contains(SimpleIdentityField::Image)); + assert!(fields.0.contains(SimpleIdentityField::Twitter)); + + // The `IdentityFields` inner `BitFlags::bits` is used for `Encode`/`Decode`, so we ensure that + // the `u64` representation matches what we expect during encode/decode operations. + assert_eq!( + fields.0.bits(), + 0b00000000_00000000_00000000_00000000_00000000_00000000_00000000_10101110 + ); +} + #[test] fn editing_subaccounts_should_work() { new_test_ext().execute_with(|| { From 9b7914711af3cacfdc2d7313472971ae49c6f2b4 Mon Sep 17 00:00:00 2001 From: georgepisaltu <george.pisaltu@parity.io> Date: Tue, 17 Oct 2023 13:02:04 +0300 Subject: [PATCH 12/14] Remove obsolete complexity doc comments Signed-off-by: georgepisaltu <george.pisaltu@parity.io> --- substrate/frame/identity/src/lib.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index fad0008f9cfc8..d2778b66fd4ab 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -371,7 +371,7 @@ pub mod pallet { <IdentityOf<T>>::insert(&sender, id); Self::deposit_event(Event::IdentitySet { who: sender }); - Ok(Some(T::WeightInfo::set_identity(judgements as u32, extra_fields)).into()) // R + Ok(Some(T::WeightInfo::set_identity(judgements as u32, extra_fields)).into()) } /// Set the sub-accounts of the sender. @@ -604,7 +604,7 @@ pub mod pallet { /// - `index`: the index of the registrar whose fee is to be set. /// - `fee`: the new fee. #[pallet::call_index(6)] - #[pallet::weight(T::WeightInfo::set_fee(T::MaxRegistrars::get()))] // R + #[pallet::weight(T::WeightInfo::set_fee(T::MaxRegistrars::get()))] pub fn set_fee( origin: OriginFor<T>, #[pallet::compact] index: RegistrarIndex, @@ -636,12 +636,8 @@ pub mod pallet { /// /// - `index`: the index of the registrar whose fee is to be set. /// - `new`: the new account ID. - /// - /// ## Complexity - /// - `O(R)`. - /// - where `R` registrar-count (governance-bounded). #[pallet::call_index(7)] - #[pallet::weight(T::WeightInfo::set_account_id(T::MaxRegistrars::get()))] // R + #[pallet::weight(T::WeightInfo::set_account_id(T::MaxRegistrars::get()))] pub fn set_account_id( origin: OriginFor<T>, #[pallet::compact] index: RegistrarIndex, From 60684f9ea3d50564d97136616d0cc7a334540624 Mon Sep 17 00:00:00 2001 From: georgepisaltu <george.pisaltu@parity.io> Date: Tue, 17 Oct 2023 14:21:38 +0300 Subject: [PATCH 13/14] Fix documentation Signed-off-by: georgepisaltu <george.pisaltu@parity.io> --- substrate/frame/identity/src/lib.rs | 9 ++++++--- substrate/frame/identity/src/types.rs | 5 ++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index d2778b66fd4ab..9b7b6a953ffc8 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -82,11 +82,13 @@ pub mod weights; use frame_support::traits::{BalanceStatus, Currency, OnUnbalanced, ReservableCurrency}; use sp_runtime::traits::{AppendZerosInput, Hash, Saturating, StaticLookup, Zero}; use sp_std::prelude::*; -use types::IdentityInformationProvider; pub use weights::WeightInfo; pub use pallet::*; -pub use types::{Data, IdentityFields, Judgement, RegistrarIndex, RegistrarInfo, Registration}; +pub use types::{ + Data, IdentityFields, IdentityInformationProvider, Judgement, RegistrarIndex, RegistrarInfo, + Registration, +}; type BalanceOf<T> = <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance; @@ -707,7 +709,8 @@ pub mod pallet { /// - `target`: the account whose identity the judgement is upon. This must be an account /// with a registered identity. /// - `judgement`: the judgement of the registrar of index `reg_index` about `target`. - /// - `identity`: The hash of the [`IdentityInfo`] for that the judgement is provided. + /// - `identity`: The hash of the [`IdentityInformationProvider`] for that the judgement is + /// provided. /// /// Emits `JudgementGiven` if successful. #[pallet::call_index(9)] diff --git a/substrate/frame/identity/src/types.rs b/substrate/frame/identity/src/types.rs index 2cc36a78b8293..7055f6d80cfb5 100644 --- a/substrate/frame/identity/src/types.rs +++ b/substrate/frame/identity/src/types.rs @@ -238,6 +238,7 @@ pub trait IdentityInformationProvider: /// flags in `u64` format. type IdentityField: Clone + Debug + Eq + PartialEq + TypeInfo + U64BitFlag; + /// Check if an identity registered information for some given `fields`. fn has_identity(&self, fields: u64) -> bool; /// Interface for providing the number of additional fields this identity information provider @@ -256,8 +257,7 @@ pub trait IdentityInformationProvider: /// Information on an identity along with judgements from registrars. /// /// NOTE: This is stored separately primarily to facilitate the addition of extra fields in a -/// backwards compatible way through a specialized `Decode` impl. Is this still the case? We need to -/// do a migration if we removed the additional fields. +/// backwards compatible way through a specialized `Decode` impl. #[derive( CloneNoBound, Encode, Eq, MaxEncodedLen, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, )] @@ -301,7 +301,6 @@ impl< > Decode for Registration<Balance, MaxJudgements, IdentityInfo> { fn decode<I: codec::Input>(input: &mut I) -> sp_std::result::Result<Self, codec::Error> { - // TODO consider removing this, will probably do migration let (judgements, deposit, info) = Decode::decode(&mut AppendZerosInput::new(input))?; Ok(Self { judgements, deposit, info }) } From cbae179d7cb483bc0e9eed70d1e845a677f56815 Mon Sep 17 00:00:00 2001 From: georgepisaltu <george.pisaltu@parity.io> Date: Tue, 17 Oct 2023 16:29:48 +0300 Subject: [PATCH 14/14] Remove the last of the obsolete code docs Signed-off-by: georgepisaltu <george.pisaltu@parity.io> --- substrate/frame/identity/src/lib.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 9b7b6a953ffc8..a341cc6bb9bda 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -290,9 +290,6 @@ pub mod pallet { /// - `account`: the account of the registrar. /// /// Emits `RegistrarAdded` if successful. - /// - /// ## Complexity - /// - `O(R)` where `R` registrar-count (governance-bounded and code-bounded). #[pallet::call_index(0)] #[pallet::weight(T::WeightInfo::add_registrar(T::MaxRegistrars::get()))] pub fn add_registrar( @@ -385,11 +382,6 @@ pub mod pallet { /// identity. /// /// - `subs`: The identity's (new) sub-accounts. - /// - /// ## Complexity - /// - `O(P + S)` - /// - where `P` old-subs-count (hard- and deposit-bounded). - /// - where `S` subs-count (hard- and deposit-bounded). // TODO: This whole extrinsic screams "not optimized". For example we could // filter any overlap between new and old subs, and avoid reading/writing // to those values... We could also ideally avoid needing to write to @@ -397,8 +389,8 @@ pub mod pallet { // is a large overestimate due to the fact that it could potentially write // to 2 x T::MaxSubAccounts::get(). #[pallet::call_index(2)] - #[pallet::weight(T::WeightInfo::set_subs_old(T::MaxSubAccounts::get()) // P: Assume max sub accounts removed. - .saturating_add(T::WeightInfo::set_subs_new(subs.len() as u32)) // S: Assume all subs are new. + #[pallet::weight(T::WeightInfo::set_subs_old(T::MaxSubAccounts::get()) + .saturating_add(T::WeightInfo::set_subs_new(subs.len() as u32)) )] pub fn set_subs( origin: OriginFor<T>,