Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronFeickert committed Mar 28, 2023
1 parent 35ed587 commit 9b35e17
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions base_layer/mmr/src/mutable_mmr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,18 @@ where
// virtue of the fact that the underlying MMRs could be different, but all elements are marked as deleted in
// both sets.
let mmr_root = self.mmr.get_merkle_root()?;

// To avoid requiring mutability, we compress a clone of the bitmap
let mut bitmap = self.deleted.clone();
bitmap.run_optimize();
let bitmap_ser = bitmap.serialize();

// Include the compressed bitmap in the root hash
let mut hasher = D::new();
hasher.update(&mmr_root);
Ok(self.hash_deleted(hasher).finalize().to_vec())
hasher.update(&bitmap_ser);

Ok(hasher.finalize().to_vec())
}

/// Returns only the MMR merkle root without the compressed serialisation of the bitmap
Expand Down Expand Up @@ -197,13 +206,6 @@ where
self.mmr.validate()
}

/// Hash the roaring bitmap of nodes that are marked for deletion
fn hash_deleted(&self, mut hasher: D) -> D {
let bitmap_ser = self.deleted.serialize();
hasher.update(&bitmap_ser);
hasher
}

// Returns a bitmap with only the deleted nodes for the specified region in the MMR.
fn get_sub_bitmap(&self, leaf_index: LeafIndex, count: usize) -> Result<Bitmap, MerkleMountainRangeError> {
let mut deleted = self.deleted.clone();
Expand Down

0 comments on commit 9b35e17

Please sign in to comment.