-
Notifications
You must be signed in to change notification settings - Fork 756
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 trie.del
#3486
Add trie.del
#3486
Conversation
packages/verkle/src/verkleTree.ts
Outdated
@@ -250,11 +250,28 @@ export class VerkleTree { | |||
) | |||
} | |||
} else { | |||
if (equalsBytes(value, createDeletedLeafValue())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this not throw an error instead of silently returning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that I've re-read the spec, I'm not sure what the expected behavior is. If it's just writing 0
to the trie, then this behavior is actually invalid and we should just let it create a new leaf node and write what I'm calling the deleted leaf value
here. Will ask kev
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My instinct here is that we should actually just create a new leaf node and write zeroes to it. There is no "deletion" in verkle tries so writing zeroes to a leaf value is the same as "deleting" a value in the trie. Will update this section of code accordingly (i.e. just remove this special handling and allow `trie.del to write zeroes)
@@ -211,7 +211,7 @@ describe('Verkle tree', () => { | |||
assert.deepEqual(val2, hexToBytes(values[2]), 'confirm values[2] can be retrieved from trie') | |||
}) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also add a test for the expected behavior when attempting to delete a value that does not exist? Left a related comment in the other file (i.e. should this throw or return?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, cool to see so much progress on the verkle tree front lately!
Left some comments, can be merged once addressed.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more. |
packages/verkle/src/verkleTree.ts
Outdated
['DEL'] | ||
) | ||
leafNode.setValue(suffix, VerkleLeafNodeValue.Deleted) | ||
} | ||
leafNode.setValue(suffix, value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't line 268 overwriting what has been done in line 266 within the if block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. Will address in the next commit.
One general Q. We currently return |
Good point. We should returns an array of zeroes for the "deleted" case. This comes back to the underlying point that there really is no concept of "deleted" in a verkle trie. There's just untouched, and then touched (with maybe a special flag for zeroes). For the moment, I think it makes the most sense to update |
Makes sense! Thanks for addressing. |
Adds
trie.del
as a simple extension oftrie.put
trie.del
function which wrapstrie.put
trie.put
for the deleted leaf valuefindPath
returns no leaf node), return early (since you can't delete a value in a leaf node that doesn't exist)VerkleLeafNodeValues.Deleted
when inserting the value into the leaf node.