Skip to content

Commit

Permalink
Merge pull request #2404 from opentensor/fix/thewhaleking/handle-webs…
Browse files Browse the repository at this point in the history
…ockets-v14

Handles websockets v14+ in async
  • Loading branch information
thewhaleking authored Nov 12, 2024
2 parents 8e9aab6 + b5eadb3 commit df7d663
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
18 changes: 9 additions & 9 deletions bittensor/utils/async_substrate_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from hashlib import blake2b
from typing import Optional, Any, Union, Callable, Awaitable, cast

import websockets
from async_property import async_property
from bittensor_wallet import Keypair
from bt_decode import PortableRegistry, decode as decode_by_type_string, MetadataV15
from packaging import version
from scalecodec import GenericExtrinsic
from scalecodec.base import ScaleBytes, ScaleType, RuntimeConfigurationObject
from scalecodec.type_registry import load_type_registry_preset
Expand All @@ -20,6 +20,7 @@
BlockNotFound,
)
from substrateinterface.storage import StorageKey
import websockets

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

Expand Down Expand Up @@ -768,14 +769,13 @@ def __init__(
"""
self.chain_endpoint = chain_endpoint
self.__chain = chain_name
self.ws = Websocket(
chain_endpoint,
options={
"max_size": 2**32,
"read_limit": 2**16,
"write_limit": 2**16,
},
)
options = {
"max_size": 2**32,
"write_limit": 2**16,
}
if version.parse(websockets.__version__) < version.parse("14.0"):
options.update({"read_limit": 2**16})
self.ws = Websocket(chain_endpoint, options=options)
self._lock = asyncio.Lock()
self.last_block_hash: Optional[str] = None
self.config = {
Expand Down
1 change: 1 addition & 0 deletions requirements/prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ python-Levenshtein
scalecodec==1.2.11
substrate-interface~=1.7.9
uvicorn
websockets>12.0
bittensor-wallet>=2.0.2

0 comments on commit df7d663

Please sign in to comment.