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

Track latest block in rpc cache #13069

Open
mattsse opened this issue Dec 2, 2024 · 4 comments · May be fixed by #13482
Open

Track latest block in rpc cache #13069

mattsse opened this issue Dec 2, 2024 · 4 comments · May be fixed by #13482
Assignees
Labels
A-rpc Related to the RPC implementation C-enhancement New feature or request D-good-first-issue Nice and easy! A great choice to get started

Comments

@mattsse
Copy link
Collaborator

mattsse commented Dec 2, 2024

Describe the feature

we have a race condition that affects the Latest block:

let block_hash = match self
.provider()
.block_hash_for_id(block_id)
.map_err(Self::Error::from_eth_err)?
{
Some(block_hash) => block_hash,
None => return Ok(None),
};
self.cache()
.get_sealed_block_with_senders(block_hash)
.await
.map_err(Self::Error::from_eth_err)

by the time the cache handles this command:

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

the latest block can be reorged in between and removed from the cache:

chain_change: ChainChange,
},
RemoveReorgedChain {

we can get rid of this race condition, in a few ways:

  1. retry on the callsite if it returns None and the blockId is latest
  2. track the latest block in the cache itself: last entry in:
    CacheNewCanonicalChain {
    chain_change: ChainChange,
    },

former would be easier but feels hacky

latter is cleaner because this approach then allows us to also track the safe+finalized in a similar way.

TODO

  • add an optional field to to statecache that tracks the last received ChainChange then add a latest_blockwith_senders function to ethstatecache

Additional context

#13001

@mattsse mattsse added C-enhancement New feature or request S-needs-triage This issue needs to be labelled labels Dec 2, 2024
@mattsse mattsse added D-good-first-issue Nice and easy! A great choice to get started A-rpc Related to the RPC implementation and removed S-needs-triage This issue needs to be labelled labels Dec 2, 2024
@lean-apple
Copy link
Contributor

Hello, can I work on this ?

@mattsse
Copy link
Collaborator Author

mattsse commented Dec 2, 2024

ty @lean-apple

noticed the number formatting was of, so in case this sounded confusing, we should go with 2.

will check your other prs asap 🙏

@mimisavage
Copy link

Could I grab this task?

@lean-apple
Copy link
Contributor

Could I grab this task?

Thanks for the assignment @mattsse :) Yet @mimisavage, feel free to open a PR if you’d like before the next couple of days, I’ve got two PRs to wrap up in the meantime.

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-enhancement New feature or request D-good-first-issue Nice and easy! A great choice to get started
Projects
Status: Todo
3 participants