lotus/storage/sectors.go

51 lines
1.2 KiB
Go
Raw Normal View History

2019-10-31 18:46:53 +00:00
package storage
import (
"context"
2020-01-10 02:11:00 +00:00
"io"
2019-11-07 18:22:59 +00:00
2020-01-13 16:34:21 +00:00
"github.com/filecoin-project/go-sectorbuilder"
2019-11-01 22:05:05 +00:00
xerrors "golang.org/x/xerrors"
2019-11-07 18:22:59 +00:00
2019-12-02 12:51:16 +00:00
"github.com/filecoin-project/lotus/lib/padreader"
2019-10-31 18:46:53 +00:00
)
2019-12-01 17:58:31 +00:00
func (m *Miner) AllocatePiece(size uint64) (sectorID uint64, offset uint64, err error) {
if padreader.PaddedSize(size) != size {
return 0, 0, xerrors.Errorf("cannot allocate unpadded piece")
}
2019-11-01 22:44:55 +00:00
2019-11-07 18:22:59 +00:00
sid, err := m.sb.AcquireSectorId() // TODO: Put more than one thing in a sector
if err != nil {
2019-12-01 17:58:31 +00:00
return 0, 0, xerrors.Errorf("acquiring sector ID: %w", err)
2019-11-07 18:22:59 +00:00
}
2019-12-01 17:58:31 +00:00
// offset hard-coded to 0 since we only put one thing in a sector for now
return sid, 0, nil
}
func (m *Miner) SealPiece(ctx context.Context, size uint64, r io.Reader, sectorID uint64, dealID uint64) error {
log.Infof("Seal piece for deal %d", dealID)
ppi, err := m.sb.AddPiece(size, sectorID, r, []uint64{})
2019-11-07 18:22:59 +00:00
if err != nil {
2019-12-01 17:58:31 +00:00
return xerrors.Errorf("adding piece to sector: %w", err)
2019-11-07 18:22:59 +00:00
}
2019-12-01 17:58:31 +00:00
return m.newSector(ctx, sectorID, dealID, ppi)
2019-11-07 18:22:59 +00:00
}
2019-12-01 17:58:31 +00:00
func (m *Miner) newSector(ctx context.Context, sid uint64, dealID uint64, ppi sectorbuilder.PublicPieceInfo) error {
2020-01-10 02:11:00 +00:00
return m.sectors.Send(sid, SectorStart{
id: sid,
pieces: []Piece{
2019-11-07 18:22:59 +00:00
{
DealID: dealID,
2019-11-07 18:43:15 +00:00
Size: ppi.Size,
CommP: ppi.CommP[:],
2019-11-07 18:22:59 +00:00
},
},
2020-01-10 02:11:00 +00:00
})
2019-10-31 18:46:53 +00:00
}