attempt to do better padding on pieces being written into sectors

This commit is contained in:
whyrusleeping 2021-04-07 15:14:14 -07:00
parent 7e25a811c3
commit 6daaf6ac2e

View File

@ -195,12 +195,16 @@ func (sb *Sealer) AddPiece(ctx context.Context, sector storage.SectorRef, existi
return piecePromises[0]() return piecePromises[0]()
} }
var payloadRoundedBytes abi.PaddedPieceSize
pieceCids := make([]abi.PieceInfo, len(piecePromises)) pieceCids := make([]abi.PieceInfo, len(piecePromises))
for i, promise := range piecePromises { for i, promise := range piecePromises {
pieceCids[i], err = promise() pinfo, err := promise()
if err != nil { if err != nil {
return abi.PieceInfo{}, err return abi.PieceInfo{}, err
} }
pieceCids[i] = pinfo
payloadRoundedBytes += pinfo.Size
} }
pieceCID, err := ffi.GenerateUnsealedCID(sector.ProofType, pieceCids) pieceCID, err := ffi.GenerateUnsealedCID(sector.ProofType, pieceCids)
@ -208,6 +212,15 @@ func (sb *Sealer) AddPiece(ctx context.Context, sector storage.SectorRef, existi
return abi.PieceInfo{}, xerrors.Errorf("generate unsealed CID: %w", err) 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 // validate that the pieceCID was properly formed
if _, err := commcid.CIDToPieceCommitmentV1(pieceCID); err != nil { if _, err := commcid.CIDToPieceCommitmentV1(pieceCID); err != nil {
return abi.PieceInfo{}, err return abi.PieceInfo{}, err