Skip to content

Commit

Permalink
feat: use AsyncLimiter to rate limit calls to block explorer (#874)
Browse files Browse the repository at this point in the history
* feat: use rate limiter for block explorer api calls

* fix: actually use the limiter

* chore: `black .`

* fix: tighten limiter

* fix: retry basescan rate limit error

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
BobTheBuidler and github-actions[bot] authored Jan 22, 2025
1 parent 89e2080 commit 3e973ab
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 113 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cchecksum>=0.0.3
checksum_dict>=1.4.2,<3
dank_mids>=4.20.113
eth-brownie>=1.19.3,<1.21
eth_retry>=0.2
eth_retry>=0.2.1
evmspec>=0.1.0
ez-a-sync>=0.24.45
inflection>=0.1,<0.6
Expand Down
1 change: 1 addition & 0 deletions y/_db/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def retry_locked_wrap(*args: _P.args, **kwargs: _P.kwargs) -> _T:
_result_count_logger = logging.getLogger(f"{__name__}.result_count")
_CHAIN_INFO = "chain", chain.id


def log_result_count(
name: str, arg_names: Iterable[str] = []
) -> Callable[[Callable[_P, _T]], Callable[_P, _T]]:
Expand Down
4 changes: 3 additions & 1 deletion y/_db/utils/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ async def bulk_insert(
(CHAINID, block, "BlockExtended")
for block in {log.blockNumber for log in logs}
)
blocks_fut = submit(_bulk_insert, Block, _BLOCK_COLS_EXTENDED, blocks, sync=True)
blocks_fut = submit(
_bulk_insert, Block, _BLOCK_COLS_EXTENDED, blocks, sync=True
)
else:
blocks = tuple((CHAINID, block) for block in {log.blockNumber for log in logs})
blocks_fut = submit(_bulk_insert, Block, _BLOCK_COLS, blocks, sync=True)
Expand Down
4 changes: 1 addition & 3 deletions y/_db/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,5 @@ def known_blocks_for_timestamps() -> Dict[datetime, int]:
- :class:`BlockAtTimestamp`
"""
return dict(
select(
(x.timestamp, x.block) for x in BlockAtTimestamp if x.chainid == CHAINID
)
select((x.timestamp, x.block) for x in BlockAtTimestamp if x.chainid == CHAINID)
)
Loading

0 comments on commit 3e973ab

Please sign in to comment.