2020-03-05 02:18:22 +00:00
|
|
|
package advmgr
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io"
|
|
|
|
|
2020-03-06 05:30:47 +00:00
|
|
|
storage2 "github.com/filecoin-project/specs-storage/storage"
|
2020-03-05 02:18:22 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"github.com/filecoin-project/go-sectorbuilder"
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/storage/sealmgr"
|
|
|
|
)
|
|
|
|
|
|
|
|
type localWorker struct {
|
2020-03-05 19:21:06 +00:00
|
|
|
scfg *sectorbuilder.Config
|
2020-03-05 02:18:22 +00:00
|
|
|
storage *storage
|
|
|
|
}
|
|
|
|
|
|
|
|
type localWorkerPathProvider struct {
|
|
|
|
w *localWorker
|
|
|
|
}
|
|
|
|
|
2020-03-06 05:30:47 +00:00
|
|
|
func (l *localWorkerPathProvider) AcquireSector(ctx context.Context, id abi.SectorNumber, existing sectorbuilder.SectorFileType, allocate sectorbuilder.SectorFileType, sealing bool) (sectorbuilder.SectorPaths, func(), error) {
|
2020-03-05 02:18:22 +00:00
|
|
|
mid, err := address.IDFromAddress(l.w.scfg.Miner)
|
|
|
|
if err != nil {
|
|
|
|
return sectorbuilder.SectorPaths{}, nil, xerrors.Errorf("get miner ID: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return l.w.storage.acquireSector(abi.ActorID(mid), id, existing, allocate, sealing)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *localWorker) sb() (sectorbuilder.Basic, error) {
|
2020-03-05 19:21:06 +00:00
|
|
|
return sectorbuilder.New(&localWorkerPathProvider{w: l}, l.scfg)
|
2020-03-05 02:18:22 +00:00
|
|
|
}
|
|
|
|
|
2020-03-06 05:30:47 +00:00
|
|
|
func (l *localWorker) AddPiece(ctx context.Context, sn abi.SectorNumber, epcs []abi.UnpaddedPieceSize, sz abi.UnpaddedPieceSize, r io.Reader) (abi.PieceInfo, error) {
|
2020-03-05 02:18:22 +00:00
|
|
|
sb, err := l.sb()
|
|
|
|
if err != nil {
|
|
|
|
return abi.PieceInfo{}, err
|
|
|
|
}
|
|
|
|
|
2020-03-06 05:30:47 +00:00
|
|
|
return sb.AddPiece(ctx, sn, epcs, sz, r)
|
2020-03-05 02:18:22 +00:00
|
|
|
}
|
|
|
|
|
2020-03-06 05:30:47 +00:00
|
|
|
func (l *localWorker) SealPreCommit1(ctx context.Context, sectorNum abi.SectorNumber, ticket abi.SealRandomness, pieces []abi.PieceInfo) (out storage2.PreCommit1Out, err error) {
|
2020-03-05 18:18:33 +00:00
|
|
|
sb, err := l.sb()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return sb.SealPreCommit1(ctx, sectorNum, ticket, pieces)
|
2020-03-05 02:18:22 +00:00
|
|
|
}
|
|
|
|
|
2020-03-06 05:30:47 +00:00
|
|
|
func (l *localWorker) SealPreCommit2(ctx context.Context, sectorNum abi.SectorNumber, phase1Out storage2.PreCommit1Out) (sealedCID cid.Cid, unsealedCID cid.Cid, err error) {
|
2020-03-05 18:18:33 +00:00
|
|
|
sb, err := l.sb()
|
|
|
|
if err != nil {
|
|
|
|
return cid.Undef, cid.Undef, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return sb.SealPreCommit2(ctx, sectorNum, phase1Out)
|
2020-03-05 02:18:22 +00:00
|
|
|
}
|
|
|
|
|
2020-03-06 05:30:47 +00:00
|
|
|
func (l *localWorker) SealCommit1(ctx context.Context, sectorNum abi.SectorNumber, ticket abi.SealRandomness, seed abi.InteractiveSealRandomness, pieces []abi.PieceInfo, sealedCID cid.Cid, unsealedCID cid.Cid) (output storage2.Commit1Out, err error) {
|
2020-03-05 18:18:33 +00:00
|
|
|
sb, err := l.sb()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return sb.SealCommit1(ctx, sectorNum, ticket, seed, pieces, sealedCID, unsealedCID)
|
2020-03-05 02:18:22 +00:00
|
|
|
}
|
|
|
|
|
2020-03-06 05:30:47 +00:00
|
|
|
func (l *localWorker) SealCommit2(ctx context.Context, sectorNum abi.SectorNumber, phase1Out storage2.Commit1Out) (proof storage2.Proof, err error) {
|
2020-03-05 18:18:33 +00:00
|
|
|
sb, err := l.sb()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return sb.SealCommit2(ctx, sectorNum, phase1Out)
|
2020-03-05 02:18:22 +00:00
|
|
|
}
|
|
|
|
|
2020-03-05 18:18:33 +00:00
|
|
|
func (l *localWorker) FinalizeSector(ctx context.Context, sectorNum abi.SectorNumber) error {
|
|
|
|
sb, err := l.sb()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return sb.FinalizeSector(ctx, sectorNum)
|
2020-03-05 02:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (l *localWorker) TaskTypes() map[sealmgr.TaskType]struct{} {
|
|
|
|
return map[sealmgr.TaskType]struct{}{
|
2020-03-05 19:21:06 +00:00
|
|
|
sealmgr.TTAddPiece: {},
|
2020-03-05 02:18:22 +00:00
|
|
|
sealmgr.TTPreCommit1: {},
|
|
|
|
sealmgr.TTPreCommit2: {},
|
2020-03-05 19:21:06 +00:00
|
|
|
sealmgr.TTCommit2: {},
|
2020-03-05 02:18:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *localWorker) Paths() []Path {
|
|
|
|
return l.storage.local()
|
|
|
|
}
|
|
|
|
|
2020-03-05 19:21:06 +00:00
|
|
|
var _ Worker = &localWorker{}
|