Skip to content

feat(transaction-controller): clamp gas estimate fallback to per-chain maxGasLimit#9191

Open
dan437 wants to merge 2 commits into
mainfrom
feat/gas-estimate-fallback-max-gas-limit
Open

feat(transaction-controller): clamp gas estimate fallback to per-chain maxGasLimit#9191
dan437 wants to merge 2 commits into
mainfrom
feat/gas-estimate-fallback-max-gas-limit

Conversation

@dan437

@dan437 dan437 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Description

When gas estimation fails, estimateGas falls back to a percentage of the latest block gas limit (default 35%). On chains with a high block gas limit but a lower per-transaction RPC gas cap, that overshoots the cap: on Polygon, 35% of the ~140M block limit is ~49M, but the node caps a single tx at ~33.5M (2^25) and rejects it with transaction gas limit too high. This surfaced as consistent failures for Predict / MetaMask Pay deposit-and-order batches submitted on the direct (non-relay) path.

This adds an optional maxGasLimit to the gasEstimateFallback feature-flag config (per-chain or default). The fixed/percentage-derived fallback is clamped to maxGasLimit, so it can never exceed the gas limit the RPC will accept — on any submission path. It is opt-in via remote config (e.g. set perChainConfig["0x89"].maxGasLimit = 33554432); behaviour is unchanged when unset.

Changelog

  • @metamask/transaction-controller: Added optional maxGasLimit to the gasEstimateFallback feature-flag config, clamping the gas estimate fallback to a chain's per-transaction gas cap.

Manual testing steps

  1. Set confirmations_transactions.gasEstimateFallback.perChainConfig["0x89"].maxGasLimit = 33554432.
  2. Trigger a transaction on Polygon whose gas estimation fails (so the fallback path runs).
  3. Confirm the resolved fallback is clamped to 33554432 instead of ~49M, and the tx is no longer rejected with "transaction gas limit too high".

Checklist

  • Unit tests added (gas.test.ts, feature-flags.test.ts)
  • Changelog entry (added in a follow-up commit referencing this PR)

Note

Low Risk
Opt-in remote config with unchanged behavior when unset; limited to gas fallback on estimation failure, with solid unit test coverage.

Overview
Adds an optional maxGasLimit on the remote gasEstimateFallback feature-flag config (per-chain or default). getGasEstimateFallback now surfaces it, with chain-specific values overriding the default.

When gas estimation fails, estimateGas still uses the fixed or block-percentage fallback, but clamps that value to maxGasLimit when configured so oversized fallbacks (e.g. ~49M from 35% of Polygon’s block limit vs a ~33.5M per-tx RPC cap) are not submitted. If maxGasLimit is unset, behavior is unchanged.

Unit tests cover flag resolution and clamp/no-clamp paths; the changelog documents the addition.

Reviewed by Cursor Bugbot for commit 50d5e21. Bugbot is set up for automated code reviews on this repo. Configure here.

…n maxGasLimit

When gas estimation fails, the fallback is a percentage of the block gas
limit (default 35%). On chains with a high block gas limit but a lower
per-transaction RPC cap (e.g. Polygon: ~140M block limit, ~33.5M per-tx
cap), the percentage-derived fallback (~49M) overshoots the cap and the
node rejects the transaction with "transaction gas limit too high".

Add an optional maxGasLimit to the gasEstimateFallback feature flag
config (per-chain or default) that clamps the fixed/percentage-derived
fallback so it can never exceed the gas limit the RPC will accept.
@dan437 dan437 requested a review from a team as a code owner June 18, 2026 13:10
@dan437 dan437 temporarily deployed to default-branch June 18, 2026 13:10 — with GitHub Actions Inactive
@dan437 dan437 requested a review from a team as a code owner June 18, 2026 13:12
@matthewwalsh0 matthewwalsh0 requested a review from jpuri June 19, 2026 11:01
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.

2 participants