1+ use async_trait:: async_trait;
2+ use rayon:: prelude:: * ;
13use std:: {
24 collections:: { BTreeMap , BTreeSet , HashMap } ,
35 sync:: Arc ,
46} ;
5-
6- use async_trait:: async_trait;
7+ use tokio:: sync:: Mutex ;
78
89use 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