Skip to content

Commit 8cc5d77

Browse files
committed
Improve submit_extrinsic with testing. Now correctly doesn't freeze, recovers connection, and has improved e2e test.
1 parent 70d13fb commit 8cc5d77

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

bittensor/core/extrinsics/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,10 @@ def submit():
9393
response = subtensor.substrate.retrieve_extrinsic_by_hash(
9494
block_hash, f"0x{extrinsic_hash.hex()}"
9595
)
96-
except ExtrinsicNotFound:
96+
except (ExtrinsicNotFound, SubstrateRequestException):
9797
continue
9898
if response:
99+
logging.debug(f"Recovered extrinsic: {extrinsic}")
99100
break
100101
if response is None:
101102
logging.error(

bittensor/core/subtensor.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ def _get_substrate(self, force: bool = False):
222222
"""
223223
try:
224224
# Set up params.
225+
if force and self.websocket:
226+
logging.debug("Closing websocket connection")
227+
self.websocket.close()
228+
225229
if force or self.websocket is None or self.websocket.close_code is not None:
226230
self.websocket = ws_client.connect(
227231
self.chain_endpoint,
@@ -235,7 +239,7 @@ def _get_substrate(self, force: bool = False):
235239
websocket=self.websocket,
236240
)
237241
if self.log_verbose:
238-
logging.debug(
242+
logging.info(
239243
f"Connected to {self.network} network and {self.chain_endpoint}."
240244
)
241245

tests/e2e_tests/test_commit_weights.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from bittensor.core.subtensor import Subtensor
77
from bittensor.utils.balance import Balance
88
from bittensor.utils.weight_utils import convert_weights_and_uids_for_emit
9+
from bittensor.core.extrinsics import utils
910
from tests.e2e_tests.utils.chain_interactions import (
1011
add_stake,
1112
register_subnet,
@@ -32,6 +33,7 @@ async def test_commit_and_reveal_weights(local_chain):
3233
AssertionError: If any of the checks or verifications fail
3334
"""
3435
netuid = 1
36+
utils.EXTRINSIC_SUBMISSION_TIMEOUT = 12 # handle fast blocks
3537
print("Testing test_commit_and_reveal_weights")
3638
# Register root as Alice
3739
keypair, alice_wallet = setup_wallet("//Alice")

0 commit comments

Comments
 (0)