Skip to content
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

fix(rpc/eth): remove cache when reorg occured #9775

Merged
merged 3 commits into from
Jul 24, 2024

Conversation

jsvisa
Copy link
Contributor

@jsvisa jsvisa commented Jul 24, 2024

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.

Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
Copy link
Member

@onbjerg onbjerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense to me, pending @mattsse

@onbjerg onbjerg added C-bug An unexpected or incorrect behavior A-rpc Related to the RPC implementation labels Jul 24, 2024
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh very nice find, ty.

this fix is fine because we also reinserting new blocks into the cache again:

self.full_block_cache.insert(block_hash, block);

@mattsse mattsse added this pull request to the merge queue Jul 24, 2024
Merged via the queue into paradigmxyz:main with commit 7531366 Jul 24, 2024
32 checks passed
@jsvisa jsvisa deleted the rpc-remove-cache branch July 25, 2024 01:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rpc Related to the RPC implementation C-bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants