diff --git a/utils/iterator.go b/utils/iterator.go index a2486df..d02cff7 100644 --- a/utils/iterator.go +++ b/utils/iterator.go @@ -138,10 +138,13 @@ func (it *symmDiffIterator) seek() { it.yieldFromA = false return case 0: - if it.a.Next(true) { + // if A and B have the same path and non-zero hash, they are identical and we can skip + // the whole subtree + noHash := it.a.Hash() == common.Hash{} + if it.a.Next(noHash) { it.count++ } - if it.b.Next(true) { + if it.b.Next(noHash) { it.count++ } } @@ -156,9 +159,6 @@ func (it *symmDiffIterator) Error() error { } func compareNodes(a, b trie.NodeIterator) int { - // if cmp := bytes.Compare(a.Path(), b.Path()); cmp != 0 { - // return cmp - // } if a.Leaf() && !b.Leaf() { return -1 } else if b.Leaf() && !a.Leaf() { diff --git a/utils/iterator_test.go b/utils/iterator_test.go index 3473c63..0ce0078 100644 --- a/utils/iterator_test.go +++ b/utils/iterator_test.go @@ -50,7 +50,7 @@ func TestSymmetricDifferenceIterator(t *testing.T) { for di.Next(true) { t.Errorf("iterator should not yield any elements") } - assert.Equal(t, 4, *count) + assert.Equal(t, 2, *count) trieb := trie.NewEmpty(db) di, count = utils.NewSymmetricDifferenceIterator(triea.NodeIterator([]byte("food")), trieb.NodeIterator(nil))