From c8b500d0d602004f750b4234d50994fa0405d36a Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Thu, 28 Nov 2024 12:34:28 -0800 Subject: [PATCH 1/9] Fixed logging configs not getting parsed when passing whole bittensor config --- bittensor/utils/btlogging/loggingmachine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bittensor/utils/btlogging/loggingmachine.py b/bittensor/utils/btlogging/loggingmachine.py index d4441054de..a3c51b3978 100644 --- a/bittensor/utils/btlogging/loggingmachine.py +++ b/bittensor/utils/btlogging/loggingmachine.py @@ -213,7 +213,7 @@ def set_config(self, config: "Config"): Args: config (bittensor.core.config.Config): Bittensor config instance. """ - self._config = config + self._config = config = self._extract_logging_config(config) if config.logging_dir and config.record_log: expanded_dir = os.path.expanduser(config.logging_dir) logfile = os.path.abspath(os.path.join(expanded_dir, DEFAULT_LOG_FILE_NAME)) From 04a8714d1168b15b42157bea86416b2d6e627de8 Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Thu, 28 Nov 2024 15:12:41 -0800 Subject: [PATCH 2/9] Handles defaultmunch behaviour --- bittensor/utils/btlogging/loggingmachine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bittensor/utils/btlogging/loggingmachine.py b/bittensor/utils/btlogging/loggingmachine.py index a3c51b3978..4915e3a30e 100644 --- a/bittensor/utils/btlogging/loggingmachine.py +++ b/bittensor/utils/btlogging/loggingmachine.py @@ -182,7 +182,7 @@ def _extract_logging_config(self, config: "Config") -> dict: Returns: (dict): btlogging's config from Bittensor config or Bittensor config. """ - if hasattr(config, "logging"): + if hasattr(config, "logging") and getattr(config, "logging", None): return config.logging else: return config From 35fd6763d2c039ec5ffc2a064ba30c0788d16f1c Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Fri, 29 Nov 2024 11:32:56 -0800 Subject: [PATCH 3/9] Improvements --- bittensor/utils/btlogging/loggingmachine.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/bittensor/utils/btlogging/loggingmachine.py b/bittensor/utils/btlogging/loggingmachine.py index 4915e3a30e..e6fe0704e0 100644 --- a/bittensor/utils/btlogging/loggingmachine.py +++ b/bittensor/utils/btlogging/loggingmachine.py @@ -182,7 +182,8 @@ def _extract_logging_config(self, config: "Config") -> dict: Returns: (dict): btlogging's config from Bittensor config or Bittensor config. """ - if hasattr(config, "logging") and getattr(config, "logging", None): + # This is to handle + if getattr(config, "logging", None): return config.logging else: return config @@ -213,14 +214,14 @@ def set_config(self, config: "Config"): Args: config (bittensor.core.config.Config): Bittensor config instance. """ - self._config = config = self._extract_logging_config(config) - if config.logging_dir and config.record_log: + self._config = self._extract_logging_config(config) + if self._config.logging_dir and self._config.record_log: expanded_dir = os.path.expanduser(config.logging_dir) logfile = os.path.abspath(os.path.join(expanded_dir, DEFAULT_LOG_FILE_NAME)) self._enable_file_logging(logfile) - if config.trace: + if self._config.trace: self.enable_trace() - elif config.debug: + elif self._config.debug: self.enable_debug() def _create_and_start_listener(self, handlers): @@ -618,7 +619,7 @@ def __call__( logging_dir: str = None, ): if config is not None: - cfg = copy.deepcopy(config) + cfg = self._extract_logging_config(config) if debug is not None: cfg.debug = debug elif trace is not None: From b70c2cd700b3f6cc7068f351a6bd5a34cd3177a4 Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Fri, 29 Nov 2024 12:16:47 -0800 Subject: [PATCH 4/9] Removes unused import --- bittensor/utils/btlogging/loggingmachine.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bittensor/utils/btlogging/loggingmachine.py b/bittensor/utils/btlogging/loggingmachine.py index e6fe0704e0..f172b9d5e8 100644 --- a/bittensor/utils/btlogging/loggingmachine.py +++ b/bittensor/utils/btlogging/loggingmachine.py @@ -23,7 +23,6 @@ import argparse import atexit -import copy import logging as stdlogging import multiprocessing as mp import os From 263218ab5c65bc7bf36bb93a129ecc240f1f234d Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Fri, 29 Nov 2024 12:17:48 -0800 Subject: [PATCH 5/9] Completes comment --- bittensor/utils/btlogging/loggingmachine.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bittensor/utils/btlogging/loggingmachine.py b/bittensor/utils/btlogging/loggingmachine.py index f172b9d5e8..96d0b2ceed 100644 --- a/bittensor/utils/btlogging/loggingmachine.py +++ b/bittensor/utils/btlogging/loggingmachine.py @@ -181,7 +181,7 @@ def _extract_logging_config(self, config: "Config") -> dict: Returns: (dict): btlogging's config from Bittensor config or Bittensor config. """ - # This is to handle + # This is to handle nature of DefaultMunch if getattr(config, "logging", None): return config.logging else: From 1f7279f26fc2fd28eede9a0aca6068ee78c31d89 Mon Sep 17 00:00:00 2001 From: Benjamin Himes <37844818+thewhaleking@users.noreply.github.com> Date: Mon, 2 Dec 2024 22:59:07 +0200 Subject: [PATCH 6/9] Improve `submit_extrinsic` util (#2502) Improve `submit_extrinsic` util --- bittensor/core/extrinsics/commit_weights.py | 4 +- bittensor/core/extrinsics/registration.py | 4 +- bittensor/core/extrinsics/root.py | 4 +- bittensor/core/extrinsics/serving.py | 4 +- bittensor/core/extrinsics/set_weights.py | 2 +- bittensor/core/extrinsics/transfer.py | 2 +- bittensor/core/extrinsics/utils.py | 43 +++++----------- bittensor/core/subtensor.py | 18 +++++-- tests/e2e_tests/test_commit_weights.py | 2 + tests/unit_tests/extrinsics/test_utils.py | 57 ++++++++++++--------- 10 files changed, 72 insertions(+), 68 deletions(-) diff --git a/bittensor/core/extrinsics/commit_weights.py b/bittensor/core/extrinsics/commit_weights.py index ef93a15d3e..dacfd27ea0 100644 --- a/bittensor/core/extrinsics/commit_weights.py +++ b/bittensor/core/extrinsics/commit_weights.py @@ -71,7 +71,7 @@ def do_commit_weights( keypair=wallet.hotkey, ) response = submit_extrinsic( - substrate=self.substrate, + subtensor=self, extrinsic=extrinsic, wait_for_inclusion=wait_for_inclusion, wait_for_finalization=wait_for_finalization, @@ -184,7 +184,7 @@ def do_reveal_weights( keypair=wallet.hotkey, ) response = submit_extrinsic( - substrate=self.substrate, + subtensor=self, extrinsic=extrinsic, wait_for_inclusion=wait_for_inclusion, wait_for_finalization=wait_for_finalization, diff --git a/bittensor/core/extrinsics/registration.py b/bittensor/core/extrinsics/registration.py index e9836938d8..f4a0848d68 100644 --- a/bittensor/core/extrinsics/registration.py +++ b/bittensor/core/extrinsics/registration.py @@ -66,7 +66,7 @@ def _do_pow_register( ) extrinsic = self.substrate.create_signed_extrinsic(call=call, keypair=wallet.hotkey) response = submit_extrinsic( - substrate=self.substrate, + self, extrinsic=extrinsic, wait_for_inclusion=wait_for_inclusion, wait_for_finalization=wait_for_finalization, @@ -297,7 +297,7 @@ def _do_burned_register( call=call, keypair=wallet.coldkey ) response = submit_extrinsic( - self.substrate, + self, extrinsic, wait_for_inclusion=wait_for_inclusion, wait_for_finalization=wait_for_finalization, diff --git a/bittensor/core/extrinsics/root.py b/bittensor/core/extrinsics/root.py index e4fec236fc..629109f9a6 100644 --- a/bittensor/core/extrinsics/root.py +++ b/bittensor/core/extrinsics/root.py @@ -33,7 +33,7 @@ def _do_root_register( call=call, keypair=wallet.coldkey ) response = submit_extrinsic( - self.substrate, + self, extrinsic, wait_for_inclusion=wait_for_inclusion, wait_for_finalization=wait_for_finalization, @@ -159,7 +159,7 @@ def _do_set_root_weights( era={"period": period}, ) response = submit_extrinsic( - self.substrate, + self, extrinsic, wait_for_inclusion=wait_for_inclusion, wait_for_finalization=wait_for_finalization, diff --git a/bittensor/core/extrinsics/serving.py b/bittensor/core/extrinsics/serving.py index 1c26b87e76..87dc96cc37 100644 --- a/bittensor/core/extrinsics/serving.py +++ b/bittensor/core/extrinsics/serving.py @@ -75,7 +75,7 @@ def do_serve_axon( ) extrinsic = self.substrate.create_signed_extrinsic(call=call, keypair=wallet.hotkey) response = submit_extrinsic( - substrate=self.substrate, + self, extrinsic=extrinsic, wait_for_inclusion=wait_for_inclusion, wait_for_finalization=wait_for_finalization, @@ -289,7 +289,7 @@ def publish_metadata( extrinsic = substrate.create_signed_extrinsic(call=call, keypair=wallet.hotkey) response = submit_extrinsic( - substrate, + self, extrinsic, wait_for_inclusion=wait_for_inclusion, wait_for_finalization=wait_for_finalization, diff --git a/bittensor/core/extrinsics/set_weights.py b/bittensor/core/extrinsics/set_weights.py index 880480e998..79c7e409a4 100644 --- a/bittensor/core/extrinsics/set_weights.py +++ b/bittensor/core/extrinsics/set_weights.py @@ -83,7 +83,7 @@ def do_set_weights( era={"period": period}, ) response = submit_extrinsic( - substrate=self.substrate, + self, extrinsic=extrinsic, wait_for_inclusion=wait_for_inclusion, wait_for_finalization=wait_for_finalization, diff --git a/bittensor/core/extrinsics/transfer.py b/bittensor/core/extrinsics/transfer.py index c3b919f381..1544476756 100644 --- a/bittensor/core/extrinsics/transfer.py +++ b/bittensor/core/extrinsics/transfer.py @@ -70,7 +70,7 @@ def do_transfer( call=call, keypair=wallet.coldkey ) response = submit_extrinsic( - substrate=self.substrate, + self, extrinsic=extrinsic, wait_for_inclusion=wait_for_inclusion, wait_for_finalization=wait_for_finalization, diff --git a/bittensor/core/extrinsics/utils.py b/bittensor/core/extrinsics/utils.py index 967d8c5a6f..7a73b75669 100644 --- a/bittensor/core/extrinsics/utils.py +++ b/bittensor/core/extrinsics/utils.py @@ -5,13 +5,14 @@ import threading from typing import TYPE_CHECKING -from substrateinterface.exceptions import SubstrateRequestException, ExtrinsicNotFound +from substrateinterface.exceptions import SubstrateRequestException from bittensor.utils.btlogging import logging from bittensor.utils import format_error_message if TYPE_CHECKING: - from substrateinterface import SubstrateInterface, ExtrinsicReceipt + from bittensor.core.subtensor import Subtensor + from substrateinterface import ExtrinsicReceipt from scalecodec.types import GenericExtrinsic try: @@ -26,7 +27,7 @@ def submit_extrinsic( - substrate: "SubstrateInterface", + subtensor: "Subtensor", extrinsic: "GenericExtrinsic", wait_for_inclusion: bool, wait_for_finalization: bool, @@ -39,7 +40,7 @@ def submit_extrinsic( it logs the error and re-raises the exception. Args: - substrate (substrateinterface.SubstrateInterface): The substrate interface instance used to interact with the blockchain. + subtensor: The Subtensor instance used to interact with the blockchain. extrinsic (scalecodec.types.GenericExtrinsic): The extrinsic to be submitted to the blockchain. wait_for_inclusion (bool): Whether to wait for the extrinsic to be included in a block. wait_for_finalization (bool): Whether to wait for the extrinsic to be finalized on the blockchain. @@ -51,20 +52,22 @@ def submit_extrinsic( SubstrateRequestException: If the submission of the extrinsic fails, the error is logged and re-raised. """ extrinsic_hash = extrinsic.extrinsic_hash - starting_block = substrate.get_block() + starting_block = subtensor.substrate.get_block() timeout = EXTRINSIC_SUBMISSION_TIMEOUT event = threading.Event() def submit(): try: - response_ = substrate.submit_extrinsic( + response_ = subtensor.substrate.submit_extrinsic( extrinsic, wait_for_inclusion=wait_for_inclusion, wait_for_finalization=wait_for_finalization, ) except SubstrateRequestException as e: - logging.error(format_error_message(e.args[0], substrate=substrate)) + logging.error( + format_error_message(e.args[0], substrate=subtensor.substrate) + ) # Re-raise the exception for retrying of the extrinsic call. If we remove the retry logic, # the raise will need to be removed. raise @@ -76,28 +79,10 @@ def submit(): response = None future = executor.submit(submit) if not event.wait(timeout): - logging.error("Timed out waiting for extrinsic submission.") - after_timeout_block = substrate.get_block() - - for block_num in range( - starting_block["header"]["number"], - after_timeout_block["header"]["number"] + 1, - ): - block_hash = substrate.get_block_hash(block_num) - try: - response = substrate.retrieve_extrinsic_by_hash( - block_hash, f"0x{extrinsic_hash.hex()}" - ) - except ExtrinsicNotFound: - continue - if response: - break - if response is None: - logging.error( - f"Extrinsic '0x{extrinsic_hash.hex()}' not submitted. " - f"Initially attempted to submit at block {starting_block['header']['number']}." - ) - raise SubstrateRequestException + logging.error("Timed out waiting for extrinsic submission. Reconnecting.") + # force reconnection of the websocket + subtensor._get_substrate(force=True) + raise SubstrateRequestException else: response = future.result() diff --git a/bittensor/core/subtensor.py b/bittensor/core/subtensor.py index fa46242277..bb110559c2 100644 --- a/bittensor/core/subtensor.py +++ b/bittensor/core/subtensor.py @@ -212,11 +212,21 @@ def close(self): if self.substrate: self.substrate.close() - def _get_substrate(self): - """Establishes a connection to the Substrate node using configured parameters.""" + def _get_substrate(self, force: bool = False): + """ + Establishes a connection to the Substrate node using configured parameters. + + Args: + force: forces a reconnection if this flag is set + + """ try: # Set up params. - if self.websocket is None or self.websocket.close_code is not None: + if force and self.websocket: + logging.debug("Closing websocket connection") + self.websocket.close() + + if force or self.websocket is None or self.websocket.close_code is not None: self.websocket = ws_client.connect( self.chain_endpoint, open_timeout=self._connection_timeout, @@ -229,7 +239,7 @@ def _get_substrate(self): websocket=self.websocket, ) if self.log_verbose: - logging.debug( + logging.info( f"Connected to {self.network} network and {self.chain_endpoint}." ) diff --git a/tests/e2e_tests/test_commit_weights.py b/tests/e2e_tests/test_commit_weights.py index 7596004603..3e29dc56ec 100644 --- a/tests/e2e_tests/test_commit_weights.py +++ b/tests/e2e_tests/test_commit_weights.py @@ -6,6 +6,7 @@ from bittensor.core.subtensor import Subtensor from bittensor.utils.balance import Balance from bittensor.utils.weight_utils import convert_weights_and_uids_for_emit +from bittensor.core.extrinsics import utils from tests.e2e_tests.utils.chain_interactions import ( add_stake, register_subnet, @@ -32,6 +33,7 @@ async def test_commit_and_reveal_weights(local_chain): AssertionError: If any of the checks or verifications fail """ netuid = 1 + utils.EXTRINSIC_SUBMISSION_TIMEOUT = 12 # handle fast blocks print("Testing test_commit_and_reveal_weights") # Register root as Alice keypair, alice_wallet = setup_wallet("//Alice") diff --git a/tests/unit_tests/extrinsics/test_utils.py b/tests/unit_tests/extrinsics/test_utils.py index 38a92e3dc2..ca8d92e29e 100644 --- a/tests/unit_tests/extrinsics/test_utils.py +++ b/tests/unit_tests/extrinsics/test_utils.py @@ -2,13 +2,12 @@ from unittest.mock import MagicMock, patch import importlib import pytest -from substrateinterface.base import ( - SubstrateInterface, - GenericExtrinsic, - SubstrateRequestException, -) +from scalecodec.types import GenericExtrinsic +from substrateinterface.base import SubstrateInterface, ExtrinsicReceipt +from substrateinterface.exceptions import ExtrinsicNotFound, SubstrateRequestException from bittensor.core.extrinsics import utils +from bittensor.core.subtensor import Subtensor @pytest.fixture @@ -16,30 +15,41 @@ def set_extrinsics_timeout_env(monkeypatch): monkeypatch.setenv("EXTRINSIC_SUBMISSION_TIMEOUT", "1") -def test_submit_extrinsic_timeout(): +@pytest.fixture +def mock_subtensor(): + mock_subtensor = MagicMock(autospec=Subtensor) + mock_substrate = MagicMock(autospec=SubstrateInterface) + mock_subtensor.substrate = mock_substrate + yield mock_subtensor + + +@pytest.fixture +def starting_block(): + yield {"header": {"number": 1, "hash": "0x0100"}} + + +def test_submit_extrinsic_timeout(mock_subtensor): timeout = 1 def wait(extrinsic, wait_for_inclusion, wait_for_finalization): time.sleep(timeout + 0.01) return True - mock_substrate = MagicMock(autospec=SubstrateInterface) - mock_substrate.submit_extrinsic = wait + mock_subtensor.substrate.submit_extrinsic = wait mock_extrinsic = MagicMock(autospec=GenericExtrinsic) with patch.object(utils, "EXTRINSIC_SUBMISSION_TIMEOUT", timeout): with pytest.raises(SubstrateRequestException): - utils.submit_extrinsic(mock_substrate, mock_extrinsic, True, True) + utils.submit_extrinsic(mock_subtensor, mock_extrinsic, True, True) -def test_submit_extrinsic_success(): - mock_substrate = MagicMock(autospec=SubstrateInterface) - mock_substrate.submit_extrinsic.return_value = True +def test_submit_extrinsic_success(mock_subtensor): + mock_subtensor.substrate.submit_extrinsic.return_value = True mock_extrinsic = MagicMock(autospec=GenericExtrinsic) - result = utils.submit_extrinsic(mock_substrate, mock_extrinsic, True, True) + result = utils.submit_extrinsic(mock_subtensor, mock_extrinsic, True, True) assert result is True -def test_submit_extrinsic_timeout_env(set_extrinsics_timeout_env): +def test_submit_extrinsic_timeout_env(set_extrinsics_timeout_env, mock_subtensor): importlib.reload(utils) timeout = utils.EXTRINSIC_SUBMISSION_TIMEOUT assert timeout < 5 # should be less than 5 seconds as taken from test env var @@ -48,23 +58,21 @@ def wait(extrinsic, wait_for_inclusion, wait_for_finalization): time.sleep(timeout + 1) return True - mock_substrate = MagicMock(autospec=SubstrateInterface) - mock_substrate.submit_extrinsic = wait + mock_subtensor.substrate.submit_extrinsic = wait mock_extrinsic = MagicMock(autospec=GenericExtrinsic) with pytest.raises(SubstrateRequestException): - utils.submit_extrinsic(mock_substrate, mock_extrinsic, True, True) + utils.submit_extrinsic(mock_subtensor, mock_extrinsic, True, True) -def test_submit_extrinsic_success_env(set_extrinsics_timeout_env): +def test_submit_extrinsic_success_env(set_extrinsics_timeout_env, mock_subtensor): importlib.reload(utils) - mock_substrate = MagicMock(autospec=SubstrateInterface) - mock_substrate.submit_extrinsic.return_value = True + mock_subtensor.substrate.submit_extrinsic.return_value = True mock_extrinsic = MagicMock(autospec=GenericExtrinsic) - result = utils.submit_extrinsic(mock_substrate, mock_extrinsic, True, True) + result = utils.submit_extrinsic(mock_subtensor, mock_extrinsic, True, True) assert result is True -def test_submit_extrinsic_timeout_env_float(monkeypatch): +def test_submit_extrinsic_timeout_env_float(monkeypatch, mock_subtensor): monkeypatch.setenv("EXTRINSIC_SUBMISSION_TIMEOUT", "1.45") # use float importlib.reload(utils) @@ -76,11 +84,10 @@ def wait(extrinsic, wait_for_inclusion, wait_for_finalization): time.sleep(timeout + 0.3) # sleep longer by float return True - mock_substrate = MagicMock(autospec=SubstrateInterface) - mock_substrate.submit_extrinsic = wait + mock_subtensor.substrate.submit_extrinsic = wait mock_extrinsic = MagicMock(autospec=GenericExtrinsic) with pytest.raises(SubstrateRequestException): - utils.submit_extrinsic(mock_substrate, mock_extrinsic, True, True) + utils.submit_extrinsic(mock_subtensor, mock_extrinsic, True, True) def test_import_timeout_env_parse(monkeypatch): From 6b486fc63cc05a29a51bcbcda48a1d2c50e00567 Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Mon, 2 Dec 2024 13:10:35 -0800 Subject: [PATCH 7/9] Bumps version and updates changelog --- CHANGELOG.md | 10 ++++++++++ VERSION | 2 +- bittensor/core/settings.py | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b061d7916e..e6b8a8fde0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## 8.4.3 /2024-12-02 + +## What's Changed + +* Fix logging config parsing by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2500 +* Improve `submit_extrinsic` util by @thewhaleking in https://github.com/opentensor/bittensor/pull/2502 +* Backmerge master to staging for 843 by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2505 + +**Full Changelog**: https://github.com/opentensor/bittensor/compare/v8.4.2...v8.4.3 + ## 8.4.2 /2024-11-28 ## What's Changed diff --git a/VERSION b/VERSION index 7857a9473e..01129dc3ec 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -8.4.2 \ No newline at end of file +8.4.3 \ No newline at end of file diff --git a/bittensor/core/settings.py b/bittensor/core/settings.py index f15754e227..d7a08c60fa 100644 --- a/bittensor/core/settings.py +++ b/bittensor/core/settings.py @@ -15,7 +15,7 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER # DEALINGS IN THE SOFTWARE. -__version__ = "8.4.2" +__version__ = "8.4.3" import os import re From 46338661f986131a42c180444d0466428d98e36f Mon Sep 17 00:00:00 2001 From: Benjamin Himes <37844818+thewhaleking@users.noreply.github.com> Date: Tue, 3 Dec 2024 00:04:19 +0200 Subject: [PATCH 8/9] WS ensure_connected socket catch (#2507) * Catch OSError for getsockopt --- bittensor/utils/networking.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bittensor/utils/networking.py b/bittensor/utils/networking.py index 21a9f1be7a..8743e8d253 100644 --- a/bittensor/utils/networking.py +++ b/bittensor/utils/networking.py @@ -168,10 +168,11 @@ def ensure_connected(func): def is_connected(substrate) -> bool: """Check if the substrate connection is active.""" sock = substrate.websocket.socket - return ( - sock is not None - and sock.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR) == 0 - ) + try: + sock_opt = sock.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR) + return sock is not None and sock_opt == 0 + except (OSError, AttributeError): + return False @retry( exceptions=ConnectionRefusedError, From b7c8bdf3739177bb149488490d2eae186f967070 Mon Sep 17 00:00:00 2001 From: ibraheem-opentensor Date: Mon, 2 Dec 2024 14:05:27 -0800 Subject: [PATCH 9/9] Updates changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6b8a8fde0..d2f6f7c7dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Fix logging config parsing by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2500 * Improve `submit_extrinsic` util by @thewhaleking in https://github.com/opentensor/bittensor/pull/2502 * Backmerge master to staging for 843 by @ibraheem-opentensor in https://github.com/opentensor/bittensor/pull/2505 +* WS ensure_connected socket catch by @thewhaleking in https://github.com/opentensor/bittensor/pull/2507 **Full Changelog**: https://github.com/opentensor/bittensor/compare/v8.4.2...v8.4.3