Skip to content

fix(apt): opt in to dynamic gas estimation - #9701

Draft
ralph-bitgo[bot] wants to merge 1 commit into
masterfrom
fix/cecho-2022-aptos-gas
Draft

fix(apt): opt in to dynamic gas estimation#9701
ralph-bitgo[bot] wants to merge 1 commit into
masterfrom
fix/cecho-2022-aptos-gas

Conversation

@ralph-bitgo

@ralph-bitgo ralph-bitgo Bot commented Sep 9, 2026

Copy link
Copy Markdown

Why

Aptos validators reject transactions whose max gas amount is below the chain minimum (MAX_GAS_UNITS_BELOW_MIN_TRANSACTION_GAS_UNITS). The pinned SDK default is too low for some broadcasts, while a simulation request is not appropriate for every existing build because it adds network latency and can fail for offline or newly-created accounts.

What changed

  • retain a validator-safe 20,000 max gas fallback for every Aptos transaction type, including delegation
  • add an explicit setDynamicGasEstimation() opt-in on Aptos transaction builders
  • build opted-in transactions with 200,000 gas, simulate through the pinned Aptos SDK 1.33.1 REST API, then rebuild with ceil(gas_used * 1.2) (never below 20,000)
  • preserve explicit gasData() values and fall back safely when simulation fails

Tests

  • deterministic builder-level tests use a stubbed createAptos seam and verify flag-off one-build/no-simulation, high-limit simulation and buffered rebuild, rejection fallback, and explicit gas bypass
  • helper tests cover rounding, minimum clamp, and invalid results

Verification

  • Aptos SDK 1.33.1 declarations/source verified: aptos.transaction.simulate.simple({ transaction }) returns Promise<Array<UserTransactionResponse>>
  • git diff --check passed
  • Scoped runtime tests are blocked because this environment has neither Node.js nor Yarn (node: command not found, yarn: command not found).

Refs: CECHO-2022

@linear-code

linear-code Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

CECHO-2022

@ralph-bitgo
ralph-bitgo Bot force-pushed the fix/cecho-2022-aptos-gas branch 6 times, most recently from c0f7a5d to 5d8ee7f Compare September 9, 2026 20:57
Use Aptos SDK simulation with a conservative 200,000-unit limit, then rebuild with ceil(gas_used * 1.2) while retaining a 20,000-unit minimum fallback. Explicit gasData remains authoritative and simulation is opt-in to avoid adding a network dependency to existing builds.

Refs: CECHO-2022
Session-Id: 9c40532a-e51d-4a1e-a703-ccd15303c96b
Task-Id: e62c1d9a-6785-4fac-a98b-400668b68cd6
@ralph-bitgo
ralph-bitgo Bot force-pushed the fix/cecho-2022-aptos-gas branch 2 times, most recently from ab3d158 to 42f087b Compare September 9, 2026 20:57
@ralph-bitgo ralph-bitgo Bot changed the title fix(apt): use validator-safe max gas amount fix(apt): opt in to dynamic gas estimation Sep 9, 2026
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

⚠️ Unit tests are failing on Node 26.x (Current release line, non-blocking). This is not an LTS version yet, so it does not block merge, but it signals an incompatibility to fix before Node 26.x becomes LTS.

View run

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.

1 participant