Skip to content

Commit

Permalink
Handle websockets version 14, verbose error output (#236)
Browse files Browse the repository at this point in the history
* Add the ability to verbosely show error tracebacks.

* Handle websockets>=14.0 rather than requiring it to be less than it.
  • Loading branch information
thewhaleking authored Nov 12, 2024
1 parent 253d686 commit e06a0cc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
6 changes: 6 additions & 0 deletions bittensor_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import re
import ssl
import sys
import traceback
from pathlib import Path
from typing import Coroutine, Optional
from dataclasses import fields
Expand Down Expand Up @@ -840,13 +841,18 @@ async def _run():
return result
except (ConnectionRefusedError, ssl.SSLError):
err_console.print(f"Unable to connect to the chain: {self.subtensor}")
verbose_console.print(traceback.format_exc())
except (
ConnectionClosed,
SubstrateRequestException,
KeyboardInterrupt,
) as e:
if isinstance(e, SubstrateRequestException):
err_console.print(str(e))
verbose_console.print(traceback.format_exc())
except Exception as e:
err_console.print(f"An unknown error has occurred: {e}")
verbose_console.print(traceback.format_exc())
finally:
if initiated is False:
asyncio.create_task(cmd).cancel()
Expand Down
20 changes: 10 additions & 10 deletions bittensor_cli/src/bittensor/async_substrate_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
from hashlib import blake2b
from typing import Optional, Any, Union, Callable, Awaitable, cast

from bt_decode import PortableRegistry, decode as decode_by_type_string, MetadataV15
from async_property import async_property
from bt_decode import PortableRegistry, decode as decode_by_type_string, MetadataV15
from bittensor_wallet import Keypair
from packaging import version
from scalecodec import GenericExtrinsic
from scalecodec.base import ScaleBytes, ScaleType, RuntimeConfigurationObject
from scalecodec.type_registry import load_type_registry_preset
from scalecodec.types import GenericCall
from bittensor_wallet import Keypair
from substrateinterface.exceptions import (
SubstrateRequestException,
ExtrinsicNotFound,
Expand Down Expand Up @@ -771,14 +772,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.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ fuzzywuzzy~=0.18.0
netaddr~=1.3.0
numpy>=2.0.1
Jinja2
packaging
pycryptodome # Crypto
PyYAML~=6.0.1
pytest
Expand Down

0 comments on commit e06a0cc

Please sign in to comment.