fix(rpc/eth): remove cache when reorg occured #9775
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's the problem?
eth_getBlockByHash
returns the ReOrged block;How to reproduce
We're running ETL process to fetch blocks and transactions from the RPC server, and then save them into our DB, and after some epoch(eg: 64 blocks), recheck the saved blocks to see if it's forked blocks or canonical ones.
If it's a forked one(by checking the block hash can continue to be queried to determine), we need to remove the saved transactions and re-fetch the block with the same block number.
And this process runs when in geth's RPC, but failed on reth. After some digging, found geth will remove the hash -> number mapping when reorg occurs: https://github.com/ethereum/go-ethereum/blob/df3f0a81a7ef6fd56c90675c32b6d732380a9fd2/core/blockchain.go#L1322-L1327
Reth will also remove the mapping in the underlying DB(by restarting reth, this issue disappeared), but the cache is not fully removed, so I propose this PR.