From c42e6e0a724bed2f445f50730b37751fe6f32ed6 Mon Sep 17 00:00:00 2001 From: bgallois <benjamin@gallois.cc> Date: Thu, 7 Mar 2024 15:28:37 +0100 Subject: [PATCH] simplify weight accounting --- pallets/membership/src/lib.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pallets/membership/src/lib.rs b/pallets/membership/src/lib.rs index 06b127ed0..afa6290d5 100644 --- a/pallets/membership/src/lib.rs +++ b/pallets/membership/src/lib.rs @@ -293,20 +293,14 @@ pub mod pallet { /// perform membership removal pub fn do_remove_membership(idty_id: T::IdtyId, reason: MembershipRemovalReason) -> 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)); - }; - + let mut weight = T::DbWeight::get().reads_writes(2, 3); if let Some(membership_data) = Membership::<T>::take(idty_id) { - add_db_reads_writes(1, 1); Self::unschedule_membership_expiry(idty_id, membership_data.expire_on); - add_db_reads_writes(1, 2); Self::deposit_event(Event::MembershipRemoved { member: idty_id, reason, }); - weight = weight.saturating_add(T::OnRemoveMembership::on_removed(&idty_id)); + weight += T::OnRemoveMembership::on_removed(&idty_id); } weight } -- GitLab