53
53
ResultHandler = Callable [[dict , Any ], tuple [dict , bool ]]
54
54
55
55
logger = logging .getLogger ("async_substrate_interface" )
56
+ raw_websocket_logger = logging .getLogger ("raw_websocket" )
56
57
57
58
58
59
class ExtrinsicReceipt :
@@ -485,6 +486,7 @@ def __init__(
485
486
max_retries : int = 5 ,
486
487
retry_timeout : float = 60.0 ,
487
488
_mock : bool = False ,
489
+ _log_raw_websockets : bool = False ,
488
490
):
489
491
"""
490
492
The sync compatible version of the subtensor interface commands we use in bittensor. Use this instance only
@@ -501,6 +503,7 @@ def __init__(
501
503
max_retries: number of times to retry RPC requests before giving up
502
504
retry_timeout: how to long wait since the last ping to retry the RPC request
503
505
_mock: whether to use mock version of the subtensor interface
506
+ _log_raw_websockets: whether to log raw websocket requests during RPC requests
504
507
505
508
"""
506
509
self .max_retries = max_retries
@@ -527,6 +530,7 @@ def __init__(
527
530
self .registry_type_map = {}
528
531
self .type_id_to_name = {}
529
532
self ._mock = _mock
533
+ self .log_raw_websockets = _log_raw_websockets
530
534
if not _mock :
531
535
self .ws = self .connect (init = True )
532
536
self .initialize ()
@@ -1831,12 +1835,18 @@ def _make_rpc_request(
1831
1835
ws = self .connect (init = False if attempt == 1 else True )
1832
1836
for payload in payloads :
1833
1837
item_id = get_next_id ()
1834
- ws .send (json .dumps ({** payload ["payload" ], ** {"id" : item_id }}))
1838
+ to_send = {** payload ["payload" ], ** {"id" : item_id }}
1839
+ if self .log_raw_websockets :
1840
+ raw_websocket_logger .debug (f"WEBSOCKET_SEND> { to_send } " )
1841
+ ws .send (json .dumps (to_send ))
1835
1842
request_manager .add_request (item_id , payload ["id" ])
1836
1843
1837
1844
while True :
1838
1845
try :
1839
- response = json .loads (ws .recv (timeout = self .retry_timeout , decode = False ))
1846
+ recd = ws .recv (timeout = self .retry_timeout , decode = False )
1847
+ if self .log_raw_websockets :
1848
+ raw_websocket_logger .debug (f"WEBSOCKET_RECEIVE> { recd .decode ()} " )
1849
+ response = json .loads (recd )
1840
1850
except (TimeoutError , ConnectionClosed ):
1841
1851
if attempt >= self .max_retries :
1842
1852
logger .warning (
0 commit comments