Skip to content

Commit 0100d8d

Browse files
committed
WIP checkin
1 parent a533d1d commit 0100d8d

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

bittensor_cli/cli.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ def __init__(self):
618618
"wallet_hotkey": None,
619619
"network": None,
620620
"use_cache": True,
621+
"disk_cache": False,
621622
"rate_tolerance": None,
622623
"safe_staking": True,
623624
"allow_partial_stake": False,
@@ -1087,6 +1088,7 @@ def initialize_chain(
10871088
"Verify this is intended.",
10881089
)
10891090
if not self.subtensor:
1091+
use_disk_cache = self.config.get("disk_cache", False)
10901092
if network:
10911093
network_ = None
10921094
for item in network:
@@ -1103,15 +1105,15 @@ def initialize_chain(
11031105
f"[{COLORS.G.ARG}]{', '.join(not_selected_networks)}[/{COLORS.G.ARG}]"
11041106
)
11051107

1106-
self.subtensor = SubtensorInterface(network_)
1108+
self.subtensor = SubtensorInterface(network_, use_disk_cache=use_disk_cache)
11071109
elif self.config["network"]:
11081110
console.print(
11091111
f"Using the specified network [{COLORS.G.LINKS}]{self.config['network']}"
11101112
f"[/{COLORS.G.LINKS}] from config"
11111113
)
1112-
self.subtensor = SubtensorInterface(self.config["network"])
1114+
self.subtensor = SubtensorInterface(self.config["network"], use_disk_cache=use_disk_cache)
11131115
else:
1114-
self.subtensor = SubtensorInterface(defaults.subtensor.network)
1116+
self.subtensor = SubtensorInterface(defaults.subtensor.network, use_disk_cache=use_disk_cache)
11151117
return self.subtensor
11161118

11171119
def _run_command(self, cmd: Coroutine, exit_early: bool = True):
@@ -1268,6 +1270,13 @@ def set_config(
12681270
help="Disable caching of some commands. This will disable the `--reuse-last` and `--html` flags on "
12691271
"commands such as `subnets metagraph`, `stake show` and `subnets list`.",
12701272
),
1273+
disk_cache: Optional[bool] = typer.Option(
1274+
None,
1275+
"--disk-cache/--no-disk-cache",
1276+
" /--no-disk-cache",
1277+
help="Enables or disables the caching on disk. Enabling this can significantly speed up commands run "
1278+
"sequentially"
1279+
),
12711280
rate_tolerance: Optional[float] = typer.Option(
12721281
None,
12731282
"--tolerance",
@@ -1314,12 +1323,13 @@ def set_config(
13141323
"wallet_hotkey": wallet_hotkey,
13151324
"network": network,
13161325
"use_cache": use_cache,
1326+
"disk_cache": disk_cache,
13171327
"rate_tolerance": rate_tolerance,
13181328
"safe_staking": safe_staking,
13191329
"allow_partial_stake": allow_partial_stake,
13201330
"dashboard_path": dashboard_path,
13211331
}
1322-
bools = ["use_cache", "safe_staking", "allow_partial_stake"]
1332+
bools = ["use_cache", "disk_cache", "safe_staking", "allow_partial_stake"]
13231333
if all(v is None for v in args.values()):
13241334
# Print existing configs
13251335
self.get_config()

bittensor_cli/src/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class config:
9494
"wallet_name": None,
9595
"wallet_hotkey": None,
9696
"use_cache": True,
97+
"disk_cache": False,
9798
"metagraph_cols": {
9899
"UID": True,
99100
"GLOBAL_STAKE": True,

bittensor_cli/src/bittensor/subtensor_interface.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@
4242
get_hotkey_pub_ss58,
4343
)
4444

45-
SubstrateClass = (
46-
DiskCachedAsyncSubstrateInterface
47-
if os.getenv("DISK_CACHE", "0") == "1"
48-
else AsyncSubstrateInterface
49-
)
50-
5145

5246
class ParamWithTypes(TypedDict):
5347
name: str # Name of the parameter.
@@ -81,7 +75,7 @@ class SubtensorInterface:
8175
Thin layer for interacting with Substrate Interface. Mostly a collection of frequently-used calls.
8276
"""
8377

84-
def __init__(self, network):
78+
def __init__(self, network, use_disk_cache: bool = False):
8579
if network in Constants.network_map:
8680
self.chain_endpoint = Constants.network_map[network]
8781
self.network = network
@@ -111,8 +105,12 @@ def __init__(self, network):
111105
)
112106
self.chain_endpoint = Constants.network_map[defaults.subtensor.network]
113107
self.network = defaults.subtensor.network
114-
115-
self.substrate = SubstrateClass(
108+
substrate_class = (
109+
DiskCachedAsyncSubstrateInterface
110+
if (use_disk_cache or os.getenv("DISK_CACHE", "0") == "1")
111+
else AsyncSubstrateInterface
112+
)
113+
self.substrate = substrate_class(
116114
url=self.chain_endpoint,
117115
ss58_format=SS58_FORMAT,
118116
type_registry=TYPE_REGISTRY,

0 commit comments

Comments
 (0)