@@ -46,7 +46,7 @@ class EthAdvanced(Eth):
46
46
]
47
47
48
48
PROPERTIES_TO_RETRY = [
49
- 'accounts' , 'hashrate' , 'block_number' , 'chain_id' , ' coinbase' , 'gas_price' ,
49
+ 'accounts' , 'hashrate' , 'block_number' , 'coinbase' , 'gas_price' ,
50
50
'max_priority_fee' , 'mining' , 'syncing'
51
51
]
52
52
@@ -73,6 +73,8 @@ def __init__(self, w3):
73
73
if self .w3 .should_retry :
74
74
self ._wrap_methods_with_retry ()
75
75
76
+ self .chain_id_cached = super ()._chain_id ()
77
+
76
78
self .filter_block_range = self ._find_max_filter_range ()
77
79
78
80
def _wrap_methods_with_retry (self ):
@@ -94,6 +96,8 @@ def get_logs(self, filter_params: FilterParams, show_progress_bar=False, p_bar=N
94
96
if not isinstance (to_block , int ):
95
97
to_block = self .get_block (to_block )["number" ]
96
98
99
+ assert to_block >= from_block , f"{ from_block = } , { to_block = } "
100
+
97
101
# note: fromBlock and toBlock are both inclusive. e.g. 5 to 6 are 2 blocks
98
102
num_blocks = to_block - from_block + 1
99
103
@@ -140,7 +144,7 @@ def get_logs(self, filter_params: FilterParams, show_progress_bar=False, p_bar=N
140
144
return results
141
145
142
146
# filter is trying to get a single block, retrying till it works
143
- assert from_block == to_block and num_blocks == 1
147
+ assert from_block == to_block and num_blocks == 1 , f" { from_block = } , { to_block = } , { num_blocks = } "
144
148
events = exponential_retry (func_name = "get_logs" )(self ._get_logs )(filter_params )
145
149
if p_bar is not None :
146
150
p_bar .update (num_blocks )
@@ -162,3 +166,7 @@ def _find_max_filter_range(self):
162
166
except Exception :
163
167
pass
164
168
raise ValueError ("Unable to use eth_getLogs" )
169
+
170
+ def _chain_id (self ):
171
+ # usually this causes an RPC call and is used in every eth_call. Getting it once in the init and then not again.
172
+ return self .chain_id_cached
0 commit comments