Skip to content

Commit 5a203bb

Browse files
author
Roman
committed
Merge branch 'staging-pre-merge-new-async' into merge/roman/async-pre-merge-new-async-to-staging
# Conflicts: # tests/e2e_tests/test_incentive.py
2 parents bbc30a0 + 0392627 commit 5a203bb

File tree

13 files changed

+89
-127
lines changed

13 files changed

+89
-127
lines changed

bittensor/core/extrinsics/asyncex/move_stake.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,6 @@ async def move_stake_extrinsic(
290290
bool: True if the move was successful, False otherwise.
291291
"""
292292
amount.set_unit(netuid=origin_netuid)
293-
# Verify ownership of origin hotkey
294-
origin_owner = await subtensor.get_hotkey_owner(origin_hotkey)
295-
if origin_owner != wallet.coldkeypub.ss58_address:
296-
logging.error(
297-
f":cross_mark: [red]Failed[/red]: Origin hotkey: {origin_hotkey} does not belong to the coldkey owner: "
298-
f"{wallet.coldkeypub.ss58_address}"
299-
)
300-
return False
301293

302294
# Check sufficient stake
303295
stake_in_origin, stake_in_destination = await _get_stake_in_origin_and_dest(

bittensor/core/extrinsics/move_stake.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,6 @@ def move_stake_extrinsic(
289289
"""
290290

291291
amount.set_unit(netuid=origin_netuid)
292-
# Verify ownership of origin hotkey
293-
origin_owner = subtensor.get_hotkey_owner(origin_hotkey)
294-
if origin_owner != wallet.coldkeypub.ss58_address:
295-
logging.error(
296-
f":cross_mark: [red]Failed[/red]: Origin hotkey: {origin_hotkey} does not belong to the coldkey owner: {wallet.coldkeypub.ss58_address}"
297-
)
298-
return False
299292

300293
# Check sufficient stake
301294
stake_in_origin, stake_in_destination = _get_stake_in_origin_and_dest(

bittensor/core/metagraph.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
MetagraphInfoPool,
2020
MetagraphInfoParams,
2121
)
22-
22+
from bittensor.utils import determine_chain_endpoint_and_network
2323
from bittensor.utils.btlogging import logging
2424
from bittensor.utils.registration import torch, use_torch
2525
from bittensor.utils.weight_utils import (
@@ -143,26 +143,6 @@ def latest_block_path(dir_path: str) -> str:
143143
return latest_file_full_path
144144

145145

146-
def determine_chain_endpoint_and_network(network: str) -> tuple[str, str]:
147-
"""
148-
Determine the chain endpoint and network name from the passed arg
149-
150-
Args:
151-
network: The network name (e.g. 'finney', 'test') or
152-
chain endpoint (e.g. wss://entrypoint-finney.opentensor.ai:443)
153-
154-
Returns:
155-
(network name, chain endpoint)
156-
"""
157-
pathless_network = network[:-1] if network.endswith("/") else network
158-
if pathless_network in settings.NETWORK_MAP:
159-
return pathless_network, settings.NETWORK_MAP[pathless_network]
160-
elif pathless_network in settings.REVERSE_NETWORK_MAP:
161-
return settings.REVERSE_NETWORK_MAP[pathless_network], pathless_network
162-
else:
163-
return "unknown", network
164-
165-
166146
class MetagraphMixin(ABC):
167147
"""
168148
The metagraph class is a core component of the Bittensor network, representing the neural graph that forms the

bittensor/core/types.py

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from bittensor.core import settings
88
from bittensor.core.config import Config
99
from bittensor.core.chain_data import NeuronInfo, NeuronInfoLite
10+
from bittensor.utils import determine_chain_endpoint_and_network
1011

1112

1213
class SubtensorMixin(ABC):
@@ -95,8 +96,8 @@ def setup_config(network: Optional[str], config: "Config"):
9596
if check:
9697
network = config_network
9798

98-
evaluated_network, evaluated_endpoint = (
99-
SubtensorMixin.determine_chain_endpoint_and_network(network)
99+
evaluated_network, evaluated_endpoint = determine_chain_endpoint_and_network(
100+
network
100101
)
101102

102103
return networking.get_formatted_ws_endpoint_url(
@@ -166,41 +167,6 @@ def add_args(cls, parser: "argparse.ArgumentParser", prefix: Optional[str] = Non
166167
# re-parsing arguments.
167168
pass
168169

169-
@staticmethod
170-
def determine_chain_endpoint_and_network(
171-
network: str,
172-
) -> tuple[Optional[str], Optional[str]]:
173-
"""Determines the chain endpoint and network from the passed network or chain_endpoint.
174-
175-
Arguments:
176-
network (str): The network flag. The choices are: ``finney`` (main network), ``archive`` (archive network
177-
+300 blocks), ``local`` (local running network), ``test`` (test network).
178-
179-
Returns:
180-
tuple[Optional[str], Optional[str]]: The network and chain endpoint flag. If passed, overrides the
181-
``network`` argument.
182-
"""
183-
184-
if network is None:
185-
return None, None
186-
if network in settings.NETWORKS:
187-
return network, settings.NETWORK_MAP[network]
188-
189-
substrings_map = {
190-
"entrypoint-finney.opentensor.ai": ("finney", settings.FINNEY_ENTRYPOINT),
191-
"test.finney.opentensor.ai": ("test", settings.FINNEY_TEST_ENTRYPOINT),
192-
"archive.chain.opentensor.ai": ("archive", settings.ARCHIVE_ENTRYPOINT),
193-
"subvortex": ("subvortex", settings.SUBVORTEX_ENTRYPOINT),
194-
"127.0.0.1": ("local", settings.LOCAL_ENTRYPOINT),
195-
"localhost": ("local", settings.LOCAL_ENTRYPOINT),
196-
}
197-
198-
for substring, result in substrings_map.items():
199-
if substring in network:
200-
return result
201-
202-
return "unknown", network
203-
204170

205171
class AxonServeCallParams:
206172
def __init__(

bittensor/utils/__init__.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from bittensor_wallet.errors import KeyFileError, PasswordError
1313
from scalecodec import ss58_decode, is_valid_ss58_address as _is_valid_ss58_address
1414

15+
from bittensor.core import settings
1516
from bittensor.core.settings import SS58_FORMAT
1617
from bittensor.utils.btlogging import logging
1718
from .registration import torch, use_torch
@@ -410,3 +411,38 @@ def unlock_key(wallet: "Wallet", unlock_type="coldkey") -> "UnlockStatus":
410411
except KeyFileError:
411412
err_msg = f"{unlock_type.capitalize()} keyfile is corrupt, non-writable, or non-readable, or non-existent."
412413
return UnlockStatus(False, err_msg)
414+
415+
416+
def determine_chain_endpoint_and_network(
417+
network: str,
418+
) -> tuple[Optional[str], Optional[str]]:
419+
"""Determines the chain endpoint and network from the passed network or chain_endpoint.
420+
421+
Arguments:
422+
network (str): The network flag. The choices are: ``finney`` (main network), ``archive`` (archive network
423+
+300 blocks), ``local`` (local running network), ``test`` (test network).
424+
425+
Returns:
426+
tuple[Optional[str], Optional[str]]: The network and chain endpoint flag. If passed, overrides the
427+
``network`` argument.
428+
"""
429+
430+
if network is None:
431+
return None, None
432+
if network in settings.NETWORKS:
433+
return network, settings.NETWORK_MAP[network]
434+
435+
substrings_map = {
436+
"entrypoint-finney.opentensor.ai": ("finney", settings.FINNEY_ENTRYPOINT),
437+
"test.finney.opentensor.ai": ("test", settings.FINNEY_TEST_ENTRYPOINT),
438+
"archive.chain.opentensor.ai": ("archive", settings.ARCHIVE_ENTRYPOINT),
439+
"subvortex": ("subvortex", settings.SUBVORTEX_ENTRYPOINT),
440+
"127.0.0.1": ("local", network),
441+
"localhost": ("local", network),
442+
}
443+
444+
for substring, result in substrings_map.items():
445+
if substring in network and validate_chain_endpoint(network):
446+
return result
447+
448+
return "unknown", network

tests/e2e_tests/conftest.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,6 @@ def local_chain(request):
4949

5050
# Pattern match indicates node is compiled and ready
5151
pattern = re.compile(r"Imported #1")
52-
53-
# install neuron templates
54-
logging.info("downloading and installing neuron templates from github")
55-
# commit with subnet-template-repo changes for rust wallet
56-
templates_dir = clone_or_update_templates()
57-
install_templates(templates_dir)
58-
5952
timestamp = int(time.time())
6053

6154
def wait_for_node_start(process, pattern):
@@ -87,7 +80,7 @@ def read_output():
8780
wait_for_node_start(process, pattern)
8881

8982
# Run the test, passing in substrate interface
90-
yield SubstrateInterface(url="ws://127.0.0.1:9945")
83+
yield SubstrateInterface(url="ws://127.0.0.1:9944")
9184

9285
# Terminate the process group (includes all child processes)
9386
os.killpg(os.getpgid(process.pid), signal.SIGTERM)
@@ -102,14 +95,25 @@ def read_output():
10295
# Ensure the process has terminated
10396
process.wait()
10497

105-
# uninstall templates
98+
99+
@pytest.fixture
100+
def templates():
101+
logging.info("downloading and installing neuron templates from github")
102+
103+
templates_dir = clone_or_update_templates()
104+
105+
install_templates(templates_dir)
106+
107+
yield templates_dir
108+
106109
logging.info("uninstalling neuron templates")
110+
107111
uninstall_templates(template_path)
108112

109113

110114
@pytest.fixture
111115
def subtensor(local_chain):
112-
return Subtensor(network="ws://localhost:9945")
116+
return Subtensor(network="ws://localhost:9944")
113117

114118

115119
@pytest.fixture

tests/e2e_tests/test_axon.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@
44
import pytest
55

66
from bittensor.utils import networking
7-
from tests.e2e_tests.utils.e2e_test_utils import (
8-
template_path,
9-
templates_repo,
10-
)
117

128

139
@pytest.mark.asyncio
14-
async def test_axon(subtensor, alice_wallet):
10+
async def test_axon(subtensor, templates, alice_wallet):
1511
"""
1612
Test the Axon mechanism and successful registration on the network.
1713
@@ -53,13 +49,13 @@ async def test_axon(subtensor, alice_wallet):
5349
cmd = " ".join(
5450
[
5551
f"{sys.executable}",
56-
f'"{template_path}{templates_repo}/miner.py"',
52+
f'"{templates}/miner.py"',
5753
"--netuid",
5854
str(netuid),
5955
"--subtensor.network",
6056
"local",
6157
"--subtensor.chain_endpoint",
62-
"ws://localhost:9945",
58+
"ws://localhost:9944",
6359
"--wallet.path",
6460
alice_wallet.path,
6561
"--wallet.name",

tests/e2e_tests/test_dendrite.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@
1010
sudo_set_hyperparameter_values,
1111
wait_epoch,
1212
)
13-
from tests.e2e_tests.utils.e2e_test_utils import (
14-
template_path,
15-
templates_repo,
16-
)
1713

1814

1915
@pytest.mark.asyncio
20-
async def test_dendrite(local_chain, subtensor, alice_wallet, bob_wallet):
16+
async def test_dendrite(local_chain, subtensor, templates, alice_wallet, bob_wallet):
2117
"""
2218
Test the Dendrite mechanism
2319
@@ -112,13 +108,13 @@ async def test_dendrite(local_chain, subtensor, alice_wallet, bob_wallet):
112108
cmd = " ".join(
113109
[
114110
f"{sys.executable}",
115-
f'"{template_path}{templates_repo}/validator.py"',
111+
f'"{templates}/validator.py"',
116112
"--netuid",
117113
str(netuid),
118114
"--subtensor.network",
119115
"local",
120116
"--subtensor.chain_endpoint",
121-
"ws://localhost:9945",
117+
"ws://localhost:9944",
122118
"--wallet.path",
123119
bob_wallet.path,
124120
"--wallet.name",

tests/e2e_tests/test_incentive.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@
88
sudo_set_hyperparameter_values,
99
wait_epoch,
1010
)
11-
from tests.e2e_tests.utils.e2e_test_utils import (
12-
template_path,
13-
templates_repo,
14-
)
1511

1612

1713
@pytest.mark.asyncio
18-
async def test_incentive(local_chain, subtensor, alice_wallet, bob_wallet):
14+
async def test_incentive(local_chain, subtensor, templates, alice_wallet, bob_wallet):
1915
"""
2016
Test the incentive mechanism and interaction of miners/validators
2117
@@ -80,7 +76,7 @@ async def test_incentive(local_chain, subtensor, alice_wallet, bob_wallet):
8076
cmd = " ".join(
8177
[
8278
f"{sys.executable}",
83-
f'"{template_path}{templates_repo}/miner.py"',
79+
f'"{templates}/miner.py"',
8480
"--netuid",
8581
str(netuid),
8682
"--subtensor.network",
@@ -109,13 +105,13 @@ async def test_incentive(local_chain, subtensor, alice_wallet, bob_wallet):
109105
cmd = " ".join(
110106
[
111107
f"{sys.executable}",
112-
f'"{template_path}{templates_repo}/validator.py"',
108+
f'"{templates}/validator.py"',
113109
"--netuid",
114110
str(netuid),
115111
"--subtensor.network",
116112
"local",
117113
"--subtensor.chain_endpoint",
118-
"ws://localhost:9945",
114+
"ws://localhost:9944",
119115
"--wallet.path",
120116
alice_wallet.path,
121117
"--wallet.name",

tests/e2e_tests/test_root_set_weights.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
wait_epoch,
77
sudo_set_hyperparameter_values,
88
)
9-
from tests.e2e_tests.utils.e2e_test_utils import (
10-
template_path,
11-
templates_repo,
12-
)
139

1410
FAST_BLOCKS_SPEEDUP_FACTOR = 5
1511

@@ -34,7 +30,13 @@
3430

3531

3632
@pytest.mark.asyncio
37-
async def test_root_reg_hyperparams(local_chain, subtensor, alice_wallet, bob_wallet):
33+
async def test_root_reg_hyperparams(
34+
local_chain,
35+
subtensor,
36+
templates,
37+
alice_wallet,
38+
bob_wallet,
39+
):
3840
"""
3941
Test root weights and hyperparameters in the Subtensor network.
4042
@@ -86,13 +88,13 @@ async def test_root_reg_hyperparams(local_chain, subtensor, alice_wallet, bob_wa
8688
cmd = " ".join(
8789
[
8890
f"{sys.executable}",
89-
f'"{template_path}{templates_repo}/validator.py"',
91+
f'"{templates}/validator.py"',
9092
"--netuid",
9193
str(netuid),
9294
"--subtensor.network",
9395
"local",
9496
"--subtensor.chain_endpoint",
95-
"ws://localhost:9945",
97+
"ws://localhost:9944",
9698
"--wallet.path",
9799
alice_wallet.path,
98100
"--wallet.name",

0 commit comments

Comments
 (0)