From 0b94a49f6bfc77fd2d49401463785cc7022360c6 Mon Sep 17 00:00:00 2001 From: harisang Date: Sat, 23 Nov 2024 03:19:28 +0200 Subject: [PATCH] fix some pylint issues --- src/sync/batch_data.py | 2 +- src/sync/common.py | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/sync/batch_data.py b/src/sync/batch_data.py index 385c565..9aeeb74 100644 --- a/src/sync/batch_data.py +++ b/src/sync/batch_data.py @@ -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] diff --git a/src/sync/common.py b/src/sync/common.py index 1a17485..ddb49e1 100644 --- a/src/sync/common.py +++ b/src/sync/common.py @@ -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 "" @@ -38,20 +39,18 @@ 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 @@ -59,7 +58,7 @@ def find_block_with_timestamp(node, time_stamp) -> int: 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: