1
+ use async_trait:: async_trait;
2
+ use rayon:: prelude:: * ;
1
3
use std:: {
2
4
collections:: { BTreeMap , BTreeSet , HashMap } ,
3
5
sync:: Arc ,
4
6
} ;
5
-
6
- use async_trait:: async_trait;
7
+ use tokio:: sync:: Mutex ;
7
8
8
9
use mithril_common:: {
9
10
crypto_helper:: { MKMap , MKMapNode , MKTree } ,
@@ -14,7 +15,6 @@ use mithril_common::{
14
15
signable_builder:: BlockRangeRootRetriever ,
15
16
StdResult ,
16
17
} ;
17
- use tokio:: sync:: Mutex ;
18
18
19
19
/// Prover service is the cryptographic engine in charge of producing cryptographic proofs for transactions
20
20
#[ cfg_attr( test, mockall:: automock) ]
@@ -129,11 +129,14 @@ impl ProverService for MithrilProverService {
129
129
. await ?;
130
130
131
131
// 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?) ;
137
140
138
141
// 3 - Compute block range roots Merkle map
139
142
self . compute_cache ( up_to) . await ?;
0 commit comments