Skip to content
3 changes: 3 additions & 0 deletions bittensor/core/async_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3812,6 +3812,7 @@ async def set_weights(
wait_for_inclusion: bool = False,
wait_for_finalization: bool = False,
max_retries: int = 5,
block_time: float = 12.0,
):
"""
Sets the inter-neuronal weights for the specified neuron. This process involves specifying the influence or
Expand All @@ -3831,6 +3832,7 @@ async def set_weights(
wait_for_finalization (bool): Waits for the transaction to be finalized on the blockchain. Default is
``False``.
max_retries (int): The number of maximum attempts to set weights. Default is ``5``.
block_time (float): The amount of seconds for block duration. Default is 12.0 seconds.

Returns:
tuple[bool, str]: ``True`` if the setting of weights is successful, False otherwise. And `msg`, a string
Expand Down Expand Up @@ -3879,6 +3881,7 @@ async def _blocks_weight_limit() -> bool:
version_key=version_key,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
block_time=block_time,
)
retries += 1
return success, message
Expand Down
3 changes: 3 additions & 0 deletions bittensor/core/extrinsics/asyncex/commit_reveal.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ async def commit_reveal_v3_extrinsic(
version_key: int = version_as_int,
wait_for_inclusion: bool = False,
wait_for_finalization: bool = False,
block_time: float = 12.0,
) -> tuple[bool, str]:
"""
Commits and reveals weights for given subtensor and wallet with provided uids and weights.
Expand All @@ -83,6 +84,7 @@ async def commit_reveal_v3_extrinsic(
version_key: The version key to use for committing and revealing. Default is version_as_int.
wait_for_inclusion: Whether to wait for the inclusion of the transaction. Default is False.
wait_for_finalization: Whether to wait for the finalization of the transaction. Default is False.
block_time (float): The amount of seconds for block duration. Default is 12.0 seconds.

Returns:
tuple[bool, str]: A tuple where the first element is a boolean indicating success or failure, and the second
Expand Down Expand Up @@ -114,6 +116,7 @@ async def commit_reveal_v3_extrinsic(
current_block=current_block["header"]["number"],
netuid=netuid,
subnet_reveal_period_epochs=subnet_reveal_period_epochs,
block_time=block_time,
)

success, message = await _do_commit_reveal_v3(
Expand Down
3 changes: 3 additions & 0 deletions bittensor/core/extrinsics/commit_reveal.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def commit_reveal_v3_extrinsic(
version_key: int = version_as_int,
wait_for_inclusion: bool = False,
wait_for_finalization: bool = False,
block_time: float = 12.0,
) -> tuple[bool, str]:
"""
Commits and reveals weights for given subtensor and wallet with provided uids and weights.
Expand All @@ -83,6 +84,7 @@ def commit_reveal_v3_extrinsic(
version_key: The version key to use for committing and revealing. Default is version_as_int.
wait_for_inclusion: Whether to wait for the inclusion of the transaction. Default is False.
wait_for_finalization: Whether to wait for the finalization of the transaction. Default is False.
block_time (float): The amount of seconds for block duration. Default is 12.0 seconds.

Returns:
tuple[bool, str]: A tuple where the first element is a boolean indicating success or failure, and the second
Expand Down Expand Up @@ -114,6 +116,7 @@ def commit_reveal_v3_extrinsic(
current_block=current_block,
netuid=netuid,
subnet_reveal_period_epochs=subnet_reveal_period_epochs,
block_time=block_time,
)

success, message = _do_commit_reveal_v3(
Expand Down
3 changes: 3 additions & 0 deletions bittensor/core/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3099,6 +3099,7 @@ def set_weights(
wait_for_inclusion: bool = False,
wait_for_finalization: bool = False,
max_retries: int = 5,
block_time: float = 12.0,
) -> tuple[bool, str]:
"""
Sets the inter-neuronal weights for the specified neuron. This process involves specifying the influence or
Expand All @@ -3118,6 +3119,7 @@ def set_weights(
wait_for_finalization (bool): Waits for the transaction to be finalized on the blockchain. Default is
``False``.
max_retries (int): The number of maximum attempts to set weights. Default is ``5``.
block_time (float): The amount of seconds for block duration. Default is 12.0 seconds.

Returns:
tuple[bool, str]: ``True`` if the setting of weights is successful, False otherwise. And `msg`, a string
Expand Down Expand Up @@ -3159,6 +3161,7 @@ def _blocks_weight_limit() -> bool:
version_key=version_key,
wait_for_inclusion=wait_for_inclusion,
wait_for_finalization=wait_for_finalization,
block_time=block_time,
)
retries += 1
return success, message
Expand Down
15 changes: 8 additions & 7 deletions tests/e2e_tests/test_commit_reveal_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)


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

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

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

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

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

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

# Ensure the expected drand round is well in the future
assert (
expected_reveal_round > latest_drand_round
expected_reveal_round >= latest_drand_round
), "Revealed drand pulse is older than the drand pulse right after setting weights"

# Fetch current commits pending on the chain
Expand Down
7 changes: 2 additions & 5 deletions tests/e2e_tests/utils/chain_interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ def next_tempo(current_block: int, tempo: int, netuid: int) -> int:
Returns:
int: The next tempo block number.
"""
current_block += 1
interval = tempo + 1
last_epoch = current_block - 1 - (current_block + netuid + 1) % interval
next_tempo_ = last_epoch + interval
return next_tempo_
return (((current_block + netuid) // tempo) + 1) * tempo + 1


async def wait_interval(
Expand Down Expand Up @@ -191,6 +187,7 @@ def sudo_set_admin_utils(
wallet (Wallet): Wallet object with the keypair for signing.
call_function (str): The AdminUtils function to call.
call_params (dict): Parameters for the AdminUtils function.
call_module (str, optional): The AdminUtils module to call. Defaults to "AdminUtils".

Returns:
tuple[bool, Optional[dict]]: (success status, error details).
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/extrinsics/asyncex/test_commit_reveal.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ async def test_commit_reveal_v3_extrinsic_success_with_torch(
tempo=mock_hyperparams.return_value.tempo,
netuid=fake_netuid,
current_block=mock_block.return_value["header"]["number"],
block_time=12.0,
)
mock_do_commit_reveal_v3.assert_awaited_once_with(
subtensor=subtensor,
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/extrinsics/test_commit_reveal.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def test_commit_reveal_v3_extrinsic_success_with_torch(
tempo=mock_hyperparams.return_value.tempo,
netuid=fake_netuid,
current_block=mock_block.return_value,
block_time=12.0,
)
mock_do_commit_reveal_v3.assert_called_once_with(
subtensor=subtensor,
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/test_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3159,6 +3159,7 @@ def test_set_weights_with_commit_reveal_enabled(subtensor, fake_wallet, mocker):
version_key=subtensor_module.version_as_int,
wait_for_inclusion=fake_wait_for_inclusion,
wait_for_finalization=fake_wait_for_finalization,
block_time=12.0,
)
assert result == mocked_commit_reveal_v3_extrinsic.return_value

Expand Down
Loading