Merge pull request #78 from filecoin-project/feat/mock-post
mock: More accurate WindowPost
This commit is contained in:
commit
7fafaf81c0
105
mock/mock.go
105
mock/mock.go
@ -5,7 +5,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"math/rand"
|
||||
"sync"
|
||||
|
||||
@ -34,14 +33,22 @@ type SectorMgr struct {
|
||||
|
||||
type mockVerif struct{}
|
||||
|
||||
func NewMockSectorMgr(ssize abi.SectorSize) *SectorMgr {
|
||||
func NewMockSectorMgr(ssize abi.SectorSize, genesisSectors []abi.SectorID) *SectorMgr {
|
||||
rt, err := ffiwrapper.SealProofTypeFromSectorSize(ssize)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
sectors := make(map[abi.SectorID]*sectorState)
|
||||
for _, sid := range genesisSectors {
|
||||
sectors[sid] = §orState{
|
||||
failed: false,
|
||||
state: stateCommit,
|
||||
}
|
||||
}
|
||||
|
||||
return &SectorMgr{
|
||||
sectors: make(map[abi.SectorID]*sectorState),
|
||||
sectors: sectors,
|
||||
pieces: map[cid.Cid][]byte{},
|
||||
sectorSize: ssize,
|
||||
nextSectorID: 5,
|
||||
@ -258,27 +265,57 @@ func AddOpFinish(ctx context.Context) (context.Context, func()) {
|
||||
}
|
||||
|
||||
func (mgr *SectorMgr) GenerateWinningPoSt(ctx context.Context, minerID abi.ActorID, sectorInfo []abi.SectorInfo, randomness abi.PoStRandomness) ([]abi.PoStProof, error) {
|
||||
return generateFakePoSt(sectorInfo, abi.RegisteredSealProof.RegisteredWinningPoStProof), nil
|
||||
return generateFakePoSt(sectorInfo, abi.RegisteredSealProof.RegisteredWinningPoStProof, randomness), nil
|
||||
}
|
||||
|
||||
func (mgr *SectorMgr) GenerateWindowPoSt(ctx context.Context, minerID abi.ActorID, sectorInfo []abi.SectorInfo, randomness abi.PoStRandomness) ([]abi.PoStProof, []abi.SectorID, error) {
|
||||
return generateFakePoSt(sectorInfo, abi.RegisteredSealProof.RegisteredWindowPoStProof), nil, nil
|
||||
si := make([]abi.SectorInfo, 0, len(sectorInfo))
|
||||
var skipped []abi.SectorID
|
||||
|
||||
for _, info := range sectorInfo {
|
||||
sid := abi.SectorID{
|
||||
Miner: minerID,
|
||||
Number: info.SectorNumber,
|
||||
}
|
||||
|
||||
_, found := mgr.sectors[sid]
|
||||
|
||||
if found && !mgr.sectors[sid].failed {
|
||||
si = append(si, info)
|
||||
} else {
|
||||
skipped = append(skipped, sid)
|
||||
}
|
||||
}
|
||||
|
||||
return generateFakePoSt(si, abi.RegisteredSealProof.RegisteredWindowPoStProof, randomness), skipped, nil
|
||||
}
|
||||
|
||||
func generateFakePoSt(sectorInfo []abi.SectorInfo, rpt func(abi.RegisteredSealProof) (abi.RegisteredPoStProof, error)) []abi.PoStProof {
|
||||
se, err := sectorInfo[0].SealProof.WindowPoStPartitionSectors()
|
||||
func generateFakePoSt(sectorInfo []abi.SectorInfo, rpt func(abi.RegisteredSealProof) (abi.RegisteredPoStProof, error), randomness abi.PoStRandomness) []abi.PoStProof {
|
||||
sectors := abi.NewBitField()
|
||||
for _, info := range sectorInfo {
|
||||
sectors.Set(uint64(info.SectorNumber))
|
||||
}
|
||||
|
||||
wp, err := rpt(sectorInfo[0].SealProof)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
wp, err := rpt(sectorInfo[0].SealProof)
|
||||
|
||||
var proofBuf bytes.Buffer
|
||||
|
||||
_, err = proofBuf.Write(randomness)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if err := sectors.MarshalCBOR(&proofBuf); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return []abi.PoStProof{
|
||||
{
|
||||
PoStProof: wp,
|
||||
ProofBytes: make([]byte, 192*int(math.Ceil(float64(len(sectorInfo))/float64(se)))),
|
||||
ProofBytes: proofBuf.Bytes(),
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -335,8 +372,18 @@ func (mgr *SectorMgr) Remove(ctx context.Context, sector abi.SectorID) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mgr *SectorMgr) CheckProvable(context.Context, abi.RegisteredSealProof, []abi.SectorID) ([]abi.SectorID, error) {
|
||||
return nil, nil
|
||||
func (mgr *SectorMgr) CheckProvable(ctx context.Context, spt abi.RegisteredSealProof, ids []abi.SectorID) ([]abi.SectorID, error) {
|
||||
var bad []abi.SectorID
|
||||
|
||||
for _, sid := range ids {
|
||||
_, found := mgr.sectors[sid]
|
||||
|
||||
if !found || mgr.sectors[sid].failed {
|
||||
bad = append(bad, sid)
|
||||
}
|
||||
}
|
||||
|
||||
return bad, nil
|
||||
}
|
||||
|
||||
func (m mockVerif) VerifySeal(svi abi.SealVerifyInfo) (bool, error) {
|
||||
@ -358,6 +405,42 @@ func (m mockVerif) VerifyWinningPoSt(ctx context.Context, info abi.WinningPoStVe
|
||||
}
|
||||
|
||||
func (m mockVerif) VerifyWindowPoSt(ctx context.Context, info abi.WindowPoStVerifyInfo) (bool, error) {
|
||||
if len(info.Proofs) != 1 {
|
||||
return false, xerrors.Errorf("expected 1 proof entry")
|
||||
}
|
||||
|
||||
proof := info.Proofs[0]
|
||||
|
||||
if !bytes.Equal(proof.ProofBytes[:len(info.Randomness)], info.Randomness) {
|
||||
return false, xerrors.Errorf("bad randomness")
|
||||
}
|
||||
|
||||
sectors := abi.NewBitField()
|
||||
if err := sectors.UnmarshalCBOR(bytes.NewReader(proof.ProofBytes[len(info.Randomness):])); err != nil {
|
||||
return false, xerrors.Errorf("unmarshaling sectors bitfield from \"proof\": %w", err)
|
||||
}
|
||||
|
||||
challenged := abi.NewBitField()
|
||||
for _, sector := range info.ChallengedSectors {
|
||||
challenged.Set(uint64(sector.SectorNumber))
|
||||
}
|
||||
|
||||
{
|
||||
b1, err := sectors.MarshalJSON()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
b2, err := challenged.MarshalJSON()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if !bytes.Equal(b1, b2) {
|
||||
return false, xerrors.Errorf("proven and challenged sector sets didn't match: %s != !s", string(b1), string(b2))
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func TestOpFinish(t *testing.T) {
|
||||
sb := NewMockSectorMgr(2048)
|
||||
sb := NewMockSectorMgr(2048, nil)
|
||||
|
||||
sid, pieces, err := sb.StageFakeData(123)
|
||||
if err != nil {
|
||||
|
@ -37,7 +37,7 @@ func newTestWorker(wcfg WorkerConfig, lstor *stores.Local) *testWorker {
|
||||
acceptTasks: acceptTasks,
|
||||
lstor: lstor,
|
||||
|
||||
mockSeal: mock.NewMockSectorMgr(ssize),
|
||||
mockSeal: mock.NewMockSectorMgr(ssize, nil),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user