Skip to content

Commit

Permalink
Improve submit_extrinsic with testing. Now correctly doesn't freeze…
Browse files Browse the repository at this point in the history
…, recovers connection, and has improved e2e test.
  • Loading branch information
thewhaleking committed Nov 30, 2024
1 parent 70d13fb commit 8cc5d77
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion bittensor/core/extrinsics/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ def submit():
response = subtensor.substrate.retrieve_extrinsic_by_hash(
block_hash, f"0x{extrinsic_hash.hex()}"
)
except ExtrinsicNotFound:
except (ExtrinsicNotFound, SubstrateRequestException):
continue
if response:
logging.debug(f"Recovered extrinsic: {extrinsic}")
break
if response is None:
logging.error(
Expand Down
6 changes: 5 additions & 1 deletion bittensor/core/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ def _get_substrate(self, force: bool = False):
"""
try:
# Set up params.
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,
Expand All @@ -235,7 +239,7 @@ def _get_substrate(self, force: bool = False):
websocket=self.websocket,
)
if self.log_verbose:
logging.debug(
logging.info(
f"Connected to {self.network} network and {self.chain_endpoint}."
)

Expand Down
2 changes: 2 additions & 0 deletions tests/e2e_tests/test_commit_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand Down

0 comments on commit 8cc5d77

Please sign in to comment.