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

Fix stateroot issue #72

Merged
merged 2 commits into from
Oct 2, 2024
Merged

Conversation

matkt
Copy link
Contributor

@matkt matkt commented Oct 1, 2024

PR description

Update code in order to fix state root issues when we reload a trie from the database ; add also some cleaning of the code

Fixed Issue(s)

Signed-off-by: Karim Taam <[email protected]>
Copy link

github-actions bot commented Oct 1, 2024

  • I thought about the changelog.

@@ -52,6 +52,9 @@ enum NodeType {
* @param <V> The type of values stored in Verkle Trie nodes.
*/
public class StoredNodeFactory<V> implements NodeFactory<V> {

private final NullLeafNode<V> nullLeafNode = new NullLeafNode<V>();
Copy link
Contributor

Choose a reason for hiding this comment

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

We always create a new VerkleTrie on the caller side so I think it would be best if this field is 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.

I used a non static field in order to have the same type as StoredNodeFactory ( V )

this.location = Optional.of(location);
this.children = new ArrayList<>();
for (int i = 0; i < maxChild(); i++) {
final NullNode<V> nullNode = new NullNode<V>();
nullNode.markDirty();
children.add(nullNode);
Copy link
Contributor

Choose a reason for hiding this comment

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

can't you use this() to avoid repetition like you did on LeafNode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done good catch

@@ -29,7 +29,7 @@
* @param <V> The type of node values.
*/
public class GetVisitor<V> implements PathNodeVisitor<V> {
private final Node<V> NULL_NODE_RESULT = new NullLeafNode<>();
public final Node<V> NULL_NODE_RESULT = new NullLeafNode<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

can't reuse the one from StoredNodeFactory? Maybe move it into a location with constants or something

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 the first comment don't found a way to have a static field and keep V type

/**
* Constructs a new BranchNode with optional location and path, initializing children to
* NullNodes.
*
* @param location The optional location in the tree.
*/
public BranchNode(final Bytes location) {
super(false, false);
super(false, true);
this.location = Optional.of(location);
this.children = new ArrayList<>();
for (int i = 0; i < maxChild(); i++) {
final NullNode<V> nullNode = new NullNode<V>();
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the difference between NullNode and NullLeafNode It seems to me that they are mostly the same apart from that NullLeafNode's ability to store a previous value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's mainly that , it's also a way to have a specific logic in the PutVisitor for NullNode and NullLeafNode

Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed offline: I was trying to do a refactoring to remove NullLeafNode and provide the same functionality but I'm getting some errors so I'll back out my last commit to not block you on this one

Copy link
Contributor

@lu-pinto lu-pinto left a comment

Choose a reason for hiding this comment

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

Made some minor remarks that could be nice to change.
Can't really assess whether all the persistence is required, might have some performance impacts if not but since it fixes the issue LGTM

Signed-off-by: Karim Taam <[email protected]>
@lu-pinto lu-pinto merged commit 69cd7e7 into hyperledger:main Oct 2, 2024
8 checks passed
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