Skip to content

Commit

Permalink
fix: rootKey empty check by len equals 0 (#801)
Browse files Browse the repository at this point in the history
Co-authored-by: Marko <marbar3778@yahoo.com>
(cherry picked from commit 06f5be1)

# Conflicts:
#	CHANGELOG.md
#	iterator.go
#	iterator_test.go
  • Loading branch information
mmsqe authored and mergify[bot] committed Aug 10, 2023
1 parent a9ce71a commit bddaff9
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
44 changes: 44 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,48 @@

## Unreleased

<<<<<<< HEAD
=======
### Improvements

- [#703](https://github.com/cosmos/iavl/pull/703) New APIs `NewCompressExporter`/`NewCompressImporter` to support more compact snapshot format.
- [#729](https://github.com/cosmos/iavl/pull/729) Speedup Genesis writes for IAVL, by writing in small batches.
- [#726](https://github.com/cosmos/iavl/pull/726) Make `KVPair` and `ChangeSet` serializable with protobuf.
- [#718](https://github.com/cosmos/iavl/pull/718) Fix `traverseNodes` unexpected behaviour
- [#770](https://github.com/cosmos/iavl/pull/770) Add `WorkingVersion()int64` API.

### Bug Fixes

- [#773](https://github.com/cosmos/iavl/pull/773) Fix memory leak in `Import`.
- [#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.

### 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

- [#646](https://github.com/cosmos/iavl/pull/646) Remove the `DeleteVersion`, `DeleteVersions`, `DeleteVersionsRange` and introduce a new endpoint of `DeleteVersionsTo` instead
- [#695](https://github.com/cosmos/iavl/pull/695) Add API `SaveChangeSet` to save the changeset as a new version.

## 0.20.0 (March 14, 2023)

### Breaking Changes

- [#586](https://github.com/cosmos/iavl/pull/586) Remove the `RangeProof` and refactor the ics23_proof to use the internal methods.

## 0.19.5 (Februrary 23, 2022)

### Breaking Changes

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

- [#640](https://github.com/cosmos/iavl/pull/640) commit `NodeDB` batch in `LoadVersionForOverwriting`.
- [#636](https://github.com/cosmos/iavl/pull/636) Speed up rollback method: `LoadVersionForOverwriting`.
>>>>>>> 06f5be1 (fix: rootKey empty check by len equals 0 (#801))
- [#654](https://github.com/cosmos/iavl/pull/654) Add API `TraverseStateChanges` to extract state changes from iavl versions.
5 changes: 5 additions & 0 deletions iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,13 @@ type NodeIterator struct {
}

// NewNodeIterator returns a new NodeIterator to traverse the tree of the root node.
<<<<<<< HEAD

Check failure on line 271 in iterator.go

View workflow job for this annotation

GitHub Actions / golangci-lint

expected declaration, found '<<' (typecheck)

Check failure on line 271 in iterator.go

View workflow job for this annotation

GitHub Actions / Test

syntax error: non-declaration statement outside function body
func NewNodeIterator(root []byte, ndb *nodeDB) (*NodeIterator, error) {
if len(root) == 0 {
=======

Check failure on line 274 in iterator.go

View workflow job for this annotation

GitHub Actions / Test

syntax error: unexpected ==, expecting }
func NewNodeIterator(rootKey []byte, ndb *nodeDB) (*NodeIterator, error) {
if len(rootKey) == 0 {
>>>>>>> 06f5be1 (fix: rootKey empty check by len equals 0 (#801))

Check failure on line 277 in iterator.go

View workflow job for this annotation

GitHub Actions / golangci-lint

illegal character U+0023 '#' (typecheck)

Check failure on line 277 in iterator.go

View workflow job for this annotation

GitHub Actions / Test

syntax error: unexpected >>, expecting }

Check failure on line 277 in iterator.go

View workflow job for this annotation

GitHub Actions / Test

invalid character U+0023 '#'
return &NodeIterator{
nodesToVisit: []*Node{},
ndb: ndb,
Expand Down
49 changes: 49 additions & 0 deletions iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,52 @@ 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
}
<<<<<<< HEAD

Check failure on line 333 in iterator_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

expected declaration, found '<<' (typecheck)

Check failure on line 333 in iterator_test.go

View workflow job for this annotation

GitHub Actions / Test

expected declaration, found '<<'
=======

func TestNodeIterator_Success(t *testing.T) {
tree, mirror := getRandomizedTreeAndMirror(t)

_, _, err := tree.SaveVersion()
require.NoError(t, err)

randomizeTreeAndMirror(t, tree, mirror)

_, _, err = tree.SaveVersion()
require.NoError(t, err)

// check if the iterating count is same with the entire node count of the tree
itr, err := NewNodeIterator(tree.root.GetKey(), tree.ndb)
require.NoError(t, err)
nodeCount := 0
for ; itr.Valid(); itr.Next(false) {
nodeCount++
}
require.Equal(t, int64(nodeCount), tree.Size()*2-1)

// check if the skipped node count is right
itr, err = NewNodeIterator(tree.root.GetKey(), tree.ndb)
require.NoError(t, err)
updateCount := 0
skipCount := 0
for itr.Valid() {
node := itr.GetNode()
updateCount++
if node.nodeKey.version < tree.Version() {
skipCount += int(node.size*2 - 2) // the size of the subtree without the root
}
itr.Next(node.nodeKey.version < tree.Version())
}
require.Equal(t, nodeCount, updateCount+skipCount)
}

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())
}
>>>>>>> 06f5be1 (fix: rootKey empty check by len equals 0 (#801))

Check failure on line 381 in iterator_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

illegal character U+0023 '#' (typecheck)

0 comments on commit bddaff9

Please sign in to comment.