-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat(rpc-eth-types+api): add latest chain state tracking to EthStateCache
and EthStateCacheService
#13164
feat(rpc-eth-types+api): add latest chain state tracking to EthStateCache
and EthStateCacheService
#13164
Conversation
…ck_with_senders/get_sealed_block_with_senders
let block = match block_id { | ||
BlockId::Number(BlockNumberOrTag::Latest) => { | ||
if let Some(block) = self | ||
.cache() | ||
.latest_block_with_senders() | ||
.await | ||
.map_err(Self::Error::from_eth_err)? | ||
{ | ||
Some(block) | ||
} else { | ||
// Fallback to traditional lookup if latest isn't cached | ||
match self | ||
.provider() | ||
.block_hash_for_id(block_id) | ||
.map_err(Self::Error::from_eth_err)? | ||
{ | ||
Some(block_hash) => self | ||
.cache() | ||
.get_sealed_block_with_senders(block_hash) | ||
.await | ||
.map_err(Self::Error::from_eth_err)?, | ||
None => None, | ||
} | ||
} | ||
} | ||
_ => { | ||
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), | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattsse A bit stuck on the integration of the new function latest_block_with_senders
, I have to add this fallback to fix the integration test but the code is very redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can look at this later, I believe we can simplify this a bit by introducing a tmp var let mut maybe_block = None;
and then do a if block_id.is_latest() { maybe_block = ... }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the last entry in this list will always be the latest
block
reth/crates/rpc/rpc-eth-types/src/cache/mod.rs
Lines 460 to 463 in 9141db7
CacheAction::CacheNewCanonicalChain { chain_change } => { | |
for block in chain_change.blocks { | |
this.on_new_block(block.hash(), Ok(Some(Arc::new(block)))); | |
} |
so we can track that separately.
and to fetch the latest block, we can add a new action variant, like this but without the hash:
reth/crates/rpc/rpc-eth-types/src/cache/mod.rs
Lines 498 to 501 in 9141db7
GetBlockWithSenders { | |
block_hash: B256, | |
response_tx: BlockWithSendersResponseSender<B>, | |
}, |
let block = match block_id { | ||
BlockId::Number(BlockNumberOrTag::Latest) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can use is_latest()
here
fn clone(&self) -> Self { | ||
Self { to_service: self.to_service.clone() } | ||
} | ||
latest_chain_change: Option<ChainChange<B, R>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need to share this and can instead rely on message passing and always fetch this from the service
if let Some(chain_change) = &self.latest_chain_change { | ||
if let Some(latest_block) = chain_change.blocks.last() { | ||
return self.get_sealed_block_with_senders(latest_block.hash()).await; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should always send an action to the service, but for fetching the latest, we'd need a new action variant
Co-authored-by: Matthias Seitz <[email protected]>
Co-authored-by: Arsenii Kulikov <[email protected]>
Co-authored-by: Matthias Seitz <[email protected]>
Co-authored-by: Matthias Seitz <[email protected]>
Co-authored-by: Arsenii Kulikov <[email protected]>
Co-authored-by: Federico Gimenez <[email protected]>
Co-authored-by: Matthias Seitz <[email protected]>
Co-authored-by: Matthias Seitz <[email protected]>
Co-authored-by: Arsenii Kulikov <[email protected]>
Closes #13069.
Only use
latest_block_with_senders
incrates/rpc/rpc-eth-api/src/helpers/block.rs
for now.