51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package storage
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
|
|
"github.com/filecoin-project/go-sectorbuilder"
|
|
xerrors "golang.org/x/xerrors"
|
|
|
|
"github.com/filecoin-project/lotus/lib/padreader"
|
|
)
|
|
|
|
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")
|
|
}
|
|
|
|
sid, err := m.sb.AcquireSectorId() // TODO: Put more than one thing in a sector
|
|
if err != nil {
|
|
return 0, 0, xerrors.Errorf("acquiring sector ID: %w", err)
|
|
}
|
|
|
|
// 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{})
|
|
if err != nil {
|
|
return xerrors.Errorf("adding piece to sector: %w", err)
|
|
}
|
|
|
|
return m.newSector(ctx, sectorID, dealID, ppi)
|
|
}
|
|
|
|
func (m *Miner) newSector(ctx context.Context, sid uint64, dealID uint64, ppi sectorbuilder.PublicPieceInfo) error {
|
|
return m.sectors.Send(sid, SectorStart{
|
|
id: sid,
|
|
pieces: []Piece{
|
|
{
|
|
DealID: dealID,
|
|
|
|
Size: ppi.Size,
|
|
CommP: ppi.CommP[:],
|
|
},
|
|
},
|
|
})
|
|
}
|