Skip to content

Commit

Permalink
chore: new GetLatestVersion api (backport #961) (#962)
Browse files Browse the repository at this point in the history
Co-authored-by: cool-developer <51834436+cool-develope@users.noreply.github.com>
  • Loading branch information
mergify[bot] and cool-develope authored Jul 26, 2024
1 parent e69b1cd commit 8ecbd9f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog


### Improvements

- [#961](https://github.com/cosmos/iavl/pull/961) Add new `GetLatestVersion` API to get the latest version.
- [#965](https://github.com/cosmos/iavl/pull/965) Use expected interface for expected IAVL `Logger`.
- [#970](https://github.com/cosmos/iavl/pull/970) Close the pruning process when the nodeDB is closed.

Expand Down
5 changes: 5 additions & 0 deletions mutable_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ func (tree *MutableTree) IsEmpty() bool {
return tree.ImmutableTree.Size() == 0
}

// GetLatestVersion returns the latest version of the tree.
func (tree *MutableTree) GetLatestVersion() (int64, error) {
return tree.ndb.getLatestVersion()
}

// VersionExists returns whether or not a version exists.
func (tree *MutableTree) VersionExists(version int64) bool {
legacyLatestVersion, err := tree.ndb.getLegacyLatestVersion()
Expand Down
6 changes: 5 additions & 1 deletion mutable_tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,15 @@ func prepareTree(t *testing.T) *MutableTree {
return newTree
}

func TestMutableTree_VersionExists(t *testing.T) {
func TestMutableTree_Version(t *testing.T) {
tree := prepareTree(t)
require.True(t, tree.VersionExists(1))
require.True(t, tree.VersionExists(2))
require.False(t, tree.VersionExists(3))

v, err := tree.GetLatestVersion()
require.NoError(t, err)
require.Equal(t, int64(2), v)
}

func checkGetVersioned(t *testing.T, tree *MutableTree, version int64, key, value []byte) {
Expand Down

0 comments on commit 8ecbd9f

Please sign in to comment.