2020-08-16 09:42:13 +00:00
|
|
|
//go:generate go run ./gen
|
|
|
|
|
2020-01-15 20:49:11 +00:00
|
|
|
package sealing
|
|
|
|
|
|
|
|
import (
|
2020-04-06 18:07:26 +00:00
|
|
|
"bytes"
|
2020-01-15 20:49:11 +00:00
|
|
|
"context"
|
2020-03-22 20:44:27 +00:00
|
|
|
"encoding/json"
|
2020-01-22 20:29:19 +00:00
|
|
|
"fmt"
|
2020-01-16 01:25:49 +00:00
|
|
|
"reflect"
|
2020-01-22 20:29:19 +00:00
|
|
|
"time"
|
2020-01-15 20:49:11 +00:00
|
|
|
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
2020-04-06 18:07:26 +00:00
|
|
|
statemachine "github.com/filecoin-project/go-statemachine"
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
2020-01-15 20:49:11 +00:00
|
|
|
)
|
|
|
|
|
2020-03-06 18:59:08 +00:00
|
|
|
func (m *Sealing) Plan(events []statemachine.Event, user interface{}) (interface{}, uint64, error) {
|
2020-08-27 10:39:20 +00:00
|
|
|
next, processed, err := m.plan(events, user.(*SectorInfo))
|
2020-01-15 20:49:11 +00:00
|
|
|
if err != nil || next == nil {
|
2020-08-27 10:39:20 +00:00
|
|
|
return nil, processed, err
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return func(ctx statemachine.Context, si SectorInfo) error {
|
|
|
|
err := next(ctx, si)
|
|
|
|
if err != nil {
|
2020-04-06 22:31:33 +00:00
|
|
|
log.Errorf("unhandled sector error (%d): %+v", si.SectorNumber, err)
|
2020-01-23 16:11:58 +00:00
|
|
|
return nil
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2020-08-27 10:39:20 +00:00
|
|
|
}, processed, nil // TODO: This processed event count is not very correct
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
2020-08-27 10:39:20 +00:00
|
|
|
var fsmPlanners = map[SectorState]func(events []statemachine.Event, state *SectorInfo) (uint64, error){
|
2020-06-22 16:42:38 +00:00
|
|
|
// Sealing
|
|
|
|
|
2020-06-23 19:32:22 +00:00
|
|
|
UndefinedSectorState: planOne(
|
2020-06-23 19:59:57 +00:00
|
|
|
on(SectorStart{}, Empty),
|
2020-06-23 19:32:22 +00:00
|
|
|
on(SectorStartCC{}, Packing),
|
|
|
|
),
|
2020-06-23 19:59:57 +00:00
|
|
|
Empty: planOne(on(SectorAddPiece{}, WaitDeals)),
|
|
|
|
WaitDeals: planOne(
|
|
|
|
on(SectorAddPiece{}, WaitDeals),
|
|
|
|
on(SectorStartPacking{}, Packing),
|
|
|
|
),
|
2020-06-23 19:32:22 +00:00
|
|
|
Packing: planOne(on(SectorPacked{}, PreCommit1)),
|
2020-04-06 20:23:37 +00:00
|
|
|
PreCommit1: planOne(
|
|
|
|
on(SectorPreCommit1{}, PreCommit2),
|
2020-06-04 15:29:31 +00:00
|
|
|
on(SectorSealPreCommit1Failed{}, SealPreCommit1Failed),
|
2020-08-27 20:41:35 +00:00
|
|
|
on(SectorDealsExpired{}, DealsExpired),
|
2020-08-27 19:04:43 +00:00
|
|
|
on(SectorInvalidDealIDs{}, RecoverDealIDs),
|
2020-04-03 16:54:01 +00:00
|
|
|
),
|
2020-04-06 20:23:37 +00:00
|
|
|
PreCommit2: planOne(
|
|
|
|
on(SectorPreCommit2{}, PreCommitting),
|
2020-06-04 15:29:31 +00:00
|
|
|
on(SectorSealPreCommit2Failed{}, SealPreCommit2Failed),
|
2020-01-16 02:53:59 +00:00
|
|
|
),
|
2020-04-06 20:23:37 +00:00
|
|
|
PreCommitting: planOne(
|
2020-06-04 15:29:31 +00:00
|
|
|
on(SectorSealPreCommit1Failed{}, SealPreCommit1Failed),
|
2020-05-18 22:49:21 +00:00
|
|
|
on(SectorPreCommitted{}, PreCommitWait),
|
2020-04-06 20:23:37 +00:00
|
|
|
on(SectorChainPreCommitFailed{}, PreCommitFailed),
|
2020-06-02 21:45:28 +00:00
|
|
|
on(SectorPreCommitLanded{}, WaitSeed),
|
2020-08-27 11:51:13 +00:00
|
|
|
on(SectorDealsExpired{}, DealsExpired),
|
2020-08-27 19:04:43 +00:00
|
|
|
on(SectorInvalidDealIDs{}, RecoverDealIDs),
|
2020-01-16 02:53:59 +00:00
|
|
|
),
|
2020-05-18 22:49:21 +00:00
|
|
|
PreCommitWait: planOne(
|
|
|
|
on(SectorChainPreCommitFailed{}, PreCommitFailed),
|
|
|
|
on(SectorPreCommitLanded{}, WaitSeed),
|
2020-08-27 12:02:00 +00:00
|
|
|
on(SectorRetryPreCommit{}, PreCommitting),
|
2020-05-18 22:49:21 +00:00
|
|
|
),
|
2020-04-06 20:23:37 +00:00
|
|
|
WaitSeed: planOne(
|
|
|
|
on(SectorSeedReady{}, Committing),
|
|
|
|
on(SectorChainPreCommitFailed{}, PreCommitFailed),
|
2020-01-16 02:53:59 +00:00
|
|
|
),
|
2020-04-06 18:07:26 +00:00
|
|
|
Committing: planCommitting,
|
2020-08-27 10:57:08 +00:00
|
|
|
SubmitCommit: planOne(
|
|
|
|
on(SectorCommitSubmitted{}, CommitWait),
|
|
|
|
on(SectorCommitFailed{}, CommitFailed),
|
|
|
|
),
|
2020-04-06 18:07:26 +00:00
|
|
|
CommitWait: planOne(
|
|
|
|
on(SectorProving{}, FinalizeSector),
|
|
|
|
on(SectorCommitFailed{}, CommitFailed),
|
2020-08-27 12:02:00 +00:00
|
|
|
on(SectorRetrySubmitCommit{}, SubmitCommit),
|
2020-01-20 08:23:56 +00:00
|
|
|
),
|
2020-01-16 01:25:49 +00:00
|
|
|
|
2020-04-06 18:07:26 +00:00
|
|
|
FinalizeSector: planOne(
|
|
|
|
on(SectorFinalized{}, Proving),
|
2020-06-03 21:42:13 +00:00
|
|
|
on(SectorFinalizeFailed{}, FinalizeFailed),
|
2020-01-29 21:25:06 +00:00
|
|
|
),
|
|
|
|
|
2020-06-22 16:42:38 +00:00
|
|
|
// Sealing errors
|
2020-01-16 02:53:59 +00:00
|
|
|
|
2020-06-04 15:29:31 +00:00
|
|
|
SealPreCommit1Failed: planOne(
|
|
|
|
on(SectorRetrySealPreCommit1{}, PreCommit1),
|
|
|
|
),
|
|
|
|
SealPreCommit2Failed: planOne(
|
|
|
|
on(SectorRetrySealPreCommit1{}, PreCommit1),
|
|
|
|
on(SectorRetrySealPreCommit2{}, PreCommit2),
|
2020-01-23 15:38:01 +00:00
|
|
|
),
|
2020-04-06 20:23:37 +00:00
|
|
|
PreCommitFailed: planOne(
|
|
|
|
on(SectorRetryPreCommit{}, PreCommitting),
|
|
|
|
on(SectorRetryWaitSeed{}, WaitSeed),
|
2020-06-04 15:29:31 +00:00
|
|
|
on(SectorSealPreCommit1Failed{}, SealPreCommit1Failed),
|
2020-06-02 21:45:28 +00:00
|
|
|
on(SectorPreCommitLanded{}, WaitSeed),
|
2020-08-27 11:51:13 +00:00
|
|
|
on(SectorDealsExpired{}, DealsExpired),
|
2020-08-27 19:04:43 +00:00
|
|
|
on(SectorInvalidDealIDs{}, RecoverDealIDs),
|
2020-01-23 17:34:04 +00:00
|
|
|
),
|
2020-04-06 20:23:37 +00:00
|
|
|
ComputeProofFailed: planOne(
|
|
|
|
on(SectorRetryComputeProof{}, Committing),
|
2020-06-04 15:29:31 +00:00
|
|
|
on(SectorSealPreCommit1Failed{}, SealPreCommit1Failed),
|
2020-04-03 17:45:48 +00:00
|
|
|
),
|
2020-04-06 20:23:37 +00:00
|
|
|
CommitFailed: planOne(
|
2020-06-04 15:29:31 +00:00
|
|
|
on(SectorSealPreCommit1Failed{}, SealPreCommit1Failed),
|
2020-04-06 20:23:37 +00:00
|
|
|
on(SectorRetryWaitSeed{}, WaitSeed),
|
|
|
|
on(SectorRetryComputeProof{}, Committing),
|
|
|
|
on(SectorRetryInvalidProof{}, Committing),
|
2020-06-17 15:19:36 +00:00
|
|
|
on(SectorRetryPreCommitWait{}, PreCommitWait),
|
2020-08-05 01:30:58 +00:00
|
|
|
on(SectorChainPreCommitFailed{}, PreCommitFailed),
|
|
|
|
on(SectorRetryPreCommit{}, PreCommitting),
|
2020-08-18 16:02:13 +00:00
|
|
|
on(SectorRetryCommitWait{}, CommitWait),
|
2020-08-27 11:51:13 +00:00
|
|
|
on(SectorDealsExpired{}, DealsExpired),
|
2020-08-27 19:04:43 +00:00
|
|
|
on(SectorInvalidDealIDs{}, RecoverDealIDs),
|
2020-04-03 17:45:48 +00:00
|
|
|
),
|
2020-06-03 21:42:13 +00:00
|
|
|
FinalizeFailed: planOne(
|
|
|
|
on(SectorRetryFinalize{}, FinalizeSector),
|
|
|
|
),
|
2020-08-27 20:41:35 +00:00
|
|
|
PackingFailed: planOne(), // TODO: Deprecated, remove
|
2020-08-27 21:14:46 +00:00
|
|
|
DealsExpired: planOne(
|
2020-08-27 11:51:13 +00:00
|
|
|
// SectorRemove (global)
|
|
|
|
),
|
2020-08-27 19:04:43 +00:00
|
|
|
RecoverDealIDs: planOne(
|
|
|
|
onReturning(SectorUpdateDealIDs{}),
|
|
|
|
),
|
2020-01-23 15:38:01 +00:00
|
|
|
|
2020-06-22 16:42:38 +00:00
|
|
|
// Post-seal
|
|
|
|
|
|
|
|
Proving: planOne(
|
|
|
|
on(SectorFaultReported{}, FaultReported),
|
|
|
|
on(SectorFaulty{}, Faulty),
|
|
|
|
),
|
|
|
|
Removing: planOne(
|
|
|
|
on(SectorRemoved{}, Removed),
|
|
|
|
on(SectorRemoveFailed{}, RemoveFailed),
|
|
|
|
),
|
2020-08-27 21:59:01 +00:00
|
|
|
RemoveFailed: planOne(
|
|
|
|
// SectorRemove (global)
|
|
|
|
),
|
2020-04-06 18:07:26 +00:00
|
|
|
Faulty: planOne(
|
|
|
|
on(SectorFaultReported{}, FaultReported),
|
2020-01-16 02:53:59 +00:00
|
|
|
),
|
2020-06-22 16:42:38 +00:00
|
|
|
|
2020-04-06 18:07:26 +00:00
|
|
|
FaultedFinal: final,
|
2020-06-22 16:42:38 +00:00
|
|
|
Removed: final,
|
2020-01-16 01:25:49 +00:00
|
|
|
}
|
|
|
|
|
2020-08-27 10:39:20 +00:00
|
|
|
func (m *Sealing) plan(events []statemachine.Event, state *SectorInfo) (func(statemachine.Context, SectorInfo) error, uint64, error) {
|
2020-01-15 20:49:11 +00:00
|
|
|
/////
|
|
|
|
// First process all events
|
|
|
|
|
2020-01-22 20:29:19 +00:00
|
|
|
for _, event := range events {
|
2020-03-22 20:44:27 +00:00
|
|
|
e, err := json.Marshal(event)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("marshaling event for logging: %+v", err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-01-22 20:29:19 +00:00
|
|
|
l := Log{
|
|
|
|
Timestamp: uint64(time.Now().Unix()),
|
2020-03-22 20:44:27 +00:00
|
|
|
Message: string(e),
|
2020-01-22 20:29:19 +00:00
|
|
|
Kind: fmt.Sprintf("event;%T", event.User),
|
|
|
|
}
|
|
|
|
|
|
|
|
if err, iserr := event.User.(xerrors.Formatter); iserr {
|
|
|
|
l.Trace = fmt.Sprintf("%+v", err)
|
|
|
|
}
|
|
|
|
|
2020-08-05 01:30:58 +00:00
|
|
|
if len(state.Log) > 8000 {
|
|
|
|
log.Warnw("truncating sector log", "sector", state.SectorNumber)
|
|
|
|
state.Log[2000] = Log{
|
|
|
|
Timestamp: uint64(time.Now().Unix()),
|
|
|
|
Message: "truncating log (above 8000 entries)",
|
|
|
|
Kind: fmt.Sprintf("truncate"),
|
|
|
|
}
|
|
|
|
|
|
|
|
state.Log = append(state.Log[:2000], state.Log[:6000]...)
|
|
|
|
}
|
|
|
|
|
2020-01-22 20:29:19 +00:00
|
|
|
state.Log = append(state.Log, l)
|
|
|
|
}
|
|
|
|
|
2020-01-16 01:25:49 +00:00
|
|
|
p := fsmPlanners[state.State]
|
|
|
|
if p == nil {
|
2020-08-27 10:39:20 +00:00
|
|
|
return nil, 0, xerrors.Errorf("planner for state %s not found", state.State)
|
2020-01-16 01:25:49 +00:00
|
|
|
}
|
|
|
|
|
2020-08-27 10:39:20 +00:00
|
|
|
processed, err := p(events, state)
|
|
|
|
if err != nil {
|
|
|
|
return nil, 0, xerrors.Errorf("running planner for state %s failed: %w", state.State, err)
|
2020-01-16 01:25:49 +00:00
|
|
|
}
|
|
|
|
|
2020-01-15 20:49:11 +00:00
|
|
|
/////
|
|
|
|
// Now decide what to do next
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
2020-08-27 10:57:08 +00:00
|
|
|
* Empty <- incoming deals
|
|
|
|
| |
|
|
|
|
| v
|
|
|
|
*<- WaitDeals <- incoming deals
|
|
|
|
| |
|
|
|
|
| v
|
|
|
|
*<- Packing <- incoming committed capacity
|
|
|
|
| |
|
|
|
|
| v
|
|
|
|
*<- PreCommit1 <--> SealPreCommit1Failed
|
|
|
|
| | ^ ^^
|
|
|
|
| | *----------++----\
|
|
|
|
| v v || |
|
|
|
|
*<- PreCommit2 --------++--> SealPreCommit2Failed
|
|
|
|
| | ||
|
|
|
|
| v /-------/|
|
|
|
|
* PreCommitting <-----+---> PreCommitFailed
|
|
|
|
| | | ^
|
|
|
|
| v | |
|
|
|
|
*<- WaitSeed -----------+-----/
|
|
|
|
| ||| ^ |
|
|
|
|
| ||| \--------*-----/
|
|
|
|
| ||| |
|
|
|
|
| vvv v----+----> ComputeProofFailed
|
|
|
|
*<- Committing |
|
|
|
|
| | ^--> CommitFailed
|
|
|
|
| v ^
|
|
|
|
| SubmitCommit |
|
|
|
|
| | |
|
|
|
|
| v |
|
|
|
|
*<- CommitWait ---/
|
|
|
|
| |
|
|
|
|
| v
|
|
|
|
| FinalizeSector <--> FinalizeFailed
|
|
|
|
| |
|
|
|
|
| v
|
|
|
|
*<- Proving
|
|
|
|
|
|
|
|
|
v
|
|
|
|
FailedUnrecoverable
|
|
|
|
|
|
|
|
UndefinedSectorState <- ¯\_(ツ)_/¯
|
|
|
|
| ^
|
|
|
|
*---------------------/
|
2020-01-15 20:49:11 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2020-08-18 14:54:05 +00:00
|
|
|
m.stats.updateSector(m.minerSector(state.SectorNumber), state.State)
|
|
|
|
|
2020-01-15 20:49:11 +00:00
|
|
|
switch state.State {
|
|
|
|
// Happy path
|
2020-06-26 15:29:08 +00:00
|
|
|
case Empty:
|
|
|
|
fallthrough
|
|
|
|
case WaitDeals:
|
|
|
|
log.Infof("Waiting for deals %d", state.SectorNumber)
|
2020-04-06 18:07:26 +00:00
|
|
|
case Packing:
|
2020-08-27 10:39:20 +00:00
|
|
|
return m.handlePacking, processed, nil
|
2020-04-06 20:23:37 +00:00
|
|
|
case PreCommit1:
|
2020-08-27 10:39:20 +00:00
|
|
|
return m.handlePreCommit1, processed, nil
|
2020-04-06 20:23:37 +00:00
|
|
|
case PreCommit2:
|
2020-08-27 10:39:20 +00:00
|
|
|
return m.handlePreCommit2, processed, nil
|
2020-04-06 20:23:37 +00:00
|
|
|
case PreCommitting:
|
2020-08-27 10:39:20 +00:00
|
|
|
return m.handlePreCommitting, processed, nil
|
2020-05-18 22:49:21 +00:00
|
|
|
case PreCommitWait:
|
2020-08-27 10:39:20 +00:00
|
|
|
return m.handlePreCommitWait, processed, nil
|
2020-04-06 18:07:26 +00:00
|
|
|
case WaitSeed:
|
2020-08-27 10:39:20 +00:00
|
|
|
return m.handleWaitSeed, processed, nil
|
2020-04-06 18:07:26 +00:00
|
|
|
case Committing:
|
2020-08-27 10:39:20 +00:00
|
|
|
return m.handleCommitting, processed, nil
|
2020-08-27 10:57:08 +00:00
|
|
|
case SubmitCommit:
|
|
|
|
return m.handleSubmitCommit, processed, nil
|
2020-04-06 18:07:26 +00:00
|
|
|
case CommitWait:
|
2020-08-27 10:39:20 +00:00
|
|
|
return m.handleCommitWait, processed, nil
|
2020-04-06 18:07:26 +00:00
|
|
|
case FinalizeSector:
|
2020-08-27 10:39:20 +00:00
|
|
|
return m.handleFinalizeSector, processed, nil
|
2020-01-15 20:49:11 +00:00
|
|
|
|
|
|
|
// Handled failure modes
|
2020-06-04 15:29:31 +00:00
|
|
|
case SealPreCommit1Failed:
|
2020-08-27 10:39:20 +00:00
|
|
|
return m.handleSealPrecommit1Failed, processed, nil
|
2020-06-04 15:29:31 +00:00
|
|
|
case SealPreCommit2Failed:
|
2020-08-27 10:39:20 +00:00
|
|
|
return m.handleSealPrecommit2Failed, processed, nil
|
2020-04-06 18:07:26 +00:00
|
|
|
case PreCommitFailed:
|
2020-08-27 10:39:20 +00:00
|
|
|
return m.handlePreCommitFailed, processed, nil
|
2020-04-06 20:23:37 +00:00
|
|
|
case ComputeProofFailed:
|
2020-08-27 10:39:20 +00:00
|
|
|
return m.handleComputeProofFailed, processed, nil
|
2020-04-06 20:23:37 +00:00
|
|
|
case CommitFailed:
|
2020-08-27 10:39:20 +00:00
|
|
|
return m.handleCommitFailed, processed, nil
|
2020-06-03 21:42:13 +00:00
|
|
|
case FinalizeFailed:
|
2020-08-27 10:39:20 +00:00
|
|
|
return m.handleFinalizeFailed, processed, nil
|
2020-08-27 20:41:35 +00:00
|
|
|
case PackingFailed: // DEPRECATED: remove this for the next reset
|
|
|
|
state.State = DealsExpired
|
|
|
|
fallthrough
|
2020-08-27 11:51:13 +00:00
|
|
|
case DealsExpired:
|
|
|
|
return m.handleDealsExpired, processed, nil
|
2020-08-28 09:43:56 +00:00
|
|
|
case RecoverDealIDs:
|
|
|
|
return m.handleRecoverDealIDs, processed, nil
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2020-06-22 16:42:38 +00:00
|
|
|
// Post-seal
|
|
|
|
case Proving:
|
2020-08-27 10:39:20 +00:00
|
|
|
return m.handleProvingSector, processed, nil
|
2020-06-22 16:42:38 +00:00
|
|
|
case Removing:
|
2020-08-27 10:39:20 +00:00
|
|
|
return m.handleRemoving, processed, nil
|
2020-07-14 08:41:19 +00:00
|
|
|
case Removed:
|
2020-08-27 10:39:20 +00:00
|
|
|
return nil, processed, nil
|
2020-06-22 16:42:38 +00:00
|
|
|
|
2020-08-27 21:59:01 +00:00
|
|
|
case RemoveFailed:
|
|
|
|
return m.handleRemoveFailed, processed, nil
|
|
|
|
|
2020-01-15 20:49:11 +00:00
|
|
|
// Faults
|
2020-04-06 18:07:26 +00:00
|
|
|
case Faulty:
|
2020-08-27 10:39:20 +00:00
|
|
|
return m.handleFaulty, processed, nil
|
2020-04-06 18:07:26 +00:00
|
|
|
case FaultReported:
|
2020-08-27 10:39:20 +00:00
|
|
|
return m.handleFaultReported, processed, nil
|
2020-01-15 20:49:11 +00:00
|
|
|
|
|
|
|
// Fatal errors
|
2020-04-06 18:07:26 +00:00
|
|
|
case UndefinedSectorState:
|
2020-01-15 20:49:11 +00:00
|
|
|
log.Error("sector update with undefined state!")
|
2020-04-06 18:07:26 +00:00
|
|
|
case FailedUnrecoverable:
|
2020-04-06 22:31:33 +00:00
|
|
|
log.Errorf("sector %d failed unrecoverably", state.SectorNumber)
|
2020-01-15 20:49:11 +00:00
|
|
|
default:
|
2020-05-18 22:49:21 +00:00
|
|
|
log.Errorf("unexpected sector update state: %s", state.State)
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
2020-08-27 10:39:20 +00:00
|
|
|
return nil, processed, nil
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
2020-08-27 10:39:20 +00:00
|
|
|
func planCommitting(events []statemachine.Event, state *SectorInfo) (uint64, error) {
|
2020-08-27 10:57:08 +00:00
|
|
|
for i, event := range events {
|
2020-01-16 01:25:49 +00:00
|
|
|
switch e := event.User.(type) {
|
2020-01-16 02:53:59 +00:00
|
|
|
case globalMutator:
|
|
|
|
if e.applyGlobal(state) {
|
2020-08-27 10:57:08 +00:00
|
|
|
return uint64(i + 1), nil
|
2020-01-16 02:53:59 +00:00
|
|
|
}
|
2020-01-16 01:25:49 +00:00
|
|
|
case SectorCommitted: // the normal case
|
|
|
|
e.apply(state)
|
2020-08-27 10:57:08 +00:00
|
|
|
state.State = SubmitCommit
|
2020-01-16 01:25:49 +00:00
|
|
|
case SectorSeedReady: // seed changed :/
|
2020-04-06 18:07:26 +00:00
|
|
|
if e.SeedEpoch == state.SeedEpoch && bytes.Equal(e.SeedValue, state.SeedValue) {
|
2020-01-16 01:25:49 +00:00
|
|
|
log.Warnf("planCommitting: got SectorSeedReady, but the seed didn't change")
|
|
|
|
continue // or it didn't!
|
|
|
|
}
|
2020-08-27 10:57:08 +00:00
|
|
|
|
2020-01-16 01:25:49 +00:00
|
|
|
log.Warnf("planCommitting: commit Seed changed")
|
|
|
|
e.apply(state)
|
2020-04-06 18:07:26 +00:00
|
|
|
state.State = Committing
|
2020-08-27 10:57:08 +00:00
|
|
|
return uint64(i + 1), nil
|
2020-01-20 22:04:46 +00:00
|
|
|
case SectorComputeProofFailed:
|
2020-04-06 20:23:37 +00:00
|
|
|
state.State = ComputeProofFailed
|
2020-06-04 15:29:31 +00:00
|
|
|
case SectorSealPreCommit1Failed:
|
2020-07-15 01:41:35 +00:00
|
|
|
state.State = SealPreCommit1Failed
|
2020-01-28 19:46:26 +00:00
|
|
|
case SectorCommitFailed:
|
2020-04-06 18:07:26 +00:00
|
|
|
state.State = CommitFailed
|
2020-08-18 16:02:13 +00:00
|
|
|
case SectorRetryCommitWait:
|
|
|
|
state.State = CommitWait
|
2020-01-16 01:25:49 +00:00
|
|
|
default:
|
2020-08-27 10:57:08 +00:00
|
|
|
return uint64(i), xerrors.Errorf("planCommitting got event of unknown type %T, events: %+v", event.User, events)
|
2020-01-16 01:25:49 +00:00
|
|
|
}
|
|
|
|
}
|
2020-08-27 10:57:08 +00:00
|
|
|
return uint64(len(events)), nil
|
2020-01-16 01:25:49 +00:00
|
|
|
}
|
|
|
|
|
2020-01-15 20:49:11 +00:00
|
|
|
func (m *Sealing) restartSectors(ctx context.Context) error {
|
|
|
|
trackedSectors, err := m.ListSectors()
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("loading sector list: %+v", err)
|
|
|
|
}
|
|
|
|
|
2020-08-18 14:20:31 +00:00
|
|
|
cfg, err := m.getConfig()
|
2020-08-18 09:07:14 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting the sealing delay: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-08-30 02:14:36 +00:00
|
|
|
m.unsealedInfoMap.lk.Lock()
|
|
|
|
defer m.unsealedInfoMap.lk.Unlock()
|
2020-01-15 20:49:11 +00:00
|
|
|
for _, sector := range trackedSectors {
|
2020-04-06 22:31:33 +00:00
|
|
|
if err := m.sectors.Send(uint64(sector.SectorNumber), SectorRestart{}); err != nil {
|
|
|
|
log.Errorf("restarting sector %d: %+v", sector.SectorNumber, err)
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
2020-08-18 09:07:14 +00:00
|
|
|
|
|
|
|
if sector.State == WaitDeals {
|
2020-08-30 02:14:36 +00:00
|
|
|
|
|
|
|
// put the sector in the unsealedInfoMap
|
|
|
|
if _, ok := m.unsealedInfoMap.infos[sector.SectorNumber]; ok {
|
|
|
|
// something's funky here, but probably safe to move on
|
|
|
|
log.Warnf("sector %v was already in the unsealedInfoMap when restarting", sector.SectorNumber)
|
|
|
|
} else {
|
|
|
|
ui := UnsealedSectorInfo{}
|
|
|
|
for _, p := range sector.Pieces {
|
|
|
|
if p.DealInfo != nil {
|
|
|
|
ui.numDeals++
|
|
|
|
}
|
|
|
|
ui.stored += p.Piece.Size
|
|
|
|
ui.pieceSizes = append(ui.pieceSizes, p.Piece.Size.Unpadded())
|
|
|
|
}
|
|
|
|
|
|
|
|
m.unsealedInfoMap.infos[sector.SectorNumber] = ui
|
|
|
|
}
|
|
|
|
|
|
|
|
// start a fresh timer for the sector
|
2020-08-18 14:20:31 +00:00
|
|
|
if cfg.WaitDealsDelay > 0 {
|
|
|
|
timer := time.NewTimer(cfg.WaitDealsDelay)
|
2020-08-18 09:07:14 +00:00
|
|
|
go func() {
|
|
|
|
<-timer.C
|
2020-08-20 04:49:10 +00:00
|
|
|
if err := m.StartPacking(sector.SectorNumber); err != nil {
|
|
|
|
log.Errorf("starting sector %d: %+v", sector.SectorNumber, err)
|
|
|
|
}
|
2020-08-18 09:07:14 +00:00
|
|
|
}()
|
|
|
|
}
|
|
|
|
}
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Grab on-chain sector set and diff with trackedSectors
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-04-06 18:07:26 +00:00
|
|
|
func (m *Sealing) ForceSectorState(ctx context.Context, id abi.SectorNumber, state SectorState) error {
|
2020-01-15 20:49:11 +00:00
|
|
|
return m.sectors.Send(id, SectorForceState{state})
|
|
|
|
}
|
2020-01-16 01:25:49 +00:00
|
|
|
|
2020-08-27 10:39:20 +00:00
|
|
|
func final(events []statemachine.Event, state *SectorInfo) (uint64, error) {
|
|
|
|
return 0, xerrors.Errorf("didn't expect any events in state %s, got %+v", state.State, events)
|
2020-01-16 01:25:49 +00:00
|
|
|
}
|
|
|
|
|
2020-08-27 19:04:43 +00:00
|
|
|
func on(mut mutator, next SectorState) func() (mutator, func(*SectorInfo) error) {
|
|
|
|
return func() (mutator, func(*SectorInfo) error) {
|
|
|
|
return mut, func(state *SectorInfo) error {
|
|
|
|
state.State = next
|
|
|
|
return nil
|
|
|
|
}
|
2020-01-16 01:25:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-27 19:04:43 +00:00
|
|
|
func onReturning(mut mutator) func() (mutator, func(*SectorInfo) error) {
|
|
|
|
return func() (mutator, func(*SectorInfo) error) {
|
|
|
|
return mut, func(state *SectorInfo) error {
|
|
|
|
if state.Return == "" {
|
|
|
|
return xerrors.Errorf("return state not set")
|
|
|
|
}
|
|
|
|
|
|
|
|
state.State = SectorState(state.Return)
|
|
|
|
state.Return = ""
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func planOne(ts ...func() (mut mutator, next func(*SectorInfo) error)) func(events []statemachine.Event, state *SectorInfo) (uint64, error) {
|
2020-08-27 10:39:20 +00:00
|
|
|
return func(events []statemachine.Event, state *SectorInfo) (uint64, error) {
|
2020-01-22 19:47:29 +00:00
|
|
|
if gm, ok := events[0].User.(globalMutator); ok {
|
2020-01-22 18:30:56 +00:00
|
|
|
gm.applyGlobal(state)
|
2020-08-27 10:39:20 +00:00
|
|
|
return 1, nil
|
2020-01-22 18:30:56 +00:00
|
|
|
}
|
|
|
|
|
2020-01-16 01:25:49 +00:00
|
|
|
for _, t := range ts {
|
|
|
|
mut, next := t()
|
|
|
|
|
|
|
|
if reflect.TypeOf(events[0].User) != reflect.TypeOf(mut) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2020-01-21 16:05:10 +00:00
|
|
|
if err, iserr := events[0].User.(error); iserr {
|
2020-04-06 22:31:33 +00:00
|
|
|
log.Warnf("sector %d got error event %T: %+v", state.SectorNumber, events[0].User, err)
|
2020-01-21 16:05:10 +00:00
|
|
|
}
|
|
|
|
|
2020-01-16 01:25:49 +00:00
|
|
|
events[0].User.(mutator).apply(state)
|
2020-08-27 19:04:43 +00:00
|
|
|
return 1, next(state)
|
2020-01-16 01:25:49 +00:00
|
|
|
}
|
|
|
|
|
2020-07-06 17:04:11 +00:00
|
|
|
_, ok := events[0].User.(Ignorable)
|
|
|
|
if ok {
|
2020-08-27 10:39:20 +00:00
|
|
|
return 1, nil
|
2020-07-06 17:04:11 +00:00
|
|
|
}
|
|
|
|
|
2020-08-27 10:39:20 +00:00
|
|
|
return 0, xerrors.Errorf("planner for state %s received unexpected event %T (%+v)", state.State, events[0].User, events[0])
|
2020-01-16 01:25:49 +00:00
|
|
|
}
|
|
|
|
}
|