-
Notifications
You must be signed in to change notification settings - Fork 11
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/stored nodes minimal #65
Feature/stored nodes minimal #65
Conversation
Signed-off-by: Thomas Zamojski <thomas.zamojski@quadratic-labs.com>
Signed-off-by: Thomas Zamojski <thomas.zamojski@quadratic-labs.com>
Stored nodes have encoded values with at least uncompressed commitments and children hashes. All (little-endian) bytes are also tail truncated to compress their representation. Furthermore, null nodes are represented by empty bytes (0x80 in RLP encoding). The commit also includes a major refactoring of location attribute for nodes. Previously, leaf location was their full key, which was a little awkward. Now, node location is truly its location in the trie, no matter what kind of node it is. Among other things, this means that we store a StemNode's depth along its stem, so we can retrieve its location. Coming up is the possibility to store commitments in compressed form, which would save a lot of space (50% on commitments). Signed-off-by: Thomas Zamojski <thomas.zamojski@quadratic-labs.com>
|
Signed-off-by: Thomas Zamojski <thomas.zamojski@quadratic-labs.com>
src/main/java/org/hyperledger/besu/ethereum/trie/verkle/node/BranchNode.java
Outdated
Show resolved
Hide resolved
if (scalars.get(i) == Bytes32.ZERO) { | ||
children.add(new NullNode<V>()); | ||
} else { | ||
children.add(new StoredNode<V>(this, nextLoc, scalars.get(i))); |
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.
why not just doing
Bytes childrenLocationPrefix = Bytes.concatenate(location,Bytes.of(0));
children.add(new StoredNode(this, Bytes.concatenate(childrenLocationPrefix,Bytes.of(i)), scalars.get(i)));
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.
I think this was a somewhat lame attempt to avoid concatenates, as you mentioned it takes a lot of the execution time.
But I am pretty sure this is not better, and less readable. So reverting is good.
for (int i = 0; i < nChild; i++) { | ||
children.add(new StoredNode<>(this, Bytes.concatenate(stem, Bytes.of(i)))); | ||
nextBuffer.set(location.size(), Bytes.of(i)); | ||
Bytes nextLoc = nextBuffer.copy(); |
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.
same here, seems to be hard to understand like that
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.
same as above
src/main/java/org/hyperledger/besu/ethereum/trie/verkle/node/InternalNode.java
Show resolved
Hide resolved
* @param value A commitment value | ||
* @return The encoded commitment | ||
*/ | ||
public static Bytes encodeCommitment(Bytes 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.
why this two methods are static ?
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.
because they do not use any info from an instance, but are rather only utility methods for the class.
But I am not particularly attached to it, so if you think that some other way is better or more consistent with besu, no problem
src/main/java/org/hyperledger/besu/ethereum/trie/verkle/node/Node.java
Outdated
Show resolved
Hide resolved
src/main/java/org/hyperledger/besu/ethereum/trie/verkle/node/StoredNode.java
Show resolved
Hide resolved
src/test/java/org/hyperledger/besu/ethereum/trie/verkle/SimpleBatchedVerkleTrieTest.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Thomas Zamojski <thomas.zamojski@quadratic-labs.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
fix tests and spotless
src/main/java/org/hyperledger/besu/ethereum/trie/verkle/visitor/CommitVisitor.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Thomas Zamojski <thomas.zamojski@quadratic-labs.com>
Signed-off-by: Thomas Zamojski <thomas.zamojski@quadratic-labs.com>
Signed-off-by: Thomas Zamojski <thomas.zamojski@quadratic-labs.com>
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.
LGTM
This is a continuation of the previous PR #65 It appeared that the previous PR had some bugs, and meanwhile it was decided to add stem extensions into the DB in order to be able to get stemNodes by stem without requiring a nearest request. In this commit, InternalNodes include stem extensions into its encodedValues, useful to create the children Stored Nodes including their appropriate keys (location or stem). The key is then used to load the StoredNode. StoredNode are also separated into Internal and Stem Nodes as well to reflect this difference. --------- Signed-off-by: Thomas Zamojski <thomas.zamojski@quadratic-labs.com> Co-authored-by: Karim Taam <karim.t2am@gmail.com>
PR description
Storing Nodes' info with RLP encodings, list containing at least uncompressed commitments and children hashes.
All (little-endian) bytes are tail truncated to compress their representation.
Furthermore, null commitments/hashes are represented by empty bytes (0x80 in RLP encoding).
The commit also includes a major refactoring of location attribute for nodes.
Previously, leaf location was their full key, which was a little awkward.
Now, node location is truly its location in the trie, no matter what kind of node it is.
Among other things, this means that we store a StemNode's depth along its stem, so we can retrieve its location.
Fixed Issue(s)
Issue #60