Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle websockets version 14, verbose error output #236

Merged
merged 5 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading