Skip to content

Conversation

@d4mr
Copy link
Contributor

@d4mr d4mr commented Jul 4, 2025

  • Introduced gasFeeCeiling in transaction schemas and types.
  • Updated transaction parsing to include gasFeeCeiling.
  • Implemented logic to delay transactions if estimated costs exceed the gas fee ceiling in the send transaction worker.

Example log:

{
  "result": {
    "raw": {
      "chainId": 84532,
      "from": "0x31812b06c9004f091c48AeCE05573389Cc1e0975",
      "to": "0x9aB78C7193c59453F3E8aE9184e1121C6Db3eb4E",
      "data": "0x",
      "value": "0",
      "overrides": {
        "gasFeeCeiling": "100"
      },
      "timeoutSeconds": 100,
      "isUserOp": true,
      "status": "errored",
      "queueId": "427119af-3951-4b47-8fbd-a8bd15d16fa4",
      "queuedAt": "2025-07-04T07:17:44.546Z",
      "resendCount": 0,
      "signerAddress": "0x31812b06c9004f091c48AeCE05573389Cc1e0975",
      "accountAddress": "0x9aB78C7193c59453F3E8aE9184e1121C6Db3eb4E",
      "target": "0x9aB78C7193c59453F3E8aE9184e1121C6Db3eb4E",
      "accountFactoryAddress": "0x4bE0ddfebcA9A5A4a617dee4DeCe99E7c862dceb",
      "entrypointAddress": "0x0000000071727De22E5E9d8BAf0edAc6f37da032",
      "errorMessage": "Exceeded 100s timeout"
    },
    "jobs": [
      {
        "queue": "transactions-1-send",
        "jobId": "427119af-3951-4b47-8fbd-a8bd15d16fa4.0",
        "timestamp": "2025-07-04T07:17:44.546Z",
        "lines": [
          "Override gas fee ceiling (100) is lower than onchain estimated cost (279894904068). Delaying job until Fri Jul 04 2025 12:52:48 GMT+0530 (India Standard Time). [callGasLimit: 27955, preVerificationGas: 68823, verificationGasLimit: 68825, maxFeePerGas: 1690156]",
          "Transaction errored: {\"chainId\":84532,\"from\":\"0x31812b06c9004f091c48AeCE05573389Cc1e0975\",\"to\":\"0x9aB78C7193c59453F3E8aE9184e1121C6Db3eb4E\",\"data\":\"0x\",\"value\":\"0\",\"overrides\":{\"gasFeeCeiling\":\"100\"},\"timeoutSeconds\":100,\"isUserOp\":true,\"status\":\"errored\",\"queueId\":\"427119af-3951-4b47-8fbd-a8bd15d16fa4\",\"queuedAt\":\"2025-07-04T07:17:44.546Z\",\"resendCount\":0,\"signerAddress\":\"0x31812b06c9004f091c48AeCE05573389Cc1e0975\",\"accountAddress\":\"0x9aB78C7193c59453F3E8aE9184e1121C6Db3eb4E\",\"target\":\"0x9aB78C7193c59453F3E8aE9184e1121C6Db3eb4E\",\"accountFactoryAddress\":\"0x4bE0ddfebcA9A5A4a617dee4DeCe99E7c862dceb\",\"entrypointAddress\":\"0x0000000071727De22E5E9d8BAf0edAc6f37da032\",\"errorMessage\":\"Exceeded 100s timeout\"}."
        ],
        "processedOn": "2025-07-04T07:22:48.337Z",
        "finishedOn": "2025-07-04T07:22:48.346Z"
      }
    ]
  }
}

PR-Codex overview

This PR introduces a new optional parameter gasFeeCeiling in various transaction-related files, enhancing transaction fee management by allowing jobs to be delayed if the estimated costs exceed this ceiling.

