From c32f7e75b5808bf1d9d4578eb1fdc4b81f131920 Mon Sep 17 00:00:00 2001 From: bdhimes Date: Mon, 27 Oct 2025 23:15:12 +0200 Subject: [PATCH 1/5] WIP --- bittensor_cli/cli.py | 3 +-- bittensor_cli/src/bittensor/subtensor_interface.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index 3b6096047..a1179199d 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -13,7 +13,7 @@ import warnings from dataclasses import fields from pathlib import Path -from typing import Coroutine, Optional, Union, Literal +from typing import Coroutine, Optional, Union import numpy as np import rich @@ -93,7 +93,6 @@ subnets, mechanisms as subnet_mechanisms, ) -from bittensor_cli.src.commands.wallets import SortByBalance from bittensor_cli.version import __version__, __version_as_int__ try: diff --git a/bittensor_cli/src/bittensor/subtensor_interface.py b/bittensor_cli/src/bittensor/subtensor_interface.py index 2ef90d284..63368755b 100644 --- a/bittensor_cli/src/bittensor/subtensor_interface.py +++ b/bittensor_cli/src/bittensor/subtensor_interface.py @@ -1,4 +1,5 @@ import asyncio +import logging import os import time from typing import Optional, Any, Union, TypedDict, Iterable @@ -45,6 +46,8 @@ get_hotkey_pub_ss58, ) +logger = logging.getLogger("btcli") + class ParamWithTypes(TypedDict): name: str # Name of the parameter. @@ -113,6 +116,7 @@ def __init__(self, network, use_disk_cache: bool = False): if (use_disk_cache or os.getenv("DISK_CACHE", "0") == "1") else AsyncSubstrateInterface ) + logger.debug(f"Using substrate class {substrate_class.__name__}") self.substrate = substrate_class( url=self.chain_endpoint, ss58_format=SS58_FORMAT, @@ -438,11 +442,13 @@ async def get_total_stake_for_coldkey( :return: {address: Balance objects} """ - sub_stakes = await self.get_stake_for_coldkeys( + sub_stakes, dynamic_info = await asyncio.gather( + self.get_stake_for_coldkeys( list(ss58_addresses), block_hash=block_hash + ), + # Token pricing info + self.all_subnets(block_hash=block_hash), ) - # Token pricing info - dynamic_info = await self.all_subnets() results = {} for ss58, stake_info_list in sub_stakes.items(): From 90331569f6969879e6a3282adbb2a1e3dba7b703 Mon Sep 17 00:00:00 2001 From: bdhimes Date: Tue, 28 Oct 2025 16:32:26 +0200 Subject: [PATCH 2/5] WIP --- bittensor_cli/cli.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index a1179199d..ca369180f 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -1338,10 +1338,13 @@ async def _run(): ): # temporarily to handle multiple run commands in one session if self.subtensor: try: - await self.subtensor.substrate.close() + # TODO for some reason having the close here tries to close it twice. + print(1341, "not closing connection") + # await self.subtensor.substrate.close() except Exception as e: # ensures we always exit cleanly if not isinstance(e, (typer.Exit, RuntimeError)): err_console.print(f"An unknown error has occurred: {e}") + traceback.print_exc() if exception_occurred: raise typer.Exit() From f45e98eba395f5519c60104034ff5ba40c698516 Mon Sep 17 00:00:00 2001 From: bdhimes Date: Tue, 28 Oct 2025 16:33:21 +0200 Subject: [PATCH 3/5] Nvm --- bittensor_cli/cli.py | 4 +--- bittensor_cli/src/commands/wallets.py | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index ca369180f..669459ddc 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -1338,9 +1338,7 @@ async def _run(): ): # temporarily to handle multiple run commands in one session if self.subtensor: try: - # TODO for some reason having the close here tries to close it twice. - print(1341, "not closing connection") - # await self.subtensor.substrate.close() + await self.subtensor.substrate.close() except Exception as e: # ensures we always exit cleanly if not isinstance(e, (typer.Exit, RuntimeError)): err_console.print(f"An unknown error has occurred: {e}") diff --git a/bittensor_cli/src/commands/wallets.py b/bittensor_cli/src/commands/wallets.py index 6473f2c69..25fb9787e 100644 --- a/bittensor_cli/src/commands/wallets.py +++ b/bittensor_cli/src/commands/wallets.py @@ -697,7 +697,6 @@ async def wallet_balance( str(total_free_balance + total_staked_balance), ) console.print(Padding(table, (0, 0, 0, 4))) - await subtensor.substrate.close() if json_output: output_balances = { key: { From 68a2d73471e0b62e8f643662ac98bee3a68ce48a Mon Sep 17 00:00:00 2001 From: bdhimes Date: Tue, 28 Oct 2025 16:54:57 +0200 Subject: [PATCH 4/5] Better switching to archive --- bittensor_cli/src/commands/wallets.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bittensor_cli/src/commands/wallets.py b/bittensor_cli/src/commands/wallets.py index 25fb9787e..607c71962 100644 --- a/bittensor_cli/src/commands/wallets.py +++ b/bittensor_cli/src/commands/wallets.py @@ -2174,7 +2174,10 @@ async def find_coldkey_swap_extrinsic( ): console.print("Querying archive node for coldkey swap events...") await subtensor.substrate.close() - subtensor = SubtensorInterface("archive") + subtensor.substrate.chain_endpoint = Constants.archive_entrypoint + subtensor.substrate.url = Constants.archive_entrypoint + subtensor.substrate.initialized = False + await subtensor.substrate.initialize() block_hashes = await asyncio.gather( *[ From 2f17683b72839b32613b878798904bc0478fbcae Mon Sep 17 00:00:00 2001 From: bdhimes Date: Tue, 28 Oct 2025 16:55:25 +0200 Subject: [PATCH 5/5] Ruff --- bittensor_cli/src/bittensor/subtensor_interface.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bittensor_cli/src/bittensor/subtensor_interface.py b/bittensor_cli/src/bittensor/subtensor_interface.py index 63368755b..12b0b6139 100644 --- a/bittensor_cli/src/bittensor/subtensor_interface.py +++ b/bittensor_cli/src/bittensor/subtensor_interface.py @@ -443,9 +443,7 @@ async def get_total_stake_for_coldkey( :return: {address: Balance objects} """ sub_stakes, dynamic_info = await asyncio.gather( - self.get_stake_for_coldkeys( - list(ss58_addresses), block_hash=block_hash - ), + self.get_stake_for_coldkeys(list(ss58_addresses), block_hash=block_hash), # Token pricing info self.all_subnets(block_hash=block_hash), )