@@ -25,13 +25,13 @@ type stackFrame struct {
2525// This function makes no assumptions, other than maximum size, about the pieces that you include.
2626// To create a correctly formed UnsealedCID (CommD) for a sector using this method, you should first
2727// ensure that the pieces add up to the required size.
28- func PieceAggregateCommP (proofType abi.RegisteredSealProof , pieceInfos []abi.PieceInfo ) (cid.Cid , error ) {
28+ func PieceAggregateCommP (proofType abi.RegisteredSealProof , pieceInfos []abi.PieceInfo ) (cid.Cid , abi. PaddedPieceSize , error ) {
2929 spi , found := abi .SealProofInfos [proofType ]
3030 if ! found {
31- return cid .Undef , fmt .Errorf ("unknown seal proof type %d" , proofType )
31+ return cid .Undef , 0 , fmt .Errorf ("unknown seal proof type %d" , proofType )
3232 }
3333 if len (pieceInfos ) == 0 {
34- return cid .Undef , errors .New ("no pieces provided" )
34+ return cid .Undef , 0 , errors .New ("no pieces provided" )
3535 }
3636
3737 maxSize := uint64 (spi .SectorSize )
@@ -41,18 +41,18 @@ func PieceAggregateCommP(proofType abi.RegisteredSealProof, pieceInfos []abi.Pie
4141 // sancheck everything
4242 for i , p := range pieceInfos {
4343 if p .Size < 128 {
44- return cid .Undef , fmt .Errorf ("invalid Size of PieceInfo %d: value %d is too small" , i , p .Size )
44+ return cid .Undef , 0 , fmt .Errorf ("invalid Size of PieceInfo %d: value %d is too small" , i , p .Size )
4545 }
4646 if uint64 (p .Size ) > maxSize {
47- return cid .Undef , fmt .Errorf ("invalid Size of PieceInfo %d: value %d is larger than sector size of SealProofType %d" , i , p .Size , proofType )
47+ return cid .Undef , 0 , fmt .Errorf ("invalid Size of PieceInfo %d: value %d is larger than sector size of SealProofType %d" , i , p .Size , proofType )
4848 }
4949 if bits .OnesCount64 (uint64 (p .Size )) != 1 {
50- return cid .Undef , fmt .Errorf ("invalid Size of PieceInfo %d: value %d is not a power of 2" , i , p .Size )
50+ return cid .Undef , 0 , fmt .Errorf ("invalid Size of PieceInfo %d: value %d is not a power of 2" , i , p .Size )
5151 }
5252
5353 cp , err := commcid .CIDToPieceCommitmentV1 (p .PieceCID )
5454 if err != nil {
55- return cid .Undef , fmt .Errorf ("invalid PieceCid for PieceInfo %d: %w" , i , err )
55+ return cid .Undef , 0 , fmt .Errorf ("invalid PieceCid for PieceInfo %d: %w" , i , err )
5656 }
5757 todo [i ] = stackFrame {size : uint64 (p .Size ), commP : cp }
5858 }
@@ -106,10 +106,12 @@ func PieceAggregateCommP(proofType abi.RegisteredSealProof, pieceInfos []abi.Pie
106106 }
107107
108108 if stack [0 ].size > maxSize {
109- return cid .Undef , fmt .Errorf ("provided pieces sum up to %d bytes, which is larger than sector size of SealProofType %d" , stack [0 ].size , proofType )
109+ return cid .Undef , 0 , fmt .Errorf ("provided pieces sum up to %d bytes, which is larger than sector size of SealProofType %d" , stack [0 ].size , proofType )
110110 }
111111
112- return commcid .PieceCommitmentV1ToCID (stack [0 ].commP )
112+ fincid , err := commcid .PieceCommitmentV1ToCID (stack [0 ].commP )
113+
114+ return fincid , abi .PaddedPieceSize (stack [0 ].size ), err
113115}
114116
115117var s256pool = sync.Pool {New : func () any { return sha256simd .New () }}
0 commit comments