From 3f1497ee0c1a73fe6f35fd766da0112bf1ca31d9 Mon Sep 17 00:00:00 2001 From: John Reed <87283488+JohnReedV@users.noreply.github.com> Date: Wed, 27 Aug 2025 10:32:04 -0700 Subject: [PATCH 1/2] reveal_timelocked_commitments returns weight --- pallets/commitments/src/lib.rs | 44 +++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/pallets/commitments/src/lib.rs b/pallets/commitments/src/lib.rs index 34192b6fa2..f9e9ac579c 100644 --- a/pallets/commitments/src/lib.rs +++ b/pallets/commitments/src/lib.rs @@ -15,10 +15,13 @@ pub use types::*; pub use weights::WeightInfo; use ark_serialize::CanonicalDeserialize; -use frame_support::{BoundedVec, traits::Currency}; +use frame_support::{ + BoundedVec, + traits::{Currency, Get}, +}; use scale_info::prelude::collections::BTreeSet; use sp_runtime::SaturatedConversion; -use sp_runtime::{Saturating, traits::Zero}; +use sp_runtime::{Saturating, Weight, traits::Zero}; use sp_std::{boxed::Box, vec::Vec}; use subtensor_runtime_common::NetUid; use tle::{ @@ -359,10 +362,13 @@ pub mod pallet { #[pallet::hooks] impl Hooks> for Pallet { fn on_initialize(n: BlockNumberFor) -> Weight { - if let Err(e) = Self::reveal_timelocked_commitments() { - log::debug!("Failed to unveil matured commitments on block {n:?}: {e:?}"); + match Self::reveal_timelocked_commitments() { + Ok(w) => w, + Err(e) => { + log::debug!("Failed to unveil matured commitments on block {n:?}: {e:?}"); + Weight::from_parts(0, 0) + } } - Weight::from_parts(0, 0) } } } @@ -399,13 +405,22 @@ pub enum CallType { use frame_support::{dispatch::DispatchResult, pallet_prelude::TypeInfo}; impl Pallet { - pub fn reveal_timelocked_commitments() -> DispatchResult { + pub fn reveal_timelocked_commitments() -> Result { + let mut total_weight = Weight::from_parts(0, 0); + let index = TimelockedIndex::::get(); + total_weight = total_weight.saturating_add(T::DbWeight::get().reads(1)); + for (netuid, who) in index.clone() { - let Some(mut registration) = >::get(netuid, &who) else { + let maybe_registration = >::get(netuid, &who); + total_weight = total_weight.saturating_add(T::DbWeight::get().reads(1)); + + let Some(mut registration) = maybe_registration else { TimelockedIndex::::mutate(|idx| { idx.remove(&(netuid, who.clone())); }); + + total_weight = total_weight.saturating_add(T::DbWeight::get().reads_writes(1, 1)); continue; }; @@ -419,6 +434,7 @@ impl Pallet { encrypted, reveal_round, } => { + total_weight = total_weight.saturating_add(T::DbWeight::get().reads(1)); let pulse = match pallet_drand::Pulses::::get(reveal_round) { Some(p) => p, None => { @@ -486,6 +502,7 @@ impl Pallet { if !revealed_fields.is_empty() { let mut existing_reveals = RevealedCommitments::::get(netuid, &who).unwrap_or_default(); + total_weight = total_weight.saturating_add(T::DbWeight::get().reads(1)); let current_block = >::block_number(); let block_u64 = current_block.saturated_into::(); @@ -507,6 +524,7 @@ impl Pallet { } RevealedCommitments::::insert(netuid, &who, existing_reveals); + total_weight = total_weight.saturating_add(T::DbWeight::get().writes(1)); } registration.info.fields = BoundedVec::try_from(remain_fields) @@ -515,12 +533,19 @@ impl Pallet { match registration.info.fields.is_empty() { true => { >::remove(netuid, &who); + total_weight = total_weight.saturating_add(T::DbWeight::get().writes(1)); + TimelockedIndex::::mutate(|idx| { idx.remove(&(netuid, who.clone())); }); + + total_weight = + total_weight.saturating_add(T::DbWeight::get().reads_writes(1, 1)); } false => { >::insert(netuid, &who, ®istration); + total_weight = total_weight.saturating_add(T::DbWeight::get().writes(1)); + let has_timelock = registration .info .fields @@ -530,11 +555,14 @@ impl Pallet { TimelockedIndex::::mutate(|idx| { idx.remove(&(netuid, who.clone())); }); + + total_weight = + total_weight.saturating_add(T::DbWeight::get().reads_writes(1, 1)); } } } } - Ok(()) + Ok(total_weight) } } From a271c9003923f12e724bd197685275aba3204b58 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 27 Aug 2025 19:39:19 +0000 Subject: [PATCH 2/2] auto-update benchmark weights --- pallets/subtensor/src/macros/dispatches.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index 35439479ab..8123fc5d22 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -120,9 +120,9 @@ mod dispatches { /// - On failure for each failed item in the batch. /// #[pallet::call_index(80)] - #[pallet::weight((Weight::from_parts(95_160_000, 0) - .saturating_add(T::DbWeight::get().reads(14)) - .saturating_add(T::DbWeight::get().writes(2)), DispatchClass::Normal, Pays::No))] + #[pallet::weight((Weight::from_parts(19_540_000, 0) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(0_u64)), DispatchClass::Normal, Pays::No))] pub fn batch_set_weights( origin: OriginFor, netuids: Vec>,