81
81
"supports_rpc_method" ,
82
82
]
83
83
84
+ RETRY_PROPS = ["properties" , "version" , "token_decimals" , "token_symbol" , "name" ]
85
+
84
86
85
87
class RetrySyncSubstrate (SubstrateInterface ):
86
88
def __init__ (
@@ -132,6 +134,8 @@ def __init__(
132
134
)
133
135
for method in RETRY_METHODS :
134
136
setattr (self , method , partial (self ._retry , method ))
137
+ for property_ in RETRY_PROPS :
138
+ setattr (self , property_ , partial (self ._retry_property , property_ ))
135
139
136
140
def _retry (self , method , * args , ** kwargs ):
137
141
try :
@@ -148,6 +152,19 @@ def _retry(self, method, *args, **kwargs):
148
152
)
149
153
raise MaxRetriesExceeded
150
154
155
+ def _retry_property (self , property_ ):
156
+ try :
157
+ return getattr (self , property_ )
158
+ except (MaxRetriesExceeded , ConnectionError , ConnectionRefusedError ) as e :
159
+ try :
160
+ self ._reinstantiate_substrate (e )
161
+ return self ._retry_property (property_ )
162
+ except StopIteration :
163
+ logging .error (
164
+ f"Max retries exceeded with { self .url } . No more fallback chains."
165
+ )
166
+ raise MaxRetriesExceeded
167
+
151
168
def _reinstantiate_substrate (self , e : Optional [Exception ] = None ) -> None :
152
169
next_network = next (self .fallback_chains )
153
170
if e .__class__ == MaxRetriesExceeded :
@@ -207,6 +224,8 @@ def __init__(
207
224
)
208
225
for method in RETRY_METHODS :
209
226
setattr (self , method , partial (self ._retry , method ))
227
+ for property_ in RETRY_PROPS :
228
+ setattr (self , property_ , partial (self ._retry_property , property_ ))
210
229
211
230
def _reinstantiate_substrate (self , e : Optional [Exception ] = None ) -> None :
212
231
next_network = next (self .fallback_chains )
@@ -237,6 +256,7 @@ async def _retry(self, method, *args, **kwargs):
237
256
except (MaxRetriesExceeded , ConnectionError , ConnectionRefusedError ) as e :
238
257
try :
239
258
self ._reinstantiate_substrate (e )
259
+ await self .initialize ()
240
260
method_ = getattr (self , method )
241
261
if asyncio .iscoroutinefunction (method_ ):
242
262
return await method_ (* args , ** kwargs )
@@ -247,3 +267,16 @@ async def _retry(self, method, *args, **kwargs):
247
267
f"Max retries exceeded with { self .url } . No more fallback chains."
248
268
)
249
269
raise MaxRetriesExceeded
270
+
271
+ async def _retry_property (self , property_ ):
272
+ try :
273
+ return await getattr (self , property_ )
274
+ except (MaxRetriesExceeded , ConnectionError , ConnectionRefusedError ) as e :
275
+ try :
276
+ self ._reinstantiate_substrate (e )
277
+ return await self ._retry_property (property_ )
278
+ except StopIteration :
279
+ logging .error (
280
+ f"Max retries exceeded with { self .url } . No more fallback chains."
281
+ )
282
+ raise MaxRetriesExceeded
0 commit comments