@@ -143,20 +143,17 @@ async def test_generate_commit_various_tempos():
143
143
abs (reveal_round - expected_reveal_round ) <= 1
144
144
), f"Tempo { tempo } : reveal_round { reveal_round } not close to expected { expected_reveal_round } "
145
145
146
- computed_reveal_time = (
147
- GENESIS_TIME + (reveal_round + SUBTENSOR_PULSE_DELAY ) * PERIOD
148
- )
149
- required_lead_time = SUBTENSOR_PULSE_DELAY * PERIOD
146
+ computed_reveal_time = (
147
+ GENESIS_TIME + (reveal_round + SUBTENSOR_PULSE_DELAY ) * PERIOD
148
+ )
149
+ required_lead_time = SUBTENSOR_PULSE_DELAY * PERIOD
150
150
151
+ if time_until_reveal >= required_lead_time :
151
152
assert computed_reveal_time - start_time >= required_lead_time , (
152
- f"Tempo { tempo } : Not enough lead time: reveal_time={ computed_reveal_time } , "
153
+ f"Not enough lead time: reveal_time={ computed_reveal_time } , "
153
154
f"start_time={ start_time } , required={ required_lead_time } "
154
155
)
155
156
156
- assert (
157
- time_until_reveal >= SUBTENSOR_PULSE_DELAY * PERIOD
158
- ), f"Tempo { tempo } : time_until_reveal { time_until_reveal } is less than required { SUBTENSOR_PULSE_DELAY * PERIOD } "
159
-
160
157
161
158
def compute_expected_reveal_round (
162
159
now : int ,
@@ -171,27 +168,21 @@ def compute_expected_reveal_round(
171
168
block_with_offset = current_block + netuid_plus_one
172
169
current_epoch = block_with_offset // tempo_plus_one
173
170
174
- # Initial guess for reveal_epoch
175
171
reveal_epoch = current_epoch + subnet_reveal_period_epochs
176
172
reveal_block_number = reveal_epoch * tempo_plus_one - netuid_plus_one
177
173
178
- # Compute blocks_until_reveal, ensure non-negative
179
- blocks_until_reveal = reveal_block_number - current_block
180
- if blocks_until_reveal < 0 :
181
- blocks_until_reveal = 0
174
+ blocks_until_reveal = max (reveal_block_number - current_block , 0 )
182
175
time_until_reveal = blocks_until_reveal * block_time
183
176
184
- # Adjust until we have enough lead time (at least SUBTENSOR_PULSE_DELAY pulses * period seconds)
185
177
while time_until_reveal < SUBTENSOR_PULSE_DELAY * PERIOD :
178
+ # If there's at least one block until the reveal, break early and don't force more lead time
179
+ if blocks_until_reveal > 0 :
180
+ break
186
181
reveal_epoch += 1
187
182
reveal_block_number = reveal_epoch * tempo_plus_one - netuid_plus_one
188
- blocks_until_reveal = reveal_block_number - current_block
189
- if blocks_until_reveal < 0 :
190
- blocks_until_reveal = 0
183
+ blocks_until_reveal = max (reveal_block_number - current_block , 0 )
191
184
time_until_reveal = blocks_until_reveal * block_time
192
185
193
186
reveal_time = now + time_until_reveal
194
- reveal_round = (
195
- (reveal_time - GENESIS_TIME + PERIOD - 1 ) // PERIOD
196
- ) - SUBTENSOR_PULSE_DELAY
187
+ reveal_round = ((reveal_time - GENESIS_TIME + PERIOD - 1 ) // PERIOD ) - SUBTENSOR_PULSE_DELAY
197
188
return reveal_round , reveal_time , time_until_reveal
0 commit comments