chore: provide a better out-of-gas error UX
fixes https://github.com/gnolang/gno/issues/3704
This PR is a proposed solution to issue #3704. It focuses only on improving the “out of gas” error, whereas PR #4451 also aims to improve the UX to help users avoid running out of gas.
Changes
- Simulation now uses the consensus Block.MaxGas as the cap (ignores tx gas-wanted), falling back to infinite only when maxGas is unset. That means you can estimate full usage up to that cap; if the tx needs more than maxGas, simulation will still OOG at that ceiling (with the “hit consensus maxGas” hint).
- The simulate OOG special case still marks an error when gasUsed > gasWanted so you see the failure even though the meter is high.
- OOG logs in running tx show “(until panic)” to make it clear gasUsed stops at the panic point.
Before
gnokey maketx call -pkgpath "gno.land/r/demo/counter" -func "Increment" -broadcast -gas-wanted=105000 -gas-fee=500ugnot test1
Enter password.
TX HASH:
INFO:
--= Error =--
Data: out of gas error
Msg Traces:
0 gno/tm2/pkg/errors/errors.go:103 - deliver transaction failed: log:out of gas, gasWanted: 105000, gasUsed: 110998 location: GetObjectPerByte
--= /Error =--
GAS USED is the gas used until the panic during the simulation stage.
Now
gnokey maketx call -pkgpath "gno.land/r/demo/counter" -func "Increment" -broadcast -gas-wanted=105000 -gas-fee=500ugnot test1
Enter password.
GAS WANTED: 105000
GAS USED: 227390
HEIGHT: 0
STORAGE DELTA: 5 bytes
STORAGE FEE: 500ugnot
TOTAL TX COST: 1000ugnot
EVENTS: [{"bytes_delta":5,"fee_delta":{"denom":"ugnot","amount":500},"pkg_path":"gno.land/r/demo/counter"}]
INFO:
TX HASH:
--= Error =--
Data: out of gas error
Msg Traces:
0 gno/tm2/pkg/errors/errors.go:103 - deliver transaction failed: log:out of gas during simulation; gasWanted: 105000, gasUsed: 227390
--= /Error =--
GAS USED is the total gas used of the transaction, now calculate during the simulation stage.
gnokey maketx call -pkgpath "gno.land/r/demo/counter" -func "Increment" -broadcast -gas-wanted=105000 -gas-fee=500ugnot -simulate skip test1
Enter password.
GAS WANTED: 105000
GAS USED: 110998
HEIGHT: 3
EVENTS: []
INFO:
TX HASH: doB/H4EvsPgIVllZM7JxQtEwNcjOzQ0HSBgUZn0yMuc=
--= Error =--
Data: out of gas error
Msg Traces:
0 gno/tm2/pkg/errors/errors.go:103 - deliver transaction failed: log:out of gas, gasWanted: 105000, gasUsed: 110998 (until panic) location: GetObjectPerByte
--= /Error =--
Message updated: GAS USED is the gas used UNTIL the panic (no simulation).
gnokey maketx call -pkgpath "gno.land/r/demo/counter" -func "Increment" -broadcast -gas-wanted=100 -gas-fee=500ugnot -simulate skip test1
Enter password.
--= Error =--
Data: out of gas error
Msg Traces:
0 gno/tm2/pkg/errors/errors.go:103 - check transaction failed: log:--= Error =--
Data: std.OutOfGasError{abciError:std.abciError{}}
Msg Traces:
0 gno/tm2/pkg/std/errors.go:108 - out of gas in location: txSize; gasWanted: 100, gasUsed: 2370 (until panic)
Stack Trace:
0 gno/tm2/pkg/errors/errors.go:93
1 gno/tm2/pkg/std/errors.go:108
2 gno/tm2/pkg/sdk/auth/ante.go:84
...
Message updated: GAS USED is the gas used UNTIL the panic (before running the tx).
🛠 PR Checks Summary
All Automated Checks passed. ✅
Manual Checks (for Reviewers):
- [ ] IGNORE the bot requirements for this PR (force green CI check)
- [ ] The pull request description provides enough details
Read More
🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.
✅ Automated Checks (for Contributors):
🟢 Maintainers must be able to edit this pull request (more info) 🟢 Pending initial approval by a review team member, or review from tech-staff
☑️ Contributor Actions:
- Fix any issues flagged by automated checks.
- Follow the Contributor Checklist to ensure your PR is ready for review.
- Add new tests, or document why they are unnecessary.
- Provide clear examples/screenshots, if necessary.
- Update documentation, if required.
- Ensure no breaking changes, or include
BREAKING CHANGEnotes. - Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
- Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)
If
🟢 Condition met └── 🟢 And ├── 🟢 The base branch matches this pattern: ^master$ └── 🟢 The pull request was created from a fork (head branch repo: D4ryl00/gno)Then
🟢 Requirement satisfied └── 🟢 Maintainer can modify this pull requestPending initial approval by a review team member, or review from tech-staff
If
🟢 Condition met └── 🟢 And ├── 🟢 The base branch matches this pattern: ^master$ └── 🟢 Not (🔴 Pull request author is a member of the team: tech-staff)Then
🟢 Requirement satisfied └── 🟢 If ├── 🟢 Condition │ └── 🟢 Or │ ├── 🟢 User jefft0 already reviewed PR 4951 with state APPROVED │ ├── 🔴 At least 1 user(s) of the team tech-staff reviewed pull request │ └── 🔴 This pull request is a draft └── 🟢 Then └── 🟢 Not (🔴 This label is applied to pull request: review/triage-pending)Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)
If
🟢 Condition met └── 🟢 On every pull requestCan be checked by
- Any user with comment edit permission
The pull request description provides enough details
If
🟢 Condition met └── 🟢 And ├── 🟢 Not (🔴 Pull request author is a member of the team: core-contributors) └── 🟢 Not (🔴 Pull request author is user: dependabot[bot])Can be checked by
- team core-contributors
Codecov Report
:x: Patch coverage is 97.61905% with 1 line in your changes missing coverage. Please review.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| tm2/pkg/crypto/keys/client/maketx.go | 90.00% | 1 Missing :warning: |
:loudspeaker: Thoughts on this report? Let us know!