55import threading
66from typing import TYPE_CHECKING
77
8- from substrateinterface .exceptions import SubstrateRequestException , ExtrinsicNotFound
8+ from substrateinterface .exceptions import SubstrateRequestException
99
1010from bittensor .utils .btlogging import logging
1111from bittensor .utils import format_error_message
1212
1313if TYPE_CHECKING :
14- from substrateinterface import SubstrateInterface , ExtrinsicReceipt
14+ from bittensor .core .subtensor import Subtensor
15+ from substrateinterface import ExtrinsicReceipt
1516 from scalecodec .types import GenericExtrinsic
1617
1718try :
2627
2728
2829def submit_extrinsic (
29- substrate : "SubstrateInterface " ,
30+ subtensor : "Subtensor " ,
3031 extrinsic : "GenericExtrinsic" ,
3132 wait_for_inclusion : bool ,
3233 wait_for_finalization : bool ,
@@ -39,7 +40,7 @@ def submit_extrinsic(
3940 it logs the error and re-raises the exception.
4041
4142 Args:
42- substrate (substrateinterface.SubstrateInterface) : The substrate interface instance used to interact with the blockchain.
43+ subtensor : The Subtensor instance used to interact with the blockchain.
4344 extrinsic (scalecodec.types.GenericExtrinsic): The extrinsic to be submitted to the blockchain.
4445 wait_for_inclusion (bool): Whether to wait for the extrinsic to be included in a block.
4546 wait_for_finalization (bool): Whether to wait for the extrinsic to be finalized on the blockchain.
@@ -51,20 +52,22 @@ def submit_extrinsic(
5152 SubstrateRequestException: If the submission of the extrinsic fails, the error is logged and re-raised.
5253 """
5354 extrinsic_hash = extrinsic .extrinsic_hash
54- starting_block = substrate .get_block ()
55+ starting_block = subtensor . substrate .get_block ()
5556
5657 timeout = EXTRINSIC_SUBMISSION_TIMEOUT
5758 event = threading .Event ()
5859
5960 def submit ():
6061 try :
61- response_ = substrate .submit_extrinsic (
62+ response_ = subtensor . substrate .submit_extrinsic (
6263 extrinsic ,
6364 wait_for_inclusion = wait_for_inclusion ,
6465 wait_for_finalization = wait_for_finalization ,
6566 )
6667 except SubstrateRequestException as e :
67- logging .error (format_error_message (e .args [0 ], substrate = substrate ))
68+ logging .error (
69+ format_error_message (e .args [0 ], substrate = subtensor .substrate )
70+ )
6871 # Re-raise the exception for retrying of the extrinsic call. If we remove the retry logic,
6972 # the raise will need to be removed.
7073 raise
@@ -76,28 +79,10 @@ def submit():
7679 response = None
7780 future = executor .submit (submit )
7881 if not event .wait (timeout ):
79- logging .error ("Timed out waiting for extrinsic submission." )
80- after_timeout_block = substrate .get_block ()
81-
82- for block_num in range (
83- starting_block ["header" ]["number" ],
84- after_timeout_block ["header" ]["number" ] + 1 ,
85- ):
86- block_hash = substrate .get_block_hash (block_num )
87- try :
88- response = substrate .retrieve_extrinsic_by_hash (
89- block_hash , f"0x{ extrinsic_hash .hex ()} "
90- )
91- except ExtrinsicNotFound :
92- continue
93- if response :
94- break
95- if response is None :
96- logging .error (
97- f"Extrinsic '0x{ extrinsic_hash .hex ()} ' not submitted. "
98- f"Initially attempted to submit at block { starting_block ['header' ]['number' ]} ."
99- )
100- raise SubstrateRequestException
82+ logging .error ("Timed out waiting for extrinsic submission. Reconnecting." )
83+ # force reconnection of the websocket
84+ subtensor ._get_substrate (force = True )
85+ raise SubstrateRequestException
10186
10287 else :
10388 response = future .result ()
0 commit comments