Skip to content

Commit

Permalink
update Subtensor.determine_chain_endpoint_and_network logic
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-opentensor committed Dec 24, 2024
1 parent 560bf29 commit 7cd6776
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 31 deletions.
17 changes: 6 additions & 11 deletions bittensor/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,13 @@
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)

# 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"
Expand All @@ -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)
Expand Down
36 changes: 16 additions & 20 deletions bittensor/core/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/unit_tests/test_subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7cd6776

Please sign in to comment.