Skip to content

Commit

Permalink
Merge pull request #14 from opentensor/release/0.2.0
Browse files Browse the repository at this point in the history
Release/0.2.0
  • Loading branch information
ibraheem-opentensor authored Jan 15, 2025
2 parents ac0ce8e + cad6cdc commit b25f5b2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## v0.2.0 /2025-01-15

## What's Changed
* fix epoch jump when epoch_block is close by @JohnReedV in https://github.com/opentensor/bittensor-commit-reveal/pull/12
* Backmerge staging to main 0.1.0 @ibraheem-opentensor in https://github.com/opentensor/bittensor-commit-reveal/pull/13

**Full Changelog**: https://github.com/opentensor/bittensor-commit-reveal/compare/v0.1.0...v0.2.0

## v0.1.0 /2024-12-12

## What's Changed
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bittensor-commit-reveal"
version = "0.1.0"
version = "0.2.0"
edition = "2021"

[lib]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "bittensor-commit-reveal"
version = "0.1.0"
version = "0.2.0"
description = ""
readme = "README.md"
license = {file = "LICENSE"}
Expand Down
9 changes: 7 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,19 @@ async fn generate_commit(
// Calculate reveal epoch and ensure enough time for SUBTENSOR_PULSE_DELAY pulses
let mut reveal_epoch = current_epoch + subnet_reveal_period_epochs;
let mut reveal_block_number = reveal_epoch * tempo_plus_one - netuid_plus_one;
let mut blocks_until_reveal = reveal_block_number.saturating_sub(current_block);
let mut blocks_until_reveal = reveal_block_number - current_block;
let mut time_until_reveal = blocks_until_reveal * block_time;

// Ensure at least SUBTENSOR_PULSE_DELAY * period seconds lead time
while time_until_reveal < SUBTENSOR_PULSE_DELAY * period {

if blocks_until_reveal > 1 {
break;
}

reveal_epoch += 1;
reveal_block_number = reveal_epoch * tempo_plus_one - netuid_plus_one;
blocks_until_reveal = reveal_block_number.saturating_sub(current_block);
blocks_until_reveal = reveal_block_number - current_block;
time_until_reveal = blocks_until_reveal * block_time;
}

Expand Down
33 changes: 12 additions & 21 deletions src/tests/test_commit_reveal.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,17 @@ async def test_generate_commit_various_tempos():
abs(reveal_round - expected_reveal_round) <= 1
), f"Tempo {tempo}: reveal_round {reveal_round} not close to expected {expected_reveal_round}"

computed_reveal_time = (
GENESIS_TIME + (reveal_round + SUBTENSOR_PULSE_DELAY) * PERIOD
)
required_lead_time = SUBTENSOR_PULSE_DELAY * PERIOD
computed_reveal_time = (
GENESIS_TIME + (reveal_round + SUBTENSOR_PULSE_DELAY) * PERIOD
)
required_lead_time = SUBTENSOR_PULSE_DELAY * PERIOD

if time_until_reveal >= required_lead_time:
assert computed_reveal_time - start_time >= required_lead_time, (
f"Tempo {tempo}: Not enough lead time: reveal_time={computed_reveal_time}, "
f"Not enough lead time: reveal_time={computed_reveal_time}, "
f"start_time={start_time}, required={required_lead_time}"
)

assert (
time_until_reveal >= SUBTENSOR_PULSE_DELAY * PERIOD
), f"Tempo {tempo}: time_until_reveal {time_until_reveal} is less than required {SUBTENSOR_PULSE_DELAY * PERIOD}"


def compute_expected_reveal_round(
now: int,
Expand All @@ -171,27 +168,21 @@ def compute_expected_reveal_round(
block_with_offset = current_block + netuid_plus_one
current_epoch = block_with_offset // tempo_plus_one

# Initial guess for reveal_epoch
reveal_epoch = current_epoch + subnet_reveal_period_epochs
reveal_block_number = reveal_epoch * tempo_plus_one - netuid_plus_one

# Compute blocks_until_reveal, ensure non-negative
blocks_until_reveal = reveal_block_number - current_block
if blocks_until_reveal < 0:
blocks_until_reveal = 0
blocks_until_reveal = max(reveal_block_number - current_block, 0)
time_until_reveal = blocks_until_reveal * block_time

# Adjust until we have enough lead time (at least SUBTENSOR_PULSE_DELAY pulses * period seconds)
while time_until_reveal < SUBTENSOR_PULSE_DELAY * PERIOD:
# If there's at least one block until the reveal, break early and don't force more lead time
if blocks_until_reveal > 0:
break
reveal_epoch += 1
reveal_block_number = reveal_epoch * tempo_plus_one - netuid_plus_one
blocks_until_reveal = reveal_block_number - current_block
if blocks_until_reveal < 0:
blocks_until_reveal = 0
blocks_until_reveal = max(reveal_block_number - current_block, 0)
time_until_reveal = blocks_until_reveal * block_time

reveal_time = now + time_until_reveal
reveal_round = (
(reveal_time - GENESIS_TIME + PERIOD - 1) // PERIOD
) - SUBTENSOR_PULSE_DELAY
reveal_round = ((reveal_time - GENESIS_TIME + PERIOD - 1) // PERIOD) - SUBTENSOR_PULSE_DELAY
return reveal_round, reveal_time, time_until_reveal

0 comments on commit b25f5b2

Please sign in to comment.