Skip to content

Commit

Permalink
Expose VersionExists (#400)
Browse files Browse the repository at this point in the history
## Describe your changes and provide context
Add an interface function `VersionExists` to store types

## Testing performed to validate your change
local sei integration
  • Loading branch information
codchen authored Jan 23, 2024
1 parent ddb04b9 commit def4c92
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 5 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ require (
github.com/regen-network/cosmos-proto v0.3.1
github.com/rs/zerolog v1.30.0
github.com/savaki/jq v0.0.0-20161209013833-0e6baecebbf8
github.com/sei-protocol/sei-db v0.0.22
github.com/sei-protocol/sei-db v0.0.27-0.20240123064153-d6dfa112e760
github.com/sei-protocol/sei-tm-db v0.0.5
github.com/spf13/cast v1.5.0
github.com/spf13/cobra v1.6.1
Expand Down Expand Up @@ -180,7 +180,7 @@ replace (
// TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.7.0
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.25
github.com/sei-protocol/sei-db => github.com/sei-protocol/sei-db v0.0.27-0.20240123064153-d6dfa112e760
// Latest goleveldb is broken, we have to stick to this version
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/tendermint/tendermint => github.com/sei-protocol/sei-tendermint v0.2.36-evm-multi-tx-per-account-2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -781,8 +781,8 @@ github.com/savaki/jq v0.0.0-20161209013833-0e6baecebbf8/go.mod h1:Nw/CCOXNyF5JDd
github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KRMzBtS3oedY=
github.com/sei-protocol/sei-db v0.0.25 h1:jC1ivcaNxSR7EmxqvxexqPpnN/G0vUTZNHZI+C9T8M8=
github.com/sei-protocol/sei-db v0.0.25/go.mod h1:F/ZKZA8HJPcUzSZPA8yt6pfwlGriJ4RDR4eHKSGLStI=
github.com/sei-protocol/sei-db v0.0.27-0.20240123064153-d6dfa112e760 h1:MiHIPwPH2Yo6LQQfINgFTofm+K1EqpQYmg8h5m/cFrs=
github.com/sei-protocol/sei-db v0.0.27-0.20240123064153-d6dfa112e760/go.mod h1:F/ZKZA8HJPcUzSZPA8yt6pfwlGriJ4RDR4eHKSGLStI=
github.com/sei-protocol/sei-iavl v0.1.9 h1:y4mVYftxLNRs6533zl7N0/Ch+CzRQc04JDfHolIxgBE=
github.com/sei-protocol/sei-iavl v0.1.9/go.mod h1:7PfkEVT5dcoQE+s/9KWdoXJ8VVVP1QpYYPLdxlkSXFk=
github.com/sei-protocol/sei-tendermint v0.2.36-evm-multi-tx-per-account-2 h1:XnJmqfmdcl/bRYla9leVWc2fOnWUZC93KaFmuSZr+lU=
Expand Down
4 changes: 4 additions & 0 deletions server/mock/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ func (kv kvStore) ReverseSubspaceIterator(prefix []byte) sdk.Iterator {
panic("not implemented")
}

func (kv kvStore) VersionExists(version int64) bool {
panic("not implemented")
}

func NewCommitMultiStore() sdk.CommitMultiStore {
return multiStore{kv: make(map[sdk.StoreKey]kvStore)}
}
Expand Down
4 changes: 4 additions & 0 deletions store/cachekv/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ func (store *Store) iterator(start, end []byte, ascending bool) types.Iterator {
return NewCacheMergeIterator(parent, cache, ascending, store.storeKey)
}

func (store *Store) VersionExists(version int64) bool {
return store.parent.VersionExists(version)
}

func findStartIndex(strL []string, startQ string) int {
// Modified binary search to find the very first element in >=startQ.
if len(strL) == 0 {
Expand Down
4 changes: 4 additions & 0 deletions store/dbadapter/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,9 @@ func (dsa Store) CacheWrapWithListeners(storeKey types.StoreKey, listeners []typ
return cachekv.NewStore(listenkv.NewStore(dsa, storeKey, listeners), storeKey, types.DefaultCacheSizeLimit)
}

func (dsa Store) VersionExists(version int64) bool {
panic("no versioning for dbadater")
}

// dbm.DB implements KVStore so we can CacheKVStore it.
var _ types.KVStore = Store{}
4 changes: 4 additions & 0 deletions store/gaskv/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ func (gs *Store) iterator(start, end []byte, ascending bool) types.Iterator {
return gi
}

func (gs *Store) VersionExists(version int64) bool {
return gs.parent.VersionExists(version)
}

type gasIterator struct {
gasMeter types.GasMeter
gasConfig types.GasConfig
Expand Down
4 changes: 4 additions & 0 deletions store/listenkv/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ func (s *Store) iterator(start, end []byte, ascending bool) types.Iterator {
return newTraceIterator(parent, s.listeners)
}

func (s *Store) VersionExists(version int64) bool {
return s.parent.VersionExists(version)
}

type listenIterator struct {
parent types.Iterator
listeners []types.WriteListener
Expand Down
4 changes: 4 additions & 0 deletions store/prefix/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ func (s Store) ReverseIterator(start, end []byte) types.Iterator {
return newPrefixIterator(s.prefix, start, end, iter)
}

func (s Store) VersionExists(version int64) bool {
return s.parent.VersionExists(version)
}

var _ types.Iterator = (*prefixIterator)(nil)

type prefixIterator struct {
Expand Down
4 changes: 4 additions & 0 deletions store/tracekv/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ func (tkv *Store) CacheWrapWithListeners(_ types.StoreKey, _ []types.WriteListen
panic("cannot CacheWrapWithListeners a TraceKVStore")
}

func (tkv *Store) VersionExists(version int64) bool {
return tkv.parent.VersionExists(version)
}

// writeOperation writes a KVStore operation to the underlying io.Writer as
// JSON-encoded data where the key/value pair is base64 encoded.
func writeOperation(w io.Writer, op operation, tc types.TraceContext, key, value []byte) {
Expand Down
2 changes: 2 additions & 0 deletions store/types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ type KVStore interface {
ReverseIterator(start, end []byte) Iterator

GetWorkingHash() ([]byte, error)

VersionExists(version int64) bool
}

// Iterator is an alias db's Iterator for convenience.
Expand Down
5 changes: 5 additions & 0 deletions storev2/commitment/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,8 @@ func (st *Store) Query(req abci.RequestQuery) (res abci.ResponseQuery) {

return res
}

func (st *Store) VersionExists(version int64) bool {
// one version per SC tree
return version == st.tree.Version()
}
11 changes: 10 additions & 1 deletion storev2/state/store.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package state

import (
"cosmossdk.io/errors"
"fmt"
"io"

"cosmossdk.io/errors"

"github.com/cosmos/cosmos-sdk/store/cachekv"
"github.com/cosmos/cosmos-sdk/store/listenkv"
"github.com/cosmos/cosmos-sdk/store/tracekv"
Expand Down Expand Up @@ -125,3 +126,11 @@ func (st *Store) Query(req abci.RequestQuery) (res abci.ResponseQuery) {

return res
}

func (st *Store) VersionExists(version int64) bool {
earliest, err := st.store.GetEarliestVersion()
if err != nil {
panic(err)
}
return version >= earliest
}
6 changes: 6 additions & 0 deletions x/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type Keeper interface {
DelegateCoins(ctx sdk.Context, delegatorAddr, moduleAccAddr sdk.AccAddress, amt sdk.Coins) error
UndelegateCoins(ctx sdk.Context, moduleAccAddr, delegatorAddr sdk.AccAddress, amt sdk.Coins) error

GetStoreKey() sdk.StoreKey

types.QueryServer
}

Expand Down Expand Up @@ -677,6 +679,10 @@ func (k BaseKeeper) trackUndelegation(ctx sdk.Context, addr sdk.AccAddress, amt
return nil
}

func (k BaseKeeper) GetStoreKey() sdk.StoreKey {
return k.storeKey
}

// IterateTotalSupply iterates over the total supply calling the given cb (callback) function
// with the balance of each coin.
// The iteration stops if the callback returns true.
Expand Down

0 comments on commit def4c92

Please sign in to comment.