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

Add leaf group "erasure" function #449

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
47 changes: 47 additions & 0 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,53 @@ func (n *InternalNode) Delete(key []byte, resolver NodeResolverFn) (bool, error)
}
}

// EraseStem overwrites values with 0s, which is the (currently specced) way of deleting
// leaves in verkle trees. It will, however, not create anything if it finds that the
// stem isn't present in the tree.
func (n *InternalNode) EraseStem(key []byte, resolver NodeResolverFn) error {
nChild := offset2key(key, n.depth)
switch child := n.children[nChild].(type) {
case Empty:
// don't create a 0 substree if it's missing from the tree
case HashedNode:
if resolver == nil {
return errDeleteHash
}
payload, err := resolver(key[:n.depth+1])
if err != nil {
return err
}
// deserialize the payload and set it as the child
c, err := ParseNode(payload, n.depth+1)
if err != nil {
return err
}
n.children[nChild] = c
return n.EraseStem(key, resolver)
case *LeafNode:
// if the stem are different, then there's nothing to
// do as no new leaf should be created.
if !bytes.Equal(key[:31], child.stem) {
return nil
}
// overwrite all non-zero values
for i := range child.values {
if child.values[i] != nil {
child.values[i] = zero32[:]
}
}
case *InternalNode:
n.cowChild(nChild)
err := child.EraseStem(key, resolver)
if err != nil {
return err
}
default:
return errUnknownNodeType
}
return nil
}

// DeleteAtStem delete a full stem. Unlike Delete, it will error out if the stem that is to
// be deleted does not exist in the tree, because it's meant to be used by rollback code,
// that should only delete things that exist.
Expand Down
Loading