Skip to content

Commit

Permalink
feat: tweak trace semaphore handling (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Dec 21, 2024
1 parent 007adf3 commit f88c445
Showing 1 changed file with 6 additions and 2 deletions.
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

0 comments on commit f88c445

Please sign in to comment.