v25
This commit is contained in:
parent
a6d0938385
commit
e854090bdd
2
extern/filecoin-ffi
vendored
2
extern/filecoin-ffi
vendored
@ -1 +1 @@
|
||||
Subproject commit e899cc1dd0720e0a4d25b0e751b84e3733cbedc5
|
||||
Subproject commit 0f03c5a6b8c57f7c008e0d9b18dbd37b576ca836
|
@ -9,7 +9,6 @@ import (
|
||||
|
||||
type Config struct {
|
||||
SealProofType abi.RegisteredProof
|
||||
PoStProofType abi.RegisteredProof
|
||||
|
||||
_ struct{} // guard against nameless init
|
||||
}
|
||||
@ -19,25 +18,8 @@ func sizeFromConfig(cfg Config) (abi.SectorSize, error) {
|
||||
return abi.SectorSize(0), xerrors.New("must specify a seal proof type from abi.RegisteredProof")
|
||||
}
|
||||
|
||||
if cfg.PoStProofType == abi.RegisteredProof(0) {
|
||||
return abi.SectorSize(0), xerrors.New("must specify a PoSt proof type from abi.RegisteredProof")
|
||||
}
|
||||
|
||||
s1, err := SectorSizeForRegisteredProof(cfg.SealProofType)
|
||||
if err != nil {
|
||||
return abi.SectorSize(0), err
|
||||
}
|
||||
|
||||
s2, err := SectorSizeForRegisteredProof(cfg.PoStProofType)
|
||||
if err != nil {
|
||||
return abi.SectorSize(0), err
|
||||
}
|
||||
|
||||
if s1 != s2 {
|
||||
return abi.SectorSize(0), xerrors.Errorf("seal sector size %d does not equal PoSt sector size %d", s1, s2)
|
||||
}
|
||||
|
||||
return s1, nil
|
||||
return SectorSizeForRegisteredProof(cfg.SealProofType)
|
||||
}
|
||||
|
||||
// TODO: remove this method after implementing it along side the registered proofs and importing it from there.
|
||||
|
@ -1,18 +0,0 @@
|
||||
package ffiwrapper
|
||||
|
||||
// /////
|
||||
// Proofs
|
||||
|
||||
// 1 / n
|
||||
const SectorChallengeRatioDiv = 25
|
||||
|
||||
const MaxFallbackPostChallengeCount = 10
|
||||
|
||||
// extracted from lotus/chain/types/blockheader
|
||||
func ElectionPostChallengeCount(sectors uint64, faults uint64) uint64 {
|
||||
if sectors-faults == 0 {
|
||||
return 0
|
||||
}
|
||||
// ceil(sectors / SectorChallengeRatioDiv)
|
||||
return (sectors-faults-1)/SectorChallengeRatioDiv + 1
|
||||
}
|
@ -9,21 +9,12 @@ var log = logging.Logger("ffiwrapper")
|
||||
|
||||
type Sealer struct {
|
||||
sealProofType abi.RegisteredProof
|
||||
postProofType abi.RegisteredProof
|
||||
ssize abi.SectorSize // a function of sealProofType and postProofType
|
||||
|
||||
sectors SectorProvider
|
||||
stopping chan struct{}
|
||||
}
|
||||
|
||||
func fallbackPostChallengeCount(sectors uint64, faults uint64) uint64 {
|
||||
challengeCount := ElectionPostChallengeCount(sectors, faults)
|
||||
if challengeCount > MaxFallbackPostChallengeCount {
|
||||
return MaxFallbackPostChallengeCount
|
||||
}
|
||||
return challengeCount
|
||||
}
|
||||
|
||||
func (sb *Sealer) Stop() {
|
||||
close(sb.stopping)
|
||||
}
|
||||
@ -35,7 +26,3 @@ func (sb *Sealer) SectorSize() abi.SectorSize {
|
||||
func (sb *Sealer) SealProofType() abi.RegisteredProof {
|
||||
return sb.sealProofType
|
||||
}
|
||||
|
||||
func (sb *Sealer) PoStProofType() abi.RegisteredProof {
|
||||
return sb.postProofType
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ func New(sectors SectorProvider, cfg *Config) (*Sealer, error) {
|
||||
|
||||
sb := &Sealer{
|
||||
sealProofType: cfg.SealProofType,
|
||||
postProofType: cfg.PoStProofType,
|
||||
ssize: sectorSize,
|
||||
|
||||
sectors: sectors,
|
||||
@ -291,7 +290,7 @@ func (sb *Sealer) FinalizeSector(ctx context.Context, sector abi.SectorID) error
|
||||
}
|
||||
defer done()
|
||||
|
||||
return ffi.ClearCache(paths.Cache)
|
||||
return ffi.ClearCache(uint64(sb.ssize), paths.Cache)
|
||||
}
|
||||
|
||||
func GeneratePieceCIDFromFile(proofType abi.RegisteredProof, piece io.Reader, pieceSize abi.UnpaddedPieceSize) (cid.Cid, error) {
|
||||
|
@ -35,8 +35,8 @@ type Storage interface {
|
||||
|
||||
type Verifier interface {
|
||||
VerifySeal(abi.SealVerifyInfo) (bool, error)
|
||||
VerifyElectionPost(ctx context.Context, info abi.PoStVerifyInfo) (bool, error)
|
||||
VerifyFallbackPost(ctx context.Context, info abi.PoStVerifyInfo) (bool, error)
|
||||
VerifyWinningPoSt(ctx context.Context, info abi.WinningPoStVerifyInfo) (bool, error)
|
||||
VerifyWindowPoSt(ctx context.Context, info abi.WindowPoStVerifyInfo) (bool, error)
|
||||
}
|
||||
|
||||
var ErrSectorNotFound = errors.New("sector not found")
|
||||
|
@ -10,78 +10,36 @@ import (
|
||||
|
||||
ffi "github.com/filecoin-project/filecoin-ffi"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/filecoin-project/specs-storage/storage"
|
||||
|
||||
"github.com/filecoin-project/sector-storage/stores"
|
||||
)
|
||||
|
||||
func (sb *Sealer) ComputeElectionPoSt(ctx context.Context, miner abi.ActorID, sectorInfo []abi.SectorInfo, challengeSeed abi.PoStRandomness, winners []abi.PoStCandidate) ([]abi.PoStProof, error) {
|
||||
challengeSeed[31] = 0
|
||||
func (sb *Sealer) GenerateWinningPoStSectorChallenge(ctx context.Context, proofType abi.RegisteredProof, minerID abi.ActorID, randomness abi.PoStRandomness, eligibleSectorCount uint64) ([]uint64, error) {
|
||||
randomness[31] = 0 // TODO: Not correct, fixme
|
||||
return ffi.GenerateWinningPoStSectorChallenge(proofType, minerID, randomness, eligibleSectorCount)
|
||||
}
|
||||
|
||||
privsects, err := sb.pubSectorToPriv(ctx, miner, sectorInfo, nil) // TODO: faults
|
||||
func (sb *Sealer) GenerateWinningPoSt(ctx context.Context, minerID abi.ActorID, sectorInfo []abi.SectorInfo, randomness abi.PoStRandomness) ([]abi.PoStProof, error) {
|
||||
randomness[31] = 0 // TODO: Not correct, fixme
|
||||
privsectors, err := sb.pubSectorToPriv(ctx, minerID, sectorInfo, nil, abi.RegisteredProof.RegisteredWinningPoStProof) // TODO: FAULTS?
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ffi.GeneratePoSt(miner, privsects, challengeSeed, winners)
|
||||
return ffi.GenerateWinningPoSt(minerID, privsectors, randomness)
|
||||
}
|
||||
|
||||
func (sb *Sealer) GenerateFallbackPoSt(ctx context.Context, miner abi.ActorID, sectorInfo []abi.SectorInfo, challengeSeed abi.PoStRandomness, faults []abi.SectorNumber) (storage.FallbackPostOut, error) {
|
||||
privsectors, err := sb.pubSectorToPriv(ctx, miner, sectorInfo, faults)
|
||||
if err != nil {
|
||||
return storage.FallbackPostOut{}, err
|
||||
}
|
||||
|
||||
challengeCount := fallbackPostChallengeCount(uint64(len(sectorInfo)), uint64(len(faults)))
|
||||
challengeSeed[31] = 0
|
||||
|
||||
candidates, err := ffi.GenerateCandidates(miner, challengeSeed, challengeCount, privsectors)
|
||||
if err != nil {
|
||||
return storage.FallbackPostOut{}, err
|
||||
}
|
||||
|
||||
winners := make([]abi.PoStCandidate, len(candidates))
|
||||
for idx := range winners {
|
||||
winners[idx] = candidates[idx].Candidate
|
||||
}
|
||||
|
||||
proof, err := ffi.GeneratePoSt(miner, privsectors, challengeSeed, winners)
|
||||
return storage.FallbackPostOut{
|
||||
PoStInputs: ffiToStorageCandidates(candidates),
|
||||
Proof: proof,
|
||||
}, err
|
||||
}
|
||||
|
||||
func (sb *Sealer) GenerateEPostCandidates(ctx context.Context, miner abi.ActorID, sectorInfo []abi.SectorInfo, challengeSeed abi.PoStRandomness, faults []abi.SectorNumber) ([]storage.PoStCandidateWithTicket, error) {
|
||||
privsectors, err := sb.pubSectorToPriv(ctx, miner, sectorInfo, faults)
|
||||
func (sb *Sealer) GenerateWindowPoSt(ctx context.Context, minerID abi.ActorID, sectorInfo []abi.SectorInfo, randomness abi.PoStRandomness) ([]abi.PoStProof, error) {
|
||||
randomness[31] = 0 // TODO: Not correct, fixme
|
||||
privsectors, err := sb.pubSectorToPriv(ctx, minerID, sectorInfo, nil, abi.RegisteredProof.RegisteredWindowPoStProof) // TODO: FAULTS?
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
challengeSeed[31] = 0
|
||||
|
||||
challengeCount := ElectionPostChallengeCount(uint64(len(sectorInfo)), uint64(len(faults)))
|
||||
pc, err := ffi.GenerateCandidates(miner, challengeSeed, challengeCount, privsectors)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ffiToStorageCandidates(pc), nil
|
||||
return ffi.GenerateWindowPoSt(minerID, privsectors, randomness)
|
||||
}
|
||||
|
||||
func ffiToStorageCandidates(pc []ffi.PoStCandidateWithTicket) []storage.PoStCandidateWithTicket {
|
||||
out := make([]storage.PoStCandidateWithTicket, len(pc))
|
||||
for i := range out {
|
||||
out[i] = storage.PoStCandidateWithTicket{
|
||||
Candidate: pc[i].Candidate,
|
||||
Ticket: pc[i].Ticket,
|
||||
}
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
func (sb *Sealer) pubSectorToPriv(ctx context.Context, mid abi.ActorID, sectorInfo []abi.SectorInfo, faults []abi.SectorNumber) (ffi.SortedPrivateSectorInfo, error) {
|
||||
func (sb *Sealer) pubSectorToPriv(ctx context.Context, mid abi.ActorID, sectorInfo []abi.SectorInfo, faults []abi.SectorNumber, rpt func(abi.RegisteredProof) (abi.RegisteredProof, error)) (ffi.SortedPrivateSectorInfo, error) {
|
||||
fmap := map[abi.SectorNumber]struct{}{}
|
||||
for _, fault := range faults {
|
||||
fmap[fault] = struct{}{}
|
||||
@ -99,7 +57,7 @@ func (sb *Sealer) pubSectorToPriv(ctx context.Context, mid abi.ActorID, sectorIn
|
||||
}
|
||||
done() // TODO: This is a tiny bit suboptimal
|
||||
|
||||
postProofType, err := s.RegisteredProof.RegisteredPoStProof()
|
||||
postProofType, err := rpt(s.RegisteredProof)
|
||||
if err != nil {
|
||||
return ffi.SortedPrivateSectorInfo{}, xerrors.Errorf("acquiring registered PoSt proof from sector info %+v: %w", s, err)
|
||||
}
|
||||
@ -125,19 +83,18 @@ func (proofVerifier) VerifySeal(info abi.SealVerifyInfo) (bool, error) {
|
||||
return ffi.VerifySeal(info)
|
||||
}
|
||||
|
||||
func (proofVerifier) VerifyElectionPost(ctx context.Context, info abi.PoStVerifyInfo) (bool, error) {
|
||||
return verifyPost(ctx, info)
|
||||
}
|
||||
|
||||
func (proofVerifier) VerifyFallbackPost(ctx context.Context, info abi.PoStVerifyInfo) (bool, error) {
|
||||
return verifyPost(ctx, info)
|
||||
}
|
||||
|
||||
func verifyPost(ctx context.Context, info abi.PoStVerifyInfo) (bool, error) {
|
||||
_, span := trace.StartSpan(ctx, "VerifyPoSt")
|
||||
func (proofVerifier) VerifyWinningPoSt(ctx context.Context, info abi.WinningPoStVerifyInfo) (bool, error) {
|
||||
info.Randomness[31] = 0 // TODO: Not correct, fixme
|
||||
_, span := trace.StartSpan(ctx, "VerifyWinningPoSt")
|
||||
defer span.End()
|
||||
|
||||
info.Randomness[31] = 0
|
||||
|
||||
return ffi.VerifyPoSt(info)
|
||||
return ffi.VerifyWinningPoSt(info)
|
||||
}
|
||||
|
||||
func (proofVerifier) VerifyWindowPoSt(ctx context.Context, info abi.WindowPoStVerifyInfo) (bool, error) {
|
||||
info.Randomness[31] = 0 // TODO: Not correct, fixme
|
||||
_, span := trace.StartSpan(ctx, "VerifyWindowPoSt")
|
||||
defer span.End()
|
||||
|
||||
return ffi.VerifyWindowPoSt(info)
|
||||
}
|
||||
|
2
go.mod
2
go.mod
@ -8,7 +8,7 @@ require (
|
||||
github.com/filecoin-project/go-fil-commcid v0.0.0-20200208005934-2b8bd03caca5
|
||||
github.com/filecoin-project/go-paramfetch v0.0.1
|
||||
github.com/filecoin-project/lotus v0.2.10
|
||||
github.com/filecoin-project/specs-actors v0.0.0-20200324235424-aef9b20a9fb1
|
||||
github.com/filecoin-project/specs-actors v0.0.0-20200409043918-e569f4a2f504
|
||||
github.com/filecoin-project/specs-storage v0.0.0-20200317225704-7420bc655c38
|
||||
github.com/gorilla/mux v1.7.4
|
||||
github.com/hashicorp/go-multierror v1.0.0
|
||||
|
2
go.sum
2
go.sum
@ -109,6 +109,8 @@ github.com/filecoin-project/specs-actors v0.0.0-20200226200336-94c9b92b2775/go.m
|
||||
github.com/filecoin-project/specs-actors v0.0.0-20200302223606-0eaf97b10aaf/go.mod h1:0HAWYrvajFHDgRaKbF0rl+IybVLZL5z4gQ8koCMPhoU=
|
||||
github.com/filecoin-project/specs-actors v0.0.0-20200324235424-aef9b20a9fb1 h1:IL6A1yAamz0HtLQEdZS57hnRZHPL11VIrQxMZ1Nn5hI=
|
||||
github.com/filecoin-project/specs-actors v0.0.0-20200324235424-aef9b20a9fb1/go.mod h1:5WngRgTN5Eo4+0SjCBqLzEr2l6Mj45DrP2606gBhqI0=
|
||||
github.com/filecoin-project/specs-actors v0.0.0-20200409043918-e569f4a2f504 h1:mwuAaqxKThl70+7FkGdFKVLdwaQZQ8XmscKdhSBBtnc=
|
||||
github.com/filecoin-project/specs-actors v0.0.0-20200409043918-e569f4a2f504/go.mod h1:mdJraXq5vMy0+/FqVQIrnNlpQ/Em6zeu06G/ltQ0/lA=
|
||||
github.com/filecoin-project/specs-storage v0.0.0-20200317225704-7420bc655c38 h1:ky+rfX3bG1TjOBLn14V674q+iwZpalyKzZxGRNzA11I=
|
||||
github.com/filecoin-project/specs-storage v0.0.0-20200317225704-7420bc655c38/go.mod h1:dUmzHS7izOD6HW3/JpzFrjxnptxbsHXBlO8puK2UzBk=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
|
@ -34,11 +34,6 @@ type LocalWorker struct {
|
||||
}
|
||||
|
||||
func NewLocalWorker(wcfg WorkerConfig, store stores.Store, local *stores.Local, sindex stores.SectorIndex) *LocalWorker {
|
||||
ppt, err := wcfg.SealProof.RegisteredPoStProof()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
acceptTasks := map[sealtasks.TaskType]struct{}{}
|
||||
for _, taskType := range wcfg.TaskTypes {
|
||||
acceptTasks[taskType] = struct{}{}
|
||||
@ -47,7 +42,6 @@ func NewLocalWorker(wcfg WorkerConfig, store stores.Store, local *stores.Local,
|
||||
return &LocalWorker{
|
||||
scfg: &ffiwrapper.Config{
|
||||
SealProofType: wcfg.SealProof,
|
||||
PoStProofType: ppt,
|
||||
},
|
||||
storage: store,
|
||||
localStore: local,
|
||||
|
Loading…
Reference in New Issue
Block a user