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

merkledb -- fix hasValue in recordNodeDeleted #2779

Merged
merged 1 commit into from
Feb 29, 2024
Merged
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
10 changes: 6 additions & 4 deletions x/merkledb/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,11 +519,12 @@ func (v *view) remove(key Key) error {
return err
}

hadValue := nodeToDelete.hasValue()
nodeToDelete.setValue(maybe.Nothing[[]byte]())

// if the removed node has no children, the node can be removed from the trie
if len(nodeToDelete.children) == 0 {
if err := v.recordNodeDeleted(nodeToDelete); err != nil {
if err := v.recordNodeDeleted(nodeToDelete, hadValue); err != nil {
return err
}

Expand Down Expand Up @@ -563,7 +564,8 @@ func (v *view) compressNodePath(parent, n *node) error {
return nil
}

if err := v.recordNodeDeleted(n); err != nil {
// We know from above that [n] has no value.
if err := v.recordNodeDeleted(n, false /* hasValue */); err != nil {
return err
}

Expand Down Expand Up @@ -768,8 +770,8 @@ func (v *view) recordNodeChange(after *node) error {

// Records that the node associated with the given key has been deleted.
// Must not be called after [calculateNodeIDs] has returned.
func (v *view) recordNodeDeleted(after *node) error {
return v.recordKeyChange(after.key, nil, after.hasValue(), false /* newNode */)
func (v *view) recordNodeDeleted(after *node, hadValue bool) error {
return v.recordKeyChange(after.key, nil, hadValue, false /* newNode */)
}

// Records that the node associated with the given key has been changed.
Expand Down
Loading