Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
fix some pylint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
harisang committed Nov 23, 2024
1 parent 22a8c27 commit 0b94a49
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/sync/batch_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async def sync_batch_data(
network_name = node_suffix(network).lower()

block_range_list, months_list = compute_block_and_month_range(node)
for i in range(len(block_range_list)):
for i, _ in enumerate(block_range_list):
start_block = block_range_list[i][0]
end_block = block_range_list[i][1]
table_name = config.table + "_" + network_name + "_" + months_list[i]
Expand Down
21 changes: 10 additions & 11 deletions src/sync/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ def last_sync_block(aws: AWSClient, table: SyncTable, genesis_block: int = 0) ->


def node_suffix(network: str) -> str:
"""
Converts network internal name to name used for nodes and dune tables
"""
if network == "mainnet":
return "MAINNET"
else:
if network == "xdai":
return "GNOSIS"
else:
if network == "arbitrum-one":
return "ARBITRUM"
if network == "xdai":
return "GNOSIS"
if network == "arbitrum-one":
return "ARBITRUM"
return ""


Expand All @@ -38,28 +39,26 @@ def find_block_with_timestamp(node, time_stamp) -> int:
This implements binary search and returns the smallest block number
whose timestamp is at least as large as the time_stamp argument passed in the function
"""
block_found = False
end_block_number = node.eth.get_block("finalized").number
start_block_number = 1
close_in_seconds = 30

while not block_found:
while True:
mid_block_number = (start_block_number + end_block_number) // 2
block = node.eth.get_block(mid_block_number)
block_time = block.timestamp
difference_in_seconds = int((time_stamp - block_time))

if abs(difference_in_seconds) < close_in_seconds:
block_found = True
continue
break

if difference_in_seconds < 0:
end_block_number = mid_block_number - 1
else:
start_block_number = mid_block_number + 1

## we now brute-force to ensure we have found the right block
for b in range(mid_block_number - 100, mid_block_number + 100):
for b in range(mid_block_number - 200, mid_block_number + 200):
block = node.eth.get_block(b)
block_time_stamp = block.timestamp
if block_time_stamp >= time_stamp:
Expand Down

0 comments on commit 0b94a49

Please sign in to comment.