Skip to content

Commit

Permalink
attempt to do better padding on pieces being written into sectors
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping committed Apr 7, 2021
1 parent a40fb1e commit cbe9bc3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion extern/sector-storage/ffiwrapper/sealer_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,32 @@ func (sb *Sealer) AddPiece(ctx context.Context, sector storage.SectorRef, existi
return piecePromises[0]()
}

var payloadRoundedBytes abi.PaddedPieceSize
pieceCids := make([]abi.PieceInfo, len(piecePromises))
for i, promise := range piecePromises {
pieceCids[i], err = promise()
pinfo, err := promise()
if err != nil {
return abi.PieceInfo{}, err
}

pieceCids[i] = pinfo
payloadRoundedBytes += pinfo.Size
}

pieceCID, err := ffi.GenerateUnsealedCID(sector.ProofType, pieceCids)
if err != nil {
return abi.PieceInfo{}, xerrors.Errorf("generate unsealed CID: %w", err)
}

if payloadRoundedBytes < pieceSize.Padded() {
paddedCid, err := commpffi.ZeroPadPieceCommitment(pieceCID, payloadRoundedBytes.Unpadded(), pieceSize)
if err != nil {
return abi.PieceInfo{}, xerrors.Errorf("failed to pad data: %w", err)
}

pieceCID = paddedCid
}

// validate that the pieceCID was properly formed
if _, err := commcid.CIDToPieceCommitmentV1(pieceCID); err != nil {
return abi.PieceInfo{}, err
Expand Down

0 comments on commit cbe9bc3

Please sign in to comment.