Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: tweak trace semaphore handling #165

Merged
merged 6 commits into from
Dec 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions eth_portfolio/_ledgers/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from abc import ABCMeta, abstractmethod
from asyncio import Lock, Queue, create_task, gather, sleep
from collections import defaultdict
from functools import partial
from http import HTTPStatus
from itertools import product
Expand Down Expand Up @@ -536,7 +537,7 @@ class InternalTransfersList(PandableList[InternalTransfer]):
"""


@a_sync.Semaphore(64, __name__ + ".trace_semaphore")
@a_sync.Semaphore(128, __name__ + ".trace_filter")
@stuck_coro_debugger
@eth_retry.auto_retry
async def trace_filter(fromBlock: int, toBlock: int, **kwargs) -> List[FilterTrace]:
Expand Down Expand Up @@ -589,6 +590,8 @@ async def get_transaction_status(txhash: str) -> Status:
return await dank_mids.eth.get_transaction_status(txhash)


_trace_semaphores = defaultdict(lambda: a_sync.Semaphore(16, __name__ + ".trace_semaphore"))

@cache_to_disk
@eth_retry.auto_retry
async def get_traces(filter_params: TraceFilterParams) -> List[FilterTrace]:
Expand All @@ -606,7 +609,8 @@ async def get_traces(filter_params: TraceFilterParams) -> List[FilterTrace]:
if chain.id == Network.Polygon:
logger.warning("polygon doesnt support trace_filter method, must develop alternate solution")
return []
return await _check_traces(await trace_filter(**filter_params))
async with _trace_semaphores[sorted(filter_params.get(x) for x in ("toAddress", "fromAddress))]:
return await _check_traces(await trace_filter(**filter_params))


@stuck_coro_debugger
Expand Down
Loading