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

Increase computation limit for Cadence tx #736

Merged
merged 2 commits into from
Feb 3, 2025

Conversation

m-Peter
Copy link
Collaborator

@m-Peter m-Peter commented Jan 28, 2025

Closes: #732

Description


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

  • New Features

    • Introduced a maximum gas limit of 50,000,000 for transactions
    • Added enhanced error handling for transactions exceeding gas limit
  • Tests

    • Added a new test case to verify transaction gas limit enforcement
  • Bug Fixes

    • Implemented checks to prevent transactions with excessively high gas limits

We set the computation limit for the Cadence tx that wraps
EVM txs, to its max value.
We also add a validation check, for rejecting EVM txs which
go beyond the max gas limit.
Copy link
Contributor

coderabbitai bot commented Jan 28, 2025

Walkthrough

This pull request introduces a comprehensive approach to managing transaction gas limits across multiple components. A new constant txMaxGasLimit is defined with a value of 50,000,000, and corresponding error handling mechanisms are implemented. The changes span error definition, transaction processing logic, and test coverage, focusing on preventing transactions with gas limits exceeding the specified maximum.

Changes

File Change Summary
models/errors/errors.go Added NewTxGasLimitTooHighError function to create custom error for gas limit violations
services/requester/requester.go Added txMaxGasLimit constant and enhanced transaction processing to check gas limit
tests/web3js/eth_failure_handling_test.js Added test case to validate gas limit error handling

Assessment against linked issues

Objective Addressed Explanation
Add validation for max gas limit on eth_sendRawTransaction
Investigate insufficient computation EVM error

Possibly related PRs

Suggested labels

Bugfix

Suggested reviewers

  • peterargue
  • sideninja
  • ramtinms

Poem

🐰 Hop, hop, through the code we go,
Gas limits checked, errors in tow,
Fifty million's the line we draw,
Transactions dance, without a flaw!
Rabbit's wisdom keeps the flow just right! 🔧

✨ 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:

  • 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 (2)
models/errors/errors.go (1)

69-74: Fix the error message format.

The error message ends with a colon but doesn't include the actual gas limit value that exceeded the maximum.

Apply this diff to fix the error message format:

-		"tx gas limit exceeds the max value of %d: ",
+		"tx gas limit exceeds the max value of %d",
tests/web3js/eth_failure_handling_test.js (1)

6-23: Consider adding more test cases for edge conditions.

While the current test case verifies the basic functionality, consider adding tests for:

  1. Gas limit exactly at the maximum (50,000,000)
  2. Gas limit at 0
  3. Gas limit slightly below maximum

Example test case for maximum gas limit:

it('should succeed when tx gas limit equals the max value', async () => {
    let receiver = web3.eth.accounts.create()

    const result = await helpers.signAndSend({
        from: conf.eoa.address,
        to: receiver.address,
        value: 10,
        gasPrice: conf.minGasPrice,
        gasLimit: 50_000_000,
    })
    
    assert.isDefined(result)
})
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8326189 and 0939865.

📒 Files selected for processing (3)
  • models/errors/errors.go (1 hunks)
  • services/requester/requester.go (4 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 (3)
services/requester/requester.go (3)

47-47: LGTM! Well-defined constant.

The constant follows Go naming conventions and uses a readable numeric format with underscores.


192-194: LGTM! Proper gas limit validation.

The validation is correctly placed before other transaction validations and uses the appropriate error type.


598-599: LGTM! Appropriate compute limit setting.

The transaction is correctly configured with the default maximum transaction gas limit from Flow.

@@ -43,6 +44,7 @@ var (

const minFlowBalance = 2
const blockGasLimit = 120_000_000
const txMaxGasLimit = 50_000_000
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought max gas was 30M

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ethereum has a max gas limit of 30M, per block. However, that is not the case with Flow EVM, we are not bounded by that. This magic value I found by running EVM transactions against Testnet & Mainnet, with SetComputeLimit(9999).

With >= 51M, we get the following error:

error: [Error Code: 1300] evm runtime error: insufficient computation
   --> 8c5303eaa26202d6.EVM:529:8

Choose a reason for hiding this comment

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

The 30M limit on Flow EVM was to keep some room for the Cadence compute units for the Cadence transaction that wraps the EVM transaction. See this FLIP - https://github.com/onflow/flips/blob/main/governance/20240508-computation-limit-hike.md under "Set Gas to compute conversion ratio ...".

Copy link
Contributor

Choose a reason for hiding this comment

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

The weights were set so that 9999 computation equates to 50M evm gas (+- rounding error).
Like Vishal mentioned this was done because we wanted to fit at least 30M evm gas into one flow transaction, but each flow transaction also has a variable computation cost coming form the cadence code (that wraps the EVM transaction).

I see nothing wrong with adding this check on the gateway, we just have to remember to change it if we change the fee weights.

@franklywatson franklywatson merged commit cb79210 into main Feb 3, 2025
2 checks passed
@franklywatson franklywatson deleted the mpeter/increase-flow-tx-compute-limit branch February 3, 2025 18:04
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.

Investigate insufficient computation EVM error
5 participants