eth_getLogs not working for most recent blocks?

I’m using ethers.js to poll for contract events and I noticed I’m missing most (if not all) of them when I’m using Infura as my provider.

I made a test program that checks eth_getLogs for my contract on the current block as it comes in, and then again 2 blocks later and again 10 blocks later.
For the current block, I almost never get events back, for 2 blocks ago sometimes and for 10 blocks ago it’s consistently working.

Is this intended behavior?

The funny thing is that if I switch to the Infura websocket, then everything works instantly. Why is the ‘normal’ JSON-RPC eth_getLogs so far behind?

hey @mathijs any chance you could share that test program you’re using ?

Thanks !

I pushed a proof-of-concept program here: https://github.com/mathijs81/infura-proof-of-concept

when I run it, I get all WEBSOCKET pings for transfers it seems, but very few (if any) REGULAR (which uses the regular json-rpc endpoint).

thanks, I see what you mean, let me look into it, it might be ethers in cause and not us.

hi @mathijs, this seems to be caused by ethers, see https://github.com/ethers-io/ethers.js/issues/1814
We have a PR submitted not implemented yet https://github.com/ethers-io/ethers.js/pull/1830

Performance wise, I think it’s better to use anyway the InfuraWebSocketProvider for this task.

Thanks,
Traian

It’s not just a problem of ethers I think, because I first implemented the ethers logic myself and that (of course) also didn’t work.
(basically the following loop:

  • poll for blocknumber
  • on new block: get logs for block
    → get empty frequently when it should actually not be empty
    )

I don’t understand why infura isn’t just returning an error when a request comes in for logs it hasn’t indexed yet? Then it’s clear that the application needs to retry later. With the current logic (just return empty when it might actually not be empty) it’s impossible for the application to know whether it’s correct.

I noticed that the websocket implementation also sometimes misses events with the default polling. I now changed my code to on every new block update (blocknumber - 2) to give infura more time to index events, but I’m not happy that I will just silently miss events when the indexing maybe occasionally falls behind more than 2 blocks.