paradigmxyz / reth

Modular, contributor-friendly and blazing-fast implementation of the Ethereum protocol, in Rust
https://reth.rs/
Apache License 2.0
3.99k stars 1.22k forks source link

Retry `Latest` block if we couldn't retrieve it via cache #11859

Open mattsse opened 1 month ago

mattsse commented 1 month ago

Describe the feature

in rpc we use a caching layer when fetching blocks, if a block is requested by a tag (Latest) then this can end up returning an error if there's a reorg in process:

because the cache operates on block hashes, we encounter a reorg after we looked up the latest hash and before we try to find the block:

https://github.com/paradigmxyz/reth/blob/52848a352a241cb1d16ef5040ef2c4b16b0cac15/crates/rpc/rpc-eth-api/src/helpers/block.rs#L236-L247

this isn't easily solvable, we can do two things, either do the id -> hash conversion during the cache lookup. or simply retry once if we encounter a block not found error and the blockid is latest.

imo simply retrying once is the best solution here and should guard against most reorg related issues.

TODO

Additional context

No response

mahmudsudo commented 1 month ago

Can i get assigned to this ?

jun0tpyrc commented 1 month ago

doing some search - sounds what being described in this thread could be the cause for https://github.com/paradigmxyz/reth/issues/11234 ?!

DanielEmmanuel1 commented 1 month ago

I’d like to resolve this.

My Developer Background: I am a developer with experience in blockchain technologies and RPC implementations. I have worked on various projects that require efficient data retrieval and error handling. My focus is on building robust systems that can gracefully handle edge cases like reorgs to ensure a seamless user experience.

My Proposed Solution To Tackle The Issue:

  1. Retry Mechanism: Implement a retry mechanism that triggers a lookup for the Latest block if the initial retrieval results in a "block not found" error.

  2. Error Handling: Ensure that the retry only occurs when the block ID is tagged as Latest.

  3. Documentation: Update the documentation to include information about this change, detailing why we are implementing this retry strategy and how it addresses reorg-related issues.

DanielEmmanuel1 commented 4 weeks ago

@mattsse Can i take up this issue I'd like to resolve this

manstevo commented 1 week ago

Can I jump on this task?