Fix iterator from t8n (#434)

* various verkle iterator fixes

* remove unused nodeToDBKey
This commit is contained in:
Guillaume Ballet 2024-05-07 13:29:05 +02:00
parent 8cbdd335ae
commit 5e02d05155
2 changed files with 5 additions and 10 deletions

View file

@ -231,11 +231,6 @@ func (trie *VerkleTrie) Hash() common.Hash {
return trie.root.Commit().Bytes() 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 // Commit writes all nodes to the trie's memory database, tracking the internal
// and external (for account tries) references. // and external (for account tries) references.
func (trie *VerkleTrie) Commit(_ bool) (common.Hash, *trienode.NodeSet, error) { func (trie *VerkleTrie) Commit(_ bool) (common.Hash, *trienode.NodeSet, error) {

View file

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