@@ -11,7 +11,7 @@ use filecoin_hashers::Hasher;
11
11
use filecoin_proofs_v1:: constants:: {
12
12
SectorShape16KiB , SectorShape16MiB , SectorShape1GiB , SectorShape2KiB , SectorShape32GiB ,
13
13
SectorShape32KiB , SectorShape4KiB , SectorShape512MiB , SectorShape64GiB , SectorShape8MiB ,
14
- SECTOR_SIZE_16_KIB , SECTOR_SIZE_16_MIB , SECTOR_SIZE_1_GIB , SECTOR_SIZE_2_KIB ,
14
+ LAYERS , SECTOR_SIZE_16_KIB , SECTOR_SIZE_16_MIB , SECTOR_SIZE_1_GIB , SECTOR_SIZE_2_KIB ,
15
15
SECTOR_SIZE_32_GIB , SECTOR_SIZE_32_KIB , SECTOR_SIZE_4_KIB , SECTOR_SIZE_512_MIB ,
16
16
SECTOR_SIZE_64_GIB , SECTOR_SIZE_8_MIB ,
17
17
} ;
@@ -402,6 +402,46 @@ fn seal_pre_commit_phase1_inner<Tree: 'static + MerkleTreeTrait>(
402
402
} )
403
403
}
404
404
405
+ /// Generate label layers (SDR).
406
+ ///
407
+ /// # Arguments
408
+ /// * `registered_proof` - Selected seal operation.
409
+ /// * `cache_path` - Directory path to use for generation of Merkle tree on disk.
410
+ /// * `output_dir` - Directory where the TreeRLast(s) are stored.
411
+ pub fn sdr < R > (
412
+ registered_proof : RegisteredSealProof ,
413
+ cache_path : R ,
414
+ replica_id : <filecoin_proofs_v1:: constants:: DefaultTreeHasher as Hasher >:: Domain ,
415
+ ) -> Result < ( ) >
416
+ where
417
+ R : AsRef < Path > ,
418
+ {
419
+ ensure ! (
420
+ registered_proof. major_version( ) == 1 ,
421
+ "unusupported version"
422
+ ) ;
423
+
424
+ with_shape ! (
425
+ u64 :: from( registered_proof. sector_size( ) ) ,
426
+ sdr_inner,
427
+ registered_proof,
428
+ cache_path. as_ref( ) ,
429
+ replica_id,
430
+ ) ?;
431
+
432
+ Ok ( ( ) )
433
+ }
434
+
435
+ fn sdr_inner < Tree : ' static + MerkleTreeTrait > (
436
+ registered_proof : RegisteredSealProof ,
437
+ cache_path : & Path ,
438
+ replica_id : <Tree :: Hasher as Hasher >:: Domain ,
439
+ ) -> Result < ( ) > {
440
+ let config = registered_proof. as_v1_config ( ) ;
441
+ filecoin_proofs_v1:: sdr :: < _ , Tree > ( & config, cache_path, & replica_id) ?;
442
+ Ok ( ( ) )
443
+ }
444
+
405
445
/// Second phase of seal precommit operation, must be called with output of
406
446
/// [`seal_pre_commit_phase1`]. Generates `comm_r` replica commitment from outputs
407
447
/// of previous step.
@@ -477,6 +517,96 @@ fn seal_pre_commit_phase2_inner<Tree: 'static + MerkleTreeTrait>(
477
517
} )
478
518
}
479
519
520
+ /// Generate Merkle tree for sector replica (TreeRLast) and return the root hash (CommRLast).
521
+ ///
522
+ /// # Arguments
523
+ /// * `registered_proof` - Selected seal operation.
524
+ /// * `replica_path` - File path of replica.
525
+ /// * `output_dir` - Directory where the TreeRLast(s) are stored.
526
+ pub fn generate_tree_r_last < O , R > (
527
+ registered_proof : RegisteredSealProof ,
528
+ replica_path : R ,
529
+ output_dir : O ,
530
+ ) -> Result < Commitment >
531
+ where
532
+ O : AsRef < Path > ,
533
+ R : AsRef < Path > ,
534
+ {
535
+ ensure ! (
536
+ registered_proof. major_version( ) == 1 ,
537
+ "unusupported version"
538
+ ) ;
539
+
540
+ let sector_size = u64:: from ( registered_proof. sector_size ( ) ) ;
541
+ let comm_r_last = with_shape ! (
542
+ sector_size,
543
+ generate_tree_r_last_inner,
544
+ sector_size,
545
+ replica_path. as_ref( ) ,
546
+ output_dir. as_ref( ) ,
547
+ ) ?;
548
+
549
+ Ok ( comm_r_last. into ( ) )
550
+ }
551
+
552
+ fn generate_tree_r_last_inner < Tree : ' static + MerkleTreeTrait > (
553
+ sector_size : u64 ,
554
+ replica_path : & Path ,
555
+ output_dir : & Path ,
556
+ ) -> Result < <Tree :: Hasher as Hasher >:: Domain > {
557
+ filecoin_proofs_v1:: generate_tree_r_last :: < _ , _ , Tree > ( sector_size, & replica_path, & output_dir)
558
+ }
559
+
560
+ /// Generate Merkle tree for the label layers (TreeC) and return the root hash (CommC).
561
+ ///
562
+ /// # Arguments
563
+ /// * `registered_proof` - Selected seal operation.
564
+ /// * `input_dir` - Directory where the label layers are stored.
565
+ /// * `output_dir` - Directory where the TreeRLast(s) are stored.
566
+ pub fn generate_tree_c < O , R > (
567
+ registered_proof : RegisteredSealProof ,
568
+ input_dir : R ,
569
+ output_dir : O ,
570
+ ) -> Result < Commitment >
571
+ where
572
+ O : AsRef < Path > ,
573
+ R : AsRef < Path > ,
574
+ {
575
+ ensure ! (
576
+ registered_proof. major_version( ) == 1 ,
577
+ "unusupported version"
578
+ ) ;
579
+
580
+ let sector_size = u64:: from ( registered_proof. sector_size ( ) ) ;
581
+ let comm_c = with_shape ! (
582
+ sector_size,
583
+ generate_tree_c_inner,
584
+ sector_size,
585
+ input_dir. as_ref( ) ,
586
+ output_dir. as_ref( ) ,
587
+ ) ?;
588
+
589
+ Ok ( comm_c. into ( ) )
590
+ }
591
+
592
+ fn generate_tree_c_inner < Tree : ' static + MerkleTreeTrait > (
593
+ sector_size : u64 ,
594
+ input_dir : & Path ,
595
+ output_dir : & Path ,
596
+ ) -> Result < <Tree :: Hasher as Hasher >:: Domain > {
597
+ let num_layers = * LAYERS
598
+ . read ( )
599
+ . expect ( "LAYERS poisoned" )
600
+ . get ( & sector_size)
601
+ . expect ( "unknown sector size" ) ;
602
+ filecoin_proofs_v1:: generate_tree_c :: < _ , _ , Tree > (
603
+ sector_size,
604
+ & input_dir,
605
+ & output_dir,
606
+ num_layers,
607
+ )
608
+ }
609
+
480
610
/// Computes a sectors's `comm_d` data commitment given its pieces.
481
611
///
482
612
/// # Arguments
0 commit comments