mars icon indicating copy to clipboard operation
mars copied to clipboard

[Bug] Stream fetching has not considered re-org situation

Open fenghaojiang opened this issue 3 years ago • 2 comments

Your code looks neat but I found a problem. Fetching block chain latest stream data can not directly insert to the storage file. Because re-org may happen after a while. See What's a re-org in Alchemy: https://www.alchemy.com/overviews/what-is-a-reorg

fenghaojiang avatar Jan 07 '23 01:01 fenghaojiang

Thanks for the report.

In bitcoin, it is safe after 6 blocks are confirmed. Not sure if Ethereum has such a mechanism. Further research is needed.

bohutang avatar Jan 15 '23 02:01 bohutang

You can check the Re-Org (latest blocks may be rolled back after a while) situation using following way: Request for the finalized block number and the latest block number, the blocks between are possible to have Re-Org situation. You can use a queue to check the block hash of finalized block. If it's different from previous block hash with the same block number, then you can say it's a Re-Org block.

reorg_handle

The mock curl: curl --location --request POST 'http://localhost:8545' --header 'Content-Type: application/json' --data-raw '{"jsonrpc": "2.0", "method": "eth_getBlockByNumber", "params": ["finalized", false], "id": 0}'

fenghaojiang avatar Feb 23 '23 07:02 fenghaojiang