Skip to content

Commit 5c750d9

Browse files
committed
feat: parallel sub Merkle tree computation in proof computation
1 parent 361c8ff commit 5c750d9

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-aggregator/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ mithril-doc = { path = "../internal/mithril-doc" }
3131
mithril-persistence = { path = "../internal/mithril-persistence" }
3232
openssl = { version = "0.10.63", features = ["vendored"], optional = true }
3333
openssl-probe = { version = "0.1.5", optional = true }
34+
rayon = "1.10.0"
3435
reqwest = { version = "0.12.0", features = ["json"] }
3536
semver = "1.0.21"
3637
serde = { version = "1.0.196", features = ["derive"] }

mithril-aggregator/src/services/prover.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
use async_trait::async_trait;
2+
use rayon::prelude::*;
13
use std::{
24
collections::{BTreeMap, BTreeSet, HashMap},
35
sync::Arc,
46
};
5-
6-
use async_trait::async_trait;
7+
use tokio::sync::Mutex;
78

89
use mithril_common::{
910
crypto_helper::{MKMap, MKMapNode, MKTree},
@@ -14,7 +15,6 @@ use mithril_common::{
1415
signable_builder::BlockRangeRootRetriever,
1516
StdResult,
1617
};
17-
use tokio::sync::Mutex;
1818

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

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

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

0 commit comments

Comments
 (0)