Begin work on integrating new sectorbuilder interfaces

This commit is contained in:
Łukasz Magiera 2020-02-28 18:17:40 +01:00
parent 4dc35285dd
commit d5b8defcbb
3 changed files with 32 additions and 71 deletions

2
go.mod
View File

@ -21,7 +21,7 @@ require (
github.com/filecoin-project/go-fil-markets v0.0.0-20200227194154-8ef88c730c81
github.com/filecoin-project/go-padreader v0.0.0-20200210211231-548257017ca6
github.com/filecoin-project/go-paramfetch v0.0.2-0.20200218225740-47c639bab663
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200227214225-a550d0267977
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200228064721-be233370d8e9
github.com/filecoin-project/go-statestore v0.1.0
github.com/filecoin-project/specs-actors v0.0.0-20200226233922-9ed222007d11
github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1

2
go.sum
View File

@ -137,6 +137,8 @@ github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200227214127-332d57b390a
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200227214127-332d57b390aa/go.mod h1:u8n91UJUua9zEiyAPw8wRAgUEoyTH8BBM9LWJ5WuxOM=
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200227214225-a550d0267977 h1:Q4VnMiorS/AcZMDHtoi+7lVzkTj+qDa0bmgMkwmvxIM=
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200227214225-a550d0267977/go.mod h1:tzTc9BxxSbjlIzhFwm5h9oBkXKkRuLxeiWspntwnKyw=
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200228064721-be233370d8e9 h1:P4IMEn3GDtAJzIVL/DqwHH8jotvafn6FLuxFhUNKhEI=
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200228064721-be233370d8e9/go.mod h1:gEQJVRVqQX8Vx02IosTdC2UA4l2MgHfG3POJEI2GIpc=
github.com/filecoin-project/go-statemachine v0.0.0-20200226041606-2074af6d51d9 h1:k9qVR9ItcziSB2rxtlkN/MDWNlbsI6yzec+zjUatLW0=
github.com/filecoin-project/go-statemachine v0.0.0-20200226041606-2074af6d51d9/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig=
github.com/filecoin-project/go-statestore v0.1.0 h1:t56reH59843TwXHkMcwyuayStBIiWBRilQjQ+5IiwdQ=

View File

@ -10,13 +10,13 @@ import (
"math/rand"
"sync"
ffi "github.com/filecoin-project/filecoin-ffi"
commcid "github.com/filecoin-project/go-fil-commcid"
"github.com/filecoin-project/go-sectorbuilder"
"github.com/filecoin-project/go-sectorbuilder/fs"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/ipfs/go-cid"
"golang.org/x/xerrors"
ffi "github.com/filecoin-project/filecoin-ffi"
)
type SBMock struct {
@ -102,40 +102,16 @@ func (sb *SBMock) AcquireSectorNumber() (abi.SectorNumber, error) {
return id, nil
}
func (sb *SBMock) Scrub([]abi.SectorNumber) []*sectorbuilder.Fault {
sb.lk.Lock()
mcopy := make(map[abi.SectorNumber]*sectorState)
for k, v := range sb.sectors {
mcopy[k] = v
}
sb.lk.Unlock()
var out []*sectorbuilder.Fault
for sid, ss := range mcopy {
ss.lk.Lock()
if ss.failed {
out = append(out, &sectorbuilder.Fault{
SectorNum: sid,
Err: fmt.Errorf("mock sector failed"),
})
}
ss.lk.Unlock()
}
return out
}
func (sb *SBMock) GenerateFallbackPoSt([]abi.SectorInfo, abi.PoStRandomness, []abi.SectorNumber) ([]ffi.PoStCandidateWithTicket, []abi.PoStProof, error) {
panic("NYI")
}
func (sb *SBMock) SealPreCommit(ctx context.Context, sid abi.SectorNumber, ticket abi.SealRandomness, pieces []abi.PieceInfo) (cid.Cid, cid.Cid, error) {
func (sb *SBMock) SealPreCommit1(ctx context.Context, sid abi.SectorNumber, ticket abi.SealRandomness, pieces []abi.PieceInfo) (out []byte, err error) {
sb.lk.Lock()
ss, ok := sb.sectors[sid]
sb.lk.Unlock()
if !ok {
return cid.Undef, cid.Undef, xerrors.Errorf("no sector with id %d in sectorbuilder", sid)
return nil, xerrors.Errorf("no sector with id %d in sectorbuilder", sid)
}
ss.lk.Lock()
@ -151,11 +127,11 @@ func (sb *SBMock) SealPreCommit(ctx context.Context, sid abi.SectorNumber, ticke
}
if sum != ussize {
return cid.Undef, cid.Undef, xerrors.Errorf("aggregated piece sizes don't match up: %d != %d", sum, ussize)
return nil, xerrors.Errorf("aggregated piece sizes don't match up: %d != %d", sum, ussize)
}
if ss.state != statePacking {
return cid.Undef, cid.Undef, xerrors.Errorf("cannot call pre-seal on sector not in 'packing' state")
return nil, xerrors.Errorf("cannot call pre-seal on sector not in 'packing' state")
}
opFinishWait(ctx)
@ -172,25 +148,35 @@ func (sb *SBMock) SealPreCommit(ctx context.Context, sid abi.SectorNumber, ticke
commd, err := MockVerifier.GenerateDataCommitment(abi.PaddedPieceSize(sb.sectorSize), pis)
if err != nil {
return cid.Undef, cid.Undef, err
return nil, err
}
cc, _, err := commcid.CIDToCommitment(commd)
if err != nil {
panic(err)
}
cc[0] ^= 'd'
return cc, nil
}
func (sb *SBMock) SealPreCommit2(ctx context.Context, sid abi.SectorNumber, phase1Out []byte) (sealedCID cid.Cid, unsealedCID cid.Cid, err error) {
db := []byte(string(phase1Out[0]))
db[0] ^= 'd'
d := commcid.DataCommitmentV1ToCID(db)
commr := make([]byte, 32)
for i := range cc {
commr[32-(i+1)] = cc[i]
for i := range db {
commr[32-(i+1)] = db[i]
}
commR := commcid.DataCommitmentV1ToCID(commr)
return commd, commR, nil
return commR, d, nil
}
func (sb *SBMock) SealCommit(ctx context.Context, sid abi.SectorNumber, ticket abi.SealRandomness, seed abi.InteractiveSealRandomness, pieces []abi.PieceInfo, sealedCid cid.Cid, unsealed cid.Cid) ([]byte, error) {
func (sb *SBMock) SealCommit1(ctx context.Context, sid abi.SectorNumber, ticket abi.SealRandomness, seed abi.InteractiveSealRandomness, pieces []abi.PieceInfo, sealedCid cid.Cid, unsealed cid.Cid) (output []byte, err error) {
sb.lk.Lock()
ss, ok := sb.sectors[sid]
sb.lk.Unlock()
@ -212,30 +198,19 @@ func (sb *SBMock) SealCommit(ctx context.Context, sid abi.SectorNumber, ticket a
var out [32]byte
for i := range out {
out[i] = unsealed.Bytes()[i] + sealedCid.Bytes()[31-i] - ticket[i]*seed[i]
out[i] = unsealed.Bytes()[i] + sealedCid.Bytes()[31-i] - ticket[i]*seed[i] ^ byte(sid & 0xff)
}
return out[:], nil
}
func (sb *SBMock) GetPath(string, string) (string, error) {
panic("nyi")
}
func (sb *SBMock) SealCommit2(ctx context.Context, sectorNum abi.SectorNumber, phase1Out []byte) (proof []byte, err error) {
var out [32]byte
for i := range out {
out[i] = phase1Out[i] ^ byte(sectorNum & 0xff)
}
func (sb *SBMock) CanCommit(sectorID abi.SectorNumber) (bool, error) {
return true, nil
}
func (sb *SBMock) WorkerStats() sectorbuilder.WorkerStats {
panic("nyi")
}
func (sb *SBMock) AddWorker(context.Context, sectorbuilder.WorkerCfg) (<-chan sectorbuilder.WorkerTask, error) {
panic("nyi")
}
func (sb *SBMock) TaskDone(context.Context, uint64, sectorbuilder.SealRes) error {
panic("nyi")
return out[:], nil
}
// Test Instrumentation Methods
@ -331,22 +306,6 @@ func (sb *SBMock) FinalizeSector(context.Context, abi.SectorNumber) error {
return nil
}
func (sb *SBMock) DropStaged(context.Context, abi.SectorNumber) error {
return nil
}
func (sb *SBMock) SectorPath(typ fs.DataType, sectorID abi.SectorNumber) (fs.SectorPath, error) {
panic("implement me")
}
func (sb *SBMock) AllocSectorPath(typ fs.DataType, sectorID abi.SectorNumber, cache bool) (fs.SectorPath, error) {
panic("implement me")
}
func (sb *SBMock) ReleaseSector(fs.DataType, fs.SectorPath) {
panic("implement me")
}
func (m mockVerif) VerifyElectionPost(ctx context.Context, pvi abi.PoStVerifyInfo) (bool, error) {
panic("implement me")
}
@ -383,4 +342,4 @@ func (m mockVerif) GenerateDataCommitment(ssize abi.PaddedPieceSize, pieces []ab
var MockVerifier = mockVerif{}
var _ sectorbuilder.Verifier = MockVerifier
var _ sectorbuilder.Interface = &SBMock{}
var _ sectorbuilder.Basic = &SBMock{}