Skip to content

Commit

Permalink
fix runtime-benchmarks for pallet-identity
Browse files Browse the repository at this point in the history
  • Loading branch information
RomarQ committed Mar 5, 2024
1 parent 18b97f1 commit 186ff58
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 36 deletions.
8 changes: 4 additions & 4 deletions primitives/account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,7 +31,7 @@ sp-std = { workspace = true }
hex = { workspace = true }

[features]
default = [ "std" ]
default = ["std"]
std = [
"full_crypto",
"hex/std",
Expand Down
20 changes: 20 additions & 0 deletions primitives/account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ impl From<[u8; 32]> for AccountId20 {
Self(buffer)
}
}
impl From<sp_runtime::AccountId32> for AccountId20 {
fn from(account: sp_runtime::AccountId32) -> Self {
let bytes: &[u8; 32] = account.as_ref();
Self::from(*bytes)
}
}

impl From<H160> for AccountId20 {
fn from(h160: H160) -> Self {
Expand Down Expand Up @@ -116,6 +122,20 @@ impl From<ecdsa::Signature> for EthereumSignature {
}
}

impl From<sp_runtime::MultiSignature> 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<L: sp_runtime::traits::Lazy<[u8]>>(&self, mut msg: L, signer: &AccountId20) -> bool {
Expand Down
123 changes: 97 additions & 26 deletions runtime/common/src/weights/pallet_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> {
/// 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`
Expand Down Expand Up @@ -127,7 +127,7 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> {
/// The range of component `r` is `[1, 20]`.
/// The range of component `s` is `[0, 100]`.
/// The range of component `x` is `[0, 100]`.
fn clear_identity(r: u32, s: u32) -> Weight {
fn clear_identity(r: u32, s: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `445 + r * (5 ±0) + s * (20 ±0) + x * (66 ±0)`
// Estimated: `10991`
Expand All @@ -148,7 +148,7 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> {
/// 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`
Expand All @@ -157,14 +157,16 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> {
.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))
}
/// Storage: `Identity::IdentityOf` (r:1 w:1)
/// 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`
Expand Down Expand Up @@ -339,32 +341,101 @@ impl<T: frame_system::Config> pallet_identity::WeightInfo for WeightInfo<T> {
.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))
}
}
4 changes: 2 additions & 2 deletions runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ impl pallet_identity::Config for Runtime {
type RegistrarOrigin = IdentityRegistrarOrigin;
type OffchainSignature = Signature;
type SigningPublicKey = <Signature as sp_runtime::traits::Verify>::Signer;
type UsernameAuthorityOrigin = EnsureRoot<Self::AccountId>;
type UsernameAuthorityOrigin = EnsureRoot<AccountId>;
type PendingUsernameExpiration = PendingUsernameExpiration;
type MaxSuffixLength = MaxSuffixLength;
type MaxUsernameLength = MaxUsernameLength;
Expand Down Expand Up @@ -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::<Runtime>]
[pallet_asset_manager, AssetManager]
Expand Down
4 changes: 2 additions & 2 deletions runtime/moonbeam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ impl pallet_identity::Config for Runtime {
type RegistrarOrigin = IdentityRegistrarOrigin;
type OffchainSignature = Signature;
type SigningPublicKey = <Signature as sp_runtime::traits::Verify>::Signer;
type UsernameAuthorityOrigin = EnsureRoot<Self::AccountId>;
type UsernameAuthorityOrigin = EnsureRoot<AccountId>;
type PendingUsernameExpiration = PendingUsernameExpiration;
type MaxSuffixLength = MaxSuffixLength;
type MaxUsernameLength = MaxUsernameLength;
Expand Down Expand Up @@ -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::<Runtime>]
[pallet_asset_manager, AssetManager]
Expand Down
4 changes: 2 additions & 2 deletions runtime/moonriver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ impl pallet_identity::Config for Runtime {
type RegistrarOrigin = IdentityRegistrarOrigin;
type OffchainSignature = Signature;
type SigningPublicKey = <Signature as sp_runtime::traits::Verify>::Signer;
type UsernameAuthorityOrigin = EnsureRoot<Self::AccountId>;
type UsernameAuthorityOrigin = EnsureRoot<AccountId>;
type PendingUsernameExpiration = PendingUsernameExpiration;
type MaxSuffixLength = MaxSuffixLength;
type MaxUsernameLength = MaxUsernameLength;
Expand Down Expand Up @@ -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::<Runtime>]
[pallet_asset_manager, AssetManager]
Expand Down

0 comments on commit 186ff58

Please sign in to comment.