From 9c9eee25d83c92da6eb70c1eab7abf25467d415a Mon Sep 17 00:00:00 2001 From: mmsqe Date: Tue, 8 Aug 2023 00:34:15 +0800 Subject: [PATCH 1/2] fix: rootKey empty check by len equals 0 (#801) Co-authored-by: Marko (cherry picked from commit 06f5be141653e56e130aac8082d0484e0039f2f5) # Conflicts: # CHANGELOG.md --- CHANGELOG.md | 5 +++++ iterator.go | 2 +- iterator_test.go | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d25acee6..a386c6174 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,11 @@ ### Bug Fixes - [#773](https://github.com/cosmos/iavl/pull/773) Fix memory leak in `Import`. +<<<<<<< HEAD +======= +- [#795](https://github.com/cosmos/iavl/pull/795) Fix plugin used for buf generate. +- [#801](https://github.com/cosmos/iavl/pull/801) Fix rootKey empty check by len equals 0. +>>>>>>> 06f5be1 (fix: rootKey empty check by len equals 0 (#801)) ### Breaking Changes diff --git a/iterator.go b/iterator.go index 205519931..131a2bdda 100644 --- a/iterator.go +++ b/iterator.go @@ -269,7 +269,7 @@ type NodeIterator struct { // NewNodeIterator returns a new NodeIterator to traverse the tree of the root node. func NewNodeIterator(rootKey []byte, ndb *nodeDB) (*NodeIterator, error) { - if rootKey == nil { + if len(rootKey) == 0 { return &NodeIterator{ nodesToVisit: []*Node{}, ndb: ndb, diff --git a/iterator_test.go b/iterator_test.go index 8d27a7232..f7a7ed0f4 100644 --- a/iterator_test.go +++ b/iterator_test.go @@ -366,4 +366,8 @@ func TestNodeIterator_WithEmptyRoot(t *testing.T) { itr, err := NewNodeIterator(nil, newNodeDB(dbm.NewMemDB(), 0, nil, log.NewNopLogger())) require.NoError(t, err) require.False(t, itr.Valid()) + + itr, err = NewNodeIterator([]byte{}, newNodeDB(dbm.NewMemDB(), 0, nil, log.NewNopLogger())) + require.NoError(t, err) + require.False(t, itr.Valid()) } From 2453df94ebe02123aba1e959638c2b45c19e2545 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 10 Aug 2023 10:23:37 +0200 Subject: [PATCH 2/2] fix changelog --- CHANGELOG.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a386c6174..45fb4c725 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,18 +13,12 @@ ### Bug Fixes - [#773](https://github.com/cosmos/iavl/pull/773) Fix memory leak in `Import`. -<<<<<<< HEAD -======= -- [#795](https://github.com/cosmos/iavl/pull/795) Fix plugin used for buf generate. - [#801](https://github.com/cosmos/iavl/pull/801) Fix rootKey empty check by len equals 0. ->>>>>>> 06f5be1 (fix: rootKey empty check by len equals 0 (#801)) ### Breaking Changes - [#735](https://github.com/cosmos/iavl/pull/735) Pass logger to `NodeDB`, `MutableTree` and `ImmutableTree` - - [#646](https://github.com/cosmos/iavl/pull/646) Remove the `orphans` from the storage - - [#777](https://github.com/cosmos/iavl/pull/777) Don't return errors from ImmutableTree.Hash, NewImmutableTree, NewImmutableTreeWIthOpts ### API Changes