-
-
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
Only fire events that were triggered at future blocks #3094
Conversation
Following up on this PR. Let me know what would be the best way to move forward. I tried running the testing suite locally but looks like I got rate limited. Thanks |
I’m still catching up on issues and preparing a minor bump. Is this problem occurring on an Ethereum network? Or is is another network, like BSC or matic? I worry in general about changes like this, since it shouldn’t be a problem in the first place due to how polling works in v5… |
Yes, Ethereum network, but it's a local network instance running via Hardhat. |
I am wondering if this is a bug in hardhat? So, you are saying you subscribe to an event on a Hardhat in-memory node, and you get old events? When an event is listened to, it uses Thanks! |
No, the initial getLogs request is performed with |
It shouldn’t send a request with a from block of -2, if it is, that is a bug. The -2 is a sentinel value only used for indicating it hasn’t been set yet. Otherwise most event calls would stall, as large ranges throw… |
I ran it through a debugger multiple times, and the value of |
Ok. I’ll look into that. That would be a bug. |
Thanks! Would you like me to create a screen recording where I reproduce the bug? |
Don’t worry about that too much yet. I’ll add some console.log statements to the code so I can see things and add more context. |
Hi. Using an event filter defined using
In both cases, the filter doesn't seem to account for the This is not what is expected - when listening to events starting at Is there any way to achieve this behaviour in the current state of things with Ethers? We would like to avoid a "frontend hack" which would still pull historical events from the chain and potentially add some load to it... Thank you. |
@hickscorp The That is unrelated to this issue. |
I have added I am using: (async function() {
const provider = ethers.getDefaultProvider();
provider.on({ topics: [ ethers.utils.id("Transfer(address,address,uint256)") ] }, (from, to, amount) => {
console.log(from, to, amount);
});
})(); Is there something missing? |
Hm, I just tried and it looks like
It would still show me the last 10 events. |
Eureka! I think I found the problem. The range used by the filter is constantly being refined as blocks and events come in. If you are currently on block 18, that range [8, 18] is fine because that is only possible if there were no matching events in blocks [8, 17], because if there was, for example in block 15, that event would have updated the That is actually the purpose of this overly complex; the So you do not want to restrict to This "gap logic" is performed on the first poll, which it shouldn't as that is expanding the range to a lower values for the |
As a note, I tracked this down and it was introduced in v5.6.0, which added support for networks which has non-consistent event indexing. It appears fixed in the above change and will go out in v5.7.0. Thanks! :) |
That's awesome! Great job @ricmoo |
Is v5.70 going to be released with this? Still on 5.6.9 and looking forward to the fix. |
@dound yes. I’m still working on it. A little more patience please. :) |
Yes, sorry. I thought I’d updated all the issues but missed this one. It was published 2 days ago. :) |
Thanks @ricmoo !! I was a little worried this might have been shifted to v6 release. Thanks for the surprise release today; we've upgraded and I appreciate the patch! |
@dound no worries. It was too important to push to v6. :) Let me know if you continue having any issues. |
Fixes #1096 #2310 #3069 #1504.
I'm not sure if this doesn't break any other workflows, but happy to modify the PR to accommodate other use cases. Also if I'm missing something obvious I'm happy to learn how to use this functionality in a way to avoid having to deal with unnecessary old events. I tried raising this issue in one of the linked GitHub issues, but got no reply, that's why I spent some time learning how events are implemented under the hood and came up with a fix.