Problem
When using RPC to fetch events, Envio does not remember the maximum block range specified by the JSON-RPC server in the error messages.
For example, Alchemy enforces a limit of 2000 blocks for eth_getLogs, but Envio continues to attempt to query 2500 blocks at a time:
This is problematic because it can lead to an excessive number of queries made to the JSON-RPC server.
Solution
Parse the JSON-RPC error message and infer what the maximum block range is for that particular JSON-RPC server, and never make a query with the same range again (to that particular server).
For example, this is the error returned by Alchemy:
{"error":{"code":-32000,"message":"block range too large (2500), maximum allowed is 2000 blocks"}}
Related
This issue has been previously discussed here: #603 (comment)
And another related issue is: #688