From 26772a951ea065ab6ef4acc4981c08f75e977528 Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Tue, 29 Apr 2025 17:40:42 +0200 Subject: [PATCH] Pulls shares in a gather rather than one-at-a-time. +ruff --- bittensor_cli/src/__init__.py | 2 +- .../src/bittensor/subtensor_interface.py | 38 +++++++++---------- bittensor_cli/src/commands/subnets/subnets.py | 4 +- tests/e2e_tests/test_unstaking.py | 23 +++++++---- 4 files changed, 38 insertions(+), 29 deletions(-) diff --git a/bittensor_cli/src/__init__.py b/bittensor_cli/src/__init__.py index d1188e547..bb3bd07f4 100644 --- a/bittensor_cli/src/__init__.py +++ b/bittensor_cli/src/__init__.py @@ -38,7 +38,7 @@ class Constants: "test": "0x8f9cf856bf558a14440e75569c9e58594757048d7b3a84b5d25f6bd978263105", } delegates_detail_url = "https://raw.githubusercontent.com/opentensor/bittensor-delegates/main/public/delegates.json" - emission_start_schedule = 7 * 24 * 60 * 60 / 12 # 7 days + emission_start_schedule = 7 * 24 * 60 * 60 / 12 # 7 days @dataclass diff --git a/bittensor_cli/src/bittensor/subtensor_interface.py b/bittensor_cli/src/bittensor/subtensor_interface.py index 7f21f90d4..2bd0057bd 100644 --- a/bittensor_cli/src/bittensor/subtensor_interface.py +++ b/bittensor_cli/src/bittensor/subtensor_interface.py @@ -238,25 +238,25 @@ async def get_stake_for_coldkey_and_hotkey( :return: Balance: The stake under the coldkey - hotkey pairing. """ - alpha_shares = await self.query( - module="SubtensorModule", - storage_function="Alpha", - params=[hotkey_ss58, coldkey_ss58, netuid], - block_hash=block_hash, - ) - - hotkey_alpha = await self.query( - module="SubtensorModule", - storage_function="TotalHotkeyAlpha", - params=[hotkey_ss58, netuid], - block_hash=block_hash, - ) - - hotkey_shares = await self.query( - module="SubtensorModule", - storage_function="TotalHotkeyShares", - params=[hotkey_ss58, netuid], - block_hash=block_hash, + alpha_shares, hotkey_alpha, hotkey_shares = await asyncio.gather( + self.query( + module="SubtensorModule", + storage_function="Alpha", + params=[hotkey_ss58, coldkey_ss58, netuid], + block_hash=block_hash, + ), + self.query( + module="SubtensorModule", + storage_function="TotalHotkeyAlpha", + params=[hotkey_ss58, netuid], + block_hash=block_hash, + ), + self.query( + module="SubtensorModule", + storage_function="TotalHotkeyShares", + params=[hotkey_ss58, netuid], + block_hash=block_hash, + ), ) alpha_shares_as_float = fixed_to_float(alpha_shares or 0) diff --git a/bittensor_cli/src/commands/subnets/subnets.py b/bittensor_cli/src/commands/subnets/subnets.py index f5eb939c3..81febc4b4 100644 --- a/bittensor_cli/src/commands/subnets/subnets.py +++ b/bittensor_cli/src/commands/subnets/subnets.py @@ -2412,7 +2412,9 @@ async def start_subnet( else: error_msg = format_error_message(await response.error_message) if "FirstEmissionBlockNumberAlreadySet" in error_msg: - console.print(f"[dark_sea_green3]Subnet {netuid} already has an emission schedule.[/dark_sea_green3]") + console.print( + f"[dark_sea_green3]Subnet {netuid} already has an emission schedule.[/dark_sea_green3]" + ) return True await get_start_schedule(subtensor, netuid) diff --git a/tests/e2e_tests/test_unstaking.py b/tests/e2e_tests/test_unstaking.py index 02b25489c..4db52d2b5 100644 --- a/tests/e2e_tests/test_unstaking.py +++ b/tests/e2e_tests/test_unstaking.py @@ -6,6 +6,7 @@ from btcli.tests.e2e_tests.utils import set_storage_extrinsic + def test_unstaking(local_chain, wallet_setup): """ Test various unstaking scenarios including partial unstake, unstake all alpha, and unstake all. @@ -38,16 +39,22 @@ def test_unstaking(local_chain, wallet_setup): # Call to make Alice root owner items = [ - ( - bytes.fromhex("658faa385070e074c85bf6b568cf055536e3e82152c8758267395fe524fbbd160000"), - bytes.fromhex("d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d") + ( + bytes.fromhex( + "658faa385070e074c85bf6b568cf055536e3e82152c8758267395fe524fbbd160000" + ), + bytes.fromhex( + "d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d" + ), ) ] - asyncio.run(set_storage_extrinsic( - local_chain, - wallet=wallet_alice, - items=items, - )) + asyncio.run( + set_storage_extrinsic( + local_chain, + wallet=wallet_alice, + items=items, + ) + ) # Create first subnet (netuid = 2) result = exec_command_alice(