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

ethclient/ethclient.go add_get_block_by_tag_function #30984

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

EdisonSR
Copy link

@EdisonSR EdisonSR commented Jan 4, 2025

When querying blocks using special tags, there is no direct method call. It requires delving into the code to find the corresponding number for the special tag and then retrieve the block, which is inconvenient. Therefore, a method was encapsulated to directly query blocks using special tags.

@EdisonSR EdisonSR requested a review from fjl as a code owner January 4, 2025 08:38
@@ -94,6 +94,13 @@ func (ec *Client) BlockByNumber(ctx context.Context, number *big.Int) (*types.Bl
return ec.getBlock(ctx, "eth_getBlockByNumber", toBlockNumArg(number), true)
}

// BlockByNumber returns a block from the current canonical chain. If tag is nil, the
Copy link
Member

Choose a reason for hiding this comment

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

You can retrieve the block by using tag with BlockByNumber endpoint.

e.g.

  • BlockByNumber(context.Background(), nil) means latest,
  • BlockByNumber(context.Background(), big.NewInt(-1)) means pending,
  • BlockByNumber(context.Background(), big.NewInt(-2)) means latest,
  • BlockByNumber(context.Background(), big.NewInt(-3)) means finalized,
  • BlockByNumber(context.Background(), big.NewInt(-4)) means safe,

However, I do see the point for having an endpoint to explicitly request blocks with tag.
While these special negative numbers can be translated by ethclient to tags, they are Geth-related, not publicly defined in the spec. Probably it's better to extend the BlockByNumber endpoint a bit, allowing specify tag explicitly?

cc @fjl

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for your reply.,Yes, I can know which numbers represent which labels after digging into the code, but it is very inconvenient, so do I need to modify the BlockByNumber method and submit it again?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree the numbers are not very visible right now. After some discussion in team, we don't want to add another method, but would be open to improving documentation. We could also add redefinitions of these constants into package ethclient for convenience.

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.

3 participants