From eab083d71832e1856afe72d7781591fee8cd1ec4 Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor <ibraheem@opentensor.dev> Date: Tue, 3 Dec 2024 11:08:17 -0800 Subject: [PATCH 1/7] Updates changelog --- CHANGELOG.MD | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 CHANGELOG.MD diff --git a/CHANGELOG.MD b/CHANGELOG.MD new file mode 100644 index 0000000..0f94c44 --- /dev/null +++ b/CHANGELOG.MD @@ -0,0 +1,15 @@ +# Changelog + +## v0.1.0a1 /2024-12-03 + +## What's Changed +* feat/roman/without-tlock-network-client by @roman-opentensor in https://github.com/opentensor/bittensor-commit-reveal/pull/1 +* improve reveal round calculation by @JohnReedV in https://github.com/opentensor/bittensor-commit-reveal/pull/2 +* Release/add workflow by @ibraheem-opentensor in https://github.com/opentensor/bittensor-commit-reveal/pull/3 + +## New Contributors +* @roman-opentensor made their first contribution in https://github.com/opentensor/bittensor-commit-reveal/pull/1 +* @JohnReedV made their first contribution in https://github.com/opentensor/bittensor-commit-reveal/pull/2 +* @ibraheem-opentensor made their first contribution in https://github.com/opentensor/bittensor-commit-reveal/pull/3 + +**Full Changelog**: https://github.com/opentensor/bittensor-commit-reveal/commits/v0.1.0a1 \ No newline at end of file From 2fd5efcd21288459a49e1051aa1a735aa5db4dd0 Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor <ibraheem@opentensor.dev> Date: Tue, 3 Dec 2024 12:02:05 -0800 Subject: [PATCH 2/7] Updates changelog --- CHANGELOG.MD | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 0f94c44..9d0f8c5 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -6,6 +6,7 @@ * feat/roman/without-tlock-network-client by @roman-opentensor in https://github.com/opentensor/bittensor-commit-reveal/pull/1 * improve reveal round calculation by @JohnReedV in https://github.com/opentensor/bittensor-commit-reveal/pull/2 * Release/add workflow by @ibraheem-opentensor in https://github.com/opentensor/bittensor-commit-reveal/pull/3 +* Updates the readme file by @ibraheem-opentensor in https://github.com/opentensor/bittensor-commit-reveal/pull/5 ## New Contributors * @roman-opentensor made their first contribution in https://github.com/opentensor/bittensor-commit-reveal/pull/1 From efaa176a786a06ecf860f5d3ca360025c6909443 Mon Sep 17 00:00:00 2001 From: JohnReedV <87283488+JohnReedV@users.noreply.github.com> Date: Thu, 12 Dec 2024 09:04:44 -0800 Subject: [PATCH 3/7] fix the reveal round at the exact epoch --- src/lib.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 0532057..b3a944f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -58,7 +58,15 @@ async fn generate_commit( let tempo_plus_one = tempo + 1; let netuid_plus_one = (netuid as u64) + 1; let block_with_offset = current_block + netuid_plus_one; - let current_epoch = block_with_offset / tempo_plus_one; + + // If at an exact epoch boundary, treat this as the new epoch start. + let is_epoch_boundary = (block_with_offset % tempo_plus_one) == 0; + let base_epoch = block_with_offset / tempo_plus_one; + let current_epoch = if is_epoch_boundary { + base_epoch + 1 + } else { + base_epoch + }; // Compute the reveal epoch let reveal_epoch = current_epoch + subnet_reveal_period_epochs; From b56b4b17463c09b14ebafa15ce364488b670f5a6 Mon Sep 17 00:00:00 2001 From: JohnReedV <87283488+JohnReedV@users.noreply.github.com> Date: Thu, 12 Dec 2024 13:07:18 -0800 Subject: [PATCH 4/7] support all tempos --- src/lib.rs | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b3a944f..bbd503b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -54,36 +54,39 @@ async fn generate_commit( .unwrap() .as_secs(); - // Compute the current epoch index + // Compute current epoch let tempo_plus_one = tempo + 1; let netuid_plus_one = (netuid as u64) + 1; let block_with_offset = current_block + netuid_plus_one; + let current_epoch = block_with_offset / tempo_plus_one; - // If at an exact epoch boundary, treat this as the new epoch start. - let is_epoch_boundary = (block_with_offset % tempo_plus_one) == 0; - let base_epoch = block_with_offset / tempo_plus_one; - let current_epoch = if is_epoch_boundary { - base_epoch + 1 - } else { - base_epoch - }; + // Compute initial reveal epoch + let mut reveal_epoch = current_epoch + subnet_reveal_period_epochs; - // Compute the reveal epoch - let reveal_epoch = current_epoch + subnet_reveal_period_epochs; + // Compute the block when the reveal epoch starts + let mut reveal_block_number = reveal_epoch * tempo_plus_one - netuid_plus_one; - // Compute the block number when the reveal epoch starts - let reveal_block_number = reveal_epoch * tempo_plus_one - netuid_plus_one; + // Compute how many blocks until reveal + let mut blocks_until_reveal = reveal_block_number.saturating_sub(current_block); - // Compute the number of blocks until the reveal epoch - let blocks_until_reveal = reveal_block_number.saturating_sub(current_block); + // Compute time until reveal in seconds + let mut time_until_reveal = blocks_until_reveal * block_time; - // Compute the time until the reveal in seconds - let time_until_reveal = blocks_until_reveal * block_time; + // Since SUBTENSOR_PULSE_DELAY is in pulses, we must ensure that we have at least + // SUBTENSOR_PULSE_DELAY pulses worth of time before reveal. + // Each pulse is 'period' seconds, so we need at least SUBTENSOR_PULSE_DELAY * period seconds. + while time_until_reveal < SUBTENSOR_PULSE_DELAY * period { + // Not enough lead time, push to next epoch + reveal_epoch += 1; + reveal_block_number = reveal_epoch * tempo_plus_one - netuid_plus_one; + blocks_until_reveal = reveal_block_number.saturating_sub(current_block); + time_until_reveal = blocks_until_reveal * block_time; + } // Compute the reveal time in seconds since UNIX_EPOCH let reveal_time = now + time_until_reveal; - // Compute the reveal round, ensuring we round up + // Compute the reveal round, ensure we pick an older Drand round by subtracting SUBTENSOR_PULSE_DELAY pulses. let reveal_round = ((reveal_time - genesis_time + period - 1) / period) - SUBTENSOR_PULSE_DELAY; // 3. Deserialize the public key From 18323f3c0a179170be3aed5c6cdc811e69d731d4 Mon Sep 17 00:00:00 2001 From: JohnReedV <87283488+JohnReedV@users.noreply.github.com> Date: Thu, 12 Dec 2024 14:15:39 -0800 Subject: [PATCH 5/7] update comments --- src/lib.rs | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index bbd503b..0fe5eee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,18 +33,14 @@ async fn generate_commit( block_time: u64, ) -> Result<(Vec<u8>, u64), (std::io::Error, String)> { // Steps comes from here https://github.com/opentensor/subtensor/pull/982/files#diff-7261bf1c7f19fc66a74c1c644ec2b4b277a341609710132fb9cd5f622350a6f5R120-R131 - // 1 Instantiate payload + // Instantiate payload let payload = WeightsTlockPayload { uids, values, version_key, }; - - // 2 Serialize payload let serialized_payload = payload.encode(); - // Calculate reveal_round - // all of 3 variables are constants for drand quicknet let period = 3; let genesis_time = 1692803367; let public_key = "83cf0f2896adee7eb8b5f01fcad3912212c437e0073e911fb90022d3e760183c8c4b450b6a0a6c3ac6a5776a2d1064510d1fec758c921cc22b0e17e63aaf4bcb5ed66304de9cf809bd274ca73bab4af5a6e9c76a4bc09e76eae8991ef5ece45a"; @@ -54,42 +50,29 @@ async fn generate_commit( .unwrap() .as_secs(); - // Compute current epoch let tempo_plus_one = tempo + 1; let netuid_plus_one = (netuid as u64) + 1; let block_with_offset = current_block + netuid_plus_one; let current_epoch = block_with_offset / tempo_plus_one; - // Compute initial reveal epoch + // Calculate reveal epoch and ensure enough time for SUBTENSOR_PULSE_DELAY pulses let mut reveal_epoch = current_epoch + subnet_reveal_period_epochs; - - // Compute the block when the reveal epoch starts let mut reveal_block_number = reveal_epoch * tempo_plus_one - netuid_plus_one; - - // Compute how many blocks until reveal let mut blocks_until_reveal = reveal_block_number.saturating_sub(current_block); - - // Compute time until reveal in seconds let mut time_until_reveal = blocks_until_reveal * block_time; - // Since SUBTENSOR_PULSE_DELAY is in pulses, we must ensure that we have at least - // SUBTENSOR_PULSE_DELAY pulses worth of time before reveal. - // Each pulse is 'period' seconds, so we need at least SUBTENSOR_PULSE_DELAY * period seconds. + // Ensure at least SUBTENSOR_PULSE_DELAY * period seconds lead time while time_until_reveal < SUBTENSOR_PULSE_DELAY * period { - // Not enough lead time, push to next epoch reveal_epoch += 1; reveal_block_number = reveal_epoch * tempo_plus_one - netuid_plus_one; blocks_until_reveal = reveal_block_number.saturating_sub(current_block); time_until_reveal = blocks_until_reveal * block_time; } - // Compute the reveal time in seconds since UNIX_EPOCH let reveal_time = now + time_until_reveal; - - // Compute the reveal round, ensure we pick an older Drand round by subtracting SUBTENSOR_PULSE_DELAY pulses. let reveal_round = ((reveal_time - genesis_time + period - 1) / period) - SUBTENSOR_PULSE_DELAY; - // 3. Deserialize the public key + // Deserialize public key let pub_key_bytes = hex::decode(public_key).map_err(|e| { ( std::io::Error::new(std::io::ErrorKind::InvalidData, format!("{:?}", e)), @@ -105,7 +88,7 @@ async fn generate_commit( ) })?; - // 4 Create identity + // Create identity from reveal_round let message = { let mut hasher = sha2::Sha256::new(); hasher.update(reveal_round.to_be_bytes()); @@ -113,7 +96,7 @@ async fn generate_commit( }; let identity = Identity::new(b"", vec![message]); - // 5. Encryption via tle with t-lock under the hood + // Encrypt payload let esk = [2; 32]; let ct = tle::<TinyBLS381, AESGCMStreamCipherProvider, OsRng>( pub_key, @@ -129,7 +112,7 @@ async fn generate_commit( ) })?; - // 6. Compress ct + // Compress ciphertext let mut ct_bytes: Vec<u8> = Vec::new(); ct.serialize_compressed(&mut ct_bytes).map_err(|e| { ( @@ -138,7 +121,6 @@ async fn generate_commit( ) })?; - // 7. Return result Ok((ct_bytes, reveal_round)) } From 0a62ea969fb94b239cae433193f7090b9cf391b7 Mon Sep 17 00:00:00 2001 From: JohnReedV <87283488+JohnReedV@users.noreply.github.com> Date: Thu, 12 Dec 2024 14:48:50 -0800 Subject: [PATCH 6/7] add tests --- src/tests/tests.py | 152 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 src/tests/tests.py diff --git a/src/tests/tests.py b/src/tests/tests.py new file mode 100644 index 0000000..f119dc1 --- /dev/null +++ b/src/tests/tests.py @@ -0,0 +1,152 @@ +import pytest +import time +from bittensor_commit_reveal import get_encrypted_commit + +SUBTENSOR_PULSE_DELAY = 24 +PERIOD = 3 # Drand period in seconds +GENESIS_TIME = 1692803367 + + +def test_get_encrypted_commit_ok(): + uids = [1, 2] + weights = [11, 22] + version_key = 50 + tempo = 100 + current_block = 1000 + netuid = 1 + reveal_period = 2 + block_time = 12 + + start_time = int(time.time()) + ct_pybytes, reveal_round = get_encrypted_commit( + uids, weights, version_key, tempo, current_block, netuid, reveal_period, block_time + ) + + # Basic checks + assert ct_pybytes is not None and len(ct_pybytes) > 0, "Ciphertext should not be empty" + assert reveal_round > 0, "Reveal round should be positive" + + expected_reveal_round, _, _ = compute_expected_reveal_round( + start_time, tempo, current_block, netuid, reveal_period, block_time + ) + + # The reveal_round should be close to what we predict + assert abs(reveal_round - expected_reveal_round) <= 1, ( + f"Reveal round {reveal_round} not close to expected {expected_reveal_round}" + ) + +def test_generate_commit_success(): + uids = [1, 2, 3] + values = [10, 20, 30] + version_key = 42 + tempo = 50 + current_block = 500 + netuid = 100 + subnet_reveal_period_epochs = 2 + block_time = 12 + + start_time = int(time.time()) + ct_pybytes, reveal_round = get_encrypted_commit( + uids, values, version_key, tempo, current_block, netuid, subnet_reveal_period_epochs, block_time + ) + + assert ct_pybytes is not None and len(ct_pybytes) > 0, "Ciphertext should not be empty" + assert reveal_round > 0, "Reveal round should be positive" + + expected_reveal_round, expected_reveal_time, time_until_reveal = compute_expected_reveal_round( + start_time, tempo, current_block, netuid, subnet_reveal_period_epochs, block_time + ) + + assert abs(reveal_round - expected_reveal_round) <= 1, ( + f"Reveal round {reveal_round} differs from expected {expected_reveal_round}" + ) + + required_lead_time = SUBTENSOR_PULSE_DELAY * PERIOD + computed_reveal_time = GENESIS_TIME + (reveal_round + SUBTENSOR_PULSE_DELAY) * PERIOD + assert computed_reveal_time - start_time >= required_lead_time, ( + "Not enough lead time before reveal. " + f"computed_reveal_time={computed_reveal_time}, start_time={start_time}, required={required_lead_time}" + ) + + assert time_until_reveal >= SUBTENSOR_PULSE_DELAY * PERIOD, ( + f"time_until_reveal {time_until_reveal} is less than required {SUBTENSOR_PULSE_DELAY * PERIOD}" + ) + + +@pytest.mark.asyncio +async def test_generate_commit_various_tempos(): + NETUID = 1 + CURRENT_BLOCK = 100_000 + SUBNET_REVEAL_PERIOD_EPOCHS = 1 + BLOCK_TIME = 6 + TEMPOS = [10, 50, 100, 250, 360, 500, 750, 1000] + + uids = [0] + values = [100] + version_key = 1 + + for tempo in TEMPOS: + start_time = int(time.time()) + + ct_pybytes, reveal_round = get_encrypted_commit( + uids, values, version_key, tempo, CURRENT_BLOCK, NETUID, SUBNET_REVEAL_PERIOD_EPOCHS, BLOCK_TIME + ) + + assert len(ct_pybytes) > 0, f"Ciphertext is empty for tempo {tempo}" + assert reveal_round > 0, f"Reveal round is zero or negative for tempo {tempo}" + + expected_reveal_round, _, time_until_reveal = compute_expected_reveal_round( + start_time, tempo, CURRENT_BLOCK, NETUID, SUBNET_REVEAL_PERIOD_EPOCHS, BLOCK_TIME + ) + + assert 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 + + assert computed_reveal_time - start_time >= required_lead_time, ( + f"Tempo {tempo}: 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, + tempo: int, + current_block: int, + netuid: int, + subnet_reveal_period_epochs: int, + block_time: int, +): + tempo_plus_one = tempo + 1 + netuid_plus_one = netuid + 1 + 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 + 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: + 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 + 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 + return reveal_round, reveal_time, time_until_reveal \ No newline at end of file From d8bfff8b5473234f90a5853b6ddd536692724b5b Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor <ibraheem@opentensor.dev> Date: Thu, 12 Dec 2024 15:13:24 -0800 Subject: [PATCH 7/7] Renames test + ruff --- src/tests/{tests.py => test_commit_reveal.py} | 103 +++++++++++++----- 1 file changed, 74 insertions(+), 29 deletions(-) rename src/tests/{tests.py => test_commit_reveal.py} (61%) diff --git a/src/tests/tests.py b/src/tests/test_commit_reveal.py similarity index 61% rename from src/tests/tests.py rename to src/tests/test_commit_reveal.py index f119dc1..fd07524 100644 --- a/src/tests/tests.py +++ b/src/tests/test_commit_reveal.py @@ -7,7 +7,7 @@ GENESIS_TIME = 1692803367 -def test_get_encrypted_commit_ok(): +def test_get_encrypted_commits(): uids = [1, 2] weights = [11, 22] version_key = 50 @@ -19,11 +19,20 @@ def test_get_encrypted_commit_ok(): start_time = int(time.time()) ct_pybytes, reveal_round = get_encrypted_commit( - uids, weights, version_key, tempo, current_block, netuid, reveal_period, block_time + uids, + weights, + version_key, + tempo, + current_block, + netuid, + reveal_period, + block_time, ) # Basic checks - assert ct_pybytes is not None and len(ct_pybytes) > 0, "Ciphertext should not be empty" + assert ( + ct_pybytes is not None and len(ct_pybytes) > 0 + ), "Ciphertext should not be empty" assert reveal_round > 0, "Reveal round should be positive" expected_reveal_round, _, _ = compute_expected_reveal_round( @@ -31,10 +40,11 @@ def test_get_encrypted_commit_ok(): ) # The reveal_round should be close to what we predict - assert abs(reveal_round - expected_reveal_round) <= 1, ( - f"Reveal round {reveal_round} not close to expected {expected_reveal_round}" - ) - + assert ( + abs(reveal_round - expected_reveal_round) <= 1 + ), f"Reveal round {reveal_round} not close to expected {expected_reveal_round}" + + def test_generate_commit_success(): uids = [1, 2, 3] values = [10, 20, 30] @@ -47,30 +57,48 @@ def test_generate_commit_success(): start_time = int(time.time()) ct_pybytes, reveal_round = get_encrypted_commit( - uids, values, version_key, tempo, current_block, netuid, subnet_reveal_period_epochs, block_time + uids, + values, + version_key, + tempo, + current_block, + netuid, + subnet_reveal_period_epochs, + block_time, ) - assert ct_pybytes is not None and len(ct_pybytes) > 0, "Ciphertext should not be empty" + assert ( + ct_pybytes is not None and len(ct_pybytes) > 0 + ), "Ciphertext should not be empty" assert reveal_round > 0, "Reveal round should be positive" - expected_reveal_round, expected_reveal_time, time_until_reveal = compute_expected_reveal_round( - start_time, tempo, current_block, netuid, subnet_reveal_period_epochs, block_time + expected_reveal_round, expected_reveal_time, time_until_reveal = ( + compute_expected_reveal_round( + start_time, + tempo, + current_block, + netuid, + subnet_reveal_period_epochs, + block_time, + ) ) - assert abs(reveal_round - expected_reveal_round) <= 1, ( - f"Reveal round {reveal_round} differs from expected {expected_reveal_round}" - ) + assert ( + abs(reveal_round - expected_reveal_round) <= 1 + ), f"Reveal round {reveal_round} differs from expected {expected_reveal_round}" required_lead_time = SUBTENSOR_PULSE_DELAY * PERIOD - computed_reveal_time = GENESIS_TIME + (reveal_round + SUBTENSOR_PULSE_DELAY) * PERIOD + computed_reveal_time = ( + GENESIS_TIME + (reveal_round + SUBTENSOR_PULSE_DELAY) * PERIOD + ) assert computed_reveal_time - start_time >= required_lead_time, ( "Not enough lead time before reveal. " f"computed_reveal_time={computed_reveal_time}, start_time={start_time}, required={required_lead_time}" ) - assert time_until_reveal >= SUBTENSOR_PULSE_DELAY * PERIOD, ( - f"time_until_reveal {time_until_reveal} is less than required {SUBTENSOR_PULSE_DELAY * PERIOD}" - ) + assert ( + time_until_reveal >= SUBTENSOR_PULSE_DELAY * PERIOD + ), f"time_until_reveal {time_until_reveal} is less than required {SUBTENSOR_PULSE_DELAY * PERIOD}" @pytest.mark.asyncio @@ -89,21 +117,35 @@ async def test_generate_commit_various_tempos(): start_time = int(time.time()) ct_pybytes, reveal_round = get_encrypted_commit( - uids, values, version_key, tempo, CURRENT_BLOCK, NETUID, SUBNET_REVEAL_PERIOD_EPOCHS, BLOCK_TIME + uids, + values, + version_key, + tempo, + CURRENT_BLOCK, + NETUID, + SUBNET_REVEAL_PERIOD_EPOCHS, + BLOCK_TIME, ) assert len(ct_pybytes) > 0, f"Ciphertext is empty for tempo {tempo}" assert reveal_round > 0, f"Reveal round is zero or negative for tempo {tempo}" expected_reveal_round, _, time_until_reveal = compute_expected_reveal_round( - start_time, tempo, CURRENT_BLOCK, NETUID, SUBNET_REVEAL_PERIOD_EPOCHS, BLOCK_TIME + start_time, + tempo, + CURRENT_BLOCK, + NETUID, + SUBNET_REVEAL_PERIOD_EPOCHS, + BLOCK_TIME, ) - assert abs(reveal_round - expected_reveal_round) <= 1, ( - f"Tempo {tempo}: reveal_round {reveal_round} not close to expected {expected_reveal_round}" - ) + assert ( + 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 + computed_reveal_time = ( + GENESIS_TIME + (reveal_round + SUBTENSOR_PULSE_DELAY) * PERIOD + ) required_lead_time = SUBTENSOR_PULSE_DELAY * PERIOD assert computed_reveal_time - start_time >= required_lead_time, ( @@ -111,9 +153,10 @@ async def test_generate_commit_various_tempos(): 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}" - ) + 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, @@ -148,5 +191,7 @@ def compute_expected_reveal_round( 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 - return reveal_round, reveal_time, time_until_reveal \ No newline at end of file + reveal_round = ( + (reveal_time - GENESIS_TIME + PERIOD - 1) // PERIOD + ) - SUBTENSOR_PULSE_DELAY + return reveal_round, reveal_time, time_until_reveal