Skip to content
Open
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
37 changes: 37 additions & 0 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -1845,3 +1845,40 @@ func (n *LeafNode) serializeLeafWithUncompressedCommitments(cBytes, c1Bytes, c2B

return result
}

// HashNodeFromInternal hashed all the internal nodes under this node, exclude itself
func (n *InternalNode) HashNodeFromInternal() {
for i, child := range n.children {
switch childNode := child.(type) {
case *LeafNode:
n.children[i] = HashedNode{}
case *InternalNode:
childNode.HashNodeFromInternal()
n.children[i] = HashedNode{}
}
}
}

// GetInternalNode returns the internal node at the path key, if it exists.
func (n *InternalNode) GetInternalNode(path []byte, flushDepth byte) (VerkleNode, error) {
curNode := n

for i := byte(0); i < flushDepth; i++ {
nchild := offset2key(path, curNode.depth)
switch child := curNode.children[nchild].(type) {
case UnknownNode:
return nil, errMissingNodeInStateless
case Empty:
return nil, nil
case HashedNode:
return nil, fmt.Errorf("encounter hashedNode on path")
case *LeafNode:
return nil, nil
case *InternalNode:
curNode = child
default:
return nil, errUnknownNodeType
}
}
return curNode, nil
}