Skip to content

Commit b25f5b2

Browse files
Merge pull request #14 from opentensor/release/0.2.0
Release/0.2.0
2 parents ac0ce8e + cad6cdc commit b25f5b2

File tree

5 files changed

+29
-25
lines changed

5 files changed

+29
-25
lines changed

CHANGELOG.MD

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## v0.2.0 /2025-01-15
4+
5+
## What's Changed
6+
* fix epoch jump when epoch_block is close by @JohnReedV in https://github.com/opentensor/bittensor-commit-reveal/pull/12
7+
* Backmerge staging to main 0.1.0 @ibraheem-opentensor in https://github.com/opentensor/bittensor-commit-reveal/pull/13
8+
9+
**Full Changelog**: https://github.com/opentensor/bittensor-commit-reveal/compare/v0.1.0...v0.2.0
10+
311
## v0.1.0 /2024-12-12
412

513
## What's Changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bittensor-commit-reveal"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
edition = "2021"
55

66
[lib]

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "bittensor-commit-reveal"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
description = ""
55
readme = "README.md"
66
license = {file = "LICENSE"}

src/lib.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,19 @@ async fn generate_commit(
5858
// Calculate reveal epoch and ensure enough time for SUBTENSOR_PULSE_DELAY pulses
5959
let mut reveal_epoch = current_epoch + subnet_reveal_period_epochs;
6060
let mut reveal_block_number = reveal_epoch * tempo_plus_one - netuid_plus_one;
61-
let mut blocks_until_reveal = reveal_block_number.saturating_sub(current_block);
61+
let mut blocks_until_reveal = reveal_block_number - current_block;
6262
let mut time_until_reveal = blocks_until_reveal * block_time;
6363

6464
// Ensure at least SUBTENSOR_PULSE_DELAY * period seconds lead time
6565
while time_until_reveal < SUBTENSOR_PULSE_DELAY * period {
66+
67+
if blocks_until_reveal > 1 {
68+
break;
69+
}
70+
6671
reveal_epoch += 1;
6772
reveal_block_number = reveal_epoch * tempo_plus_one - netuid_plus_one;
68-
blocks_until_reveal = reveal_block_number.saturating_sub(current_block);
73+
blocks_until_reveal = reveal_block_number - current_block;
6974
time_until_reveal = blocks_until_reveal * block_time;
7075
}
7176

src/tests/test_commit_reveal.py

+12-21
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,17 @@ async def test_generate_commit_various_tempos():
143143
abs(reveal_round - expected_reveal_round) <= 1
144144
), f"Tempo {tempo}: reveal_round {reveal_round} not close to expected {expected_reveal_round}"
145145

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
150150

151+
if time_until_reveal >= required_lead_time:
151152
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}, "
153154
f"start_time={start_time}, required={required_lead_time}"
154155
)
155156

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-
160157

161158
def compute_expected_reveal_round(
162159
now: int,
@@ -171,27 +168,21 @@ def compute_expected_reveal_round(
171168
block_with_offset = current_block + netuid_plus_one
172169
current_epoch = block_with_offset // tempo_plus_one
173170

174-
# Initial guess for reveal_epoch
175171
reveal_epoch = current_epoch + subnet_reveal_period_epochs
176172
reveal_block_number = reveal_epoch * tempo_plus_one - netuid_plus_one
177173

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)
182175
time_until_reveal = blocks_until_reveal * block_time
183176

184-
# Adjust until we have enough lead time (at least SUBTENSOR_PULSE_DELAY pulses * period seconds)
185177
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
186181
reveal_epoch += 1
187182
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)
191184
time_until_reveal = blocks_until_reveal * block_time
192185

193186
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
197188
return reveal_round, reveal_time, time_until_reveal

0 commit comments

Comments
 (0)