From 7cd67760630ef7d3c01235d3f37d2b63c60f0914 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 24 Dec 2024 10:54:00 -0800 Subject: [PATCH] update `Subtensor.determine_chain_endpoint_and_network` logic --- bittensor/core/settings.py | 17 +++++--------- bittensor/core/subtensor.py | 36 +++++++++++++----------------- tests/unit_tests/test_subtensor.py | 1 + 3 files changed, 23 insertions(+), 31 deletions(-) diff --git a/bittensor/core/settings.py b/bittensor/core/settings.py index 04d94436e..bbebf2120 100644 --- a/bittensor/core/settings.py +++ b/bittensor/core/settings.py @@ -30,7 +30,6 @@ WALLETS_DIR = USER_BITTENSOR_DIR / "wallets" MINERS_DIR = USER_BITTENSOR_DIR / "miners" - # Create dirs if they don't exist WALLETS_DIR.mkdir(parents=True, exist_ok=True) MINERS_DIR.mkdir(parents=True, exist_ok=True) @@ -38,9 +37,6 @@ # Bittensor networks name NETWORKS = ["finney", "test", "archive", "local", "subvortex"] -DEFAULT_ENDPOINT = "wss://entrypoint-finney.opentensor.ai:443" -DEFAULT_NETWORK = NETWORKS[0] - # Bittensor endpoints (Needs to use wss://) FINNEY_ENTRYPOINT = "wss://entrypoint-finney.opentensor.ai:443" FINNEY_TEST_ENTRYPOINT = "wss://test.finney.opentensor.ai:443" @@ -56,13 +52,12 @@ NETWORKS[4]: SUBVORTEX_ENTRYPOINT, } -REVERSE_NETWORK_MAP = { - FINNEY_ENTRYPOINT: NETWORKS[0], - FINNEY_TEST_ENTRYPOINT: NETWORKS[1], - ARCHIVE_ENTRYPOINT: NETWORKS[2], - LOCAL_ENTRYPOINT: NETWORKS[3], - SUBVORTEX_ENTRYPOINT: NETWORKS[4], -} +# Default Network and Endpoint +DEFAULT_NETWORK = NETWORKS[0] +DEFAULT_ENDPOINT = NETWORK_MAP[DEFAULT_NETWORK] + +# Reverse mapping for endpoints to networks +REVERSE_NETWORK_MAP = {v: k for k, v in NETWORK_MAP.items()} # Currency Symbols Bittensor TAO_SYMBOL: str = chr(0x03C4) diff --git a/bittensor/core/subtensor.py b/bittensor/core/subtensor.py index c2e85352e..596a41478 100644 --- a/bittensor/core/subtensor.py +++ b/bittensor/core/subtensor.py @@ -726,26 +726,22 @@ def determine_chain_endpoint_and_network( return None, None if network in settings.NETWORKS: return network, settings.NETWORK_MAP[network] - else: - if ( - network == settings.FINNEY_ENTRYPOINT - or "entrypoint-finney.opentensor.ai" in network - ): - return "finney", settings.FINNEY_ENTRYPOINT - elif ( - network == settings.FINNEY_TEST_ENTRYPOINT - or "test.finney.opentensor.ai" in network - ): - return "test", settings.FINNEY_TEST_ENTRYPOINT - elif ( - network == settings.ARCHIVE_ENTRYPOINT - or "archive.chain.opentensor.ai" in network - ): - return "archive", settings.ARCHIVE_ENTRYPOINT - elif "127.0.0.1" in network or "localhost" in network: - return "local", network - else: - return "unknown", network + + substrings_map = { + "entrypoint-finney.opentensor.ai": ("finney", settings.FINNEY_ENTRYPOINT), + "test.finney.opentensor.ai": ("test", settings.FINNEY_TEST_ENTRYPOINT), + "archive.chain.opentensor.ai": ("archive", settings.ARCHIVE_ENTRYPOINT), + "subvortex": ("subvortex", network), + "subvortex.info": ("subvortex", network), + "127.0.0.1": ("local", network), + "localhost": ("local", network), + } + + for substring, result in substrings_map.items(): + if substring in network: + return result + + return "unknown", network def get_netuids_for_hotkey( self, hotkey_ss58: str, block: Optional[int] = None diff --git a/tests/unit_tests/test_subtensor.py b/tests/unit_tests/test_subtensor.py index 5b9e15339..878c33774 100644 --- a/tests/unit_tests/test_subtensor.py +++ b/tests/unit_tests/test_subtensor.py @@ -229,6 +229,7 @@ def mock_add_argument(*args, **kwargs): "archive", settings.ARCHIVE_ENTRYPOINT, ), + ("subvortex", "subvortex", settings.SUBVORTEX_ENTRYPOINT), ("127.0.0.1", "local", "127.0.0.1"), ("localhost", "local", "localhost"), # Edge cases