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/jmt (2/4) Implementation of functions to manipulate a Jmt #892

Draft
wants to merge 1 commit into
base: feature/jmt-1-integrate-storage-traits-with-jmt
Choose a base branch
from

Conversation

acerone85
Copy link
Contributor

This PR builds upon #891 to provide the basic functions to manipulate a jmt:

  • create a new Jmt backed by a generic storage,
  • load a Jmt from existing storage
  • return the tree root
  • create a Jmt from a set of key-value pairs
  • update and delete a key-value pair in a Jmt

Tests are provided in the last PR of this feature.

Checklist

  • Breaking changes are clearly marked as such in the PR description and changelog
  • New behavior is reflected in tests
  • If performance characteristic of an instruction change, update gas costs as well or make a follow-up PR for that
  • The specification matches the implemented behavior (link update PR if changes are needed)

Before requesting review

  • I have reviewed the code myself
  • I have created follow-up issues caused by this PR and linked them here

After merging, notify other teams

[Add or remove entries as needed]

@acerone85 acerone85 requested review from netrome and rymnc January 16, 2025 23:04
@acerone85 acerone85 self-assigned this Jan 16, 2025
@acerone85 acerone85 marked this pull request as draft January 16, 2025 23:04
Copy link
Contributor

@netrome netrome left a comment

Choose a reason for hiding this comment

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

So far so good. I haven't done a deep review of the update logic.

Comment on lines +252 to +259
// Inclusion and Exclusion proof require that the root is set, hence we add it
// here. Jmt does not make the constructor for `NibblePath` accessible, so
// we add and remove a node instead.
// TODO: Find a way to set the root without adding and deleting a node
let mock_key = MerkleTreeKey::new(Bytes32::default());
let mock_value = vec![0u8];
tree.update(mock_key, &mock_value)?;
tree.delete(mock_key)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Ugh...

// We start from version 2 to be consistent with the version obtained
// when returning a new tree.
// TODO: Change Self::new so that the initial version of a new tree is 0.
let version = 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps this should be a constant

set: I,
) -> Result<Self, MerkleTreeError<StorageError>>
where
I: Iterator<Item = (B, D)>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This could be more generic if we use IntoIterator. It saves the caller from explicitly calling .iter() or .into_iter() most of the time.

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