Skip to content

Commit

Permalink
feat(store): add new api LatestVersion (#22305)
Browse files Browse the repository at this point in the history
  • Loading branch information
cool-develope authored Oct 21, 2024
1 parent 6e59ad0 commit 97d37ae
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func (app *BaseApp) LastCommitID() storetypes.CommitID {

// LastBlockHeight returns the last committed block height.
func (app *BaseApp) LastBlockHeight() int64 {
return app.cms.LastCommitID().Version
return app.cms.LatestVersion()
}

// ChainID returns the chainID of the app.
Expand Down
4 changes: 4 additions & 0 deletions store/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

### Improvements

* (store) [#22305](https://github.com/cosmos/cosmos-sdk/pull/22305) Add `LatestVersion` to the `Committer` interface to get the latest version of the store.

### Bug Fixes

* (store) [#20425](https://github.com/cosmos/cosmos-sdk/pull/20425) Fix nil pointer panic when query historical state where a new store don't exist.
Expand Down
5 changes: 5 additions & 0 deletions store/iavl/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ func (st *Store) LastCommitID() types.CommitID {
}
}

// LatestVersion implements Committer.
func (st *Store) LatestVersion() int64 {
return st.tree.Version()
}

// PausePruning implements CommitKVStore interface.
func (st *Store) PausePruning(pause bool) {
if pause {
Expand Down
2 changes: 2 additions & 0 deletions store/mem/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@ func (s *Store) GetPruning() pruningtypes.PruningOptions {

func (s Store) LastCommitID() (id types.CommitID) { return }

func (s Store) LatestVersion() (version int64) { return }

func (s Store) WorkingHash() (hash []byte) { return }
4 changes: 4 additions & 0 deletions store/rootmulti/dbadapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func (cdsa commitDBStoreAdapter) LastCommitID() types.CommitID {
}
}

func (cdsa commitDBStoreAdapter) LatestVersion() int64 {
return -1
}

func (cdsa commitDBStoreAdapter) WorkingHash() []byte {
return commithash
}
Expand Down
6 changes: 5 additions & 1 deletion store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,11 @@ func (rs *Store) PopStateCache() []*types.StoreKVPair {

// LatestVersion returns the latest version in the store
func (rs *Store) LatestVersion() int64 {
return rs.LastCommitID().Version
if rs.lastCommitInfo == nil {
return GetLatestVersion(rs.db)
}

return rs.lastCommitInfo.Version
}

// LastCommitID implements Committer/CommitStore.
Expand Down
5 changes: 5 additions & 0 deletions store/transient/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func (ts *Store) LastCommitID() types.CommitID {
return types.CommitID{}
}

// LatestVersion implements Committer
func (ts *Store) LatestVersion() int64 {
return 0
}

func (ts *Store) WorkingHash() []byte {
return []byte{}
}
Expand Down
1 change: 1 addition & 0 deletions store/types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Store interface {
type Committer interface {
Commit() CommitID
LastCommitID() CommitID
LatestVersion() int64

// WorkingHash returns the hash of the KVStore's state before commit.
WorkingHash() []byte
Expand Down

0 comments on commit 97d37ae

Please sign in to comment.