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

binarytree: create binarytree package #3857

Merged
merged 50 commits into from
Feb 20, 2025
Merged

Conversation

gabrocheleau
Copy link
Contributor

This PR creates a new binarytree package for implementing binary trees as described in https://eips.ethereum.org/EIPS/eip-7864

Copy link

codecov bot commented Jan 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.64%. Comparing base (60ce8e7) to head (86b1d45).
Report is 1 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
block 76.87% <ø> (ø)
blockchain 85.69% <ø> (ø)
client 66.30% <ø> (ø)
common 90.72% <ø> (ø)
devp2p 76.21% <ø> (-0.07%) ⬇️
ethash 81.04% <ø> (ø)
evm 69.66% <ø> (ø)
genesis 99.84% <ø> (ø)
mpt 60.19% <ø> (+0.23%) ⬆️
rlp 69.70% <ø> (ø)
statemanager 70.47% <ø> (ø)
tx 80.52% <ø> (ø)
util 85.51% <100.00%> (+0.34%) ⬆️
vm 57.81% <ø> (ø)
wallet 83.78% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Copy link
Contributor

@acolytec3 acolytec3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some early feedback. I need to look at the put logic some more. We might want to think about going to the recursive model they use in the python implementation.

this.DEBUG && this.debug(`Deleting stem node for stem: ${bytesToHex(stem)}`, ['put'])
putStack.push([this.merkelize(stemNode), null])
} else {
return // nothing to delete
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check if it's a deletion first and only then handle creating or updating the stem node.

@acolytec3 acolytec3 force-pushed the feat/binarytree-package branch from f6b0b73 to e0b215f Compare February 18, 2025 22:40
@acolytec3 acolytec3 force-pushed the feat/binarytree-package branch from ba8bd14 to a7d9f0d Compare February 19, 2025 19:45
@acolytec3 acolytec3 marked this pull request as ready for review February 19, 2025 20:02
protected _root: Uint8Array

protected DEBUG: boolean
protected _debug: Debugger = debug('binarytree:#')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the "#" on the end here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the new logging convention we use for the base topic for any package (so mpt:#, evm:#, etc). There was some screwiness with doing DEBUG=ethjs,evm* as opposed to DEBUG=ethjs,evm:* where subtopics weren't getting logged or something.

return value !== null
} catch (error: any) {
if (error.message === 'Missing node in DB') {
return equalsBytes(root, this.EMPTY_TREE_ROOT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the idea that checkRoot(this.EMPTY_TREE_ROOT) should return true? as written it will not, because db.get won't throw an error looking for it, but also wont find anything there, so this will return false

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually not sure here. I think this might have been copied over from another trie class since I don't know if we use this anywhere. We can definitely fix though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure and this is untested behavior, but I think we have a similar setup here than in the MPT, where we are putting and retrieving null from the DB even though it's not typed as such.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyhow let's keep that change, we can revisit this whole handling once we have more clarity on how to handle deleted values etc.

ScottyPoi
ScottyPoi previously approved these changes Feb 20, 2025
Copy link
Contributor

@ScottyPoi ScottyPoi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few tests to boost the coverage.
This looks great! Giving my approval 👍
I gather that there are unanswered questions around how tree.del should work?
And, of course, the proof methods and whatnot need to be filled in. Are those defined yet in the spec, or is that still being worked on?

Copy link
Contributor Author

@gabrocheleau gabrocheleau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm!

@acolytec3 acolytec3 merged commit a3e7361 into master Feb 20, 2025
40 of 41 checks passed
@acolytec3 acolytec3 deleted the feat/binarytree-package branch February 20, 2025 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants