Log syncing with proper re-org handling

I am using Infura WSS to listen event logs emitted by the contract and then based on the event Log I am storing them into the database.

Now handling any re-org when the client is still running WSS is easy, as infura emits removed as True during a re-org.

The problem, where I see is, what will happen, if my client subscribed to Infura WSS gets some event logs and then for some reason, my client goes offline for 15 minutes. And during that moment the logs were removed due to re-org.

One way to handle this is to store the block number and block hash with the logs and to check if they are the part of the mainchain when I restart the client again after 15 minutes. If for the given block number, the block hash doesn’t match, in that case, I will consider that the log has been re-orged, and I will revert the operations.
Otherwise, if the blockhash matches then I will simply subscribe for the logs mentioning fromBlock equals to latest blocknumber in DB + 1.

However, I feel what if after I matched the block hash matches and just before I start the subscription, the re-org happens.
This is where I would like to know if there any best way to solve this issue using INFURA api.

Hi @cyyber, and welcome to the Infura community!

Your suggestion sounds like the best way to check for that at this point; we don’t necessarily have something that will let you know if a reorg has happened while your client is offline.