2020-01-15 20:49:11 +00:00
|
|
|
package sealing
|
2019-11-01 23:43:54 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
2020-02-23 00:47:47 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
2020-01-25 11:15:28 +00:00
|
|
|
|
2020-02-28 18:01:43 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2020-02-27 00:54:39 +00:00
|
|
|
"github.com/filecoin-project/lotus/lib/nullreader"
|
|
|
|
)
|
2020-01-25 11:15:28 +00:00
|
|
|
|
2020-02-23 00:47:47 +00:00
|
|
|
func (m *Sealing) pledgeReader(size abi.UnpaddedPieceSize) io.Reader {
|
2020-02-27 00:54:39 +00:00
|
|
|
return io.LimitReader(&nullreader.Reader{}, int64(size))
|
2020-01-25 11:15:28 +00:00
|
|
|
}
|
|
|
|
|
2020-02-08 02:18:32 +00:00
|
|
|
func (m *Sealing) pledgeSector(ctx context.Context, sectorID abi.SectorNumber, existingPieceSizes []abi.UnpaddedPieceSize, sizes ...abi.UnpaddedPieceSize) ([]Piece, error) {
|
2019-11-07 19:54:24 +00:00
|
|
|
if len(sizes) == 0 {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2020-01-31 19:22:31 +00:00
|
|
|
log.Infof("Pledge %d, contains %+v", sectorID, existingPieceSizes)
|
|
|
|
|
|
|
|
out := make([]Piece, len(sizes))
|
2019-11-06 23:09:48 +00:00
|
|
|
for i, size := range sizes {
|
2020-03-06 05:30:47 +00:00
|
|
|
ppi, err := m.sealer.AddPiece(ctx, sectorID, existingPieceSizes, size, m.pledgeReader(size))
|
2019-11-01 23:43:54 +00:00
|
|
|
if err != nil {
|
2020-01-28 23:08:02 +00:00
|
|
|
return nil, xerrors.Errorf("add piece: %w", err)
|
2019-11-01 23:43:54 +00:00
|
|
|
}
|
|
|
|
|
2019-11-07 20:40:46 +00:00
|
|
|
existingPieceSizes = append(existingPieceSizes, size)
|
|
|
|
|
2019-11-07 18:22:59 +00:00
|
|
|
out[i] = Piece{
|
2020-02-27 00:42:39 +00:00
|
|
|
Size: ppi.Size.Unpadded(),
|
|
|
|
CommP: ppi.PieceCID,
|
2019-11-07 18:22:59 +00:00
|
|
|
}
|
2019-11-06 23:09:48 +00:00
|
|
|
}
|
|
|
|
|
2019-11-07 18:22:59 +00:00
|
|
|
return out, nil
|
2019-11-06 23:09:48 +00:00
|
|
|
}
|
|
|
|
|
2020-01-15 20:49:11 +00:00
|
|
|
func (m *Sealing) PledgeSector() error {
|
2019-11-06 23:09:48 +00:00
|
|
|
go func() {
|
2019-11-08 23:06:07 +00:00
|
|
|
ctx := context.TODO() // we can't use the context from command which invokes
|
|
|
|
// this, as we run everything here async, and it's cancelled when the
|
|
|
|
// command exits
|
|
|
|
|
2020-03-03 22:19:22 +00:00
|
|
|
size := abi.PaddedPieceSize(m.sealer.SectorSize()).Unpadded()
|
2019-11-06 23:09:48 +00:00
|
|
|
|
2020-03-05 18:18:33 +00:00
|
|
|
_, rt, err := api.ProofTypeFromSectorSize(m.sealer.SectorSize())
|
2020-02-28 18:01:43 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-03-03 22:19:22 +00:00
|
|
|
sid, err := m.sealer.NewSector()
|
2019-11-01 23:43:54 +00:00
|
|
|
if err != nil {
|
2019-11-06 23:09:48 +00:00
|
|
|
log.Errorf("%+v", err)
|
2019-11-01 23:43:54 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-02-22 13:10:46 +00:00
|
|
|
pieces, err := m.pledgeSector(ctx, sid, []abi.UnpaddedPieceSize{}, size)
|
2019-11-07 18:22:59 +00:00
|
|
|
if err != nil {
|
2019-11-06 23:09:48 +00:00
|
|
|
log.Errorf("%+v", err)
|
2019-11-01 23:43:54 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-02-28 18:01:43 +00:00
|
|
|
if err := m.newSector(sid, rt, pieces); err != nil {
|
2019-11-07 18:22:59 +00:00
|
|
|
log.Errorf("%+v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
return nil
|
2019-11-01 23:43:54 +00:00
|
|
|
}
|