ape icon indicating copy to clipboard operation
ape copied to clipboard

Fetching all contract events searches through a lot of useless history

Open fubuloubu opened this issue 2 years ago • 0 comments

What went wrong?

The default value for start_block for a query about events starts with block 0, not whatever block was the first block that the contract existed: https://github.com/ApeWorX/ape/blob/595a63a36ae3b59debba92f8b3e62ade5b9f29dc/src/ape/contracts/base.py#L480

This causes ape to cycle through a lot of history that isn't useful to query, because we know that the contract didn't exist at that point in time: https://github.com/ApeWorX/ape/blob/595a63a36ae3b59debba92f8b3e62ade5b9f29dc/src/ape/api/providers.py#L872

Typically, this leads my requests to time out if using a remote provider

How can it be fixed?

If possible, the contract instance object should find a way of determining the block where the contract was (first) deployed, and start it's query from there instead. I say "first" deployed, because a re-initializable proxy can be re-deployed to a given address.

fubuloubu avatar Sep 21 '22 13:09 fubuloubu