Skip to content

Commit

Permalink
fix: rootKey empty check by len equals 0 (backport #801) (#809)
Browse files Browse the repository at this point in the history
Co-authored-by: mmsqe <mavis@crypto.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
  • Loading branch information
3 people authored Aug 10, 2023
1 parent bcdaadf commit 78072ce
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
### Bug Fixes

- [#773](https://github.com/cosmos/iavl/pull/773) Fix memory leak in `Import`.
- [#801](https://github.com/cosmos/iavl/pull/801) Fix rootKey empty check by len equals 0.

### 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
Expand Down
2 changes: 1 addition & 1 deletion iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

0 comments on commit 78072ce

Please # to comment.