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

feat: add the gas estimation API to the signer #4270

Merged
merged 2 commits into from
Jan 27, 2025

Conversation

rach-id
Copy link
Member

@rach-id rach-id commented Jan 27, 2025

Overview

Closes #4258

If there are other places where it would be beneficial to document the API, please let me know to make the corresponding changes.

@rach-id rach-id added the WS: BestTxs Reliable and seamless transaction flow label Jan 27, 2025
@rach-id rach-id self-assigned this Jan 27, 2025
@rach-id rach-id requested a review from a team as a code owner January 27, 2025 11:05
@rach-id rach-id requested review from rootulp and ninabarbakadze and removed request for a team January 27, 2025 11:05
Copy link
Contributor

coderabbitai bot commented Jan 27, 2025

📝 Walkthrough

Walkthrough

The pull request introduces two new methods to the Signer struct in the pkg/user/signer.go file, focusing on gas price estimation functionality. The QueryGasPrice method retrieves the estimated gas price for a given transaction priority, while the QueryGasUsedAndPrice method provides both gas price and estimated gas used for a specific transaction. These additions are accompanied by a corresponding test method in tx_client_test.go to validate the new gas estimation capabilities.

Changes

File Change Summary
pkg/user/signer.go - Added QueryGasPrice method to estimate gas price
- Added QueryGasUsedAndPrice method to estimate gas price and usage
- Updated import statements to include necessary packages
pkg/user/tx_client_test.go - Added TestGasPriceAndUsedEstimate test method
- Imported gasestimation and assert packages

Assessment against linked issues

Objective Addressed Explanation
Add helper function for gas price estimation [#4258]
Create method to query gas price

Possibly related PRs

Suggested reviewers

  • cmwaters
  • vgonkivs
  • ninabarbakadze
  • evan-forbes
  • rootulp
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Sorry, something went wrong.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
pkg/user/tx_client_test.go (1)

357-381: Consider adding edge case tests.

While the current tests cover the happy path well, consider adding tests for:

  1. Different transaction priorities (low, medium)
  2. Invalid transaction bytes
  3. Context cancellation/timeout scenarios
  4. Error cases from the gRPC client

Example test cases to add:

t.Run("query with different priorities", func(t *testing.T) {
    priorities := []gasestimation.TxPriority{
        gasestimation.TxPriority_TX_PRIORITY_LOW,
        gasestimation.TxPriority_TX_PRIORITY_MEDIUM,
    }
    for _, priority := range priorities {
        gasPrice, err := signer.QueryGasPrice(ctx, suite.ctx.GRPCClient, priority)
        assert.NoError(t, err)
        assert.Greater(t, gasPrice, float64(0))
    }
})

t.Run("query with invalid tx bytes", func(t *testing.T) {
    invalidTx := []byte("invalid tx")
    _, _, err := signer.QueryGasUsedAndPrice(
        ctx,
        suite.ctx.GRPCClient,
        gasestimation.TxPriority_TX_PRIORITY_HIGH,
        invalidTx,
    )
    assert.Error(t, err)
})

t.Run("query with cancelled context", func(t *testing.T) {
    ctx, cancel := context.WithCancel(context.Background())
    cancel()
    _, err := signer.QueryGasPrice(ctx, suite.ctx.GRPCClient, gasestimation.TxPriority_TX_PRIORITY_HIGH)
    assert.Error(t, err)
})
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 629b807 and dc733b7.

📒 Files selected for processing (2)
  • pkg/user/signer.go (2 hunks)
  • pkg/user/tx_client_test.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test / test
  • GitHub Check: Summary
🔇 Additional comments (2)
pkg/user/signer.go (2)

305-322: LGTM! Well-documented gas price estimation method.

The implementation is clean, includes proper error handling, and references the architecture decision record (ADR-023) for more details.


324-346: LGTM! Well-documented gas estimation method.

The implementation correctly handles both gas price and usage estimation, includes proper error handling, and references the architecture decision record (ADR-023) for more details.

@evan-forbes evan-forbes added the backport:v3.x PR will be backported automatically to the v3.x branch upon merging label Jan 27, 2025
Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

LGTM

@rach-id rach-id merged commit eb9f3c2 into main Jan 27, 2025
28 checks passed
@rach-id rach-id deleted the add-the-gas-estimation-API-to-the-signer branch January 27, 2025 15:10
mergify bot pushed a commit that referenced this pull request Jan 27, 2025
## Overview

Closes #4258

If there are other places where it would be beneficial to document the
API, please let me know to make the corresponding changes.

(cherry picked from commit eb9f3c2)
rach-id added a commit that referenced this pull request Jan 27, 2025
## Overview

Closes #4258

If there are other places where it would be beneficial to document the
API, please let me know to make the corresponding changes.

(cherry picked from commit eb9f3c2)
@vgonkivs
Copy link
Member

Hey, are there any plans to rework EstimateGas in TxClient using the new functionality? I had an impression that the signer's responsibility is to build and sign the transactions. IMO, the most effective way of interacting with this API is through the TxClient, since it already has a relevant method.

@rach-id
Copy link
Member Author

rach-id commented Jan 31, 2025

this means that the txclient will always need to have an app gRPC endpoint. is this something we want?

@vgonkivs
Copy link
Member

but it already keeps it

grpc *grpc.ClientConn
. Or you mean gas estimator endpoint, provided by the user? The node can do it for you and pass it if it is configured.

@rach-id
Copy link
Member Author

rach-id commented Jan 31, 2025

then let's do it :shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:v3.x PR will be backported automatically to the v3.x branch upon merging WS: BestTxs Reliable and seamless transaction flow
Projects
None yet
Development

Successfully merging this pull request may close these issues.

gas estimation helper function and documentation
4 participants