feat(store): add new api LatestVersion (#22305)

This commit is contained in:
cool-developer 2024-10-21 09:09:58 -04:00 committed by GitHub
parent 6e59ad0dee
commit 97d37ae243
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 27 additions and 2 deletions

View File

@ -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.

View File

@ -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.

View File

@ -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 {

View File

@ -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 }

View File

@ -36,6 +36,10 @@ func (cdsa commitDBStoreAdapter) LastCommitID() types.CommitID {
}
}
func (cdsa commitDBStoreAdapter) LatestVersion() int64 {
return -1
}
func (cdsa commitDBStoreAdapter) WorkingHash() []byte {
return commithash
}

View File

@ -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.

View File

@ -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{}
}

View File

@ -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