call onleaf in verkle commit (#45)

This commit is contained in:
Guillaume Ballet 2022-01-03 16:27:18 +01:00 committed by GitHub
parent 99ebf767b9
commit f215cc0791
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -118,6 +118,16 @@ func (trie *VerkleTrie) Commit(onleaf LeafCallback) (common.Hash, int, error) {
flush := make(chan verkle.VerkleNode)
go func() {
trie.root.(*verkle.InternalNode).Flush(func(n verkle.VerkleNode) {
if onleaf != nil {
if leaf, isLeaf := n.(*verkle.LeafNode); isLeaf {
for i := 0; i < verkle.NodeWidth; i++ {
if leaf.Value(i) != nil {
comm := n.ComputeCommitment().Bytes()
onleaf(nil, nil, leaf.Value(i), common.BytesToHash(comm[:]))
}
}
}
}
flush <- n
})
close(flush)
@ -135,7 +145,6 @@ func (trie *VerkleTrie) Commit(onleaf LeafCallback) (common.Hash, int, error) {
}
}
// XXX onleaf hasn't been called
return trie.Hash(), commitCount, nil
}