Skip to content

Commit

Permalink
Fix iterator from t8n (#434)
Browse files Browse the repository at this point in the history
* various verkle iterator fixes

* remove unused nodeToDBKey
  • Loading branch information
gballet authored May 7, 2024
1 parent 7cae5e3 commit 8f8e320
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
5 changes: 0 additions & 5 deletions trie/verkle.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,6 @@ func (trie *VerkleTrie) Hash() common.Hash {
return trie.root.Commit().Bytes()
}

func nodeToDBKey(n verkle.VerkleNode) []byte {
ret := n.Commitment().Bytes()
return ret[:]
}

// Commit writes all nodes to the trie's memory database, tracking the internal
// and external (for account tries) references.
func (trie *VerkleTrie) Commit(_ bool) (common.Hash, *trienode.NodeSet, error) {
Expand Down
10 changes: 5 additions & 5 deletions trie/verkle_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

type verkleNodeIteratorState struct {
Node verkle.VerkleNode
Index int
Index int // points to _next_ value
}

type verkleNodeIterator struct {
Expand Down Expand Up @@ -97,9 +97,9 @@ func (it *verkleNodeIterator) Next(descend bool) bool {
it.current = it.stack[len(it.stack)-1].Node
it.stack[len(it.stack)-1].Index++
return it.Next(descend)
case *verkle.HashedNode:
case verkle.HashedNode:
// resolve the node
data, err := it.trie.db.diskdb.Get(nodeToDBKey(node))
data, err := it.trie.FlatdbNodeResolver(it.Path())
if err != nil {
panic(err)
}
Expand All @@ -112,7 +112,7 @@ func (it *verkleNodeIterator) Next(descend bool) bool {
it.stack[len(it.stack)-1].Node = it.current
parent := &it.stack[len(it.stack)-2]
parent.Node.(*verkle.InternalNode).SetChild(parent.Index, it.current)
return true
return it.Next(true)
default:
panic("invalid node type")
}
Expand Down Expand Up @@ -147,7 +147,7 @@ func (it *verkleNodeIterator) Path() []byte {
var path []byte
for i, state := range it.stack {
// skip the last byte
if i <= len(it.stack)-1 {
if i >= len(it.stack)-1 {
break
}
path = append(path, byte(state.Index))
Expand Down

0 comments on commit 8f8e320

Please sign in to comment.