Skip to content
Snippets Groups Projects
Unverified Commit 4a415952 authored by bgallois's avatar bgallois
Browse files

feat(pallet_membership): add weights info

parent ca6f0867
No related branches found
No related tags found
No related merge requests found
......@@ -150,6 +150,7 @@ impl pallet_membership::Config<Instance1> for Test {
type MetaData = ();
type OnEvent = DuniterWot;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type PendingMembershipPeriod = PendingMembershipPeriod;
}
......@@ -204,6 +205,7 @@ impl pallet_membership::Config<Instance2> for Test {
type MetaData = ();
type OnEvent = SmithsSubWot;
type PendingMembershipPeriod = SmithsPendingMembershipPeriod;
type WeightInfo = ();
type RuntimeEvent = RuntimeEvent;
}
......
......@@ -26,7 +26,10 @@ mod tests;
#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
pub mod weights;
pub use pallet::*;
pub use weights::WeightInfo;
use frame_support::dispatch::Weight;
use frame_support::error::BadOrigin;
......@@ -80,6 +83,7 @@ pub mod pallet {
/// Because this pallet emits events, it depends on the runtime's definition of an event.
type RuntimeEvent: From<Event<Self, I>>
+ IsType<<Self as frame_system::Config>::RuntimeEvent>;
type WeightInfo: WeightInfo;
}
// GENESIS STUFF //
......@@ -197,8 +201,8 @@ pub mod pallet {
#[pallet::call]
impl<T: Config<I>, I: 'static> Pallet<T, I> {
#[pallet::weight(1_000_000_000)]
/// request membership without checks
#[pallet::weight(T::WeightInfo::force_request_membership())]
pub fn force_request_membership(
origin: OriginFor<T>,
idty_id: T::IdtyId,
......@@ -209,9 +213,9 @@ pub mod pallet {
Self::do_request_membership(idty_id, metadata)
}
#[pallet::weight(1_000_000_000)]
/// submit a membership request (must have a declared identity)
/// (only available for sub wot, automatic for main wot)
#[pallet::weight(T::WeightInfo::request_membership())]
pub fn request_membership(
origin: OriginFor<T>,
metadata: T::MetaData,
......@@ -227,9 +231,9 @@ pub mod pallet {
Self::do_request_membership(idty_id, metadata)
}
#[pallet::weight(1_000_000_000)]
/// claim that the previously requested membership fullfills the requirements
/// (only available for sub wot, automatic for main wot)
#[pallet::weight(T::WeightInfo::claim_membership())]
pub fn claim_membership(
origin: OriginFor<T>,
maybe_idty_id: Option<T::IdtyId>,
......@@ -255,8 +259,8 @@ pub mod pallet {
Ok(().into())
}
#[pallet::weight(1_000_000_000)]
/// extend the validity period of an active membership
#[pallet::weight(T::WeightInfo::renew_membership())]
pub fn renew_membership(
origin: OriginFor<T>,
maybe_idty_id: Option<T::IdtyId>,
......@@ -276,9 +280,9 @@ pub mod pallet {
Ok(().into())
}
#[pallet::weight(1_000_000_000)]
/// revoke an active membership
/// (only available for sub wot, automatic for main wot)
#[pallet::weight(T::WeightInfo::revoke_membership())]
pub fn revoke_membership(
origin: OriginFor<T>,
maybe_idty_id: Option<T::IdtyId>,
......
......@@ -92,6 +92,7 @@ impl pallet_membership::Config for Test {
type OnEvent = ();
type PendingMembershipPeriod = PendingMembershipPeriod;
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 force_request_membership() -> Weight;
fn request_membership() -> Weight;
fn claim_membership() -> Weight;
fn renew_membership() -> Weight;
fn revoke_membership() -> Weight;
}
// Insecure weights implementation, use it for tests only!
impl WeightInfo for () {
// 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 force_request_membership() -> Weight {
// Minimum execution time: 89_725 nanoseconds.
Weight::from_ref_time(98_333_000 as u64)
.saturating_add(RocksDbWeight::get().reads(4 as u64))
.saturating_add(RocksDbWeight::get().writes(2 as u64))
}
// Storage: Identity IdentityIndexOf (r:1 w:0)
// Storage: Identity Identities (r:1 w:0)
fn request_membership() -> Weight {
// Minimum execution time: 48_477 nanoseconds.
Weight::from_ref_time(50_689_000 as u64)
.saturating_add(RocksDbWeight::get().reads(2 as u64))
}
// Storage: Identity IdentityIndexOf (r:1 w:0)
// 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)
fn claim_membership() -> Weight {
// Minimum execution time: 144_079 nanoseconds.
Weight::from_ref_time(146_565_000 as u64)
.saturating_add(RocksDbWeight::get().reads(7 as u64))
.saturating_add(RocksDbWeight::get().writes(4 as u64))
}
// Storage: Identity IdentityIndexOf (r:1 w:0)
// Storage: Membership Membership (r:1 w:1)
// Storage: Identity Identities (r:1 w:0)
// Storage: Parameters ParametersStorage (r:1 w:0)
// Storage: Membership MembershipsExpireOn (r:1 w:1)
fn renew_membership() -> Weight {
// Minimum execution time: 120_859 nanoseconds.
Weight::from_ref_time(124_222_000 as u64)
.saturating_add(RocksDbWeight::get().reads(5 as u64))
.saturating_add(RocksDbWeight::get().writes(2 as u64))
}
// Storage: Identity IdentityIndexOf (r:1 w:0)
// Storage: Membership Membership (r:1 w:1)
// Storage: Membership CounterForMembership (r:1 w:1)
// Storage: Identity Identities (r:1 w:0)
// Storage: UniversalDividend CurrentUdIndex (r:1 w:0)
fn revoke_membership() -> Weight {
// Minimum execution time: 109_486 nanoseconds.
Weight::from_ref_time(113_303_000 as u64)
.saturating_add(RocksDbWeight::get().reads(5 as u64))
.saturating_add(RocksDbWeight::get().writes(2 as u64))
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment