feat: Add Mmr::nodes_from and Mmr::from_nodes_unchecked - #3585
Merged
Conversation
sergerad
force-pushed
the
sergerad-mmr-incr-serde
branch
from
August 11, 2026 23:38
689e1a3 to
83d9f73
Compare
sergerad
force-pushed
the
sergerad-mmr-incr-serde
branch
from
August 11, 2026 23:40
83d9f73 to
5645e98
Compare
sergerad
marked this pull request as draft
August 12, 2026 00:01
sergerad
marked this pull request as ready for review
August 12, 2026 23:57
huitseeker
reviewed
Aug 13, 2026
huitseeker
left a comment
Collaborator
There was a problem hiding this comment.
Overall, this looks good, but I think this PR needs one code change and one wording change:
- Restore the early count check in read_from.
- State clearly that count validation checks representation shape, while trusted commitment comparison checks the accumulator state.
from_nodes_uncheckeddoes neither full rehashing nor full internal node validation.
sergerad
commented
Aug 13, 2026
| /// | ||
| /// Skips directly to the chunk containing `start` instead of walking from the front. Returns | ||
| /// an empty iterator if `start >= self.len()`. | ||
| pub fn iter_from(&self, start: usize) -> MmrNodeIter<'_> { |
Contributor
Author
There was a problem hiding this comment.
Just noting that this doesn't leak MmrNodeIter into pub api b/c pub(super) struct NodeStore.
huitseeker
reviewed
Aug 14, 2026
huitseeker
approved these changes
Aug 17, 2026
sergerad
force-pushed
the
sergerad-mmr-incr-serde
branch
from
August 17, 2026 20:48
1801e05 to
b6ad5bf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your changes
Unblocks 0xMiden/node#2468 which wants to persist
Mmrsegments incrementally to a flat file.Write side: adds
Mmr::nodes_from(start), returning an iterator over the MMR's nodes at indicesstart..in insertion (postorder) order. The node buffer is append-only, so a consumer that has persisted the firststartnodes can sync incrementally by appending only the nodes returned here — this lets miden-node keep a flat file of 32-byte node records instead of rewriting the full MMR or using RocksDB.Read side: adds
Mmr::from_nodes_unchecked(forest, nodes), reconstructing an MMR from its complete postorder node array without re-hashing (the exact cost the flat file exists to avoid —try_from_iterrecomputes every merge). The node count is validated against the forest, but node values are taken verbatim, so the caller is responsible for checking the result against a trusted commitment (e.g.peaks()) — same trust model asread_from_bytes, with the_uncheckedsuffix followingBlockchain::from_mmr_unchecked.Deserializable::read_fromnow delegates to the same validation path instead of duplicating the count check.The backing
NodeStore::iter_fromskips directly to the starting chunk. Tests cover chunk-boundary/mid-chunk/past-the-end starts, an incremental-persistence round trip, rebuild-from-nodes round trips (forest/nodes/peaks match and openings verify, including empty-forest and multi-chunk sizes), and count-mismatch rejection (MmrError::InvalidNodeCount).Checklist before requesting a review
nextaccording to naming convention.CHANGELOG.md