Skip to content

fix(examples): derive the automation task's max gas and fee cap from a simulation - #46

Open
isaacdoidge wants to merge 1 commit into
masterfrom
fix/automation-max-gas
Open

isaacdoidge wants to merge 1 commit into
masterfrom
fix/automation-max-gas

Conversation

@isaacdoidge

Copy link
Copy Markdown
Collaborator

What

examples/automation.py and the node-backed automation tests registered a task running 0x1::supra_account::transfer(0x1, 1) with a max gas of 9 and a fee cap of 1 SUPRA. The first execution of that transfer uses about 500 gas units, so the automated transaction ran out of gas. Neither the example nor the tests waited for an automated transaction, so nothing noticed.

  • examples/automation.py has a new helper, automation_task_limits(supra_client, sender, automated_function). It simulates the automated function as a user transaction from the task's owner and returns:
    • max gas: twice the simulated gas_used. The automated transaction runs in a later block, on state that may differ.
    • fee cap for the epoch: twice the registry's estimate for that max gas, read from 0x1::automation_registry::estimate_automation_fee. The registry refuses a cap below its estimate, and the estimate rises with the gas other tasks have committed.
  • register_test_automation_task in tests/unit/test_supra_client.py uses the same helper. Tests already import from examples (test_faucet_funder.py).
  • The register_automation_task docstring says what happens when an automated transaction needs more than the max gas, and that the registry refuses a fee cap below its estimate.

No change to SDK behaviour.

Checks

On fresh localnets of supra_node_v12.0.0.rc7 (Devnet's release) and supra_node_v11.7.2 (Mainnet's and Testnet's), gas price 100000:

Node Simulated gas_used Max gas Fee cap (quants) Automated gas_used
v12.0.0-rc7 543 1086 2,606,400 543, 8, 8
v11.7.2 508 1016 2,438,400 508, 9, 9
  • A task registered by the helper produced 3 automated transactions with status Success on each node.
  • examples/automation.py completed on both.
  • SUPRA_RPC_URL=<localnet> make test-unit: 397 tests, OK, 0 skipped, on both.
  • make fmt-check, make lint, make typecheck, make test-unit (offline), make test-spec and make build pass.

🤖 Generated with Claude Code

…a simulation

The automation example and the node-backed tests registered a task running
0x1::supra_account::transfer(0x1, 1) with a max gas of 9 and a fee cap of 1 SUPRA.
A SUPRA transfer uses about 500 gas units on its first execution, so the automated
transaction ran out of gas, and nothing in the example or the tests waited for an
automated transaction to notice.

`automation_task_limits` in examples/automation.py simulates the automated function
as a user transaction from the task's owner and registers the task with twice the gas
used. The fee cap is twice the registry's estimate for that max gas
(`0x1::automation_registry::estimate_automation_fee`), since the estimate depends on
the gas other tasks have committed. The node-backed tests use the same helper. The
docstring of `register_automation_task` describes both limits.

Measured on localnets: the simulated transfer used 543 gas units on
supra_node_v12.0.0.rc7 and 508 on supra_node_v11.7.2. A task registered with the
resulting max gas (1086 and 1016) produced automated transactions with status
Success on both: the first used 543 and 508 units, the following ones 8 and 9.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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