From 186ff589f7d1a10d7e960fa2ba2c5d90b3283f4f Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Tue, 5 Mar 2024 14:28:34 +0000 Subject: [PATCH] fix runtime-benchmarks for pallet-identity --- primitives/account/Cargo.toml | 8 +- primitives/account/src/lib.rs | 20 +++ runtime/common/src/weights/pallet_identity.rs | 123 ++++++++++++++---- runtime/moonbase/src/lib.rs | 4 +- runtime/moonbeam/src/lib.rs | 4 +- runtime/moonriver/src/lib.rs | 4 +- 6 files changed, 127 insertions(+), 36 deletions(-) diff --git a/primitives/account/Cargo.toml b/primitives/account/Cargo.toml index 92ffb618b42..4865ca9f0ed 100644 --- a/primitives/account/Cargo.toml +++ b/primitives/account/Cargo.toml @@ -8,14 +8,14 @@ repository = { workspace = true } version = "0.1.1" [package.metadata.docs.rs] -targets = [ "x86_64-unknown-linux-gnu" ] +targets = ["x86_64-unknown-linux-gnu"] [dependencies] blake2-rfc = { workspace = true, optional = true } impl-serde = { workspace = true } -libsecp256k1 = { workspace = true, features = [ "hmac" ] } +libsecp256k1 = { workspace = true, features = ["hmac"] } log = { workspace = true } -serde = { workspace = true, features = [ "derive" ] } +serde = { workspace = true, features = ["derive"] } sha3 = { workspace = true } # Substrate @@ -31,7 +31,7 @@ sp-std = { workspace = true } hex = { workspace = true } [features] -default = [ "std" ] +default = ["std"] std = [ "full_crypto", "hex/std", diff --git a/primitives/account/src/lib.rs b/primitives/account/src/lib.rs index 84f6e121c77..1a1d6a916a8 100644 --- a/primitives/account/src/lib.rs +++ b/primitives/account/src/lib.rs @@ -82,6 +82,12 @@ impl From<[u8; 32]> for AccountId20 { Self(buffer) } } +impl From for AccountId20 { + fn from(account: sp_runtime::AccountId32) -> Self { + let bytes: &[u8; 32] = account.as_ref(); + Self::from(*bytes) + } +} impl From for AccountId20 { fn from(h160: H160) -> Self { @@ -116,6 +122,20 @@ impl From for EthereumSignature { } } +impl From for EthereumSignature { + fn from(signature: sp_runtime::MultiSignature) -> Self { + match signature { + sp_runtime::MultiSignature::Ed25519(_) => { + panic!("Ed25519 not supported for EthereumSignature") + } + sp_runtime::MultiSignature::Sr25519(_) => { + panic!("Sr25519 not supported for EthereumSignature") + } + sp_runtime::MultiSignature::Ecdsa(sig) => Self(sig), + } + } +} + impl sp_runtime::traits::Verify for EthereumSignature { type Signer = EthereumSigner; fn verify>(&self, mut msg: L, signer: &AccountId20) -> bool { diff --git a/runtime/common/src/weights/pallet_identity.rs b/runtime/common/src/weights/pallet_identity.rs index 640b7a87484..669f07eacd7 100644 --- a/runtime/common/src/weights/pallet_identity.rs +++ b/runtime/common/src/weights/pallet_identity.rs @@ -64,7 +64,7 @@ impl pallet_identity::WeightInfo for WeightInfo { /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7526), added: 10001, mode: `MaxEncodedLen`) /// The range of component `r` is `[1, 20]`. /// The range of component `x` is `[0, 100]`. - fn set_identity(r: u32 ) -> Weight { + fn set_identity(r: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `430 + r * (5 ±0)` // Estimated: `10991` @@ -127,7 +127,7 @@ impl pallet_identity::WeightInfo for WeightInfo { /// The range of component `r` is `[1, 20]`. /// The range of component `s` is `[0, 100]`. /// The range of component `x` is `[0, 100]`. - fn clear_identity(r: u32, s: u32) -> Weight { + fn clear_identity(r: u32, s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `445 + r * (5 ±0) + s * (20 ±0) + x * (66 ±0)` // Estimated: `10991` @@ -148,7 +148,7 @@ impl pallet_identity::WeightInfo for WeightInfo { /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7526), added: 10001, mode: `MaxEncodedLen`) /// The range of component `r` is `[1, 20]`. /// The range of component `x` is `[0, 100]`. - fn request_judgement(r: u32, ) -> Weight { + fn request_judgement(r: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `355 + r * (45 ±0) + x * (66 ±0)` // Estimated: `10991` @@ -157,6 +157,8 @@ impl pallet_identity::WeightInfo for WeightInfo { .saturating_add(Weight::from_parts(0, 10991)) // Standard Error: 3_421 .saturating_add(Weight::from_parts(109_577, 0).saturating_mul(r.into())) + // Standard Error: 667 + .saturating_add(Weight::from_parts(537_126, 0).saturating_mul(x.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -164,7 +166,7 @@ impl pallet_identity::WeightInfo for WeightInfo { /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7526), added: 10001, mode: `MaxEncodedLen`) /// The range of component `r` is `[1, 20]`. /// The range of component `x` is `[0, 100]`. - fn cancel_request(r: u32,) -> Weight { + fn cancel_request(r: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `386 + x * (66 ±0)` // Estimated: `10991` @@ -339,32 +341,101 @@ impl pallet_identity::WeightInfo for WeightInfo { .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(2)) } - + /// Storage: `Identity::UsernameAuthorities` (r:0 w:1) + /// Proof: `Identity::UsernameAuthorities` (`max_values`: None, `max_size`: Some(40), added: 2515, mode: `MaxEncodedLen`) fn add_username_authority() -> Weight { - todo!() - } - + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 6_000_000 picoseconds. + Weight::from_parts(7_000_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `Identity::UsernameAuthorities` (r:1 w:1) + /// Proof: `Identity::UsernameAuthorities` (`max_values`: None, `max_size`: Some(40), added: 2515, mode: `MaxEncodedLen`) fn remove_username_authority() -> Weight { - todo!() - } - + // Proof Size summary in bytes: + // Measured: `67` + // Estimated: `3505` + // Minimum execution time: 9_000_000 picoseconds. + Weight::from_parts(9_000_000, 0) + .saturating_add(Weight::from_parts(0, 3505)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `Identity::UsernameAuthorities` (r:1 w:1) + /// Proof: `Identity::UsernameAuthorities` (`max_values`: None, `max_size`: Some(40), added: 2515, mode: `MaxEncodedLen`) + /// Storage: `Identity::AccountOfUsername` (r:1 w:1) + /// Proof: `Identity::AccountOfUsername` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`) + /// Storage: `Identity::PendingUsernames` (r:1 w:0) + /// Proof: `Identity::PendingUsernames` (`max_values`: None, `max_size`: Some(73), added: 2548, mode: `MaxEncodedLen`) + /// Storage: `Identity::IdentityOf` (r:1 w:1) + /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7560), added: 10035, mode: `MaxEncodedLen`) fn set_username_for() -> Weight { - todo!() - } - + // Proof Size summary in bytes: + // Measured: `67` + // Estimated: `11025` + // Minimum execution time: 21_000_000 picoseconds. + Weight::from_parts(23_000_000, 0) + .saturating_add(Weight::from_parts(0, 11025)) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `Identity::PendingUsernames` (r:1 w:1) + /// Proof: `Identity::PendingUsernames` (`max_values`: None, `max_size`: Some(73), added: 2548, mode: `MaxEncodedLen`) + /// Storage: `Identity::IdentityOf` (r:1 w:1) + /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7560), added: 10035, mode: `MaxEncodedLen`) + /// Storage: `Identity::AccountOfUsername` (r:0 w:1) + /// Proof: `Identity::AccountOfUsername` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`) fn accept_username() -> Weight { - todo!() - } - + // Proof Size summary in bytes: + // Measured: `101` + // Estimated: `11025` + // Minimum execution time: 19_000_000 picoseconds. + Weight::from_parts(20_000_000, 0) + .saturating_add(Weight::from_parts(0, 11025)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `Identity::PendingUsernames` (r:1 w:1) + /// Proof: `Identity::PendingUsernames` (`max_values`: None, `max_size`: Some(73), added: 2548, mode: `MaxEncodedLen`) fn remove_expired_approval() -> Weight { - todo!() - } - + // Proof Size summary in bytes: + // Measured: `101` + // Estimated: `3538` + // Minimum execution time: 27_000_000 picoseconds. + Weight::from_parts(30_000_000, 0) + .saturating_add(Weight::from_parts(0, 3538)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `Identity::AccountOfUsername` (r:1 w:0) + /// Proof: `Identity::AccountOfUsername` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`) + /// Storage: `Identity::IdentityOf` (r:1 w:1) + /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7560), added: 10035, mode: `MaxEncodedLen`) fn set_primary_username() -> Weight { - todo!() - } - + // Proof Size summary in bytes: + // Measured: `232` + // Estimated: `11025` + // Minimum execution time: 15_000_000 picoseconds. + Weight::from_parts(16_000_000, 0) + .saturating_add(Weight::from_parts(0, 11025)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `Identity::AccountOfUsername` (r:1 w:1) + /// Proof: `Identity::AccountOfUsername` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`) + /// Storage: `Identity::IdentityOf` (r:1 w:0) + /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7560), added: 10035, mode: `MaxEncodedLen`) fn remove_dangling_username() -> Weight { - todo!() - } -} + // Proof Size summary in bytes: + // Measured: `86` + // Estimated: `11025` + // Minimum execution time: 10_000_000 picoseconds. + Weight::from_parts(11_000_000, 0) + .saturating_add(Weight::from_parts(0, 11025)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + } +} \ No newline at end of file diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index fad06dcc9e3..67258400064 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -640,7 +640,7 @@ impl pallet_identity::Config for Runtime { type RegistrarOrigin = IdentityRegistrarOrigin; type OffchainSignature = Signature; type SigningPublicKey = ::Signer; - type UsernameAuthorityOrigin = EnsureRoot; + type UsernameAuthorityOrigin = EnsureRoot; type PendingUsernameExpiration = PendingUsernameExpiration; type MaxSuffixLength = MaxSuffixLength; type MaxUsernameLength = MaxUsernameLength; @@ -1512,7 +1512,7 @@ mod benches { [pallet_crowdloan_rewards, CrowdloanRewards] [pallet_author_mapping, AuthorMapping] [pallet_proxy, Proxy] - // TODO(RODRIGO) [pallet_identity, Identity] + [pallet_identity, Identity] [cumulus_pallet_xcmp_queue, XcmpQueue] [pallet_xcm, PalletXcmExtrinsiscsBenchmark::] [pallet_asset_manager, AssetManager] diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 58f1e4602e5..135b668f8f6 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -623,7 +623,7 @@ impl pallet_identity::Config for Runtime { type RegistrarOrigin = IdentityRegistrarOrigin; type OffchainSignature = Signature; type SigningPublicKey = ::Signer; - type UsernameAuthorityOrigin = EnsureRoot; + type UsernameAuthorityOrigin = EnsureRoot; type PendingUsernameExpiration = PendingUsernameExpiration; type MaxSuffixLength = MaxSuffixLength; type MaxUsernameLength = MaxUsernameLength; @@ -1461,7 +1461,7 @@ mod benches { [pallet_crowdloan_rewards, CrowdloanRewards] [pallet_author_mapping, AuthorMapping] [pallet_proxy, Proxy] - // TODO(RODRIGO) [pallet_identity, Identity] + [pallet_identity, Identity] [cumulus_pallet_xcmp_queue, XcmpQueue] [pallet_xcm, PalletXcmExtrinsiscsBenchmark::] [pallet_asset_manager, AssetManager] diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index a408273fd3e..d41000ccbe7 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -624,7 +624,7 @@ impl pallet_identity::Config for Runtime { type RegistrarOrigin = IdentityRegistrarOrigin; type OffchainSignature = Signature; type SigningPublicKey = ::Signer; - type UsernameAuthorityOrigin = EnsureRoot; + type UsernameAuthorityOrigin = EnsureRoot; type PendingUsernameExpiration = PendingUsernameExpiration; type MaxSuffixLength = MaxSuffixLength; type MaxUsernameLength = MaxUsernameLength; @@ -1463,7 +1463,7 @@ mod benches { [pallet_crowdloan_rewards, CrowdloanRewards] [pallet_author_mapping, AuthorMapping] [pallet_proxy, Proxy] - // TODO(RODRIGO) [pallet_identity, Identity] + [pallet_identity, Identity] [cumulus_pallet_xcmp_queue, XcmpQueue] [pallet_xcm, PalletXcmExtrinsiscsBenchmark::] [pallet_asset_manager, AssetManager]