Skip to content

Commit

Permalink
fix: retry intermittent type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
BobTheBuidler authored Dec 14, 2024
1 parent 5d74c11 commit 3ff1f08
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions eth_portfolio/_ledgers/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,22 +465,30 @@ class InternalTransfersList(PandableList[InternalTransfer]):
@a_sync.Semaphore(64, __name__ + ".trace_semaphore")
@eth_retry.auto_retry
async def trace_filter(fromBlock: int, toBlock: int, **kwargs) -> List[FilterTrace]:
try:
return await dank_mids.eth.trace_filter(
{"fromBlock": fromBlock, "toBlock": toBlock, **kwargs}
)
except ClientResponseError as e:
if e.status != HTTPStatus.SERVICE_UNAVAILABLE or toBlock == fromBlock:
raise

range_size = toBlock - fromBlock + 1
chunk_size = range_size // 2
halfway = fromBlock + chunk_size
results = await asyncio.gather(
trace_filter(fromBlock=fromBlock, toBlock=halfway, **kwargs),
trace_filter(fromBlock=halfway + 1, toBlock=toBlock, **kwargs),
)
return results[0] + results[1]
while True:
try:
return await dank_mids.eth.trace_filter(
{"fromBlock": fromBlock, "toBlock": toBlock, **kwargs}
)
except ClientResponseError as e:
if e.status != HTTPStatus.SERVICE_UNAVAILABLE or toBlock == fromBlock:
raise

range_size = toBlock - fromBlock + 1
chunk_size = range_size // 2
halfway = fromBlock + chunk_size
results = await asyncio.gather(
trace_filter(fromBlock=fromBlock, toBlock=halfway, **kwargs),
trace_filter(fromBlock=halfway + 1, toBlock=toBlock, **kwargs),
)
return results[0] + results[1]
except TypeError as e:
# This is some intermittent error I need to debug in dank_mids, I think it occurs when we get rate limited
if str(e) != "a bytes-like object is required, not 'NoneType'":
raise
await asyncio.sleep(0.5)
# remove this logger when I know there are no looping issues
logger.info("call failed, trying again")


@alru_cache(maxsize=None)
Expand Down

0 comments on commit 3ff1f08

Please sign in to comment.