Skip to content

Commit

Permalink
Update iterator gas pricing model
Browse files Browse the repository at this point in the history
  • Loading branch information
cwgoes committed May 15, 2018
1 parent ef1923f commit 9dfccb1
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions store/gaskvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// nolint
const (
HasCost = 10
ReadCostFlat = 10
ReadCostPerByte = 1
WriteCostFlat = 10
WriteCostPerByte = 10
KeyCostFlat = 5
ValueCostFlat = 10
ValueCostPerByte = 1
)

// gasKVStore applies gas tracking to an underlying kvstore
Expand Down Expand Up @@ -118,28 +122,23 @@ func (g *gasIterator) Valid() bool {
return g.parent.Valid()
}

/*
TODO
Not quite sure what to charge for here. Depends on underlying retrieval model.
Could charge for Next(), and Key()/Value() are free, but want to have value-size-proportional gas.
*/

// Implements Iterator.
func (g *gasIterator) Next() {
g.parent.Next()
}

// Implements Iterator.
func (g *gasIterator) Key() (key []byte) {
return g.parent.Key()
g.gasMeter.ConsumeGas(KeyCostFlat, "KeyFlat")
key = g.parent.Key()
return key
}

// Implements Iterator.
func (g *gasIterator) Value() (value []byte) {
value = g.parent.Value()
g.gasMeter.ConsumeGas(ReadCostFlat, "ValueFlat")
g.gasMeter.ConsumeGas(ReadCostPerByte*sdk.Gas(len(value)), "ValuePerByte")
g.gasMeter.ConsumeGas(ValueCostFlat, "ValueFlat")
g.gasMeter.ConsumeGas(ValueCostPerByte*sdk.Gas(len(value)), "ValuePerByte")
return value
}

Expand Down

0 comments on commit 9dfccb1

Please sign in to comment.