diff --git a/bittensor_cli/src/bittensor/subtensor_interface.py b/bittensor_cli/src/bittensor/subtensor_interface.py index 9e8692e8..f7a4ee39 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 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, diff --git a/pyproject.toml b/pyproject.toml index aa8043d0..8d2b6986 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.7", "aiohttp~=3.10.2", "backoff~=2.2.1", "GitPython>=3.0.0",