Skip to content

Commit b35e4ff

Browse files
mmsqetac0turtle
andauthored
fix: rootKey empty check by len equals 0 (backport: cosmos#801) (cosmos#808)
Co-authored-by: Marko <marbar3778@yahoo.com>
1 parent 633397c commit b35e4ff

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
- [#726](https://github.com/cosmos/iavl/pull/726) Make `KVPair` and `ChangeSet` serializable with protobuf.
99
- [#795](https://github.com/cosmos/iavl/pull/795) Use gogofaster buf plugin.
1010

11+
### Bug Fixes
12+
13+
- [#801](https://github.com/cosmos/iavl/pull/801) Fix rootKey empty check by len equals 0.
14+
1115
## 0.20.0 (March 14, 2023)
1216

1317
- [#622](https://github.com/cosmos/iavl/pull/622) `export/newExporter()` and `ImmutableTree.Export()` returns error for nil arguements

iterator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ type NodeIterator struct {
269269

270270
// NewNodeIterator returns a new NodeIterator to traverse the tree of the root node.
271271
func NewNodeIterator(rootKey []byte, ndb *nodeDB) (*NodeIterator, error) {
272-
if rootKey == nil {
272+
if len(rootKey) == 0 {
273273
return &NodeIterator{
274274
nodesToVisit: []*Node{},
275275
ndb: ndb,

iterator_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,13 @@ func setupUnsavedFastIterator(t *testing.T, config *iteratorTestConfig) (dbm.Ite
330330
itr := NewUnsavedFastIterator(config.startIterate, config.endIterate, config.ascending, tree.ndb, tree.unsavedFastNodeAdditions, tree.unsavedFastNodeRemovals)
331331
return itr, mirror
332332
}
333+
334+
func TestNodeIterator_WithEmptyRoot(t *testing.T) {
335+
itr, err := NewNodeIterator(nil, newNodeDB(dbm.NewMemDB(), 0, nil))
336+
require.NoError(t, err)
337+
require.False(t, itr.Valid())
338+
339+
itr, err = NewNodeIterator([]byte{}, newNodeDB(dbm.NewMemDB(), 0, nil))
340+
require.NoError(t, err)
341+
require.False(t, itr.Valid())
342+
}

0 commit comments

Comments
 (0)