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

Feature/stored nodes minimal #65

Merged
merged 10 commits into from
Aug 12, 2024

Conversation

thomas-quadratic
Copy link
Contributor

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

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>
Copy link

github-actions bot commented Jul 8, 2024

  • I thought about the changelog.

Signed-off-by: Thomas Zamojski <thomas.zamojski@quadratic-labs.com>
build.gradle Outdated Show resolved Hide resolved
gradle/versions.gradle 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)));
Copy link
Contributor

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)));

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 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();
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as above

* @param value A commitment value
* @return The encoded commitment
*/
public static Bytes encodeCommitment(Bytes value) {
Copy link
Contributor

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 ?

Copy link
Contributor Author

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

thomas-quadratic and others added 3 commits August 12, 2024 10:49
Signed-off-by: Thomas Zamojski <thomas.zamojski@quadratic-labs.com>
Signed-off-by: Karim Taam <karim.t2am@gmail.com>
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>
Copy link
Contributor

@matkt matkt left a comment

Choose a reason for hiding this comment

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

LGTM

@matkt matkt merged commit 04a8027 into hyperledger:main Aug 12, 2024
4 checks passed
matkt added a commit that referenced this pull request Oct 1, 2024
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants