diff --git a/bittensor/core/async_subtensor.py b/bittensor/core/async_subtensor.py index dbae08cb4a..9a132f4258 100644 --- a/bittensor/core/async_subtensor.py +++ b/bittensor/core/async_subtensor.py @@ -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 @@ -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 @@ -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 diff --git a/bittensor/core/extrinsics/asyncex/commit_reveal.py b/bittensor/core/extrinsics/asyncex/commit_reveal.py index 2a5212b569..d1b528e509 100644 --- a/bittensor/core/extrinsics/asyncex/commit_reveal.py +++ b/bittensor/core/extrinsics/asyncex/commit_reveal.py @@ -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. @@ -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 @@ -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( diff --git a/bittensor/core/extrinsics/commit_reveal.py b/bittensor/core/extrinsics/commit_reveal.py index f71fae5581..86795f1624 100644 --- a/bittensor/core/extrinsics/commit_reveal.py +++ b/bittensor/core/extrinsics/commit_reveal.py @@ -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. @@ -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 @@ -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( diff --git a/bittensor/core/subtensor.py b/bittensor/core/subtensor.py index ec3654d953..7ddb049957 100644 --- a/bittensor/core/subtensor.py +++ b/bittensor/core/subtensor.py @@ -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 @@ -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 @@ -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 diff --git a/tests/e2e_tests/test_commit_reveal_v3.py b/tests/e2e_tests/test_commit_reveal_v3.py index 52d2324c62..6d45cbd94d 100644 --- a/tests/e2e_tests/test_commit_reveal_v3.py +++ b/tests/e2e_tests/test_commit_reveal_v3.py @@ -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): """ @@ -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") @@ -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, @@ -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: @@ -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 @@ -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 diff --git a/tests/e2e_tests/utils/chain_interactions.py b/tests/e2e_tests/utils/chain_interactions.py index 93fabb29ff..99e03beaf3 100644 --- a/tests/e2e_tests/utils/chain_interactions.py +++ b/tests/e2e_tests/utils/chain_interactions.py @@ -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( @@ -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). diff --git a/tests/unit_tests/extrinsics/asyncex/test_commit_reveal.py b/tests/unit_tests/extrinsics/asyncex/test_commit_reveal.py index 4dec244651..7802ccf9bb 100644 --- a/tests/unit_tests/extrinsics/asyncex/test_commit_reveal.py +++ b/tests/unit_tests/extrinsics/asyncex/test_commit_reveal.py @@ -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, diff --git a/tests/unit_tests/extrinsics/test_commit_reveal.py b/tests/unit_tests/extrinsics/test_commit_reveal.py index 406bd0a824..37b131e391 100644 --- a/tests/unit_tests/extrinsics/test_commit_reveal.py +++ b/tests/unit_tests/extrinsics/test_commit_reveal.py @@ -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, diff --git a/tests/unit_tests/test_subtensor.py b/tests/unit_tests/test_subtensor.py index 3215d49a0e..513ce7ab3b 100644 --- a/tests/unit_tests/test_subtensor.py +++ b/tests/unit_tests/test_subtensor.py @@ -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