Skip to content

Commit

Permalink
Merge branch 'development' into ho_igor_faucet
Browse files Browse the repository at this point in the history
  • Loading branch information
hansieodendaal authored Mar 30, 2023
2 parents 8639932 + dfddc66 commit a1bd035
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,6 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> {
// in the output MMR
let bitmap = self.full_bitmap_mut();
bitmap.or_inplace(&diff_bitmap);
bitmap.run_optimize();

let pruned_output_set = output_mmr.get_pruned_hash_set()?;
let output_mmr = MutablePrunedOutputMmr::new(pruned_output_set.clone(), bitmap.clone())?;
Expand Down
2 changes: 0 additions & 2 deletions base_layer/core/src/chain_storage/blockchain_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1360,8 +1360,6 @@ pub fn calculate_mmr_roots<T: BlockchainBackend>(
}
}

output_mmr.compress();

let block_height = block.header.height;
let epoch_len = rules.consensus_constants(block_height).epoch_length();
let validator_node_mr = if block_height % epoch_len == 0 {
Expand Down
1 change: 0 additions & 1 deletion base_layer/mmr/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ where
for index in deletions {
pruned_mmr.delete(index);
}
pruned_mmr.compress();
pruned_mmr.get_merkle_root()
}

Expand Down
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 a1bd035

Please sign in to comment.