Skip to content
Snippets Groups Projects
Commit d3730345 authored by bgallois's avatar bgallois Committed by Pascal Engélibert
Browse files

feat(pallet_certification): add weights info

parent adf41261
No related branches found
No related tags found
1 merge request!145Certification pallet benchmark
......@@ -16,10 +16,12 @@
#![cfg_attr(not(feature = "std"), no_std)]
mod benchmarking;
#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking;
pub mod traits;
mod types;
pub mod weights;
#[cfg(test)]
mod mock;
......@@ -29,6 +31,7 @@ mod tests;
pub use pallet::*;
pub use types::*;
pub use weights::WeightInfo;
use crate::traits::*;
use codec::Codec;
......@@ -85,6 +88,8 @@ 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 representing the weight of this pallet
type WeightInfo: WeightInfo;
#[pallet::constant]
/// Duration of validity of a certification
type ValidityPeriod: Get<Self::BlockNumber>;
......@@ -272,7 +277,7 @@ pub mod pallet {
#[pallet::call]
impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// add a certification without checks (only root)
#[pallet::weight(1_000_000_000)]
#[pallet::weight(T::WeightInfo::force_add_cert())]
pub fn force_add_cert(
origin: OriginFor<T>,
issuer: T::IdtyIndex,
......@@ -315,7 +320,7 @@ pub mod pallet {
/// - `receiver`: the account receiving the certification from the origin
///
/// The origin must be allow to certify.
#[pallet::weight(1_000_000_000)]
#[pallet::weight(T::WeightInfo::add_cert())]
pub fn add_cert(
origin: OriginFor<T>,
issuer: T::IdtyIndex,
......@@ -359,7 +364,7 @@ pub mod pallet {
}
/// remove a certification (only root)
#[pallet::weight(1_000_000_000)]
#[pallet::weight(T::WeightInfo::del_cert())]
pub fn del_cert(
origin: OriginFor<T>,
issuer: T::IdtyIndex,
......@@ -371,7 +376,7 @@ pub mod pallet {
}
/// remove all certifications received by an identity (only root)
#[pallet::weight(1_000_000_000)]
#[pallet::weight(T::WeightInfo::remove_all_certs_received_by(CertsByReceiver::<T, I>::get(idty_index).len() as u32))]
pub fn remove_all_certs_received_by(
origin: OriginFor<T>,
idty_index: T::IdtyIndex,
......
......@@ -108,6 +108,7 @@ impl pallet_certification::Config for Test {
type OnNewcert = ();
type OnRemovedCert = ();
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type ValidityPeriod = ValidityPeriod;
}
......
// Copyright 2021-2022 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_add_cert() -> Weight;
fn add_cert() -> Weight;
fn del_cert() -> Weight;
fn remove_all_certs_received_by(i: u32) -> Weight;
}
// Insecure weights implementation, use it for tests only!
impl WeightInfo for () {
// Storage: Cert StorageIdtyCertMeta (r:2 w:2)
// Storage: Parameters ParametersStorage (r:1 w:0)
// Storage: Cert StorageCertsRemovableOn (r:1 w:1)
// Storage: Cert CertsByReceiver (r:1 w:1)
fn force_add_cert() -> Weight {
// Minimum execution time: 221_467 nanoseconds.
Weight::from_ref_time(227_833_000 as u64)
.saturating_add(RocksDbWeight::get().reads(5 as u64))
.saturating_add(RocksDbWeight::get().writes(4 as u64))
}
// Storage: Identity Identities (r:2 w:0)
// Storage: Cert StorageIdtyCertMeta (r:2 w:2)
// Storage: Parameters ParametersStorage (r:1 w:0)
// Storage: Cert StorageCertsRemovableOn (r:1 w:1)
// Storage: Cert CertsByReceiver (r:1 w:1)
fn add_cert() -> Weight {
// Minimum execution time: 259_247 nanoseconds.
Weight::from_ref_time(269_348_000 as u64)
.saturating_add(RocksDbWeight::get().reads(7 as u64))
.saturating_add(RocksDbWeight::get().writes(4 as u64))
}
// Storage: Cert CertsByReceiver (r:1 w:1)
// Storage: Cert StorageIdtyCertMeta (r:2 w:2)
// Storage: Parameters ParametersStorage (r:1 w:0)
// Storage: Membership Membership (r:1 w:0)
fn del_cert() -> Weight {
// Minimum execution time: 216_762 nanoseconds.
Weight::from_ref_time(222_570_000 as u64)
.saturating_add(RocksDbWeight::get().reads(5 as u64))
.saturating_add(RocksDbWeight::get().writes(3 as u64))
}
// Storage: Cert CertsByReceiver (r:1 w:1)
// Storage: Cert StorageIdtyCertMeta (r:2 w:2)
// Storage: Parameters ParametersStorage (r:1 w:0)
// Storage: Membership Membership (r:1 w:0)
/// The range of component `i` is `[2, 1000]`.
fn remove_all_certs_received_by(i: u32) -> Weight {
// Minimum execution time: 223_292 nanoseconds.
Weight::from_ref_time(233_586_000 as u64)
// Standard Error: 598_929
.saturating_add(Weight::from_ref_time(53_659_501 as u64).saturating_mul(i as u64))
.saturating_add(RocksDbWeight::get().reads(3 as u64))
.saturating_add(RocksDbWeight::get().reads((1 as u64).saturating_mul(i as u64)))
.saturating_add(RocksDbWeight::get().writes(1 as u64))
.saturating_add(RocksDbWeight::get().writes((1 as u64).saturating_mul(i as u64)))
}
}
......@@ -170,6 +170,7 @@ impl pallet_certification::Config<Instance1> for Test {
type OnNewcert = DuniterWot;
type OnRemovedCert = DuniterWot;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type ValidityPeriod = ValidityPeriod;
}
......@@ -222,6 +223,7 @@ impl pallet_certification::Config<Instance2> for Test {
type OnNewcert = SmithsSubWot;
type OnRemovedCert = SmithsSubWot;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = ();
type ValidityPeriod = SmithsValidityPeriod;
}
......
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