Skip to content

Commit 8fbf49b

Browse files
authored
Merge pull request #2917 from opentensor/feat/thewhaleking/new-websockets-option
New websockets option
2 parents 1ebb466 + 12297af commit 8fbf49b

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class SubtensorApi:
3131
mock: Whether this is a mock instance. Mainly just for use in testing.
3232
archive_endpoints: Similar to fallback_endpoints, but specifically only archive nodes. Will be used in cases
3333
where you are requesting a block that is too old for your current (presumably lite) node. Defaults to `None`
34+
websocket_shutdown_timer: Amount of time, in seconds, to wait after the last response from the chain to close
35+
the connection. Only applicable to AsyncSubtensor.
3436
3537
Example:
3638
# sync version
@@ -78,11 +80,13 @@ def __init__(
7880
log_verbose: bool = False,
7981
mock: bool = False,
8082
archive_endpoints: Optional[list[str]] = None,
83+
websocket_shutdown_timer: float = 5.0,
8184
):
8285
self.network = network
8386
self._fallback_endpoints = fallback_endpoints
8487
self._archive_endpoints = archive_endpoints
8588
self._retry_forever = retry_forever
89+
self._ws_shutdown_timer = websocket_shutdown_timer
8690
self._mock = mock
8791
self.log_verbose = log_verbose
8892
self.is_async = async_subtensor
@@ -124,6 +128,7 @@ def _get_subtensor(self) -> Union["_Subtensor", "_AsyncSubtensor"]:
124128
retry_forever=self._retry_forever,
125129
_mock=self._mock,
126130
archive_endpoints=self._archive_endpoints,
131+
websocket_shutdown_timer=self._ws_shutdown_timer,
127132
)
128133
self.initialize = _subtensor.initialize
129134
return _subtensor

0 commit comments

Comments
 (0)