11
11
12
12
RETRY_METHODS = [
13
13
"_get_block_handler" ,
14
- "apply_type_registry_presets" ,
15
14
"close" ,
16
15
"compose_call" ,
17
- "connect" ,
18
16
"create_scale_object" ,
19
17
"create_signed_extrinsic" ,
20
18
"create_storage_key" ,
21
19
"decode_scale" ,
22
20
"encode_scale" ,
23
- "extension_call" ,
24
- "filter_events" ,
25
- "filter_extrinsics" ,
26
21
"generate_signature_payload" ,
27
22
"get_account_next_index" ,
28
23
"get_account_nonce" ,
33
28
"get_block_number" ,
34
29
"get_block_runtime_info" ,
35
30
"get_block_runtime_version_for" ,
36
- "get_block_timestamp" ,
37
31
"get_chain_finalised_head" ,
38
32
"get_chain_head" ,
39
33
"get_constant" ,
56
50
"get_type_registry" ,
57
51
"init_runtime" ,
58
52
"initialize" ,
59
- "is_valid_ss58_address" ,
60
- "load_runtime" ,
61
- "make_payload" ,
62
53
"query" ,
63
54
"query_map" ,
64
55
"query_multi" ,
65
56
"query_multiple" ,
66
- "reload_type_registry" ,
67
- "retrieve_extrinsic_by_hash" ,
68
57
"retrieve_extrinsic_by_identifier" ,
69
58
"rpc_request" ,
70
59
"runtime_call" ,
71
- "search_block_number" ,
72
- "serialize_constant" ,
73
- "serialize_module_call" ,
74
- "serialize_module_error" ,
75
- "serialize_module_event" ,
76
- "serialize_storage_item" ,
77
- "ss58_decode" ,
78
- "ss58_encode" ,
79
60
"submit_extrinsic" ,
80
61
"subscribe_block_headers" ,
81
62
"supports_rpc_method" ,
@@ -132,14 +113,15 @@ def __init__(
132
113
raise ConnectionError (
133
114
f"Unable to connect at any chains specified: { [url ] + fallback_chains } "
134
115
)
116
+ self ._original_methods = {
117
+ method : getattr (self , method ) for method in RETRY_METHODS
118
+ }
135
119
for method in RETRY_METHODS :
136
120
setattr (self , method , partial (self ._retry , method ))
137
- for property_ in RETRY_PROPS :
138
- setattr (self , property_ , partial (self ._retry_property , property_ ))
139
121
140
122
def _retry (self , method , * args , ** kwargs ):
141
123
try :
142
- method_ = getattr ( self , method )
124
+ method_ = self . _original_methods [ method ]
143
125
return method_ (* args , ** kwargs )
144
126
except (MaxRetriesExceeded , ConnectionError , ConnectionRefusedError ) as e :
145
127
try :
@@ -222,10 +204,11 @@ def __init__(
222
204
retry_timeout = retry_timeout ,
223
205
max_retries = max_retries ,
224
206
)
207
+ self ._original_methods = {
208
+ method : getattr (self , method ) for method in RETRY_METHODS
209
+ }
225
210
for method in RETRY_METHODS :
226
211
setattr (self , method , partial (self ._retry , method ))
227
- for property_ in RETRY_PROPS :
228
- setattr (self , property_ , partial (self ._retry_property , property_ ))
229
212
230
213
def _reinstantiate_substrate (self , e : Optional [Exception ] = None ) -> None :
231
214
next_network = next (self .fallback_chains )
@@ -248,11 +231,8 @@ def _reinstantiate_substrate(self, e: Optional[Exception] = None) -> None:
248
231
249
232
async def _retry (self , method , * args , ** kwargs ):
250
233
try :
251
- method_ = getattr (self , method )
252
- if asyncio .iscoroutinefunction (method_ ):
253
- return await method_ (* args , ** kwargs )
254
- else :
255
- return method_ (* args , ** kwargs )
234
+ method_ = self ._original_methods [method ]
235
+ return await method_ (* args , ** kwargs )
256
236
except (MaxRetriesExceeded , ConnectionError , ConnectionRefusedError ) as e :
257
237
try :
258
238
self ._reinstantiate_substrate (e )
0 commit comments