lotus/storage/sealer/mock/mock.go

740 lines
20 KiB
Go
Raw Normal View History

2020-03-23 11:40:02 +00:00
package mock
import (
"bytes"
"context"
"crypto/sha256"
2020-03-23 11:40:02 +00:00
"fmt"
"io"
2021-06-04 13:41:38 +00:00
"io/ioutil"
2020-03-23 11:40:02 +00:00
"math/rand"
"sync"
2022-06-14 15:00:51 +00:00
"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2"
"golang.org/x/xerrors"
2020-09-07 06:08:53 +00:00
2021-12-08 22:16:27 +00:00
"github.com/filecoin-project/dagstore/mount"
commpffi "github.com/filecoin-project/go-commp-utils/ffiwrapper"
2020-03-23 11:40:02 +00:00
commcid "github.com/filecoin-project/go-fil-commcid"
2020-09-07 03:49:10 +00:00
"github.com/filecoin-project/go-state-types/abi"
2022-06-14 15:00:51 +00:00
prooftypes "github.com/filecoin-project/go-state-types/proof"
2020-03-23 11:40:02 +00:00
"github.com/filecoin-project/lotus/storage/sealer/ffiwrapper"
"github.com/filecoin-project/lotus/storage/sealer/storiface"
2020-03-23 11:40:02 +00:00
)
var log = logging.Logger("sbmock")
type SectorMgr struct {
sectors map[abi.SectorID]*sectorState
failPoSt bool
2020-05-26 14:39:25 +00:00
pieces map[cid.Cid][]byte
2020-03-23 11:40:02 +00:00
nextSectorID abi.SectorNumber
lk sync.Mutex
}
2021-06-03 15:31:05 +00:00
type mockVerifProver struct {
2022-04-20 21:34:28 +00:00
aggregates map[string]prooftypes.AggregateSealVerifyProofAndInfos // used for logging bad verifies
2021-06-03 15:31:05 +00:00
}
2020-03-23 11:40:02 +00:00
2020-11-05 06:34:24 +00:00
func NewMockSectorMgr(genesisSectors []abi.SectorID) *SectorMgr {
2020-07-23 17:00:20 +00:00
sectors := make(map[abi.SectorID]*sectorState)
for _, sid := range genesisSectors {
sectors[sid] = &sectorState{
failed: false,
state: stateCommit,
}
}
2020-03-23 11:40:02 +00:00
return &SectorMgr{
2020-07-23 17:00:20 +00:00
sectors: sectors,
2020-05-26 14:39:25 +00:00
pieces: map[cid.Cid][]byte{},
2020-03-23 11:40:02 +00:00
nextSectorID: 5,
}
}
const (
statePacking = iota
statePreCommit
2020-04-01 23:18:20 +00:00
stateCommit // nolint
2020-03-23 11:40:02 +00:00
)
type sectorState struct {
2020-09-10 20:07:20 +00:00
pieces []cid.Cid
failed bool
corrupted bool
2020-03-23 11:40:02 +00:00
state int
lk sync.Mutex
}
func (mgr *SectorMgr) NewSector(ctx context.Context, sector storiface.SectorRef) error {
2020-03-23 11:40:02 +00:00
return nil
}
func (mgr *SectorMgr) SectorsUnsealPiece(ctx context.Context, sector storiface.SectorRef, offset storiface.UnpaddedByteIndex, size abi.UnpaddedPieceSize, randomness abi.SealRandomness, commd *cid.Cid) error {
2021-06-04 13:41:38 +00:00
panic("SectorMgr: unsealing piece: implement me")
}
2022-04-26 19:37:48 +00:00
func (mgr *SectorMgr) DataCid(ctx context.Context, size abi.UnpaddedPieceSize, r io.Reader) (abi.PieceInfo, error) {
panic("todo")
}
func (mgr *SectorMgr) AddPiece(ctx context.Context, sectorID storiface.SectorRef, existingPieces []abi.UnpaddedPieceSize, size abi.UnpaddedPieceSize, r io.Reader) (abi.PieceInfo, error) {
2020-11-05 06:34:24 +00:00
log.Warn("Add piece: ", sectorID, size, sectorID.ProofType)
2020-03-23 11:40:02 +00:00
2020-05-26 14:39:25 +00:00
var b bytes.Buffer
tr := io.TeeReader(r, &b)
c, err := commpffi.GeneratePieceCIDFromFile(sectorID.ProofType, tr, size)
2020-03-23 11:40:02 +00:00
if err != nil {
return abi.PieceInfo{}, xerrors.Errorf("failed to generate piece cid: %w", err)
}
log.Warn("Generated Piece CID: ", c)
mgr.lk.Lock()
2020-05-26 14:39:25 +00:00
mgr.pieces[c] = b.Bytes()
2020-11-05 06:34:24 +00:00
ss, ok := mgr.sectors[sectorID.ID]
if !ok {
ss = &sectorState{
state: statePacking,
}
2020-11-05 06:34:24 +00:00
mgr.sectors[sectorID.ID] = ss
}
mgr.lk.Unlock()
ss.lk.Lock()
2020-03-23 11:40:02 +00:00
ss.pieces = append(ss.pieces, c)
ss.lk.Unlock()
2020-03-23 11:40:02 +00:00
return abi.PieceInfo{
2020-03-23 11:40:02 +00:00
Size: size.Padded(),
PieceCID: c,
}, nil
}
2020-04-10 19:12:23 +00:00
func (mgr *SectorMgr) AcquireSectorNumber() (abi.SectorNumber, error) {
mgr.lk.Lock()
defer mgr.lk.Unlock()
id := mgr.nextSectorID
mgr.nextSectorID++
2020-03-23 11:40:02 +00:00
return id, nil
}
func (mgr *SectorMgr) IsUnsealed(ctx context.Context, sector storiface.SectorRef, offset storiface.UnpaddedByteIndex, size abi.UnpaddedPieceSize) (bool, error) {
2021-06-08 04:07:12 +00:00
return false, nil
}
func (mgr *SectorMgr) ForceState(sid storiface.SectorRef, st int) error {
2020-09-30 17:18:38 +00:00
mgr.lk.Lock()
2020-11-05 06:34:24 +00:00
ss, ok := mgr.sectors[sid.ID]
2020-09-30 17:18:38 +00:00
mgr.lk.Unlock()
if !ok {
return xerrors.Errorf("no sector with id %d in storage", sid)
}
ss.state = st
return nil
}
func (mgr *SectorMgr) SealPreCommit1(ctx context.Context, sid storiface.SectorRef, ticket abi.SealRandomness, pieces []abi.PieceInfo) (out storiface.PreCommit1Out, err error) {
2020-04-10 19:12:23 +00:00
mgr.lk.Lock()
2020-11-05 06:34:24 +00:00
ss, ok := mgr.sectors[sid.ID]
2020-04-10 19:12:23 +00:00
mgr.lk.Unlock()
2020-03-23 11:40:02 +00:00
if !ok {
2020-03-26 19:34:38 +00:00
return nil, xerrors.Errorf("no sector with id %d in storage", sid)
2020-03-23 11:40:02 +00:00
}
2020-11-05 06:34:24 +00:00
ssize, err := sid.ProofType.SectorSize()
if err != nil {
return nil, xerrors.Errorf("failed to get proof sector size: %w", err)
}
2020-03-23 11:40:02 +00:00
ss.lk.Lock()
defer ss.lk.Unlock()
2020-11-05 06:34:24 +00:00
ussize := abi.PaddedPieceSize(ssize).Unpadded()
2020-03-23 11:40:02 +00:00
// TODO: verify pieces in sinfo.pieces match passed in pieces
var sum abi.UnpaddedPieceSize
for _, p := range pieces {
sum += p.Size.Unpadded()
}
if sum != ussize {
return nil, xerrors.Errorf("aggregated piece sizes don't match up: %d != %d", sum, ussize)
}
if ss.state != statePacking {
return nil, xerrors.Errorf("cannot call pre-seal on sector not in 'packing' state")
}
opFinishWait(ctx)
ss.state = statePreCommit
pis := make([]abi.PieceInfo, len(ss.pieces))
for i, piece := range ss.pieces {
pis[i] = abi.PieceInfo{
Size: pieces[i].Size,
PieceCID: piece,
}
}
2020-11-05 06:34:24 +00:00
commd, err := MockVerifier.GenerateDataCommitment(sid.ProofType, pis)
2020-03-23 11:40:02 +00:00
if err != nil {
return nil, err
}
_, _, cc, err := commcid.CIDToCommitment(commd)
2020-03-23 11:40:02 +00:00
if err != nil {
panic(err)
}
cc[0] ^= 'd'
return cc, nil
}
func (mgr *SectorMgr) SealPreCommit2(ctx context.Context, sid storiface.SectorRef, phase1Out storiface.PreCommit1Out) (cids storiface.SectorCids, err error) {
2020-03-23 11:40:02 +00:00
db := []byte(string(phase1Out))
db[0] ^= 'd'
d, _ := commcid.DataCommitmentV1ToCID(db)
2020-03-23 11:40:02 +00:00
commr := make([]byte, 32)
for i := range db {
commr[32-(i+1)] = db[i]
}
commR, _ := commcid.ReplicaCommitmentV1ToCID(commr)
2020-03-23 11:40:02 +00:00
return storiface.SectorCids{
2020-03-23 11:40:02 +00:00
Unsealed: d,
Sealed: commR,
}, nil
}
func (mgr *SectorMgr) SealCommit1(ctx context.Context, sid storiface.SectorRef, ticket abi.SealRandomness, seed abi.InteractiveSealRandomness, pieces []abi.PieceInfo, cids storiface.SectorCids) (output storiface.Commit1Out, err error) {
2020-04-10 19:12:23 +00:00
mgr.lk.Lock()
2020-11-05 06:34:24 +00:00
ss, ok := mgr.sectors[sid.ID]
2020-04-10 19:12:23 +00:00
mgr.lk.Unlock()
2020-03-23 11:40:02 +00:00
if !ok {
return nil, xerrors.Errorf("no such sector %d", sid)
}
ss.lk.Lock()
defer ss.lk.Unlock()
if ss.failed {
return nil, xerrors.Errorf("[mock] cannot commit failed sector %d", sid)
}
if ss.state != statePreCommit {
return nil, xerrors.Errorf("cannot commit sector that has not been precommitted")
}
opFinishWait(ctx)
var out [32]byte
for i := range out {
2020-11-05 06:34:24 +00:00
out[i] = cids.Unsealed.Bytes()[i] + cids.Sealed.Bytes()[31-i] - ticket[i]*seed[i] ^ byte(sid.ID.Number&0xff)
2020-03-23 11:40:02 +00:00
}
return out[:], nil
}
func (mgr *SectorMgr) SealCommit2(ctx context.Context, sid storiface.SectorRef, phase1Out storiface.Commit1Out) (proof storiface.Proof, err error) {
plen, err := sid.ProofType.ProofSize()
if err != nil {
return nil, err
}
out := make([]byte, plen)
2020-10-12 06:31:23 +00:00
for i := range out[:len(phase1Out)] {
2020-11-05 06:34:24 +00:00
out[i] = phase1Out[i] ^ byte(sid.ID.Number&0xff)
2020-03-23 11:40:02 +00:00
}
return out[:], nil
}
func (mgr *SectorMgr) ReplicaUpdate(ctx context.Context, sid storiface.SectorRef, pieces []abi.PieceInfo) (storiface.ReplicaUpdateOut, error) {
out := storiface.ReplicaUpdateOut{}
return out, nil
}
func (mgr *SectorMgr) ProveReplicaUpdate1(ctx context.Context, sector storiface.SectorRef, sectorKey, newSealed, newUnsealed cid.Cid) (storiface.ReplicaVanillaProofs, error) {
out := make([][]byte, 0)
return out, nil
}
func (mgr *SectorMgr) ProveReplicaUpdate2(ctx context.Context, sector storiface.SectorRef, sectorKey, newSealed, newUnsealed cid.Cid, vanillaProofs storiface.ReplicaVanillaProofs) (storiface.ReplicaUpdateProof, error) {
return make([]byte, 0), nil
}
func (mgr *SectorMgr) GenerateSectorKeyFromData(ctx context.Context, sector storiface.SectorRef, commD cid.Cid) error {
return nil
}
func (mgr *SectorMgr) ReleaseSealed(ctx context.Context, sid storiface.SectorRef) error {
return nil
}
2020-03-23 11:40:02 +00:00
// Test Instrumentation Methods
func (mgr *SectorMgr) MarkFailed(sid storiface.SectorRef, failed bool) error {
2020-04-10 19:12:23 +00:00
mgr.lk.Lock()
defer mgr.lk.Unlock()
2020-11-05 06:34:24 +00:00
ss, ok := mgr.sectors[sid.ID]
2020-03-23 11:40:02 +00:00
if !ok {
2020-03-26 19:34:38 +00:00
return fmt.Errorf("no such sector in storage")
2020-03-23 11:40:02 +00:00
}
ss.failed = failed
2020-03-23 11:40:02 +00:00
return nil
}
func (mgr *SectorMgr) Fail() {
mgr.lk.Lock()
defer mgr.lk.Unlock()
mgr.failPoSt = true
return
}
func (mgr *SectorMgr) MarkCorrupted(sid storiface.SectorRef, corrupted bool) error {
mgr.lk.Lock()
defer mgr.lk.Unlock()
2020-11-05 06:34:24 +00:00
ss, ok := mgr.sectors[sid.ID]
if !ok {
return fmt.Errorf("no such sector in storage")
}
ss.corrupted = corrupted
return nil
}
2020-03-23 11:40:02 +00:00
func opFinishWait(ctx context.Context) {
val, ok := ctx.Value("opfinish").(chan struct{})
if !ok {
return
}
<-val
}
func AddOpFinish(ctx context.Context) (context.Context, func()) {
done := make(chan struct{})
2020-08-16 10:40:35 +00:00
return context.WithValue(ctx, "opfinish", done), func() { // nolint
2020-03-23 11:40:02 +00:00
close(done)
}
}
2022-04-20 21:34:28 +00:00
func (mgr *SectorMgr) GenerateWinningPoSt(ctx context.Context, minerID abi.ActorID, xSectorInfo []prooftypes.ExtendedSectorInfo, randomness abi.PoStRandomness) ([]prooftypes.PoStProof, error) {
mgr.lk.Lock()
defer mgr.lk.Unlock()
2022-04-20 21:34:28 +00:00
sectorInfo := make([]prooftypes.SectorInfo, len(xSectorInfo))
for i, xssi := range xSectorInfo {
2022-04-20 21:34:28 +00:00
sectorInfo[i] = prooftypes.SectorInfo{
SealProof: xssi.SealProof,
SectorNumber: xssi.SectorNumber,
SealedCID: xssi.SealedCID,
}
}
2020-07-23 17:00:20 +00:00
return generateFakePoSt(sectorInfo, abi.RegisteredSealProof.RegisteredWinningPoStProof, randomness), nil
2020-03-23 11:40:02 +00:00
}
2022-04-20 21:34:28 +00:00
func (mgr *SectorMgr) GenerateWindowPoSt(ctx context.Context, minerID abi.ActorID, xSectorInfo []prooftypes.ExtendedSectorInfo, randomness abi.PoStRandomness) ([]prooftypes.PoStProof, []abi.SectorID, error) {
mgr.lk.Lock()
defer mgr.lk.Unlock()
if mgr.failPoSt {
return nil, nil, xerrors.Errorf("failed to post (mock)")
}
2022-04-20 21:34:28 +00:00
si := make([]prooftypes.ExtendedSectorInfo, 0, len(xSectorInfo))
2021-03-10 15:16:44 +00:00
2020-07-23 17:00:20 +00:00
var skipped []abi.SectorID
var err error
for _, xsi := range xSectorInfo {
2020-07-23 17:00:20 +00:00
sid := abi.SectorID{
Miner: minerID,
Number: xsi.SectorNumber,
2020-07-23 17:00:20 +00:00
}
_, found := mgr.sectors[sid]
if found && !mgr.sectors[sid].failed && !mgr.sectors[sid].corrupted {
si = append(si, xsi)
2020-07-23 17:00:20 +00:00
} else {
skipped = append(skipped, sid)
err = xerrors.Errorf("skipped some sectors")
2020-07-23 17:00:20 +00:00
}
}
if err != nil {
return nil, skipped, err
}
2022-04-20 21:34:28 +00:00
sectorInfo := make([]prooftypes.SectorInfo, len(si))
for i, xssi := range si {
2022-04-20 21:34:28 +00:00
sectorInfo[i] = prooftypes.SectorInfo{
SealProof: xssi.SealProof,
SectorNumber: xssi.SectorNumber,
SealedCID: xssi.SealedCID,
}
}
return generateFakePoSt(sectorInfo, abi.RegisteredSealProof.RegisteredWindowPoStProof, randomness), skipped, nil
}
2022-04-20 21:34:28 +00:00
func generateFakePoStProof(sectorInfo []prooftypes.SectorInfo, randomness abi.PoStRandomness) []byte {
randomness[31] &= 0x3f
hasher := sha256.New()
_, _ = hasher.Write(randomness)
2020-07-23 17:00:20 +00:00
for _, info := range sectorInfo {
err := info.MarshalCBOR(hasher)
if err != nil {
panic(err)
}
}
return hasher.Sum(nil)
2020-07-23 17:00:20 +00:00
}
2020-07-23 17:00:20 +00:00
2022-04-20 21:34:28 +00:00
func generateFakePoSt(sectorInfo []prooftypes.SectorInfo, rpt func(abi.RegisteredSealProof) (abi.RegisteredPoStProof, error), randomness abi.PoStRandomness) []prooftypes.PoStProof {
wp, err := rpt(sectorInfo[0].SealProof)
2020-06-15 12:32:17 +00:00
if err != nil {
panic(err)
}
2022-04-20 21:34:28 +00:00
return []prooftypes.PoStProof{
{
2020-06-15 12:32:17 +00:00
PoStProof: wp,
ProofBytes: generateFakePoStProof(sectorInfo, randomness),
},
}
2020-03-23 11:40:02 +00:00
}
2022-04-20 21:34:28 +00:00
func (mgr *SectorMgr) GenerateWinningPoStWithVanilla(ctx context.Context, proofType abi.RegisteredPoStProof, minerID abi.ActorID, randomness abi.PoStRandomness, proofs [][]byte) ([]prooftypes.PoStProof, error) {
2022-01-14 13:11:04 +00:00
panic("implement me")
}
2022-04-20 21:34:28 +00:00
func (mgr *SectorMgr) GenerateWindowPoStWithVanilla(ctx context.Context, proofType abi.RegisteredPoStProof, minerID abi.ActorID, randomness abi.PoStRandomness, proofs [][]byte, partitionIdx int) (prooftypes.PoStProof, error) {
2022-01-14 13:11:04 +00:00
panic("implement me")
}
func (mgr *SectorMgr) ReadPiece(ctx context.Context, sector storiface.SectorRef, offset storiface.UnpaddedByteIndex, size abi.UnpaddedPieceSize, ticket abi.SealRandomness, unsealed cid.Cid) (mount.Reader, bool, error) {
off := storiface.UnpaddedByteIndex(0)
var piece cid.Cid
for _, c := range mgr.sectors[sector.ID].pieces {
piece = c
if off >= offset {
break
}
off += storiface.UnpaddedByteIndex(len(mgr.pieces[piece]))
2020-03-23 11:40:02 +00:00
}
if off > offset {
panic("non-aligned offset todo")
}
br := bytes.NewReader(mgr.pieces[piece][:size])
2021-12-09 15:26:59 +00:00
2021-12-08 22:16:27 +00:00
return struct {
io.ReadCloser
io.Seeker
io.ReaderAt
}{
2021-12-09 15:26:59 +00:00
ReadCloser: ioutil.NopCloser(br),
Seeker: br,
ReaderAt: br,
2021-12-08 22:16:27 +00:00
}, false, nil
2020-03-23 11:40:02 +00:00
}
func (mgr *SectorMgr) StageFakeData(mid abi.ActorID, spt abi.RegisteredSealProof) (storiface.SectorRef, []abi.PieceInfo, error) {
2020-11-05 06:34:24 +00:00
psize, err := spt.SectorSize()
if err != nil {
return storiface.SectorRef{}, nil, err
2020-11-05 06:34:24 +00:00
}
usize := abi.PaddedPieceSize(psize).Unpadded()
2020-04-10 19:12:23 +00:00
sid, err := mgr.AcquireSectorNumber()
2020-03-23 11:40:02 +00:00
if err != nil {
return storiface.SectorRef{}, nil, err
2020-03-23 11:40:02 +00:00
}
buf := make([]byte, usize)
2020-08-16 10:40:35 +00:00
_, _ = rand.Read(buf) // nolint:gosec
2020-03-23 11:40:02 +00:00
id := storiface.SectorRef{
2020-11-05 06:34:24 +00:00
ID: abi.SectorID{
Miner: mid,
Number: sid,
},
ProofType: spt,
2020-03-23 11:40:02 +00:00
}
2020-04-10 19:12:23 +00:00
pi, err := mgr.AddPiece(context.TODO(), id, nil, usize, bytes.NewReader(buf))
2020-03-23 11:40:02 +00:00
if err != nil {
return storiface.SectorRef{}, nil, err
2020-03-23 11:40:02 +00:00
}
return id, []abi.PieceInfo{pi}, nil
}
func (mgr *SectorMgr) FinalizeSector(context.Context, storiface.SectorRef, []storiface.Range) error {
return nil
}
func (mgr *SectorMgr) FinalizeReplicaUpdate(context.Context, storiface.SectorRef, []storiface.Range) error {
2022-02-03 12:51:59 +00:00
return nil
}
func (mgr *SectorMgr) ReleaseUnsealed(ctx context.Context, sector storiface.SectorRef, safeToFree []storiface.Range) error {
return nil
}
func (mgr *SectorMgr) ReleaseReplicaUpgrade(ctx context.Context, sector storiface.SectorRef) error {
return nil
}
func (mgr *SectorMgr) ReleaseSectorKey(ctx context.Context, sector storiface.SectorRef) error {
return nil
}
func (mgr *SectorMgr) Remove(ctx context.Context, sector storiface.SectorRef) error {
mgr.lk.Lock()
defer mgr.lk.Unlock()
2020-11-05 06:34:24 +00:00
if _, has := mgr.sectors[sector.ID]; !has {
return xerrors.Errorf("sector not found")
}
2020-11-05 06:34:24 +00:00
delete(mgr.sectors, sector.ID)
2020-03-23 11:40:02 +00:00
return nil
}
func (mgr *SectorMgr) CheckProvable(ctx context.Context, pp abi.RegisteredPoStProof, ids []storiface.SectorRef, rg storiface.RGetter) (map[abi.SectorID]string, error) {
2020-11-27 15:34:41 +00:00
bad := map[abi.SectorID]string{}
2020-07-23 17:00:20 +00:00
for _, sid := range ids {
2020-11-05 12:43:05 +00:00
_, found := mgr.sectors[sid.ID]
2020-07-23 17:00:20 +00:00
2020-11-05 12:43:05 +00:00
if !found || mgr.sectors[sid.ID].failed {
2020-11-27 15:34:41 +00:00
bad[sid.ID] = "mock fail"
2020-07-23 17:00:20 +00:00
}
}
return bad, nil
2020-05-16 21:03:29 +00:00
}
var _ storiface.WorkerReturn = &SectorMgr{}
2022-04-26 19:37:48 +00:00
func (mgr *SectorMgr) ReturnDataCid(ctx context.Context, callID storiface.CallID, pi abi.PieceInfo, err *storiface.CallError) error {
panic("not supported")
}
2020-11-17 15:17:45 +00:00
func (mgr *SectorMgr) ReturnAddPiece(ctx context.Context, callID storiface.CallID, pi abi.PieceInfo, err *storiface.CallError) error {
2020-09-07 14:35:54 +00:00
panic("not supported")
}
func (mgr *SectorMgr) ReturnSealPreCommit1(ctx context.Context, callID storiface.CallID, p1o storiface.PreCommit1Out, err *storiface.CallError) error {
2020-09-07 14:35:54 +00:00
panic("not supported")
}
func (mgr *SectorMgr) ReturnSealPreCommit2(ctx context.Context, callID storiface.CallID, sealed storiface.SectorCids, err *storiface.CallError) error {
2020-09-07 14:35:54 +00:00
panic("not supported")
}
func (mgr *SectorMgr) ReturnSealCommit1(ctx context.Context, callID storiface.CallID, out storiface.Commit1Out, err *storiface.CallError) error {
2020-09-07 14:35:54 +00:00
panic("not supported")
}
func (mgr *SectorMgr) ReturnSealCommit2(ctx context.Context, callID storiface.CallID, proof storiface.Proof, err *storiface.CallError) error {
2020-09-07 14:35:54 +00:00
panic("not supported")
}
2020-11-17 15:17:45 +00:00
func (mgr *SectorMgr) ReturnFinalizeSector(ctx context.Context, callID storiface.CallID, err *storiface.CallError) error {
2020-09-07 14:35:54 +00:00
panic("not supported")
}
2020-11-17 15:17:45 +00:00
func (mgr *SectorMgr) ReturnReleaseUnsealed(ctx context.Context, callID storiface.CallID, err *storiface.CallError) error {
2020-09-07 14:35:54 +00:00
panic("not supported")
}
2020-11-17 15:17:45 +00:00
func (mgr *SectorMgr) ReturnMoveStorage(ctx context.Context, callID storiface.CallID, err *storiface.CallError) error {
2020-09-07 14:35:54 +00:00
panic("not supported")
}
2020-11-17 15:17:45 +00:00
func (mgr *SectorMgr) ReturnUnsealPiece(ctx context.Context, callID storiface.CallID, err *storiface.CallError) error {
2020-09-07 14:35:54 +00:00
panic("not supported")
}
2020-11-17 15:17:45 +00:00
func (mgr *SectorMgr) ReturnReadPiece(ctx context.Context, callID storiface.CallID, ok bool, err *storiface.CallError) error {
2020-09-07 14:35:54 +00:00
panic("not supported")
}
2020-11-17 15:17:45 +00:00
func (mgr *SectorMgr) ReturnFetch(ctx context.Context, callID storiface.CallID, err *storiface.CallError) error {
2020-09-07 14:35:54 +00:00
panic("not supported")
}
func (mgr *SectorMgr) ReturnReplicaUpdate(ctx context.Context, callID storiface.CallID, out storiface.ReplicaUpdateOut, err *storiface.CallError) error {
panic("not supported")
}
func (mgr *SectorMgr) ReturnProveReplicaUpdate1(ctx context.Context, callID storiface.CallID, out storiface.ReplicaVanillaProofs, err *storiface.CallError) error {
panic("not supported")
}
func (mgr *SectorMgr) ReturnProveReplicaUpdate2(ctx context.Context, callID storiface.CallID, out storiface.ReplicaUpdateProof, err *storiface.CallError) error {
panic("not supported")
}
func (mgr *SectorMgr) ReturnGenerateSectorKeyFromData(ctx context.Context, callID storiface.CallID, err *storiface.CallError) error {
panic("not supported")
}
func (mgr *SectorMgr) ReturnFinalizeReplicaUpdate(ctx context.Context, callID storiface.CallID, err *storiface.CallError) error {
panic("not supported")
}
2022-04-20 21:34:28 +00:00
func (m mockVerifProver) VerifySeal(svi prooftypes.SealVerifyInfo) (bool, error) {
plen, err := svi.SealProof.ProofSize()
if err != nil {
return false, err
}
if len(svi.Proof) != int(plen) {
2020-03-23 11:40:02 +00:00
return false, nil
}
2020-10-12 06:31:23 +00:00
// only the first 32 bytes, the rest are 0.
for i, b := range svi.Proof[:32] {
2021-03-10 15:16:44 +00:00
// unsealed+sealed-seed*ticket
2020-05-22 01:19:46 +00:00
if b != svi.UnsealedCID.Bytes()[i]+svi.SealedCID.Bytes()[31-i]-svi.InteractiveRandomness[i]*svi.Randomness[i] {
2020-03-23 11:40:02 +00:00
return false, nil
}
}
return true, nil
}
2022-04-20 21:34:28 +00:00
func (m mockVerifProver) VerifyAggregateSeals(aggregate prooftypes.AggregateSealVerifyProofAndInfos) (bool, error) {
2021-05-26 07:58:57 +00:00
out := make([]byte, m.aggLen(len(aggregate.Infos)))
2021-03-10 15:16:44 +00:00
for pi, svi := range aggregate.Infos {
for i := 0; i < 32; i++ {
b := svi.UnsealedCID.Bytes()[i] + svi.SealedCID.Bytes()[31-i] - svi.InteractiveRandomness[i]*svi.Randomness[i] // raw proof byte
2021-05-18 16:58:41 +00:00
2021-05-18 18:34:23 +00:00
b *= uint8(pi) // with aggregate index
2021-03-10 15:16:44 +00:00
out[i] += b
}
}
2021-06-03 15:31:05 +00:00
ok := bytes.Equal(aggregate.Proof, out)
if !ok {
genInfo, found := m.aggregates[string(aggregate.Proof)]
if !found {
log.Errorf("BAD AGGREGATE: saved generate inputs not found; agg.Proof: %x; expected: %x", aggregate.Proof, out)
} else {
log.Errorf("BAD AGGREGATE (1): agg.Proof: %x; expected: %x", aggregate.Proof, out)
log.Errorf("BAD AGGREGATE (2): Verify Infos: %+v", aggregate.Infos)
log.Errorf("BAD AGGREGATE (3): Generate Infos: %+v", genInfo.Infos)
}
}
return ok, nil
2021-03-10 15:16:44 +00:00
}
2022-04-20 21:34:28 +00:00
func (m mockVerifProver) VerifyReplicaUpdate(update prooftypes.ReplicaUpdateInfo) (bool, error) {
2021-11-17 17:41:42 +00:00
return true, nil
2021-11-04 15:59:29 +00:00
}
2022-04-20 21:34:28 +00:00
func (m mockVerifProver) AggregateSealProofs(aggregateInfo prooftypes.AggregateSealVerifyProofAndInfos, proofs [][]byte) ([]byte, error) {
2021-05-26 07:58:57 +00:00
out := make([]byte, m.aggLen(len(aggregateInfo.Infos))) // todo: figure out more real length
2021-03-10 15:16:44 +00:00
for pi, proof := range proofs {
for i := range proof[:32] {
out[i] += proof[i] * uint8(pi)
}
}
2021-05-18 16:58:41 +00:00
2021-06-03 15:31:05 +00:00
m.aggregates[string(out)] = aggregateInfo
2021-03-10 15:16:44 +00:00
return out, nil
}
2021-05-26 07:58:57 +00:00
func (m mockVerifProver) aggLen(nproofs int) int {
switch {
case nproofs <= 8:
return 11220
case nproofs <= 16:
return 14196
case nproofs <= 32:
return 17172
case nproofs <= 64:
return 20148
case nproofs <= 128:
return 23124
case nproofs <= 256:
return 26100
case nproofs <= 512:
return 29076
case nproofs <= 1024:
return 32052
case nproofs <= 2048:
return 35028
case nproofs <= 4096:
return 38004
case nproofs <= 8192:
return 40980
default:
panic("too many proofs")
}
}
2022-04-20 21:34:28 +00:00
func (m mockVerifProver) VerifyWinningPoSt(ctx context.Context, info prooftypes.WinningPoStVerifyInfo) (bool, error) {
info.Randomness[31] &= 0x3f
return true, nil
2020-04-10 19:12:23 +00:00
}
2022-04-20 21:34:28 +00:00
func (m mockVerifProver) VerifyWindowPoSt(ctx context.Context, info prooftypes.WindowPoStVerifyInfo) (bool, error) {
2020-07-23 17:00:20 +00:00
if len(info.Proofs) != 1 {
return false, xerrors.Errorf("expected 1 proof entry")
}
proof := info.Proofs[0]
expected := generateFakePoStProof(info.ChallengedSectors, info.Randomness)
if !bytes.Equal(proof.ProofBytes, expected) {
return false, xerrors.Errorf("bad proof")
2020-07-23 17:00:20 +00:00
}
return true, nil
2020-04-10 19:12:23 +00:00
}
2021-05-19 13:20:23 +00:00
func (m mockVerifProver) GenerateDataCommitment(pt abi.RegisteredSealProof, pieces []abi.PieceInfo) (cid.Cid, error) {
return ffiwrapper.GenerateUnsealedCID(pt, pieces)
2020-03-23 11:40:02 +00:00
}
2021-05-19 13:20:23 +00:00
func (m mockVerifProver) GenerateWinningPoStSectorChallenge(ctx context.Context, proofType abi.RegisteredPoStProof, minerID abi.ActorID, randomness abi.PoStRandomness, eligibleSectorCount uint64) ([]uint64, error) {
2020-04-17 22:52:42 +00:00
return []uint64{0}, nil
}
2021-06-03 15:31:05 +00:00
var MockVerifier = mockVerifProver{
2022-04-20 21:34:28 +00:00
aggregates: map[string]prooftypes.AggregateSealVerifyProofAndInfos{},
2021-06-03 15:31:05 +00:00
}
var MockProver = MockVerifier
2020-03-23 11:40:02 +00:00
var _ storiface.Sealer = &SectorMgr{}
2022-06-17 11:52:19 +00:00
var _ storiface.Verifier = MockVerifier
var _ storiface.Prover = MockProver