Unify gas depletion handling
- Dominant language
- Go
- Stars
- 416
- Forks
- 538
- PR merge metrics
- No merged PRs in 30d
Description
We have two types of gas:
* `WasmD Gas` - the unit that is used in `WasmD`,
* `WasmVM Gas` - currently `1 Cosmos Gas` = `140_000 WasmVM Gas`
The test case `TestLimitRecursiveQueryGas` runs the following scenario:
* Translate `WasmD Gas` to `WasmVM Gas` and set the limit for the Query call,
* Run **WasmVM** to perform and finish a recursive Query call, return the amount of `WasmVM gas` used,
* Translate the returned `WasmVM Gas` back to `WasmD Gas` and subtract it from the gas limit assigned for the whole operation,
* Check in **WasmD** if there is no gas left - panic in such case.
When we updated **WasmVM** to `v2.2` the gas fee calculations in **WasmVM** has changed. We encountered the following scenario:
* Translate `WasmD Gas` to `WasmVM Gas` and set the limit for the Query call,
* Run **WasmVM** to perform and finish a recursive Query call, return the amount of `WasmVM Gas` used. This step returned `VmError::GasDepletion` error.
In the second case if we artificially increase the gas limit set for the Query operation of `1 WasmD Gas` or `116_370 WasmVM Gas`, the test behave the same way as in the first case i.e. the **WasmVM** finishes the operation and **WasmD** panics when theres `0` gas left.
**WasmD** panics when it has `0 WasmD Gas` left, regardless of the fact that there was enough gas to run the whole procedure for **WasmVM**. In the first case **WasmVM** finished and returned `23_630 WasmVM Gas`. After translation **WasmD** is left with `23_630 WasmVM Gas / 140_000 = 0.214285714 WasmD Gas`. This is rounded down to `0`, that's why we get panic from **WasmD** and not the error from **WasmVM**.
It seems to me that getting `VmError::GasDepletion` should be the only valid way to raise the `RanOutOfGas` panic in **WasmD**.
Contributor guide
Research direction
Start with the TestLimitRecursiveQueryGas test and trace the WasmD/WasmVM gas translation and error path described in the issue. Compare behavior with WasmVM v2.2 and verify that only VmError::GasDepletion results in WasmD's RanOutOfGas panic, while remaining gas is handled consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, wasm
- Domain
- backend, blockchain
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100