Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions async_substrate_interface/substrate_addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def __init__(
max_retries: int = 5,
retry_timeout: float = 60.0,
_mock: bool = False,
_log_raw_websockets: bool = False,
archive_nodes: Optional[list[str]] = None,
):
fallback_chains = fallback_chains or []
Expand Down Expand Up @@ -150,6 +151,7 @@ def __init__(
_mock=_mock,
retry_timeout=retry_timeout,
max_retries=max_retries,
_log_raw_websockets=_log_raw_websockets,
)
initialized = True
logger.info(f"Connected to {chain_url}")
Expand Down
14 changes: 12 additions & 2 deletions async_substrate_interface/sync_substrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
ResultHandler = Callable[[dict, Any], tuple[dict, bool]]

logger = logging.getLogger("async_substrate_interface")
raw_websocket_logger = logging.getLogger("raw_websocket")


class ExtrinsicReceipt:
Expand Down Expand Up @@ -485,6 +486,7 @@ def __init__(
max_retries: int = 5,
retry_timeout: float = 60.0,
_mock: bool = False,
_log_raw_websockets: bool = False,
):
"""
The sync compatible version of the subtensor interface commands we use in bittensor. Use this instance only
Expand All @@ -501,6 +503,7 @@ def __init__(
max_retries: number of times to retry RPC requests before giving up
retry_timeout: how to long wait since the last ping to retry the RPC request
_mock: whether to use mock version of the subtensor interface
_log_raw_websockets: whether to log raw websocket requests during RPC requests

"""
self.max_retries = max_retries
Expand All @@ -527,6 +530,7 @@ def __init__(
self.registry_type_map = {}
self.type_id_to_name = {}
self._mock = _mock
self.log_raw_websockets = _log_raw_websockets
if not _mock:
self.ws = self.connect(init=True)
self.initialize()
Expand Down Expand Up @@ -1831,12 +1835,18 @@ def _make_rpc_request(
ws = self.connect(init=False if attempt == 1 else True)
for payload in payloads:
item_id = get_next_id()
ws.send(json.dumps({**payload["payload"], **{"id": item_id}}))
to_send = {**payload["payload"], **{"id": item_id}}
if self.log_raw_websockets:
raw_websocket_logger.debug(f"WEBSOCKET_SEND> {to_send}")
ws.send(json.dumps(to_send))
request_manager.add_request(item_id, payload["id"])

while True:
try:
response = json.loads(ws.recv(timeout=self.retry_timeout, decode=False))
recd = ws.recv(timeout=self.retry_timeout, decode=False)
if self.log_raw_websockets:
raw_websocket_logger.debug(f"WEBSOCKET_RECEIVE> {recd.decode()}")
response = json.loads(recd)
except (TimeoutError, ConnectionClosed):
if attempt >= self.max_retries:
logger.warning(
Expand Down
Loading