Skip to content

Commit c54fc3d

Browse files
author
EchoBT
committed
fix: always emit phase events based on tempo timing
Previously, phase detection required commit_reveal_enabled=true. This broke mechanism weights which always use commit-reveal. Now phases are calculated based on tempo timing regardless of the CommitRevealWeightsEnabled subnet parameter: - Evaluation: 0% - 75% of epoch - CommitWindow: 75% - 87.5% of epoch - RevealWindow: 87.5% - 100% of epoch This ensures CommitWindowOpen and RevealWindowOpen events fire correctly for mechanism weight submission.
1 parent c4e6df8 commit c54fc3d

1 file changed

Lines changed: 40 additions & 10 deletions

File tree

src/blocks/epoch_tracker.rs

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,21 +147,26 @@ impl EpochTracker {
147147
}
148148
}
149149

150-
/// Determine the current phase based on block position
150+
/// Determine the current phase based on block position in epoch
151+
///
152+
/// Always calculates phase based on tempo timing, regardless of commit_reveal_enabled.
153+
/// This ensures mechanism weights (which always use commit-reveal) work correctly.
154+
///
155+
/// Phases:
156+
/// - Evaluation: 0% - 75% of epoch
157+
/// - CommitWindow: 75% - 87.5% of epoch
158+
/// - RevealWindow: 87.5% - 100% of epoch
151159
fn determine_phase(&self, current_block: u64, epoch_start_block: u64) -> EpochPhase {
152-
if !self.commit_reveal_enabled {
160+
if self.tempo == 0 {
153161
return EpochPhase::Evaluation;
154162
}
155163

156164
let blocks_into_epoch = current_block.saturating_sub(epoch_start_block);
157165

158-
// Bittensor commit-reveal windows:
159-
// - Commit window: blocks before reveal window
160-
// - Reveal window: last portion of epoch
161-
// The exact timing depends on subnet parameters
162-
163-
// Default: last 25% of epoch is commit/reveal
164-
// Last 12.5% is reveal, 12.5% before that is commit
166+
// Bittensor commit-reveal windows based on tempo:
167+
// - Last 12.5% is reveal window
168+
// - 12.5% before that is commit window
169+
// - First 75% is evaluation
165170
let reveal_start = (self.tempo * 7) / 8; // 87.5%
166171
let commit_start = (self.tempo * 3) / 4; // 75%
167172

@@ -260,7 +265,7 @@ mod tests {
260265
let mut tracker = EpochTracker {
261266
netuid: 1,
262267
tempo: 360,
263-
commit_reveal_enabled: false,
268+
commit_reveal_enabled: false, // Phases still work even if this is false
264269
reveal_period_epochs: 1,
265270
last_epoch_number: 0,
266271
};
@@ -278,4 +283,29 @@ mod tests {
278283
// No transition at block 400 (same epoch)
279284
assert!(tracker.check_epoch_transition(400).is_none());
280285
}
286+
287+
#[test]
288+
fn test_phases_work_regardless_of_commit_reveal_enabled() {
289+
// Even with commit_reveal_enabled = false, phases should be calculated
290+
// This is important for mechanism weights which always use commit-reveal
291+
let tracker = EpochTracker {
292+
netuid: 1,
293+
tempo: 360,
294+
commit_reveal_enabled: false,
295+
reveal_period_epochs: 1,
296+
last_epoch_number: 0,
297+
};
298+
299+
// Block 100 - evaluation phase
300+
let info = tracker.get_epoch_info(100);
301+
assert_eq!(info.phase, EpochPhase::Evaluation);
302+
303+
// Block 270 - commit window (75% of 360)
304+
let info = tracker.get_epoch_info(270);
305+
assert_eq!(info.phase, EpochPhase::CommitWindow);
306+
307+
// Block 315 - reveal window (87.5% of 360)
308+
let info = tracker.get_epoch_info(315);
309+
assert_eq!(info.phase, EpochPhase::RevealWindow);
310+
}
281311
}

0 commit comments

Comments
 (0)