From 4bb71f5bf4553a7ccf5df255cef33898df7727b6 Mon Sep 17 00:00:00 2001 From: bgallois <benjamin@gallois.cc> Date: Thu, 7 Mar 2024 13:43:49 +0100 Subject: [PATCH] remove weight accounting OnNewIdty --- pallets/certification/src/benchmarking.rs | 6 +++--- pallets/certification/src/lib.rs | 4 +--- pallets/duniter-wot/src/lib.rs | 10 ++-------- pallets/identity/src/traits.rs | 8 +++----- pallets/quota/src/lib.rs | 9 +-------- 5 files changed, 10 insertions(+), 27 deletions(-) diff --git a/pallets/certification/src/benchmarking.rs b/pallets/certification/src/benchmarking.rs index 1109f97a3..7084dc11d 100644 --- a/pallets/certification/src/benchmarking.rs +++ b/pallets/certification/src/benchmarking.rs @@ -38,7 +38,7 @@ mod benchmarks { fn add_certs<T: Config>(i: u32, receiver: T::IdtyIndex) -> Result<(), &'static str> { Pallet::<T>::remove_all_certs_received_by(RawOrigin::Root.into(), receiver)?; for j in 1..i { - let _ = Pallet::<T>::do_add_cert_checked(j.into(), receiver, false); + Pallet::<T>::do_add_cert_checked(j.into(), receiver, false); } assert!( CertsByReceiver::<T>::get(receiver).len() as u32 == i - 1, @@ -103,7 +103,7 @@ mod benchmarks { let receiver: T::IdtyIndex = 2.into(); // try to add cert if missing, else ignore // this depends on initial data - let _ = Pallet::<T>::do_add_cert_checked(issuer, receiver, false); + Pallet::<T>::do_add_cert_checked(issuer, receiver, false); #[extrinsic_call] _(RawOrigin::Root, issuer, receiver); @@ -154,7 +154,7 @@ mod benchmarks { let issuer: T::IdtyIndex = 1.into(); let receiver: T::IdtyIndex = 0.into(); Pallet::<T>::do_remove_cert(issuer, receiver, None); - let _ = Pallet::<T>::do_add_cert_checked(issuer, receiver, false); + Pallet::<T>::do_add_cert_checked(issuer, receiver, false); let block_number = T::ValidityPeriod::get(); frame_system::pallet::Pallet::<T>::set_block_number(block_number); diff --git a/pallets/certification/src/lib.rs b/pallets/certification/src/lib.rs index 0f237cb51..56bf87f5e 100644 --- a/pallets/certification/src/lib.rs +++ b/pallets/certification/src/lib.rs @@ -360,21 +360,19 @@ pub mod pallet { issuer: T::IdtyIndex, receiver: T::IdtyIndex, verify_rules: bool, - ) -> Weight { + ) { let block_number = frame_system::pallet::Pallet::<T>::block_number(); if verify_rules { // only verify internal rules if asked if let Err(e) = Self::check_add_cert_internal(issuer, receiver, block_number) { sp_std::if_std! {println!("fail to force add cert: {:?}", e)} - return T::WeightInfo::do_add_cert_checked(); } } if let Err(e) = Self::try_add_cert(block_number, issuer, receiver) { sp_std::if_std! {println!("fail to force add cert: {:?}", e)} } - T::WeightInfo::do_add_cert_checked() } /// perform cert addition if not existing, else CertAlreadyExists diff --git a/pallets/duniter-wot/src/lib.rs b/pallets/duniter-wot/src/lib.rs index a3076f124..4ff1bfce9 100644 --- a/pallets/duniter-wot/src/lib.rs +++ b/pallets/duniter-wot/src/lib.rs @@ -222,15 +222,9 @@ where // implement identity event handler impl<T: Config> pallet_identity::traits::OnNewIdty<T> for Pallet<T> { - fn on_created(idty_index: &IdtyIndex, creator: &IdtyIndex) -> Weight { - let mut weight = Weight::zero(); + fn on_created(idty_index: &IdtyIndex, creator: &IdtyIndex) { // identity just has been created, a cert must be added - weight = weight.saturating_add(<pallet_certification::Pallet<T>>::do_add_cert_checked( - *creator, - *idty_index, - true, - )); - weight + <pallet_certification::Pallet<T>>::do_add_cert_checked(*creator, *idty_index, true); } } diff --git a/pallets/identity/src/traits.rs b/pallets/identity/src/traits.rs index ed8abc16a..65679ca7d 100644 --- a/pallets/identity/src/traits.rs +++ b/pallets/identity/src/traits.rs @@ -36,7 +36,7 @@ pub trait IdtyNameValidator { } pub trait OnNewIdty<T: Config> { - fn on_created(idty_index: &T::IdtyIndex, creator: &T::IdtyIndex) -> Weight; + fn on_created(idty_index: &T::IdtyIndex, creator: &T::IdtyIndex); } pub trait OnRemoveIdty<T: Config> { @@ -47,10 +47,8 @@ pub trait OnRemoveIdty<T: Config> { #[impl_for_tuples(5)] #[allow(clippy::let_and_return)] impl<T: Config> OnNewIdty<T> for Tuple { - fn on_created(idty_index: &T::IdtyIndex, creator: &T::IdtyIndex) -> Weight { - let mut weight = Weight::zero(); - for_tuples!( #( weight = weight.saturating_add(Tuple::on_created(idty_index, creator)); )* ); - weight + fn on_created(idty_index: &T::IdtyIndex, creator: &T::IdtyIndex) { + for_tuples!( #( Tuple::on_created(idty_index, creator); )* ); } } diff --git a/pallets/quota/src/lib.rs b/pallets/quota/src/lib.rs index 398f67aad..85d0a35e2 100644 --- a/pallets/quota/src/lib.rs +++ b/pallets/quota/src/lib.rs @@ -339,12 +339,7 @@ fn is_eligible_for_refund<T: pallet_identity::Config>(_identity: IdtyId<T>) -> b // implement identity event handler impl<T: Config> pallet_identity::traits::OnNewIdty<T> for Pallet<T> { - fn on_created(idty_index: &IdtyId<T>, _creator: &T::IdtyIndex) -> Weight { - let mut weight = Weight::zero(); - let mut add_db_reads_writes = |reads, writes| { - weight = weight.saturating_add(T::DbWeight::get().reads_writes(reads, writes)); - }; - + fn on_created(idty_index: &IdtyId<T>, _creator: &T::IdtyIndex) { IdtyQuota::<T>::insert( idty_index, Quota { @@ -352,8 +347,6 @@ impl<T: Config> pallet_identity::traits::OnNewIdty<T> for Pallet<T> { amount: BalanceOf::<T>::zero(), }, ); - add_db_reads_writes(0, 1); - weight } } -- GitLab