@@ -118,12 +118,7 @@ impl ProverService for MithrilProverService {
118
118
// 2 - Compute block ranges sub Merkle trees
119
119
let mut mk_trees = BTreeMap :: new ( ) ;
120
120
for ( block_range, transactions) in block_range_transactions {
121
- let mk_tree = MKTree :: new (
122
- & transactions
123
- . iter ( )
124
- . map ( |t| t. transaction_hash . clone ( ) )
125
- . collect :: < Vec < _ > > ( ) ,
126
- ) ?;
121
+ let mk_tree = MKTree :: new ( & transactions) ?;
127
122
mk_trees. insert ( block_range, mk_tree) ;
128
123
}
129
124
@@ -140,15 +135,11 @@ impl ProverService for MithrilProverService {
140
135
141
136
// 5 - Compute the proof for all transactions
142
137
if let Ok ( mk_proof) = mk_map. compute_proof ( transaction_hashes) {
143
- let transaction_hashes_certified = transaction_hashes
138
+ let transaction_hashes_certified: Vec < TransactionHash > = transaction_hashes
144
139
. iter ( )
145
- . filter_map ( |hash| {
146
- mk_proof
147
- . contains ( & hash. to_owned ( ) . into ( ) )
148
- . ok ( )
149
- . map ( |_| hash. clone ( ) )
150
- } )
151
- . collect :: < Vec < _ > > ( ) ;
140
+ . filter ( |hash| mk_proof. contains ( & hash. as_str ( ) . into ( ) ) . is_ok ( ) )
141
+ . cloned ( )
142
+ . collect ( ) ;
152
143
153
144
Ok ( vec ! [ CardanoTransactionsSetProof :: new(
154
145
transaction_hashes_certified,
@@ -194,7 +185,7 @@ mod tests {
194
185
195
186
// Generate transactions for 'total_block_ranges' consecutive block ranges,
196
187
// with 'total_transactions_per_block_range' transactions per block range
197
- pub ( crate ) fn generate_transactions (
188
+ pub fn generate_transactions (
198
189
total_block_ranges : usize ,
199
190
total_transactions_per_block_range : usize ,
200
191
) -> Vec < CardanoTransaction > {
@@ -229,7 +220,7 @@ mod tests {
229
220
transactions
230
221
}
231
222
232
- pub ( crate ) fn filter_transactions_for_indices (
223
+ pub fn filter_transactions_for_indices (
233
224
indices : & [ usize ] ,
234
225
transactions : & [ CardanoTransaction ] ,
235
226
) -> Vec < CardanoTransaction > {
@@ -241,7 +232,7 @@ mod tests {
241
232
. collect ( )
242
233
}
243
234
244
- pub ( crate ) fn compute_transaction_hashes_from_transactions (
235
+ pub fn compute_transaction_hashes_from_transactions (
245
236
transactions : & [ CardanoTransaction ] ,
246
237
) -> Vec < TransactionHash > {
247
238
transactions
@@ -250,7 +241,7 @@ mod tests {
250
241
. collect ( )
251
242
}
252
243
253
- pub ( crate ) fn compute_block_ranges_map_from_transactions (
244
+ pub fn compute_block_ranges_map_from_transactions (
254
245
transactions : & [ CardanoTransaction ] ,
255
246
) -> BTreeMap < BlockRange , Vec < CardanoTransaction > > {
256
247
let mut block_ranges_map = BTreeMap :: new ( ) ;
@@ -264,7 +255,7 @@ mod tests {
264
255
block_ranges_map
265
256
}
266
257
267
- pub ( crate ) fn filter_transactions_for_block_ranges (
258
+ pub fn filter_transactions_for_block_ranges (
268
259
block_ranges : & [ BlockRange ] ,
269
260
transactions : & [ CardanoTransaction ] ,
270
261
) -> Vec < CardanoTransaction > {
@@ -275,13 +266,7 @@ mod tests {
275
266
. collect ( )
276
267
}
277
268
278
- pub ( crate ) fn compute_mk_tree_from_transactions (
279
- transactions : & [ CardanoTransaction ] ,
280
- ) -> MKTree {
281
- MKTree :: new ( & compute_transaction_hashes_from_transactions ( transactions) ) . unwrap ( )
282
- }
283
-
284
- pub ( crate ) fn compute_mk_map_from_block_ranges_map (
269
+ pub fn compute_mk_map_from_block_ranges_map (
285
270
block_ranges_map : BTreeMap < BlockRange , Vec < CardanoTransaction > > ,
286
271
) -> MKMap < BlockRange , MKMapNode < BlockRange > > {
287
272
MKMap :: new_from_iter (
@@ -291,7 +276,8 @@ mod tests {
291
276
(
292
277
block_range,
293
278
MKMapNode :: TreeNode (
294
- compute_mk_tree_from_transactions ( & transactions)
279
+ MKTree :: new ( & transactions)
280
+ . unwrap ( )
295
281
. compute_root ( )
296
282
. unwrap ( )
297
283
. clone ( ) ,
@@ -302,7 +288,7 @@ mod tests {
302
288
. unwrap ( )
303
289
}
304
290
305
- pub ( crate ) fn compute_beacon_from_transactions (
291
+ pub fn compute_beacon_from_transactions (
306
292
transactions : & [ CardanoTransaction ] ,
307
293
) -> CardanoDbBeacon {
308
294
CardanoDbBeacon {
@@ -311,15 +297,15 @@ mod tests {
311
297
}
312
298
}
313
299
314
- pub ( crate ) struct TestData {
315
- pub ( crate ) transaction_hashes_to_prove : Vec < TransactionHash > ,
316
- pub ( crate ) block_ranges_map : BTreeMap < BlockRange , Vec < CardanoTransaction > > ,
317
- pub ( crate ) block_ranges_to_prove : Vec < BlockRange > ,
318
- pub ( crate ) all_transactions_in_block_ranges_to_prove : Vec < CardanoTransaction > ,
319
- pub ( crate ) beacon : CardanoDbBeacon ,
300
+ pub struct TestData {
301
+ pub transaction_hashes_to_prove : Vec < TransactionHash > ,
302
+ pub block_ranges_map : BTreeMap < BlockRange , Vec < CardanoTransaction > > ,
303
+ pub block_ranges_to_prove : Vec < BlockRange > ,
304
+ pub all_transactions_in_block_ranges_to_prove : Vec < CardanoTransaction > ,
305
+ pub beacon : CardanoDbBeacon ,
320
306
}
321
307
322
- pub ( crate ) fn build_test_data (
308
+ pub fn build_test_data (
323
309
transactions_to_prove : & [ CardanoTransaction ] ,
324
310
transactions : & [ CardanoTransaction ] ,
325
311
) -> TestData {
@@ -480,12 +466,11 @@ mod tests {
480
466
vec ! [ "tx-unknown-123" . to_string( ) , "tx-unknown-456" . to_string( ) ] ;
481
467
let mut test_data = test_data:: build_test_data ( & transactions_to_prove, & transactions) ;
482
468
let transaction_hashes_known = test_data. transaction_hashes_to_prove . clone ( ) ;
483
- test_data. transaction_hashes_to_prove = test_data
484
- . transaction_hashes_to_prove
485
- . clone ( )
486
- . into_iter ( )
487
- . chain ( transaction_hashes_unknown. into_iter ( ) )
488
- . collect :: < Vec < _ > > ( ) ;
469
+ test_data. transaction_hashes_to_prove = [
470
+ test_data. transaction_hashes_to_prove . clone ( ) ,
471
+ transaction_hashes_unknown,
472
+ ]
473
+ . concat ( ) ;
489
474
let prover = build_prover (
490
475
|retriever_mock| {
491
476
let transaction_hashes_to_prove = test_data. transaction_hashes_to_prove . clone ( ) ;
@@ -541,10 +526,8 @@ mod tests {
541
526
let test_data = test_data:: build_test_data ( & transactions_to_prove, & transactions) ;
542
527
let prover = build_prover (
543
528
|retriever_mock| {
544
- let transaction_hashes_to_prove = test_data. transaction_hashes_to_prove . clone ( ) ;
545
529
retriever_mock
546
530
. expect_get_by_hashes ( )
547
- . with ( eq ( transaction_hashes_to_prove) )
548
531
. returning ( |_| Err ( anyhow ! ( "Error" ) ) ) ;
549
532
} ,
550
533
|block_range_root_retriever_mock| {
@@ -573,19 +556,15 @@ mod tests {
573
556
let test_data = test_data:: build_test_data ( & transactions_to_prove, & transactions) ;
574
557
let prover = build_prover (
575
558
|retriever_mock| {
576
- let transaction_hashes_to_prove = test_data. transaction_hashes_to_prove . clone ( ) ;
577
559
let transactions_to_prove = transactions_to_prove. clone ( ) ;
578
560
retriever_mock
579
561
. expect_get_by_hashes ( )
580
- . with ( eq ( transaction_hashes_to_prove) )
581
562
. return_once ( move |_| Ok ( transactions_to_prove) ) ;
582
563
583
- let block_ranges_to_prove = test_data. block_ranges_to_prove . clone ( ) ;
584
564
let all_transactions_in_block_ranges_to_prove =
585
565
test_data. all_transactions_in_block_ranges_to_prove . clone ( ) ;
586
566
retriever_mock
587
567
. expect_get_by_block_ranges ( )
588
- . with ( eq ( block_ranges_to_prove) )
589
568
. return_once ( move |_| Ok ( all_transactions_in_block_ranges_to_prove) ) ;
590
569
} ,
591
570
|block_range_root_retriever_mock| {
0 commit comments