From 173989f6eda3b6109b6e0249c5f2ab4a846d7cc4 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 4 Apr 2025 16:28:02 -0700 Subject: [PATCH 01/11] improve `next_tempo` + netuid offset --- tests/e2e_tests/utils/chain_interactions.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) 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). From 33e402496779886ef81b6966f4a8c55c73d70517 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 4 Apr 2025 16:28:40 -0700 Subject: [PATCH 02/11] add block_time argument to crv3 extrinsic --- bittensor/core/extrinsics/commit_reveal.py | 3 +++ 1 file changed, 3 insertions(+) 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( From 4c8cdbf9480cfd5e8173a68e66925cb49b0a7a94 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 4 Apr 2025 16:28:55 -0700 Subject: [PATCH 03/11] add block_time argument to crv3 call in subtensor --- bittensor/core/subtensor.py | 3 +++ 1 file changed, 3 insertions(+) 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 From e62c17614cbc3f7952003e59d9f159a4ed3785df Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 4 Apr 2025 16:29:08 -0700 Subject: [PATCH 04/11] fix unit test --- tests/unit_tests/extrinsics/test_commit_reveal.py | 1 + 1 file changed, 1 insertion(+) 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, From 3dc33a586e0ec948519fc86707eb84394a6cff4f Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 4 Apr 2025 16:29:23 -0700 Subject: [PATCH 05/11] improve CRv3 e2e test --- tests/e2e_tests/test_commit_reveal_v3.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/e2e_tests/test_commit_reveal_v3.py b/tests/e2e_tests/test_commit_reveal_v3.py index 52d2324c62..a7d04f4e05 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") @@ -127,6 +128,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 +150,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 From 4e81520fa35120843302b3db4683b7ed37da49d3 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 4 Apr 2025 16:50:35 -0700 Subject: [PATCH 06/11] fix `wait_for_block` logic in CRv3 test --- tests/e2e_tests/test_commit_reveal_v3.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/e2e_tests/test_commit_reveal_v3.py b/tests/e2e_tests/test_commit_reveal_v3.py index a7d04f4e05..1313cd9e80 100644 --- a/tests/e2e_tests/test_commit_reveal_v3.py +++ b/tests/e2e_tests/test_commit_reveal_v3.py @@ -72,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 = 20 assert ( sudo_set_admin_utils( local_chain, @@ -102,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: From b8c5dd16385525cd59696b6b16117822be5671c9 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 4 Apr 2025 16:57:45 -0700 Subject: [PATCH 07/11] fix one more unit test --- tests/unit_tests/test_subtensor.py | 1 + 1 file changed, 1 insertion(+) 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 From 706e6acea47eab9a250a0361f25ab6799e663418 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 4 Apr 2025 17:03:38 -0700 Subject: [PATCH 08/11] increase tempo for test (chain has not enough time to store revealed data) --- tests/e2e_tests/test_commit_reveal_v3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e_tests/test_commit_reveal_v3.py b/tests/e2e_tests/test_commit_reveal_v3.py index 1313cd9e80..6d45cbd94d 100644 --- a/tests/e2e_tests/test_commit_reveal_v3.py +++ b/tests/e2e_tests/test_commit_reveal_v3.py @@ -73,7 +73,7 @@ async def test_commit_and_reveal_weights_cr3(local_chain, subtensor, alice_walle logging.console.info("sudo_set_weights_set_rate_limit executed: set to 0") # Change the tempo of the subnet - tempo_set = 20 + tempo_set = 50 assert ( sudo_set_admin_utils( local_chain, From 5632150be573e3ed1ce0c2145367e3d04b0382ca Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 4 Apr 2025 17:19:20 -0700 Subject: [PATCH 09/11] fix async CRv2 --- bittensor/core/extrinsics/asyncex/commit_reveal.py | 3 +++ 1 file changed, 3 insertions(+) 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( From 3d256e77dcbf49104ad497e0637d3ad2cb875521 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 4 Apr 2025 17:20:55 -0700 Subject: [PATCH 10/11] improve async subtensor call --- bittensor/core/async_subtensor.py | 3 +++ 1 file changed, 3 insertions(+) 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 From 6e002ff7bc4e3be47be888b48b007f672601cdee Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 4 Apr 2025 17:21:20 -0700 Subject: [PATCH 11/11] fix async CRv3 unit test --- tests/unit_tests/extrinsics/asyncex/test_commit_reveal.py | 1 + 1 file changed, 1 insertion(+) 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,