Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7818cf8
Update run_epoch.rs
JohnReedV Jun 26, 2025
48cccca
Update benchmark_action.sh
JohnReedV Jun 27, 2025
b24733d
Revert "Update benchmark_action.sh"
JohnReedV Jun 27, 2025
64968cd
Update run_epoch.rs
JohnReedV Jun 27, 2025
18b054d
refactor
JohnReedV Jul 2, 2025
8942eb8
Merge branch 'devnet-ready' into commit-reveal-last-update-fix
JohnReedV Jul 7, 2025
5b04f5a
bump spec
JohnReedV Jul 8, 2025
fe38a6a
add tests
JohnReedV Jul 9, 2025
59cb77c
add tests
JohnReedV Jul 9, 2025
c46a80c
bump spec
JohnReedV Jul 9, 2025
d039bfa
clippy
JohnReedV Jul 9, 2025
827de33
Merge branch 'devnet-ready' into commit-reveal-last-update-fix
JohnReedV Jul 9, 2025
b6150b1
fix logic
JohnReedV Jul 9, 2025
160a617
add full test coverage
JohnReedV Jul 10, 2025
1e1877a
clippy
JohnReedV Jul 10, 2025
bef199b
zero weights in the next peroid
JohnReedV Jul 10, 2025
3de6f8a
remove unused helper
JohnReedV Jul 10, 2025
8e84c47
Merge branch 'devnet-ready' into commit-reveal-last-update-fix
JohnReedV Jul 10, 2025
d4e3bda
update comment
JohnReedV Jul 10, 2025
aafa2a2
fmt
JohnReedV Jul 10, 2025
8d92896
add tests
JohnReedV Jul 10, 2025
7e83105
bump spec
JohnReedV Jul 10, 2025
cdd4aee
fix bug
JohnReedV Jul 14, 2025
16a9228
fix test
JohnReedV Jul 14, 2025
6bd559a
add test_epoch_masks_incoming_to_sniped_uid_prevents_inheritance
JohnReedV Jul 14, 2025
31ca88e
cap reveal_periods at 100
JohnReedV Jul 14, 2025
9259d5b
test RevealPeriodOutOfBounds
JohnReedV Jul 14, 2025
ada05e9
Merge branch 'devnet-ready' into commit-reveal-last-update-fix
JohnReedV Jul 15, 2025
c193cb4
change check to updated < safe_block
JohnReedV Jul 15, 2025
a62f7a5
update test
JohnReedV Jul 15, 2025
47c6f88
add test for classic block masking
JohnReedV Jul 15, 2025
47dc034
add test_get_first_block_of_epoch
JohnReedV Jul 15, 2025
2617a58
add test_get_first_block_of_epoch_step_blocks
JohnReedV Jul 15, 2025
86c4350
cargo clippy
JohnReedV Jul 15, 2025
7234617
improve all tests
JohnReedV Jul 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ pub mod pallet {
BondsMovingAverageMaxReached,
/// Only root can set negative sigmoid steepness values
NegativeSigmoidSteepness,
/// Reveal Peroid is not within the valid range.
RevealPeriodOutOfBounds,
}
/// Enum for specifying the type of precompile operation.
#[derive(Encode, Decode, TypeInfo, Clone, PartialEq, Eq, Debug, Copy)]
Expand Down Expand Up @@ -1364,6 +1366,12 @@ pub mod pallet {
Error::<T>::SubnetDoesNotExist
);

const MAX_COMMIT_REVEAL_PEROIDS: u64 = 100;
ensure!(
interval <= MAX_COMMIT_REVEAL_PEROIDS,
Error::<T>::RevealPeriodOutOfBounds
);

pallet_subtensor::Pallet::<T>::set_reveal_period(netuid, interval);
log::debug!(
"SetWeightCommitInterval( netuid: {:?}, interval: {:?} ) ",
Expand Down
10 changes: 10 additions & 0 deletions pallets/admin-utils/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,16 @@ fn sudo_set_commit_reveal_weights_interval() {
let netuid = NetUid::from(1);
add_network(netuid, 10);

let too_high = 101;
assert_err!(
AdminUtils::sudo_set_commit_reveal_weights_interval(
<<Test as Config>::RuntimeOrigin>::root(),
netuid,
too_high
),
Error::<Test>::RevealPeriodOutOfBounds
);

let to_be_set = 55;
let init_value = SubtensorModule::get_reveal_period(netuid);

Expand Down
26 changes: 26 additions & 0 deletions pallets/subtensor/src/epoch/run_epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,32 @@ impl<T: Config> Pallet<T> {
);
log::trace!("Weights (permit+diag+outdate): {:?}", &weights);

if Self::get_commit_reveal_weights_enabled(netuid) {
// Precompute safe blocks for all UIDs
let safe_blocks: Vec<u64> = block_at_registration
.iter()
.map(|reg_block| {
let reg_epoch = Self::get_epoch_index(netuid, *reg_block);
let safe_epoch =
reg_epoch.saturating_add(Self::get_reveal_period(netuid).saturating_mul(2));

Self::get_first_block_of_epoch(netuid, safe_epoch)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the reveal period is not tied to the epoch timing, then the check here should be to get the next epoch from the block after the reveal period ends.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So maybe last block of epoch +1, or next epoch, with just the reveal period end block

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the check here should be to get the next epoch from the block after the reveal period ends.

This is what the current implementation already does

  • safe_epoch = reg_epoch + (reveal_period * 2) -> first block of that epoch is the block after the 2-period window.
  • The extra period shields against unrevealed commits made during the deregistration period that still target the vacated UID. Dropping it would remove that protection.
  • reveal_period is in epochs.

})
.collect();

// Mask out weights to recently registered UIDs
weights = vec_mask_sparse_matrix(
&weights,
&last_update,
&safe_blocks,
&|updated, safe_block| updated < safe_block,
);

log::trace!(
"Masking weights to miners inside reveal window (recent registrations masked)"
);
}

// Normalize remaining weights.
inplace_row_normalize_sparse(&mut weights);
log::trace!("Weights (mask+norm): {:?}", &weights);
Expand Down
9 changes: 9 additions & 0 deletions pallets/subtensor/src/subnets/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,4 +1095,13 @@ impl<T: Config> Pallet<T> {
pub fn get_reveal_period(netuid: NetUid) -> u64 {
RevealPeriodEpochs::<T>::get(netuid)
}

pub fn get_first_block_of_epoch(netuid: NetUid, epoch: u64) -> u64 {
let tempo: u64 = Self::get_tempo(netuid) as u64;
let tempo_plus_one: u64 = tempo.saturating_add(1);
let netuid_plus_one: u64 = (u16::from(netuid) as u64).saturating_add(1);
epoch
.saturating_mul(tempo_plus_one)
.saturating_sub(netuid_plus_one)
}
}
Loading
Loading