Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(store/v2): gaskv store #18240

Merged
merged 29 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
cb7d4b0
init commit
alexanderbez Oct 24, 2023
befd5df
updates
alexanderbez Oct 24, 2023
ef597c6
Merge branch 'main' into bez/18225-store-v2-gaskv-store
alexanderbez Oct 24, 2023
512f8d6
updates
alexanderbez Oct 24, 2023
c4d76ae
updates
alexanderbez Oct 24, 2023
cc268b5
updates
alexanderbez Oct 24, 2023
c2c4e2c
updates
alexanderbez Oct 24, 2023
dba50b4
updates
alexanderbez Oct 24, 2023
c891c47
updates
alexanderbez Oct 24, 2023
b5b6315
updates
alexanderbez Oct 24, 2023
700a7b0
Merge branch 'main' into bez/18225-store-v2-gaskv-store
alexanderbez Oct 24, 2023
b94a997
updates
alexanderbez Oct 24, 2023
cd02d13
updates
alexanderbez Oct 24, 2023
ffe6b61
updates
alexanderbez Oct 24, 2023
7ce1c4c
updates
alexanderbez Oct 25, 2023
04f25b0
updates
alexanderbez Oct 25, 2023
373b643
updates
alexanderbez Oct 25, 2023
3ab1ddc
updates
alexanderbez Oct 25, 2023
1b6c905
updates
alexanderbez Oct 25, 2023
2238f44
Merge branch 'main' into bez/18225-store-v2-gaskv-store
alexanderbez Oct 25, 2023
af99893
lint++
alexanderbez Oct 25, 2023
78bf4e6
Merge branch 'bez/18225-store-v2-gaskv-store' of github.com:cosmos/co…
alexanderbez Oct 25, 2023
f32b30f
Merge branch 'main' into bez/18225-store-v2-gaskv-store
alexanderbez Oct 25, 2023
0145d72
lint++
alexanderbez Oct 25, 2023
0c4f0bd
Merge branch 'bez/18225-store-v2-gaskv-store' of github.com:cosmos/co…
alexanderbez Oct 25, 2023
1b3beef
lint++
alexanderbez Oct 25, 2023
a9be8ea
lint++
alexanderbez Oct 26, 2023
68f8156
Merge branch 'main' into bez/18225-store-v2-gaskv-store
alexanderbez Oct 26, 2023
88d7d0a
godoc++
alexanderbez Oct 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions store/gas.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package store

import "fmt"

// Gas defines type alias of uint64 for gas consumption. Gas is measured by the
// SDK for store operations such as Get and Set calls. In addition, callers have
// the ability to explicitly charge gas for costly operations such as signature
// verification.
type Gas uint64

// Gas consumption descriptors.
const (
GasIterNextCostFlatDesc = "IterNextFlat"
GasValuePerByteDesc = "ValuePerByte"
GasWritePerByteDesc = "WritePerByte"
GasReadPerByteDesc = "ReadPerByte"
GasWriteCostFlatDesc = "WriteFlat"
GasReadCostFlatDesc = "ReadFlat"
GasHasDesc = "Has"
GasDeleteDesc = "Delete"
)

type (
// ErrorNegativeGasConsumed defines an error thrown when the amount of gas refunded
// results in a negative gas consumed amount.
ErrorNegativeGasConsumed struct {
Descriptor string
}

// ErrorOutOfGas defines an error thrown when an action results in out of gas.
ErrorOutOfGas struct {
Descriptor string
}

// ErrorGasOverflow defines an error thrown when an action results gas consumption
// unsigned integer overflow.
ErrorGasOverflow struct {
Descriptor string
}
)
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved

// GasMeter defines an interface for gas consumption tracking.
type GasMeter interface {
GasConsumed() Gas
GasConsumedToLimit() Gas
GasRemaining() Gas
Limit() Gas
ConsumeGas(amount Gas, descriptor string)
RefundGas(amount Gas, descriptor string)
IsPastLimit() bool
IsOutOfGas() bool

fmt.Stringer
}

// GasConfig defines gas cost for each operation on a KVStore.
type GasConfig struct {
HasCost Gas
DeleteCost Gas
ReadCostFlat Gas
ReadCostPerByte Gas
WriteCostFlat Gas
WriteCostPerByte Gas
IterNextCostFlat Gas
}
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved

// DefaultGasConfig returns a default GasConfig for gas metering.
//
// Note, these values are essentially arbitrary. They are not based on any specific
// computation or measurements, but mainly reflect relative costs, i.e. writes
// should be more expensive than reads.
func DefaultGasConfig() GasConfig {
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
return GasConfig{
HasCost: 1000,
DeleteCost: 1000,
ReadCostFlat: 1000,
ReadCostPerByte: 3,
WriteCostFlat: 2000,
WriteCostPerByte: 30,
IterNextCostFlat: 30,
}
}
49 changes: 49 additions & 0 deletions store/gaskv/store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package gaskv

import "cosmossdk.io/store/v2"

var _ store.BranchedKVStore = (*Store)(nil)

type Store struct {
parent store.KVStore
}

func (s *Store) GetStoreKey() string {
return s.parent.GetStoreKey()
}

func (s *Store) GetStoreType() store.StoreType {
return store.StoreTypeGas
}

func (s *Store) Get(key []byte) []byte {
panic("not implemented!")
}

func (s *Store) Has(key []byte) bool {
panic("not implemented!")
}

func (s *Store) Set(key, value []byte) {
panic("not implemented!")
}

func (s *Store) Delete(key []byte) {
panic("not implemented!")
}

func (s *Store) GetChangeset() *store.Changeset {
panic("not implemented!")
}

func (s *Store) Reset() error {
panic("not implemented!")
}

func (s *Store) Iterator(start, end []byte) store.Iterator {
panic("not implemented!")
}

func (s *Store) ReverseIterator(start, end []byte) store.Iterator {
panic("not implemented!")
}
6 changes: 2 additions & 4 deletions store/memkv/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import (
"cosmossdk.io/store/v2"
)

const (
// degree defines the approximate number of items and children per B-tree node.
degree = 32
)
// degree defines the approximate number of items and children per B-tree node.
const degree = 32

var _ store.KVStore = (*Store)(nil)

Expand Down
1 change: 1 addition & 0 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const (
StoreTypeBranch StoreType = iota
StoreTypeTrace
StoreTypeMem
StoreTypeGas
)

// RootStore defines an abstraction layer containing a State Storage (SS) engine
Expand Down
Loading