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

feat(SMT): reverse mutations generation, mutations serialization #355

Open
wants to merge 3 commits into
base: next
Choose a base branch
from

Conversation

polydez
Copy link
Contributor

@polydez polydez commented Dec 12, 2024

Related to 0xPolygonMiden/miden-node#527

While refactoring account inclusion proofs in-memory storage, I realized that it's very hard to keep persistent state for additional "initial" structure, and it would be easier to keep only reverse mutation sets and the latest state. Thus, we need to store only reverse mutations set, but latest state we can still reconstruct from the database.

In this PR I implemented reverse mutations set generation on mutations applying. Also implemented serialization of mutations set.

The only concern I have is that now we produce reverse mutations set on each applying of mutations set. For the node it's fine, because we always need them after changing of the latest accounts SMT. But if someone else uses our SMT, it might be unnecessary to calculate such reversion on each mutations set applying.

@polydez polydez requested a review from bobbinth December 12, 2024 11:46
@polydez polydez marked this pull request as ready for review December 12, 2024 11:48
@polydez polydez changed the title feat: revert mutations generation, mutations serialization feat: reverse mutations generation, mutations serialization Dec 12, 2024
@polydez polydez changed the title feat: reverse mutations generation, mutations serialization feat(SMT): reverse mutations generation, mutations serialization Dec 12, 2024
},
Addition(node) => {
if let Some(old_node) = self.insert_inner_node(index, node) {
reverse_mutations.insert(index, Addition(old_node));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we rely on the computation of mutations set, that it didn't generate useless update where new value is the same as previous (actually it does generate unnecessary changes in mutations set). Otherwise we would need to clone node and compare it with old_node.

for (key, value) in new_pairs {
self.insert_value(key, value);
if let Some(old_value) = self.insert_value(key.clone(), value) {
reverse_pairs.insert(key, old_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.

Here we also rely on the computation of mutations set, that it didn't generate useless update where new value is the same as previous (actually it does generate unnecessary changes in mutations set). Otherwise we would need to clone value and compare it with old_value.

Copy link

sonarcloud bot commented Dec 12, 2024

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.

1 participant