diff --git a/dank_mids/eth.py b/dank_mids/eth.py index 1ccef900..63f80e8b 100644 --- a/dank_mids/eth.py +++ b/dank_mids/eth.py @@ -1,3 +1,4 @@ +import asyncio from typing import ( Awaitable, Callable, @@ -187,7 +188,12 @@ async def trace_filter( Raises: ValidationError: If a trace cannot be decoded. """ - traces_bytes = await self._trace_filter(filter_params) + attempts = 0 + traces_bytes = None + # TODO: figure out a better way to handle intermittent errors + while (traces_bytes := await self._trace_filter(filter_params)) is None and attempts < 5: + attempts += 1 + await asyncio.sleep(1) try: return json.decode(traces_bytes, type=decode_to, dec_hook=decode_hook) except ValidationError: @@ -255,7 +261,12 @@ async def get_logs( decode_hook: Hook function to assist in decoding. **kwargs: Additional keyword arguments. """ - logs_bytes = await self._get_logs_raw(*args, **kwargs) # type: ignore [attr-defined] + attempts = 0 + logs_bytes = None + # TODO: figure out a better way to handle intermittent errors + while (logs_bytes := await self._get_logs_raw(*args, **kwargs)) is None and attempts < 5: # type: ignore [attr-defined] + attempts += 1 + await asyncio.sleep(1) return json.decode(logs_bytes, type=decode_to, dec_hook=decode_hook) meth = MethodNoFormat.default(RPC.eth_getTransactionReceipt) # type: ignore [arg-type, var-annotated]