2020-03-03 00:45:32 +00:00
|
|
|
package sealmgr
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io"
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-address"
|
|
|
|
"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-17 20:19:52 +00:00
|
|
|
"github.com/ipfs/go-cid"
|
2020-03-03 00:45:32 +00:00
|
|
|
)
|
|
|
|
|
2020-03-05 02:18:22 +00:00
|
|
|
type LocalWorker struct {
|
|
|
|
sectorbuilder.Basic
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ Worker = &LocalWorker{}
|
|
|
|
|
2020-03-03 00:45:32 +00:00
|
|
|
// Simple implements a very basic storage manager which has one local worker,
|
|
|
|
// running one thing locally
|
|
|
|
type Simple struct {
|
|
|
|
maddr address.Address
|
|
|
|
|
|
|
|
rateLimiter sync.Mutex
|
|
|
|
worker Worker
|
|
|
|
}
|
|
|
|
|
2020-03-05 22:27:30 +00:00
|
|
|
type sszgetter interface {
|
|
|
|
SectorSize() abi.SectorSize
|
|
|
|
}
|
|
|
|
|
2020-03-18 01:08:11 +00:00
|
|
|
func (s *LocalWorker) SectorSize() abi.SectorSize {
|
|
|
|
return s.Basic.(sszgetter).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 00:45:32 +00:00
|
|
|
|
2020-03-17 20:19:52 +00:00
|
|
|
func NewSimpleManager(maddr address.Address, sb sectorbuilder.Basic) (*Simple, error) {
|
2020-03-03 00:45:32 +00:00
|
|
|
w := &LocalWorker{
|
2020-03-03 22:19:22 +00:00
|
|
|
sb,
|
2020-03-03 00:45:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &Simple{
|
|
|
|
maddr: maddr,
|
|
|
|
worker: w,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-03-17 20:19:52 +00:00
|
|
|
func (s *Simple) NewSector(ctx context.Context, id abi.SectorID) error {
|
|
|
|
return s.worker.NewSector(ctx, id)
|
2020-03-03 22:19:22 +00:00
|
|
|
}
|
2020-03-03 00:45:32 +00:00
|
|
|
|
2020-03-17 20:19:52 +00:00
|
|
|
func (s *Simple) AddPiece(ctx context.Context, id abi.SectorID, 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-17 20:19:52 +00:00
|
|
|
return s.worker.AddPiece(ctx, id, existingPieces, sz, r)
|
2020-03-03 00:45:32 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 20:19:52 +00:00
|
|
|
func (s *Simple) SealPreCommit1(ctx context.Context, id abi.SectorID, ticket abi.SealRandomness, pieces []abi.PieceInfo) (out storage.PreCommit1Out, err error) {
|
2020-03-03 00:45:32 +00:00
|
|
|
s.rateLimiter.Lock()
|
|
|
|
defer s.rateLimiter.Unlock()
|
|
|
|
|
2020-03-17 20:19:52 +00:00
|
|
|
return s.worker.SealPreCommit1(ctx, id, ticket, pieces)
|
2020-03-03 00:45:32 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 20:19:52 +00:00
|
|
|
func (s *Simple) SealPreCommit2(ctx context.Context, id abi.SectorID, phase1Out storage.PreCommit1Out) (cids storage.SectorCids, err error) {
|
2020-03-03 00:45:32 +00:00
|
|
|
s.rateLimiter.Lock()
|
|
|
|
defer s.rateLimiter.Unlock()
|
|
|
|
|
2020-03-17 20:19:52 +00:00
|
|
|
return s.worker.SealPreCommit2(ctx, id, phase1Out)
|
2020-03-03 22:19:22 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 20:19:52 +00:00
|
|
|
func (s *Simple) SealCommit1(ctx context.Context, id abi.SectorID, ticket abi.SealRandomness, seed abi.InteractiveSealRandomness, pieces []abi.PieceInfo, cids storage.SectorCids) (output storage.Commit1Out, err error) {
|
2020-03-03 22:19:22 +00:00
|
|
|
s.rateLimiter.Lock()
|
|
|
|
defer s.rateLimiter.Unlock()
|
|
|
|
|
2020-03-17 20:19:52 +00:00
|
|
|
return s.worker.SealCommit1(ctx, id, ticket, seed, pieces, cids)
|
2020-03-03 22:19:22 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 20:19:52 +00:00
|
|
|
func (s *Simple) SealCommit2(ctx context.Context, id abi.SectorID, phase1Out storage.Commit1Out) (proof storage.Proof, err error) {
|
2020-03-03 22:19:22 +00:00
|
|
|
s.rateLimiter.Lock()
|
|
|
|
defer s.rateLimiter.Unlock()
|
|
|
|
|
2020-03-17 20:19:52 +00:00
|
|
|
return s.worker.SealCommit2(ctx, id, phase1Out)
|
2020-03-03 22:19:22 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 20:19:52 +00:00
|
|
|
func (s *Simple) FinalizeSector(ctx context.Context, id abi.SectorID) error {
|
2020-03-03 22:19:22 +00:00
|
|
|
s.rateLimiter.Lock()
|
|
|
|
defer s.rateLimiter.Unlock()
|
|
|
|
|
2020-03-17 20:19:52 +00:00
|
|
|
return s.worker.FinalizeSector(ctx, id)
|
2020-03-03 00:45:32 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 20:19:52 +00:00
|
|
|
func (s *Simple) GenerateEPostCandidates(ctx context.Context, miner abi.ActorID, sectorInfo []abi.SectorInfo, challengeSeed abi.PoStRandomness, faults []abi.SectorNumber) ([]storage.PoStCandidateWithTicket, error) {
|
|
|
|
return s.worker.GenerateEPostCandidates(ctx, miner, sectorInfo, challengeSeed, faults)
|
2020-03-03 00:45:32 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 20:19:52 +00:00
|
|
|
func (s *Simple) GenerateFallbackPoSt(ctx context.Context, miner abi.ActorID, sectorInfo []abi.SectorInfo, challengeSeed abi.PoStRandomness, faults []abi.SectorNumber) (storage.FallbackPostOut, error) {
|
|
|
|
return s.worker.GenerateFallbackPoSt(ctx, miner, sectorInfo, challengeSeed, faults)
|
2020-03-03 00:45:32 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 20:19:52 +00:00
|
|
|
func (s *Simple) ComputeElectionPoSt(ctx context.Context, miner abi.ActorID, sectorInfo []abi.SectorInfo, challengeSeed abi.PoStRandomness, winners []abi.PoStCandidate) ([]abi.PoStProof, error) {
|
|
|
|
return s.worker.ComputeElectionPoSt(ctx, miner, sectorInfo, challengeSeed, winners)
|
2020-03-03 22:19:22 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 20:19:52 +00:00
|
|
|
func (s *Simple) ReadPieceFromSealedSector(context.Context, abi.SectorID, sectorbuilder.UnpaddedByteIndex, abi.UnpaddedPieceSize, abi.SealRandomness, cid.Cid) (io.ReadCloser, error) {
|
2020-03-03 22:19:22 +00:00
|
|
|
panic("todo")
|
2020-03-03 00:45:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ Manager = &Simple{}
|