-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Contract events not being emitted reliably #3486
Comments
Just noting that I have been experiencing similar issues - events being created on chain, but not triggering my event listeners - also with Alchemy, but on the Arbitrum Testnet. My situation also differs in that I am calling Further findings:
My conclusion is that it is something to do with Alchemy more than ethers, but I am not sure how to proceed with testing/verification. |
Since most rollups consider every transaction as a "block" it might be that the default value for Related #3599 |
having the same issue. running off my own Optimism node. |
Can you please update to the latest version? Similar problems were addressed since the version your OP indicated you were on. :) |
I am on 5.7.2. |
my issue might not be ethers-related, I see that I'm stuck on block number |
Is this correct? I wasn't able to find this logic in ethers implementation, but I can confirm this for Hardhat. I created an event listener and made 20 transactions. But I only received 10 events via the listener. |
@Siegrift have you tried using the websocket provider? |
A polling provider searches ranges, not individual blocks (so if during the last poll it ended on block 1000 and the current poll it is block 1016, it will search blocks 1001 through 1016, inclusive). |
(It also maintains a sliding window, with capped end-points, to account for networks with fast block times that do not index events before emitting block numbers) |
Mhh, maybe there is something I am missing... I've created a small repro in https://github.com/Siegrift/ethers-events-skip-demo There is a simple contract which just emits an event. The test file contains three tests, but the first two fail... (The output of the first test - notice that I only received the last 11 logs) The second test only gives me the last event, I guess the provider only looks for the last block for some reason? |
When I had to get rid of this issue I concluded this v5 base provider snippet was my problem: ethers.js/packages/providers/src.ts/base-provider.ts Lines 1082 to 1089 in 0bfa7f4
Range being constructed here:
|
@panukettu What did you change the range to? |
I lowered the But in Optimism to catch 99%, would need to assume bursts around ~15blocks/s. So would set the range to ~60 myself with the default 4s interval. |
Thanks! I will probably add this to the Network config as a plug-in then. It was originally added for Polygon which was the first network to have inconsistent log reads. I will talk to the optimism team too to figure out if there is an upper bound, or if it is a function of polling interval. |
Makes sense for Polygon. Not stepped to v6 yet but given the v5 API, overloading |
Btw. I am using this as well, but I don't like this solution. Shouldn't the expected behaviour though, be to chunk the range and get logs for each chunk? I don't think we should ever skip a block - or am I missing something? |
The window isn't about skipping blocks. It expands the search window. The problem is that that a node might respond to It internally updates the base block when an event is returned for that block, so if no events have been seen for block 1000 yet, but If that makes sense. So, nothing is skipped. It is just used to determine how long to allow a node to return inconsistent results (in this case, inconsistent means returning a block height X for which it hasn't added the events from block X to its db yet). |
@Siegrift One thing I noticed with one of your above examples, is that you are not waiting for the event to start before triggering the events. The |
Right, that's a good point. However, I found this issue during an e2e test - and I started my BE system in advance, so the event listener has time to initialise. I tried adding a 15s wait period after initialising the listener in the example above and still got the same result (only last 11 events).
Yeah, I think that would be very useful. |
@Siegrift That's weird. I will add a test to the integration tests which runs against a Geth dev node deployed during the CI. |
Hi, just checking in again. Did you try reproducing this? In our project we are happy with lowering the polling interval workaround - but I am still bugged how/why this happens. I've edited the https://github.com/Siegrift/ethers-events-skip-demo to also wait until the event is registered, but it has the same problem as I mentioned above. |
Ethers Version
5.6.7
Search Terms
alchemy, event, eventfilter, optimism
Describe the Problem
Hey all,
I'm having a problem with contract events being not reliable as in they are mostly not emitted but sometimes are emitted.
Events from a smart contract (Gnosis Safe contract,
SignMsg
but true for other events as well) events usually are not being emitted through**ethers**
on**optimism**
even though I can see they are actually emitted from the contract on etherscan. I'm using Alchemy as the RPC provider and it seems there are no outages or rate limiting on there as well.In the below code, you can see how i wait for the events.
This only happens on Optimism. Goerli works perfectly fine.
I'm curious why this piece of code fails to receive the events sometimes. Any clue or suggestion is appreciated 🙏🙏🙏
Thanks in advance.
Code Snippet
Errors
No response
Environment
Browser (Chrome, Safari, etc)
Environment (Other)
optimism, alchemy
The text was updated successfully, but these errors were encountered: