Skip to content

Commit

Permalink
fix: improved error logging
Browse files Browse the repository at this point in the history
.

.
  • Loading branch information
platonfloria committed May 22, 2024
1 parent 8733c8b commit ccbda71
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
10 changes: 7 additions & 3 deletions fastlane_bot/events/event_gatherer.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,7 +24,7 @@ class EventGatherer:

def __init__(
self,
blockchain: str,
config: Config,
w3: AsyncWeb3,
exchanges: Dict[str, Exchange],
event_contracts: Dict[str, Contract],
Expand All @@ -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()
Expand All @@ -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:
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions run_blockchain_terraformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ccbda71

Please sign in to comment.