diff --git a/eth_portfolio/_cache.py b/eth_portfolio/_cache.py index 46c4c53a..1dc68ef3 100644 --- a/eth_portfolio/_cache.py +++ b/eth_portfolio/_cache.py @@ -15,6 +15,7 @@ BASE_PATH = f"./cache/{chain.id}/" EXECUTOR = a_sync.PruningThreadPoolExecutor(32) + def cache_to_disk(fn: AnyFn[P, T]) -> AnyFn[P, T]: module = fn.__module__.replace(".", "/") cache_path_for_fn = BASE_PATH + module + "/" + fn.__name__ @@ -35,7 +36,7 @@ async def disk_cache_wrap(*args: P.args, **kwargs: P.kwargs) -> T: async with aiofiles.open(cache_path, "rb", executor=EXECUTOR) as f: with contextlib.suppress(EOFError): return pickle.loads(await f.read()) - + async_result: T = await fn(*args, **kwargs) await __cache_write(cache_path, async_result) return async_result diff --git a/eth_portfolio/_ledgers/address.py b/eth_portfolio/_ledgers/address.py index 5a5874ba..22400c33 100644 --- a/eth_portfolio/_ledgers/address.py +++ b/eth_portfolio/_ledgers/address.py @@ -473,10 +473,12 @@ async def trace_filter(fromBlock: int, toBlock: int, **kwargs) -> List[FilterTra except ClientResponseError as e: if e.status != HTTPStatus.SERVICE_UNAVAILABLE or toBlock == fromBlock: raise - - range_size = toBlock - fromBlock + 1 + + from_block = int(fromBlock, 16) + range_size = int(toBlock, 16) - from_block + 1 chunk_size = range_size // 2 - halfway = fromBlock + chunk_size + halfway = from_block + chunk_size + results = await asyncio.gather( trace_filter(fromBlock=fromBlock, toBlock=halfway, **kwargs), trace_filter(fromBlock=halfway + 1, toBlock=toBlock, **kwargs), diff --git a/eth_portfolio/_loaders/token_transfer.py b/eth_portfolio/_loaders/token_transfer.py index 85f1d642..86af07c7 100644 --- a/eth_portfolio/_loaders/token_transfer.py +++ b/eth_portfolio/_loaders/token_transfer.py @@ -152,7 +152,7 @@ async def get_symbol(token: ERC20) -> Optional[str]: return None -@alru_cache(ttl=60*60) +@alru_cache(ttl=60 * 60) @stuck_coro_debugger @cache_to_disk async def _get_transaction_index(hash: str) -> int: