From c32f7e75b5808bf1d9d4578eb1fdc4b81f131920 Mon Sep 17 00:00:00 2001 From: bdhimes Date: Mon, 27 Oct 2025 23:15:12 +0200 Subject: [PATCH 1/8] 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/8] 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/8] 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/8] 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/8] 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), ) From 9de25916c5f3d050de3920f2d7f6227fb59e788f Mon Sep 17 00:00:00 2001 From: BD Himes Date: Mon, 26 Jan 2026 21:31:26 +0200 Subject: [PATCH 6/8] Make disk cache default on --- README.md | 2 +- bittensor_cli/cli.py | 4 ++-- bittensor_cli/src/bittensor/subtensor_interface.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e3d8d38ad..a6ba1ea79 100644 --- a/README.md +++ b/README.md @@ -138,7 +138,7 @@ The default location of the config file is: `~/.bittensor/config.yml`. An exampl network: local use_cache: true dashboard_path: null -disk_cache: false +disk_cache: true rate_tolerance: null safe_staking: true wallet_hotkey: default diff --git a/bittensor_cli/cli.py b/bittensor_cli/cli.py index f431c2617..a83447568 100755 --- a/bittensor_cli/cli.py +++ b/bittensor_cli/cli.py @@ -797,7 +797,7 @@ def __init__(self): "wallet_hotkey": None, "network": None, "use_cache": True, - "disk_cache": False, + "disk_cache": True, "rate_tolerance": None, "safe_staking": True, "allow_partial_stake": False, @@ -1431,7 +1431,7 @@ def initialize_chain( "Verify this is intended.", ) if not self.subtensor: - use_disk_cache = self.config.get("disk_cache", False) + use_disk_cache = self.config.get("disk_cache", True) if network: network_ = None for item in network: diff --git a/bittensor_cli/src/bittensor/subtensor_interface.py b/bittensor_cli/src/bittensor/subtensor_interface.py index 2d01f914e..376318282 100644 --- a/bittensor_cli/src/bittensor/subtensor_interface.py +++ b/bittensor_cli/src/bittensor/subtensor_interface.py @@ -85,7 +85,7 @@ class SubtensorInterface: Thin layer for interacting with Substrate Interface. Mostly a collection of frequently-used calls. """ - def __init__(self, network, use_disk_cache: bool = False): + def __init__(self, network, use_disk_cache: bool = True): if network in Constants.network_map: self.chain_endpoint = Constants.network_map[network] self.network = network @@ -117,7 +117,7 @@ def __init__(self, network, use_disk_cache: bool = False): self.network = defaults.subtensor.network substrate_class = ( DiskCachedAsyncSubstrateInterface - if (use_disk_cache or os.getenv("DISK_CACHE", "0") == "1") + if (use_disk_cache or os.getenv("DISK_CACHE", "1") == "1") else AsyncSubstrateInterface ) logger.debug(f"Using substrate class {substrate_class.__name__}") From 05116c6a8cebb85f9b12dfc95ad0bb958461fb49 Mon Sep 17 00:00:00 2001 From: BD Himes Date: Mon, 26 Jan 2026 21:50:33 +0200 Subject: [PATCH 7/8] Bump ASI --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 3ec9af78e..767c365c5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,7 @@ classifiers = [ ] dependencies = [ "wheel", - "async-substrate-interface>=1.5.14", + "async-substrate-interface>=1.6.0", "aiohttp~=3.13", "backoff~=2.2.1", "bittensor-drand>=1.2.0", From 02101f173c2ae9ce96a6ed4b4336836af060acfc Mon Sep 17 00:00:00 2001 From: BD Himes Date: Mon, 26 Jan 2026 21:51:58 +0200 Subject: [PATCH 8/8] Remove debug logging --- bittensor_cli/src/bittensor/subtensor_interface.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/bittensor_cli/src/bittensor/subtensor_interface.py b/bittensor_cli/src/bittensor/subtensor_interface.py index 376318282..57b4a627e 100644 --- a/bittensor_cli/src/bittensor/subtensor_interface.py +++ b/bittensor_cli/src/bittensor/subtensor_interface.py @@ -1,5 +1,4 @@ import asyncio -import logging import os import time from typing import Optional, Any, Union, TypedDict, Iterable, Literal @@ -50,8 +49,6 @@ GENESIS_ADDRESS = "5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM" -logger = logging.getLogger("btcli") - class ParamWithTypes(TypedDict): name: str # Name of the parameter. @@ -120,7 +117,6 @@ def __init__(self, network, use_disk_cache: bool = True): if (use_disk_cache or os.getenv("DISK_CACHE", "1") == "1") else AsyncSubstrateInterface ) - logger.debug(f"Using substrate class {substrate_class.__name__}") self.substrate = substrate_class( url=self.chain_endpoint, ss58_format=SS58_FORMAT,