Skip to content

Commit

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

local sei integration
  • Loading branch information
codchen authored and udpatil committed Apr 19, 2024
1 parent e8a949d commit 1da5407
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,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
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 @@ -197,6 +197,10 @@ func (store *Store) iterator(start, end []byte, ascending bool) types.Iterator {
return NewCacheMergeIterator(parent, cache, ascending, store.storeKey, store.eventManager)
}

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 @@ -253,6 +253,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 1da5407

Please sign in to comment.