diff --git a/pallets/subtensor/src/macros/dispatches.rs b/pallets/subtensor/src/macros/dispatches.rs index e98ecbd6a..8f645f1af 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 87042f456..d3e311990 100644 --- a/pallets/subtensor/src/subnets/weights.rs +++ b/pallets/subtensor/src/subnets/weights.rs @@ -204,13 +204,13 @@ impl Pallet { .position(|(hash, _, _, _)| *hash == provided_hash) { // --- 8. Get the commit block for the commit being revealed. - let (_, commit_block, _, _) = commits + let (_, commit_block, _, _) = *commits .get(position) .ok_or(Error::::NoWeightsCommitFound)?; // --- 9. Ensure the commit is ready to be revealed in the current block range. ensure!( - Self::is_reveal_block_range(netuid, *commit_block), + Self::is_reveal_block_range(netuid, commit_block), Error::::RevealTooEarly ); @@ -225,7 +225,14 @@ impl Pallet { } // --- 12. Proceed to set the revealed weights. - Self::do_set_weights(origin, netuid, uids.clone(), values.clone(), version_key)?; + Self::do_set_weights( + origin, + netuid, + uids.clone(), + values.clone(), + version_key, + commit_block, + )?; // --- 13. Emit the WeightsRevealed event. Self::deposit_event(Event::WeightsRevealed(who.clone(), netuid, provided_hash)); @@ -391,10 +398,18 @@ impl Pallet { .position(|(hash, _, _, _)| *hash == provided_hash) { // --- 8b. Remove the commit from the queue. - commits.remove(position); + let (_, commit_block, _, _) = + commits.remove(position).expect("commit_block exists"); // --- 8c. Proceed to set the revealed weights. - Self::do_set_weights(origin.clone(), netuid, uids, values, version_key)?; + Self::do_set_weights( + origin.clone(), + netuid, + uids, + values, + version_key, + commit_block, + )?; // --- 8d. Collect the revealed hash. revealed_hashes.push(provided_hash); @@ -484,15 +499,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. @@ -588,7 +605,7 @@ impl Pallet { // --- 18. Set the activity for the weights on this network. if !Self::get_commit_reveal_weights_enabled(netuid) { - 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. diff --git a/pallets/subtensor/tests/weights.rs b/pallets/subtensor/tests/weights.rs index 7dbeba288..a7a0b79db 100644 --- a/pallets/subtensor/tests/weights.rs +++ b/pallets/subtensor/tests/weights.rs @@ -1554,6 +1554,7 @@ fn test_commit_reveal_tempo_interval() { ), Error::::NoWeightsCommitFound ); + assert_eq!(SubtensorModule::get_last_update(netuid)[1], 0); assert_ok!(SubtensorModule::commit_weights( RuntimeOrigin::signed(hotkey), @@ -1575,6 +1576,7 @@ fn test_commit_reveal_tempo_interval() { ), Error::::ExpiredWeightCommit ); + assert_eq!(SubtensorModule::get_last_update(netuid)[1], 105); assert_ok!(SubtensorModule::commit_weights( RuntimeOrigin::signed(hotkey), @@ -1595,6 +1597,7 @@ fn test_commit_reveal_tempo_interval() { ), Error::::RevealTooEarly ); + assert_eq!(SubtensorModule::get_last_update(netuid)[1], 301); step_epochs(1, netuid); @@ -1606,6 +1609,7 @@ fn test_commit_reveal_tempo_interval() { salt, version_key, )); + assert_eq!(SubtensorModule::get_last_update(netuid)[1], 301); }); }