From ac9f37ecd15116a694e0f26888883ef95a2a735a Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Wed, 25 Oct 2023 20:10:32 +0300 Subject: [PATCH 01/27] Rename `simple` module to `legacy` Signed-off-by: georgepisaltu --- 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/lib.rs | 2 +- substrate/frame/alliance/src/mock.rs | 2 +- .../identity/src/{simple.rs => legacy.rs} | 0 substrate/frame/identity/src/lib.rs | 2 +- substrate/frame/identity/src/tests.rs | 58 +++++++++---------- 8 files changed, 34 insertions(+), 36 deletions(-) rename substrate/frame/identity/src/{simple.rs => legacy.rs} (100%) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index e6ad061ce069..3a0c7a1e3131 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -76,7 +76,7 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; -use pallet_identity::simple::IdentityInfo; +use pallet_identity::legacy::IdentityInfo; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use pallet_session::historical as session_historical; use pallet_transaction_payment::{CurrencyAdapter, FeeDetails, RuntimeDispatchInfo}; diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 9ee4f3cf23e5..a6a1d3025425 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -40,7 +40,7 @@ use frame_support::{ }; use frame_system::EnsureRoot; use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId}; -use pallet_identity::simple::IdentityInfo; +use pallet_identity::legacy::IdentityInfo; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use pallet_session::historical as session_historical; use pallet_transaction_payment::{CurrencyAdapter, FeeDetails, RuntimeDispatchInfo}; diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index a2d100e1f8b5..2f658ed7324c 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -60,7 +60,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::IdentityInfo; +use pallet_identity::legacy::IdentityInfo; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; use pallet_nfts::PalletFeatures; use pallet_nis::WithMaximumOf; diff --git a/substrate/frame/alliance/src/lib.rs b/substrate/frame/alliance/src/lib.rs index f3ff03780f59..77d8fe3c5b34 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::simple::IdentityField; +use pallet_identity::legacy::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 a5970bc7af67..1bc7632ae9af 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -31,7 +31,7 @@ pub use frame_support::{ BoundedVec, }; use frame_system::{EnsureRoot, EnsureSignedBy}; -use pallet_identity::{simple::IdentityInfo, Data, Judgement}; +use pallet_identity::{legacy::IdentityInfo, Data, Judgement}; pub use crate as pallet_alliance; diff --git a/substrate/frame/identity/src/simple.rs b/substrate/frame/identity/src/legacy.rs similarity index 100% rename from substrate/frame/identity/src/simple.rs rename to substrate/frame/identity/src/legacy.rs diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index a341cc6bb9bd..c830d6ddb2e9 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; -pub mod simple; +pub mod legacy; #[cfg(test)] mod tests; mod types; diff --git a/substrate/frame/identity/src/tests.rs b/substrate/frame/identity/src/tests.rs index f0980e9c7cc8..c8a7afb4098c 100644 --- a/substrate/frame/identity/src/tests.rs +++ b/substrate/frame/identity/src/tests.rs @@ -20,7 +20,7 @@ use super::*; use crate::{ self as pallet_identity, - simple::{IdentityField as SimpleIdentityField, IdentityInfo}, + legacy::{IdentityField, IdentityInfo}, }; use codec::{Decode, Encode}; @@ -145,32 +145,32 @@ fn twenty() -> IdentityInfo { #[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); + // `IdentityField` sanity checks. + assert_eq!(IdentityField::Display as u64, 1 << 0); + assert_eq!(IdentityField::Legal as u64, 1 << 1); + assert_eq!(IdentityField::Web as u64, 1 << 2); + assert_eq!(IdentityField::Riot as u64, 1 << 3); + assert_eq!(IdentityField::Email as u64, 1 << 4); + assert_eq!(IdentityField::PgpFingerprint as u64, 1 << 5); + assert_eq!(IdentityField::Image as u64, 1 << 6); + assert_eq!(IdentityField::Twitter as u64, 1 << 7); let fields = IdentityFields( - SimpleIdentityField::Legal | - SimpleIdentityField::Web | - SimpleIdentityField::Riot | - SimpleIdentityField::PgpFingerprint | - SimpleIdentityField::Twitter, + IdentityField::Legal | + IdentityField::Web | + IdentityField::Riot | + IdentityField::PgpFingerprint | + IdentityField::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)); + assert!(!fields.0.contains(IdentityField::Display)); + assert!(fields.0.contains(IdentityField::Legal)); + assert!(fields.0.contains(IdentityField::Web)); + assert!(fields.0.contains(IdentityField::Riot)); + assert!(!fields.0.contains(IdentityField::Email)); + assert!(fields.0.contains(IdentityField::PgpFingerprint)); + assert!(!fields.0.contains(IdentityField::Image)); + assert!(fields.0.contains(IdentityField::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. @@ -274,7 +274,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(SimpleIdentityField::Display | SimpleIdentityField::Legal); + let fields = IdentityFields(IdentityField::Display | IdentityField::Legal); assert_ok!(Identity::set_fields(RuntimeOrigin::signed(3), 0, fields)); assert_eq!( Identity::registrars(), @@ -649,17 +649,15 @@ 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, SimpleIdentityField::Display as u64)); - assert!(Identity::has_identity(&10, SimpleIdentityField::Legal as u64)); + 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 | SimpleIdentityField::Legal as u64 + IdentityField::Display as u64 | IdentityField::Legal as u64 )); assert!(!Identity::has_identity( &10, - SimpleIdentityField::Display as u64 | - SimpleIdentityField::Legal as u64 | - SimpleIdentityField::Web as u64 + IdentityField::Display as u64 | IdentityField::Legal as u64 | IdentityField::Web as u64 )); }); } From e3ce237d535728266d74340fe8aaf7636461967e Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Wed, 25 Oct 2023 20:30:46 +0300 Subject: [PATCH 02/27] Fix benchmarks incorrectly using `additional` Signed-off-by: georgepisaltu --- .../rococo/src/weights/pallet_identity.rs | 31 ++------ .../westend/src/weights/pallet_identity.rs | 30 ++------ substrate/frame/identity/src/benchmarking.rs | 30 +++----- substrate/frame/identity/src/lib.rs | 47 +++--------- substrate/frame/identity/src/weights.rs | 72 +++++-------------- 5 files changed, 50 insertions(+), 160 deletions(-) diff --git a/polkadot/runtime/rococo/src/weights/pallet_identity.rs b/polkadot/runtime/rococo/src/weights/pallet_identity.rs index e10c042dde6a..e8c25269ac37 100644 --- a/polkadot/runtime/rococo/src/weights/pallet_identity.rs +++ b/polkadot/runtime/rococo/src/weights/pallet_identity.rs @@ -65,8 +65,7 @@ impl pallet_identity::WeightInfo for WeightInfo { /// 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 pallet_identity::WeightInfo for WeightInfo { .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,8 +127,7 @@ impl pallet_identity::WeightInfo for WeightInfo { /// 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` @@ -140,8 +136,6 @@ impl pallet_identity::WeightInfo for WeightInfo { .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,8 +145,7 @@ impl pallet_identity::WeightInfo for WeightInfo { /// 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` @@ -161,16 +154,14 @@ impl pallet_identity::WeightInfo for WeightInfo { .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)` // Estimated: `11003` @@ -179,8 +170,6 @@ impl pallet_identity::WeightInfo for WeightInfo { .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,8 +223,7 @@ impl pallet_identity::WeightInfo for WeightInfo { /// 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` @@ -244,8 +232,6 @@ impl pallet_identity::WeightInfo for WeightInfo { .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,8 +245,7 @@ impl pallet_identity::WeightInfo for WeightInfo { /// 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` @@ -271,8 +256,6 @@ impl pallet_identity::WeightInfo for WeightInfo { .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/weights/pallet_identity.rs b/polkadot/runtime/westend/src/weights/pallet_identity.rs index 8c11482ebdc1..dea631b9316b 100644 --- a/polkadot/runtime/westend/src/weights/pallet_identity.rs +++ b/polkadot/runtime/westend/src/weights/pallet_identity.rs @@ -68,8 +68,7 @@ impl pallet_identity::WeightInfo for WeightInfo { /// 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 pallet_identity::WeightInfo for WeightInfo { .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,8 +130,7 @@ impl pallet_identity::WeightInfo for WeightInfo { /// 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` @@ -145,8 +141,6 @@ impl pallet_identity::WeightInfo for WeightInfo { .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()))) @@ -156,8 +150,7 @@ impl pallet_identity::WeightInfo for WeightInfo { /// 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` @@ -166,16 +159,13 @@ impl pallet_identity::WeightInfo for WeightInfo { .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)` // Estimated: `11003` @@ -184,8 +174,6 @@ impl pallet_identity::WeightInfo for WeightInfo { .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,8 +227,7 @@ impl pallet_identity::WeightInfo for WeightInfo { /// 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` @@ -249,8 +236,6 @@ impl pallet_identity::WeightInfo for WeightInfo { .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,8 +249,7 @@ impl pallet_identity::WeightInfo for WeightInfo { /// 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` @@ -276,8 +260,6 @@ impl pallet_identity::WeightInfo for WeightInfo { .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/frame/identity/src/benchmarking.rs b/substrate/frame/identity/src/benchmarking.rs index 16ce4d8246e6..29347a644e22 100644 --- a/substrate/frame/identity/src/benchmarking.rs +++ b/substrate/frame/identity/src/benchmarking.rs @@ -118,10 +118,7 @@ mod benchmarks { } #[benchmark] - fn set_identity( - r: Linear<1, { T::MaxRegistrars::get() }>, - x: Linear<0, { T::MaxAdditionalFields::get() }>, - ) -> Result<(), BenchmarkError> { + fn set_identity(r: Linear<1, { T::MaxRegistrars::get() }>) -> Result<(), BenchmarkError> { add_registrars::(r)?; let caller: T::AccountId = whitelisted_caller(); @@ -154,7 +151,7 @@ mod benchmarks { #[extrinsic_call] _( RawOrigin::Signed(caller.clone()), - Box::new(T::IdentityInformation::create_identity_info(x)), + Box::new(T::IdentityInformation::create_identity_info(T::MaxAdditionalFields::get())), ); assert_last_event::(Event::::IdentitySet { who: caller }.into()); @@ -201,7 +198,6 @@ mod benchmarks { fn clear_identity( r: Linear<1, { T::MaxRegistrars::get() }>, s: Linear<0, { T::MaxSubAccounts::get() }>, - x: Linear<0, { T::MaxAdditionalFields::get() }>, ) -> Result<(), BenchmarkError> { let caller: T::AccountId = whitelisted_caller(); let caller_origin = @@ -216,7 +212,7 @@ mod benchmarks { let _ = add_sub_accounts::(&caller, s)?; // Create their main identity with x additional fields - let info = T::IdentityInformation::create_identity_info(x); + let info = T::IdentityInformation::create_identity_info(T::MaxAdditionalFields::get()); Identity::::set_identity(caller_origin.clone(), Box::new(info.clone()))?; // User requests judgement from all the registrars, and they approve @@ -245,10 +241,7 @@ mod benchmarks { } #[benchmark] - fn request_judgement( - r: Linear<1, { T::MaxRegistrars::get() }>, - x: Linear<0, { T::MaxAdditionalFields::get() }>, - ) -> Result<(), BenchmarkError> { + fn request_judgement(r: Linear<1, { T::MaxRegistrars::get() }>) -> Result<(), BenchmarkError> { let caller: T::AccountId = whitelisted_caller(); let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); @@ -256,7 +249,7 @@ mod benchmarks { add_registrars::(r)?; // Create their main identity with x additional fields - let info = T::IdentityInformation::create_identity_info(x); + let info = T::IdentityInformation::create_identity_info(T::MaxAdditionalFields::get()); let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); Identity::::set_identity(caller_origin.clone(), Box::new(info))?; @@ -272,10 +265,7 @@ mod benchmarks { } #[benchmark] - fn cancel_request( - r: Linear<1, { T::MaxRegistrars::get() }>, - x: Linear<0, { T::MaxAdditionalFields::get() }>, - ) -> Result<(), BenchmarkError> { + fn cancel_request(r: Linear<1, { T::MaxRegistrars::get() }>) -> Result<(), BenchmarkError> { let caller: T::AccountId = whitelisted_caller(); let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); @@ -283,7 +273,7 @@ mod benchmarks { add_registrars::(r)?; // Create their main identity with x additional fields - let info = T::IdentityInformation::create_identity_info(x); + let info = T::IdentityInformation::create_identity_info(T::MaxAdditionalFields::get()); let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); Identity::::set_identity(caller_origin.clone(), Box::new(info))?; @@ -392,7 +382,6 @@ mod benchmarks { #[benchmark] fn provide_judgement( r: Linear<1, { T::MaxRegistrars::get() - 1 }>, - x: Linear<0, { T::MaxAdditionalFields::get() }>, ) -> Result<(), BenchmarkError> { // The user let user: T::AccountId = account("user", r, SEED); @@ -407,7 +396,7 @@ mod benchmarks { add_registrars::(r)?; - let info = T::IdentityInformation::create_identity_info(x); + let info = T::IdentityInformation::create_identity_info(T::MaxAdditionalFields::get()); let info_hash = T::Hashing::hash_of(&info); Identity::::set_identity(user_origin.clone(), Box::new(info))?; @@ -430,7 +419,6 @@ mod benchmarks { fn kill_identity( r: Linear<1, { T::MaxRegistrars::get() }>, s: Linear<0, { T::MaxSubAccounts::get() }>, - x: Linear<0, { T::MaxAdditionalFields::get() }>, ) -> Result<(), BenchmarkError> { add_registrars::(r)?; @@ -440,7 +428,7 @@ mod benchmarks { let target_lookup = T::Lookup::unlookup(target.clone()); let _ = T::Currency::make_free_balance_be(&target, BalanceOf::::max_value()); - let info = T::IdentityInformation::create_identity_info(x); + let info = T::IdentityInformation::create_identity_info(T::MaxAdditionalFields::get()); Identity::::set_identity(target_origin.clone(), Box::new(info.clone()))?; let _ = add_sub_accounts::(&target, s)?; diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index c830d6ddb2e9..7a35ac105f94 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -328,10 +328,7 @@ pub mod pallet { /// /// Emits `IdentitySet` if successful. #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::set_identity( - T::MaxRegistrars::get(), - T::MaxAdditionalFields::get(), - ))] + #[pallet::weight(T::WeightInfo::set_identity(T::MaxRegistrars::get()))] pub fn set_identity( origin: OriginFor, info: Box, @@ -370,7 +367,7 @@ pub mod pallet { >::insert(&sender, id); Self::deposit_event(Event::IdentitySet { who: sender }); - Ok(Some(T::WeightInfo::set_identity(judgements as u32, extra_fields)).into()) + Ok(Some(T::WeightInfo::set_identity(judgements as u32)).into()) } /// Set the sub-accounts of the sender. @@ -454,7 +451,6 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::clear_identity( T::MaxRegistrars::get(), T::MaxSubAccounts::get(), - T::MaxAdditionalFields::get(), ))] pub fn clear_identity(origin: OriginFor) -> DispatchResultWithPostInfo { let sender = ensure_signed(origin)?; @@ -475,7 +471,6 @@ pub mod pallet { Ok(Some(T::WeightInfo::clear_identity( id.judgements.len() as u32, sub_ids.len() as u32, - id.info.additional() as u32, )) .into()) } @@ -497,10 +492,7 @@ pub mod pallet { /// /// Emits `JudgementRequested` if successful. #[pallet::call_index(4)] - #[pallet::weight(T::WeightInfo::request_judgement( - T::MaxRegistrars::get(), - T::MaxAdditionalFields::get(), - ))] + #[pallet::weight(T::WeightInfo::request_judgement(T::MaxRegistrars::get(),))] pub fn request_judgement( origin: OriginFor, #[pallet::compact] reg_index: RegistrarIndex, @@ -530,8 +522,6 @@ pub mod pallet { T::Currency::reserve(&sender, registrar.fee)?; let judgements = id.judgements.len(); - #[allow(deprecated)] - let extra_fields = id.info.additional(); >::insert(&sender, id); Self::deposit_event(Event::JudgementRequested { @@ -539,8 +529,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)).into()) } /// Cancel a previous request. @@ -554,10 +543,7 @@ pub mod pallet { /// /// Emits `JudgementUnrequested` if successful. #[pallet::call_index(5)] - #[pallet::weight(T::WeightInfo::cancel_request( - T::MaxRegistrars::get(), - T::MaxAdditionalFields::get(), - ))] + #[pallet::weight(T::WeightInfo::cancel_request(T::MaxRegistrars::get()))] pub fn cancel_request( origin: OriginFor, reg_index: RegistrarIndex, @@ -578,8 +564,6 @@ 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(); >::insert(&sender, id); Self::deposit_event(Event::JudgementUnrequested { @@ -587,7 +571,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)).into()) } /// Set the fee required for a judgement to be requested from a registrar. @@ -706,10 +690,7 @@ pub mod pallet { /// /// Emits `JudgementGiven` if successful. #[pallet::call_index(9)] - #[pallet::weight(T::WeightInfo::provide_judgement( - T::MaxRegistrars::get(), - T::MaxAdditionalFields::get(), - ))] + #[pallet::weight(T::WeightInfo::provide_judgement(T::MaxRegistrars::get()))] pub fn provide_judgement( origin: OriginFor, #[pallet::compact] reg_index: RegistrarIndex, @@ -752,13 +733,10 @@ pub mod pallet { } let judgements = id.judgements.len(); - #[allow(deprecated)] - let extra_fields = id.info.additional(); >::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)).into()) } /// Remove an account's identity and sub-account information and slash the deposits. @@ -777,7 +755,6 @@ pub mod pallet { #[pallet::weight(T::WeightInfo::kill_identity( T::MaxRegistrars::get(), T::MaxSubAccounts::get(), - T::MaxAdditionalFields::get(), ))] pub fn kill_identity( origin: OriginFor, @@ -800,12 +777,8 @@ pub mod pallet { Self::deposit_event(Event::IdentityKilled { who: target, deposit }); #[allow(deprecated)] - Ok(Some(T::WeightInfo::kill_identity( - id.judgements.len() as u32, - sub_ids.len() as u32, - id.info.additional() as u32, - )) - .into()) + Ok(Some(T::WeightInfo::kill_identity(id.judgements.len() as u32, sub_ids.len() as u32)) + .into()) } /// Add the given account to the sender's subs. diff --git a/substrate/frame/identity/src/weights.rs b/substrate/frame/identity/src/weights.rs index 02fcd7db3c95..95898e6c6cdf 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 WeightInfo for SubstrateWeight { /// 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 WeightInfo for SubstrateWeight { 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)) } @@ -152,8 +149,7 @@ impl WeightInfo for SubstrateWeight { /// 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` @@ -163,8 +159,6 @@ impl WeightInfo for SubstrateWeight { .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,8 +168,7 @@ impl WeightInfo for SubstrateWeight { /// 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` @@ -183,16 +176,13 @@ impl WeightInfo for SubstrateWeight { 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)) } /// 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` @@ -200,8 +190,6 @@ impl WeightInfo for SubstrateWeight { 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)) } @@ -252,8 +240,7 @@ impl WeightInfo for SubstrateWeight { /// 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` @@ -261,8 +248,6 @@ impl WeightInfo for SubstrateWeight { 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)) } @@ -276,8 +261,7 @@ impl WeightInfo for SubstrateWeight { /// 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` @@ -287,8 +271,6 @@ impl WeightInfo for SubstrateWeight { .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()))) @@ -384,8 +366,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 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 +374,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 +425,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 +435,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 +444,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,16 +452,13 @@ 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)` // Estimated: `11003` @@ -494,8 +466,6 @@ impl WeightInfo for () { 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 +516,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 +524,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 +537,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 +547,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 0e72dc1b7caee01f83551bbbaf23182ee951c779 Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Wed, 25 Oct 2023 21:07:55 +0300 Subject: [PATCH 03/27] Implement byte deposit Signed-off-by: georgepisaltu --- polkadot/runtime/rococo/src/lib.rs | 4 + polkadot/runtime/westend/src/lib.rs | 4 + substrate/bin/node/runtime/src/lib.rs | 2 + substrate/frame/alliance/src/mock.rs | 10 +- substrate/frame/identity/src/legacy.rs | 4 - substrate/frame/identity/src/lib.rs | 20 ++- substrate/frame/identity/src/tests.rs | 183 +++++++++++++++---------- substrate/frame/identity/src/types.rs | 9 -- 8 files changed, 146 insertions(+), 90 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 3a0c7a1e3131..eeeb72954721 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -597,9 +597,11 @@ parameter_types! { // Minimum 100 bytes/ROC deposited (1 CENT/byte) pub const BasicDeposit: Balance = 1000 * CENTS; // 258 bytes on-chain pub const FieldDeposit: Balance = 250 * CENTS; // 66 bytes on-chain + pub const ByteDeposit: Balance = deposit(0, 1); pub const SubAccountDeposit: Balance = 200 * CENTS; // 53 bytes on-chain pub const MaxSubAccounts: u32 = 100; pub const MaxAdditionalFields: u32 = 100; + pub const MaxIdentityBytes: u32 = 4 * 1024 * 1024; // 4 MiB pub const MaxRegistrars: u32 = 20; } @@ -608,9 +610,11 @@ impl pallet_identity::Config for Runtime { type Currency = Balances; type BasicDeposit = BasicDeposit; type FieldDeposit = FieldDeposit; + type ByteDeposit = ByteDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; type MaxAdditionalFields = MaxAdditionalFields; + type MaxIdentityBytes = MaxIdentityBytes; type IdentityInformation = IdentityInfo; type MaxRegistrars = MaxRegistrars; type Slashed = Treasury; diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index a6a1d3025425..724dcadd612f 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -862,9 +862,11 @@ parameter_types! { // Minimum 100 bytes/KSM deposited (1 CENT/byte) pub const BasicDeposit: Balance = 1000 * CENTS; // 258 bytes on-chain pub const FieldDeposit: Balance = 250 * CENTS; // 66 bytes on-chain + pub const ByteDeposit: Balance = deposit(0, 1); pub const SubAccountDeposit: Balance = 200 * CENTS; // 53 bytes on-chain pub const MaxSubAccounts: u32 = 100; pub const MaxAdditionalFields: u32 = 100; + pub const MaxIdentityBytes: u32 = 4 * 1024 * 1024; // 4 MiB pub const MaxRegistrars: u32 = 20; } @@ -874,9 +876,11 @@ impl pallet_identity::Config for Runtime { type Slashed = (); type BasicDeposit = BasicDeposit; type FieldDeposit = FieldDeposit; + type ByteDeposit = ByteDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; type MaxAdditionalFields = MaxAdditionalFields; + type MaxIdentityBytes = MaxIdentityBytes; type IdentityInformation = IdentityInfo; type MaxRegistrars = MaxRegistrars; type ForceOrigin = EitherOf, GeneralAdmin>; diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 2f658ed7324c..374cdeeb60d1 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -1461,6 +1461,7 @@ impl pallet_grandpa::Config for Runtime { parameter_types! { pub const BasicDeposit: Balance = 10 * DOLLARS; // 258 bytes on-chain pub const FieldDeposit: Balance = 250 * CENTS; // 66 bytes on-chain + pub const ByteDeposit: Balance = deposit(0, 1); pub const SubAccountDeposit: Balance = 2 * DOLLARS; // 53 bytes on-chain pub const MaxSubAccounts: u32 = 100; pub const MaxAdditionalFields: u32 = 100; @@ -1472,6 +1473,7 @@ impl pallet_identity::Config for Runtime { type Currency = Balances; type BasicDeposit = BasicDeposit; type FieldDeposit = FieldDeposit; + type ByteDeposit = ByteDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; type MaxAdditionalFields = MaxAdditionalFields; diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index 1bc7632ae9af..93798983b649 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -96,11 +96,13 @@ impl pallet_collective::Config for Test { } parameter_types! { - pub const BasicDeposit: u64 = 10; - pub const FieldDeposit: u64 = 10; - pub const SubAccountDeposit: u64 = 10; + pub const BasicDeposit: u64 = 100; + pub const FieldDeposit: u64 = 100; + pub const ByteDeposit: u64 = 10; + pub const SubAccountDeposit: u64 = 100; pub const MaxSubAccounts: u32 = 2; pub const MaxAdditionalFields: u32 = 2; + pub const MaxIdentityBytes: u32 = 1000; pub const MaxRegistrars: u32 = 20; } ord_parameter_types! { @@ -118,9 +120,11 @@ impl pallet_identity::Config for Test { type Currency = Balances; type BasicDeposit = BasicDeposit; type FieldDeposit = FieldDeposit; + type ByteDeposit = ByteDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; type MaxAdditionalFields = MaxAdditionalFields; + type MaxIdentityBytes = MaxIdentityBytes; type IdentityInformation = IdentityInfo; type MaxRegistrars = MaxRegistrars; type Slashed = (); diff --git a/substrate/frame/identity/src/legacy.rs b/substrate/frame/identity/src/legacy.rs index db5ecf3b1c97..0d4c3faf5aa1 100644 --- a/substrate/frame/identity/src/legacy.rs +++ b/substrate/frame/identity/src/legacy.rs @@ -130,10 +130,6 @@ impl + '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(num_fields: u32) -> Self { let data = Data::Raw(vec![0; 32].try_into().unwrap()); diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 7a35ac105f94..6674d7bc7a97 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -119,6 +119,10 @@ pub mod pallet { #[pallet::constant] type FieldDeposit: Get>; + /// The amount held on deposit per encoded byte for a registered identity. + #[pallet::constant] + type ByteDeposit: Get>; + /// 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. @@ -134,6 +138,11 @@ pub mod pallet { #[pallet::constant] type MaxAdditionalFields: Get; + /// Maximum number of encoded bytes 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 MaxIdentityBytes: Get; + /// Structure holding information about an identity. type IdentityInformation: IdentityInformationProvider; @@ -240,6 +249,8 @@ pub mod pallet { InvalidTarget, /// Too many additional fields. TooManyFields, + /// Identity encoded size is too high. + IdentitySize, /// Maximum amount of registrars reached. Cannot add any more. TooManyRegistrars, /// Account ID is already named. @@ -334,10 +345,9 @@ pub mod pallet { info: Box, ) -> DispatchResultWithPostInfo { let sender = ensure_signed(origin)?; - #[allow(deprecated)] - let extra_fields = info.additional() as u32; - ensure!(extra_fields <= T::MaxAdditionalFields::get(), Error::::TooManyFields); - let fd = >::from(extra_fields) * T::FieldDeposit::get(); + let encoded_byte_size = info.encoded_size() as u32; + ensure!(encoded_byte_size <= T::MaxIdentityBytes::get(), Error::::IdentitySize); + let byte_deposit = T::ByteDeposit::get() * >::from(encoded_byte_size); let mut id = match >::get(&sender) { Some(mut id) => { @@ -354,7 +364,7 @@ pub mod pallet { }; let old_deposit = id.deposit; - id.deposit = T::BasicDeposit::get() + fd; + id.deposit = T::BasicDeposit::get() + byte_deposit; if id.deposit > old_deposit { T::Currency::reserve(&sender, id.deposit - old_deposit)?; } diff --git a/substrate/frame/identity/src/tests.rs b/substrate/frame/identity/src/tests.rs index c8a7afb4098c..aabfa81b8cc8 100644 --- a/substrate/frame/identity/src/tests.rs +++ b/substrate/frame/identity/src/tests.rs @@ -32,7 +32,7 @@ use frame_support::{ use frame_system::{EnsureRoot, EnsureSignedBy}; use sp_core::H256; use sp_runtime::{ - traits::{BadOrigin, BlakeTwo256, IdentityLookup}, + traits::{BadOrigin, BlakeTwo256, Get, IdentityLookup}, BuildStorage, }; @@ -92,6 +92,7 @@ impl pallet_balances::Config for Test { parameter_types! { pub const MaxAdditionalFields: u32 = 2; + pub const MaxIdentityBytes: u32 = 1000; pub const MaxRegistrars: u32 = 20; } @@ -105,11 +106,13 @@ impl pallet_identity::Config for Test { type RuntimeEvent = RuntimeEvent; type Currency = Balances; type Slashed = (); - type BasicDeposit = ConstU64<10>; - type FieldDeposit = ConstU64<10>; - type SubAccountDeposit = ConstU64<10>; + type BasicDeposit = ConstU64<100>; + type FieldDeposit = ConstU64<100>; + type ByteDeposit = ConstU64<10>; + type SubAccountDeposit = ConstU64<100>; type MaxSubAccounts = ConstU32<2>; type MaxAdditionalFields = MaxAdditionalFields; + type MaxIdentityBytes = MaxIdentityBytes; type IdentityInformation = IdentityInfo; type MaxRegistrars = MaxRegistrars; type RegistrarOrigin = EnsureOneOrRoot; @@ -120,7 +123,7 @@ impl pallet_identity::Config for Test { pub fn new_test_ext() -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); pallet_balances::GenesisConfig:: { - balances: vec![(1, 10), (2, 10), (3, 10), (10, 100), (20, 100), (30, 100)], + balances: vec![(1, 100), (2, 100), (3, 100), (10, 1000), (20, 1000), (30, 1000)], } .assimilate_storage(&mut t) .unwrap(); @@ -143,6 +146,13 @@ fn twenty() -> IdentityInfo { } } +fn id_deposit(id: &IdentityInfo) -> u64 { + let base_deposit: u64 = <::BasicDeposit as Get>::get(); + let byte_deposit: u64 = <::ByteDeposit as Get>::get() * + TryInto::::try_into(id.encoded_size()).unwrap(); + base_deposit + byte_deposit +} + #[test] fn identity_fields_repr_works() { // `IdentityField` sanity checks. @@ -190,18 +200,23 @@ fn editing_subaccounts_should_work() { Error::::NoIdentity ); - assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten()))); + let ten = ten(); + assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten.clone()))); + let id_deposit = id_deposit(&ten); + assert_eq!(Balances::free_balance(10), 1000 - id_deposit); + + let sub_deposit: u64 = <::SubAccountDeposit as Get>::get(); // first sub account assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 1, data(1))); assert_eq!(SuperOf::::get(1), Some((10, data(1)))); - assert_eq!(Balances::free_balance(10), 80); + assert_eq!(Balances::free_balance(10), 1000 - id_deposit - sub_deposit); // second sub account assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 2, data(2))); assert_eq!(SuperOf::::get(1), Some((10, data(1)))); assert_eq!(SuperOf::::get(2), Some((10, data(2)))); - assert_eq!(Balances::free_balance(10), 70); + assert_eq!(Balances::free_balance(10), 1000 - id_deposit - 2 * sub_deposit); // third sub account is too many assert_noop!( @@ -213,20 +228,20 @@ fn editing_subaccounts_should_work() { assert_ok!(Identity::rename_sub(RuntimeOrigin::signed(10), 1, data(11))); assert_eq!(SuperOf::::get(1), Some((10, data(11)))); assert_eq!(SuperOf::::get(2), Some((10, data(2)))); - assert_eq!(Balances::free_balance(10), 70); + assert_eq!(Balances::free_balance(10), 1000 - id_deposit - 2 * sub_deposit); // remove first sub account assert_ok!(Identity::remove_sub(RuntimeOrigin::signed(10), 1)); assert_eq!(SuperOf::::get(1), None); assert_eq!(SuperOf::::get(2), Some((10, data(2)))); - assert_eq!(Balances::free_balance(10), 80); + assert_eq!(Balances::free_balance(10), 1000 - id_deposit - sub_deposit); // add third sub account assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 3, data(3))); assert_eq!(SuperOf::::get(1), None); assert_eq!(SuperOf::::get(2), Some((10, data(2)))); assert_eq!(SuperOf::::get(3), Some((10, data(3)))); - assert_eq!(Balances::free_balance(10), 70); + assert_eq!(Balances::free_balance(10), 1000 - id_deposit - 2 * sub_deposit); }); } @@ -234,15 +249,22 @@ fn editing_subaccounts_should_work() { fn resolving_subaccount_ownership_works() { new_test_ext().execute_with(|| { let data = |x| Data::Raw(vec![x; 1].try_into().unwrap()); + let sub_deposit: u64 = <::SubAccountDeposit as Get>::get(); - assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten()))); - assert_ok!(Identity::set_identity(RuntimeOrigin::signed(20), Box::new(twenty()))); + let ten = ten(); + let ten_deposit = id_deposit(&ten); + let twenty = twenty(); + let twenty_deposit = id_deposit(&twenty); + assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten))); + assert_eq!(Balances::free_balance(10), 1000 - ten_deposit); + assert_ok!(Identity::set_identity(RuntimeOrigin::signed(20), Box::new(twenty))); + assert_eq!(Balances::free_balance(20), 1000 - twenty_deposit); // 10 claims 1 as a subaccount assert_ok!(Identity::add_sub(RuntimeOrigin::signed(10), 1, data(1))); - assert_eq!(Balances::free_balance(1), 10); - assert_eq!(Balances::free_balance(10), 80); - assert_eq!(Balances::reserved_balance(10), 20); + assert_eq!(Balances::free_balance(1), 100); + assert_eq!(Balances::free_balance(10), 1000 - ten_deposit - sub_deposit); + assert_eq!(Balances::reserved_balance(10), ten_deposit + sub_deposit); // 20 cannot claim 1 now assert_noop!( Identity::add_sub(RuntimeOrigin::signed(20), 1, data(1)), @@ -251,9 +273,9 @@ fn resolving_subaccount_ownership_works() { // 1 wants to be with 20 so it quits from 10 assert_ok!(Identity::quit_sub(RuntimeOrigin::signed(1))); // 1 gets the 10 that 10 paid. - assert_eq!(Balances::free_balance(1), 20); - assert_eq!(Balances::free_balance(10), 80); - assert_eq!(Balances::reserved_balance(10), 10); + assert_eq!(Balances::free_balance(1), 100 + sub_deposit); + assert_eq!(Balances::free_balance(10), 1000 - ten_deposit - sub_deposit); + assert_eq!(Balances::reserved_balance(10), ten_deposit); // 20 can claim 1 now assert_ok!(Identity::add_sub(RuntimeOrigin::signed(20), 1, data(1))); }); @@ -306,11 +328,13 @@ fn registration_should_work() { 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); + let ten = ten(); + let id_deposit = id_deposit(&ten); + assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten.clone()))); + assert_eq!(Identity::identity(10).unwrap().info, ten); + assert_eq!(Balances::free_balance(10), 1000 - id_deposit); assert_ok!(Identity::clear_identity(RuntimeOrigin::signed(10))); - assert_eq!(Balances::free_balance(10), 100); + assert_eq!(Balances::free_balance(10), 1000); assert_noop!(Identity::clear_identity(RuntimeOrigin::signed(10)), Error::::NotNamed); }); } @@ -407,11 +431,13 @@ fn clearing_judgement_should_work() { #[test] fn killing_slashing_should_work() { new_test_ext().execute_with(|| { - assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten()))); + let ten = ten(); + let id_deposit = id_deposit(&ten); + assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten))); assert_noop!(Identity::kill_identity(RuntimeOrigin::signed(1), 10), BadOrigin); assert_ok!(Identity::kill_identity(RuntimeOrigin::signed(2), 10)); assert_eq!(Identity::identity(10), None); - assert_eq!(Balances::free_balance(10), 90); + assert_eq!(Balances::free_balance(10), 1000 - id_deposit); assert_noop!( Identity::kill_identity(RuntimeOrigin::signed(2), 10), Error::::NotNamed @@ -422,38 +448,43 @@ fn killing_slashing_should_work() { #[test] fn setting_subaccounts_should_work() { new_test_ext().execute_with(|| { + let ten = ten(); + let id_deposit = id_deposit(&ten); + let sub_deposit: u64 = <::SubAccountDeposit as Get>::get(); let mut subs = vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))]; assert_noop!( Identity::set_subs(RuntimeOrigin::signed(10), subs.clone()), Error::::NotFound ); - assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten()))); + assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten))); + assert_eq!(Balances::free_balance(10), 1000 - id_deposit); assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), subs.clone())); - assert_eq!(Balances::free_balance(10), 80); - assert_eq!(Identity::subs_of(10), (10, vec![20].try_into().unwrap())); + assert_eq!(Balances::free_balance(10), 1000 - id_deposit - sub_deposit); + assert_eq!(Identity::subs_of(10), (sub_deposit, vec![20].try_into().unwrap())); assert_eq!(Identity::super_of(20), Some((10, Data::Raw(vec![40; 1].try_into().unwrap())))); // push another item and re-set it. subs.push((30, Data::Raw(vec![50; 1].try_into().unwrap()))); assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), subs.clone())); - assert_eq!(Balances::free_balance(10), 70); - assert_eq!(Identity::subs_of(10), (20, vec![20, 30].try_into().unwrap())); + assert_eq!(Balances::free_balance(10), 1000 - id_deposit - 2 * sub_deposit); + assert_eq!(Identity::subs_of(10), (2 * sub_deposit, vec![20, 30].try_into().unwrap())); assert_eq!(Identity::super_of(20), Some((10, Data::Raw(vec![40; 1].try_into().unwrap())))); assert_eq!(Identity::super_of(30), Some((10, Data::Raw(vec![50; 1].try_into().unwrap())))); // switch out one of the items and re-set. subs[0] = (40, Data::Raw(vec![60; 1].try_into().unwrap())); assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), subs.clone())); - assert_eq!(Balances::free_balance(10), 70); // no change in the balance - assert_eq!(Identity::subs_of(10), (20, vec![40, 30].try_into().unwrap())); + // no change in the balance + assert_eq!(Balances::free_balance(10), 1000 - id_deposit - 2 * sub_deposit); + assert_eq!(Identity::subs_of(10), (2 * sub_deposit, vec![40, 30].try_into().unwrap())); assert_eq!(Identity::super_of(20), None); assert_eq!(Identity::super_of(30), Some((10, Data::Raw(vec![50; 1].try_into().unwrap())))); assert_eq!(Identity::super_of(40), Some((10, Data::Raw(vec![60; 1].try_into().unwrap())))); // clear assert_ok!(Identity::set_subs(RuntimeOrigin::signed(10), vec![])); - assert_eq!(Balances::free_balance(10), 90); + assert_eq!(Balances::free_balance(10), 1000 - id_deposit); assert_eq!(Identity::subs_of(10), (0, BoundedVec::default())); assert_eq!(Identity::super_of(30), None); assert_eq!(Identity::super_of(40), None); @@ -469,13 +500,15 @@ fn setting_subaccounts_should_work() { #[test] fn clearing_account_should_remove_subaccounts_and_refund() { new_test_ext().execute_with(|| { - assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten()))); + let ten = ten(); + assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten.clone()))); + assert_eq!(Balances::free_balance(10), 1000 - id_deposit(&ten)); assert_ok!(Identity::set_subs( RuntimeOrigin::signed(10), vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))] )); assert_ok!(Identity::clear_identity(RuntimeOrigin::signed(10))); - assert_eq!(Balances::free_balance(10), 100); + assert_eq!(Balances::free_balance(10), 1000); assert!(Identity::super_of(20).is_none()); }); } @@ -483,13 +516,18 @@ fn clearing_account_should_remove_subaccounts_and_refund() { #[test] fn killing_account_should_remove_subaccounts_and_not_refund() { new_test_ext().execute_with(|| { - assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten()))); + let ten = ten(); + let id_deposit = id_deposit(&ten); + let sub_deposit: u64 = <::SubAccountDeposit as Get>::get(); + assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten))); + assert_eq!(Balances::free_balance(10), 1000 - id_deposit); assert_ok!(Identity::set_subs( RuntimeOrigin::signed(10), vec![(20, Data::Raw(vec![40; 1].try_into().unwrap()))] )); + assert_eq!(Balances::free_balance(10), 1000 - id_deposit - sub_deposit); assert_ok!(Identity::kill_identity(RuntimeOrigin::signed(2), 10)); - assert_eq!(Balances::free_balance(10), 80); + assert_eq!(Balances::free_balance(10), 1000 - id_deposit - sub_deposit); assert!(Identity::super_of(20).is_none()); }); } @@ -503,10 +541,12 @@ fn cancelling_requested_judgement_should_work() { Identity::cancel_request(RuntimeOrigin::signed(10), 0), Error::::NoIdentity ); - assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten()))); + let ten = ten(); + assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten.clone()))); + assert_eq!(Balances::free_balance(10), 1000 - id_deposit(&ten)); assert_ok!(Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10)); assert_ok!(Identity::cancel_request(RuntimeOrigin::signed(10), 0)); - assert_eq!(Balances::free_balance(10), 90); + assert_eq!(Balances::free_balance(10), 1000 - id_deposit(&ten)); assert_noop!( Identity::cancel_request(RuntimeOrigin::signed(10), 0), Error::::NotFound @@ -517,7 +557,7 @@ fn cancelling_requested_judgement_should_work() { 0, 10, Judgement::Reasonable, - BlakeTwo256::hash_of(&ten()) + BlakeTwo256::hash_of(&ten) )); assert_noop!( Identity::cancel_request(RuntimeOrigin::signed(10), 0), @@ -531,14 +571,17 @@ fn requesting_judgement_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(ten()))); + let ten = ten(); + let id_deposit = id_deposit(&ten); + assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten.clone()))); + assert_eq!(Balances::free_balance(10), 1000 - id_deposit); assert_noop!( Identity::request_judgement(RuntimeOrigin::signed(10), 0, 9), Error::::FeeChanged ); assert_ok!(Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10)); - // 10 for the judgement request, 10 for the identity. - assert_eq!(Balances::free_balance(10), 80); + // 10 for the judgement request and the deposit for the identity. + assert_eq!(Balances::free_balance(10), 1000 - id_deposit - 10); // Re-requesting won't work as we already paid. assert_noop!( @@ -550,10 +593,11 @@ fn requesting_judgement_should_work() { 0, 10, Judgement::Erroneous, - BlakeTwo256::hash_of(&ten()) + BlakeTwo256::hash_of(&ten) )); // Registrar got their payment now. - assert_eq!(Balances::free_balance(3), 20); + // 100 initial balance and 10 for the judgement. + assert_eq!(Balances::free_balance(3), 100 + 10); // Re-requesting still won't work as it's erroneous. assert_noop!( @@ -571,7 +615,7 @@ fn requesting_judgement_should_work() { 0, 10, Judgement::OutOfDate, - BlakeTwo256::hash_of(&ten()) + BlakeTwo256::hash_of(&ten) )); assert_ok!(Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10)); }); @@ -580,12 +624,14 @@ fn requesting_judgement_should_work() { #[test] fn provide_judgement_should_return_judgement_payment_failed_error() { new_test_ext().execute_with(|| { + let ten = ten(); + let id_deposit = id_deposit(&ten); 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(ten()))); + assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(ten.clone()))); assert_ok!(Identity::request_judgement(RuntimeOrigin::signed(10), 0, 10)); - // 10 for the judgement request, 10 for the identity. - assert_eq!(Balances::free_balance(10), 80); + // 10 for the judgement request and the deposit for the identity. + assert_eq!(Balances::free_balance(10), 1000 - id_deposit - 10); // This forces judgement payment failed error Balances::make_free_balance_be(&3, 0); @@ -595,7 +641,7 @@ fn provide_judgement_should_return_judgement_payment_failed_error() { 0, 10, Judgement::Erroneous, - BlakeTwo256::hash_of(&ten()) + BlakeTwo256::hash_of(&ten) ), Error::::JudgementPaymentFailed ); @@ -607,25 +653,24 @@ 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); + let id = 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() + }; + let id_deposit = id_deposit(&id); + assert_ok!(Identity::set_identity(RuntimeOrigin::signed(10), Box::new(id))); + assert_eq!(Balances::free_balance(10), 1000 - id_deposit); }); } diff --git a/substrate/frame/identity/src/types.rs b/substrate/frame/identity/src/types.rs index 7055f6d80cfb..2fc5006af3b4 100644 --- a/substrate/frame/identity/src/types.rs +++ b/substrate/frame/identity/src/types.rs @@ -241,15 +241,6 @@ pub trait IdentityInformationProvider: /// 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 - /// 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(num_fields: u32) -> Self; } From 3112da81bd1a9eef18b73b9dd6593db27dc9ffa6 Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Thu, 26 Oct 2023 16:12:27 +0300 Subject: [PATCH 04/27] Add `poke_deposit` extrinsic Change adapted from https://github.com/paritytech/polkadot-sdk/pull/1814 Co-authored-by: joepetrowski Signed-off-by: georgepisaltu --- .../rococo/src/weights/pallet_identity.rs | 16 +++ .../westend/src/weights/pallet_identity.rs | 16 +++ substrate/frame/identity/src/benchmarking.rs | 50 +++++++ substrate/frame/identity/src/lib.rs | 81 ++++++++++- substrate/frame/identity/src/tests.rs | 136 +++++++++++++++++- substrate/frame/identity/src/weights.rs | 33 +++++ 6 files changed, 329 insertions(+), 3 deletions(-) diff --git a/polkadot/runtime/rococo/src/weights/pallet_identity.rs b/polkadot/runtime/rococo/src/weights/pallet_identity.rs index e8c25269ac37..c2a456738a85 100644 --- a/polkadot/runtime/rococo/src/weights/pallet_identity.rs +++ b/polkadot/runtime/rococo/src/weights/pallet_identity.rs @@ -334,4 +334,20 @@ impl pallet_identity::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) } + /// Storage: `Identity::IdentityOf` (r:1 w:1) + /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7538), added: 10013, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Identity::SubsOf` (r:1 w:1) + /// Proof: `Identity::SubsOf` (`max_values`: None, `max_size`: Some(3258), added: 5733, mode: `MaxEncodedLen`) + fn poke_deposit() -> Weight { + // Proof Size summary in bytes: + // Measured: `628` + // Estimated: `11003` + // Minimum execution time: 525_039_000 picoseconds. + Weight::from_parts(554_552_000, 0) + .saturating_add(Weight::from_parts(0, 11003)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + } } diff --git a/polkadot/runtime/westend/src/weights/pallet_identity.rs b/polkadot/runtime/westend/src/weights/pallet_identity.rs index dea631b9316b..8e8c56d48031 100644 --- a/polkadot/runtime/westend/src/weights/pallet_identity.rs +++ b/polkadot/runtime/westend/src/weights/pallet_identity.rs @@ -338,4 +338,20 @@ impl pallet_identity::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) } + /// Storage: `Identity::IdentityOf` (r:1 w:1) + /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7538), added: 10013, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Identity::SubsOf` (r:1 w:1) + /// Proof: `Identity::SubsOf` (`max_values`: None, `max_size`: Some(3258), added: 5733, mode: `MaxEncodedLen`) + fn poke_deposit() -> Weight { + // Proof Size summary in bytes: + // Measured: `628` + // Estimated: `11003` + // Minimum execution time: 525_039_000 picoseconds. + Weight::from_parts(554_552_000, 0) + .saturating_add(Weight::from_parts(0, 11003)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + } } diff --git a/substrate/frame/identity/src/benchmarking.rs b/substrate/frame/identity/src/benchmarking.rs index 29347a644e22..baa2392b50cb 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 codec::Encode; use enumflags2::BitFlag; use frame_benchmarking::{ account, impl_benchmark_test_suite, v2::*, whitelisted_caller, BenchmarkError, @@ -29,6 +30,7 @@ use frame_benchmarking::{ use frame_support::{ ensure, traits::{EnsureOrigin, Get}, + BoundedVec, }; use frame_system::RawOrigin; use sp_runtime::traits::Bounded; @@ -529,5 +531,53 @@ mod benchmarks { Ok(()) } + #[benchmark] + fn poke_deposit() -> Result<(), BenchmarkError> { + let caller: T::AccountId = whitelisted_caller(); + let target: T::AccountId = account("target", 0, SEED); + let target_lookup = T::Lookup::unlookup(target.clone()); + let _ = T::Currency::make_free_balance_be(&target, BalanceOf::::max_value()); + let additional_fields = 0; + + // insert identity into storage with zero deposit + let id = T::IdentityInformation::create_identity_info(additional_fields); + IdentityOf::::insert( + &target, + Registration { + judgements: BoundedVec::default(), + deposit: Zero::zero(), + info: id.clone(), + }, + ); + + // insert subs into storage with zero deposit + let sub_account = account("sub", 0, SEED); + let subs = BoundedVec::<_, T::MaxSubAccounts>::try_from(vec![sub_account]).unwrap(); + SubsOf::::insert::< + &T::AccountId, + (BalanceOf, BoundedVec), + >(&target, (Zero::zero(), subs)); + + // expected deposits + let expected_id_deposit = T::ByteDeposit::get() + .saturating_mul(id.encoded_size().try_into().unwrap_or_default()) + .saturating_add(T::BasicDeposit::get()); + let expected_sub_deposit = T::SubAccountDeposit::get(); // only 1 + + #[extrinsic_call] + _(RawOrigin::Signed(caller), target_lookup); + + assert_last_event::( + Event::::DepositUpdated { + who: target, + identity: expected_id_deposit, + subs: expected_sub_deposit, + } + .into(), + ); + + Ok(()) + } + impl_benchmark_test_suite!(Identity, crate::tests::new_test_ext(), crate::tests::Test); } diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 6674d7bc7a97..48b00a492016 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -79,7 +79,10 @@ mod tests; mod types; pub mod weights; -use frame_support::traits::{BalanceStatus, Currency, OnUnbalanced, ReservableCurrency}; +use frame_support::{ + pallet_prelude::DispatchResult, + traits::{BalanceStatus, Currency, Get, OnUnbalanced, ReservableCurrency}, +}; use sp_runtime::traits::{AppendZerosInput, Hash, Saturating, StaticLookup, Zero}; use sp_std::prelude::*; pub use weights::WeightInfo; @@ -289,6 +292,9 @@ pub mod pallet { /// A sub-identity was cleared, and the given deposit repatriated from the /// main identity account to the sub-identity account. SubIdentityRevoked { sub: T::AccountId, main: T::AccountId, deposit: BalanceOf }, + /// The deposits held for `who` were updated. `identity` is the new deposit held for + /// identity info, and `subs` is the new deposit held for the sub-accounts. + DepositUpdated { who: T::AccountId, identity: BalanceOf, subs: BalanceOf }, } #[pallet::call] @@ -905,6 +911,59 @@ pub mod pallet { }); Ok(()) } + + /// Update the deposits held by `target` for its identity info. + /// + /// Parameters: + /// - `target`: The account for which to update deposits. + /// + /// May be called by any signed origin. + #[pallet::call_index(16)] + #[pallet::weight(T::WeightInfo::poke_deposit())] + pub fn poke_deposit(origin: OriginFor, target: AccountIdLookupOf) -> DispatchResult { + // No locked check: used for migration. + // anyone or root (so that the system can call it for identity migration) + let _ = ensure_signed_or_root(origin)?; + let target = T::Lookup::lookup(target)?; + + // Identity Deposit + ensure!(IdentityOf::::contains_key(&target), Error::::NoIdentity); + let new_id_deposit = IdentityOf::::try_mutate( + &target, + |registration| -> Result, DispatchError> { + let reg = registration.as_mut().ok_or(Error::::NoIdentity)?; + // Calculate what deposit should be + let encoded_byte_size = reg.info.encoded_size() as u32; + let byte_deposit = + T::ByteDeposit::get() * >::from(encoded_byte_size); + let new_id_deposit = T::BasicDeposit::get().saturating_add(byte_deposit); + + // Update account + Self::rejig_deposit(&target, reg.deposit, new_id_deposit)?; + + reg.deposit = new_id_deposit; + Ok(new_id_deposit) + }, + )?; + + // Subs Deposit + let new_subs_deposit = SubsOf::::try_mutate( + &target, + |(current_subs_deposit, subs_of)| -> Result, DispatchError> { + let new_subs_deposit = Self::subs_deposit(subs_of.len() as u32); + Self::rejig_deposit(&target, *current_subs_deposit, new_subs_deposit)?; + *current_subs_deposit = new_subs_deposit; + Ok(new_subs_deposit) + }, + )?; + + Self::deposit_event(Event::DepositUpdated { + who: target, + identity: new_id_deposit, + subs: new_subs_deposit, + }); + Ok(()) + } } } @@ -923,4 +982,24 @@ impl Pallet { IdentityOf::::get(who) .map_or(false, |registration| (registration.info.has_identity(fields))) } + + /// Calculate the deposit required for a number of `sub` accounts. + fn subs_deposit(subs: u32) -> BalanceOf { + T::SubAccountDeposit::get().saturating_mul(>::from(subs)) + } + + /// Take the `current` deposit that `who` is holding, and update it to a `new` one. + fn rejig_deposit( + who: &T::AccountId, + current: BalanceOf, + new: BalanceOf, + ) -> DispatchResult { + if new > current { + T::Currency::reserve(who, new - current)?; + } else if new < current { + let err_amount = T::Currency::unreserve(who, current - new); + debug_assert!(err_amount.is_zero()); + } + Ok(()) + } } diff --git a/substrate/frame/identity/src/tests.rs b/substrate/frame/identity/src/tests.rs index aabfa81b8cc8..885aa72b32da 100644 --- a/substrate/frame/identity/src/tests.rs +++ b/substrate/frame/identity/src/tests.rs @@ -26,13 +26,13 @@ use crate::{ use codec::{Decode, Encode}; use frame_support::{ assert_noop, assert_ok, ord_parameter_types, parameter_types, - traits::{ConstU32, ConstU64, EitherOfDiverse}, + traits::{ConstU32, ConstU64, EitherOfDiverse, Get}, BoundedVec, }; use frame_system::{EnsureRoot, EnsureSignedBy}; use sp_core::H256; use sp_runtime::{ - traits::{BadOrigin, BlakeTwo256, Get, IdentityLookup}, + traits::{BadOrigin, BlakeTwo256, IdentityLookup}, BuildStorage, }; @@ -706,3 +706,135 @@ fn test_has_identity() { )); }); } + +#[test] +fn poke_deposit_increase_works() { + new_test_ext().execute_with(|| { + let ten = ten(); + let id_deposit = id_deposit(&ten); + let sub_deposit: u64 = <::SubAccountDeposit as Get>::get(); + // Set a custom registration with 0 deposit + IdentityOf::::insert( + &10, + Registration { + judgements: BoundedVec::default(), + deposit: Zero::zero(), + info: ten.clone(), + }, + ); + assert!(Identity::identity(10).is_some()); + // Set a sub with zero deposit + SubsOf::::insert::<&u64, (u64, BoundedVec>)>( + &10, + (0, vec![20].try_into().unwrap()), + ); + SuperOf::::insert(&20, (&10, Data::Raw(vec![1; 1].try_into().unwrap()))); + // Balance is free + assert_eq!(Balances::free_balance(10), 1000); + + // Poke + assert_ok!(Identity::poke_deposit(RuntimeOrigin::signed(1), 10)); + + // Free balance reduced by the identity deposit and the deposit for one sub + assert_eq!(Balances::free_balance(10), 1000 - id_deposit - sub_deposit); + // New registration deposit is now `id_deposit` + assert_eq!( + Identity::identity(&10), + Some(Registration { + judgements: BoundedVec::default(), + deposit: id_deposit, + info: ten + }) + ); + // New subs deposit is `sub_deposit` + assert_eq!(Identity::subs_of(10), (sub_deposit, vec![20].try_into().unwrap())); + }); +} + +#[test] +fn poke_deposit_decrease_works() { + new_test_ext().execute_with(|| { + let ten = ten(); + let id_deposit = id_deposit(&ten); + let sub_deposit: u64 = <::SubAccountDeposit as Get>::get(); + let inflated_sub_deposit = sub_deposit * 10; + SubsOf::::insert::<&u64, (u64, BoundedVec>)>( + &10, + (inflated_sub_deposit, vec![20].try_into().unwrap()), + ); + SuperOf::::insert(&20, (&10, Data::Raw(vec![1; 1].try_into().unwrap()))); + // Set a custom registration with some inflated deposit + let inflated_id_deposit = id_deposit * 10; + IdentityOf::::insert( + &10, + Registration { + judgements: BoundedVec::default(), + deposit: inflated_id_deposit, + info: ten.clone(), + }, + ); + assert!(Identity::identity(10).is_some()); + // Balance is untouched + assert_eq!(Balances::free_balance(10), 1000); + // Simulate the deposits + Balances::make_free_balance_be(&10, 1000 + inflated_id_deposit + inflated_sub_deposit); + assert_ok!(Balances::reserve(&10, inflated_id_deposit + inflated_sub_deposit)); + + // Poke + assert_ok!(Identity::poke_deposit(RuntimeOrigin::signed(1), 10)); + + // Free balance increased by the difference between the inflated deposits and the actual + // deposits + assert_eq!( + Balances::free_balance(10), + 1000 + (inflated_id_deposit - id_deposit) + (inflated_sub_deposit - sub_deposit) + ); + assert_eq!(Balances::reserved_balance(10), id_deposit + sub_deposit); + // New registration deposit is now `id_deposit` + assert_eq!( + Identity::identity(&10), + Some(Registration { + judgements: BoundedVec::default(), + deposit: id_deposit, + info: ten + }) + ); + // New subs deposit is `sub_deposit` + assert_eq!(Identity::subs_of(10), (sub_deposit, vec![20].try_into().unwrap())); + }); +} + +#[test] +#[should_panic] +fn poke_deposit_decrease_insufficient_reserved() { + new_test_ext().execute_with(|| { + let ten = ten(); + let id_deposit = id_deposit(&ten); + let sub_deposit: u64 = <::SubAccountDeposit as Get>::get(); + let inflated_sub_deposit = sub_deposit * 10; + SubsOf::::insert::<&u64, (u64, BoundedVec>)>( + &10, + (inflated_sub_deposit, vec![20].try_into().unwrap()), + ); + SuperOf::::insert(&20, (&10, Data::Raw(vec![1; 1].try_into().unwrap()))); + // Set a custom registration with some inflated deposit + let inflated_id_deposit = id_deposit * 10; + IdentityOf::::insert( + &10, + Registration { + judgements: BoundedVec::default(), + deposit: inflated_id_deposit, + info: ten.clone(), + }, + ); + assert!(Identity::identity(10).is_some()); + // Balance is untouched + assert_eq!(Balances::free_balance(10), 1000); + // Ensure the reserved amount is 0 so that `unreserve`` will not succeed + assert_eq!(Balances::free_balance(10), 1000); + + // Poke - this should panic in the test because of a `debug_assert` that the entire deposit + // is successfully unreserved + let _ = Identity::poke_deposit(RuntimeOrigin::signed(1), 10); + }); +} diff --git a/substrate/frame/identity/src/weights.rs b/substrate/frame/identity/src/weights.rs index 95898e6c6cdf..3f03d2c2a4e6 100644 --- a/substrate/frame/identity/src/weights.rs +++ b/substrate/frame/identity/src/weights.rs @@ -68,6 +68,7 @@ pub trait WeightInfo { fn rename_sub(s: u32, ) -> Weight; fn remove_sub(s: u32, ) -> Weight; fn quit_sub(s: u32, ) -> Weight; + fn poke_deposit() -> Weight; } /// Weights for pallet_identity using the Substrate node and recommended hardware. @@ -345,6 +346,22 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } + /// Storage: `Identity::IdentityOf` (r:1 w:1) + /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7538), added: 10013, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Identity::SubsOf` (r:1 w:1) + /// Proof: `Identity::SubsOf` (`max_values`: None, `max_size`: Some(3258), added: 5733, mode: `MaxEncodedLen`) + fn poke_deposit() -> Weight { + // Proof Size summary in bytes: + // Measured: `628` + // Estimated: `11003` + // Minimum execution time: 525_039_000 picoseconds. + Weight::from_parts(554_552_000, 0) + .saturating_add(Weight::from_parts(0, 11003)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + } } // For backwards compatibility and tests @@ -621,4 +638,20 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } + /// Storage: `Identity::IdentityOf` (r:1 w:1) + /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7538), added: 10013, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Identity::SubsOf` (r:1 w:1) + /// Proof: `Identity::SubsOf` (`max_values`: None, `max_size`: Some(3258), added: 5733, mode: `MaxEncodedLen`) + fn poke_deposit() -> Weight { + // Proof Size summary in bytes: + // Measured: `628` + // Estimated: `11003` + // Minimum execution time: 525_039_000 picoseconds. + Weight::from_parts(554_552_000, 0) + .saturating_add(Weight::from_parts(0, 11003)) + .saturating_add(RocksDbWeight::get().reads(3)) + .saturating_add(RocksDbWeight::get().writes(3)) + } } From f41d3f0a475b5c379cefb2a2a1160e8c94e93d06 Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Thu, 26 Oct 2023 17:27:03 +0300 Subject: [PATCH 05/27] Move max identity size to constant out of pallet Signed-off-by: georgepisaltu --- polkadot/runtime/rococo/src/lib.rs | 2 -- polkadot/runtime/westend/src/lib.rs | 2 -- substrate/frame/alliance/src/mock.rs | 2 -- substrate/frame/identity/src/lib.rs | 10 ++++------ substrate/frame/identity/src/tests.rs | 2 -- 5 files changed, 4 insertions(+), 14 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index eeeb72954721..0816e09d7b7d 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -601,7 +601,6 @@ parameter_types! { pub const SubAccountDeposit: Balance = 200 * CENTS; // 53 bytes on-chain pub const MaxSubAccounts: u32 = 100; pub const MaxAdditionalFields: u32 = 100; - pub const MaxIdentityBytes: u32 = 4 * 1024 * 1024; // 4 MiB pub const MaxRegistrars: u32 = 20; } @@ -614,7 +613,6 @@ impl pallet_identity::Config for Runtime { type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; type MaxAdditionalFields = MaxAdditionalFields; - type MaxIdentityBytes = MaxIdentityBytes; type IdentityInformation = IdentityInfo; type MaxRegistrars = MaxRegistrars; type Slashed = Treasury; diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 724dcadd612f..906e63922591 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -866,7 +866,6 @@ parameter_types! { pub const SubAccountDeposit: Balance = 200 * CENTS; // 53 bytes on-chain pub const MaxSubAccounts: u32 = 100; pub const MaxAdditionalFields: u32 = 100; - pub const MaxIdentityBytes: u32 = 4 * 1024 * 1024; // 4 MiB pub const MaxRegistrars: u32 = 20; } @@ -880,7 +879,6 @@ impl pallet_identity::Config for Runtime { type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; type MaxAdditionalFields = MaxAdditionalFields; - type MaxIdentityBytes = MaxIdentityBytes; type IdentityInformation = IdentityInfo; type MaxRegistrars = MaxRegistrars; type ForceOrigin = EitherOf, GeneralAdmin>; diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index 93798983b649..a24344e772c8 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -102,7 +102,6 @@ parameter_types! { pub const SubAccountDeposit: u64 = 100; pub const MaxSubAccounts: u32 = 2; pub const MaxAdditionalFields: u32 = 2; - pub const MaxIdentityBytes: u32 = 1000; pub const MaxRegistrars: u32 = 20; } ord_parameter_types! { @@ -124,7 +123,6 @@ impl pallet_identity::Config for Test { type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; type MaxAdditionalFields = MaxAdditionalFields; - type MaxIdentityBytes = MaxIdentityBytes; type IdentityInformation = IdentityInfo; type MaxRegistrars = MaxRegistrars; type Slashed = (); diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 48b00a492016..48c0f31b77b0 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -100,6 +100,9 @@ type NegativeImbalanceOf = <::Currency as Currency< >>::NegativeImbalance; type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; +/// Maximum size of an identity we can store is 4 MiB. +const IDENTITY_MAX_SIZE: u32 = 4 * 1024 * 1024; + #[frame_support::pallet] pub mod pallet { use super::*; @@ -141,11 +144,6 @@ pub mod pallet { #[pallet::constant] type MaxAdditionalFields: Get; - /// Maximum number of encoded bytes 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 MaxIdentityBytes: Get; - /// Structure holding information about an identity. type IdentityInformation: IdentityInformationProvider; @@ -352,7 +350,7 @@ pub mod pallet { ) -> DispatchResultWithPostInfo { let sender = ensure_signed(origin)?; let encoded_byte_size = info.encoded_size() as u32; - ensure!(encoded_byte_size <= T::MaxIdentityBytes::get(), Error::::IdentitySize); + ensure!(encoded_byte_size <= IDENTITY_MAX_SIZE, Error::::IdentitySize); let byte_deposit = T::ByteDeposit::get() * >::from(encoded_byte_size); let mut id = match >::get(&sender) { diff --git a/substrate/frame/identity/src/tests.rs b/substrate/frame/identity/src/tests.rs index 885aa72b32da..e059571861d0 100644 --- a/substrate/frame/identity/src/tests.rs +++ b/substrate/frame/identity/src/tests.rs @@ -92,7 +92,6 @@ impl pallet_balances::Config for Test { parameter_types! { pub const MaxAdditionalFields: u32 = 2; - pub const MaxIdentityBytes: u32 = 1000; pub const MaxRegistrars: u32 = 20; } @@ -112,7 +111,6 @@ impl pallet_identity::Config for Test { type SubAccountDeposit = ConstU64<100>; type MaxSubAccounts = ConstU32<2>; type MaxAdditionalFields = MaxAdditionalFields; - type MaxIdentityBytes = MaxIdentityBytes; type IdentityInformation = IdentityInfo; type MaxRegistrars = MaxRegistrars; type RegistrarOrigin = EnsureOneOrRoot; From c6e7bf0d77254efb16f433858dab42f4d500389c Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Thu, 26 Oct 2023 19:58:16 +0300 Subject: [PATCH 06/27] Remove obsolete config and fix alliance tests Signed-off-by: georgepisaltu --- 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 | 53 +++++++++++--------- substrate/frame/alliance/src/tests.rs | 16 ++++-- substrate/frame/identity/src/benchmarking.rs | 19 ++++--- substrate/frame/identity/src/legacy.rs | 9 +++- substrate/frame/identity/src/lib.rs | 9 ---- substrate/frame/identity/src/tests.rs | 2 - substrate/frame/identity/src/types.rs | 4 +- 10 files changed, 60 insertions(+), 61 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 0816e09d7b7d..4054af7a85ac 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -596,7 +596,6 @@ impl claims::Config for Runtime { parameter_types! { // Minimum 100 bytes/ROC deposited (1 CENT/byte) pub const BasicDeposit: Balance = 1000 * CENTS; // 258 bytes on-chain - pub const FieldDeposit: Balance = 250 * CENTS; // 66 bytes on-chain pub const ByteDeposit: Balance = deposit(0, 1); pub const SubAccountDeposit: Balance = 200 * CENTS; // 53 bytes on-chain pub const MaxSubAccounts: u32 = 100; @@ -608,11 +607,9 @@ impl pallet_identity::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; type BasicDeposit = BasicDeposit; - type FieldDeposit = FieldDeposit; type ByteDeposit = ByteDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; - type MaxAdditionalFields = MaxAdditionalFields; type IdentityInformation = IdentityInfo; type MaxRegistrars = MaxRegistrars; type Slashed = Treasury; diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 906e63922591..346997171194 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -861,7 +861,6 @@ where parameter_types! { // Minimum 100 bytes/KSM deposited (1 CENT/byte) pub const BasicDeposit: Balance = 1000 * CENTS; // 258 bytes on-chain - pub const FieldDeposit: Balance = 250 * CENTS; // 66 bytes on-chain pub const ByteDeposit: Balance = deposit(0, 1); pub const SubAccountDeposit: Balance = 200 * CENTS; // 53 bytes on-chain pub const MaxSubAccounts: u32 = 100; @@ -874,11 +873,9 @@ impl pallet_identity::Config for Runtime { type Currency = Balances; type Slashed = (); type BasicDeposit = BasicDeposit; - type FieldDeposit = FieldDeposit; type ByteDeposit = ByteDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; - type MaxAdditionalFields = MaxAdditionalFields; type IdentityInformation = IdentityInfo; type MaxRegistrars = MaxRegistrars; type ForceOrigin = EitherOf, GeneralAdmin>; diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 374cdeeb60d1..d7b3ced42a64 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -1460,7 +1460,6 @@ impl pallet_grandpa::Config for Runtime { parameter_types! { pub const BasicDeposit: Balance = 10 * DOLLARS; // 258 bytes on-chain - pub const FieldDeposit: Balance = 250 * CENTS; // 66 bytes on-chain pub const ByteDeposit: Balance = deposit(0, 1); pub const SubAccountDeposit: Balance = 2 * DOLLARS; // 53 bytes on-chain pub const MaxSubAccounts: u32 = 100; @@ -1472,11 +1471,9 @@ impl pallet_identity::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; type BasicDeposit = BasicDeposit; - type FieldDeposit = FieldDeposit; type ByteDeposit = ByteDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; - type MaxAdditionalFields = MaxAdditionalFields; type IdentityInformation = IdentityInfo; type MaxRegistrars = MaxRegistrars; type Slashed = Treasury; diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index a24344e772c8..331ea553bbf9 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -97,7 +97,6 @@ impl pallet_collective::Config for Test { parameter_types! { pub const BasicDeposit: u64 = 100; - pub const FieldDeposit: u64 = 100; pub const ByteDeposit: u64 = 10; pub const SubAccountDeposit: u64 = 100; pub const MaxSubAccounts: u32 = 2; @@ -118,11 +117,9 @@ impl pallet_identity::Config for Test { type RuntimeEvent = RuntimeEvent; type Currency = Balances; type BasicDeposit = BasicDeposit; - type FieldDeposit = FieldDeposit; type ByteDeposit = ByteDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; - type MaxAdditionalFields = MaxAdditionalFields; type IdentityInformation = IdentityInfo; type MaxRegistrars = MaxRegistrars; type Slashed = (); @@ -234,20 +231,40 @@ frame_support::construct_runtime!( } ); +fn test_identity_info() -> IdentityInfo { + 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()), + riot: Data::default(), + email: Data::default(), + pgp_fingerprint: None, + image: Data::default(), + twitter: Data::default(), + } +} + +pub(super) fn test_identity_info_deposit() -> ::Balance { + let basic_deposit: u64 = ::BasicDeposit::get(); + let byte_deposit: u64 = ::ByteDeposit::get(); + byte_deposit * test_identity_info().encoded_size() as u64 + basic_deposit +} + pub fn new_test_ext() -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); pallet_balances::GenesisConfig:: { balances: vec![ - (1, 50), - (2, 50), - (3, 50), - (4, 50), - (5, 30), - (6, 50), - (7, 50), - (8, 50), - (9, 50), + (1, 1000), + (2, 1000), + (3, 1000), + (4, 1000), + (5, test_identity_info_deposit() + 10), + (6, 1000), + (7, 1000), + (8, 1000), + (9, 1000), ], } .assimilate_storage(&mut t) @@ -265,17 +282,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { ext.execute_with(|| { 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()), - riot: Data::default(), - email: Data::default(), - pgp_fingerprint: None, - image: Data::default(), - twitter: Data::default(), - }; + let info = test_identity_info(); assert_ok!(Identity::set_identity(RuntimeOrigin::signed(1), Box::new(info.clone()))); assert_ok!(Identity::provide_judgement( RuntimeOrigin::signed(1), diff --git a/substrate/frame/alliance/src/tests.rs b/substrate/frame/alliance/src/tests.rs index 098fd86bbae1..ddf89597e0e4 100644 --- a/substrate/frame/alliance/src/tests.rs +++ b/substrate/frame/alliance/src/tests.rs @@ -105,6 +105,9 @@ fn init_members_works() { #[test] fn disband_works() { new_test_ext().execute_with(|| { + let id_deposit = test_identity_info_deposit(); + let expected_join_deposit = ::AllyDeposit::get(); + assert_eq!(Balances::free_balance(9), 1000 - id_deposit); // ensure alliance is set assert_eq!(Alliance::voting_members(), vec![1, 2, 3]); @@ -113,10 +116,10 @@ fn disband_works() { assert!(Alliance::is_member_of(&2, MemberRole::Retiring)); // join alliance and reserve funds - assert_eq!(Balances::free_balance(9), 40); + assert_eq!(Balances::free_balance(9), 1000 - id_deposit); assert_ok!(Alliance::join_alliance(RuntimeOrigin::signed(9))); - assert_eq!(Alliance::deposit_of(9), Some(25)); - assert_eq!(Balances::free_balance(9), 15); + assert_eq!(Alliance::deposit_of(9), Some(expected_join_deposit)); + assert_eq!(Balances::free_balance(9), 1000 - id_deposit - expected_join_deposit); assert!(Alliance::is_member_of(&9, MemberRole::Ally)); // fails without root @@ -146,7 +149,7 @@ fn disband_works() { // assert a retiring member from the previous Alliance not removed assert!(Alliance::is_member_of(&2, MemberRole::Retiring)); // deposit unreserved - assert_eq!(Balances::free_balance(9), 40); + assert_eq!(Balances::free_balance(9), 1000 - id_deposit); System::assert_last_event(mock::RuntimeEvent::Alliance(crate::Event::AllianceDisbanded { fellow_members: 2, @@ -358,6 +361,9 @@ fn remove_announcement_works() { #[test] fn join_alliance_works() { new_test_ext().execute_with(|| { + let id_deposit = test_identity_info_deposit(); + let join_deposit = ::AllyDeposit::get(); + assert_eq!(Balances::free_balance(9), 1000 - id_deposit); // check already member assert_noop!( Alliance::join_alliance(RuntimeOrigin::signed(1)), @@ -384,8 +390,10 @@ fn join_alliance_works() { Error::::InsufficientFunds ); + assert_eq!(Balances::free_balance(4), 1000 - id_deposit); // success to submit assert_ok!(Alliance::join_alliance(RuntimeOrigin::signed(4))); + assert_eq!(Balances::free_balance(4), 1000 - id_deposit - join_deposit); assert_eq!(Alliance::deposit_of(4), Some(25)); assert_eq!(Alliance::members(MemberRole::Ally), vec![4]); diff --git a/substrate/frame/identity/src/benchmarking.rs b/substrate/frame/identity/src/benchmarking.rs index baa2392b50cb..8adbc38f80aa 100644 --- a/substrate/frame/identity/src/benchmarking.rs +++ b/substrate/frame/identity/src/benchmarking.rs @@ -79,7 +79,7 @@ fn create_sub_accounts( // Set identity so `set_subs` does not fail. if IdentityOf::::get(who).is_none() { let _ = T::Currency::make_free_balance_be(who, BalanceOf::::max_value() / 2u32.into()); - let info = T::IdentityInformation::create_identity_info(1); + let info = T::IdentityInformation::create_identity_info(); Identity::::set_identity(who_origin.into(), Box::new(info))?; } @@ -130,7 +130,7 @@ mod benchmarks { let _ = T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); // Add an initial identity - let initial_info = T::IdentityInformation::create_identity_info(1); + let initial_info = T::IdentityInformation::create_identity_info(); Identity::::set_identity(caller_origin.clone(), Box::new(initial_info.clone()))?; // User requests judgement from all the registrars, and they approve @@ -153,7 +153,7 @@ mod benchmarks { #[extrinsic_call] _( RawOrigin::Signed(caller.clone()), - Box::new(T::IdentityInformation::create_identity_info(T::MaxAdditionalFields::get())), + Box::new(T::IdentityInformation::create_identity_info()), ); assert_last_event::(Event::::IdentitySet { who: caller }.into()); @@ -214,7 +214,7 @@ mod benchmarks { let _ = add_sub_accounts::(&caller, s)?; // Create their main identity with x additional fields - let info = T::IdentityInformation::create_identity_info(T::MaxAdditionalFields::get()); + let info = T::IdentityInformation::create_identity_info(); Identity::::set_identity(caller_origin.clone(), Box::new(info.clone()))?; // User requests judgement from all the registrars, and they approve @@ -251,7 +251,7 @@ mod benchmarks { add_registrars::(r)?; // Create their main identity with x additional fields - let info = T::IdentityInformation::create_identity_info(T::MaxAdditionalFields::get()); + let info = T::IdentityInformation::create_identity_info(); let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); Identity::::set_identity(caller_origin.clone(), Box::new(info))?; @@ -275,7 +275,7 @@ mod benchmarks { add_registrars::(r)?; // Create their main identity with x additional fields - let info = T::IdentityInformation::create_identity_info(T::MaxAdditionalFields::get()); + let info = T::IdentityInformation::create_identity_info(); let caller_origin = ::RuntimeOrigin::from(RawOrigin::Signed(caller.clone())); Identity::::set_identity(caller_origin.clone(), Box::new(info))?; @@ -398,7 +398,7 @@ mod benchmarks { add_registrars::(r)?; - let info = T::IdentityInformation::create_identity_info(T::MaxAdditionalFields::get()); + let info = T::IdentityInformation::create_identity_info(); let info_hash = T::Hashing::hash_of(&info); Identity::::set_identity(user_origin.clone(), Box::new(info))?; @@ -430,7 +430,7 @@ mod benchmarks { let target_lookup = T::Lookup::unlookup(target.clone()); let _ = T::Currency::make_free_balance_be(&target, BalanceOf::::max_value()); - let info = T::IdentityInformation::create_identity_info(T::MaxAdditionalFields::get()); + let info = T::IdentityInformation::create_identity_info(); Identity::::set_identity(target_origin.clone(), Box::new(info.clone()))?; let _ = add_sub_accounts::(&target, s)?; @@ -537,10 +537,9 @@ mod benchmarks { let target: T::AccountId = account("target", 0, SEED); let target_lookup = T::Lookup::unlookup(target.clone()); let _ = T::Currency::make_free_balance_be(&target, BalanceOf::::max_value()); - let additional_fields = 0; // insert identity into storage with zero deposit - let id = T::IdentityInformation::create_identity_info(additional_fields); + let id = T::IdentityInformation::create_identity_info(); IdentityOf::::insert( &target, Registration { diff --git a/substrate/frame/identity/src/legacy.rs b/substrate/frame/identity/src/legacy.rs index 0d4c3faf5aa1..6edbc7a2a116 100644 --- a/substrate/frame/identity/src/legacy.rs +++ b/substrate/frame/identity/src/legacy.rs @@ -24,6 +24,9 @@ use sp_std::prelude::*; use crate::types::{Data, IdentityFields, IdentityInformationProvider, U64BitFlag}; +#[cfg(feature = "runtime-benchmarks")] +const MAX_ADDITIONAL_FIELDS: usize = 2; + /// The fields that we use to identify the owner of an account with. Each corresponds to a field /// in the `IdentityInfo` struct. #[bitflags] @@ -131,11 +134,13 @@ impl + 'static> IdentityInformationProvider for IdentityInf } #[cfg(feature = "runtime-benchmarks")] - fn create_identity_info(num_fields: u32) -> Self { + fn create_identity_info() -> Self { let data = Data::Raw(vec![0; 32].try_into().unwrap()); IdentityInfo { - additional: vec![(data.clone(), data.clone()); num_fields as usize].try_into().unwrap(), + additional: vec![(data.clone(), data.clone()); MAX_ADDITIONAL_FIELDS] + .try_into() + .unwrap(), display: data.clone(), legal: data.clone(), web: data.clone(), diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 48c0f31b77b0..2a5c21428875 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -121,10 +121,6 @@ pub mod pallet { #[pallet::constant] type BasicDeposit: Get>; - /// The amount held on deposit per additional field for a registered identity. - #[pallet::constant] - type FieldDeposit: Get>; - /// The amount held on deposit per encoded byte for a registered identity. #[pallet::constant] type ByteDeposit: Get>; @@ -139,11 +135,6 @@ pub mod pallet { #[pallet::constant] type MaxSubAccounts: Get; - /// 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; - /// Structure holding information about an identity. type IdentityInformation: IdentityInformationProvider; diff --git a/substrate/frame/identity/src/tests.rs b/substrate/frame/identity/src/tests.rs index e059571861d0..d7cb110bedb6 100644 --- a/substrate/frame/identity/src/tests.rs +++ b/substrate/frame/identity/src/tests.rs @@ -106,11 +106,9 @@ impl pallet_identity::Config for Test { type Currency = Balances; type Slashed = (); type BasicDeposit = ConstU64<100>; - type FieldDeposit = ConstU64<100>; type ByteDeposit = ConstU64<10>; type SubAccountDeposit = ConstU64<100>; type MaxSubAccounts = ConstU32<2>; - type MaxAdditionalFields = MaxAdditionalFields; type IdentityInformation = IdentityInfo; type MaxRegistrars = MaxRegistrars; type RegistrarOrigin = EnsureOneOrRoot; diff --git a/substrate/frame/identity/src/types.rs b/substrate/frame/identity/src/types.rs index 2fc5006af3b4..22228bfdb83e 100644 --- a/substrate/frame/identity/src/types.rs +++ b/substrate/frame/identity/src/types.rs @@ -242,7 +242,7 @@ pub trait IdentityInformationProvider: fn has_identity(&self, fields: u64) -> bool; #[cfg(feature = "runtime-benchmarks")] - fn create_identity_info(num_fields: u32) -> Self; + fn create_identity_info() -> Self; } /// Information on an identity along with judgements from registrars. @@ -253,7 +253,7 @@ pub trait IdentityInformationProvider: CloneNoBound, Encode, Eq, MaxEncodedLen, PartialEqNoBound, RuntimeDebugNoBound, TypeInfo, )] #[codec(mel_bound())] -#[scale_info(skip_type_params(MaxJudgements, MaxAdditionalFields))] +#[scale_info(skip_type_params(MaxJudgements))] pub struct Registration< Balance: Encode + Decode + MaxEncodedLen + Copy + Clone + Debug + Eq + PartialEq, MaxJudgements: Get, From e84fdcaaad9c80c6b914bf62a252027a9eb049f9 Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Fri, 27 Oct 2023 13:57:39 +0300 Subject: [PATCH 07/27] Address review comments Signed-off-by: georgepisaltu --- substrate/frame/identity/src/lib.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 2a5c21428875..b1a6f526f1b3 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -100,8 +100,8 @@ type NegativeImbalanceOf = <::Currency as Currency< >>::NegativeImbalance; type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; -/// Maximum size of an identity we can store is 4 MiB. -const IDENTITY_MAX_SIZE: u32 = 4 * 1024 * 1024; +/// Maximum size of an identity we can store is 7 KiB. +const IDENTITY_MAX_SIZE: u32 = 7 * 1024; #[frame_support::pallet] pub mod pallet { @@ -342,7 +342,8 @@ pub mod pallet { let sender = ensure_signed(origin)?; let encoded_byte_size = info.encoded_size() as u32; ensure!(encoded_byte_size <= IDENTITY_MAX_SIZE, Error::::IdentitySize); - let byte_deposit = T::ByteDeposit::get() * >::from(encoded_byte_size); + let byte_deposit = + T::ByteDeposit::get().saturating_mul(>::from(encoded_byte_size)); let mut id = match >::get(&sender) { Some(mut id) => { @@ -359,7 +360,7 @@ pub mod pallet { }; let old_deposit = id.deposit; - id.deposit = T::BasicDeposit::get() + byte_deposit; + id.deposit = T::BasicDeposit::get().saturating_add(byte_deposit); if id.deposit > old_deposit { T::Currency::reserve(&sender, id.deposit - old_deposit)?; } @@ -907,7 +908,7 @@ pub mod pallet { /// - `target`: The account for which to update deposits. /// /// May be called by any signed origin. - #[pallet::call_index(16)] + #[pallet::call_index(15)] #[pallet::weight(T::WeightInfo::poke_deposit())] pub fn poke_deposit(origin: OriginFor, target: AccountIdLookupOf) -> DispatchResult { // No locked check: used for migration. @@ -923,8 +924,8 @@ pub mod pallet { let reg = registration.as_mut().ok_or(Error::::NoIdentity)?; // Calculate what deposit should be let encoded_byte_size = reg.info.encoded_size() as u32; - let byte_deposit = - T::ByteDeposit::get() * >::from(encoded_byte_size); + let byte_deposit = T::ByteDeposit::get() + .saturating_mul(>::from(encoded_byte_size)); let new_id_deposit = T::BasicDeposit::get().saturating_add(byte_deposit); // Update account From 2ff0b51bad7b46f23565b88ab70a221b25a58791 Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Fri, 27 Oct 2023 14:04:59 +0300 Subject: [PATCH 08/27] Add more checked arithmetic Signed-off-by: georgepisaltu --- substrate/frame/identity/src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index b1a6f526f1b3..b42400672a8c 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -407,7 +407,8 @@ pub mod pallet { ); let (old_deposit, old_ids) = >::get(&sender); - let new_deposit = T::SubAccountDeposit::get() * >::from(subs.len() as u32); + let new_deposit = + T::SubAccountDeposit::get().saturating_mul(>::from(subs.len() as u32)); let not_other_sub = subs.iter().filter_map(|i| SuperOf::::get(&i.0)).all(|i| i.0 == sender); @@ -463,7 +464,7 @@ pub mod pallet { let (subs_deposit, sub_ids) = >::take(&sender); let id = >::take(&sender).ok_or(Error::::NotNamed)?; - let deposit = id.total_deposit() + subs_deposit; + let deposit = id.total_deposit().saturating_add(subs_deposit); for sub in sub_ids.iter() { >::remove(sub); } @@ -773,7 +774,7 @@ pub mod pallet { // Grab their deposit (and check that they have one). let (subs_deposit, sub_ids) = >::take(&target); let id = >::take(&target).ok_or(Error::::NotNamed)?; - let deposit = id.total_deposit() + subs_deposit; + let deposit = id.total_deposit().saturating_add(subs_deposit); for sub in sub_ids.iter() { >::remove(sub); } From 09cdec0e3386210bca7d5c5f499409ca34813a1d Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Thu, 26 Oct 2023 20:49:19 +0300 Subject: [PATCH 09/27] Remove explicit `IdentityFields` parameter Signed-off-by: georgepisaltu --- substrate/frame/identity/src/benchmarking.rs | 4 +-- substrate/frame/identity/src/legacy.rs | 4 ++- substrate/frame/identity/src/lib.rs | 29 ++++++++---------- substrate/frame/identity/src/tests.rs | 31 +++++++++++++++++++- substrate/frame/identity/src/types.rs | 20 +++++++++---- 5 files changed, 62 insertions(+), 26 deletions(-) diff --git a/substrate/frame/identity/src/benchmarking.rs b/substrate/frame/identity/src/benchmarking.rs index 8adbc38f80aa..9406e9327bbc 100644 --- a/substrate/frame/identity/src/benchmarking.rs +++ b/substrate/frame/identity/src/benchmarking.rs @@ -54,7 +54,7 @@ fn add_registrars(r: u32) -> Result<(), &'static str> { let fields = IdentityFields( ::IdentityField::all(), ); - Identity::::set_fields(RawOrigin::Signed(registrar.clone()).into(), i, fields)?; + Identity::::set_fields(RawOrigin::Signed(registrar.clone()).into(), i, fields.0.bits())?; } assert_eq!(Registrars::::get().len(), r as usize); @@ -370,7 +370,7 @@ mod benchmarks { ); #[extrinsic_call] - _(RawOrigin::Signed(caller), r, fields); + _(RawOrigin::Signed(caller), r, fields.0.bits()); let updated_registrars = Registrars::::get(); ensure!( diff --git a/substrate/frame/identity/src/legacy.rs b/substrate/frame/identity/src/legacy.rs index 6edbc7a2a116..0ab53e1d8158 100644 --- a/substrate/frame/identity/src/legacy.rs +++ b/substrate/frame/identity/src/legacy.rs @@ -61,7 +61,9 @@ impl TypeInfo for IdentityField { } } -impl U64BitFlag for IdentityField {} +impl U64BitFlag for IdentityField { + type NumericRepresentation = u64; +} /// Information concerning the identity of the controller of an account. /// diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index b42400672a8c..34824b9067cf 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -79,6 +79,8 @@ mod tests; mod types; pub mod weights; +use enumflags2::BitFlags; + use frame_support::{ pallet_prelude::DispatchResult, traits::{BalanceStatus, Currency, Get, OnUnbalanced, ReservableCurrency}, @@ -90,7 +92,7 @@ pub use weights::WeightInfo; pub use pallet::*; pub use types::{ Data, IdentityFields, IdentityInformationProvider, Judgement, RegistrarIndex, RegistrarInfo, - Registration, + Registration, U64BitFlag, }; type BalanceOf = @@ -255,6 +257,8 @@ pub mod pallet { JudgementForDifferentIdentity, /// Error that occurs when there is an issue paying for judgement. JudgementPaymentFailed, + /// Invalid identity fields. + InvalidFields, } #[pallet::event] @@ -660,25 +664,16 @@ pub mod pallet { pub fn set_fields( origin: OriginFor, #[pallet::compact] index: RegistrarIndex, - fields: IdentityFields< - ::IdentityField, - >, + fields: + <::IdentityField as U64BitFlag>::NumericRepresentation, ) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; - let registrars = >::mutate(|rs| -> Result { - rs.get_mut(index as usize) - .and_then(|x| x.as_mut()) - .and_then(|r| { - if r.account == who { - r.fields = fields; - Some(()) - } else { - None - } - }) - .ok_or_else(|| DispatchError::from(Error::::InvalidIndex))?; - Ok(rs.len()) + let registrars = >::mutate(|registrars| -> Result { + let registrar = registrars.get_mut(index as usize).map(|r| r.as_mut()).flatten().filter(|r| r.account == who).ok_or_else(|| DispatchError::from(Error::::InvalidIndex))?; + registrar.fields = IdentityFields(BitFlags::from_bits(fields).map_err(|_| Error::::InvalidFields)?); + + Ok(registrars.len()) })?; Ok(Some(T::WeightInfo::set_fields(registrars as u32)).into()) } diff --git a/substrate/frame/identity/src/tests.rs b/substrate/frame/identity/src/tests.rs index d7cb110bedb6..cf510434c7b3 100644 --- a/substrate/frame/identity/src/tests.rs +++ b/substrate/frame/identity/src/tests.rs @@ -24,6 +24,7 @@ use crate::{ }; use codec::{Decode, Encode}; +use enumflags2::BitFlag; use frame_support::{ assert_noop, assert_ok, ord_parameter_types, parameter_types, traits::{ConstU32, ConstU64, EitherOfDiverse, Get}, @@ -287,13 +288,41 @@ fn trailing_zeros_decodes_into_default_data() { assert_eq!(b, Data::None); } +#[test] +fn adding_registrar_invalid_index() { + 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); + assert_noop!( + Identity::set_fields(RuntimeOrigin::signed(3), 100, fields.0.bits()), + Error::::InvalidIndex + ); + }); +} + +#[test] +fn adding_registrar_invalid_fields() { + new_test_ext().execute_with(|| { + assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3)); + assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10)); + // If all fields can be set, there can be no invalid fields + if <::IdentityInformation as IdentityInformationProvider>::IdentityField::all().bits() != u64::MAX { + assert_noop!( + Identity::set_fields(RuntimeOrigin::signed(3), 0, u64::MAX), + Error::::InvalidFields + ); + } + }); +} + #[test] 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); - assert_ok!(Identity::set_fields(RuntimeOrigin::signed(3), 0, fields)); + assert_ok!(Identity::set_fields(RuntimeOrigin::signed(3), 0, fields.0.bits())); assert_eq!( Identity::registrars(), vec![Some(RegistrarInfo { account: 3, fee: 10, fields })] diff --git a/substrate/frame/identity/src/types.rs b/substrate/frame/identity/src/types.rs index 22228bfdb83e..195ed775258e 100644 --- a/substrate/frame/identity/src/types.rs +++ b/substrate/frame/identity/src/types.rs @@ -17,7 +17,10 @@ use super::*; use codec::{Decode, Encode, MaxEncodedLen}; -use enumflags2::{BitFlag, BitFlags, _internal::RawBitFlags}; +use enumflags2::{ + BitFlag, BitFlags, + _internal::{BitFlagNum, RawBitFlags}, +}; use frame_support::{ traits::{ConstU32, Get}, BoundedVec, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, @@ -32,7 +35,9 @@ use sp_std::{fmt::Debug, iter::once, ops::Add, prelude::*}; /// An identifier for a single name registrar/identity verification service. pub type RegistrarIndex = u32; -pub trait U64BitFlag: BitFlag + RawBitFlags {} +pub trait U64BitFlag: BitFlag + RawBitFlags { + type NumericRepresentation: BitFlagNum + Into + TryFrom + Encode + Decode + TypeInfo; +} /// 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. @@ -337,14 +342,19 @@ where impl Eq for IdentityFields {} impl Encode for IdentityFields { fn using_encoded R>(&self, f: F) -> R { - let bits: u64 = self.0.bits(); + let bits: ::NumericRepresentation = self.0.bits(); bits.using_encoded(f) } } impl Decode for IdentityFields { fn decode(input: &mut I) -> sp_std::result::Result { - let field = u64::decode(input)?; - Ok(Self(>::from_bits(field).map_err(|_| "invalid value")?)) + let field = ::NumericRepresentation::decode(input)?; + Ok(Self( + >::from_bits( + field.try_into().map_err(|_| "value couldn't convert to u64")?, + ) + .map_err(|_| "invalid value")?, + )) } } impl TypeInfo From 47ae9b6c7ad0a6cca807b9a613d90963d95dfffb Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Fri, 27 Oct 2023 20:00:20 +0300 Subject: [PATCH 10/27] Fix formatting Signed-off-by: georgepisaltu --- substrate/frame/identity/src/lib.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 34824b9067cf..18b85372d8eb 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -664,17 +664,24 @@ pub mod pallet { pub fn set_fields( origin: OriginFor, #[pallet::compact] index: RegistrarIndex, - fields: - <::IdentityField as U64BitFlag>::NumericRepresentation, + fields: <::IdentityField as U64BitFlag>::NumericRepresentation, ) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; - let registrars = >::mutate(|registrars| -> Result { - let registrar = registrars.get_mut(index as usize).map(|r| r.as_mut()).flatten().filter(|r| r.account == who).ok_or_else(|| DispatchError::from(Error::::InvalidIndex))?; - registrar.fields = IdentityFields(BitFlags::from_bits(fields).map_err(|_| Error::::InvalidFields)?); - - Ok(registrars.len()) - })?; + let registrars = + >::mutate(|registrars| -> Result { + let registrar = registrars + .get_mut(index as usize) + .map(|r| r.as_mut()) + .flatten() + .filter(|r| r.account == who) + .ok_or_else(|| DispatchError::from(Error::::InvalidIndex))?; + registrar.fields = IdentityFields( + BitFlags::from_bits(fields).map_err(|_| Error::::InvalidFields)?, + ); + + Ok(registrars.len()) + })?; Ok(Some(T::WeightInfo::set_fields(registrars as u32)).into()) } From 41b3d81ae1d3e5d8f813b03c4af19698cca1fae4 Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Fri, 27 Oct 2023 20:21:54 +0300 Subject: [PATCH 11/27] Fix clippy Signed-off-by: georgepisaltu --- substrate/frame/identity/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 18b85372d8eb..18c9ba328c74 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -672,8 +672,7 @@ pub mod pallet { >::mutate(|registrars| -> Result { let registrar = registrars .get_mut(index as usize) - .map(|r| r.as_mut()) - .flatten() + .and_then(|r| r.as_mut()) .filter(|r| r.account == who) .ok_or_else(|| DispatchError::from(Error::::InvalidIndex))?; registrar.fields = IdentityFields( From d0d23a2cc0ce7acd566061ed76d88af7bc721ccc Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Tue, 31 Oct 2023 13:49:46 +0200 Subject: [PATCH 12/27] Remove `poke_deposit` extrinsic Signed-off-by: georgepisaltu --- .../rococo/src/weights/pallet_identity.rs | 16 --- .../westend/src/weights/pallet_identity.rs | 16 --- substrate/frame/identity/src/benchmarking.rs | 49 ------- substrate/frame/identity/src/lib.rs | 76 ---------- substrate/frame/identity/src/tests.rs | 132 ------------------ substrate/frame/identity/src/weights.rs | 33 ----- 6 files changed, 322 deletions(-) diff --git a/polkadot/runtime/rococo/src/weights/pallet_identity.rs b/polkadot/runtime/rococo/src/weights/pallet_identity.rs index c2a456738a85..e8c25269ac37 100644 --- a/polkadot/runtime/rococo/src/weights/pallet_identity.rs +++ b/polkadot/runtime/rococo/src/weights/pallet_identity.rs @@ -334,20 +334,4 @@ impl pallet_identity::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) } - /// Storage: `Identity::IdentityOf` (r:1 w:1) - /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7538), added: 10013, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - /// Storage: `Identity::SubsOf` (r:1 w:1) - /// Proof: `Identity::SubsOf` (`max_values`: None, `max_size`: Some(3258), added: 5733, mode: `MaxEncodedLen`) - fn poke_deposit() -> Weight { - // Proof Size summary in bytes: - // Measured: `628` - // Estimated: `11003` - // Minimum execution time: 525_039_000 picoseconds. - Weight::from_parts(554_552_000, 0) - .saturating_add(Weight::from_parts(0, 11003)) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(3)) - } } diff --git a/polkadot/runtime/westend/src/weights/pallet_identity.rs b/polkadot/runtime/westend/src/weights/pallet_identity.rs index 8e8c56d48031..dea631b9316b 100644 --- a/polkadot/runtime/westend/src/weights/pallet_identity.rs +++ b/polkadot/runtime/westend/src/weights/pallet_identity.rs @@ -338,20 +338,4 @@ impl pallet_identity::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) } - /// Storage: `Identity::IdentityOf` (r:1 w:1) - /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7538), added: 10013, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - /// Storage: `Identity::SubsOf` (r:1 w:1) - /// Proof: `Identity::SubsOf` (`max_values`: None, `max_size`: Some(3258), added: 5733, mode: `MaxEncodedLen`) - fn poke_deposit() -> Weight { - // Proof Size summary in bytes: - // Measured: `628` - // Estimated: `11003` - // Minimum execution time: 525_039_000 picoseconds. - Weight::from_parts(554_552_000, 0) - .saturating_add(Weight::from_parts(0, 11003)) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(3)) - } } diff --git a/substrate/frame/identity/src/benchmarking.rs b/substrate/frame/identity/src/benchmarking.rs index 9406e9327bbc..44606a9fa1fc 100644 --- a/substrate/frame/identity/src/benchmarking.rs +++ b/substrate/frame/identity/src/benchmarking.rs @@ -22,7 +22,6 @@ use super::*; use crate::Pallet as Identity; -use codec::Encode; use enumflags2::BitFlag; use frame_benchmarking::{ account, impl_benchmark_test_suite, v2::*, whitelisted_caller, BenchmarkError, @@ -30,7 +29,6 @@ use frame_benchmarking::{ use frame_support::{ ensure, traits::{EnsureOrigin, Get}, - BoundedVec, }; use frame_system::RawOrigin; use sp_runtime::traits::Bounded; @@ -531,52 +529,5 @@ mod benchmarks { Ok(()) } - #[benchmark] - fn poke_deposit() -> Result<(), BenchmarkError> { - let caller: T::AccountId = whitelisted_caller(); - let target: T::AccountId = account("target", 0, SEED); - let target_lookup = T::Lookup::unlookup(target.clone()); - let _ = T::Currency::make_free_balance_be(&target, BalanceOf::::max_value()); - - // insert identity into storage with zero deposit - let id = T::IdentityInformation::create_identity_info(); - IdentityOf::::insert( - &target, - Registration { - judgements: BoundedVec::default(), - deposit: Zero::zero(), - info: id.clone(), - }, - ); - - // insert subs into storage with zero deposit - let sub_account = account("sub", 0, SEED); - let subs = BoundedVec::<_, T::MaxSubAccounts>::try_from(vec![sub_account]).unwrap(); - SubsOf::::insert::< - &T::AccountId, - (BalanceOf, BoundedVec), - >(&target, (Zero::zero(), subs)); - - // expected deposits - let expected_id_deposit = T::ByteDeposit::get() - .saturating_mul(id.encoded_size().try_into().unwrap_or_default()) - .saturating_add(T::BasicDeposit::get()); - let expected_sub_deposit = T::SubAccountDeposit::get(); // only 1 - - #[extrinsic_call] - _(RawOrigin::Signed(caller), target_lookup); - - assert_last_event::( - Event::::DepositUpdated { - who: target, - identity: expected_id_deposit, - subs: expected_sub_deposit, - } - .into(), - ); - - Ok(()) - } - impl_benchmark_test_suite!(Identity, crate::tests::new_test_ext(), crate::tests::Test); } diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 18c9ba328c74..2ea0f6d84070 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -285,9 +285,6 @@ pub mod pallet { /// A sub-identity was cleared, and the given deposit repatriated from the /// main identity account to the sub-identity account. SubIdentityRevoked { sub: T::AccountId, main: T::AccountId, deposit: BalanceOf }, - /// The deposits held for `who` were updated. `identity` is the new deposit held for - /// identity info, and `subs` is the new deposit held for the sub-accounts. - DepositUpdated { who: T::AccountId, identity: BalanceOf, subs: BalanceOf }, } #[pallet::call] @@ -903,59 +900,6 @@ pub mod pallet { }); Ok(()) } - - /// Update the deposits held by `target` for its identity info. - /// - /// Parameters: - /// - `target`: The account for which to update deposits. - /// - /// May be called by any signed origin. - #[pallet::call_index(15)] - #[pallet::weight(T::WeightInfo::poke_deposit())] - pub fn poke_deposit(origin: OriginFor, target: AccountIdLookupOf) -> DispatchResult { - // No locked check: used for migration. - // anyone or root (so that the system can call it for identity migration) - let _ = ensure_signed_or_root(origin)?; - let target = T::Lookup::lookup(target)?; - - // Identity Deposit - ensure!(IdentityOf::::contains_key(&target), Error::::NoIdentity); - let new_id_deposit = IdentityOf::::try_mutate( - &target, - |registration| -> Result, DispatchError> { - let reg = registration.as_mut().ok_or(Error::::NoIdentity)?; - // Calculate what deposit should be - let encoded_byte_size = reg.info.encoded_size() as u32; - let byte_deposit = T::ByteDeposit::get() - .saturating_mul(>::from(encoded_byte_size)); - let new_id_deposit = T::BasicDeposit::get().saturating_add(byte_deposit); - - // Update account - Self::rejig_deposit(&target, reg.deposit, new_id_deposit)?; - - reg.deposit = new_id_deposit; - Ok(new_id_deposit) - }, - )?; - - // Subs Deposit - let new_subs_deposit = SubsOf::::try_mutate( - &target, - |(current_subs_deposit, subs_of)| -> Result, DispatchError> { - let new_subs_deposit = Self::subs_deposit(subs_of.len() as u32); - Self::rejig_deposit(&target, *current_subs_deposit, new_subs_deposit)?; - *current_subs_deposit = new_subs_deposit; - Ok(new_subs_deposit) - }, - )?; - - Self::deposit_event(Event::DepositUpdated { - who: target, - identity: new_id_deposit, - subs: new_subs_deposit, - }); - Ok(()) - } } } @@ -974,24 +918,4 @@ impl Pallet { IdentityOf::::get(who) .map_or(false, |registration| (registration.info.has_identity(fields))) } - - /// Calculate the deposit required for a number of `sub` accounts. - fn subs_deposit(subs: u32) -> BalanceOf { - T::SubAccountDeposit::get().saturating_mul(>::from(subs)) - } - - /// Take the `current` deposit that `who` is holding, and update it to a `new` one. - fn rejig_deposit( - who: &T::AccountId, - current: BalanceOf, - new: BalanceOf, - ) -> DispatchResult { - if new > current { - T::Currency::reserve(who, new - current)?; - } else if new < current { - let err_amount = T::Currency::unreserve(who, current - new); - debug_assert!(err_amount.is_zero()); - } - Ok(()) - } } diff --git a/substrate/frame/identity/src/tests.rs b/substrate/frame/identity/src/tests.rs index cf510434c7b3..06135a3d2ae0 100644 --- a/substrate/frame/identity/src/tests.rs +++ b/substrate/frame/identity/src/tests.rs @@ -731,135 +731,3 @@ fn test_has_identity() { )); }); } - -#[test] -fn poke_deposit_increase_works() { - new_test_ext().execute_with(|| { - let ten = ten(); - let id_deposit = id_deposit(&ten); - let sub_deposit: u64 = <::SubAccountDeposit as Get>::get(); - // Set a custom registration with 0 deposit - IdentityOf::::insert( - &10, - Registration { - judgements: BoundedVec::default(), - deposit: Zero::zero(), - info: ten.clone(), - }, - ); - assert!(Identity::identity(10).is_some()); - // Set a sub with zero deposit - SubsOf::::insert::<&u64, (u64, BoundedVec>)>( - &10, - (0, vec![20].try_into().unwrap()), - ); - SuperOf::::insert(&20, (&10, Data::Raw(vec![1; 1].try_into().unwrap()))); - // Balance is free - assert_eq!(Balances::free_balance(10), 1000); - - // Poke - assert_ok!(Identity::poke_deposit(RuntimeOrigin::signed(1), 10)); - - // Free balance reduced by the identity deposit and the deposit for one sub - assert_eq!(Balances::free_balance(10), 1000 - id_deposit - sub_deposit); - // New registration deposit is now `id_deposit` - assert_eq!( - Identity::identity(&10), - Some(Registration { - judgements: BoundedVec::default(), - deposit: id_deposit, - info: ten - }) - ); - // New subs deposit is `sub_deposit` - assert_eq!(Identity::subs_of(10), (sub_deposit, vec![20].try_into().unwrap())); - }); -} - -#[test] -fn poke_deposit_decrease_works() { - new_test_ext().execute_with(|| { - let ten = ten(); - let id_deposit = id_deposit(&ten); - let sub_deposit: u64 = <::SubAccountDeposit as Get>::get(); - let inflated_sub_deposit = sub_deposit * 10; - SubsOf::::insert::<&u64, (u64, BoundedVec>)>( - &10, - (inflated_sub_deposit, vec![20].try_into().unwrap()), - ); - SuperOf::::insert(&20, (&10, Data::Raw(vec![1; 1].try_into().unwrap()))); - // Set a custom registration with some inflated deposit - let inflated_id_deposit = id_deposit * 10; - IdentityOf::::insert( - &10, - Registration { - judgements: BoundedVec::default(), - deposit: inflated_id_deposit, - info: ten.clone(), - }, - ); - assert!(Identity::identity(10).is_some()); - // Balance is untouched - assert_eq!(Balances::free_balance(10), 1000); - // Simulate the deposits - Balances::make_free_balance_be(&10, 1000 + inflated_id_deposit + inflated_sub_deposit); - assert_ok!(Balances::reserve(&10, inflated_id_deposit + inflated_sub_deposit)); - - // Poke - assert_ok!(Identity::poke_deposit(RuntimeOrigin::signed(1), 10)); - - // Free balance increased by the difference between the inflated deposits and the actual - // deposits - assert_eq!( - Balances::free_balance(10), - 1000 + (inflated_id_deposit - id_deposit) + (inflated_sub_deposit - sub_deposit) - ); - assert_eq!(Balances::reserved_balance(10), id_deposit + sub_deposit); - // New registration deposit is now `id_deposit` - assert_eq!( - Identity::identity(&10), - Some(Registration { - judgements: BoundedVec::default(), - deposit: id_deposit, - info: ten - }) - ); - // New subs deposit is `sub_deposit` - assert_eq!(Identity::subs_of(10), (sub_deposit, vec![20].try_into().unwrap())); - }); -} - -#[test] -#[should_panic] -fn poke_deposit_decrease_insufficient_reserved() { - new_test_ext().execute_with(|| { - let ten = ten(); - let id_deposit = id_deposit(&ten); - let sub_deposit: u64 = <::SubAccountDeposit as Get>::get(); - let inflated_sub_deposit = sub_deposit * 10; - SubsOf::::insert::<&u64, (u64, BoundedVec>)>( - &10, - (inflated_sub_deposit, vec![20].try_into().unwrap()), - ); - SuperOf::::insert(&20, (&10, Data::Raw(vec![1; 1].try_into().unwrap()))); - // Set a custom registration with some inflated deposit - let inflated_id_deposit = id_deposit * 10; - IdentityOf::::insert( - &10, - Registration { - judgements: BoundedVec::default(), - deposit: inflated_id_deposit, - info: ten.clone(), - }, - ); - assert!(Identity::identity(10).is_some()); - // Balance is untouched - assert_eq!(Balances::free_balance(10), 1000); - // Ensure the reserved amount is 0 so that `unreserve`` will not succeed - assert_eq!(Balances::free_balance(10), 1000); - - // Poke - this should panic in the test because of a `debug_assert` that the entire deposit - // is successfully unreserved - let _ = Identity::poke_deposit(RuntimeOrigin::signed(1), 10); - }); -} diff --git a/substrate/frame/identity/src/weights.rs b/substrate/frame/identity/src/weights.rs index 3f03d2c2a4e6..95898e6c6cdf 100644 --- a/substrate/frame/identity/src/weights.rs +++ b/substrate/frame/identity/src/weights.rs @@ -68,7 +68,6 @@ pub trait WeightInfo { fn rename_sub(s: u32, ) -> Weight; fn remove_sub(s: u32, ) -> Weight; fn quit_sub(s: u32, ) -> Weight; - fn poke_deposit() -> Weight; } /// Weights for pallet_identity using the Substrate node and recommended hardware. @@ -346,22 +345,6 @@ impl WeightInfo for SubstrateWeight { .saturating_add(T::DbWeight::get().reads(3_u64)) .saturating_add(T::DbWeight::get().writes(2_u64)) } - /// Storage: `Identity::IdentityOf` (r:1 w:1) - /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7538), added: 10013, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - /// Storage: `Identity::SubsOf` (r:1 w:1) - /// Proof: `Identity::SubsOf` (`max_values`: None, `max_size`: Some(3258), added: 5733, mode: `MaxEncodedLen`) - fn poke_deposit() -> Weight { - // Proof Size summary in bytes: - // Measured: `628` - // Estimated: `11003` - // Minimum execution time: 525_039_000 picoseconds. - Weight::from_parts(554_552_000, 0) - .saturating_add(Weight::from_parts(0, 11003)) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(3)) - } } // For backwards compatibility and tests @@ -638,20 +621,4 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(3_u64)) .saturating_add(RocksDbWeight::get().writes(2_u64)) } - /// Storage: `Identity::IdentityOf` (r:1 w:1) - /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7538), added: 10013, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - /// Storage: `Identity::SubsOf` (r:1 w:1) - /// Proof: `Identity::SubsOf` (`max_values`: None, `max_size`: Some(3258), added: 5733, mode: `MaxEncodedLen`) - fn poke_deposit() -> Weight { - // Proof Size summary in bytes: - // Measured: `628` - // Estimated: `11003` - // Minimum execution time: 525_039_000 picoseconds. - Weight::from_parts(554_552_000, 0) - .saturating_add(Weight::from_parts(0, 11003)) - .saturating_add(RocksDbWeight::get().reads(3)) - .saturating_add(RocksDbWeight::get().writes(3)) - } } From 07b24e34f59e23cc9043f26250eb11b90a93c30c Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Tue, 31 Oct 2023 19:00:07 +0200 Subject: [PATCH 13/27] Fix doc comment Signed-off-by: georgepisaltu --- substrate/frame/identity/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 2ea0f6d84070..3237475afc36 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -243,7 +243,7 @@ pub mod pallet { InvalidTarget, /// Too many additional fields. TooManyFields, - /// Identity encoded size is too high. + /// Identity encoded size is too large. IdentitySize, /// Maximum amount of registrars reached. Cannot add any more. TooManyRegistrars, From f84b0bfe18d4223377617b7a36e3d0cbae436c78 Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Wed, 1 Nov 2023 16:41:20 +0200 Subject: [PATCH 14/27] Base substrate node basic deposit on byte size Signed-off-by: georgepisaltu --- substrate/bin/node/runtime/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 4032f4226c33..64f3516e17c1 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -1459,7 +1459,9 @@ impl pallet_grandpa::Config for Runtime { } parameter_types! { - pub const BasicDeposit: Balance = 10 * DOLLARS; // 258 bytes on-chain + // difference of 26 bytes on-chain for the registration and 9 bytes on-chain for the identity + // information, already accounted for by the byte deposit + pub const BasicDeposit: Balance = deposit(1, 17); pub const ByteDeposit: Balance = deposit(0, 1); pub const SubAccountDeposit: Balance = 2 * DOLLARS; // 53 bytes on-chain pub const MaxSubAccounts: u32 = 100; From 70abd0dc98ceb0d49d16852e00e49db084b05580 Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Wed, 1 Nov 2023 19:28:58 +0200 Subject: [PATCH 15/27] Use correct max additional fields in legacy Signed-off-by: georgepisaltu --- substrate/frame/identity/src/legacy.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/substrate/frame/identity/src/legacy.rs b/substrate/frame/identity/src/legacy.rs index 0ab53e1d8158..34a9a0c74218 100644 --- a/substrate/frame/identity/src/legacy.rs +++ b/substrate/frame/identity/src/legacy.rs @@ -24,9 +24,6 @@ use sp_std::prelude::*; use crate::types::{Data, IdentityFields, IdentityInformationProvider, U64BitFlag}; -#[cfg(feature = "runtime-benchmarks")] -const MAX_ADDITIONAL_FIELDS: usize = 2; - /// The fields that we use to identify the owner of an account with. Each corresponds to a field /// in the `IdentityInfo` struct. #[bitflags] @@ -140,7 +137,7 @@ impl + 'static> IdentityInformationProvider for IdentityInf let data = Data::Raw(vec![0; 32].try_into().unwrap()); IdentityInfo { - additional: vec![(data.clone(), data.clone()); MAX_ADDITIONAL_FIELDS] + additional: vec![(data.clone(), data.clone()); FieldLimit::get().try_into().unwrap()] .try_into() .unwrap(), display: data.clone(), From d92dfff935d1a11f8439f86f47bdee15774ecb55 Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Wed, 1 Nov 2023 19:37:17 +0200 Subject: [PATCH 16/27] Add integrity test for identity max size Signed-off-by: georgepisaltu --- substrate/frame/identity/src/lib.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 3237475afc36..05420f2e2677 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -103,7 +103,7 @@ type NegativeImbalanceOf = <::Currency as Currency< type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; /// Maximum size of an identity we can store is 7 KiB. -const IDENTITY_MAX_SIZE: u32 = 7 * 1024; +pub const IDENTITY_MAX_SIZE: u32 = 7 * 1024; #[frame_support::pallet] pub mod pallet { @@ -287,6 +287,16 @@ pub mod pallet { SubIdentityRevoked { sub: T::AccountId, main: T::AccountId, deposit: BalanceOf }, } + #[pallet::hooks] + impl Hooks> for Pallet { + fn integrity_test() { + assert!( + T::IdentityInformation::max_encoded_len() <= IDENTITY_MAX_SIZE as usize, + "maximum encoded size of an identity is 7 KiB" + ); + } + } + #[pallet::call] /// Identity pallet declaration. impl Pallet { From 4d742cb391f10b351b4c35c4a8514159bc8587d3 Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Thu, 2 Nov 2023 19:55:08 +0200 Subject: [PATCH 17/27] Refine identity field impl Signed-off-by: georgepisaltu --- substrate/frame/identity/src/benchmarking.rs | 14 +--- substrate/frame/identity/src/legacy.rs | 24 +++--- substrate/frame/identity/src/lib.rs | 16 ++-- substrate/frame/identity/src/tests.rs | 63 ++++++--------- substrate/frame/identity/src/types.rs | 82 ++++---------------- 5 files changed, 63 insertions(+), 136 deletions(-) diff --git a/substrate/frame/identity/src/benchmarking.rs b/substrate/frame/identity/src/benchmarking.rs index 44606a9fa1fc..3d976bd6c881 100644 --- a/substrate/frame/identity/src/benchmarking.rs +++ b/substrate/frame/identity/src/benchmarking.rs @@ -22,7 +22,6 @@ use super::*; use crate::Pallet as Identity; -use enumflags2::BitFlag; use frame_benchmarking::{ account, impl_benchmark_test_suite, v2::*, whitelisted_caller, BenchmarkError, }; @@ -49,10 +48,8 @@ fn add_registrars(r: u32) -> Result<(), &'static str> { .expect("RegistrarOrigin has no successful origin required for the benchmark"); Identity::::add_registrar(registrar_origin, registrar_lookup)?; Identity::::set_fee(RawOrigin::Signed(registrar.clone()).into(), i, 10u32.into())?; - let fields = IdentityFields( - ::IdentityField::all(), - ); - Identity::::set_fields(RawOrigin::Signed(registrar.clone()).into(), i, fields.0.bits())?; + let fields = T::IdentityInformation::all_fields(); + Identity::::set_fields(RawOrigin::Signed(registrar.clone()).into(), i, fields)?; } assert_eq!(Registrars::::get().len(), r as usize); @@ -357,18 +354,15 @@ mod benchmarks { .expect("RegistrarOrigin has no successful origin required for the benchmark"); Identity::::add_registrar(registrar_origin, caller_lookup)?; - let fields = IdentityFields( - ::IdentityField::all(), - ); - let registrars = Registrars::::get(); ensure!( registrars[r as usize].as_ref().unwrap().fields == Default::default(), "fields already set." ); + let fields = T::IdentityInformation::all_fields(); #[extrinsic_call] - _(RawOrigin::Signed(caller), r, fields.0.bits()); + _(RawOrigin::Signed(caller), r, fields); let updated_registrars = Registrars::::get(); ensure!( diff --git a/substrate/frame/identity/src/legacy.rs b/substrate/frame/identity/src/legacy.rs index 34a9a0c74218..4091ee763adb 100644 --- a/substrate/frame/identity/src/legacy.rs +++ b/substrate/frame/identity/src/legacy.rs @@ -16,13 +16,15 @@ // limitations under the License. use codec::{Decode, Encode, MaxEncodedLen}; +#[cfg(feature = "runtime-benchmarks")] +use enumflags2::BitFlag; use enumflags2::{bitflags, BitFlags}; use frame_support::{traits::Get, CloneNoBound, EqNoBound, PartialEqNoBound, RuntimeDebugNoBound}; use scale_info::{build::Variants, Path, Type, TypeInfo}; use sp_runtime::{BoundedVec, RuntimeDebug}; use sp_std::prelude::*; -use crate::types::{Data, IdentityFields, IdentityInformationProvider, U64BitFlag}; +use crate::types::{Data, IdentityInformationProvider}; /// The fields that we use to identify the owner of an account with. Each corresponds to a field /// in the `IdentityInfo` struct. @@ -58,10 +60,6 @@ impl TypeInfo for IdentityField { } } -impl U64BitFlag for IdentityField { - type NumericRepresentation = u64; -} - /// 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 @@ -126,10 +124,10 @@ pub struct IdentityInfo> { } impl + 'static> IdentityInformationProvider for IdentityInfo { - type IdentityField = IdentityField; + type IdentityField = u64; - fn has_identity(&self, fields: u64) -> bool { - self.fields().0.bits() & fields == fields + fn has_identity(&self, fields: Self::IdentityField) -> bool { + self.fields().bits() & fields == fields } #[cfg(feature = "runtime-benchmarks")] @@ -150,11 +148,15 @@ impl + 'static> IdentityInformationProvider for IdentityInf twitter: data, } } + + #[cfg(feature = "runtime-benchmarks")] + fn all_fields() -> Self::IdentityField { + IdentityField::all().bits() + } } impl> IdentityInfo { - #[allow(unused)] - pub(crate) fn fields(&self) -> IdentityFields { + pub(crate) fn fields(&self) -> BitFlags { let mut res = >::empty(); if !self.display.is_none() { res.insert(IdentityField::Display); @@ -180,6 +182,6 @@ impl> IdentityInfo { if !self.twitter.is_none() { res.insert(IdentityField::Twitter); } - IdentityFields(res) + res } } diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 05420f2e2677..d84862fbb04e 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -79,8 +79,6 @@ mod tests; mod types; pub mod weights; -use enumflags2::BitFlags; - use frame_support::{ pallet_prelude::DispatchResult, traits::{BalanceStatus, Currency, Get, OnUnbalanced, ReservableCurrency}, @@ -91,8 +89,7 @@ pub use weights::WeightInfo; pub use pallet::*; pub use types::{ - Data, IdentityFields, IdentityInformationProvider, Judgement, RegistrarIndex, RegistrarInfo, - Registration, U64BitFlag, + Data, IdentityInformationProvider, Judgement, RegistrarIndex, RegistrarInfo, Registration, }; type BalanceOf = @@ -671,7 +668,7 @@ pub mod pallet { pub fn set_fields( origin: OriginFor, #[pallet::compact] index: RegistrarIndex, - fields: <::IdentityField as U64BitFlag>::NumericRepresentation, + fields: ::IdentityField, ) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; @@ -682,9 +679,7 @@ pub mod pallet { .and_then(|r| r.as_mut()) .filter(|r| r.account == who) .ok_or_else(|| DispatchError::from(Error::::InvalidIndex))?; - registrar.fields = IdentityFields( - BitFlags::from_bits(fields).map_err(|_| Error::::InvalidFields)?, - ); + registrar.fields = fields; Ok(registrars.len()) })?; @@ -924,7 +919,10 @@ impl Pallet { } /// Check if the account has corresponding identity information by the identity field. - pub fn has_identity(who: &T::AccountId, fields: u64) -> bool { + pub fn has_identity( + who: &T::AccountId, + fields: ::IdentityField, + ) -> bool { IdentityOf::::get(who) .map_or(false, |registration| (registration.info.has_identity(fields))) } diff --git a/substrate/frame/identity/src/tests.rs b/substrate/frame/identity/src/tests.rs index 06135a3d2ae0..71192ea65a8c 100644 --- a/substrate/frame/identity/src/tests.rs +++ b/substrate/frame/identity/src/tests.rs @@ -24,7 +24,6 @@ use crate::{ }; use codec::{Decode, Encode}; -use enumflags2::BitFlag; use frame_support::{ assert_noop, assert_ok, ord_parameter_types, parameter_types, traits::{ConstU32, ConstU64, EitherOfDiverse, Get}, @@ -162,27 +161,24 @@ fn identity_fields_repr_works() { assert_eq!(IdentityField::Image as u64, 1 << 6); assert_eq!(IdentityField::Twitter as u64, 1 << 7); - let fields = IdentityFields( - IdentityField::Legal | - IdentityField::Web | - IdentityField::Riot | - IdentityField::PgpFingerprint | - IdentityField::Twitter, - ); - - assert!(!fields.0.contains(IdentityField::Display)); - assert!(fields.0.contains(IdentityField::Legal)); - assert!(fields.0.contains(IdentityField::Web)); - assert!(fields.0.contains(IdentityField::Riot)); - assert!(!fields.0.contains(IdentityField::Email)); - assert!(fields.0.contains(IdentityField::PgpFingerprint)); - assert!(!fields.0.contains(IdentityField::Image)); - assert!(fields.0.contains(IdentityField::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. + let fields = IdentityField::Legal | + IdentityField::Web | + IdentityField::Riot | + IdentityField::PgpFingerprint | + IdentityField::Twitter; + + assert!(!fields.contains(IdentityField::Display)); + assert!(fields.contains(IdentityField::Legal)); + assert!(fields.contains(IdentityField::Web)); + assert!(fields.contains(IdentityField::Riot)); + assert!(!fields.contains(IdentityField::Email)); + assert!(fields.contains(IdentityField::PgpFingerprint)); + assert!(!fields.contains(IdentityField::Image)); + assert!(fields.contains(IdentityField::Twitter)); + + // Ensure that the `u64` representation matches what we expect. assert_eq!( - fields.0.bits(), + fields.bits(), 0b00000000_00000000_00000000_00000000_00000000_00000000_00000000_10101110 ); } @@ -293,39 +289,24 @@ fn adding_registrar_invalid_index() { 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 = IdentityField::Display | IdentityField::Legal; assert_noop!( - Identity::set_fields(RuntimeOrigin::signed(3), 100, fields.0.bits()), + Identity::set_fields(RuntimeOrigin::signed(3), 100, fields.bits()), Error::::InvalidIndex ); }); } -#[test] -fn adding_registrar_invalid_fields() { - new_test_ext().execute_with(|| { - assert_ok!(Identity::add_registrar(RuntimeOrigin::signed(1), 3)); - assert_ok!(Identity::set_fee(RuntimeOrigin::signed(3), 0, 10)); - // If all fields can be set, there can be no invalid fields - if <::IdentityInformation as IdentityInformationProvider>::IdentityField::all().bits() != u64::MAX { - assert_noop!( - Identity::set_fields(RuntimeOrigin::signed(3), 0, u64::MAX), - Error::::InvalidFields - ); - } - }); -} - #[test] 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); - assert_ok!(Identity::set_fields(RuntimeOrigin::signed(3), 0, fields.0.bits())); + let fields = IdentityField::Display | IdentityField::Legal; + assert_ok!(Identity::set_fields(RuntimeOrigin::signed(3), 0, fields.bits())); assert_eq!( Identity::registrars(), - vec![Some(RegistrarInfo { account: 3, fee: 10, fields })] + vec![Some(RegistrarInfo { account: 3, fee: 10, fields: fields.bits() })] ); }); } diff --git a/substrate/frame/identity/src/types.rs b/substrate/frame/identity/src/types.rs index 195ed775258e..8a4bd9f86f02 100644 --- a/substrate/frame/identity/src/types.rs +++ b/substrate/frame/identity/src/types.rs @@ -17,17 +17,13 @@ use super::*; use codec::{Decode, Encode, MaxEncodedLen}; -use enumflags2::{ - BitFlag, BitFlags, - _internal::{BitFlagNum, RawBitFlags}, -}; use frame_support::{ traits::{ConstU32, Get}, BoundedVec, CloneNoBound, PartialEqNoBound, RuntimeDebugNoBound, }; use scale_info::{ build::{Fields, Variants}, - meta_type, Path, Type, TypeInfo, TypeParameter, + Path, Type, TypeInfo, }; use sp_runtime::{traits::Zero, RuntimeDebug}; use sp_std::{fmt::Debug, iter::once, ops::Add, prelude::*}; @@ -35,10 +31,6 @@ use sp_std::{fmt::Debug, iter::once, ops::Add, prelude::*}; /// An identifier for a single name registrar/identity verification service. pub type RegistrarIndex = u32; -pub trait U64BitFlag: BitFlag + RawBitFlags { - type NumericRepresentation: BitFlagNum + Into + TryFrom + Encode + Decode + TypeInfo; -} - /// 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. /// @@ -239,15 +231,25 @@ impl bool; + fn has_identity(&self, fields: Self::IdentityField) -> bool; #[cfg(feature = "runtime-benchmarks")] fn create_identity_info() -> Self; + + #[cfg(feature = "runtime-benchmarks")] + fn all_fields() -> Self::IdentityField; } /// Information on an identity along with judgements from registrars. @@ -307,7 +309,7 @@ impl< pub struct RegistrarInfo< Balance: Encode + Decode + Clone + Debug + Eq + PartialEq, AccountId: Encode + Decode + Clone + Debug + Eq + PartialEq, - IdField: Clone + Debug + Eq + PartialEq + TypeInfo + U64BitFlag, + IdField: Encode + Decode + Clone + Debug + Default + Eq + PartialEq + TypeInfo + MaxEncodedLen, > { /// The account of the registrar. pub account: AccountId, @@ -317,57 +319,7 @@ pub struct RegistrarInfo< /// Relevant fields for this registrar. Registrar judgements are limited to attestations on /// these fields. - pub fields: IdentityFields, -} - -/// Wrapper type for `BitFlags` that implements `Codec`. -#[derive(Clone, Copy, PartialEq, RuntimeDebug)] -pub struct IdentityFields(pub BitFlags); - -impl Default for IdentityFields { - fn default() -> Self { - Self(Default::default()) - } -} - -impl MaxEncodedLen for IdentityFields -where - IdentityFields: Encode, -{ - fn max_encoded_len() -> usize { - u64::max_encoded_len() - } -} - -impl Eq for IdentityFields {} -impl Encode for IdentityFields { - fn using_encoded R>(&self, f: F) -> R { - let bits: ::NumericRepresentation = self.0.bits(); - bits.using_encoded(f) - } -} -impl Decode for IdentityFields { - fn decode(input: &mut I) -> sp_std::result::Result { - let field = ::NumericRepresentation::decode(input)?; - Ok(Self( - >::from_bits( - field.try_into().map_err(|_| "value couldn't convert to 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::()))]) - .composite(Fields::unnamed().field(|f| f.ty::().type_name("IdentityField"))) - } + pub fields: IdField, } #[cfg(test)] From 810cbd70fdf748d967c29c2dcc57d0d92342189b Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Thu, 2 Nov 2023 20:24:32 +0200 Subject: [PATCH 18/27] Adapt alliance pallet to new identity impl Signed-off-by: georgepisaltu --- substrate/frame/alliance/src/lib.rs | 25 ++++++++++++++++--------- substrate/frame/alliance/src/mock.rs | 13 +++++++++++-- substrate/frame/alliance/src/tests.rs | 4 ++-- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/substrate/frame/alliance/src/lib.rs b/substrate/frame/alliance/src/lib.rs index 77d8fe3c5b34..edc5b5cffc73 100644 --- a/substrate/frame/alliance/src/lib.rs +++ b/substrate/frame/alliance/src/lib.rs @@ -112,7 +112,6 @@ use frame_support::{ }, weights::Weight, }; -use pallet_identity::legacy::IdentityField; use scale_info::TypeInfo; pub use pallet::*; @@ -135,9 +134,14 @@ type NegativeImbalanceOf = <>::Currency as Currency< /// Interface required for identity verification. pub trait IdentityVerifier { + type IdentityField; + + /// Returns the relevant identities that an account is required to have set. + fn required_identities() -> Self::IdentityField; + /// Function that returns whether an account has an identity registered with the identity /// provider. - fn has_identity(who: &AccountId, fields: u64) -> bool; + fn has_identity(who: &AccountId, fields: Self::IdentityField) -> bool; /// Whether an account has been deemed "good" by the provider. fn has_good_judgement(who: &AccountId) -> bool; @@ -149,7 +153,13 @@ pub trait IdentityVerifier { /// The non-provider. Imposes no restrictions on account identity. impl IdentityVerifier for () { - fn has_identity(_who: &AccountId, _fields: u64) -> bool { + type IdentityField = (); + + fn required_identities() -> Self::IdentityField { + () + } + + fn has_identity(_who: &AccountId, _fields: Self::IdentityField) -> bool { true } @@ -339,7 +349,7 @@ pub mod pallet { /// Balance is insufficient for the required deposit. InsufficientFunds, /// The account's identity does not have display field and website field. - WithoutIdentityDisplayAndWebsite, + WithoutRequiredIdentityFields, /// The account's identity has no good judgement. WithoutGoodIdentityJudgement, /// The proposal hash is not found. @@ -1082,13 +1092,10 @@ impl, I: 'static> Pallet { } fn has_identity(who: &T::AccountId) -> DispatchResult { - const IDENTITY_FIELD_DISPLAY: u64 = IdentityField::Display as u64; - const IDENTITY_FIELD_WEB: u64 = IdentityField::Web as u64; - let judgement = |who: &T::AccountId| -> DispatchResult { ensure!( - T::IdentityVerifier::has_identity(who, IDENTITY_FIELD_DISPLAY | IDENTITY_FIELD_WEB), - Error::::WithoutIdentityDisplayAndWebsite + T::IdentityVerifier::has_identity(who, T::IdentityVerifier::required_identities()), + Error::::WithoutRequiredIdentityFields ); ensure!( T::IdentityVerifier::has_good_judgement(who), diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index 331ea553bbf9..9be3b7ad00f2 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::{legacy::IdentityInfo, Data, Judgement}; +use pallet_identity::{ + legacy::{IdentityField, IdentityInfo}, + Data, IdentityInformationProvider, Judgement, +}; pub use crate as pallet_alliance; @@ -130,7 +133,13 @@ impl pallet_identity::Config for Test { pub struct AllianceIdentityVerifier; impl IdentityVerifier for AllianceIdentityVerifier { - fn has_identity(who: &AccountId, fields: u64) -> bool { + type IdentityField = <::IdentityInformation as IdentityInformationProvider>::IdentityField; + + fn required_identities() -> Self::IdentityField { + (IdentityField::Display | IdentityField::Web).bits() + } + + fn has_identity(who: &AccountId, fields: Self::IdentityField) -> bool { Identity::has_identity(who, fields) } diff --git a/substrate/frame/alliance/src/tests.rs b/substrate/frame/alliance/src/tests.rs index ddf89597e0e4..8011627b237a 100644 --- a/substrate/frame/alliance/src/tests.rs +++ b/substrate/frame/alliance/src/tests.rs @@ -413,7 +413,7 @@ fn join_alliance_works() { #[cfg(not(feature = "runtime-benchmarks"))] assert_noop!( Alliance::join_alliance(RuntimeOrigin::signed(7)), - Error::::WithoutIdentityDisplayAndWebsite + Error::::WithoutRequiredIdentityFields ); }); } @@ -468,7 +468,7 @@ fn nominate_ally_works() { #[cfg(not(feature = "runtime-benchmarks"))] assert_noop!( Alliance::join_alliance(RuntimeOrigin::signed(7)), - Error::::WithoutIdentityDisplayAndWebsite + Error::::WithoutRequiredIdentityFields ); }); } From cf03bae7a5a23cd1d49716308abe4d0680ef57b9 Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Thu, 2 Nov 2023 20:29:26 +0200 Subject: [PATCH 19/27] Rename `IdentityField` to `FieldsBitFlags` Signed-off-by: georgepisaltu --- substrate/frame/alliance/src/lib.rs | 12 ++++++------ substrate/frame/alliance/src/mock.rs | 6 +++--- substrate/frame/identity/src/legacy.rs | 6 +++--- substrate/frame/identity/src/lib.rs | 6 +++--- substrate/frame/identity/src/types.rs | 6 +++--- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/substrate/frame/alliance/src/lib.rs b/substrate/frame/alliance/src/lib.rs index edc5b5cffc73..223c9c88a191 100644 --- a/substrate/frame/alliance/src/lib.rs +++ b/substrate/frame/alliance/src/lib.rs @@ -134,14 +134,14 @@ type NegativeImbalanceOf = <>::Currency as Currency< /// Interface required for identity verification. pub trait IdentityVerifier { - type IdentityField; + type FieldsBitFlags; /// Returns the relevant identities that an account is required to have set. - fn required_identities() -> Self::IdentityField; + fn required_identities() -> Self::FieldsBitFlags; /// Function that returns whether an account has an identity registered with the identity /// provider. - fn has_identity(who: &AccountId, fields: Self::IdentityField) -> bool; + fn has_identity(who: &AccountId, fields: Self::FieldsBitFlags) -> bool; /// Whether an account has been deemed "good" by the provider. fn has_good_judgement(who: &AccountId) -> bool; @@ -153,13 +153,13 @@ pub trait IdentityVerifier { /// The non-provider. Imposes no restrictions on account identity. impl IdentityVerifier for () { - type IdentityField = (); + type FieldsBitFlags = (); - fn required_identities() -> Self::IdentityField { + fn required_identities() -> Self::FieldsBitFlags { () } - fn has_identity(_who: &AccountId, _fields: Self::IdentityField) -> bool { + fn has_identity(_who: &AccountId, _fields: Self::FieldsBitFlags) -> bool { true } diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index 9be3b7ad00f2..1184169dd4a1 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -133,13 +133,13 @@ impl pallet_identity::Config for Test { pub struct AllianceIdentityVerifier; impl IdentityVerifier for AllianceIdentityVerifier { - type IdentityField = <::IdentityInformation as IdentityInformationProvider>::IdentityField; + type FieldsBitFlags = <::IdentityInformation as IdentityInformationProvider>::FieldsBitFlags; - fn required_identities() -> Self::IdentityField { + fn required_identities() -> Self::FieldsBitFlags { (IdentityField::Display | IdentityField::Web).bits() } - fn has_identity(who: &AccountId, fields: Self::IdentityField) -> bool { + fn has_identity(who: &AccountId, fields: Self::FieldsBitFlags) -> bool { Identity::has_identity(who, fields) } diff --git a/substrate/frame/identity/src/legacy.rs b/substrate/frame/identity/src/legacy.rs index 4091ee763adb..fe59ad939fc4 100644 --- a/substrate/frame/identity/src/legacy.rs +++ b/substrate/frame/identity/src/legacy.rs @@ -124,9 +124,9 @@ pub struct IdentityInfo> { } impl + 'static> IdentityInformationProvider for IdentityInfo { - type IdentityField = u64; + type FieldsBitFlags = u64; - fn has_identity(&self, fields: Self::IdentityField) -> bool { + fn has_identity(&self, fields: Self::FieldsBitFlags) -> bool { self.fields().bits() & fields == fields } @@ -150,7 +150,7 @@ impl + 'static> IdentityInformationProvider for IdentityInf } #[cfg(feature = "runtime-benchmarks")] - fn all_fields() -> Self::IdentityField { + fn all_fields() -> Self::FieldsBitFlags { IdentityField::all().bits() } } diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index d84862fbb04e..deb778a0e740 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -206,7 +206,7 @@ pub mod pallet { RegistrarInfo< BalanceOf, T::AccountId, - ::IdentityField, + ::FieldsBitFlags, >, >, T::MaxRegistrars, @@ -668,7 +668,7 @@ pub mod pallet { pub fn set_fields( origin: OriginFor, #[pallet::compact] index: RegistrarIndex, - fields: ::IdentityField, + fields: ::FieldsBitFlags, ) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; @@ -921,7 +921,7 @@ impl Pallet { /// Check if the account has corresponding identity information by the identity field. pub fn has_identity( who: &T::AccountId, - fields: ::IdentityField, + fields: ::FieldsBitFlags, ) -> bool { IdentityOf::::get(who) .map_or(false, |registration| (registration.info.has_identity(fields))) diff --git a/substrate/frame/identity/src/types.rs b/substrate/frame/identity/src/types.rs index 8a4bd9f86f02..22c3f4b68a8d 100644 --- a/substrate/frame/identity/src/types.rs +++ b/substrate/frame/identity/src/types.rs @@ -232,7 +232,7 @@ pub trait IdentityInformationProvider: Encode + Decode + MaxEncodedLen + Clone + Debug + Eq + PartialEq + TypeInfo { /// Type capable of representing all of the fields present in the identity information. - type IdentityField: Encode + type FieldsBitFlags: Encode + Decode + Clone + Debug @@ -243,13 +243,13 @@ pub trait IdentityInformationProvider: + MaxEncodedLen; /// Check if an identity registered information for some given `fields`. - fn has_identity(&self, fields: Self::IdentityField) -> bool; + fn has_identity(&self, fields: Self::FieldsBitFlags) -> bool; #[cfg(feature = "runtime-benchmarks")] fn create_identity_info() -> Self; #[cfg(feature = "runtime-benchmarks")] - fn all_fields() -> Self::IdentityField; + fn all_fields() -> Self::FieldsBitFlags; } /// Information on an identity along with judgements from registrars. From b6f914bc92ac81ec66beae21beca0b1d4e9199ad Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Thu, 2 Nov 2023 20:39:22 +0200 Subject: [PATCH 20/27] Move `MAX_IDENTITY_SIZE` to pallet config Signed-off-by: georgepisaltu --- 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 | 2 ++ substrate/frame/identity/src/lib.rs | 10 +++++++--- substrate/frame/identity/src/tests.rs | 2 ++ 6 files changed, 17 insertions(+), 3 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 257f364dca01..3587ae218fcc 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -599,6 +599,7 @@ parameter_types! { pub const ByteDeposit: Balance = deposit(0, 1); pub const SubAccountDeposit: Balance = 200 * CENTS; // 53 bytes on-chain pub const MaxSubAccounts: u32 = 100; + pub const MaxIdentitySize: u32 = 7 * 1024; // 7 KiB pub const MaxAdditionalFields: u32 = 100; pub const MaxRegistrars: u32 = 20; } @@ -610,6 +611,7 @@ impl pallet_identity::Config for Runtime { type ByteDeposit = ByteDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; + type MaxIdentitySize = MaxIdentitySize; type IdentityInformation = IdentityInfo; type MaxRegistrars = MaxRegistrars; type Slashed = Treasury; diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index ec94973af4f3..827119c01329 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -866,6 +866,7 @@ parameter_types! { pub const ByteDeposit: Balance = deposit(0, 1); pub const SubAccountDeposit: Balance = 200 * CENTS; // 53 bytes on-chain pub const MaxSubAccounts: u32 = 100; + pub const MaxIdentitySize: u32 = 7 * 1024; // 7 KiB pub const MaxAdditionalFields: u32 = 100; pub const MaxRegistrars: u32 = 20; } @@ -878,6 +879,7 @@ impl pallet_identity::Config for Runtime { type ByteDeposit = ByteDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; + type MaxIdentitySize = MaxIdentitySize; type IdentityInformation = IdentityInfo; type MaxRegistrars = MaxRegistrars; type ForceOrigin = EitherOf, GeneralAdmin>; diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 620e89a65e53..a5cbe0de9fa1 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -1465,6 +1465,7 @@ parameter_types! { pub const ByteDeposit: Balance = deposit(0, 1); pub const SubAccountDeposit: Balance = 2 * DOLLARS; // 53 bytes on-chain pub const MaxSubAccounts: u32 = 100; + pub const MaxIdentitySize: u32 = 7 * 1024; // 7 KiB pub const MaxAdditionalFields: u32 = 100; pub const MaxRegistrars: u32 = 20; } @@ -1476,6 +1477,7 @@ impl pallet_identity::Config for Runtime { type ByteDeposit = ByteDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; + type MaxIdentitySize = MaxIdentitySize; type IdentityInformation = IdentityInfo; type MaxRegistrars = MaxRegistrars; type Slashed = Treasury; diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index 1184169dd4a1..bc7a1d642c58 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -103,6 +103,7 @@ parameter_types! { pub const ByteDeposit: u64 = 10; pub const SubAccountDeposit: u64 = 100; pub const MaxSubAccounts: u32 = 2; + pub const MaxIdentitySize: u32 = 7 * 1024; pub const MaxAdditionalFields: u32 = 2; pub const MaxRegistrars: u32 = 20; } @@ -123,6 +124,7 @@ impl pallet_identity::Config for Test { type ByteDeposit = ByteDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; + type MaxIdentitySize = MaxIdentitySize; type IdentityInformation = IdentityInfo; type MaxRegistrars = MaxRegistrars; type Slashed = (); diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index deb778a0e740..a7a9dc5b085d 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -134,6 +134,10 @@ pub mod pallet { #[pallet::constant] type MaxSubAccounts: Get; + /// The maximum encoded size of an identity information. + #[pallet::constant] + type MaxIdentitySize: Get; + /// Structure holding information about an identity. type IdentityInformation: IdentityInformationProvider; @@ -288,8 +292,8 @@ pub mod pallet { impl Hooks> for Pallet { fn integrity_test() { assert!( - T::IdentityInformation::max_encoded_len() <= IDENTITY_MAX_SIZE as usize, - "maximum encoded size of an identity is 7 KiB" + T::IdentityInformation::max_encoded_len() <= T::MaxIdentitySize::get() as usize, + "max encoded size of the identity information is too large" ); } } @@ -349,7 +353,7 @@ pub mod pallet { ) -> DispatchResultWithPostInfo { let sender = ensure_signed(origin)?; let encoded_byte_size = info.encoded_size() as u32; - ensure!(encoded_byte_size <= IDENTITY_MAX_SIZE, Error::::IdentitySize); + ensure!(encoded_byte_size <= T::MaxIdentitySize::get(), Error::::IdentitySize); let byte_deposit = T::ByteDeposit::get().saturating_mul(>::from(encoded_byte_size)); diff --git a/substrate/frame/identity/src/tests.rs b/substrate/frame/identity/src/tests.rs index 71192ea65a8c..f69fde4373f0 100644 --- a/substrate/frame/identity/src/tests.rs +++ b/substrate/frame/identity/src/tests.rs @@ -91,6 +91,7 @@ impl pallet_balances::Config for Test { } parameter_types! { + pub const MaxIdentitySize: u32 = 7 * 1024; pub const MaxAdditionalFields: u32 = 2; pub const MaxRegistrars: u32 = 20; } @@ -109,6 +110,7 @@ impl pallet_identity::Config for Test { type ByteDeposit = ConstU64<10>; type SubAccountDeposit = ConstU64<100>; type MaxSubAccounts = ConstU32<2>; + type MaxIdentitySize = MaxIdentitySize; type IdentityInformation = IdentityInfo; type MaxRegistrars = MaxRegistrars; type RegistrarOrigin = EnsureOneOrRoot; From 7a188537bfe7b2456711278ef8a0a73612e7a339 Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Thu, 2 Nov 2023 21:14:50 +0200 Subject: [PATCH 21/27] Fix substrate-node alliance impl Signed-off-by: georgepisaltu --- substrate/bin/node/runtime/src/impls.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/substrate/bin/node/runtime/src/impls.rs b/substrate/bin/node/runtime/src/impls.rs index 430a1ac2824b..487b0c24ba5f 100644 --- a/substrate/bin/node/runtime/src/impls.rs +++ b/substrate/bin/node/runtime/src/impls.rs @@ -26,6 +26,7 @@ use frame_support::{ }; use pallet_alliance::{IdentityVerifier, ProposalIndex, ProposalProvider}; use pallet_asset_tx_payment::HandleCredit; +use pallet_identity::{legacy::IdentityField, IdentityInformationProvider}; use sp_std::prelude::*; use crate::{ @@ -56,7 +57,14 @@ impl HandleCredit for CreditToBlockAuthor { pub struct AllianceIdentityVerifier; impl IdentityVerifier for AllianceIdentityVerifier { - fn has_identity(who: &AccountId, fields: u64) -> bool { + type FieldsBitFlags = + <::IdentityInformation as IdentityInformationProvider>::FieldsBitFlags; + + fn required_identities() -> Self::FieldsBitFlags { + (IdentityField::Display | IdentityField::Web).bits() + } + + fn has_identity(who: &AccountId, fields: Self::FieldsBitFlags) -> bool { crate::Identity::has_identity(who, fields) } From de4678333f2214fe48307748859f1b16e89cd613 Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Fri, 3 Nov 2023 17:00:07 +0200 Subject: [PATCH 22/27] Collapse alliance required id functions Signed-off-by: georgepisaltu --- substrate/bin/node/runtime/src/impls.rs | 11 ++--------- substrate/frame/alliance/src/lib.rs | 21 +++++---------------- substrate/frame/alliance/src/mock.rs | 12 +++--------- 3 files changed, 10 insertions(+), 34 deletions(-) diff --git a/substrate/bin/node/runtime/src/impls.rs b/substrate/bin/node/runtime/src/impls.rs index 487b0c24ba5f..0f847fd606d6 100644 --- a/substrate/bin/node/runtime/src/impls.rs +++ b/substrate/bin/node/runtime/src/impls.rs @@ -57,15 +57,8 @@ impl HandleCredit for CreditToBlockAuthor { pub struct AllianceIdentityVerifier; impl IdentityVerifier for AllianceIdentityVerifier { - type FieldsBitFlags = - <::IdentityInformation as IdentityInformationProvider>::FieldsBitFlags; - - fn required_identities() -> Self::FieldsBitFlags { - (IdentityField::Display | IdentityField::Web).bits() - } - - fn has_identity(who: &AccountId, fields: Self::FieldsBitFlags) -> bool { - crate::Identity::has_identity(who, fields) + fn has_required_identities(who: &AccountId) -> bool { + crate::Identity::has_identity(who, (IdentityField::Display | IdentityField::Web).bits()) } fn has_good_judgement(who: &AccountId) -> bool { diff --git a/substrate/frame/alliance/src/lib.rs b/substrate/frame/alliance/src/lib.rs index 223c9c88a191..d4703db68dbb 100644 --- a/substrate/frame/alliance/src/lib.rs +++ b/substrate/frame/alliance/src/lib.rs @@ -134,14 +134,9 @@ type NegativeImbalanceOf = <>::Currency as Currency< /// Interface required for identity verification. pub trait IdentityVerifier { - type FieldsBitFlags; - - /// Returns the relevant identities that an account is required to have set. - fn required_identities() -> Self::FieldsBitFlags; - - /// Function that returns whether an account has an identity registered with the identity - /// provider. - fn has_identity(who: &AccountId, fields: Self::FieldsBitFlags) -> bool; + /// Function that returns whether an account has the required identities registered with the + /// identity provider. + fn has_required_identities(who: &AccountId) -> bool; /// Whether an account has been deemed "good" by the provider. fn has_good_judgement(who: &AccountId) -> bool; @@ -153,13 +148,7 @@ pub trait IdentityVerifier { /// The non-provider. Imposes no restrictions on account identity. impl IdentityVerifier for () { - type FieldsBitFlags = (); - - fn required_identities() -> Self::FieldsBitFlags { - () - } - - fn has_identity(_who: &AccountId, _fields: Self::FieldsBitFlags) -> bool { + fn has_required_identities(_who: &AccountId) -> bool { true } @@ -1094,7 +1083,7 @@ impl, I: 'static> Pallet { fn has_identity(who: &T::AccountId) -> DispatchResult { let judgement = |who: &T::AccountId| -> DispatchResult { ensure!( - T::IdentityVerifier::has_identity(who, T::IdentityVerifier::required_identities()), + T::IdentityVerifier::has_required_identities(who), Error::::WithoutRequiredIdentityFields ); ensure!( diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index bc7a1d642c58..9106a1753d92 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -33,7 +33,7 @@ pub use frame_support::{ use frame_system::{EnsureRoot, EnsureSignedBy}; use pallet_identity::{ legacy::{IdentityField, IdentityInfo}, - Data, IdentityInformationProvider, Judgement, + Data, Judgement, }; pub use crate as pallet_alliance; @@ -135,14 +135,8 @@ impl pallet_identity::Config for Test { pub struct AllianceIdentityVerifier; impl IdentityVerifier for AllianceIdentityVerifier { - type FieldsBitFlags = <::IdentityInformation as IdentityInformationProvider>::FieldsBitFlags; - - fn required_identities() -> Self::FieldsBitFlags { - (IdentityField::Display | IdentityField::Web).bits() - } - - fn has_identity(who: &AccountId, fields: Self::FieldsBitFlags) -> bool { - Identity::has_identity(who, fields) + fn has_required_identities(who: &AccountId) -> bool { + Identity::has_identity(who, (IdentityField::Display | IdentityField::Web).bits()) } fn has_good_judgement(who: &AccountId) -> bool { From 8d713cc315dbb53d418cfb4ec1f1c0b0379bc73b Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Fri, 3 Nov 2023 17:10:21 +0200 Subject: [PATCH 23/27] Minor refactoring Signed-off-by: georgepisaltu --- substrate/frame/identity/src/lib.rs | 7 ------- substrate/frame/identity/src/types.rs | 15 +++++---------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index a7a9dc5b085d..e2030489c9a2 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -99,9 +99,6 @@ type NegativeImbalanceOf = <::Currency as Currency< >>::NegativeImbalance; type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; -/// Maximum size of an identity we can store is 7 KiB. -pub const IDENTITY_MAX_SIZE: u32 = 7 * 1024; - #[frame_support::pallet] pub mod pallet { use super::*; @@ -242,8 +239,6 @@ pub mod pallet { InvalidIndex, /// The target is invalid. InvalidTarget, - /// Too many additional fields. - TooManyFields, /// Identity encoded size is too large. IdentitySize, /// Maximum amount of registrars reached. Cannot add any more. @@ -258,8 +253,6 @@ pub mod pallet { JudgementForDifferentIdentity, /// Error that occurs when there is an issue paying for judgement. JudgementPaymentFailed, - /// Invalid identity fields. - InvalidFields, } #[pallet::event] diff --git a/substrate/frame/identity/src/types.rs b/substrate/frame/identity/src/types.rs index 22c3f4b68a8d..e3448277d1e2 100644 --- a/substrate/frame/identity/src/types.rs +++ b/substrate/frame/identity/src/types.rs @@ -25,7 +25,10 @@ use scale_info::{ build::{Fields, Variants}, Path, Type, TypeInfo, }; -use sp_runtime::{traits::Zero, RuntimeDebug}; +use sp_runtime::{ + traits::{Member, Zero}, + RuntimeDebug, +}; use sp_std::{fmt::Debug, iter::once, ops::Add, prelude::*}; /// An identifier for a single name registrar/identity verification service. @@ -232,15 +235,7 @@ pub trait IdentityInformationProvider: Encode + Decode + MaxEncodedLen + Clone + Debug + Eq + PartialEq + TypeInfo { /// Type capable of representing all of the fields present in the identity information. - type FieldsBitFlags: Encode - + Decode - + Clone - + Debug - + Default - + Eq - + PartialEq - + TypeInfo - + MaxEncodedLen; + type FieldsBitFlags: Member + Encode + Decode + MaxEncodedLen + TypeInfo + Default; /// Check if an identity registered information for some given `fields`. fn has_identity(&self, fields: Self::FieldsBitFlags) -> bool; From 63e952e82100456fda8833890d4746c780dce1ea Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Fri, 3 Nov 2023 17:14:35 +0200 Subject: [PATCH 24/27] Remove `MaxIdentitySize` from config Signed-off-by: georgepisaltu --- 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 | 2 -- substrate/frame/identity/src/lib.rs | 17 ----------------- substrate/frame/identity/src/tests.rs | 2 -- 6 files changed, 27 deletions(-) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 3587ae218fcc..257f364dca01 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -599,7 +599,6 @@ parameter_types! { pub const ByteDeposit: Balance = deposit(0, 1); pub const SubAccountDeposit: Balance = 200 * CENTS; // 53 bytes on-chain pub const MaxSubAccounts: u32 = 100; - pub const MaxIdentitySize: u32 = 7 * 1024; // 7 KiB pub const MaxAdditionalFields: u32 = 100; pub const MaxRegistrars: u32 = 20; } @@ -611,7 +610,6 @@ impl pallet_identity::Config for Runtime { type ByteDeposit = ByteDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; - type MaxIdentitySize = MaxIdentitySize; type IdentityInformation = IdentityInfo; type MaxRegistrars = MaxRegistrars; type Slashed = Treasury; diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index 827119c01329..ec94973af4f3 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -866,7 +866,6 @@ parameter_types! { pub const ByteDeposit: Balance = deposit(0, 1); pub const SubAccountDeposit: Balance = 200 * CENTS; // 53 bytes on-chain pub const MaxSubAccounts: u32 = 100; - pub const MaxIdentitySize: u32 = 7 * 1024; // 7 KiB pub const MaxAdditionalFields: u32 = 100; pub const MaxRegistrars: u32 = 20; } @@ -879,7 +878,6 @@ impl pallet_identity::Config for Runtime { type ByteDeposit = ByteDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; - type MaxIdentitySize = MaxIdentitySize; type IdentityInformation = IdentityInfo; type MaxRegistrars = MaxRegistrars; type ForceOrigin = EitherOf, GeneralAdmin>; diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index a5cbe0de9fa1..620e89a65e53 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -1465,7 +1465,6 @@ parameter_types! { pub const ByteDeposit: Balance = deposit(0, 1); pub const SubAccountDeposit: Balance = 2 * DOLLARS; // 53 bytes on-chain pub const MaxSubAccounts: u32 = 100; - pub const MaxIdentitySize: u32 = 7 * 1024; // 7 KiB pub const MaxAdditionalFields: u32 = 100; pub const MaxRegistrars: u32 = 20; } @@ -1477,7 +1476,6 @@ impl pallet_identity::Config for Runtime { type ByteDeposit = ByteDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; - type MaxIdentitySize = MaxIdentitySize; type IdentityInformation = IdentityInfo; type MaxRegistrars = MaxRegistrars; type Slashed = Treasury; diff --git a/substrate/frame/alliance/src/mock.rs b/substrate/frame/alliance/src/mock.rs index 9106a1753d92..ace5214f145f 100644 --- a/substrate/frame/alliance/src/mock.rs +++ b/substrate/frame/alliance/src/mock.rs @@ -103,7 +103,6 @@ parameter_types! { pub const ByteDeposit: u64 = 10; pub const SubAccountDeposit: u64 = 100; pub const MaxSubAccounts: u32 = 2; - pub const MaxIdentitySize: u32 = 7 * 1024; pub const MaxAdditionalFields: u32 = 2; pub const MaxRegistrars: u32 = 20; } @@ -124,7 +123,6 @@ impl pallet_identity::Config for Test { type ByteDeposit = ByteDeposit; type SubAccountDeposit = SubAccountDeposit; type MaxSubAccounts = MaxSubAccounts; - type MaxIdentitySize = MaxIdentitySize; type IdentityInformation = IdentityInfo; type MaxRegistrars = MaxRegistrars; type Slashed = (); diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index e2030489c9a2..3c5b81edff2f 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -131,10 +131,6 @@ pub mod pallet { #[pallet::constant] type MaxSubAccounts: Get; - /// The maximum encoded size of an identity information. - #[pallet::constant] - type MaxIdentitySize: Get; - /// Structure holding information about an identity. type IdentityInformation: IdentityInformationProvider; @@ -239,8 +235,6 @@ pub mod pallet { InvalidIndex, /// The target is invalid. InvalidTarget, - /// Identity encoded size is too large. - IdentitySize, /// Maximum amount of registrars reached. Cannot add any more. TooManyRegistrars, /// Account ID is already named. @@ -281,16 +275,6 @@ pub mod pallet { SubIdentityRevoked { sub: T::AccountId, main: T::AccountId, deposit: BalanceOf }, } - #[pallet::hooks] - impl Hooks> for Pallet { - fn integrity_test() { - assert!( - T::IdentityInformation::max_encoded_len() <= T::MaxIdentitySize::get() as usize, - "max encoded size of the identity information is too large" - ); - } - } - #[pallet::call] /// Identity pallet declaration. impl Pallet { @@ -346,7 +330,6 @@ pub mod pallet { ) -> DispatchResultWithPostInfo { let sender = ensure_signed(origin)?; let encoded_byte_size = info.encoded_size() as u32; - ensure!(encoded_byte_size <= T::MaxIdentitySize::get(), Error::::IdentitySize); let byte_deposit = T::ByteDeposit::get().saturating_mul(>::from(encoded_byte_size)); diff --git a/substrate/frame/identity/src/tests.rs b/substrate/frame/identity/src/tests.rs index f69fde4373f0..71192ea65a8c 100644 --- a/substrate/frame/identity/src/tests.rs +++ b/substrate/frame/identity/src/tests.rs @@ -91,7 +91,6 @@ impl pallet_balances::Config for Test { } parameter_types! { - pub const MaxIdentitySize: u32 = 7 * 1024; pub const MaxAdditionalFields: u32 = 2; pub const MaxRegistrars: u32 = 20; } @@ -110,7 +109,6 @@ impl pallet_identity::Config for Test { type ByteDeposit = ConstU64<10>; type SubAccountDeposit = ConstU64<100>; type MaxSubAccounts = ConstU32<2>; - type MaxIdentitySize = MaxIdentitySize; type IdentityInformation = IdentityInfo; type MaxRegistrars = MaxRegistrars; type RegistrarOrigin = EnsureOneOrRoot; From b01a556b9432f1c1ff9434f8f7fd97610bcbeeea Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Fri, 3 Nov 2023 17:17:49 +0200 Subject: [PATCH 25/27] Improve docs for `IdentityInformationProvider` Signed-off-by: georgepisaltu --- substrate/frame/identity/src/types.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/substrate/frame/identity/src/types.rs b/substrate/frame/identity/src/types.rs index e3448277d1e2..9e952ea8224a 100644 --- a/substrate/frame/identity/src/types.rs +++ b/substrate/frame/identity/src/types.rs @@ -240,9 +240,11 @@ pub trait IdentityInformationProvider: /// Check if an identity registered information for some given `fields`. fn has_identity(&self, fields: Self::FieldsBitFlags) -> bool; + /// Create a basic instance of the identity information. #[cfg(feature = "runtime-benchmarks")] fn create_identity_info() -> Self; + /// The identity information representation for all identity fields enabled. #[cfg(feature = "runtime-benchmarks")] fn all_fields() -> Self::FieldsBitFlags; } From 9d5405ad4a8197032983771ee0788d0004203e12 Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Fri, 3 Nov 2023 17:26:53 +0200 Subject: [PATCH 26/27] Rename `FieldsBitFlags` to `FieldsIdentifier` Signed-off-by: georgepisaltu --- substrate/frame/identity/src/legacy.rs | 6 +++--- substrate/frame/identity/src/lib.rs | 6 +++--- substrate/frame/identity/src/types.rs | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/substrate/frame/identity/src/legacy.rs b/substrate/frame/identity/src/legacy.rs index fe59ad939fc4..a7953f7e1786 100644 --- a/substrate/frame/identity/src/legacy.rs +++ b/substrate/frame/identity/src/legacy.rs @@ -124,9 +124,9 @@ pub struct IdentityInfo> { } impl + 'static> IdentityInformationProvider for IdentityInfo { - type FieldsBitFlags = u64; + type FieldsIdentifier = u64; - fn has_identity(&self, fields: Self::FieldsBitFlags) -> bool { + fn has_identity(&self, fields: Self::FieldsIdentifier) -> bool { self.fields().bits() & fields == fields } @@ -150,7 +150,7 @@ impl + 'static> IdentityInformationProvider for IdentityInf } #[cfg(feature = "runtime-benchmarks")] - fn all_fields() -> Self::FieldsBitFlags { + fn all_fields() -> Self::FieldsIdentifier { IdentityField::all().bits() } } diff --git a/substrate/frame/identity/src/lib.rs b/substrate/frame/identity/src/lib.rs index 3c5b81edff2f..264ea3ddb41f 100644 --- a/substrate/frame/identity/src/lib.rs +++ b/substrate/frame/identity/src/lib.rs @@ -203,7 +203,7 @@ pub mod pallet { RegistrarInfo< BalanceOf, T::AccountId, - ::FieldsBitFlags, + ::FieldsIdentifier, >, >, T::MaxRegistrars, @@ -648,7 +648,7 @@ pub mod pallet { pub fn set_fields( origin: OriginFor, #[pallet::compact] index: RegistrarIndex, - fields: ::FieldsBitFlags, + fields: ::FieldsIdentifier, ) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; @@ -901,7 +901,7 @@ impl Pallet { /// Check if the account has corresponding identity information by the identity field. pub fn has_identity( who: &T::AccountId, - fields: ::FieldsBitFlags, + fields: ::FieldsIdentifier, ) -> bool { IdentityOf::::get(who) .map_or(false, |registration| (registration.info.has_identity(fields))) diff --git a/substrate/frame/identity/src/types.rs b/substrate/frame/identity/src/types.rs index 9e952ea8224a..d3e6bf3973f0 100644 --- a/substrate/frame/identity/src/types.rs +++ b/substrate/frame/identity/src/types.rs @@ -234,11 +234,11 @@ impl bool; + fn has_identity(&self, fields: Self::FieldsIdentifier) -> bool; /// Create a basic instance of the identity information. #[cfg(feature = "runtime-benchmarks")] @@ -246,7 +246,7 @@ pub trait IdentityInformationProvider: /// The identity information representation for all identity fields enabled. #[cfg(feature = "runtime-benchmarks")] - fn all_fields() -> Self::FieldsBitFlags; + fn all_fields() -> Self::FieldsIdentifier; } /// Information on an identity along with judgements from registrars. From 0d171408bc8225881dab328d87476398d3a99c24 Mon Sep 17 00:00:00 2001 From: georgepisaltu Date: Fri, 3 Nov 2023 17:50:16 +0200 Subject: [PATCH 27/27] Remove unused import in substrate node impls Signed-off-by: georgepisaltu --- substrate/bin/node/runtime/src/impls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/bin/node/runtime/src/impls.rs b/substrate/bin/node/runtime/src/impls.rs index 0f847fd606d6..717fbeadada4 100644 --- a/substrate/bin/node/runtime/src/impls.rs +++ b/substrate/bin/node/runtime/src/impls.rs @@ -26,7 +26,7 @@ use frame_support::{ }; use pallet_alliance::{IdentityVerifier, ProposalIndex, ProposalProvider}; use pallet_asset_tx_payment::HandleCredit; -use pallet_identity::{legacy::IdentityField, IdentityInformationProvider}; +use pallet_identity::legacy::IdentityField; use sp_std::prelude::*; use crate::{