sealing: wire up checkPieces and checkSeal

This commit is contained in:
Łukasz Magiera 2020-01-22 20:47:29 +01:00
parent 032b2d877c
commit 7463ee72d0
4 changed files with 20 additions and 6 deletions

View File

@ -10,7 +10,7 @@ import (
"github.com/filecoin-project/lotus/chain/types"
)
func checkPieces(ctx context.Context, si *SectorInfo, api sealingApi) error {
func checkPieces(ctx context.Context, si SectorInfo, api sealingApi) error {
for i, piece := range si.Pieces {
deal, err := api.StateMarketStorageDeal(ctx, piece.DealID, nil)
if err != nil {
@ -29,7 +29,7 @@ func checkPieces(ctx context.Context, si *SectorInfo, api sealingApi) error {
return nil
}
func checkSeal(ctx context.Context, maddr address.Address, si *SectorInfo, api sealingApi) (err error) {
func checkSeal(ctx context.Context, maddr address.Address, si SectorInfo, api sealingApi) (err error) {
ssize, err := api.StateMinerSectorSize(ctx, maddr, nil)
if err != nil {
return err
@ -45,7 +45,7 @@ func checkSeal(ctx context.Context, maddr address.Address, si *SectorInfo, api s
ccmt := &types.Message{
To: actors.StorageMarketAddress,
From: actors.StorageMarketAddress,
From: maddr,
Value: types.NewInt(0),
GasPrice: types.NewInt(0),
GasLimit: types.NewInt(9999999999),
@ -57,7 +57,7 @@ func checkSeal(ctx context.Context, maddr address.Address, si *SectorInfo, api s
return xerrors.Errorf("calling ComputeDataCommitment: %w", err)
}
if r.ExitCode != 0 {
return xerrors.Errorf("receipt for ComputeDataCommitment han exit code %d", r.ExitCode)
return xerrors.Errorf("receipt for ComputeDataCommitment had exit code %d", r.ExitCode)
}
if string(r.Return) != string(si.CommD) {
return xerrors.Errorf("on chain CommD differs from sector: %x != %x", r.Return, si.CommD)

6
fsm.go
View File

@ -34,8 +34,10 @@ var fsmPlanners = []func(events []statemachine.Event, state *SectorInfo) error{
api.Unsealed: planOne(
on(SectorSealed{}, api.PreCommitting),
on(SectorSealFailed{}, api.SealFailed),
on(SectorPackingFailed{}, api.PackingFailed),
),
api.PreCommitting: planOne(
on(SectorSealFailed{}, api.SealFailed),
on(SectorPreCommitted{}, api.WaitSeed),
on(SectorPreCommitFailed{}, api.PreCommitFailed),
),
@ -221,7 +223,7 @@ func planOne(ts ...func() (mut mutator, next api.SectorState)) func(events []sta
return func(events []statemachine.Event, state *SectorInfo) error {
if len(events) != 1 {
for _, event := range events {
if gm, ok := event.User.(globalMutator); !ok {
if gm, ok := event.User.(globalMutator); ok {
gm.applyGlobal(state)
return nil
}
@ -229,7 +231,7 @@ func planOne(ts ...func() (mut mutator, next api.SectorState)) func(events []sta
return xerrors.Errorf("planner for state %s only has a plan for a single event only, got %+v", api.SectorStates[state.State], events)
}
if gm, ok := events[0].User.(globalMutator); !ok {
if gm, ok := events[0].User.(globalMutator); ok {
gm.applyGlobal(state)
return nil
}

View File

@ -60,6 +60,10 @@ func (evt SectorPacked) apply(state *SectorInfo) {
state.Pieces = append(state.Pieces, evt.pieces...)
}
type SectorPackingFailed struct{ error }
func (evt SectorPackingFailed) apply(*SectorInfo) {}
type SectorSealed struct {
commR []byte
commD []byte

View File

@ -44,6 +44,10 @@ func (m *Sealing) handlePacking(ctx statemachine.Context, sector SectorInfo) err
}
func (m *Sealing) handleUnsealed(ctx statemachine.Context, sector SectorInfo) error {
if err := checkPieces(ctx.Context(), sector, m.api); err != nil { // Sanity check state
return ctx.Send(SectorPackingFailed{xerrors.Errorf("checkPieces error: %w", err)})
}
log.Infow("performing sector replication...", "sector", sector.SectorID)
ticket, err := m.tktFn(ctx.Context())
if err != nil {
@ -66,6 +70,10 @@ func (m *Sealing) handleUnsealed(ctx statemachine.Context, sector SectorInfo) er
}
func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInfo) error {
if err := checkSeal(ctx.Context(), m.maddr, sector, m.api); err != nil {
return ctx.Send(SectorSealFailed{xerrors.Errorf("checkPieces error: %w", err)})
}
params := &actors.SectorPreCommitInfo{
SectorNumber: sector.SectorID,