From 8733c8bef6390e984e23e33a0de5a6c008c0f559 Mon Sep 17 00:00:00 2001 From: Platon Floria Date: Wed, 22 May 2024 17:13:34 +0800 Subject: [PATCH 1/2] fix: handle timeout exception correctly --- fastlane_bot/events/event_gatherer.py | 1 - run_blockchain_terraformer.py | 1 - 2 files changed, 2 deletions(-) diff --git a/fastlane_bot/events/event_gatherer.py b/fastlane_bot/events/event_gatherer.py index 16061aeb1..6694135f5 100644 --- a/fastlane_bot/events/event_gatherer.py +++ b/fastlane_bot/events/event_gatherer.py @@ -86,7 +86,6 @@ async def _get_logs_recursive(self, from_block: int, to_block: int, topics: List "topics": topics }) except Exception as e: - assert "eth_getLogs" in str(e), str(e) if from_block < to_block: mid_block = (from_block + to_block) // 2 log_lists = await asyncio.gather( diff --git a/run_blockchain_terraformer.py b/run_blockchain_terraformer.py index df514dbee..ee35ceb99 100644 --- a/run_blockchain_terraformer.py +++ b/run_blockchain_terraformer.py @@ -679,7 +679,6 @@ def get_events_recursive(get_logs: any, start_block: int, end_block: int) -> lis try: return get_logs(fromBlock=start_block, toBlock=end_block) except Exception as e: - assert "eth_getLogs" in str(e), str(e) if start_block < end_block: mid_block = (start_block + end_block) // 2 event_list_1 = get_events_recursive(get_logs, start_block, mid_block) From ccbda7178fda89b326d4d4abf1a99a3da040b932 Mon Sep 17 00:00:00 2001 From: Platon Floria Date: Wed, 22 May 2024 19:46:50 +0800 Subject: [PATCH 2/2] fix: improved error logging . . --- fastlane_bot/events/event_gatherer.py | 10 +++++++--- main.py | 2 +- run_blockchain_terraformer.py | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/fastlane_bot/events/event_gatherer.py b/fastlane_bot/events/event_gatherer.py index 6694135f5..fa6b9bb4b 100644 --- a/fastlane_bot/events/event_gatherer.py +++ b/fastlane_bot/events/event_gatherer.py @@ -1,12 +1,14 @@ import asyncio from itertools import chain from typing import Dict, List +from traceback import format_exc import nest_asyncio from web3 import AsyncWeb3 from web3.contract import Contract +from fastlane_bot.config import Config from fastlane_bot.config.constants import BLOCK_CHUNK_SIZE_MAP from .interfaces.subscription import Subscription from .exchanges.base import Exchange @@ -22,7 +24,7 @@ class EventGatherer: def __init__( self, - blockchain: str, + config: Config, w3: AsyncWeb3, exchanges: Dict[str, Exchange], event_contracts: Dict[str, Contract], @@ -32,7 +34,7 @@ def __init__( manager: The Manager object w3: The connected AsyncWeb3 object. """ - self._blockchain = blockchain + self._config = config self._w3 = w3 self._subscriptions = [] unique_topics = set() @@ -59,7 +61,7 @@ async def _get_events_for_subscription(self, from_block: int, to_block: int, sub return [subscription.parse_log(log) for log in await self._get_logs_for_topics(from_block, to_block, [subscription.topic])] async def _get_logs_for_topics(self, from_block: int, to_block: int, topics: List[str]): - chunk_size = BLOCK_CHUNK_SIZE_MAP[self._blockchain] + chunk_size = BLOCK_CHUNK_SIZE_MAP[self._config.network.NETWORK] if chunk_size > 0: return await self._get_logs_iterative(from_block, to_block, topics, chunk_size) else: @@ -86,6 +88,8 @@ async def _get_logs_recursive(self, from_block: int, to_block: int, topics: List "topics": topics }) except Exception as e: + if "eth_getLogs" not in str(e): + self._config.logger.error(f"Unexpected exception in EventGatherer: {format_exc()}") if from_block < to_block: mid_block = (from_block + to_block) // 2 log_lists = await asyncio.gather( diff --git a/main.py b/main.py index 4c3dffe51..dc402b112 100644 --- a/main.py +++ b/main.py @@ -307,7 +307,7 @@ def run(mgr, args, tenderly_uri=None) -> None: handle_static_pools_update(mgr) event_gatherer = EventGatherer( - blockchain=mgr.cfg.network.NETWORK, + config=mgr.cfg, w3=mgr.w3_async, exchanges=mgr.exchanges, event_contracts=mgr.event_contracts diff --git a/run_blockchain_terraformer.py b/run_blockchain_terraformer.py index ee35ceb99..df514dbee 100644 --- a/run_blockchain_terraformer.py +++ b/run_blockchain_terraformer.py @@ -679,6 +679,7 @@ def get_events_recursive(get_logs: any, start_block: int, end_block: int) -> lis try: return get_logs(fromBlock=start_block, toBlock=end_block) except Exception as e: + assert "eth_getLogs" in str(e), str(e) if start_block < end_block: mid_block = (start_block + end_block) // 2 event_list_1 = get_events_recursive(get_logs, start_block, mid_block)