@@ -235,7 +235,10 @@ def get_logs(
235
235
assert next_block <= to_block + 1 , "SubSquid returned logs for more blocks than specified"
236
236
if next_block == to_block + 1 :
237
237
return results
238
- return results + self .get_logs ({** filter_params , "fromBlock" : next_block }, ** kwargs )
238
+ partial_filter = {** filter_params , "fromBlock" : next_block }
239
+ if from_block_parent_hash is not None and next_block != from_block :
240
+ del partial_filter ["fromBlockParentHash" ]
241
+ return results + self .get_logs (partial_filter , ** kwargs )
239
242
240
243
# getting logs for a single block, which is not at the chain head. No drama
241
244
if num_blocks == 1 :
@@ -283,11 +286,11 @@ def get_logs(
283
286
from_block_body , events , to_block_body = batch_results
284
287
assert from_block_body ["number" ] == from_block , "eth_getLogs RPC returned unexpected from block number"
285
288
if from_block_body ["parentHash" ].to_0x_hex () != from_block_parent_hash :
286
- raise ForkedBlock (f"expected={ from_block_parent_hash } , actual={ from_block_body ['parentHash' ].to_0x_hex ()} " )
289
+ raise ForkedBlock (f"expected={ from_block_parent_hash } , actual={ from_block_body ['parentHash' ].to_0x_hex ()} (get_logs fromBlockParentHash) " )
287
290
288
291
assert to_block_body ["number" ] == to_block , "eth_getLogs RPC returned unexpected to block number"
289
292
if to_block_hash is not None and to_block_body ["hash" ].to_0x_hex () != to_block_hash :
290
- raise ForkedBlock (f"expected={ to_block_hash } , actual={ to_block_body ['hash' ].to_0x_hex ()} " )
293
+ raise ForkedBlock (f"expected={ to_block_hash } , actual={ to_block_body ['hash' ].to_0x_hex ()} (get_logs toBlockHash) " )
291
294
292
295
if p_bar is not None :
293
296
p_bar .update (num_blocks )
@@ -300,9 +303,9 @@ def get_logs(
300
303
mid_block = (from_block + to_block ) // 2
301
304
left_filter = {** filter_params , "toBlock" : mid_block }
302
305
right_filter = {** filter_params , "fromBlock" : mid_block + 1 }
303
- if "toBlockHash" in left_filter :
306
+ if to_block_hash is not None :
304
307
del left_filter ["toBlockHash" ]
305
- if "fromBlockParentHash" in right_filter :
308
+ if from_block_parent_hash is not None :
306
309
del right_filter ["fromBlockParentHash" ]
307
310
return self .get_logs (left_filter , ** kwargs ) + self .get_logs (right_filter , ** kwargs )
308
311
0 commit comments