Skip to content

Commit 90ae7e6

Browse files
fix do_set_weights to use commit_block in commit reveal
1 parent c05342a commit 90ae7e6

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

pallets/subtensor/src/macros/dispatches.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,15 @@ mod dispatches {
8383
version_key: u64,
8484
) -> DispatchResult {
8585
if !Self::get_commit_reveal_weights_enabled(netuid) {
86-
return Self::do_set_weights(origin, netuid, dests, weights, version_key);
86+
let current_block: u64 = Self::get_current_block_as_u64();
87+
return Self::do_set_weights(
88+
origin,
89+
netuid,
90+
dests,
91+
weights,
92+
version_key,
93+
current_block,
94+
);
8795
}
8896

8997
Err(Error::<T>::CommitRevealEnabled.into())

pallets/subtensor/src/subnets/weights.rs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,13 @@ impl<T: Config> Pallet<T> {
204204
.position(|(hash, _, _, _)| *hash == provided_hash)
205205
{
206206
// --- 8. Get the commit block for the commit being revealed.
207-
let (_, commit_block, _, _) = commits
207+
let (_, commit_block, _, _) = *commits
208208
.get(position)
209209
.ok_or(Error::<T>::NoWeightsCommitFound)?;
210210

211211
// --- 9. Ensure the commit is ready to be revealed in the current block range.
212212
ensure!(
213-
Self::is_reveal_block_range(netuid, *commit_block),
213+
Self::is_reveal_block_range(netuid, commit_block),
214214
Error::<T>::RevealTooEarly
215215
);
216216

@@ -225,7 +225,14 @@ impl<T: Config> Pallet<T> {
225225
}
226226

227227
// --- 12. Proceed to set the revealed weights.
228-
Self::do_set_weights(origin, netuid, uids.clone(), values.clone(), version_key)?;
228+
Self::do_set_weights(
229+
origin,
230+
netuid,
231+
uids.clone(),
232+
values.clone(),
233+
version_key,
234+
commit_block,
235+
)?;
229236

230237
// --- 13. Emit the WeightsRevealed event.
231238
Self::deposit_event(Event::WeightsRevealed(who.clone(), netuid, provided_hash));
@@ -391,10 +398,18 @@ impl<T: Config> Pallet<T> {
391398
.position(|(hash, _, _, _)| *hash == provided_hash)
392399
{
393400
// --- 8b. Remove the commit from the queue.
394-
commits.remove(position);
401+
let (_, commit_block, _, _) =
402+
commits.remove(position).expect("commit_block exists");
395403

396404
// --- 8c. Proceed to set the revealed weights.
397-
Self::do_set_weights(origin.clone(), netuid, uids, values, version_key)?;
405+
Self::do_set_weights(
406+
origin.clone(),
407+
netuid,
408+
uids,
409+
values,
410+
version_key,
411+
commit_block,
412+
)?;
398413

399414
// --- 8d. Collect the revealed hash.
400415
revealed_hashes.push(provided_hash);
@@ -484,15 +499,17 @@ impl<T: Config> Pallet<T> {
484499
uids: Vec<u16>,
485500
values: Vec<u16>,
486501
version_key: u64,
502+
block: u64,
487503
) -> dispatch::DispatchResult {
488504
// --- 1. Check the caller's signature. This is the hotkey of a registered account.
489505
let hotkey = ensure_signed(origin)?;
490506
log::debug!(
491-
"do_set_weights( origin:{:?} netuid:{:?}, uids:{:?}, values:{:?})",
507+
"do_set_weights( origin:{:?} netuid:{:?}, uids:{:?}, values:{:?}, block:{:?})",
492508
hotkey,
493509
netuid,
494510
uids,
495-
values
511+
values,
512+
block
496513
);
497514

498515
// --- Check that the netuid is not the root network.
@@ -588,7 +605,7 @@ impl<T: Config> Pallet<T> {
588605

589606
// --- 18. Set the activity for the weights on this network.
590607
if !Self::get_commit_reveal_weights_enabled(netuid) {
591-
Self::set_last_update_for_uid(netuid, neuron_uid, current_block);
608+
Self::set_last_update_for_uid(netuid, neuron_uid, block);
592609
}
593610

594611
// --- 19. Emit the tracking event.

pallets/subtensor/tests/weights.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,7 @@ fn test_commit_reveal_tempo_interval() {
15541554
),
15551555
Error::<Test>::NoWeightsCommitFound
15561556
);
1557+
assert_eq!(SubtensorModule::get_last_update(netuid)[1], 0);
15571558

15581559
assert_ok!(SubtensorModule::commit_weights(
15591560
RuntimeOrigin::signed(hotkey),
@@ -1575,6 +1576,7 @@ fn test_commit_reveal_tempo_interval() {
15751576
),
15761577
Error::<Test>::ExpiredWeightCommit
15771578
);
1579+
assert_eq!(SubtensorModule::get_last_update(netuid)[1], 105);
15781580

15791581
assert_ok!(SubtensorModule::commit_weights(
15801582
RuntimeOrigin::signed(hotkey),
@@ -1595,6 +1597,7 @@ fn test_commit_reveal_tempo_interval() {
15951597
),
15961598
Error::<Test>::RevealTooEarly
15971599
);
1600+
assert_eq!(SubtensorModule::get_last_update(netuid)[1], 301);
15981601

15991602
step_epochs(1, netuid);
16001603

@@ -1606,6 +1609,7 @@ fn test_commit_reveal_tempo_interval() {
16061609
salt,
16071610
version_key,
16081611
));
1612+
assert_eq!(SubtensorModule::get_last_update(netuid)[1], 301);
16091613
});
16101614
}
16111615

0 commit comments

Comments
 (0)