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

Consolidate the validations for max TX gas limit #759

Merged
merged 2 commits into from
Feb 21, 2025

Conversation

m-Peter
Copy link
Collaborator

@m-Peter m-Peter commented Feb 17, 2025

Closes: #758

Description

The max TX gas limit for eth_sendRawTransaction was recently set to 50M.
Now we apply this same limit to the following endpoints:

  • eth_call
  • eth_estimateGas
  • debug_traceCall

For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Summary by CodeRabbit

  • Refactor

    • Streamlined error handling in transaction processing, enhancing clarity in feedback when operations exceed allowed gas limits.
  • Tests

    • Added new test cases to ensure transactions with gas limits above the maximum are correctly identified as invalid and that appropriate error messages are returned across various methods.
    • Enhanced testing for gas limit scenarios in Ethereum transactions, ensuring proper error handling for exceeded limits.

Copy link
Contributor

coderabbitai bot commented Feb 17, 2025

Walkthrough

This update modifies error handling and gas limit validation across multiple components. API methods now return errors directly without additional wrapping, and references to the deprecated gas limit constant have been replaced with a new constant defined in the models package. The changes also include stricter gas limit validation in transaction validation logic, along with corresponding test cases to ensure that transactions exceeding the maximum gas limit are rejected.

Changes

File(s) Change Summary
api/api.go, api/debug.go, api/utils.go Updated error handling in key API methods, including returning raw errors; replaced usage of BlockGasLimit with models.TxMaxGasLimit for gas limit configuration in transaction calls and tracing functions.
models/transaction.go, models/transaction_test.go Introduced new constant TxMaxGasLimit with a value of 50,000,000 and modified the transaction validation logic to check against this limit; added a test case to validate that transactions exceeding the maximum gas limit are flagged with an appropriate error.
services/requester/requester.go Removed the hardcoded txMaxGasLimit constant and updated code to use models.TxMaxGasLimit instead; eliminated the direct gas limit check from the SendRawTransaction method.
tests/web3js/debug_traces_test.js, tests/web3js/eth_failure_handling_test.js Added test cases to verify that the system rejects transactions whose gas limits exceed the maximum allowed value; updated error message assertions across various Ethereum RPC methods like eth_call and eth_estimateGas to align with the new validation logic.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant API as API Handler
    participant TX as Transaction Validator
    C->>API: Submit Transaction Request
    API->>TX: Validate Transaction Gas Limit (using TxMaxGasLimit)
    alt Gas Limit Valid
        TX-->>API: Return success
        API-->>C: Process Transaction
    else Gas Limit Exceeded
        TX-->>API: Return error (Gas limit exceeded)
        API-->>C: Error Response
    end
Loading

Possibly related PRs

Suggested labels

Bugfix

Suggested reviewers

  • peterargue
  • zhangchiqing
  • janezpodhostnik

Poem

I'm a hopping rabbit, joyful and bright,
Scurrying through code from morning till night.
Gas limits checked with a careful glance,
Errors now flow in a more direct dance.
With whiskers twitching and a happy little hop,
I celebrate clean code that will never stop!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1848004 and 93437a2.

📒 Files selected for processing (3)
  • api/api.go (3 hunks)
  • models/transaction.go (3 hunks)
  • models/transaction_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • models/transaction_test.go
  • api/api.go
  • models/transaction.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Test

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:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

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)
api/api.go (1)

730-732: Consider error propagation in EstimateGas.

Instead of returning the max gas limit on encoding error, consider propagating the error to provide better feedback to the caller.

-		// return max tx gas limit
-		return hexutil.Uint64(models.TxMaxGasLimit), nil
+		return 0, fmt.Errorf("failed to encode transaction: %w", err)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f4a6cb and dd7b851.

