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

fix BuildBlocksValidator: use bytes buffer pool correctly #10965

Merged

Conversation

zhiqiangxu
Copy link
Contributor

@zhiqiangxu zhiqiangxu commented Jun 20, 2024

The original implementation is essentially the same as passing nil as dst and thus is a waste of memory.

And there's no need to update res unless data is larger.

This PR also simplifies expressions like:

payload.BlobGasUsed == nil || (payload.BlobGasUsed != nil && *payload.BlobGasUsed != 0)

to:

payload.BlobGasUsed == nil || *payload.BlobGasUsed != 0.

@zhiqiangxu zhiqiangxu requested a review from a team as a code owner June 20, 2024 08:27
@zhiqiangxu zhiqiangxu requested a review from refcell June 20, 2024 08:27
Copy link
Contributor

@protolambda protolambda left a comment

Choose a reason for hiding this comment

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

Nice catch. It looks like the underlying snappy.Decode function uses len, not cap, to determine if the destination-slice can grow to the necessary capacity. So passing in a [:0] indeed doesn't help. The len(data) > len(*res) would be better to use cap though, since we care about the available size, not the utilized size.

Also, there is a similar issue in BuildMsgIdFn. I'll update it to fix that also.

@protolambda protolambda added this pull request to the merge queue Jun 28, 2024
Merged via the queue into ethereum-optimism:develop with commit b219b84 Jun 28, 2024
60 checks passed
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.

2 participants