Skip to content

Commit 6abcd27

Browse files
authored
Merge pull request #368 from opentensor/feat/thewhaleking/disk-cache
Disk-Cache Async-Substrate-Interface Calls
2 parents 78659af + cf8bef2 commit 6abcd27

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

bittensor_cli/src/bittensor/subtensor_interface.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import os
23
from typing import Optional, Any, Union, TypedDict, Iterable
34

45
import aiohttp
@@ -9,7 +10,10 @@
910
import typer
1011

1112

12-
from async_substrate_interface.async_substrate import AsyncSubstrateInterface
13+
from async_substrate_interface.async_substrate import (
14+
DiskCachedAsyncSubstrateInterface,
15+
AsyncSubstrateInterface,
16+
)
1317
from bittensor_cli.src.bittensor.chain_data import (
1418
DelegateInfo,
1519
StakeInfo,
@@ -34,6 +38,12 @@
3438
u16_normalized_float,
3539
)
3640

41+
SubstrateClass = (
42+
DiskCachedAsyncSubstrateInterface
43+
if os.getenv("DISK_CACHE", "0") == "1"
44+
else AsyncSubstrateInterface
45+
)
46+
3747

3848
class ParamWithTypes(TypedDict):
3949
name: str # Name of the parameter.
@@ -98,7 +108,7 @@ def __init__(self, network):
98108
self.chain_endpoint = Constants.network_map[defaults.subtensor.network]
99109
self.network = defaults.subtensor.network
100110

101-
self.substrate = AsyncSubstrateInterface(
111+
self.substrate = SubstrateClass(
102112
url=self.chain_endpoint,
103113
ss58_format=SS58_FORMAT,
104114
type_registry=TYPE_REGISTRY,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ requires-python = ">=3.9,<3.13"
1616
dependencies = [
1717
"wheel",
1818
"async-property==0.2.2",
19-
"async-substrate-interface>=1.0.5",
19+
"async-substrate-interface>=1.0.7",
2020
"aiohttp~=3.10.2",
2121
"backoff~=2.2.1",
2222
"GitPython>=3.0.0",

0 commit comments

Comments
 (0)