Skip to content
Snippets Groups Projects
Commit 2c9ff2f6 authored by bgallois's avatar bgallois Committed by Hugo Trentesaux
Browse files

feat(pallet_identity): add weights info

parent 6559e67a
No related branches found
No related tags found
1 merge request!138Identity pallet benchmark
......@@ -133,6 +133,7 @@ impl pallet_identity::Config for Test {
type RevocationSigner = UintAuthorityId;
type RevocationSignature = TestSignature;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}
// Membership
......
......@@ -19,6 +19,7 @@
pub mod traits;
mod types;
pub mod weights;
#[cfg(test)]
mod mock;
......@@ -31,6 +32,7 @@ pub mod benchmarking;
pub use pallet::*;
pub use types::*;
pub use weights::WeightInfo;
use crate::traits::*;
use codec::Codec;
......@@ -109,6 +111,8 @@ pub mod pallet {
type RevocationSignature: Parameter + Verify<Signer = Self::RevocationSigner>;
/// Because this pallet emits events, it depends on the runtime's definition of an event.
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
/// Type representing the weight of this pallet
type WeightInfo: WeightInfo;
}
// GENESIS STUFF //
......@@ -258,7 +262,7 @@ pub mod pallet {
/// - `owner_key`: the public key corresponding to the identity to be created
///
/// The origin must be allowed to create an identity.
#[pallet::weight(1_000_000_000)]
#[pallet::weight(T::WeightInfo::create_identity())]
pub fn create_identity(
origin: OriginFor<T>,
owner_key: T::AccountId,
......@@ -322,7 +326,7 @@ pub mod pallet {
/// - `idty_name`: the name uniquely associated to this identity. Must match the validation rules defined by the runtime.
///
/// The identity must have been created using `create_identity` before it can be confirmed.
#[pallet::weight(1_000_000_000)]
#[pallet::weight(T::WeightInfo::confirm_identity())]
pub fn confirm_identity(
origin: OriginFor<T>,
idty_name: IdtyName,
......@@ -361,7 +365,7 @@ pub mod pallet {
Ok(().into())
}
#[pallet::weight(1_000_000_000)]
#[pallet::weight(T::WeightInfo::validate_identity())]
/// validate the owned identity (must meet the main wot requirements)
pub fn validate_identity(
origin: OriginFor<T>,
......@@ -399,7 +403,7 @@ pub mod pallet {
/// Must be signed by `new_key`.
///
/// The origin should be the old identity owner key.
#[pallet::weight(1_000_000_000)]
#[pallet::weight(T::WeightInfo::change_owner_key())]
pub fn change_owner_key(
origin: OriginFor<T>,
new_key: T::AccountId,
......@@ -482,7 +486,7 @@ pub mod pallet {
/// Must be signed by `revocation_key`.
///
/// Any signed origin can execute this call.
#[pallet::weight(1_000_000_000)]
#[pallet::weight(T::WeightInfo::revoke_identity())]
pub fn revoke_identity(
origin: OriginFor<T>,
idty_index: T::IdtyIndex,
......@@ -523,7 +527,7 @@ pub mod pallet {
Ok(().into())
}
#[pallet::weight(1_000_000_000)]
#[pallet::weight(T::WeightInfo::remove_identity())]
/// remove an identity from storage
pub fn remove_identity(
origin: OriginFor<T>,
......@@ -540,7 +544,7 @@ pub mod pallet {
Ok(().into())
}
#[pallet::weight(1_000_000_000)]
#[pallet::weight(T::WeightInfo::prune_item_identities_names(names.len() as u32))]
/// remove identity names from storage
pub fn prune_item_identities_names(
origin: OriginFor<T>,
......@@ -555,7 +559,7 @@ pub mod pallet {
Ok(().into())
}
#[pallet::weight(1_000_000_000)]
#[pallet::weight(T::WeightInfo::fix_sufficients())]
/// change sufficient ref count for given key
pub fn fix_sufficients(
origin: OriginFor<T>,
......
......@@ -115,6 +115,7 @@ impl pallet_identity::Config for Test {
type RevocationSigner = AccountPublic;
type RevocationSignature = Signature;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
}
// Build genesis storage according to the mock runtime.
......
// Copyright 2021-2023 Axiom-Team
//
// This file is part of Duniter-v2S.
//
// Duniter-v2S is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Duniter-v2S is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Duniter-v2S. If not, see <https://www.gnu.org/licenses/>.
#![allow(clippy::unnecessary_cast)]
use frame_support::weights::{constants::RocksDbWeight, Weight};
/// Weight functions needed for pallet_universal_dividend.
pub trait WeightInfo {
fn create_identity() -> Weight;
fn confirm_identity() -> Weight;
fn validate_identity() -> Weight;
fn change_owner_key() -> Weight;
fn revoke_identity() -> Weight;
fn remove_identity() -> Weight;
fn prune_item_identities_names(i: u32) -> Weight;
fn fix_sufficients() -> Weight;
}
// Insecure weights implementation, use it for tests only!
impl WeightInfo for () {
// Storage: Identity IdentityIndexOf (r:2 w:1)
// Storage: Identity Identities (r:2 w:2)
// Storage: Cert StorageIdtyCertMeta (r:2 w:2)
// Storage: Parameters ParametersStorage (r:1 w:0)
// Storage: System Account (r:1 w:1)
// Storage: Identity NextIdtyIndex (r:1 w:1)
// Storage: Identity CounterForIdentities (r:1 w:1)
// Storage: Identity IdentitiesRemovableOn (r:1 w:1)
// Storage: Cert StorageCertsRemovableOn (r:1 w:1)
// Storage: Cert CertsByReceiver (r:1 w:1)
fn create_identity() -> Weight {
// Minimum execution time: 440_987 nanoseconds.
Weight::from_ref_time(462_747_000 as u64)
.saturating_add(RocksDbWeight::get().reads(13 as u64))
.saturating_add(RocksDbWeight::get().writes(11 as u64))
}
// Storage: Identity IdentityIndexOf (r:1 w:0)
// Storage: Identity Identities (r:1 w:1)
// Storage: Identity IdentitiesNames (r:1 w:1)
// Storage: Membership PendingMembership (r:1 w:1)
// Storage: Membership Membership (r:1 w:0)
// Storage: Parameters ParametersStorage (r:1 w:0)
// Storage: Membership PendingMembershipsExpireOn (r:1 w:1)
fn confirm_identity() -> Weight {
// Minimum execution time: 186_617 nanoseconds.
Weight::from_ref_time(309_527_000 as u64)
.saturating_add(RocksDbWeight::get().reads(7 as u64))
.saturating_add(RocksDbWeight::get().writes(4 as u64))
}
// Storage: Identity Identities (r:1 w:1)
// Storage: Membership Membership (r:1 w:1)
// Storage: Cert StorageIdtyCertMeta (r:1 w:0)
// Storage: Parameters ParametersStorage (r:1 w:0)
// Storage: Membership PendingMembership (r:1 w:1)
// Storage: Membership CounterForMembership (r:1 w:1)
// Storage: Membership MembershipsExpireOn (r:1 w:1)
// Storage: UniversalDividend CurrentUdIndex (r:1 w:0)
fn validate_identity() -> Weight {
// Minimum execution time: 299_920 nanoseconds.
Weight::from_ref_time(320_025_000 as u64)
.saturating_add(RocksDbWeight::get().reads(8 as u64))
.saturating_add(RocksDbWeight::get().writes(5 as u64))
}
// Storage: Identity IdentityIndexOf (r:2 w:2)
// Storage: Identity Identities (r:1 w:1)
// Storage: SmithsMembership Membership (r:1 w:0)
// Storage: System BlockHash (r:1 w:0)
// Storage: System Account (r:1 w:1)
// Storage: AuthorityMembers Members (r:1 w:0)
fn change_owner_key() -> Weight {
// Minimum execution time: 442_260 nanoseconds.
Weight::from_ref_time(728_714_000 as u64)
.saturating_add(RocksDbWeight::get().reads(7 as u64))
.saturating_add(RocksDbWeight::get().writes(4 as u64))
}
// Storage: Identity Identities (r:1 w:1)
// Storage: SmithsMembership Membership (r:1 w:0)
// Storage: System BlockHash (r:1 w:0)
// Storage: Membership Membership (r:1 w:1)
// Storage: Identity CounterForIdentities (r:1 w:1)
// Storage: System Account (r:1 w:1)
// Storage: Cert CertsByReceiver (r:1 w:1)
// Storage: Cert StorageIdtyCertMeta (r:2 w:2)
// Storage: Parameters ParametersStorage (r:1 w:0)
// Storage: Identity IdentityIndexOf (r:0 w:1)
fn revoke_identity() -> Weight {
// Minimum execution time: 494_407 nanoseconds.
Weight::from_ref_time(800_824_000 as u64)
.saturating_add(RocksDbWeight::get().reads(10 as u64))
.saturating_add(RocksDbWeight::get().writes(8 as u64))
}
// Storage: Identity Identities (r:1 w:1)
// Storage: SmithsMembership Membership (r:1 w:0)
// Storage: Membership Membership (r:1 w:1)
// Storage: Identity CounterForIdentities (r:1 w:1)
// Storage: System Account (r:1 w:1)
// Storage: Cert CertsByReceiver (r:1 w:1)
// Storage: Cert StorageIdtyCertMeta (r:2 w:2)
// Storage: Parameters ParametersStorage (r:1 w:0)
// Storage: Identity IdentityIndexOf (r:0 w:1)
// Storage: Identity IdentitiesNames (r:0 w:1)
fn remove_identity() -> Weight {
// Minimum execution time: 302_574 nanoseconds.
Weight::from_ref_time(504_132_000 as u64)
.saturating_add(RocksDbWeight::get().reads(9 as u64))
.saturating_add(RocksDbWeight::get().writes(9 as u64))
}
// Storage: Identity IdentitiesNames (r:0 w:20)
/// The range of component `i` is `[1, 1000]`.
fn prune_item_identities_names(i: u32) -> Weight {
// Minimum execution time: 22_533 nanoseconds.
Weight::from_ref_time(282_674_421 as u64)
// Standard Error: 170_391
.saturating_add(Weight::from_ref_time(5_660_460 as u64).saturating_mul(i as u64))
.saturating_add(RocksDbWeight::get().writes((1 as u64).saturating_mul(i as u64)))
}
// Storage: System Account (r:1 w:1)
fn fix_sufficients() -> Weight {
// Minimum execution time: 112_793 nanoseconds.
Weight::from_ref_time(122_192_000 as u64)
.saturating_add(RocksDbWeight::get().reads(1 as u64))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment