Skip to content

Commit

Permalink
fix(core/gas): Add consumed API for GasMeter (#21443)
Browse files Browse the repository at this point in the history
  • Loading branch information
sontrinh16 authored Aug 29, 2024
1 parent 33c463e commit 41a9af7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions core/gas/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Meter interface {
Consume(amount Gas, descriptor string) error
Refund(amount Gas, descriptor string) error
Remaining() Gas
Consumed() Gas
Limit() Gas
}

Expand Down
14 changes: 14 additions & 0 deletions core/testing/gas/service_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions runtime/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func (cgm CoreGasmeter) Consume(amount gas.Gas, descriptor string) error {
return nil
}

func (cgm CoreGasmeter) Consumed() gas.Gas {
return cgm.gm.GasConsumed()
}

func (cgm CoreGasmeter) Refund(amount gas.Gas, descriptor string) error {
cgm.gm.RefundGas(amount, descriptor)
return nil
Expand All @@ -55,14 +59,14 @@ type SDKGasMeter struct {
}

func (gm SDKGasMeter) GasConsumed() storetypes.Gas {
return gm.gm.Remaining()
return gm.gm.Consumed()
}

func (gm SDKGasMeter) GasConsumedToLimit() storetypes.Gas {
if gm.IsPastLimit() {
return gm.gm.Limit()
}
return gm.gm.Remaining()
return gm.gm.Consumed()
}

func (gm SDKGasMeter) GasRemaining() storetypes.Gas {
Expand Down

0 comments on commit 41a9af7

Please sign in to comment.