Skip to content

Commit 5e3c65f

Browse files
committed
chore: remove default retry usage and keep retry utility optional
1 parent 94d5894 commit 5e3c65f

File tree

3 files changed

+24
-96
lines changed

3 files changed

+24
-96
lines changed

bittensor/core/dendrite.py

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from bittensor.core.stream import StreamingSynapse
1616
from bittensor.core.synapse import Synapse, TerminalInfo
1717
from bittensor.utils import networking
18-
from bittensor.utils.retry import retry_async
18+
1919
from bittensor.utils.btlogging import logging
2020
from bittensor.utils.registration import torch, use_torch
2121

@@ -576,29 +576,16 @@ async def call(
576576
self._log_outgoing_request(synapse)
577577

578578
# Make the HTTP POST request
579-
async def _make_request():
580-
async with (await self.session).post(
581-
url=url,
582-
headers=synapse.to_headers(),
583-
json=synapse.model_dump(),
584-
timeout=aiohttp.ClientTimeout(total=timeout),
585-
) as response:
586-
# Extract the JSON response from the server
587-
json_response = await response.json()
588-
# Process the server response and fill synapse
589-
self.process_server_response(response, json_response, synapse)
590-
591-
# Retry the request if enabled
592-
await retry_async(
593-
_make_request,
594-
retry_exceptions=(
595-
aiohttp.ClientConnectorError,
596-
asyncio.TimeoutError,
597-
aiohttp.ServerDisconnectedError,
598-
aiohttp.ServerConnectionError,
599-
aiohttp.ClientError,
600-
),
601-
)
579+
async with (await self.session).post(
580+
url=url,
581+
headers=synapse.to_headers(),
582+
json=synapse.model_dump(),
583+
timeout=aiohttp.ClientTimeout(total=timeout),
584+
) as response:
585+
# Extract the JSON response from the server
586+
json_response = await response.json()
587+
# Process the server response and fill synapse
588+
self.process_server_response(response, json_response, synapse)
602589

603590
# Set process time and log the response
604591
synapse.dendrite.process_time = str(time.time() - start_time) # type: ignore
@@ -678,13 +665,7 @@ async def _make_stream_request():
678665

679666
# Process the server response
680667
self.process_server_response(response, json_response, synapse)
681-
682-
# NOTE: streaming requests (`call_stream`) are intentionally NOT retried here.
683-
# Async generators cannot be safely retried once they start yielding data without buffering
684-
# or complex replay logic, which risks protocol side effects.
685-
# To enable retries for streaming, the higher-level caller must handle the restart logic.
686668

687-
688669
async with (await self.session).post(
689670
url,
690671
headers=synapse.to_headers(),

bittensor/core/subtensor.py

Lines changed: 9 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163
price_to_tick,
164164
tick_to_price,
165165
)
166-
from bittensor.utils.retry import retry_call
166+
167167

168168
if TYPE_CHECKING:
169169
from async_substrate_interface.sync_substrate import QueryMapResult
@@ -564,19 +564,11 @@ def get_hyperparameter(
564564
logging.error(f"subnet {netuid} does not exist")
565565
return None
566566

567-
result = retry_call(
568-
self.substrate.query,
567+
result = self.substrate.query(
569568
module="SubtensorModule",
570569
storage_function=param_name,
571570
params=[netuid],
572571
block_hash=block_hash,
573-
retry_exceptions=(
574-
SubstrateRequestException,
575-
ConnectionRefusedError,
576-
TimeoutError,
577-
BrokenPipeError,
578-
ConnectionResetError,
579-
),
580572
)
581573

582574
if result is None:
@@ -719,18 +711,10 @@ def query_constant(
719711
Common types include int (for counts/blocks), Balance objects (for amounts in Rao), and booleans.
720712
721713
"""
722-
return retry_call(
723-
self.substrate.get_constant,
714+
return self.substrate.get_constant(
724715
module_name=module_name,
725716
constant_name=constant_name,
726717
block_hash=self.determine_block_hash(block),
727-
retry_exceptions=(
728-
SubstrateRequestException,
729-
ConnectionRefusedError,
730-
TimeoutError,
731-
BrokenPipeError,
732-
ConnectionResetError,
733-
),
734718
)
735719

736720
def query_map(
@@ -754,19 +738,11 @@ def query_map(
754738
Returns:
755739
QueryMapResult: A data structure representing the map storage if found, None otherwise.
756740
"""
757-
result = retry_call(
758-
self.substrate.query_map,
741+
result = self.substrate.query_map(
759742
module=module,
760743
storage_function=name,
761744
params=params,
762745
block_hash=self.determine_block_hash(block=block),
763-
retry_exceptions=(
764-
SubstrateRequestException,
765-
ConnectionRefusedError,
766-
TimeoutError,
767-
BrokenPipeError,
768-
ConnectionResetError,
769-
),
770746
)
771747
return result
772748

@@ -789,19 +765,11 @@ def query_map_subtensor(
789765
Returns:
790766
An object containing the map-like data structure, or `None` if not found.
791767
"""
792-
return retry_call(
793-
self.substrate.query_map,
768+
return self.substrate.query_map(
794769
module="SubtensorModule",
795770
storage_function=name,
796771
params=params,
797772
block_hash=self.determine_block_hash(block),
798-
retry_exceptions=(
799-
SubstrateRequestException,
800-
ConnectionRefusedError,
801-
TimeoutError,
802-
BrokenPipeError,
803-
ConnectionResetError,
804-
),
805773
)
806774

807775
def query_module(
@@ -826,22 +794,13 @@ def query_module(
826794
An object containing the requested data if found, `None` otherwise.
827795
828796
"""
829-
return retry_call(
830-
self.substrate.query,
797+
return self.substrate.query(
831798
module=module,
832799
storage_function=name,
833800
params=params,
834801
block_hash=self.determine_block_hash(block),
835-
retry_exceptions=(
836-
SubstrateRequestException,
837-
ConnectionRefusedError,
838-
TimeoutError,
839-
BrokenPipeError,
840-
ConnectionResetError,
841-
),
842802
)
843803

844-
845804
def query_runtime_api(
846805
self,
847806
runtime_api: str,
@@ -864,20 +823,12 @@ def query_runtime_api(
864823
865824
"""
866825
block_hash = self.determine_block_hash(block)
867-
868-
return retry_call(
869-
self.substrate.runtime_call,
826+
827+
return self.substrate.runtime_call(
870828
api=runtime_api,
871829
method=method,
872830
params=params,
873831
block_hash=block_hash,
874-
retry_exceptions=(
875-
SubstrateRequestException,
876-
ConnectionRefusedError,
877-
TimeoutError,
878-
BrokenPipeError,
879-
ConnectionResetError,
880-
),
881832
).value
882833

883834
def query_subtensor(
@@ -899,19 +850,11 @@ def query_subtensor(
899850
Returns:
900851
query_response: An object containing the requested data.
901852
"""
902-
return retry_call(
903-
self.substrate.query,
853+
return self.substrate.query(
904854
module="SubtensorModule",
905855
storage_function=name,
906856
params=params,
907857
block_hash=self.determine_block_hash(block),
908-
retry_exceptions=(
909-
SubstrateRequestException,
910-
ConnectionRefusedError,
911-
TimeoutError,
912-
BrokenPipeError,
913-
ConnectionResetError,
914-
),
915858
)
916859

917860
def state_call(

bittensor/utils/retry.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
logger = logging.getLogger(__name__)
99

10+
# Note: This utility is not used internally by the SDK.
11+
# It is provided as an optional helper for users who wish
12+
# to implement consistent retry behavior themselves.
13+
1014

1115
# Helpers for runtime environment variable access
1216
def _retry_enabled() -> bool:

0 commit comments

Comments
 (0)