I have a Dapp which subscribes to events using web3. I'm wondering how I can detect that the longest chain has changed or rather how I can make sure the events that I've received are canonical. The could should also work correctly for hardforks and with both
getPastEvents() and subscribing to new events.
During my research, I've found this question: Is it possible to get duplicates of the log events on Ethereum when we have a fork of the chain?. The answer suggests a
status field. There is a
status in the receipt but that's only a boolean. Also, there is no
status in the results of
getPastEvents() - what happens when the fork happens while
getPastEvents() receives events?
I'm not sure how web3 makes sure that events are canonical in the current implementation. In tests with Geth, the event became visible in the Dapp after about 10 seconds which suggests that it just takes the latest block into account and doesn't wait for the usual 6 or 12 blocks for the chain to become canonical.