-
Notifications
You must be signed in to change notification settings - Fork 24
feat(diff): Framework for change proofs #839
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
Draft
rkuris
wants to merge
18
commits into
main
Choose a base branch
from
rkuris/change-proofs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
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
c2035b5 to
7a1242e
Compare
3961602 to
9c8aab4
Compare
9c8aab4 to
05fb244
Compare
0f0f65b to
6595ba7
Compare
Unoptimized version for reference, with some tests
Generates BatchOp operations representing the differences between two merkle tries, with an optional start key. Sub-tries with identical hashes are skipped. The two main structures are DiffMerkleKeyValueStreams which manages the dual trie iteration and holds the pending values, and DiffIteratorState which keeps track of which values are saved because they haven't been matched to the other trie yet. Algorithm: 1. Iterates through both trees simultaneously from optional start key 2. Compares keys lexicographically to determine operation type 3. Generate Put operations for additions/modifications 4. Generate Delete operations for removals 5. Saves out-of-order values in iterator state for next iteration 6. Optimizes by skipping subtrees with matching hashes (when possible) Testing: There are basic tests and a fuzz test. If the test fails, instructions on how to rerun it with the correct seed are provided in the error output. This follows the same pattern as the merkle fuzz tests.
78dffbb to
10dbdf1
Compare
10dbdf1 to
27698b4
Compare
Took a slightly different approach, since the previous diff didn't use the optimized node iterator, and didn't even check for it. Other changes: - Renamed children_have_same_hash() to child_identical() - Added documentation around more complicated functions - Added additional tests to verify that fewer nodes are read when diffing tries with hashes already computed - Installed a test metrics recorder so metrics can be checked at runtime Note that if we add additional tests that want to use this metrics recorder, we would need to put this into a utility method and save it in case some other test initializes the metrics.
27698b4 to
3a4032d
Compare
demosdemon
reviewed
Jun 11, 2025
firewood/src/diff.rs
Outdated
Comment on lines
51
to
58
| impl fmt::Debug for VisitedPairState { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| f.debug_struct("VisitedPairState") | ||
| .field("children_iter_left", &"<iterator>") | ||
| .field("children_iter_right", &"<iterator>") | ||
| .finish() | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use derivative to clean up these manually implemented Debugs.
|
Group review comments:
|
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.
This is part 2 of 3 for change proofs, and contains the bulk of the work. The remaining changes involve calling these methods from the API to resolve #443.
Generates
BatchOpoperations representing the differences between two merkle tries, with an optional start key. Sub-tries with identical hashes are skipped.The two main structures are
DiffMerkleKeyValueStreamswhich manages the dual trie iteration and holds the pending values, andDiffIteratorStatewhich keeps track of which values are saved because they haven't been matched to the other trie yet.Algorithm: