Skip to content

Conversation

@d4mr
Copy link
Contributor

@d4mr d4mr commented Aug 19, 2025

  • Added a fallback case to handle transaction reverts during gas estimation, ensuring that fundamentally broken transactions fail appropriately.

Summary by CodeRabbit

  • Bug Fixes
    • Improved gas estimation handling: transactions that revert during estimation are now reported as per-transaction failures with clear messages, rather than causing broader worker failures.
    • Enhanced compatibility with providers that don’t return revert data by detecting revert indications in error messages.
    • Minor error message formatting cleanup with no functional impact.

- Added a fallback case to handle transaction reverts during gas estimation, ensuring that fundamentally broken transactions fail appropriately.
@coderabbitai
Copy link

coderabbitai bot commented Aug 19, 2025

Walkthrough

Adds a revert-detection fallback in gas estimation error handling: if EIP-1559 estimation fails and no revert data is present but the message includes "revert", return TransactionSimulationFailed with a descriptive message. Also consolidates a legacy gas price error format string into a single line. No API changes.

Changes

Cohort / File(s) Summary
EOA transaction gas estimation and legacy gas price handling
executors/src/eoa/worker/transaction.rs
Added message-based revert detection when EIP-1559 gas estimation fails without revert data; returns TransactionSimulationFailed with original engine error. Minor formatting: single-line legacy gas price error string. No public signatures changed.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Worker
  participant Provider
  participant Engine

  rect rgb(245,245,255)
  note over Worker: Estimate gas (EIP-1559)
  Worker->>Provider: eth_estimateGas (EIP-1559)
  alt Estimation succeeds
    Provider-->>Worker: Gas estimate
    Worker->>Engine: Proceed with transaction
  else Estimation fails
    Provider-->>Worker: Error payload
    alt Has revert data
      note over Worker: Existing handling
      Worker-->>Engine: TransactionSimulationFailed (with revert data)
    else Message contains "revert" (new)
      note over Worker: New branch: message-based revert detection
      Worker-->>Engine: TransactionSimulationFailed ("Transaction reverted during gas estimation: …", with inner error)
    else Other error
      Worker->>Provider: Fallback to legacy gas price path
      Provider-->>Worker: Legacy gas price or error
      Worker->>Engine: Continue or propagate error (formatted single-line)
    end
  end
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch pb/fix-handling-revert-without-data

🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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

@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)
executors/src/eoa/worker/transaction.rs (2)

327-337: Broaden revert detection and avoid full Unicode lowercasing

  • Use to_ascii_lowercase() (cheaper than to_lowercase()).
  • Optionally recognize other revert-like phrases commonly returned by nodes (“invalid opcode”, “bad instruction”, “out of gas”, etc.), which are also deterministic execution failures.

Proposed focused change:

-                        } else if error_payload.message.to_lowercase().contains("revert") {
+                        } else {
+                            // Fallback: detect deterministic EVM execution failures via message text.
+                            // Use ASCII case-insensitive checks for common phrases.
+                            let msg_lc = error_payload.message.to_ascii_lowercase();
+                            if msg_lc.contains("revert")
+                                || msg_lc.contains("invalid opcode")
+                                || msg_lc.contains("bad instruction")
+                                || msg_lc.contains("out of gas")
+                                || msg_lc.contains("stack underflow")
+                                || msg_lc.contains("stack overflow")
+                                || msg_lc.contains("invalid jump")
+                            {
+                                tracing::debug!("Classifying gas estimation failure as deterministic revert (no data): {}", error_payload.message);
                             // This is a revert - the transaction is fundamentally broken
                             // This should fail the individual transaction, not the worker
                             // We need this fallback case because some providers don't return revert data
-                            return Err(EoaExecutorWorkerError::TransactionSimulationFailed {
-                                message: format!(
-                                    "Transaction reverted during gas estimation: {}",
-                                    error_payload.message
-                                ),
-                                inner_error: e.to_engine_error(&self.chain),
-                            });
+                                return Err(EoaExecutorWorkerError::TransactionSimulationFailed {
+                                    message: format!(
+                                        "Transaction reverted during gas estimation: {}",
+                                        error_payload.message
+                                    ),
+                                    inner_error: e.to_engine_error(&self.chain),
+                                });
+                            }
                         }

327-337: Add test coverage for revert-without-data classification in gas estimation

Please add unit tests for the estimate_gas call in executors/src/eoa/worker/transaction.rs to verify all revert‐handling paths:

• When the mocked provider returns RpcError::ErrorResp { data: Some(revert_data), message, … }, assert that the result is
Err(EoaExecutorWorkerError::TransactionSimulationFailed) and that the error message includes the hex-encoded revert_data.
• When it returns RpcError::ErrorResp { data: None, message } where message.to_lowercase().contains("revert"), assert the same TransactionSimulationFailed without data in the message.
• When it returns any other RpcError::ErrorResp (no “revert” marker), assert that the original RpcError is returned (so the worker will nack).

You can use a test double or mockall to implement a fake Provider that returns these scenarios, and place the tests alongside existing ones in executors/src/eoa/worker.

📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 6f87137 and a231375.

📒 Files selected for processing (1)
  • executors/src/eoa/worker/transaction.rs (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
executors/src/eoa/worker/transaction.rs (1)
executors/src/eoa/error_classifier.rs (1)
  • message (224-236)
🔇 Additional comments (2)
executors/src/eoa/worker/transaction.rs (2)

213-215: LGTM: streamlined legacy gas price error message formatting

Single-line format keeps the same semantics and improves readability. No functional change.


327-337: Good fallback for revert-without-data during gas estimation

Treating “revert” in the error message as a simulation failure closes the gap for providers that omit revert data. This aligns with the intent to fail the transaction rather than the worker.

),
inner_error: e.to_engine_error(&self.chain),
});
} else if error_payload.message.to_lowercase().contains("revert") {
Copy link
Member

Choose a reason for hiding this comment

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

What happens for execution reverted with data 0x which can be lack of gas (evm panic), we handle that elsewhere? If not would add an extra condition that data is not 0x potentially

Don't need to block this pr on this, just wanted to add the comment for future reference

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is simulation not execution, so we don't have the actual gas limit with us yet. In case you're referring to insufficient balance, that's handled here:

pub fn should_update_balance_threshold(error: &EngineError) -> bool {

@d4mr d4mr merged commit f3d700a into main Aug 19, 2025
3 checks passed
@d4mr d4mr deleted the pb/fix-handling-revert-without-data branch August 19, 2025 14:03
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