lotus/storage/sealmgr/simple.go

122 lines
3.9 KiB
Go
Raw Normal View History

package sealmgr
import (
"context"
"io"
"sync"
"github.com/ipfs/go-cid"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-fil-markets/storedcounter"
"github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/specs-actors/actors/abi"
2020-03-06 05:30:47 +00:00
"github.com/filecoin-project/specs-storage/storage"
)
2020-03-05 02:18:22 +00:00
type LocalWorker struct {
sectorbuilder.Basic
}
var _ Worker = &LocalWorker{}
// Simple implements a very basic storage manager which has one local worker,
// running one thing locally
type Simple struct {
sc *storedcounter.StoredCounter
maddr address.Address
rateLimiter sync.Mutex
worker Worker
}
2020-03-05 22:27:30 +00:00
type sszgetter interface {
SectorSize() abi.SectorSize
}
2020-03-03 22:19:22 +00:00
func (s *Simple) SectorSize() abi.SectorSize {
2020-03-05 22:27:30 +00:00
return s.worker.(sszgetter).SectorSize()
2020-03-03 22:19:22 +00:00
}
2020-03-03 22:19:22 +00:00
func NewSimpleManager(sc *storedcounter.StoredCounter, maddr address.Address, sb sectorbuilder.Basic) (*Simple, error) {
w := &LocalWorker{
2020-03-03 22:19:22 +00:00
sb,
}
return &Simple{
sc: sc,
maddr: maddr,
worker: w,
}, nil
}
2020-03-03 22:19:22 +00:00
func (s *Simple) NewSector() (abi.SectorNumber, error) {
n, err := s.sc.Next()
if err != nil {
2020-03-03 22:19:22 +00:00
return 0, xerrors.Errorf("acquire sector number: %w", err)
}
2020-03-03 22:19:22 +00:00
return abi.SectorNumber(n), nil
}
2020-03-06 05:30:47 +00:00
func (s *Simple) AddPiece(ctx context.Context, sectorNum abi.SectorNumber, existingPieces []abi.UnpaddedPieceSize, sz abi.UnpaddedPieceSize, r storage.Data) (abi.PieceInfo, error) {
2020-03-03 22:19:22 +00:00
s.rateLimiter.Lock()
defer s.rateLimiter.Unlock()
2020-03-06 05:30:47 +00:00
return s.worker.AddPiece(ctx, sectorNum, existingPieces, sz, r)
}
2020-03-06 05:30:47 +00:00
func (s *Simple) SealPreCommit1(ctx context.Context, sectorNum abi.SectorNumber, ticket abi.SealRandomness, pieces []abi.PieceInfo) (out storage.PreCommit1Out, err error) {
s.rateLimiter.Lock()
defer s.rateLimiter.Unlock()
2020-03-03 22:19:22 +00:00
return s.worker.SealPreCommit1(ctx, sectorNum, ticket, pieces)
}
2020-03-06 05:30:47 +00:00
func (s *Simple) SealPreCommit2(ctx context.Context, sectorNum abi.SectorNumber, phase1Out storage.PreCommit1Out) (sealedCID cid.Cid, unsealedCID cid.Cid, err error) {
s.rateLimiter.Lock()
defer s.rateLimiter.Unlock()
2020-03-03 22:19:22 +00:00
return s.worker.SealPreCommit2(ctx, sectorNum, phase1Out)
}
2020-03-06 05:30:47 +00:00
func (s *Simple) SealCommit1(ctx context.Context, sectorNum abi.SectorNumber, ticket abi.SealRandomness, seed abi.InteractiveSealRandomness, pieces []abi.PieceInfo, sealedCID cid.Cid, unsealedCID cid.Cid) (output storage.Commit1Out, err error) {
2020-03-03 22:19:22 +00:00
s.rateLimiter.Lock()
defer s.rateLimiter.Unlock()
return s.worker.SealCommit1(ctx, sectorNum, ticket, seed, pieces, sealedCID, unsealedCID)
}
2020-03-06 05:30:47 +00:00
func (s *Simple) SealCommit2(ctx context.Context, sectorNum abi.SectorNumber, phase1Out storage.Commit1Out) (proof storage.Proof, err error) {
2020-03-03 22:19:22 +00:00
s.rateLimiter.Lock()
defer s.rateLimiter.Unlock()
return s.worker.SealCommit2(ctx, sectorNum, phase1Out)
}
func (s *Simple) FinalizeSector(ctx context.Context, sectorNum abi.SectorNumber) error {
s.rateLimiter.Lock()
defer s.rateLimiter.Unlock()
return s.worker.FinalizeSector(ctx, sectorNum)
}
2020-03-06 05:30:47 +00:00
func (s *Simple) GenerateEPostCandidates(sectorInfo []abi.SectorInfo, challengeSeed abi.PoStRandomness, faults []abi.SectorNumber) ([]storage.PoStCandidateWithTicket, error) {
2020-03-03 22:19:22 +00:00
return s.worker.GenerateEPostCandidates(sectorInfo, challengeSeed, faults)
}
2020-03-06 05:30:47 +00:00
func (s *Simple) GenerateFallbackPoSt(sectorInfo []abi.SectorInfo, challengeSeed abi.PoStRandomness, faults []abi.SectorNumber) ([]storage.PoStCandidateWithTicket, []abi.PoStProof, error) {
2020-03-03 22:19:22 +00:00
return s.worker.GenerateFallbackPoSt(sectorInfo, challengeSeed, faults)
}
func (s *Simple) ComputeElectionPoSt(sectorInfo []abi.SectorInfo, challengeSeed abi.PoStRandomness, winners []abi.PoStCandidate) ([]abi.PoStProof, error) {
2020-03-03 22:19:22 +00:00
return s.worker.ComputeElectionPoSt(sectorInfo, challengeSeed, winners)
}
func (s *Simple) ReadPieceFromSealedSector(context.Context, abi.SectorNumber, sectorbuilder.UnpaddedByteIndex, abi.UnpaddedPieceSize, abi.SealRandomness, cid.Cid) (io.ReadCloser, error) {
panic("todo")
}
var _ Manager = &Simple{}