diff --git a/CHANGELOG.md b/CHANGELOG.md index ea382ddef..d8f703aad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ - [#726](https://github.com/cosmos/iavl/pull/726) Make `KVPair` and `ChangeSet` serializable with protobuf. - [#795](https://github.com/cosmos/iavl/pull/795) Use gogofaster buf plugin. +### Bug Fixes + +- [#801](https://github.com/cosmos/iavl/pull/801) Fix rootKey empty check by len equals 0. + ## 0.20.0 (March 14, 2023) - [#622](https://github.com/cosmos/iavl/pull/622) `export/newExporter()` and `ImmutableTree.Export()` returns error for nil arguements diff --git a/iterator.go b/iterator.go index e2f128216..63a7d0b60 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 0eefed302..dff2a05a9 100644 --- a/iterator_test.go +++ b/iterator_test.go @@ -330,3 +330,13 @@ func setupUnsavedFastIterator(t *testing.T, config *iteratorTestConfig) (dbm.Ite itr := NewUnsavedFastIterator(config.startIterate, config.endIterate, config.ascending, tree.ndb, tree.unsavedFastNodeAdditions, tree.unsavedFastNodeRemovals) return itr, mirror } + +func TestNodeIterator_WithEmptyRoot(t *testing.T) { + itr, err := NewNodeIterator(nil, newNodeDB(dbm.NewMemDB(), 0, nil)) + require.NoError(t, err) + require.False(t, itr.Valid()) + + itr, err = NewNodeIterator([]byte{}, newNodeDB(dbm.NewMemDB(), 0, nil)) + require.NoError(t, err) + require.False(t, itr.Valid()) +}