Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rootKey empty check by len equals 0 (backport #801) #811

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,15 +268,20 @@
}

// 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,
}, nil
}

node, err := ndb.GetNode(root)

Check failure on line 284 in iterator.go

View workflow job for this annotation

GitHub Actions / Test

syntax error: non-declaration statement outside function body
if err != nil {
return nil, err
}
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 @@
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)
Loading