75
75
ResultHandler = Callable [[dict , Any ], Awaitable [tuple [dict , bool ]]]
76
76
77
77
logger = logging .getLogger ("async_substrate_interface" )
78
+ raw_websocket_logger = logging .getLogger ("raw_websocket" )
78
79
79
80
80
81
class AsyncExtrinsicReceipt :
@@ -505,6 +506,7 @@ def __init__(
505
506
max_connections = 100 ,
506
507
shutdown_timer = 5 ,
507
508
options : Optional [dict ] = None ,
509
+ _log_raw_websockets : bool = False ,
508
510
):
509
511
"""
510
512
Websocket manager object. Allows for the use of a single websocket connection by multiple
@@ -532,6 +534,8 @@ def __init__(
532
534
self ._exit_task = None
533
535
self ._open_subscriptions = 0
534
536
self ._options = options if options else {}
537
+ self ._log_raw_websockets = _log_raw_websockets
538
+
535
539
try :
536
540
now = asyncio .get_running_loop ().time ()
537
541
except RuntimeError :
@@ -615,7 +619,10 @@ async def shutdown(self):
615
619
async def _recv (self ) -> None :
616
620
try :
617
621
# TODO consider wrapping this in asyncio.wait_for and use that for the timeout logic
618
- response = json .loads (await self .ws .recv (decode = False ))
622
+ recd = await self .ws .recv (decode = False )
623
+ if self ._log_raw_websockets :
624
+ raw_websocket_logger .debug (f"WEBSOCKET_RECEIVE> { recd .decode ()} " )
625
+ response = json .loads ()
619
626
self .last_received = await self .loop_time ()
620
627
async with self ._lock :
621
628
# note that these 'subscriptions' are all waiting sent messages which have not received
@@ -660,7 +667,10 @@ async def send(self, payload: dict) -> int:
660
667
# self._open_subscriptions += 1
661
668
await self .max_subscriptions .acquire ()
662
669
try :
663
- await self .ws .send (json .dumps ({** payload , ** {"id" : original_id }}))
670
+ to_send = {** payload , ** {"id" : original_id }}
671
+ if self ._log_raw_websockets :
672
+ raw_websocket_logger .debug (f"WEBSOCKET_SEND> { to_send } " )
673
+ await self .ws .send (json .dumps (to_send ))
664
674
self .last_sent = await self .loop_time ()
665
675
return original_id
666
676
except (ConnectionClosed , ssl .SSLError , EOFError ):
@@ -699,6 +709,7 @@ def __init__(
699
709
max_retries : int = 5 ,
700
710
retry_timeout : float = 60.0 ,
701
711
_mock : bool = False ,
712
+ _log_raw_websockets : bool = False ,
702
713
):
703
714
"""
704
715
The asyncio-compatible version of the subtensor interface commands we use in bittensor. It is important to
@@ -716,16 +727,19 @@ def __init__(
716
727
max_retries: number of times to retry RPC requests before giving up
717
728
retry_timeout: how to long wait since the last ping to retry the RPC request
718
729
_mock: whether to use mock version of the subtensor interface
730
+ _log_raw_websockets: whether to log raw websocket requests during RPC requests
719
731
720
732
"""
721
733
self .max_retries = max_retries
722
734
self .retry_timeout = retry_timeout
723
735
self .chain_endpoint = url
724
736
self .url = url
725
737
self ._chain = chain_name
738
+ self ._log_raw_websockets = _log_raw_websockets
726
739
if not _mock :
727
740
self .ws = Websocket (
728
741
url ,
742
+ _log_raw_websockets = _log_raw_websockets ,
729
743
options = {
730
744
"max_size" : self .ws_max_size ,
731
745
"write_limit" : 2 ** 16 ,
0 commit comments