Skip to content

Commit ba7e34c

Browse files
committed
update comments
1 parent 8a97a12 commit ba7e34c

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

pallets/subtensor/src/subnets/weights.rs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,78 +19,88 @@ impl<T: Config> Pallet<T> {
1919
///
2020
/// # Raises:
2121
/// * `CommitRevealDisabled`:
22-
/// - Attempting to commit when the commit-reveal mechanism is disabled.
22+
/// - Raised if commit-reveal is disabled for the specified network.
23+
///
24+
/// * `HotKeyNotRegisteredInSubNet`:
25+
/// - Raised if the hotkey is not registered on the specified network.
26+
///
27+
/// * `CommittingWeightsTooFast`:
28+
/// - Raised if the hotkey's commit rate exceeds the permitted limit.
2329
///
2430
/// * `TooManyUnrevealedCommits`:
25-
/// - Attempting to commit when the user has more than the allowed limit of unrevealed commits.
31+
/// - Raised if the hotkey has reached the maximum number of unrevealed commits.
32+
///
33+
/// # Events:
34+
/// * `WeightsCommitted`:
35+
/// - Emitted upon successfully storing the weight hash.
2636
pub fn do_commit_weights(
2737
origin: T::RuntimeOrigin,
2838
netuid: u16,
2939
commit_hash: H256,
3040
) -> DispatchResult {
31-
// --- 1. Check the caller's signature (hotkey).
41+
// 1. Verify the caller's signature (hotkey).
3242
let who = ensure_signed(origin)?;
3343

34-
log::debug!("do_commit_weights( hotkey:{:?} netuid:{:?})", who, netuid);
44+
log::debug!("do_commit_weights(hotkey: {:?}, netuid: {:?})", who, netuid);
3545

36-
// --- 2. Ensure commit-reveal is enabled for the network.
46+
// 2. Ensure commit-reveal is enabled.
3747
ensure!(
3848
Self::get_commit_reveal_weights_enabled(netuid),
3949
Error::<T>::CommitRevealDisabled
4050
);
4151

52+
// 3. Ensure the hotkey is registered on the network.
4253
ensure!(
4354
Self::is_hotkey_registered_on_network(netuid, &who),
4455
Error::<T>::HotKeyNotRegisteredInSubNet
4556
);
4657

47-
let commit_block: u64 = Self::get_current_block_as_u64();
48-
let neuron_uid: u16 = Self::get_uid_for_net_and_hotkey(netuid, &who)?;
58+
// 4. Check that the commit rate does not exceed the allowed frequency.
59+
let commit_block = Self::get_current_block_as_u64();
60+
let neuron_uid = Self::get_uid_for_net_and_hotkey(netuid, &who)?;
4961
ensure!(
5062
Self::check_rate_limit(netuid, neuron_uid, commit_block),
5163
Error::<T>::CommittingWeightsTooFast
5264
);
5365

54-
// --- 3. Calculate the reveal blocks based on tempo and reveal period.
66+
// 5. Calculate the reveal blocks based on network tempo and reveal period.
5567
let (first_reveal_block, last_reveal_block) = Self::get_reveal_blocks(netuid, commit_block);
5668

57-
// --- 4. Mutate the WeightCommits to retrieve existing commits for the user.
69+
// 6. Retrieve or initialize the VecDeque of commits for the hotkey.
5870
WeightCommits::<T>::try_mutate(netuid, &who, |maybe_commits| -> DispatchResult {
59-
// --- 5. Take the existing commits or create a new VecDeque.
6071
let mut commits: VecDeque<(H256, u64, u64, u64)> =
6172
maybe_commits.take().unwrap_or_default();
6273

63-
// --- 6. Remove any expired commits from the front of the queue.
74+
// 7. Remove any expired commits from the front of the queue.
6475
while let Some((_, commit_block_existing, _, _)) = commits.front() {
6576
if Self::is_commit_expired(netuid, *commit_block_existing) {
66-
// Remove the expired commit
6777
commits.pop_front();
6878
} else {
6979
break;
7080
}
7181
}
7282

73-
// --- 7. Check if the current number of unrevealed commits is within the allowed limit.
83+
// 8. Verify that the number of unrevealed commits is within the allowed limit.
7484
ensure!(commits.len() < 10, Error::<T>::TooManyUnrevealedCommits);
7585

76-
// --- 8. Append the new commit to the queue.
86+
// 9. Append the new commit with calculated reveal blocks.
7787
commits.push_back((
7888
commit_hash,
7989
commit_block,
8090
first_reveal_block,
8191
last_reveal_block,
8292
));
8393

84-
// --- 9. Store the updated queue back to storage.
94+
// 10. Store the updated commits queue back to storage.
8595
*maybe_commits = Some(commits);
8696

87-
// --- 10. Emit the WeightsCommitted event.
97+
// 11. Emit the WeightsCommitted event
8898
Self::deposit_event(Event::WeightsCommitted(who.clone(), netuid, commit_hash));
8999

90-
// --- 11. Set last update for the UID
100+
// 12. Update the last commit block for the hotkey's UID.
91101
Self::set_last_update_for_uid(netuid, neuron_uid, commit_block);
92102

93-
// --- 12. Return ok.
103+
// 13. Return success.
94104
Ok(())
95105
})
96106
}

0 commit comments

Comments
 (0)