📒 Files selected for processing (8)
  • api/api.go (3 hunks)
  • api/debug.go (1 hunks)
  • api/utils.go (2 hunks)
  • models/transaction.go (3 hunks)
  • models/transaction_test.go (1 hunks)
  • services/requester/requester.go (2 hunks)
  • tests/web3js/debug_traces_test.js (1 hunks)
  • tests/web3js/eth_failure_handling_test.js (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Test
🔇 Additional comments (14)
api/utils.go (2)

12-12: LGTM!

The import is correctly added to access the TxMaxGasLimit constant from the models package.


157-157: LGTM!

The gas limit is correctly updated to use the standardized models.TxMaxGasLimit constant, aligning with the PR objectives.

tests/web3js/eth_failure_handling_test.js (3)

6-27: LGTM!

The test case correctly validates that transactions with gas limit exceeding 50M are rejected with the appropriate error message.


29-49: LGTM!

The test case correctly validates that eth_call operations with gas limit exceeding 50M are rejected with the appropriate error message.


51-71: LGTM!

The test case correctly validates that eth_estimateGas operations with gas limit exceeding 50M are rejected with the appropriate error message.

models/transaction.go (2)

10-10: LGTM!

The import is correctly added to access error types for gas limit validation.


32-35: LGTM!

The implementation correctly:

  1. Defines the maximum gas limit constant with clear documentation.
  2. Adds gas limit validation as an early check in the transaction validation flow.
  3. Uses appropriate error handling for validation failures.

Also applies to: 276-278

api/debug.go (1)

197-197: LGTM!

The gas limit is correctly updated to use the standardized models.TxMaxGasLimit constant, maintaining consistency across the codebase.

services/requester/requester.go (2)

331-332: LGTM! Gas limit standardization in EstimateGas.

The code now uses models.TxMaxGasLimit as the upper bound for gas estimation, aligning with the standardization of gas limits across endpoints.


471-472: LGTM! Gas limit standardization in getBlockView.

The code now uses models.TxMaxGasLimit for view provider initialization, maintaining consistency in gas limit usage.

models/transaction_test.go (1)

306-319: LGTM! Comprehensive test case for gas limit validation.

The test case verifies that transactions with gas limits exceeding TxMaxGasLimit are correctly rejected, with appropriate error messaging.

tests/web3js/debug_traces_test.js (1)

660-679: LGTM! Integration test for gas limit validation.

The test verifies that debug_traceCall correctly rejects transactions with gas limits exceeding 50M, ensuring consistent gas limit validation across endpoints.

api/api.go (2)

581-582: LGTM! Simplified error handling in Call method.

Direct error propagation improves error transparency.


751-752: LGTM! Simplified error handling in EstimateGas.

Direct error propagation improves error transparency.

@m-Peter m-Peter force-pushed the mpeter/consolidate-tx-max-gas-limit branch from dd7b851 to 1848004 Compare February 18, 2025 09:33
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

🔭 Outside diff range comments (1)
services/requester/requester.go (1)

46-46: 🛠️ Refactor suggestion

Remove unused constant and update header initialization.

The blockGasLimit constant is no longer used after standardizing gas limits. Update the code as follows:

-const blockGasLimit = 120_000_000
...
-		GasLimit: blockGasLimit,
+		GasLimit: models.TxMaxGasLimit,

Also applies to: 149-149

🧹 Nitpick comments (2)
models/transaction.go (1)

32-35: Clarify the relationship between computation limit and gas limit.

The comment mentions "9999 as the computation limit" but doesn't explain how this relates to the 50M gas limit value. Consider expanding the comment to explain this relationship for better maintainability.

tests/web3js/eth_failure_handling_test.js (1)

29-49: Consider standardizing error messages across endpoints.

The error message format differs from the eth_sendRawTransaction endpoint:

  • eth_sendRawTransaction: "tx gas limit exceeds the max value of 50000000"
  • eth_call: "gas limit is bigger than max gas limit allowed 51000000 > 50000000"

Consider using consistent error message formats across all endpoints for better user experience.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dd7b851 and 1848004.

📒 Files selected for processing (8)
  • api/api.go (3 hunks)
  • api/debug.go (1 hunks)
  • api/utils.go (2 hunks)
  • models/transaction.go (3 hunks)
  • models/transaction_test.go (1 hunks)
  • services/requester/requester.go (2 hunks)
  • tests/web3js/debug_traces_test.js (1 hunks)
  • tests/web3js/eth_failure_handling_test.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • api/debug.go
  • api/utils.go
  • tests/web3js/debug_traces_test.js
  • models/transaction_test.go
  • api/api.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Test
🔇 Additional comments (6)
services/requester/requester.go (3)

191-193: LGTM! Centralized validation improves consistency.

The change to use models.ValidateTransaction centralizes the gas limit validation, which aligns with the PR objective to standardize validation across endpoints.


331-331: LGTM! Standardized gas limit in estimation logic.

Using models.TxMaxGasLimit ensures consistency with other endpoints while maintaining the efficient binary search algorithm for gas estimation.


471-471: LGTM! Standardized gas limit in view provider.

Using models.TxMaxGasLimit in the view provider ensures consistent gas limits for eth_call and debug_traceCall endpoints.

models/transaction.go (1)

276-278: LGTM! Clean and effective gas limit validation.

The implementation correctly validates the transaction gas limit against the new maximum value, with clear error handling.

tests/web3js/eth_failure_handling_test.js (2)

6-27: LGTM! Comprehensive test for raw transaction gas limit.

The test effectively verifies that transactions exceeding the 50M gas limit are rejected with the appropriate error message.


51-71: LGTM! Good test coverage for estimateGas endpoint.

The test effectively verifies gas limit validation for the eth_estimateGas endpoint, maintaining consistency with the eth_call test structure.

@@ -189,10 +188,6 @@ func (e *EVM) SendRawTransaction(ctx context.Context, data []byte) (common.Hash,
return common.Hash{}, err
}

if tx.Gas() > txMaxGasLimit {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this check removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@franklywatson franklywatson merged commit 7274b59 into main Feb 21, 2025
2 checks passed
@franklywatson franklywatson deleted the mpeter/consolidate-tx-max-gas-limit branch February 21, 2025 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consolidate validations for max TX gas limit
4 participants