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

fix pallet_certification weight::zero

parent b6f94294
No related branches found
No related tags found
No related merge requests found
Pipeline #34369 failed
......@@ -19,6 +19,7 @@
use super::*;
use frame_benchmarking::benchmarks_instance_pallet;
use frame_benchmarking::Zero;
use frame_system::RawOrigin;
use sp_runtime::traits::Convert;
......@@ -78,6 +79,32 @@ benchmarks_instance_pallet! {
verify {
assert!(CertsByReceiver::<T, I>::get(receiver).len() == 0 );
}
on_initialize {
assert!(StorageCertsRemovableOn::<T, I>::try_get(T::BlockNumber::zero()).is_err());
}: {Pallet::<T, I>::on_initialize(T::BlockNumber::zero());}
remove_cert_inner_noop {
}: {Pallet::<T, I>::remove_cert_inner(100.into(), 101.into(), Some(T::BlockNumber::zero()));}
remove_cert_inner {
let issuer: T::IdtyIndex = 1.into();
let receiver: T::IdtyIndex = 0.into();
Pallet::<T, I>::do_add_cert_checked(issuer, receiver, false)?;
let issuer_cert: u32 = StorageIdtyCertMeta::<T, I>::get(issuer).issued_count;
let receiver_cert: u32 = StorageIdtyCertMeta::<T, I>::get(receiver).received_count;
let block_number = T::ValidityPeriod::get();
frame_system::pallet::Pallet::<T>::set_block_number(block_number);
}: {Pallet::<T, I>::remove_cert_inner(issuer, receiver, Some(block_number));}
verify {
assert_has_event::<T, I>(Event::<T, I>::RemovedCert{ issuer: issuer, issuer_issued_count: issuer_cert - 1, receiver: receiver, receiver_received_count: receiver_cert - 1, expiration: true }.into());
}
on_remove_cert {
let issuer: T::IdtyIndex = 1.into();
let receiver: T::IdtyIndex = 0.into();
Pallet::<T, I>::do_add_cert_checked(issuer, receiver, false)?;
let issuer_cert: u32 = StorageIdtyCertMeta::<T, I>::get(issuer).issued_count;
let receiver_cert: u32 = StorageIdtyCertMeta::<T, I>::get(receiver).received_count;
let block_number = T::ValidityPeriod::get();
frame_system::pallet::Pallet::<T>::set_block_number(block_number);
}: {T::OnRemovedCert::on_removed_cert(issuer, issuer_cert, receiver, receiver_cert, true);}
impl_benchmark_test_suite!(
Pallet,
......
......@@ -268,7 +268,7 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {
fn on_initialize(n: T::BlockNumber) -> Weight {
Self::prune_certifications(n)
Self::prune_certifications(n).saturating_add(T::WeightInfo::on_initialize())
}
}
......@@ -464,6 +464,7 @@ pub mod pallet {
/// remove the certifications due to expire on the given block
// (run at on_initialize step)
fn prune_certifications(block_number: T::BlockNumber) -> Weight {
// See on initialize for the overhead weight compatibility
let mut total_weight = Weight::zero();
if let Some(certs) = StorageCertsRemovableOn::<T, I>::take(block_number) {
......@@ -476,7 +477,7 @@ pub mod pallet {
}
/// perform the certification removal
/// if block number is given only remove cert if still set to expire at this block number
fn remove_cert_inner(
pub fn remove_cert_inner(
issuer: T::IdtyIndex,
receiver: T::IdtyIndex,
block_number_opt: Option<T::BlockNumber>,
......@@ -498,6 +499,8 @@ pub mod pallet {
issuers.remove(index);
removed = true;
}
} else {
total_weight += T::WeightInfo::remove_cert_inner_noop();
}
});
if removed {
......@@ -526,7 +529,11 @@ pub mod pallet {
receiver,
receiver_received_count,
block_number_opt.is_some(),
);
)
.saturating_add(
T::WeightInfo::remove_cert_inner()
.saturating_sub(T::WeightInfo::on_remove_cert()),
); // Pessimistic overhead estimation based on the worst path of a successful certificate removal to avoid multiplying benchmarks for every branching
}
total_weight
}
......
......@@ -23,6 +23,10 @@ pub trait WeightInfo {
fn add_cert() -> Weight;
fn del_cert() -> Weight;
fn remove_all_certs_received_by(i: u32) -> Weight;
fn on_initialize() -> Weight;
fn remove_cert_inner_noop() -> Weight;
fn remove_cert_inner() -> Weight;
fn on_remove_cert() -> Weight;
}
// Insecure weights implementation, use it for tests only!
......@@ -63,4 +67,28 @@ impl WeightInfo for () {
.saturating_add(RocksDbWeight::get().writes(1 as u64))
.saturating_add(RocksDbWeight::get().writes((1 as u64).saturating_mul(i as u64)))
}
fn on_initialize() -> Weight {
// Minimum execution time: 259_247 nanoseconds.
Weight::from_parts(269_348_000 as u64, 0)
.saturating_add(RocksDbWeight::get().reads(7 as u64))
.saturating_add(RocksDbWeight::get().writes(4 as u64))
}
fn remove_cert_inner_noop() -> Weight {
// Minimum execution time: 259_247 nanoseconds.
Weight::from_parts(269_348_000 as u64, 0)
.saturating_add(RocksDbWeight::get().reads(7 as u64))
.saturating_add(RocksDbWeight::get().writes(4 as u64))
}
fn remove_cert_inner() -> Weight {
// Minimum execution time: 259_247 nanoseconds.
Weight::from_parts(269_348_000 as u64, 0)
.saturating_add(RocksDbWeight::get().reads(7 as u64))
.saturating_add(RocksDbWeight::get().writes(4 as u64))
}
fn on_remove_cert() -> Weight {
// Minimum execution time: 259_247 nanoseconds.
Weight::from_parts(269_348_000 as u64, 0)
.saturating_add(RocksDbWeight::get().reads(7 as u64))
.saturating_add(RocksDbWeight::get().writes(4 as u64))
}
}
// 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/>.
//! Autogenerated weights for `pallet_certification`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-06-08, STEPS: `5`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2023-11-21, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `benjamin-xps139380`, CPU: `Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("gdev-benchmark"), DB CACHE: 1024
//! HOSTNAME: `bgallois-ms7d43`, CPU: `12th Gen Intel(R) Core(TM) i3-12100F`
//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
// Executed Command:
// target/release/duniter
// ./target/release/duniter
// benchmark
// pallet
// --chain=gdev-benchmark
// --steps=5
// --repeat=2
// --pallet=*
// --extrinsic=*
// --execution=wasm
// --chain
// dev
// --wasm-execution=compiled
// --heap-pages=4096
// --header=./file_header.txt
// --output=./runtime/common/src/weights/
// --pallet
// pallet-certification
// --extrinsic
// *
// --steps
// 50
// --repeat
// 20
// --output=runtime/common/src/weights/
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
......@@ -60,11 +47,11 @@ impl<T: frame_system::Config> pallet_certification::WeightInfo for WeightInfo<T>
/// Proof Skipped: Cert CertsByReceiver (max_values: None, max_size: None, mode: Measured)
fn add_cert() -> Weight {
// Proof Size summary in bytes:
// Measured: `831`
// Estimated: `6771`
// Minimum execution time: 125_750_000 picoseconds.
Weight::from_parts(144_960_000, 0)
.saturating_add(Weight::from_parts(0, 6771))
// Measured: `839`
// Estimated: `6779`
// Minimum execution time: 18_636_000 picoseconds.
Weight::from_parts(20_058_000, 0)
.saturating_add(Weight::from_parts(0, 6779))
.saturating_add(T::DbWeight::get().reads(7))
.saturating_add(T::DbWeight::get().writes(4))
}
......@@ -78,11 +65,11 @@ impl<T: frame_system::Config> pallet_certification::WeightInfo for WeightInfo<T>
/// Proof Skipped: Membership Membership (max_values: None, max_size: None, mode: Measured)
fn del_cert() -> Weight {
// Proof Size summary in bytes:
// Measured: `695`
// Estimated: `6635`
// Minimum execution time: 97_607_000 picoseconds.
Weight::from_parts(111_284_000, 0)
.saturating_add(Weight::from_parts(0, 6635))
// Measured: `722`
// Estimated: `6662`
// Minimum execution time: 16_022_000 picoseconds.
Weight::from_parts(17_077_000, 0)
.saturating_add(Weight::from_parts(0, 6662))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(3))
}
......@@ -98,17 +85,71 @@ impl<T: frame_system::Config> pallet_certification::WeightInfo for WeightInfo<T>
/// The range of component `i` is `[2, 1000]`.
fn remove_all_certs_received_by(i: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `623 + i * (35 ±0)`
// Estimated: `4098 + i * (2511 ±0)`
// Minimum execution time: 101_183_000 picoseconds.
Weight::from_parts(101_610_000, 0)
.saturating_add(Weight::from_parts(0, 4098))
// Standard Error: 551_959
.saturating_add(Weight::from_parts(36_743_850, 0).saturating_mul(i.into()))
// Measured: `608 + i * (35 ±0)`
// Estimated: `4079 + i * (2511 ±0)`
// Minimum execution time: 16_103_000 picoseconds.
Weight::from_parts(16_586_000, 0)
.saturating_add(Weight::from_parts(0, 4079))
// Standard Error: 8_385
.saturating_add(Weight::from_parts(4_802_613, 0).saturating_mul(i.into()))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(i.into())))
.saturating_add(T::DbWeight::get().writes(1))
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(i.into())))
.saturating_add(Weight::from_parts(0, 2511).saturating_mul(i.into()))
}
/// Storage: Cert StorageCertsRemovableOn (r:1 w:0)
/// Proof Skipped: Cert StorageCertsRemovableOn (max_values: None, max_size: None, mode: Measured)
fn on_initialize() -> Weight {
// Proof Size summary in bytes:
// Measured: `181`
// Estimated: `3646`
// Minimum execution time: 2_845_000 picoseconds.
Weight::from_parts(3_030_000, 0)
.saturating_add(Weight::from_parts(0, 3646))
.saturating_add(T::DbWeight::get().reads(1))
}
/// Storage: Cert CertsByReceiver (r:1 w:1)
/// Proof Skipped: Cert CertsByReceiver (max_values: None, max_size: None, mode: Measured)
fn remove_cert_inner_noop() -> Weight {
// Proof Size summary in bytes:
// Measured: `279`
// Estimated: `3744`
// Minimum execution time: 3_712_000 picoseconds.
Weight::from_parts(3_901_000, 0)
.saturating_add(Weight::from_parts(0, 3744))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: Cert CertsByReceiver (r:1 w:1)
/// Proof Skipped: Cert CertsByReceiver (max_values: None, max_size: None, mode: Measured)
/// Storage: Cert StorageIdtyCertMeta (r:2 w:2)
/// Proof Skipped: Cert StorageIdtyCertMeta (max_values: None, max_size: None, mode: Measured)
/// Storage: Parameters ParametersStorage (r:1 w:0)
/// Proof Skipped: Parameters ParametersStorage (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Membership Membership (r:1 w:0)
/// Proof Skipped: Membership Membership (max_values: None, max_size: None, mode: Measured)
fn remove_cert_inner() -> Weight {
// Proof Size summary in bytes:
// Measured: `722`
// Estimated: `6662`
// Minimum execution time: 14_417_000 picoseconds.
Weight::from_parts(15_092_000, 0)
.saturating_add(Weight::from_parts(0, 6662))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(3))
}
/// Storage: Parameters ParametersStorage (r:1 w:0)
/// Proof Skipped: Parameters ParametersStorage (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Membership Membership (r:1 w:0)
/// Proof Skipped: Membership Membership (max_values: None, max_size: None, mode: Measured)
fn on_remove_cert() -> Weight {
// Proof Size summary in bytes:
// Measured: `297`
// Estimated: `3762`
// Minimum execution time: 5_743_000 picoseconds.
Weight::from_parts(6_005_000, 0)
.saturating_add(Weight::from_parts(0, 3762))
.saturating_add(T::DbWeight::get().reads(2))
}
}
// 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/>.
//! Autogenerated weights for `pallet_certification`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-06-08, STEPS: `5`, REPEAT: `2`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2023-11-21, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `benjamin-xps139380`, CPU: `Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("gdev-benchmark"), DB CACHE: 1024
//! HOSTNAME: `bgallois-ms7d43`, CPU: `12th Gen Intel(R) Core(TM) i3-12100F`
//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
// Executed Command:
// target/release/duniter
// ./target/release/duniter
// benchmark
// pallet
// --chain=gdev-benchmark
// --steps=5
// --repeat=2
// --pallet=*
// --extrinsic=*
// --execution=wasm
// --chain
// dev
// --wasm-execution=compiled
// --heap-pages=4096
// --header=./file_header.txt
// --output=./runtime/common/src/weights/
// --pallet
// pallet-certification
// --extrinsic
// *
// --steps
// 50
// --repeat
// 20
// --output=runtime/common/src/weights/
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
......@@ -60,11 +47,11 @@ impl<T: frame_system::Config> pallet_certification::WeightInfo for WeightInfo<T>
/// Proof Skipped: SmithCert CertsByReceiver (max_values: None, max_size: None, mode: Measured)
fn add_cert() -> Weight {
// Proof Size summary in bytes:
// Measured: `761`
// Estimated: `6701`
// Minimum execution time: 135_356_000 picoseconds.
Weight::from_parts(137_673_000, 0)
.saturating_add(Weight::from_parts(0, 6701))
// Measured: `769`
// Estimated: `6709`
// Minimum execution time: 19_525_000 picoseconds.
Weight::from_parts(21_344_000, 0)
.saturating_add(Weight::from_parts(0, 6709))
.saturating_add(T::DbWeight::get().reads(7))
.saturating_add(T::DbWeight::get().writes(4))
}
......@@ -78,11 +65,11 @@ impl<T: frame_system::Config> pallet_certification::WeightInfo for WeightInfo<T>
/// Proof Skipped: SmithMembership Membership (max_values: None, max_size: None, mode: Measured)
fn del_cert() -> Weight {
// Proof Size summary in bytes:
// Measured: `630`
// Estimated: `6570`
// Minimum execution time: 98_544_000 picoseconds.
Weight::from_parts(111_976_000, 0)
.saturating_add(Weight::from_parts(0, 6570))
// Measured: `638`
// Estimated: `6578`
// Minimum execution time: 16_022_000 picoseconds.
Weight::from_parts(17_197_000, 0)
.saturating_add(Weight::from_parts(0, 6578))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(3))
}
......@@ -98,17 +85,71 @@ impl<T: frame_system::Config> pallet_certification::WeightInfo for WeightInfo<T>
/// The range of component `i` is `[2, 1000]`.
fn remove_all_certs_received_by(i: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `558 + i * (35 ±0)`
// Estimated: `4043 + i * (2511 ±0)`
// Minimum execution time: 101_214_000 picoseconds.
Weight::from_parts(102_668_000, 0)
.saturating_add(Weight::from_parts(0, 4043))
// Standard Error: 545_354
.saturating_add(Weight::from_parts(36_672_449, 0).saturating_mul(i.into()))
// Measured: `546 + i * (35 ±0)`
// Estimated: `4020 + i * (2511 ±0)`
// Minimum execution time: 16_488_000 picoseconds.
Weight::from_parts(17_057_000, 0)
.saturating_add(Weight::from_parts(0, 4020))
// Standard Error: 8_341
.saturating_add(Weight::from_parts(4_790_454, 0).saturating_mul(i.into()))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(i.into())))
.saturating_add(T::DbWeight::get().writes(1))
.saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(i.into())))
.saturating_add(Weight::from_parts(0, 2511).saturating_mul(i.into()))
}
/// Storage: SmithCert StorageCertsRemovableOn (r:1 w:0)
/// Proof Skipped: SmithCert StorageCertsRemovableOn (max_values: None, max_size: None, mode: Measured)
fn on_initialize() -> Weight {
// Proof Size summary in bytes:
// Measured: `181`
// Estimated: `3646`
// Minimum execution time: 2_861_000 picoseconds.
Weight::from_parts(3_062_000, 0)
.saturating_add(Weight::from_parts(0, 3646))
.saturating_add(T::DbWeight::get().reads(1))
}
/// Storage: SmithCert CertsByReceiver (r:1 w:1)
/// Proof Skipped: SmithCert CertsByReceiver (max_values: None, max_size: None, mode: Measured)
fn remove_cert_inner_noop() -> Weight {
// Proof Size summary in bytes:
// Measured: `235`
// Estimated: `3700`
// Minimum execution time: 3_973_000 picoseconds.
Weight::from_parts(4_237_000, 0)
.saturating_add(Weight::from_parts(0, 3700))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: SmithCert CertsByReceiver (r:1 w:1)
/// Proof Skipped: SmithCert CertsByReceiver (max_values: None, max_size: None, mode: Measured)
/// Storage: SmithCert StorageIdtyCertMeta (r:2 w:2)
/// Proof Skipped: SmithCert StorageIdtyCertMeta (max_values: None, max_size: None, mode: Measured)
/// Storage: Parameters ParametersStorage (r:1 w:0)
/// Proof Skipped: Parameters ParametersStorage (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: SmithMembership Membership (r:1 w:0)
/// Proof Skipped: SmithMembership Membership (max_values: None, max_size: None, mode: Measured)
fn remove_cert_inner() -> Weight {
// Proof Size summary in bytes:
// Measured: `638`
// Estimated: `6578`
// Minimum execution time: 14_505_000 picoseconds.
Weight::from_parts(15_130_000, 0)
.saturating_add(Weight::from_parts(0, 6578))
.saturating_add(T::DbWeight::get().reads(5))
.saturating_add(T::DbWeight::get().writes(3))
}
/// Storage: Parameters ParametersStorage (r:1 w:0)
/// Proof Skipped: Parameters ParametersStorage (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: SmithMembership Membership (r:1 w:0)
/// Proof Skipped: SmithMembership Membership (max_values: None, max_size: None, mode: Measured)
fn on_remove_cert() -> Weight {
// Proof Size summary in bytes:
// Measured: `277`
// Estimated: `3742`
// Minimum execution time: 5_443_000 picoseconds.
Weight::from_parts(5_707_000, 0)
.saturating_add(Weight::from_parts(0, 3742))
.saturating_add(T::DbWeight::get().reads(2))
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment