Skip to content

Commit

Permalink
Improve ToWasmVMGas/FromWasmVMGas code level documentation (#1564) (#…
Browse files Browse the repository at this point in the history
…1569)

(cherry picked from commit 881d6a7)

Co-authored-by: Simon Warta <[email protected]>
  • Loading branch information
mergify[bot] and webmaster128 authored Aug 24, 2023
1 parent 21ec15a commit aae393e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions x/wasm/keeper/gas_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,13 @@ type GasRegister interface {
ReplyCosts(pinned bool, reply wasmvmtypes.Reply) sdk.Gas
// EventCosts costs to persist an event
EventCosts(attrs []wasmvmtypes.EventAttribute, events wasmvmtypes.Events) sdk.Gas
// ToWasmVMGas converts from sdk gas to wasmvm gas
// ToWasmVMGas converts from Cosmos SDK gas units to [CosmWasm gas] (aka. wasmvm gas)
//
// [CosmWasm gas]: https://github.com/CosmWasm/cosmwasm/blob/v1.3.1/docs/GAS.md
ToWasmVMGas(source sdk.Gas) uint64
// FromWasmVMGas converts from wasmvm gas to sdk gas
// FromWasmVMGas converts from [CosmWasm gas] (aka. wasmvm gas) to Cosmos SDK gas units
//
// [CosmWasm gas]: https://github.com/CosmWasm/cosmwasm/blob/v1.3.1/docs/GAS.md
FromWasmVMGas(source uint64) sdk.Gas
}

Expand Down Expand Up @@ -237,7 +241,9 @@ func calcWithFreeTier(storedBytes uint64, freeTier uint64) (uint64, uint64) {
return storedBytes, 0
}

// ToWasmVMGas convert to wasmVM contract runtime gas unit
// ToWasmVMGas converts from Cosmos SDK gas units to [CosmWasm gas] (aka. wasmvm gas)
//
// [CosmWasm gas]: https://github.com/CosmWasm/cosmwasm/blob/v1.3.1/docs/GAS.md
func (g WasmGasRegister) ToWasmVMGas(source storetypes.Gas) uint64 {
x := source * g.c.GasMultiplier
if x < source {
Expand All @@ -246,7 +252,9 @@ func (g WasmGasRegister) ToWasmVMGas(source storetypes.Gas) uint64 {
return x
}

// FromWasmVMGas converts to SDK gas unit
// FromWasmVMGas converts from [CosmWasm gas] (aka. wasmvm gas) to Cosmos SDK gas units
//
// [CosmWasm gas]: https://github.com/CosmWasm/cosmwasm/blob/v1.3.1/docs/GAS.md
func (g WasmGasRegister) FromWasmVMGas(source uint64) sdk.Gas {
return source / g.c.GasMultiplier
}

0 comments on commit aae393e

Please sign in to comment.