Skip to content

Commit 5cfbb74

Browse files
committed
Adds ws_shutdown_timer arg to AsyncSubtensor and SubtensorAPI
1 parent d5669e3 commit 5cfbb74

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

bittensor/core/async_subtensor.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def __init__(
119119
retry_forever: bool = False,
120120
_mock: bool = False,
121121
archive_endpoints: Optional[list[str]] = None,
122+
websocket_shutdown_timer: float = 5.0,
122123
):
123124
"""
124125
Initializes an instance of the AsyncSubtensor class.
@@ -157,6 +158,7 @@ def __init__(
157158
retry_forever=retry_forever,
158159
_mock=_mock,
159160
archive_endpoints=archive_endpoints,
161+
ws_shutdown_timer=websocket_shutdown_timer
160162
)
161163
if self.log_verbose:
162164
logging.info(
@@ -296,6 +298,7 @@ def _get_substrate(
296298
retry_forever: bool = False,
297299
_mock: bool = False,
298300
archive_endpoints: Optional[list[str]] = None,
301+
ws_shutdown_timer: float = 5.0
299302
) -> Union[AsyncSubstrateInterface, RetryAsyncSubstrate]:
300303
"""Creates the Substrate instance based on provided arguments.
301304
@@ -307,6 +310,8 @@ def _get_substrate(
307310
archive_endpoints: Similar to fallback_endpoints, but specifically only archive nodes. Will be used in cases
308311
where you are requesting a block that is too old for your current (presumably lite) node. Defaults to
309312
`None`
313+
ws_shutdown_timer: Amount of time, in seconds, to wait after the last response from the chain to close the
314+
connection.
310315
311316
Returns:
312317
the instance of the SubstrateInterface or RetrySyncSubstrate class.
@@ -322,6 +327,7 @@ def _get_substrate(
322327
chain_name="Bittensor",
323328
_mock=_mock,
324329
archive_nodes=archive_endpoints,
330+
ws_shutdown_timer=ws_shutdown_timer
325331
)
326332
return AsyncSubstrateInterface(
327333
url=self.chain_endpoint,
@@ -330,6 +336,7 @@ def _get_substrate(
330336
use_remote_preset=True,
331337
chain_name="Bittensor",
332338
_mock=_mock,
339+
ws_shutdown_timer=ws_shutdown_timer
333340
)
334341

335342
# Subtensor queries ===========================================================================================

bittensor/core/subtensor_api/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ class SubtensorApi:
2929
retry_forever: Whether to retry forever on connection errors. Defaults to `False`.
3030
log_verbose: Enables or disables verbose logging.
3131
mock: Whether this is a mock instance. Mainly just for use in testing.
32+
archive_endpoints: Similar to fallback_endpoints, but specifically only archive nodes. Will be used in cases
33+
where you are requesting a block that is too old for your current (presumably lite) node. Defaults to
34+
`None`
35+
websocket_shutdown_timer: Amount of time, in seconds, to wait after the last response from the chain to close
36+
the connection. Only applicable to AsyncSubtensor.
3237
3338
Example:
3439
# sync version
@@ -76,11 +81,13 @@ def __init__(
7681
log_verbose: bool = False,
7782
mock: bool = False,
7883
archive_endpoints: Optional[list[str]] = None,
84+
websocket_shutdown_timer: float = 5.0
7985
):
8086
self.network = network
8187
self._fallback_endpoints = fallback_endpoints
8288
self._archive_endpoints = archive_endpoints
8389
self._retry_forever = retry_forever
90+
self._ws_shutdown_timer = websocket_shutdown_timer
8491
self._mock = mock
8592
self.log_verbose = log_verbose
8693
self.is_async = async_subtensor
@@ -122,6 +129,7 @@ def _get_subtensor(self) -> Union["_Subtensor", "_AsyncSubtensor"]:
122129
retry_forever=self._retry_forever,
123130
_mock=self._mock,
124131
archive_endpoints=self._archive_endpoints,
132+
websocket_shutdown_timer=self._ws_shutdown_timer
125133
)
126134
self.initialize = _subtensor.initialize
127135
return _subtensor

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ dependencies = [
3636
"uvicorn",
3737
"bittensor-drand>=0.5.0",
3838
"bittensor-wallet>=3.0.8",
39-
"async-substrate-interface>=1.3.0"
39+
"async-substrate-interface>=1.3.1"
4040
]
4141

4242
[project.optional-dependencies]

0 commit comments

Comments
 (0)