diff --git a/CHANGELOG.md b/CHANGELOG.md index 6935553b55..4992a86911 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## 6.4.1 / 2023-12-01 + +## What's Changed +* add helpful messages to signal coming changes in https://github.com/opentensor/bittensor/pull/1600/commits/86c0c3ccfcd91d0e3ff87f53bdc3e9c5e68661da +* revert default subtensor network to finney in https://github.com/opentensor/bittensor/pull/1600/commits/8c69a3c15cd556384d0309e951f0a9b164dd36cb + +**Full Changelog**: https://github.com/opentensor/bittensor/compare/v6.0.1...v6.4.1 + + ## 6.4.0 / 2023-11-29 ## What's Changed diff --git a/VERSION b/VERSION index 19b860c187..306894a15e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.4.0 +6.4.1 \ No newline at end of file diff --git a/bittensor/__init__.py b/bittensor/__init__.py index 72fd3a0654..196f632ce4 100644 --- a/bittensor/__init__.py +++ b/bittensor/__init__.py @@ -27,7 +27,7 @@ nest_asyncio.apply() # Bittensor code and protocol version. -__version__ = "6.4.0" +__version__ = "6.4.1" version_split = __version__.split(".") __version_as_int__ = ( (100 * int(version_split[0])) diff --git a/bittensor/subtensor.py b/bittensor/subtensor.py index 20dc254599..52ae1b482c 100644 --- a/bittensor/subtensor.py +++ b/bittensor/subtensor.py @@ -109,8 +109,8 @@ class subtensor: investments. Attributes: - network (str): The name of the Bittensor network (e.g., 'finney', 'local') the instance is - connected to, determining the blockchain interaction context. + network (str): The name of the Bittensor network (e.g., 'finney', 'test', 'archive', 'local') the instance + is connected to, determining the blockchain interaction context. chain_endpoint (str): The blockchain node endpoint URL, enabling direct communication with the Bittensor blockchain for transaction processing and data retrieval. @@ -154,18 +154,20 @@ def help(cls): def add_args(cls, parser: argparse.ArgumentParser, prefix: str = None): prefix_str = "" if prefix == None else prefix + "." try: - default_network = os.getenv("BT_SUBTENSOR_NETWORK") or "local" + default_network = os.getenv("BT_SUBTENSOR_NETWORK") or "finney" default_chain_endpoint = ( os.getenv("BT_SUBTENSOR_CHAIN_ENDPOINT") - or bittensor.__local_entrypoint__ + or bittensor.__finney_entrypoint__ ) parser.add_argument( "--" + prefix_str + "subtensor.network", default=default_network, type=str, help="""The subtensor network flag. The likely choices are: - -- local (local running network) -- finney (main network) + -- test (test network) + -- archive (archive network +300 blocks) + -- local (local running network) If this option is set it overloads subtensor.chain_endpoint with an entry point node from that network. """, @@ -195,6 +197,7 @@ def determine_chain_endpoint_and_network(network: str): Args: network (str): The network flag. The likely choices are: -- finney (main network) + -- archive (archive network +300 blocks) -- local (local running network) -- test (test network) chain_endpoint (str): The chain endpoint flag. If set, overrides the network argument. @@ -299,6 +302,13 @@ def __init__( """ Initializes a Subtensor interface for interacting with the Bittensor blockchain. + NOTE: Currently subtensor defaults to the finney network. This will change in a future release. + + We strongly encourage users to run their own local subtensor node whenever possible. This increases + decentralization and resilience of the network. In a future release, local subtensor will become the + default and the fallback to finney removed. Please plan ahead for this change. We will provide detailed + instructions on how to run a local subtensor node in the documentation in a subsequent release. + Args: network (str, optional): The network name to connect to (e.g., 'finney', 'local'). Defaults to the main Bittensor network if not specified. @@ -320,6 +330,22 @@ def __init__( # Setup config.subtensor.network and config.subtensor.chain_endpoint self.chain_endpoint, self.network = subtensor.setup_config(network, config) + if ( + self.network == "finney" + or self.chain_endpoint == bittensor.__finney_entrypoint__ + ): + bittensor.logging.info( + f"You are connecting to {self.network} network with endpoint {self.chain_endpoint}." + ) + bittensor.logging.warning( + "We strongly encourage running a local subtensor node whenever possible. " + "This increases decentralization and resilience of the network." + ) + bittensor.logging.warning( + "In a future release, local subtensor will become the default endpoint. " + "To get ahead of this change, please run a local subtensor node and point to it." + ) + # Returns a mocked connection with a background chain connection. self.config.subtensor._mock = ( _mock @@ -330,12 +356,27 @@ def __init__( config.subtensor._mock = True return bittensor.subtensor_mock.MockSubtensor() - # Set up params. - self.substrate = SubstrateInterface( - ss58_format=bittensor.__ss58_format__, - use_remote_preset=True, - url=self.chain_endpoint, - type_registry=bittensor.__type_registry__, + # Attempt to connect to chosen endpoint. Fallback to finney if local unavailable. + try: + # Set up params. + self.substrate = SubstrateInterface( + ss58_format=bittensor.__ss58_format__, + use_remote_preset=True, + url=self.chain_endpoint, + type_registry=bittensor.__type_registry__, + ) + except ConnectionRefusedError as e: + bittensor.logging.error( + f"Could not connect to {self.network} network with {self.chain_endpoint} chain endpoint. Exiting..." + ) + bittensor.logging.info( + f"You can check if you have connectivity by runing this command: nc -vz localhost {self.chain_endpoint.split(':')[2]}" + ) + exit(1) + # TODO (edu/phil): Advise to run local subtensor and point to dev docs. + + bittensor.logging.info( + f"Connected to {self.network} network and {self.chain_endpoint}." ) def __str__(self) -> str: diff --git a/tests/integration_tests/test_subtensor_integration.py b/tests/integration_tests/test_subtensor_integration.py index a01ee90ddd..ab00e903e5 100644 --- a/tests/integration_tests/test_subtensor_integration.py +++ b/tests/integration_tests/test_subtensor_integration.py @@ -587,25 +587,10 @@ class ExitEarly(Exception): msg="only tries to submit once, then exits", ) - @staticmethod - def is_port_open(host, port): - """Check if a port is open on a given host.""" - with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: - return s.connect_ex((host, port)) == 0 - - def test_defaults_to_local(self): - port = int( - bittensor.__local_entrypoint__.split(":")[-1] - ) # Default port for local subtensor - if self.is_port_open("127.0.0.1", port): - # If service is running, check default values - sub = bittensor.subtensor() - self.assertEqual(sub.network, "local") - self.assertEqual(sub.chain_endpoint, bittensor.__local_entrypoint__) - else: - # If service is not running, expect a ConnectionRefusedError - with self.assertRaises(ConnectionRefusedError): - bittensor.subtensor() + def test_defaults_to_finney(self): + sub = bittensor.subtensor() + assert sub.network == "finney" + assert sub.chain_endpoint == bittensor.__finney_entrypoint__ if __name__ == "__main__":