Skip to content

Commit

Permalink
chore: addressing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
krushimir committed Jan 29, 2025
1 parent 17b03a8 commit 1eb7769
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/merkle/smt/full/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,7 @@ impl Smt {
<Self as SparseMerkleTree<SMT_DEPTH>>::compute_mutations(self, kv_pairs)
}

/// Applies the prospective mutations computed with [`Smt::compute_mutations()`] to
/// this tree and returns the reverse mutation set. Applying the reverse mutation sets to the
/// updated tree will revert the changes.
/// Applies the prospective mutations computed with [`Smt::compute_mutations()`] to this tree.
///
/// # Errors
/// If `mutations` was computed on a tree with a different root than this one, returns
Expand Down
6 changes: 5 additions & 1 deletion src/merkle/smt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ pub(crate) trait SparseMerkleTree<const DEPTH: u8> {
) -> MutationSet<DEPTH, Self::Key, Self::Value>
where
Self: Sized + Sync,
Self::Key: Send + Sync,
Self::Value: Send + Sync,
{
#[cfg(feature = "concurrent")]
{
Expand Down Expand Up @@ -307,12 +309,14 @@ pub(crate) trait SparseMerkleTree<const DEPTH: u8> {
) -> MutationSet<DEPTH, Self::Key, Self::Value>
where
Self: Sized + Sync,
Self::Key: Send + Sync,
Self::Value: Send + Sync,
{
use rayon::prelude::*;

// Collect and sort key-value pairs by their corresponding leaf index
let mut sorted_kv_pairs: Vec<_> = kv_pairs.into_iter().collect();
sorted_kv_pairs.sort_unstable_by_key(|(key, _)| Self::key_to_leaf_index(key).value());
sorted_kv_pairs.par_sort_unstable_by_key(|(key, _)| Self::key_to_leaf_index(key).value());

// Convert sorted pairs into mutated leaves and capture any new pairs
let (mut subtree_leaves, new_pairs) =
Expand Down

0 comments on commit 1eb7769

Please sign in to comment.