Skip to content

Commit

Permalink
Merge branch 'develop' into remove-sei-and-tri-complete
Browse files Browse the repository at this point in the history
  • Loading branch information
zavelevsky authored May 22, 2024
2 parents 23be764 + 7f5ebd7 commit d8697a5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 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,7 +88,8 @@ 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 "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

0 comments on commit d8697a5

Please sign in to comment.