Skip to content

Commit

Permalink
feat: parallel sub Merkle tree computation in proof computation
Browse files Browse the repository at this point in the history
  • Loading branch information
jpraynaud committed May 23, 2024
1 parent df2f400 commit 723e04d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mithril-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ mithril-doc = { path = "../internal/mithril-doc" }
mithril-persistence = { path = "../internal/mithril-persistence" }
openssl = { version = "0.10.63", features = ["vendored"], optional = true }
openssl-probe = { version = "0.1.5", optional = true }
rayon = "1.10.0"
reqwest = { version = "0.12.0", features = ["json"] }
semver = "1.0.21"
serde = { version = "1.0.196", features = ["derive"] }
Expand Down
19 changes: 11 additions & 8 deletions mithril-aggregator/src/services/prover.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use async_trait::async_trait;
use rayon::prelude::*;
use std::{
collections::{BTreeMap, BTreeSet, HashMap},
sync::Arc,
};

use async_trait::async_trait;
use tokio::sync::Mutex;

use mithril_common::{
crypto_helper::{MKMap, MKMapNode, MKTree},
Expand All @@ -14,7 +15,6 @@ use mithril_common::{
signable_builder::BlockRangeRootRetriever,
StdResult,
};
use tokio::sync::Mutex;

/// Prover service is the cryptographic engine in charge of producing cryptographic proofs for transactions
#[cfg_attr(test, mockall::automock)]
Expand Down Expand Up @@ -129,11 +129,14 @@ impl ProverService for MithrilProverService {
.await?;

// 2 - Compute block ranges sub Merkle trees
let mut mk_trees = BTreeMap::new();
for (block_range, transactions) in block_range_transactions {
let mk_tree = MKTree::new(&transactions)?;
mk_trees.insert(block_range, mk_tree);
}
let mk_trees: StdResult<Vec<(BlockRange, MKTree)>> = block_range_transactions
.into_par_iter()
.map(|(block_range, transactions)| {
let mk_tree = MKTree::new(&transactions)?;
Ok((block_range, mk_tree))
})
.collect();
let mk_trees = BTreeMap::from_iter(mk_trees?);

// 3 - Compute block range roots Merkle map
self.compute_cache(up_to).await?;
Expand Down

0 comments on commit 723e04d

Please sign in to comment.