Skip to content

Commit df7d663

Browse files
authored
Merge pull request #2404 from opentensor/fix/thewhaleking/handle-websockets-v14
Handles websockets v14+ in async
2 parents 8e9aab6 + b5eadb3 commit df7d663

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

bittensor/utils/async_substrate_interface.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
from hashlib import blake2b
77
from typing import Optional, Any, Union, Callable, Awaitable, cast
88

9-
import websockets
109
from async_property import async_property
1110
from bittensor_wallet import Keypair
1211
from bt_decode import PortableRegistry, decode as decode_by_type_string, MetadataV15
12+
from packaging import version
1313
from scalecodec import GenericExtrinsic
1414
from scalecodec.base import ScaleBytes, ScaleType, RuntimeConfigurationObject
1515
from scalecodec.type_registry import load_type_registry_preset
@@ -20,6 +20,7 @@
2020
BlockNotFound,
2121
)
2222
from substrateinterface.storage import StorageKey
23+
import websockets
2324

2425
ResultHandler = Callable[[dict, Any], Awaitable[tuple[dict, bool]]]
2526

@@ -768,14 +769,13 @@ def __init__(
768769
"""
769770
self.chain_endpoint = chain_endpoint
770771
self.__chain = chain_name
771-
self.ws = Websocket(
772-
chain_endpoint,
773-
options={
774-
"max_size": 2**32,
775-
"read_limit": 2**16,
776-
"write_limit": 2**16,
777-
},
778-
)
772+
options = {
773+
"max_size": 2**32,
774+
"write_limit": 2**16,
775+
}
776+
if version.parse(websockets.__version__) < version.parse("14.0"):
777+
options.update({"read_limit": 2**16})
778+
self.ws = Websocket(chain_endpoint, options=options)
779779
self._lock = asyncio.Lock()
780780
self.last_block_hash: Optional[str] = None
781781
self.config = {

requirements/prod.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ python-Levenshtein
2424
scalecodec==1.2.11
2525
substrate-interface~=1.7.9
2626
uvicorn
27+
websockets>12.0
2728
bittensor-wallet>=2.0.2

0 commit comments

Comments
 (0)