Skip to content

Commit dc9532d

Browse files
committed
v0.2.7 fixed to_block_hash and from_block_parent_hash parameters in get_logs when splitting the filter
1 parent 0c9cb44 commit dc9532d

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

IceCreamSwapWeb3/EthAdvanced.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,10 @@ def get_logs(
235235
assert next_block <= to_block + 1, "SubSquid returned logs for more blocks than specified"
236236
if next_block == to_block + 1:
237237
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)
239242

240243
# getting logs for a single block, which is not at the chain head. No drama
241244
if num_blocks == 1:
@@ -283,11 +286,11 @@ def get_logs(
283286
from_block_body, events, to_block_body = batch_results
284287
assert from_block_body["number"] == from_block, "eth_getLogs RPC returned unexpected from block number"
285288
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)")
287290

288291
assert to_block_body["number"] == to_block, "eth_getLogs RPC returned unexpected to block number"
289292
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)")
291294

292295
if p_bar is not None:
293296
p_bar.update(num_blocks)
@@ -300,9 +303,9 @@ def get_logs(
300303
mid_block = (from_block + to_block) // 2
301304
left_filter = {**filter_params, "toBlock": mid_block}
302305
right_filter = {**filter_params, "fromBlock": mid_block + 1}
303-
if "toBlockHash" in left_filter:
306+
if to_block_hash is not None:
304307
del left_filter["toBlockHash"]
305-
if "fromBlockParentHash" in right_filter:
308+
if from_block_parent_hash is not None:
306309
del right_filter["fromBlockParentHash"]
307310
return self.get_logs(left_filter, **kwargs) + self.get_logs(right_filter, **kwargs)
308311

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup, find_packages
22

3-
VERSION = '0.2.6'
3+
VERSION = '0.2.7'
44
DESCRIPTION = 'IceCreamSwap Web3.py wrapper'
55
LONG_DESCRIPTION = 'IceCreamSwap Web3.py wrapper with automatic retries, multicall and other advanced functionality'
66

0 commit comments

Comments
 (0)