Detailed summary

  • Added gasFeeCeiling as an optional parameter in:
    • src/shared/db/transactions/queue-tx.ts
    • src/shared/utils/transaction/types.ts
  • Implemented logic to handle gasFeeCeiling in:
    • src/server/utils/transaction-overrides.ts
    • src/server/schemas/tx-overrides.ts
    • src/worker/tasks/send-transaction-worker.ts (multiple instances)
  • Enhanced error message formatting for improved readability in send-transaction-worker.ts.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Introduced support for a new optional "gas fee ceiling" parameter when submitting transactions, allowing users to specify the maximum total gas fee they are willing to pay. Transactions will be delayed if network fees exceed this ceiling and processed when fees are within the specified limit.
  • Refactor

    • Improved clarity in the handling of gas fee overrides and related error messages during transaction processing.

@coderabbitai
Copy link

coderabbitai bot commented Jul 4, 2025

Walkthrough

A new optional gasFeeCeiling parameter was introduced across schemas, types, and transaction processing logic. This ceiling allows users to specify the maximum total gas fee they are willing to pay for a transaction. Transaction workers now check this ceiling and delay processing if estimated gas costs exceed it, resuming once conditions improve.

Changes

File(s) Change Summary
src/server/schemas/tx-overrides.ts Added optional gasFeeCeiling property to the txOverrides schema with a detailed description.
src/server/utils/transaction-overrides.ts Extended parseTransactionOverrides to include parsed gasFeeCeiling in returned overrides.
src/shared/db/transactions/queue-tx.ts Added optional gasFeeCeiling?: string to txOverrides in QueueTxParams interface.
src/shared/utils/transaction/types.ts Added optional gasFeeCeiling?: bigint to overrides in InsertedTransaction type.
src/worker/tasks/send-transaction-worker.ts Added logic to delay jobs if estimated gas cost exceeds gasFeeCeiling in transaction workers.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant API
    participant Worker
    participant Blockchain

    User->>API: Submit transaction with txOverrides (may include gasFeeCeiling)
    API->>Worker: Queue transaction (includes gasFeeCeiling in overrides)
    Worker->>Worker: Estimate gas cost
    alt Estimated cost > gasFeeCeiling
        Worker->>Worker: Delay job (moveToDelayed, throw DelayedError)
    else Estimated cost <= gasFeeCeiling
        Worker->>Blockchain: Send transaction
        Blockchain-->>Worker: Transaction result
    end
    Worker-->>API: Update transaction status
Loading

Possibly related PRs


📜 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 49fb6f4 and f1e09f4.

