Skip to content

Commit

Permalink
fix do_set_weights to use commit_block in commit reveal
Browse files Browse the repository at this point in the history
  • Loading branch information
andreea-popescu-reef committed Nov 4, 2024
1 parent aa521f4 commit 88ab613
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 9 additions & 1 deletion pallets/subtensor/src/macros/dispatches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<T>::CommitRevealEnabled.into())
Expand Down
12 changes: 7 additions & 5 deletions pallets/subtensor/src/subnets/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl<T: Config> Pallet<T> {
Error::<T>::InvalidRevealCommitHashNotMatch
);

Self::do_set_weights(origin, netuid, uids, values, version_key)
Self::do_set_weights(origin, netuid, uids, values, version_key, *commit_block)
})
}

Expand Down Expand Up @@ -185,15 +185,17 @@ impl<T: Config> Pallet<T> {
uids: Vec<u16>,
values: Vec<u16>,
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.
Expand Down Expand Up @@ -242,7 +244,7 @@ impl<T: Config> Pallet<T> {
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::<T>::SettingWeightsTooFast
);

Expand Down Expand Up @@ -286,7 +288,7 @@ impl<T: Config> Pallet<T> {
Weights::<T>::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!(
Expand Down

0 comments on commit 88ab613

Please sign in to comment.