Skip to content

Commit

Permalink
Add NoConsumptionInfiniteGasMeter (#308)
Browse files Browse the repository at this point in the history
## Describe your changes and provide context
In some use cases we want infinite gas meter to always return 0 for gas
consumed

## Testing performed to validate your change
  • Loading branch information
codchen authored Jul 12, 2023
1 parent 6ecb719 commit 9dda0a0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions store/types/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,31 @@ func (g *infiniteGasMeter) String() string {
return fmt.Sprintf("InfiniteGasMeter:\n consumed: %d", g.consumed)
}

type noConsumptionInfiniteGasMeter struct {
infiniteGasMeter
}

func NewNoConsumptionInfiniteGasMeter() GasMeter {
return &noConsumptionInfiniteGasMeter{
infiniteGasMeter: infiniteGasMeter{
consumed: 0,
lock: &sync.Mutex{},
},
}
}

func (g *noConsumptionInfiniteGasMeter) GasConsumed() Gas {
return 0
}

func (g *noConsumptionInfiniteGasMeter) GasConsumedToLimit() Gas {
return 0
}

func (g *noConsumptionInfiniteGasMeter) ConsumeGas(amount Gas, descriptor string) {}

func (g *noConsumptionInfiniteGasMeter) RefundGas(amount Gas, descriptor string) {}

// GasConfig defines gas cost for each operation on KVStores
type GasConfig struct {
HasCost Gas
Expand Down

0 comments on commit 9dda0a0

Please sign in to comment.