diff --git a/Cargo.lock b/Cargo.lock index 4c4812190f0..2bbd2d85c85 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3470,6 +3470,7 @@ dependencies = [ "mockall", "openssl", "openssl-probe", + "rayon", "reqwest 0.12.4", "semver", "serde", diff --git a/mithril-aggregator/Cargo.toml b/mithril-aggregator/Cargo.toml index d73b14b0aea..67d2efb1ba5 100644 --- a/mithril-aggregator/Cargo.toml +++ b/mithril-aggregator/Cargo.toml @@ -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"] } diff --git a/mithril-aggregator/src/services/prover.rs b/mithril-aggregator/src/services/prover.rs index da84fc59ca3..cb2928d1903 100644 --- a/mithril-aggregator/src/services/prover.rs +++ b/mithril-aggregator/src/services/prover.rs @@ -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}, @@ -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)] @@ -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> = 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?;