@@ -54,36 +54,39 @@ async fn generate_commit(
54
54
. unwrap ( )
55
55
. as_secs ( ) ;
56
56
57
- // Compute the current epoch index
57
+ // Compute current epoch
58
58
let tempo_plus_one = tempo + 1 ;
59
59
let netuid_plus_one = ( netuid as u64 ) + 1 ;
60
60
let block_with_offset = current_block + netuid_plus_one;
61
+ let current_epoch = block_with_offset / tempo_plus_one;
61
62
62
- // If at an exact epoch boundary, treat this as the new epoch start.
63
- let is_epoch_boundary = ( block_with_offset % tempo_plus_one) == 0 ;
64
- let base_epoch = block_with_offset / tempo_plus_one;
65
- let current_epoch = if is_epoch_boundary {
66
- base_epoch + 1
67
- } else {
68
- base_epoch
69
- } ;
63
+ // Compute initial reveal epoch
64
+ let mut reveal_epoch = current_epoch + subnet_reveal_period_epochs;
70
65
71
- // Compute the reveal epoch
72
- let reveal_epoch = current_epoch + subnet_reveal_period_epochs ;
66
+ // Compute the block when the reveal epoch starts
67
+ let mut reveal_block_number = reveal_epoch * tempo_plus_one - netuid_plus_one ;
73
68
74
- // Compute the block number when the reveal epoch starts
75
- let reveal_block_number = reveal_epoch * tempo_plus_one - netuid_plus_one ;
69
+ // Compute how many blocks until reveal
70
+ let mut blocks_until_reveal = reveal_block_number . saturating_sub ( current_block ) ;
76
71
77
- // Compute the number of blocks until the reveal epoch
78
- let blocks_until_reveal = reveal_block_number . saturating_sub ( current_block ) ;
72
+ // Compute time until reveal in seconds
73
+ let mut time_until_reveal = blocks_until_reveal * block_time ;
79
74
80
- // Compute the time until the reveal in seconds
81
- let time_until_reveal = blocks_until_reveal * block_time;
75
+ // Since SUBTENSOR_PULSE_DELAY is in pulses, we must ensure that we have at least
76
+ // SUBTENSOR_PULSE_DELAY pulses worth of time before reveal.
77
+ // Each pulse is 'period' seconds, so we need at least SUBTENSOR_PULSE_DELAY * period seconds.
78
+ while time_until_reveal < SUBTENSOR_PULSE_DELAY * period {
79
+ // Not enough lead time, push to next epoch
80
+ reveal_epoch += 1 ;
81
+ reveal_block_number = reveal_epoch * tempo_plus_one - netuid_plus_one;
82
+ blocks_until_reveal = reveal_block_number. saturating_sub ( current_block) ;
83
+ time_until_reveal = blocks_until_reveal * block_time;
84
+ }
82
85
83
86
// Compute the reveal time in seconds since UNIX_EPOCH
84
87
let reveal_time = now + time_until_reveal;
85
88
86
- // Compute the reveal round, ensuring we round up
89
+ // Compute the reveal round, ensure we pick an older Drand round by subtracting SUBTENSOR_PULSE_DELAY pulses.
87
90
let reveal_round = ( ( reveal_time - genesis_time + period - 1 ) / period) - SUBTENSOR_PULSE_DELAY ;
88
91
89
92
// 3. Deserialize the public key
0 commit comments