Skip to content

ethclient: fix retrieval of pending block #31504

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

Merged
merged 4 commits into from
May 2, 2025

Conversation

islishude
Copy link
Contributor

It's null in a pending block

if number == rpc.PendingBlockNumber {
// Pending blocks need to nil out a few fields
for _, field := range []string{"hash", "nonce", "miner"} {
response[field] = nil
}

@islishude islishude requested a review from fjl as a code owner March 27, 2025 08:39
Comment on lines +161 to +166
// Pending blocks don't return a block hash, compute it for sender caching.
if body.Hash == nil {
tmp := head.Hash()
body.Hash = &tmp
}

Copy link
Member

@lightclient lightclient May 1, 2025

Choose a reason for hiding this comment

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

Mostly added this addition here. This allows us to correctly set the sender caching. It seems like a nice thing to have, since we're returning a types.Block anyways the user can compute the block hash and it's possible they later call TransactionSender with it. Felt weird to just drop that optimization on the ground for pending blocks.

Copy link
Member

@lightclient lightclient left a comment

Choose a reason for hiding this comment

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

LGTM

@lightclient lightclient added this to the 1.15.11 milestone May 1, 2025
@lightclient lightclient changed the title ethclient: change Hash field of rpcBlock to pointer ethclient: fix retrieval of pending block May 1, 2025
@lightclient lightclient self-assigned this May 1, 2025
@lightclient lightclient merged commit af9673b into ethereum:master May 2, 2025
3 of 4 checks passed
0g-wh pushed a commit to 0g-wh/0g-geth that referenced this pull request May 8, 2025
Since the block hash is not returned for pending blocks, ethclient cannot unmarshal into RPC block. This makes hash optional on rpc block and compute the hash locally for pending blocks to correctly key the tx sender cache.


https://github.com/ethereum/go-ethereum/blob/a82303f4e3cedcebe31540a53dde4f24fc93da80/internal/ethapi/api.go#L500-L504

---------

Co-authored-by: lightclient <[email protected]>
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