sealing: FinalizeSector step

This commit is contained in:
Łukasz Magiera 2020-01-29 22:25:06 +01:00
parent 73839692d9
commit 4ce9d005dd
3 changed files with 23 additions and 1 deletions

8
fsm.go
View File

@ -48,10 +48,14 @@ var fsmPlanners = []func(events []statemachine.Event, state *SectorInfo) error{
), ),
api.Committing: planCommitting, api.Committing: planCommitting,
api.CommitWait: planOne( api.CommitWait: planOne(
on(SectorProving{}, api.Proving), on(SectorProving{}, api.FinalizeSector),
on(SectorCommitFailed{}, api.CommitFailed), on(SectorCommitFailed{}, api.CommitFailed),
), ),
api.FinalizeSector: planOne(
on(SectorFinalized{}, api.Proving),
),
api.Proving: planOne( api.Proving: planOne(
on(SectorFaultReported{}, api.FaultReported), on(SectorFaultReported{}, api.FaultReported),
on(SectorFaulty{}, api.Faulty), on(SectorFaulty{}, api.Faulty),
@ -150,6 +154,8 @@ func (m *Sealing) plan(events []statemachine.Event, state *SectorInfo) (func(sta
return m.handleCommitting, nil return m.handleCommitting, nil
case api.CommitWait: case api.CommitWait:
return m.handleCommitWait, nil return m.handleCommitWait, nil
case api.FinalizeSector:
case api.Proving: case api.Proving:
// TODO: track sector health / expiration // TODO: track sector health / expiration
log.Infof("Proving sector %d", state.SectorID) log.Infof("Proving sector %d", state.SectorID)

View File

@ -120,6 +120,14 @@ type SectorProving struct{}
func (evt SectorProving) apply(*SectorInfo) {} func (evt SectorProving) apply(*SectorInfo) {}
type SectorFinalized struct{}
func (evt SectorFinalized) apply(*SectorInfo) {}
type SectorFinalizeFailed struct{ error }
func (evt SectorFinalizeFailed) apply(*SectorInfo) {}
// Failed state recovery // Failed state recovery
type SectorRetrySeal struct{} type SectorRetrySeal struct{}

View File

@ -232,6 +232,14 @@ func (m *Sealing) handleCommitWait(ctx statemachine.Context, sector SectorInfo)
return ctx.Send(SectorProving{}) return ctx.Send(SectorProving{})
} }
func (m *Sealing) handleFinalizeSector(ctx statemachine.Context, sector SectorInfo) error {
if err := m.sb.FinalizeSector(ctx.Context(), sector.SectorID); err != nil {
return ctx.Send(SectorCommitFailed{err})
}
return ctx.Send(SectorFinalized{})
}
func (m *Sealing) handleFaulty(ctx statemachine.Context, sector SectorInfo) error { func (m *Sealing) handleFaulty(ctx statemachine.Context, sector SectorInfo) error {
// TODO: check if the fault has already been reported, and that this sector is even valid // TODO: check if the fault has already been reported, and that this sector is even valid