Reduce clones and cleanup in block cache path#6431
Open
incrypto32 wants to merge 4 commits intomasterfrom
Open
Reduce clones and cleanup in block cache path#6431incrypto32 wants to merge 4 commits intomasterfrom
incrypto32 wants to merge 4 commits intomasterfrom
Conversation
Use the typed `blocks()` method instead of `blocks_as_json()` so that block comparisons go through the same alloy serialization on both the cached and provider sides. This gives a fairer diff by normalizing both blocks through the same types, and only compares the block data (without receipts) since `eth_getBlockByHash` does not return receipts.
All callers now use the typed `blocks()` method. The resolver serializes the CachedBlock to JSON at the GraphQL boundary. This eliminates the separate raw-JSON code path from the trait.
Arc-wrap the Light variant to avoid expensive deep clones of AnyBlock. into_light_block now borrows self and returns Arc via cheap refcount bumps.
Remove the single-consumer EthereumJsonBlock wrapper and inline its deserialization and patching logic directly into CachedBlock::from_json.
lutter
approved these changes
Mar 10, 2026
Collaborator
lutter
left a comment
There was a problem hiding this comment.
Nice! Just a few very minor comments, feel free to ignore
| let json = match block { | ||
| CachedBlock::Full(ref b) => serde_json::to_value(b), | ||
| CachedBlock::Light(ref b) => serde_json::to_value(b), | ||
| }; |
Collaborator
There was a problem hiding this comment.
This could be a to_json method on CachedBlock
| .unwrap_or_default() | ||
| .into_iter() | ||
| .map(CachedBlock::into_light_block) | ||
| .map(|b| b.into_light_block()) |
Collaborator
There was a problem hiding this comment.
This seems like a noop, but I assume it's because b isn't a reference here. Maybe changing into_iter() to iter() would be better to make it clear that some copying is going on
| } | ||
|
|
||
| pub fn into_light_block(self) -> Arc<LightEthereumBlock> { | ||
| pub fn into_light_block(&self) -> Arc<LightEthereumBlock> { |
Collaborator
There was a problem hiding this comment.
Very minor, but in Rust, into_ methods usually take ownership; to_ methods usually operate on references.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses review feedback from #6400.
check_blocksto use typedblocks()instead of raw JSONblocks_as_jsonfromChainStoretraitLightEthereumBlockinArcinsideCachedBlock::Lightto avoid expensive deep clonesEthereumJsonBlockintoCachedBlock::from_jsonand delete the wrapper