Skip to content

Commit fcdc1c9

Browse files
committed
PR suggestions
1 parent ada539c commit fcdc1c9

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

bittensor_cli/cli.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6354,11 +6354,13 @@ def best_connection(
63546354
additional_networks = additional_networks or []
63556355
if any(not x.startswith("ws") for x in additional_networks):
63566356
err_console.print(
6357-
"Invalid network endpoint. Ensure you are specifying a valid websocket endpoint.",
6357+
"Invalid network endpoint. Ensure you are specifying a valid websocket endpoint"
6358+
f" (starting with [{COLORS.G.LINKS}]ws://[/{COLORS.G.LINKS}] or "
6359+
f"[{COLORS.G.LINKS}]wss://[/{COLORS.G.LINKS}]).",
63586360
)
63596361
return False
63606362
results: dict[str, list[float]] = self._run_command(
6361-
best_connection(Constants.finney_nodes + (additional_networks or []))
6363+
best_connection(Constants.lite_nodes + additional_networks)
63626364
)
63636365
sorted_results = {
63646366
k: v for k, v in sorted(results.items(), key=lambda item: item[1][0])

bittensor_cli/src/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Constants:
2323
dev_entrypoint = "wss://dev.chain.opentensor.ai:443"
2424
local_entrypoint = "ws://127.0.0.1:9944"
2525
latent_lite_entrypoint = "wss://lite.sub.latent.to:443"
26-
finney_nodes = [finney_entrypoint, subvortex_entrypoint, latent_lite_entrypoint]
26+
lite_nodes = [finney_entrypoint, subvortex_entrypoint, latent_lite_entrypoint]
2727
network_map = {
2828
"finney": finney_entrypoint,
2929
"test": finney_test_entrypoint,

bittensor_cli/src/bittensor/subtensor_interface.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,15 +1669,18 @@ async def best_connection(networks: list[str]):
16691669
"""
16701670
results = {}
16711671
for network in networks:
1672-
t1 = time.monotonic()
1673-
async with websockets.connect(network) as websocket:
1674-
pong = await websocket.ping()
1675-
latency = await pong
1676-
pt1 = time.monotonic()
1677-
await websocket.send(
1678-
"{'jsonrpc': '2.0', 'method': 'chain_getHead', 'params': [], 'id': '82'}"
1679-
)
1680-
await websocket.recv()
1681-
t2 = time.monotonic()
1682-
results[network] = [t2 - t1, latency, t2 - pt1]
1672+
try:
1673+
t1 = time.monotonic()
1674+
async with websockets.connect(network) as websocket:
1675+
pong = await websocket.ping()
1676+
latency = await pong
1677+
pt1 = time.monotonic()
1678+
await websocket.send(
1679+
"{'jsonrpc': '2.0', 'method': 'chain_getHead', 'params': [], 'id': '82'}"
1680+
)
1681+
await websocket.recv()
1682+
t2 = time.monotonic()
1683+
results[network] = [t2 - t1, latency, t2 - pt1]
1684+
except Exception as e:
1685+
err_console.print(f"Error attempting network {network}: {e}")
16831686
return results

0 commit comments

Comments
 (0)