📒 Files selected for processing (5)
  • src/server/schemas/tx-overrides.ts (1 hunks)
  • src/server/utils/transaction-overrides.ts (1 hunks)
  • src/shared/db/transactions/queue-tx.ts (1 hunks)
  • src/shared/utils/transaction/types.ts (1 hunks)
  • src/worker/tasks/send-transaction-worker.ts (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/server/utils/transaction-overrides.ts
  • src/shared/db/transactions/queue-tx.ts
  • src/shared/utils/transaction/types.ts
  • src/server/schemas/tx-overrides.ts
  • src/worker/tasks/send-transaction-worker.ts
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: build
  • GitHub Check: lint
  • GitHub Check: Analyze (javascript-typescript)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

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

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

@d4mr d4mr requested a review from arcoraven July 4, 2025 07:25
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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9a8a054 and 2b55889.

📒 Files selected for processing (5)
  • src/server/schemas/tx-overrides.ts (1 hunks)
  • src/server/utils/transaction-overrides.ts (1 hunks)
  • src/shared/db/transactions/queue-tx.ts (1 hunks)
  • src/shared/utils/transaction/types.ts (1 hunks)
  • src/worker/tasks/send-transaction-worker.ts (7 hunks)
🧰 Additional context used
🧠 Learnings (1)
src/worker/tasks/send-transaction-worker.ts (1)
Learnt from: d4mr
PR: thirdweb-dev/engine#897
File: src/server/routes/backend-wallet/transfer.ts:15-0
Timestamp: 2025-06-09T23:37:07.373Z
Learning: The `getChecksumAddress` function in this codebase safely handles undefined/null values by accepting `val?: string | Address | null` and returning `Address | undefined`. It returns `undefined` when passed falsy values, so calling it on potentially undefined values like `accountFactoryAddress` does not cause runtime errors.
🧬 Code Graph Analysis (3)
src/server/utils/transaction-overrides.ts (1)
src/shared/utils/primitive-types.ts (1)
  • maybeBigInt (5-5)
src/server/schemas/tx-overrides.ts (1)
src/server/schemas/number.ts (1)
  • WeiAmountStringSchema (8-11)
src/worker/tasks/send-transaction-worker.ts (1)
src/shared/utils/error.ts (1)
  • wrapError (5-6)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: lint
  • GitHub Check: build
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (8)
src/shared/db/transactions/queue-tx.ts (1)

26-26: LGTM! Clean interface addition.

The addition of the optional gasFeeCeiling property is consistent with other gas-related properties in the interface and aligns with the PR's objective to add gas fee ceiling support.

src/server/utils/transaction-overrides.ts (1)

23-23: LGTM! Consistent parsing implementation.

The gasFeeCeiling parsing follows the established pattern using maybeBigInt, which safely handles the string-to-BigInt conversion and is consistent with other gas-related properties.

src/shared/utils/transaction/types.ts (1)

48-48: LGTM! Proper type definition.

The optional gasFeeCeiling property with bigint type is consistent with the parser output and follows the same pattern as other gas-related properties in the overrides object.

src/server/schemas/tx-overrides.ts (1)

27-31: LGTM! Well-documented schema addition.

The gasFeeCeiling schema is properly defined using WeiAmountStringSchema and includes an excellent description that clearly explains the delay behavior and clarifies that it doesn't affect actual gas fee calculation.

src/worker/tasks/send-transaction-worker.ts (4)

307-327: LGTM! Correct userOp gas fee ceiling implementation.

The gasFeeCeiling logic for user operations correctly:

  • Calculates total estimated cost using maxFeePerGas * (callGasLimit + preVerificationGas + verificationGasLimit)
  • Delays the job for 5 minutes when estimated cost exceeds the ceiling
  • Provides detailed logging with all relevant gas parameters
  • Uses proper DelayedError handling for BullMQ

331-333: LGTM! Improved maxFeePerGas logic clarity.

The refactoring improves readability by storing the override in a local variable and using clearer conditional logic. The comparison unsignedUserOp.maxFeePerGas > overrideMaxFeePerGas correctly delays when onchain fees exceed the override.


213-215: LGTM! Improved error message formatting.

The multiline template literal formatting improves readability while maintaining the same error message content. The use of wrapError ensures consistent error handling.

Also applies to: 238-240, 356-358, 383-385


550-552: LGTM! Cleaner transaction sending code.

The single-line await expression is more concise while maintaining the same functionality.

@d4mr d4mr force-pushed the pb/gas-fee-ceiling branch from 95791db to 49fb6f4 Compare July 4, 2025 07:29
Comment on lines +311 to +315
const estimatedCost =
unsignedUserOp.maxFeePerGas *
(unsignedUserOp.callGasLimit +
unsignedUserOp.preVerificationGas +
unsignedUserOp.verificationGasLimit);
Copy link
Contributor

Choose a reason for hiding this comment

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

do we do this elsewhere? might be useful to abstract into some helper and explain this formula

Copy link
Contributor Author

Choose a reason for hiding this comment

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

don't do it anywhere else, if/when we do I'll extract it out

@d4mr d4mr force-pushed the pb/gas-fee-ceiling branch from 49fb6f4 to f1e09f4 Compare July 4, 2025 08:58
@d4mr d4mr merged commit 067d5da into main Jul 4, 2025
8 checks passed
@d4mr d4mr deleted the pb/gas-fee-ceiling branch July 4, 2025 09:00
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