From 68f6d4c1ffe408e897163340dc348912e9b9d5ee Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Fri, 7 Mar 2025 13:08:57 +0200 Subject: [PATCH 1/4] Uses the disk-cached async-substrate-interface. Must be used with https://github.com/opentensor/async-substrate-interface/pull/67 --- bittensor_cli/src/bittensor/subtensor_interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bittensor_cli/src/bittensor/subtensor_interface.py b/bittensor_cli/src/bittensor/subtensor_interface.py index 9e8692e89..56d71acee 100644 --- a/bittensor_cli/src/bittensor/subtensor_interface.py +++ b/bittensor_cli/src/bittensor/subtensor_interface.py @@ -9,7 +9,7 @@ import typer -from async_substrate_interface.async_substrate import AsyncSubstrateInterface +from async_substrate_interface.async_substrate import DiskCachedAsyncSubstrateInterface as AsyncSubstrateInterface from bittensor_cli.src.bittensor.chain_data import ( DelegateInfo, StakeInfo, From 8a0dba56d5ae80eaf8b45495e7c532d021926456 Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Wed, 12 Mar 2025 15:19:32 +0200 Subject: [PATCH 2/4] Makes the disk cache optional (requires env var "DISK_CACHE=1") for the experimental state --- bittensor_cli/src/bittensor/subtensor_interface.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/bittensor_cli/src/bittensor/subtensor_interface.py b/bittensor_cli/src/bittensor/subtensor_interface.py index 56d71acee..f7a4ee39a 100644 --- a/bittensor_cli/src/bittensor/subtensor_interface.py +++ b/bittensor_cli/src/bittensor/subtensor_interface.py @@ -1,4 +1,5 @@ import asyncio +import os from typing import Optional, Any, Union, TypedDict, Iterable import aiohttp @@ -9,7 +10,10 @@ import typer -from async_substrate_interface.async_substrate import DiskCachedAsyncSubstrateInterface as AsyncSubstrateInterface +from async_substrate_interface.async_substrate import ( + DiskCachedAsyncSubstrateInterface, + AsyncSubstrateInterface, +) from bittensor_cli.src.bittensor.chain_data import ( DelegateInfo, StakeInfo, @@ -34,6 +38,12 @@ u16_normalized_float, ) +SubstrateClass = ( + DiskCachedAsyncSubstrateInterface + if os.getenv("DISK_CACHE", "0") == "1" + else AsyncSubstrateInterface +) + class ParamWithTypes(TypedDict): name: str # Name of the parameter. @@ -98,7 +108,7 @@ def __init__(self, network): self.chain_endpoint = Constants.network_map[defaults.subtensor.network] self.network = defaults.subtensor.network - self.substrate = AsyncSubstrateInterface( + self.substrate = SubstrateClass( url=self.chain_endpoint, ss58_format=SS58_FORMAT, type_registry=TYPE_REGISTRY, From a19755c64245e47910b01c22c2b4e50b8d317c09 Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Wed, 12 Mar 2025 15:41:50 +0200 Subject: [PATCH 3/4] Bump required async-substrate-interface version. --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index aa8043d0b..318179fdb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,7 @@ requires-python = ">=3.9,<3.13" dependencies = [ "wheel", "async-property==0.2.2", - "async-substrate-interface>=1.0.5", + "async-substrate-interface>=1.0.6", "aiohttp~=3.10.2", "backoff~=2.2.1", "GitPython>=3.0.0", From cf8bef2dfba497d98d669be46c9228e14e983a9e Mon Sep 17 00:00:00 2001 From: Benjamin Himes Date: Wed, 12 Mar 2025 22:02:24 +0200 Subject: [PATCH 4/4] Bump version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 318179fdb..8d2b6986f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,7 @@ requires-python = ">=3.9,<3.13" dependencies = [ "wheel", "async-property==0.2.2", - "async-substrate-interface>=1.0.6", + "async-substrate-interface>=1.0.7", "aiohttp~=3.10.2", "backoff~=2.2.1", "GitPython>=3.0.0",