2020-01-15 20:49:11 +00:00
|
|
|
package sealing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2020-11-04 20:29:08 +00:00
|
|
|
"github.com/filecoin-project/specs-storage/storage"
|
2020-02-27 00:54:39 +00:00
|
|
|
)
|
2020-01-25 11:15:28 +00:00
|
|
|
|
2020-11-04 20:29:08 +00:00
|
|
|
func (m *Sealing) pledgeSector(ctx context.Context, sectorID storage.SectorRef, existingPieceSizes []abi.UnpaddedPieceSize, sizes ...abi.UnpaddedPieceSize) ([]abi.PieceInfo, error) {
|
2020-01-15 20:49:11 +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)
|
|
|
|
|
2020-04-07 21:44:33 +00:00
|
|
|
out := make([]abi.PieceInfo, len(sizes))
|
2020-01-15 20:49:11 +00:00
|
|
|
for i, size := range sizes {
|
2020-08-14 14:06:53 +00:00
|
|
|
ppi, err := m.sealer.AddPiece(ctx, sectorID, existingPieceSizes, size, NewNullReader(size))
|
2020-01-15 20:49:11 +00:00
|
|
|
if err != nil {
|
2020-01-28 23:08:02 +00:00
|
|
|
return nil, xerrors.Errorf("add piece: %w", err)
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
existingPieceSizes = append(existingPieceSizes, size)
|
|
|
|
|
2020-04-07 22:33:24 +00:00
|
|
|
out[i] = ppi
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Sealing) PledgeSector() error {
|
2020-08-18 17:26:17 +00:00
|
|
|
cfg, err := m.getConfig()
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting config: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.MaxSealingSectors > 0 {
|
|
|
|
if m.stats.curSealing() > cfg.MaxSealingSectors {
|
|
|
|
return xerrors.Errorf("too many sectors sealing (curSealing: %d, max: %d)", m.stats.curSealing(), cfg.MaxSealingSectors)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-15 20:49:11 +00:00
|
|
|
go func() {
|
|
|
|
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-11-04 20:29:08 +00:00
|
|
|
spt, err := m.currentSealProof(ctx)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("%+v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
size, err := spt.SectorSize()
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("%+v", err)
|
|
|
|
return
|
|
|
|
}
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2020-03-17 20:19:52 +00:00
|
|
|
sid, err := m.sc.Next()
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("%+v", err)
|
|
|
|
return
|
|
|
|
}
|
2020-11-04 20:29:08 +00:00
|
|
|
sectorID := m.minerSector(spt, sid)
|
2020-11-08 08:24:50 +00:00
|
|
|
err = m.sealer.NewSector(ctx, sectorID)
|
2020-01-15 20:49:11 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("%+v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-04 20:29:08 +00:00
|
|
|
pieces, err := m.pledgeSector(ctx, sectorID, []abi.UnpaddedPieceSize{}, abi.PaddedPieceSize(size).Unpadded())
|
2020-01-15 20:49:11 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("%+v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-04-08 14:56:35 +00:00
|
|
|
ps := make([]Piece, len(pieces))
|
|
|
|
for idx := range ps {
|
|
|
|
ps[idx] = Piece{
|
2020-04-07 21:44:33 +00:00
|
|
|
Piece: pieces[idx],
|
|
|
|
DealInfo: nil,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-04 20:29:08 +00:00
|
|
|
if err := m.newSectorCC(ctx, sid, ps); err != nil {
|
2020-01-15 20:49:11 +00:00
|
|
|
log.Errorf("%+v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
return nil
|
|
|
|
}
|