Skip to content

Commit a1d034f

Browse files
authored
Merge branch 'staging' into fix/roman/balance-unit
2 parents cb95522 + ff4ace4 commit a1d034f

File tree

9 files changed

+24
-12
lines changed

9 files changed

+24
-12
lines changed

bittensor/core/async_subtensor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3812,6 +3812,7 @@ async def set_weights(
38123812
wait_for_inclusion: bool = False,
38133813
wait_for_finalization: bool = False,
38143814
max_retries: int = 5,
3815+
block_time: float = 12.0,
38153816
):
38163817
"""
38173818
Sets the inter-neuronal weights for the specified neuron. This process involves specifying the influence or
@@ -3831,6 +3832,7 @@ async def set_weights(
38313832
wait_for_finalization (bool): Waits for the transaction to be finalized on the blockchain. Default is
38323833
``False``.
38333834
max_retries (int): The number of maximum attempts to set weights. Default is ``5``.
3835+
block_time (float): The amount of seconds for block duration. Default is 12.0 seconds.
38343836
38353837
Returns:
38363838
tuple[bool, str]: ``True`` if the setting of weights is successful, False otherwise. And `msg`, a string
@@ -3879,6 +3881,7 @@ async def _blocks_weight_limit() -> bool:
38793881
version_key=version_key,
38803882
wait_for_inclusion=wait_for_inclusion,
38813883
wait_for_finalization=wait_for_finalization,
3884+
block_time=block_time,
38823885
)
38833886
retries += 1
38843887
return success, message

bittensor/core/extrinsics/asyncex/commit_reveal.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ async def commit_reveal_v3_extrinsic(
7070
version_key: int = version_as_int,
7171
wait_for_inclusion: bool = False,
7272
wait_for_finalization: bool = False,
73+
block_time: float = 12.0,
7374
) -> tuple[bool, str]:
7475
"""
7576
Commits and reveals weights for given subtensor and wallet with provided uids and weights.
@@ -83,6 +84,7 @@ async def commit_reveal_v3_extrinsic(
8384
version_key: The version key to use for committing and revealing. Default is version_as_int.
8485
wait_for_inclusion: Whether to wait for the inclusion of the transaction. Default is False.
8586
wait_for_finalization: Whether to wait for the finalization of the transaction. Default is False.
87+
block_time (float): The amount of seconds for block duration. Default is 12.0 seconds.
8688
8789
Returns:
8890
tuple[bool, str]: A tuple where the first element is a boolean indicating success or failure, and the second
@@ -114,6 +116,7 @@ async def commit_reveal_v3_extrinsic(
114116
current_block=current_block["header"]["number"],
115117
netuid=netuid,
116118
subnet_reveal_period_epochs=subnet_reveal_period_epochs,
119+
block_time=block_time,
117120
)
118121

119122
success, message = await _do_commit_reveal_v3(

bittensor/core/extrinsics/commit_reveal.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def commit_reveal_v3_extrinsic(
7070
version_key: int = version_as_int,
7171
wait_for_inclusion: bool = False,
7272
wait_for_finalization: bool = False,
73+
block_time: float = 12.0,
7374
) -> tuple[bool, str]:
7475
"""
7576
Commits and reveals weights for given subtensor and wallet with provided uids and weights.
@@ -83,6 +84,7 @@ def commit_reveal_v3_extrinsic(
8384
version_key: The version key to use for committing and revealing. Default is version_as_int.
8485
wait_for_inclusion: Whether to wait for the inclusion of the transaction. Default is False.
8586
wait_for_finalization: Whether to wait for the finalization of the transaction. Default is False.
87+
block_time (float): The amount of seconds for block duration. Default is 12.0 seconds.
8688
8789
Returns:
8890
tuple[bool, str]: A tuple where the first element is a boolean indicating success or failure, and the second
@@ -114,6 +116,7 @@ def commit_reveal_v3_extrinsic(
114116
current_block=current_block,
115117
netuid=netuid,
116118
subnet_reveal_period_epochs=subnet_reveal_period_epochs,
119+
block_time=block_time,
117120
)
118121

119122
success, message = _do_commit_reveal_v3(

bittensor/core/subtensor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3099,6 +3099,7 @@ def set_weights(
30993099
wait_for_inclusion: bool = False,
31003100
wait_for_finalization: bool = False,
31013101
max_retries: int = 5,
3102+
block_time: float = 12.0,
31023103
) -> tuple[bool, str]:
31033104
"""
31043105
Sets the inter-neuronal weights for the specified neuron. This process involves specifying the influence or
@@ -3118,6 +3119,7 @@ def set_weights(
31183119
wait_for_finalization (bool): Waits for the transaction to be finalized on the blockchain. Default is
31193120
``False``.
31203121
max_retries (int): The number of maximum attempts to set weights. Default is ``5``.
3122+
block_time (float): The amount of seconds for block duration. Default is 12.0 seconds.
31213123
31223124
Returns:
31233125
tuple[bool, str]: ``True`` if the setting of weights is successful, False otherwise. And `msg`, a string
@@ -3159,6 +3161,7 @@ def _blocks_weight_limit() -> bool:
31593161
version_key=version_key,
31603162
wait_for_inclusion=wait_for_inclusion,
31613163
wait_for_finalization=wait_for_finalization,
3164+
block_time=block_time,
31623165
)
31633166
retries += 1
31643167
return success, message

tests/e2e_tests/test_commit_reveal_v3.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
)
1313

1414

15-
@pytest.mark.parametrize("local_chain", [False], indirect=True)
15+
@pytest.mark.parametrize("local_chain", [True], indirect=True)
1616
@pytest.mark.asyncio
1717
async def test_commit_and_reveal_weights_cr3(local_chain, subtensor, alice_wallet):
1818
"""
@@ -29,6 +29,7 @@ async def test_commit_and_reveal_weights_cr3(local_chain, subtensor, alice_walle
2929
Raises:
3030
AssertionError: If any of the checks or verifications fail
3131
"""
32+
BLOCK_TIME = 0.25 # 12 for non-fast-block, 0.25 for fast block
3233
netuid = 2
3334
logging.console.info("Testing test_commit_and_reveal_weights")
3435

@@ -71,9 +72,8 @@ async def test_commit_and_reveal_weights_cr3(local_chain, subtensor, alice_walle
7172
assert subtensor.weights_rate_limit(netuid=netuid) == 0
7273
logging.console.info("sudo_set_weights_set_rate_limit executed: set to 0")
7374

74-
# Change the tempo of the subnet from default 360
75-
# Since this is in normal blocks, this is necessary
76-
tempo_set = 10
75+
# Change the tempo of the subnet
76+
tempo_set = 50
7777
assert (
7878
sudo_set_admin_utils(
7979
local_chain,
@@ -101,8 +101,8 @@ async def test_commit_and_reveal_weights_cr3(local_chain, subtensor, alice_walle
101101
f"Checking if window is too low with Current block: {current_block}, next tempo: {upcoming_tempo}"
102102
)
103103

104-
# Wait for 2 tempos to pass as CR3 only reveals weights after 2 tempos
105-
subtensor.wait_for_block(20)
104+
# Wait for 2 tempos to pass as CR3 only reveals weights after 2 tempos + 1
105+
subtensor.wait_for_block((tempo_set * 2) + 1)
106106

107107
# Lower than this might mean weights will get revealed before we can check them
108108
if upcoming_tempo - current_block < 3:
@@ -127,6 +127,7 @@ async def test_commit_and_reveal_weights_cr3(local_chain, subtensor, alice_walle
127127
weights=weight_vals,
128128
wait_for_inclusion=True,
129129
wait_for_finalization=True,
130+
block_time=BLOCK_TIME,
130131
)
131132

132133
# Assert committing was a success
@@ -148,7 +149,7 @@ async def test_commit_and_reveal_weights_cr3(local_chain, subtensor, alice_walle
148149

149150
# Ensure the expected drand round is well in the future
150151
assert (
151-
expected_reveal_round > latest_drand_round
152+
expected_reveal_round >= latest_drand_round
152153
), "Revealed drand pulse is older than the drand pulse right after setting weights"
153154

154155
# Fetch current commits pending on the chain

tests/e2e_tests/utils/chain_interactions.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,7 @@ def next_tempo(current_block: int, tempo: int, netuid: int) -> int:
105105
Returns:
106106
int: The next tempo block number.
107107
"""
108-
current_block += 1
109-
interval = tempo + 1
110-
last_epoch = current_block - 1 - (current_block + netuid + 1) % interval
111-
next_tempo_ = last_epoch + interval
112-
return next_tempo_
108+
return (((current_block + netuid) // tempo) + 1) * tempo + 1
113109

114110

115111
async def wait_interval(

tests/unit_tests/extrinsics/asyncex/test_commit_reveal.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ async def test_commit_reveal_v3_extrinsic_success_with_torch(
213213
tempo=mock_hyperparams.return_value.tempo,
214214
netuid=fake_netuid,
215215
current_block=mock_block.return_value["header"]["number"],
216+
block_time=12.0,
216217
)
217218
mock_do_commit_reveal_v3.assert_awaited_once_with(
218219
subtensor=subtensor,

tests/unit_tests/extrinsics/test_commit_reveal.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ def test_commit_reveal_v3_extrinsic_success_with_torch(
199199
tempo=mock_hyperparams.return_value.tempo,
200200
netuid=fake_netuid,
201201
current_block=mock_block.return_value,
202+
block_time=12.0,
202203
)
203204
mock_do_commit_reveal_v3.assert_called_once_with(
204205
subtensor=subtensor,

tests/unit_tests/test_subtensor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3159,6 +3159,7 @@ def test_set_weights_with_commit_reveal_enabled(subtensor, fake_wallet, mocker):
31593159
version_key=subtensor_module.version_as_int,
31603160
wait_for_inclusion=fake_wait_for_inclusion,
31613161
wait_for_finalization=fake_wait_for_finalization,
3162+
block_time=12.0,
31623163
)
31633164
assert result == mocked_commit_reveal_v3_extrinsic.return_value
31643165

0 commit comments

Comments
 (0)