feat(store): add new api LatestVersion (#22305)
This commit is contained in:
parent
6e59ad0dee
commit
97d37ae243
@ -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.
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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 }
|
||||
|
||||
@ -36,6 +36,10 @@ func (cdsa commitDBStoreAdapter) LastCommitID() types.CommitID {
|
||||
}
|
||||
}
|
||||
|
||||
func (cdsa commitDBStoreAdapter) LatestVersion() int64 {
|
||||
return -1
|
||||
}
|
||||
|
||||
func (cdsa commitDBStoreAdapter) WorkingHash() []byte {
|
||||
return commithash
|
||||
}
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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{}
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user