From 0b6f1b68c802d2e3851a86c8a8805f7e1a33ef46 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 28 Jun 2024 15:02:16 +0200 Subject: [PATCH 1/2] build(deps): Bump amannn/action-semantic-pull-request from 5.5.2 to 5.5.3 (#958) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/lint-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-pr.yml b/.github/workflows/lint-pr.yml index 80fa625af..05d5cc6ef 100644 --- a/.github/workflows/lint-pr.yml +++ b/.github/workflows/lint-pr.yml @@ -17,6 +17,6 @@ jobs: statuses: write # for amannn/action-semantic-pull-request to mark status of analyzed PR runs-on: ubuntu-latest steps: - - uses: amannn/action-semantic-pull-request@v5.5.2 + - uses: amannn/action-semantic-pull-request@v5.5.3 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From a514883e2f4101b2c8009dfdc421abbb5f324dcd Mon Sep 17 00:00:00 2001 From: cool-developer <51834436+cool-develope@users.noreply.github.com> Date: Tue, 9 Jul 2024 08:07:57 -0400 Subject: [PATCH 2/2] chore: new `GetLatestVersion` api (#961) --- CHANGELOG.md | 4 ++++ mutable_tree.go | 5 +++++ mutable_tree_test.go | 6 +++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5adc9e76..2a4e297e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +### Improvements + +- [#961](https://github.com/cosmos/iavl/pull/961) Add new `GetLatestVersion` API to get the latest version. + ## v1.2.0 May 13, 2024 ### Improvements diff --git a/mutable_tree.go b/mutable_tree.go index e71253852..350e39b93 100644 --- a/mutable_tree.go +++ b/mutable_tree.go @@ -73,6 +73,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() diff --git a/mutable_tree_test.go b/mutable_tree_test.go index 6e58843ff..1f28c572d 100644 --- a/mutable_tree_test.go +++ b/mutable_tree_test.go @@ -347,11 +347,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) {