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

rpc: retry latest block via cache in block_with_senders #11861

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tcoratger
Copy link
Contributor

Should close #11859

Copy link
Member

@emhane emhane left a comment

Choose a reason for hiding this comment

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

isn't it a better option to change the block_hash field of CacheAction::GetBlockWithSenders to a BlockId? the EthCacheService also stores a provider, so can fetch the latest block hash when it processes the cache action.

this would makes more sense, since the EthCacheService has a queue of cache action events that it processes. the delay between sending the request and processing is only trivially solved by a retry to fetch the hash in this rpc method impl, if solved at all.

GetBlockWithSenders {
block_hash: B256,
response_tx: BlockWithSendersResponseSender,
},

@tcoratger
Copy link
Contributor Author

@emhane I get your point, it seems like a good idea to me. I think that in the issue opened by @mattsse he mentioned the fact that retrying was the easiest solution to perform and that would solve most reorg issues but not all:

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

But I am totally open if it needs to be modified. Maybe I am wrong but I have the following remarks:

  • In the CacheAction everything is fetches by hashes and this will be the unique field fetched by ID, is this not a problem in order to have some kind of similar logic for everything and not something different everywhere?
  • If we do that, it requires also modifying the BlockLruCache to have a block ID instead of the hash here

type BlockLruCache<L> = MultiConsumerLruCache<
B256,
Arc<SealedBlockWithSenders>,
L,
Either<BlockWithSendersResponseSender, BlockTransactionsResponseSender>,
>;

so maybe it requires a bit more changes.

Maybe doing the block hash to block id transformation directly in the lookup here as pointed out in the issue description

CacheAction::GetBlockWithSenders { block_hash, response_tx } => {

could be an intermediate solution? But if the block hash to block ID switch is the best solution given everything, more than happy to modify it.

@mattsse
Copy link
Collaborator

mattsse commented Oct 18, 2024

yeah I think we could use a new command in the cache that looks up by blockid, this way we delay the tag -> hash conversion as late as possible and can prevent a miss due to a reorg

@mattsse
Copy link
Collaborator

mattsse commented Oct 18, 2024

modifying the BlockLruCache to have a block ID

we can't do that, only hashes map blocks correctly

@tcoratger
Copy link
Contributor Author

@mattsse Let me know if this is what you had in mind, I may have done it a little differently than you thought:

  • I realized that simply changing the block hash to block id in the CacheAction could be negative for other use cases where we already had the block hash before. This would have amounted to:
    • Transforming the block ID into a block hash in a function
    • Then transforming it back into a block ID to enter it in the GetBlockWithSenders
    • Finally transforming again to a block hash at the beginning of the lookup
    • Which generally produced a useless round trip.
  • I favored another technique where I simply create a new specific instance for this use case without touching the rest.

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.

actually using the cache with BlockId isn't trivial, I'd like to limit this pr to just the retry which should be fine

@tcoratger
Copy link
Contributor Author

actually using the cache with BlockId isn't trivial, I'd like to limit this pr to just the retry which should be fine

@mattsse Fine just reverted the changes to have only the retry here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Retry Latest block if we couldn't retrieve it via cache
3 participants