Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add functionality of producing hashedNode #438

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
}