Skip to content

Commit

Permalink
Add public interface for multistore to return earlist version (#525)
Browse files Browse the repository at this point in the history
## Describe your changes and provide context
This PR add a public interface for Multistore to return the earlist
available version for state store (historical state). For seidb, if only
SC is enabled, then it will assume only latest state is available.

## Testing performed to validate your change
  • Loading branch information
yzang2019 authored Jul 18, 2024
1 parent 1fa43a5 commit b0473e9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
5 changes: 5 additions & 0 deletions server/mock/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,8 @@ func (ms multiStore) SetKVStores(handler func(key store.StoreKey, s sdk.KVStore)
func (ms multiStore) StoreKeys() []sdk.StoreKey {
panic("not implemented")
}

func (ms multiStore) GetEarliestVersion() int64 {
//TODO implement me
panic("not implemented")
}
4 changes: 4 additions & 0 deletions store/cachemulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,7 @@ func (cms Store) Close() {
closer.Close()
}
}

func (cms Store) GetEarliestVersion() int64 {
panic("not implemented")
}
8 changes: 8 additions & 0 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type Store struct {
pruneHeights []int64
initialVersion int64
archivalVersion int64
earliestVersion int64
orphanOpts *iavltree.Options

traceWriter io.Writer
Expand Down Expand Up @@ -526,6 +527,9 @@ func (rs *Store) PruneStores(clearStorePruningHeights bool, pruningHeights []int
}
}
}
if len(pruningHeights) > 0 {
rs.earliestVersion = pruningHeights[len(pruningHeights)-1]
}

if clearStorePruningHeights {
rs.pruneHeights = make([]int64, 0)
Expand Down Expand Up @@ -1217,3 +1221,7 @@ func (rs *Store) StoreKeys() []types.StoreKey {
}
return res
}

func (rs *Store) GetEarliestVersion() int64 {
return rs.earliestVersion
}
3 changes: 3 additions & 0 deletions store/types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ type MultiStore interface {
GetStore(StoreKey) Store
GetKVStore(StoreKey) KVStore

// Get the earliest available version for state store
GetEarliestVersion() int64

// TracingEnabled returns if tracing is enabled for the MultiStore.
TracingEnabled() bool

Expand Down
19 changes: 16 additions & 3 deletions storev2/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -854,10 +854,23 @@ func (*Store) SetKVStores(handler func(key types.StoreKey, s types.KVStore) type
}

// StoreKeys implements types.CommitMultiStore.
func (s *Store) StoreKeys() []types.StoreKey {
res := make([]types.StoreKey, len(s.storeKeys))
for _, sk := range s.storeKeys {
func (rs *Store) StoreKeys() []types.StoreKey {
res := make([]types.StoreKey, len(rs.storeKeys))
for _, sk := range rs.storeKeys {
res = append(res, sk)
}
return res
}

// GetEarliestVersion return earliest version for SS or latestVersion if only SC is enabled
func (rs *Store) GetEarliestVersion() int64 {
latestVersion := rs.lastCommitInfo.Version
if rs.ssStore != nil {
version, err := rs.ssStore.GetEarliestVersion()
if err != nil {
return latestVersion
}
return version
}
return latestVersion
}

0 comments on commit b0473e9

Please sign in to comment.