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

test: fix mutable MMR test and add documentation #5276

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion base_layer/mmr/src/mutable_mmr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ where
}

/// Returns a merkle(ish) root for this merkle set.
///
///
/// You _must_ have run `compress()` on this MMR if any deletions were made, or the root may be incorrect.
///
/// The root is calculated by concatenating the MMR merkle root with the compressed serialisation of the bitmap
/// and then hashing the result.
pub fn get_merkle_root(&self) -> Result<Hash, MerkleMountainRangeError> {
Expand Down
6 changes: 5 additions & 1 deletion base_layer/mmr/tests/pruned_mmr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,23 @@ fn get_changes() -> (usize, Vec<Hash>, Vec<u32>) {
/// result of `calculate_pruned_mmr_root`
#[test]
pub fn calculate_pruned_mmr_roots() {
// Check that the root changes with nontrivial additions and deletions
let (src_size, additions, deletions) = get_changes();
let mut src = create_mutable_mmr(src_size);
let src_root = src.get_merkle_root().expect("Did not get source root");
let root =
calculate_pruned_mmr_root(&src, additions.clone(), deletions.clone()).expect("Did not calculate new root");
assert_ne!(src_root, root);
// Double check

// To check the pruned root computation, manually apply the additions and deletions
// We need to compress the deletion bitmap, but as an extra check, we don't apply pruning
additions.into_iter().for_each(|h| {
src.push(h).unwrap();
});
deletions.iter().for_each(|i| {
src.delete(*i);
});
src.compress();
let new_root = src.get_merkle_root().expect("Did not calculate new root");
assert_eq!(root, new_root);
}
Expand Down