diff --git a/api/api_storage.go b/api/api_storage.go index 77cf32a84..7f6894c75 100644 --- a/api/api_storage.go +++ b/api/api_storage.go @@ -22,11 +22,11 @@ const ( WaitSeed // waiting for seed Committing CommitWait // waiting for message to land on chain + FinalizeSector Proving _ // reserved _ _ - _ // recovery handling // Reseal diff --git a/storage/sealing/fsm.go b/storage/sealing/fsm.go index ad0803488..4e48be15e 100644 --- a/storage/sealing/fsm.go +++ b/storage/sealing/fsm.go @@ -48,10 +48,14 @@ var fsmPlanners = []func(events []statemachine.Event, state *SectorInfo) error{ ), api.Committing: planCommitting, api.CommitWait: planOne( - on(SectorProving{}, api.Proving), + on(SectorProving{}, api.FinalizeSector), on(SectorCommitFailed{}, api.CommitFailed), ), + api.FinalizeSector: planOne( + on(SectorFinalized{}, api.Proving), + ), + api.Proving: planOne( on(SectorFaultReported{}, api.FaultReported), on(SectorFaulty{}, api.Faulty), @@ -150,6 +154,8 @@ func (m *Sealing) plan(events []statemachine.Event, state *SectorInfo) (func(sta return m.handleCommitting, nil case api.CommitWait: return m.handleCommitWait, nil + case api.FinalizeSector: + case api.Proving: // TODO: track sector health / expiration log.Infof("Proving sector %d", state.SectorID) diff --git a/storage/sealing/fsm_events.go b/storage/sealing/fsm_events.go index ee4963750..84b1120c8 100644 --- a/storage/sealing/fsm_events.go +++ b/storage/sealing/fsm_events.go @@ -120,6 +120,14 @@ type SectorProving struct{} 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 type SectorRetrySeal struct{} diff --git a/storage/sealing/states.go b/storage/sealing/states.go index 519245e03..22a7f642b 100644 --- a/storage/sealing/states.go +++ b/storage/sealing/states.go @@ -232,6 +232,14 @@ func (m *Sealing) handleCommitWait(ctx statemachine.Context, sector SectorInfo) 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 { // TODO: check if the fault has already been reported, and that this sector is even valid