ApeWorX / ape-alchemy

Alchemy network provider plugin for the Ape Framework
https://www.apeworx.io/
21 stars 13 forks source link

bug: rate limiting not being handled #60

Open mikeshultz opened 11 months ago

mikeshultz commented 11 months ago

Environment information

$ ape --version
0.6.21

$ ape plugins list
Installed Plugins
  alchemy    0.6.5
  foundry    0.6.17
  vyper      0.6.11

What went wrong?

Trying to use this with a free tier Alchemy key and can't make it usable.

[...snip...]
  File "/path/to/venv/lib/python3.11/site-packages/ape/contracts/base.py", line 641, in range
    yield from self.query_manager.query(contract_event_query)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/venv/lib/python3.11/site-packages/ape/api/providers.py", line 1392, in get_contract_logs
    for page in pool.map(fetch_log_page, block_ranges):
  File "/usr/lib/python3.11/concurrent/futures/_base.py", line 619, in result_iterator
    yield _result_or_cancel(fs.pop())
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/concurrent/futures/_base.py", line 317, in _result_or_cancel
    return fut.result(timeout)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/concurrent/futures/_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/usr/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/venv/lib/python3.11/site-packages/ape/api/providers.py", line 1388, in fetch_log_page
    logs = self._get_logs(page_filter.dict(), raw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/venv/lib/python3.11/site-packages/ape/api/providers.py", line 1399, in _get_logs
    return self._make_request("eth_getLogs", [filter_params])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/venv/lib/python3.11/site-packages/ape_alchemy/provider.py", line 200, in _make_request
    raise cls(message) from err
ape_alchemy.exceptions.AlchemyProviderError: Your app has exceeded its compute units per second capacity. If you have retries enabled, you can safely ignore this message. If not, check out https://docs.alchemy.com/reference/throughput

How can it be fixed?

I think it's critical to have HTTP retries (probably with a backoff) in this lib. This isn't a recoverable error or anything I can do about other than upgrading my Alchemy subscription.

Should be noted that Alchemy's own SDK implements retries and they recommend doing so if you implement your own provider.

I saw #35 which may be a path forward but it looks a bit stalled.