From 88ab613cba38b6b40b14988ae5d5346ea70512e8 Mon Sep 17 00:00:00 2001 From: Andreea Popescu Date: Mon, 4 Nov 2024 06:03:12 +0000 Subject: [PATCH] fix do_set_weights to use commit_block in commit reveal --- pallets/subtensor/src/macros/dispatches.rs | 10 +++++++++- pallets/subtensor/src/subnets/weights.rs | 12 +++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index a97e4494d..65a95a194 100644 --- a/pallets/subtensor/src/macros/dispatches.rs +++ b/pallets/subtensor/src/macros/dispatches.rs @@ -83,7 +83,15 @@ mod dispatches { version_key: u64, ) -> DispatchResult { if !Self::get_commit_reveal_weights_enabled(netuid) { - return Self::do_set_weights(origin, netuid, dests, weights, version_key); + let current_block: u64 = Self::get_current_block_as_u64(); + return Self::do_set_weights( + origin, + netuid, + dests, + weights, + version_key, + current_block, + ); } Err(Error::::CommitRevealEnabled.into()) diff --git a/pallets/subtensor/src/subnets/weights.rs b/pallets/subtensor/src/subnets/weights.rs index bcb70e183..06a71a7f3 100644 --- a/pallets/subtensor/src/subnets/weights.rs +++ b/pallets/subtensor/src/subnets/weights.rs @@ -119,7 +119,7 @@ impl Pallet { Error::::InvalidRevealCommitHashNotMatch ); - Self::do_set_weights(origin, netuid, uids, values, version_key) + Self::do_set_weights(origin, netuid, uids, values, version_key, *commit_block) }) } @@ -185,15 +185,17 @@ impl Pallet { uids: Vec, values: Vec, version_key: u64, + block: u64, ) -> dispatch::DispatchResult { // --- 1. Check the caller's signature. This is the hotkey of a registered account. let hotkey = ensure_signed(origin)?; log::debug!( - "do_set_weights( origin:{:?} netuid:{:?}, uids:{:?}, values:{:?})", + "do_set_weights( origin:{:?} netuid:{:?}, uids:{:?}, values:{:?}, block:{:?})", hotkey, netuid, uids, - values + values, + block ); // --- Check that the netuid is not the root network. @@ -242,7 +244,7 @@ impl Pallet { let neuron_uid = Self::get_uid_for_net_and_hotkey(netuid, &hotkey)?; let current_block: u64 = Self::get_current_block_as_u64(); ensure!( - Self::check_rate_limit(netuid, neuron_uid, current_block), + Self::check_rate_limit(netuid, neuron_uid, block), Error::::SettingWeightsTooFast ); @@ -286,7 +288,7 @@ impl Pallet { Weights::::insert(netuid, neuron_uid, zipped_weights); // --- 18. Set the activity for the weights on this network. - Self::set_last_update_for_uid(netuid, neuron_uid, current_block); + Self::set_last_update_for_uid(netuid, neuron_uid, block); // --- 19. Emit the tracking event. log::debug!(