@@ -8,7 +8,7 @@ use std::{
8
8
} ;
9
9
10
10
use mithril_common:: {
11
- crypto_helper:: { MKMap , MKMapNode , MKTree } ,
11
+ crypto_helper:: { MKMap , MKMapNode , MKTree , MKTreeStorer } ,
12
12
entities:: {
13
13
BlockNumber , BlockRange , CardanoTransaction , CardanoTransactionsSetProof , TransactionHash ,
14
14
} ,
@@ -51,18 +51,18 @@ pub trait TransactionsRetriever: Sync + Send {
51
51
}
52
52
53
53
/// Mithril prover
54
- pub struct MithrilProverService {
54
+ pub struct MithrilProverService < S : MKTreeStorer > {
55
55
transaction_retriever : Arc < dyn TransactionsRetriever > ,
56
- block_range_root_retriever : Arc < dyn BlockRangeRootRetriever > ,
57
- mk_map_pool : ResourcePool < MKMap < BlockRange , MKMapNode < BlockRange > > > ,
56
+ block_range_root_retriever : Arc < dyn BlockRangeRootRetriever < S > > ,
57
+ mk_map_pool : ResourcePool < MKMap < BlockRange , MKMapNode < BlockRange , S > , S > > ,
58
58
logger : Logger ,
59
59
}
60
60
61
- impl MithrilProverService {
61
+ impl < S : MKTreeStorer > MithrilProverService < S > {
62
62
/// Create a new Mithril prover
63
63
pub fn new (
64
64
transaction_retriever : Arc < dyn TransactionsRetriever > ,
65
- block_range_root_retriever : Arc < dyn BlockRangeRootRetriever > ,
65
+ block_range_root_retriever : Arc < dyn BlockRangeRootRetriever < S > > ,
66
66
mk_map_pool_size : usize ,
67
67
logger : Logger ,
68
68
) -> Self {
@@ -113,7 +113,7 @@ impl MithrilProverService {
113
113
}
114
114
115
115
#[ async_trait]
116
- impl ProverService for MithrilProverService {
116
+ impl < S : MKTreeStorer > ProverService for MithrilProverService < S > {
117
117
async fn compute_transactions_proofs (
118
118
& self ,
119
119
up_to : BlockNumber ,
@@ -126,7 +126,7 @@ impl ProverService for MithrilProverService {
126
126
. await ?;
127
127
128
128
// 2 - Compute block ranges sub Merkle trees
129
- let mk_trees: StdResult < Vec < ( BlockRange , MKTree ) > > = block_range_transactions
129
+ let mk_trees: StdResult < Vec < ( BlockRange , MKTree < S > ) > > = block_range_transactions
130
130
. into_iter ( )
131
131
. map ( |( block_range, transactions) | {
132
132
let mk_tree = MKTree :: new ( & transactions) ?;
@@ -183,7 +183,7 @@ impl ProverService for MithrilProverService {
183
183
) ;
184
184
mk_map_cache. clone ( )
185
185
} )
186
- . collect :: < Vec < MKMap < _ , _ > > > ( ) ;
186
+ . collect :: < Vec < MKMap < _ , _ , _ > > > ( ) ;
187
187
debug ! ( self . logger, "Prover is draining the Merkle map pool" ) ;
188
188
let discriminant_new = self . mk_map_pool . discriminant ( ) ? + 1 ;
189
189
self . mk_map_pool . set_discriminant ( discriminant_new) ?;
@@ -211,7 +211,9 @@ impl ProverService for MithrilProverService {
211
211
#[ cfg( test) ]
212
212
mod tests {
213
213
use anyhow:: anyhow;
214
- use mithril_common:: crypto_helper:: { MKMap , MKMapNode , MKTreeNode } ;
214
+ use mithril_common:: crypto_helper:: {
215
+ MKMap , MKMapNode , MKTreeNode , MKTreeStoreInMemory , MKTreeStorer ,
216
+ } ;
215
217
use mithril_common:: entities:: CardanoTransaction ;
216
218
use mithril_common:: test_utils:: CardanoTransactionsBuilder ;
217
219
use mockall:: mock;
@@ -220,10 +222,10 @@ mod tests {
220
222
use super :: * ;
221
223
222
224
mock ! {
223
- pub BlockRangeRootRetrieverImpl { }
225
+ pub BlockRangeRootRetrieverImpl < S : MKTreeStorer > { }
224
226
225
227
#[ async_trait]
226
- impl BlockRangeRootRetriever for BlockRangeRootRetrieverImpl {
228
+ impl < S : MKTreeStorer > BlockRangeRootRetriever < S > for BlockRangeRootRetrieverImpl < S > {
227
229
async fn retrieve_block_range_roots<' a>(
228
230
& ' a self ,
229
231
up_to_beacon: BlockNumber ,
@@ -232,11 +234,13 @@ mod tests {
232
234
async fn compute_merkle_map_from_block_range_roots(
233
235
& self ,
234
236
up_to_beacon: BlockNumber ,
235
- ) -> StdResult <MKMap <BlockRange , MKMapNode <BlockRange > >>;
237
+ ) -> StdResult <MKMap <BlockRange , MKMapNode <BlockRange , S > , S >>;
236
238
}
237
239
}
238
240
239
241
mod test_data {
242
+ use mithril_common:: crypto_helper:: MKTreeStoreInMemory ;
243
+
240
244
use super :: * ;
241
245
242
246
pub fn filter_transactions_for_indices (
@@ -287,15 +291,16 @@ mod tests {
287
291
288
292
pub fn compute_mk_map_from_block_ranges_map (
289
293
block_ranges_map : BTreeMap < BlockRange , Vec < CardanoTransaction > > ,
290
- ) -> MKMap < BlockRange , MKMapNode < BlockRange > > {
294
+ ) -> MKMap < BlockRange , MKMapNode < BlockRange , MKTreeStoreInMemory > , MKTreeStoreInMemory >
295
+ {
291
296
MKMap :: new_from_iter (
292
297
block_ranges_map
293
298
. into_iter ( )
294
299
. map ( |( block_range, transactions) | {
295
300
(
296
301
block_range,
297
302
MKMapNode :: TreeNode (
298
- MKTree :: new ( & transactions)
303
+ MKTree :: < MKTreeStoreInMemory > :: new ( & transactions)
299
304
. unwrap ( )
300
305
. compute_root ( )
301
306
. unwrap ( )
@@ -348,13 +353,13 @@ mod tests {
348
353
}
349
354
}
350
355
351
- fn build_prover < F , G > (
356
+ fn build_prover < F , G , S : MKTreeStorer + ' static > (
352
357
transaction_retriever_mock_config : F ,
353
358
block_range_root_retriever_mock_config : G ,
354
- ) -> MithrilProverService
359
+ ) -> MithrilProverService < S >
355
360
where
356
361
F : FnOnce ( & mut MockTransactionsRetriever ) ,
357
- G : FnOnce ( & mut MockBlockRangeRootRetrieverImpl ) ,
362
+ G : FnOnce ( & mut MockBlockRangeRootRetrieverImpl < S > ) ,
358
363
{
359
364
let mut transaction_retriever = MockTransactionsRetriever :: new ( ) ;
360
365
transaction_retriever_mock_config ( & mut transaction_retriever) ;
@@ -581,7 +586,7 @@ mod tests {
581
586
let transactions_to_prove =
582
587
test_data:: filter_transactions_for_indices ( & [ 1 , 2 , 4 ] , & transactions) ;
583
588
let test_data = test_data:: build_test_data ( & transactions_to_prove, & transactions) ;
584
- let prover = build_prover (
589
+ let prover = build_prover :: < _ , _ , MKTreeStoreInMemory > (
585
590
|transaction_retriever_mock| {
586
591
transaction_retriever_mock
587
592
. expect_get_by_hashes ( )
@@ -610,7 +615,7 @@ mod tests {
610
615
let transactions_to_prove =
611
616
test_data:: filter_transactions_for_indices ( & [ 1 , 2 , 4 ] , & transactions) ;
612
617
let test_data = test_data:: build_test_data ( & transactions_to_prove, & transactions) ;
613
- let prover = build_prover (
618
+ let prover = build_prover :: < _ , _ , MKTreeStoreInMemory > (
614
619
|transaction_retriever_mock| {
615
620
let transactions_to_prove = transactions_to_prove. clone ( ) ;
616
621
transaction_retriever_mock
0 commit comments