diff --git a/bittensor/__init__.py b/bittensor/__init__.py index 091e5896d4..8794960867 100644 --- a/bittensor/__init__.py +++ b/bittensor/__init__.py @@ -52,28 +52,27 @@ def turn_console_off(): # Wallet ss58 address length __ss58_address_length__ = 48 -__networks__ = [ 'local', 'nobunaga', 'nakamoto'] +__networks__ = [ 'local', 'bellagene', 'nobunaga', 'nakamoto'] __datasets__ = ['ArXiv', 'BookCorpus2', 'Books3', 'DMMathematics', 'EnronEmails', 'EuroParl', 'Gutenberg_PG', 'HackerNews', 'NIHExPorter', 'OpenSubtitles', 'PhilPapers', 'UbuntuIRC', 'YoutubeSubtitles'] -__nakamoto_entrypoints__ = [ - "AtreusLB-2c6154f73e6429a9.elb.us-east-2.amazonaws.com:9944" -] +__nakamoto_entrypoint__ = "AtreusLB-2c6154f73e6429a9.elb.us-east-2.amazonaws.com:9944" -__nobunaga_entrypoints__ = [ - 'staging.nobunaga.opentensor.ai:9944' -] -__local_entrypoints__ = [ - '127.0.0.1:9944' -] +__nobunaga_entrypoint__ = "staging.nobunaga.opentensor.ai:9944" + + +__bellagene_entrypoint__ = "parachain.opentensor.ai:443" + + +__local_entrypoint__ = "127.0.0.1:9944" + # Avoid collisions with other processes from .utils.test_utils import get_random_unused_port mock_subtensor_port = get_random_unused_port() -__mock_entrypoints__ = [ - f"localhost:{mock_subtensor_port}" -] +__mock_entrypoint__ = f"localhost:{mock_subtensor_port}" + # ---- Config ---- diff --git a/bittensor/_subtensor/__init__.py b/bittensor/_subtensor/__init__.py index 3b0c870671..8dd68c973a 100644 --- a/bittensor/_subtensor/__init__.py +++ b/bittensor/_subtensor/__init__.py @@ -130,12 +130,16 @@ def __new__( else: config.subtensor.chain_endpoint = subtensor.determine_chain_endpoint( bittensor.defaults.subtensor.network ) config.subtensor.network = bittensor.defaults.subtensor.network - + # make sure it's wss:// or ws:// + # If it's bellagene (parachain testnet) then it has to be wss endpoint_url: str = config.subtensor.chain_endpoint if endpoint_url[0:6] != "wss://" and endpoint_url[0:5] != "ws://": - endpoint_url = "ws://{}".format(endpoint_url) - + if config.subtensor.network == "bellagene": + endpoint_url = "wss://{}".format(endpoint_url) + else: + endpoint_url = "ws://{}".format(endpoint_url) + substrate = SubstrateInterface( ss58_format = bittensor.__ss58_format__, type_registry_preset='substrate-node-template', @@ -235,14 +239,17 @@ def check_config( config: 'bittensor.Config' ): def determine_chain_endpoint(network: str): if network == "nakamoto": # Main network. - return bittensor.__nakamoto_entrypoints__[0] + return bittensor.__nakamoto_entrypoint__ elif network == "nobunaga": # Staging network. - return bittensor.__nobunaga_entrypoints__[0] + return bittensor.__nobunaga_entrypoint__ + elif network == "bellagene": + # Parachain test net + return bittensor.__bellagene_entrypoint__ elif network == "local": # Local chain. - return bittensor.__local_entrypoints__[0] + return bittensor.__local_entrypoint__ elif network == 'mock': - return bittensor.__mock_entrypoints__[0] + return bittensor.__mock_entrypoint__ else: - return bittensor.__local_entrypoints__[0] + return bittensor.__local_entrypoint__ diff --git a/bittensor/_subtensor/subtensor_impl.py b/bittensor/_subtensor/subtensor_impl.py index 5da7dd1232..ea19251b60 100644 --- a/bittensor/_subtensor/subtensor_impl.py +++ b/bittensor/_subtensor/subtensor_impl.py @@ -481,10 +481,10 @@ def register ( """ with bittensor.__console__.status(":satellite: Checking Account..."): - neuron = self.neuron_for_pubkey( wallet.hotkey.ss58_address ) - if not neuron.is_null: - bittensor.__console__.print(":white_heavy_check_mark: [green]Already Registered[/green]:\n uid: [bold white]{}[/bold white]\n hotkey: [bold white]{}[/bold white]\n coldkey: [bold white]{}[/bold white]".format(neuron.uid, neuron.hotkey, neuron.coldkey)) - return True + neuron = self.neuron_for_pubkey( wallet.hotkey.ss58_address ) + if not neuron.is_null: + bittensor.__console__.print(":white_heavy_check_mark: [green]Already Registered[/green]:\n uid: [bold white]{}[/bold white]\n hotkey: [bold white]{}[/bold white]\n coldkey: [bold white]{}[/bold white]".format(neuron.uid, neuron.hotkey, neuron.coldkey)) + return True if prompt: if not Confirm.ask("Continue Registration?\n hotkey: [bold white]{}[/bold white]\n coldkey: [bold white]{}[/bold white]\n network: [bold white]{}[/bold white]".format( wallet.hotkey.ss58_address, wallet.coldkeypub.ss58_address, self.network ) ): @@ -562,9 +562,8 @@ def register ( else: # Exited loop because pow is no longer valid. bittensor.__console__.print( "[red]POW is stale.[/red]" ) - # Try again. + # Try again continue - if attempts < max_allowed_attempts: #Failed registration, retry pow attempts += 1 diff --git a/bittensor/_subtensor/subtensor_mock.py b/bittensor/_subtensor/subtensor_mock.py index 13e824f6e0..691faa7a83 100644 --- a/bittensor/_subtensor/subtensor_mock.py +++ b/bittensor/_subtensor/subtensor_mock.py @@ -58,7 +58,7 @@ def mock(cls): _owned_mock_subtensor_process = None print ('Mock subtensor already running.') - endpoint = bittensor.__mock_entrypoints__[0] + endpoint = bittensor.__mock_entrypoint__ port = int(endpoint.split(':')[1]) substrate = SubstrateInterface( ss58_format = bittensor.__ss58_format__, @@ -105,7 +105,7 @@ def create_global_mock_process(self): try: operating_system = "OSX" if platform == "darwin" else "Linux" path = "./bin/chain/{}/node-subtensor".format(operating_system) - ws_port = int(bittensor.__mock_entrypoints__[0].split(':')[1]) + ws_port = int(bittensor.__mock_entrypoint__.split(':')[1]) print(ws_port) print(os.getpid()) baseport = get_random_unused_port() diff --git a/bittensor/_wallet/__init__.py b/bittensor/_wallet/__init__.py index 9849d50664..4080ad8cf2 100644 --- a/bittensor/_wallet/__init__.py +++ b/bittensor/_wallet/__init__.py @@ -117,9 +117,6 @@ def add_args(cls, parser: argparse.ArgumentParser, prefix: str = None ): parser.add_argument('--' + prefix_str + 'wallet.reregister', required=False, action='store', default=bittensor.defaults.wallet.reregister, type=bool, help='''Whether to reregister the wallet if it is not already registered.''') except argparse.ArgumentError as e: - import pdb - #pdb.set_trace() - # re-parsing arguments. pass @classmethod diff --git a/bittensor/utils/__init__.py b/bittensor/utils/__init__.py index ef448484e2..65742e278d 100644 --- a/bittensor/utils/__init__.py +++ b/bittensor/utils/__init__.py @@ -1,5 +1,6 @@ import binascii import hashlib +from inspect import Attribute import math import multiprocessing import numbers diff --git a/tests/integration_tests/test_subtensor.py b/tests/integration_tests/test_subtensor.py index fca7cb08f9..e86f93746a 100644 --- a/tests/integration_tests/test_subtensor.py +++ b/tests/integration_tests/test_subtensor.py @@ -64,15 +64,15 @@ def setUp(self): assert True def test_defaults_to_nobunaga( self ): - assert self.subtensor.endpoint_for_network() in bittensor.__nobunaga_entrypoints__ + assert self.subtensor.endpoint_for_network() == bittensor.__nobunaga_entrypoint__ def test_networks( self ): - assert self.subtensor.endpoint_for_network() in bittensor.__nobunaga_entrypoints__ + assert self.subtensor.endpoint_for_network() == bittensor.__nobunaga_entrypoint__ def test_network_overrides( self ): config = bittensor.subtensor.config() subtensor = bittensor.subtensor(network='nobunaga', config=config, ) - assert subtensor.endpoint_for_network() in bittensor.__nobunaga_entrypoints__ + assert subtensor.endpoint_for_network() == bittensor.__nobunaga_entrypoint__ def test_connect_no_failure( self ): self.subtensor.connect(timeout = 1, failure=False) diff --git a/tests/unit_tests/bittensor_tests/utils/test_utils.py b/tests/unit_tests/bittensor_tests/utils/test_utils.py index fb748013fe..feb1807250 100644 --- a/tests/unit_tests/bittensor_tests/utils/test_utils.py +++ b/tests/unit_tests/bittensor_tests/utils/test_utils.py @@ -17,6 +17,8 @@ from _pytest.fixtures import fixture from loguru import logger +from types import SimpleNamespace + from unittest.mock import MagicMock, patch @@ -400,5 +402,58 @@ class MockException(Exception): assert call_params['nonce'] == mock_result['nonce'] +def test_pow_called_for_cuda(): + class MockException(Exception): + pass + mock_compose_call = MagicMock(side_effect=MockException) + + mock_subtensor = bittensor.subtensor(_mock=True) + mock_subtensor.neuron_for_pubkey=MagicMock(is_null=True) + mock_subtensor.substrate = MagicMock( + __enter__= MagicMock(return_value=MagicMock( + compose_call=mock_compose_call + )), + __exit__ = MagicMock(return_value=None), + ) + + mock_wallet = SimpleNamespace( + hotkey=SimpleNamespace( + ss58_address='' + ), + coldkeypub=SimpleNamespace( + ss58_address='' + ) + ) + + mock_result = { + "block_number": 1, + 'nonce': random.randint(0, pow(2, 32)), + 'work': b'\x00' * 64, + } + + with patch('bittensor.utils.POWNotStale', return_value=True) as mock_pow_not_stale: + with patch('torch.cuda.is_available', return_value=True) as mock_cuda_available: + with patch('bittensor.utils.create_pow', return_value=mock_result) as mock_create_pow: + with patch('bittensor.utils.hex_bytes_to_u8_list', return_value=b''): + + # Should exit early + with pytest.raises(MockException): + mock_subtensor.register(mock_wallet, cuda=True, prompt=False) + + mock_pow_not_stale.assert_called_once() + mock_create_pow.assert_called_once() + mock_cuda_available.assert_called_once() + + call0 = mock_pow_not_stale.call_args + assert call0[0][0] == mock_subtensor + assert call0[0][1] == mock_result + + mock_compose_call.assert_called_once() + call1 = mock_compose_call.call_args + assert call1[1]['call_function'] == 'register' + call_params = call1[1]['call_params'] + assert call_params['nonce'] == mock_result['nonce'] + + if __name__ == "__main__": - test_solve_for_difficulty_fast_registered_already() \ No newline at end of file + test_solve_for_difficulty_fast_registered_already()