From 4ba23c9c01cf4677541a0bd878a6d5a221012d18 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Fri, 20 Dec 2024 12:53:03 -0400 Subject: [PATCH 1/5] feat: tweak trace semaphore handling --- eth_portfolio/_ledgers/address.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/eth_portfolio/_ledgers/address.py b/eth_portfolio/_ledgers/address.py index c3d78727..93c1a994 100644 --- a/eth_portfolio/_ledgers/address.py +++ b/eth_portfolio/_ledgers/address.py @@ -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 @@ -535,7 +536,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]: @@ -588,9 +589,11 @@ async def get_transaction_status(txhash: str) -> Status: return await dank_mids.eth.get_transaction_status(txhash) +_trace_semaphores = defaultdict(lambda: a_sync.Semaphore(32)) + @cache_to_disk @eth_retry.auto_retry -async def get_traces(filter_params: TraceFilterParams) -> List[FilterTrace]: +async def get_traces(address: ChecksumAddress, filter_params: TraceFilterParams) -> List[FilterTrace]: """ Retrieves traces from the web3 provider using the given parameters. @@ -602,7 +605,9 @@ async def get_traces(filter_params: TraceFilterParams) -> List[FilterTrace]: Returns: The list of traces. """ - return await _check_traces(await trace_filter(**filter_params)) + address = filter_params.get("toAddress) or filter_params.get("fromAddress") + async with _trace_semaphores[address]: + return await _check_traces(await trace_filter(**filter_params)) @stuck_coro_debugger From 5af8cdff24736ce6d505c2f5de66bc1baecdb5f4 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Fri, 20 Dec 2024 12:54:35 -0400 Subject: [PATCH 2/5] Update address.py --- eth_portfolio/_ledgers/address.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eth_portfolio/_ledgers/address.py b/eth_portfolio/_ledgers/address.py index 93c1a994..a7bc1228 100644 --- a/eth_portfolio/_ledgers/address.py +++ b/eth_portfolio/_ledgers/address.py @@ -593,7 +593,7 @@ async def get_transaction_status(txhash: str) -> Status: @cache_to_disk @eth_retry.auto_retry -async def get_traces(address: ChecksumAddress, filter_params: TraceFilterParams) -> List[FilterTrace]: +async def get_traces(filter_params: TraceFilterParams) -> List[FilterTrace]: """ Retrieves traces from the web3 provider using the given parameters. From c9528bdb980d02a7a0c5d57836d3c0c74223ee77 Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Fri, 20 Dec 2024 12:55:13 -0400 Subject: [PATCH 3/5] Update address.py --- eth_portfolio/_ledgers/address.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eth_portfolio/_ledgers/address.py b/eth_portfolio/_ledgers/address.py index a7bc1228..db76c31b 100644 --- a/eth_portfolio/_ledgers/address.py +++ b/eth_portfolio/_ledgers/address.py @@ -589,7 +589,7 @@ async def get_transaction_status(txhash: str) -> Status: return await dank_mids.eth.get_transaction_status(txhash) -_trace_semaphores = defaultdict(lambda: a_sync.Semaphore(32)) +_trace_semaphores = defaultdict(lambda: a_sync.Semaphore(32, __name__ + ".trace_semaphore")) @cache_to_disk @eth_retry.auto_retry From 78aea95a5a33b7f1380faba87ac9fc144f6df3fc Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Fri, 20 Dec 2024 13:50:20 -0400 Subject: [PATCH 4/5] Update address.py --- eth_portfolio/_ledgers/address.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/eth_portfolio/_ledgers/address.py b/eth_portfolio/_ledgers/address.py index db76c31b..62e9fbaf 100644 --- a/eth_portfolio/_ledgers/address.py +++ b/eth_portfolio/_ledgers/address.py @@ -589,7 +589,7 @@ async def get_transaction_status(txhash: str) -> Status: return await dank_mids.eth.get_transaction_status(txhash) -_trace_semaphores = defaultdict(lambda: a_sync.Semaphore(32, __name__ + ".trace_semaphore")) +_trace_semaphores = defaultdict(lambda: a_sync.Semaphore(16, __name__ + ".trace_semaphore")) @cache_to_disk @eth_retry.auto_retry @@ -605,8 +605,7 @@ async def get_traces(filter_params: TraceFilterParams) -> List[FilterTrace]: Returns: The list of traces. """ - address = filter_params.get("toAddress) or filter_params.get("fromAddress") - async with _trace_semaphores[address]: + async with _trace_semaphores[sorted((filter_params.get("toAddress), filter_params.get("fromAddress))]: return await _check_traces(await trace_filter(**filter_params)) From cbc2410b10b53b1a04dba00ef29128488100fe0e Mon Sep 17 00:00:00 2001 From: BobTheBuidler <70677534+BobTheBuidler@users.noreply.github.com> Date: Fri, 20 Dec 2024 13:51:23 -0400 Subject: [PATCH 5/5] Update address.py --- eth_portfolio/_ledgers/address.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eth_portfolio/_ledgers/address.py b/eth_portfolio/_ledgers/address.py index 62e9fbaf..d02bc616 100644 --- a/eth_portfolio/_ledgers/address.py +++ b/eth_portfolio/_ledgers/address.py @@ -605,7 +605,7 @@ async def get_traces(filter_params: TraceFilterParams) -> List[FilterTrace]: Returns: The list of traces. """ - async with _trace_semaphores[sorted((filter_params.get("toAddress), filter_params.get("fromAddress))]: + async with _trace_semaphores[sorted(filter_params.get(x) for x in ("toAddress", "fromAddress))]: return await _check_traces(await trace_filter(**filter_params))