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"
|
2022-09-09 12:38:23 +00:00
|
|
|
"net/http"
|
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-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2022-06-15 10:06:22 +00:00
|
|
|
"github.com/filecoin-project/go-statemachine"
|
2022-09-09 12:38:23 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/api"
|
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 {
|
2022-03-02 20:03:03 +00:00
|
|
|
l := Log{
|
|
|
|
Timestamp: uint64(time.Now().Unix()),
|
|
|
|
Message: fmt.Sprintf("state machine error: %s", err),
|
|
|
|
Kind: fmt.Sprintf("error;%T", err),
|
|
|
|
}
|
|
|
|
user.(*SectorInfo).logAppend(l)
|
|
|
|
return nil, processed, nil
|
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){
|
2022-08-31 10:43:40 +00:00
|
|
|
// external import
|
|
|
|
ReceiveSector: planOne(
|
|
|
|
onReturning(SectorReceived{}),
|
|
|
|
),
|
|
|
|
|
2020-06-22 16:42:38 +00:00
|
|
|
// Sealing
|
|
|
|
|
2020-06-23 19:32:22 +00:00
|
|
|
UndefinedSectorState: planOne(
|
2021-01-18 13:26:03 +00:00
|
|
|
on(SectorStart{}, WaitDeals),
|
2020-06-23 19:32:22 +00:00
|
|
|
on(SectorStartCC{}, Packing),
|
2022-09-06 08:52:56 +00:00
|
|
|
on(SectorReceive{}, ReceiveSector),
|
2020-06-23 19:32:22 +00:00
|
|
|
),
|
2021-01-18 13:26:03 +00:00
|
|
|
Empty: planOne( // deprecated
|
|
|
|
on(SectorAddPiece{}, AddPiece),
|
|
|
|
on(SectorStartPacking{}, Packing),
|
|
|
|
),
|
2020-06-23 19:59:57 +00:00
|
|
|
WaitDeals: planOne(
|
2021-01-18 13:26:03 +00:00
|
|
|
on(SectorAddPiece{}, AddPiece),
|
2020-06-23 19:59:57 +00:00
|
|
|
on(SectorStartPacking{}, Packing),
|
|
|
|
),
|
2021-01-18 13:26:03 +00:00
|
|
|
AddPiece: planOne(
|
|
|
|
on(SectorPieceAdded{}, WaitDeals),
|
2021-01-18 20:59:34 +00:00
|
|
|
apply(SectorStartPacking{}),
|
2021-04-14 18:26:07 +00:00
|
|
|
apply(SectorAddPiece{}),
|
2021-01-20 17:42:22 +00:00
|
|
|
on(SectorAddPieceFailed{}, AddPieceFailed),
|
2021-01-18 13:26:03 +00:00
|
|
|
),
|
2020-10-13 19:35:29 +00:00
|
|
|
Packing: planOne(on(SectorPacked{}, GetTicket)),
|
|
|
|
GetTicket: planOne(
|
|
|
|
on(SectorTicket{}, PreCommit1),
|
|
|
|
on(SectorCommitFailed{}, CommitFailed),
|
|
|
|
),
|
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-09-29 07:57:36 +00:00
|
|
|
on(SectorOldTicket{}, GetTicket),
|
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-09-30 15:53:15 +00:00
|
|
|
on(SectorSealPreCommit1Failed{}, SealPreCommit1Failed),
|
2020-01-16 02:53:59 +00:00
|
|
|
),
|
2020-04-06 20:23:37 +00:00
|
|
|
PreCommitting: planOne(
|
2021-05-18 15:21:10 +00:00
|
|
|
on(SectorPreCommitBatch{}, SubmitPreCommitBatch),
|
2020-05-18 22:49:21 +00:00
|
|
|
on(SectorPreCommitted{}, PreCommitWait),
|
2021-05-20 16:39:59 +00:00
|
|
|
on(SectorSealPreCommit1Failed{}, SealPreCommit1Failed),
|
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
|
|
|
),
|
2021-05-18 15:37:52 +00:00
|
|
|
SubmitPreCommitBatch: planOne(
|
|
|
|
on(SectorPreCommitBatchSent{}, PreCommitBatchWait),
|
2021-05-20 16:39:59 +00:00
|
|
|
on(SectorSealPreCommit1Failed{}, SealPreCommit1Failed),
|
|
|
|
on(SectorChainPreCommitFailed{}, PreCommitFailed),
|
|
|
|
on(SectorPreCommitLanded{}, WaitSeed),
|
|
|
|
on(SectorDealsExpired{}, DealsExpired),
|
|
|
|
on(SectorInvalidDealIDs{}, RecoverDealIDs),
|
2021-05-18 15:37:52 +00:00
|
|
|
),
|
|
|
|
PreCommitBatchWait: planOne(
|
|
|
|
on(SectorChainPreCommitFailed{}, PreCommitFailed),
|
|
|
|
on(SectorPreCommitLanded{}, WaitSeed),
|
|
|
|
on(SectorRetryPreCommit{}, PreCommitting),
|
|
|
|
),
|
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,
|
2021-06-11 09:41:28 +00:00
|
|
|
CommitFinalize: planOne(
|
|
|
|
on(SectorFinalized{}, SubmitCommit),
|
2022-03-16 18:29:47 +00:00
|
|
|
on(SectorFinalizedAvailable{}, SubmitCommit),
|
2021-06-11 09:41:28 +00:00
|
|
|
on(SectorFinalizeFailed{}, CommitFinalizeFailed),
|
|
|
|
),
|
2020-08-27 10:57:08 +00:00
|
|
|
SubmitCommit: planOne(
|
|
|
|
on(SectorCommitSubmitted{}, CommitWait),
|
2021-03-10 15:16:44 +00:00
|
|
|
on(SectorSubmitCommitAggregate{}, SubmitCommitAggregate),
|
2021-05-20 16:39:59 +00:00
|
|
|
on(SectorCommitFailed{}, CommitFailed),
|
2021-03-10 15:16:44 +00:00
|
|
|
),
|
|
|
|
SubmitCommitAggregate: planOne(
|
2021-09-01 09:31:49 +00:00
|
|
|
on(SectorCommitAggregateSent{}, CommitAggregateWait),
|
2021-03-10 15:16:44 +00:00
|
|
|
on(SectorCommitFailed{}, CommitFailed),
|
2021-06-25 09:25:17 +00:00
|
|
|
on(SectorRetrySubmitCommit{}, SubmitCommit),
|
2020-08-27 10:57:08 +00:00
|
|
|
),
|
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
|
|
|
),
|
2021-03-10 15:16:44 +00:00
|
|
|
CommitAggregateWait: planOne(
|
|
|
|
on(SectorProving{}, FinalizeSector),
|
|
|
|
on(SectorCommitFailed{}, CommitFailed),
|
|
|
|
on(SectorRetrySubmitCommit{}, SubmitCommit),
|
|
|
|
),
|
2020-01-16 01:25:49 +00:00
|
|
|
|
2020-04-06 18:07:26 +00:00
|
|
|
FinalizeSector: planOne(
|
2022-09-09 12:38:23 +00:00
|
|
|
onWithCB(SectorFinalized{}, Proving, maybeNotifyRemoteDone(true, "Proving")),
|
|
|
|
onWithCB(SectorFinalizedAvailable{}, Available, maybeNotifyRemoteDone(true, "Available")),
|
2020-06-03 21:42:13 +00:00
|
|
|
on(SectorFinalizeFailed{}, FinalizeFailed),
|
2020-01-29 21:25:06 +00:00
|
|
|
),
|
|
|
|
|
2021-12-08 17:11:19 +00:00
|
|
|
// Snap deals
|
|
|
|
SnapDealsWaitDeals: planOne(
|
|
|
|
on(SectorAddPiece{}, SnapDealsAddPiece),
|
|
|
|
on(SectorStartPacking{}, SnapDealsPacking),
|
2022-01-21 17:39:18 +00:00
|
|
|
on(SectorAbortUpgrade{}, AbortUpgrade),
|
2021-12-08 17:11:19 +00:00
|
|
|
),
|
|
|
|
SnapDealsAddPiece: planOne(
|
|
|
|
on(SectorPieceAdded{}, SnapDealsWaitDeals),
|
|
|
|
apply(SectorStartPacking{}),
|
|
|
|
apply(SectorAddPiece{}),
|
|
|
|
on(SectorAddPieceFailed{}, SnapDealsAddPieceFailed),
|
2022-01-21 17:39:18 +00:00
|
|
|
on(SectorAbortUpgrade{}, AbortUpgrade),
|
2021-12-08 17:11:19 +00:00
|
|
|
),
|
|
|
|
SnapDealsPacking: planOne(
|
|
|
|
on(SectorPacked{}, UpdateReplica),
|
2022-01-21 17:39:18 +00:00
|
|
|
on(SectorAbortUpgrade{}, AbortUpgrade),
|
2021-12-08 17:11:19 +00:00
|
|
|
),
|
|
|
|
UpdateReplica: planOne(
|
|
|
|
on(SectorReplicaUpdate{}, ProveReplicaUpdate),
|
|
|
|
on(SectorUpdateReplicaFailed{}, ReplicaUpdateFailed),
|
|
|
|
on(SectorDealsExpired{}, SnapDealsDealsExpired),
|
|
|
|
on(SectorInvalidDealIDs{}, SnapDealsRecoverDealIDs),
|
2022-01-21 17:39:18 +00:00
|
|
|
on(SectorAbortUpgrade{}, AbortUpgrade),
|
2021-12-08 17:11:19 +00:00
|
|
|
),
|
|
|
|
ProveReplicaUpdate: planOne(
|
2022-05-02 20:18:31 +00:00
|
|
|
on(SectorProveReplicaUpdate{}, FinalizeReplicaUpdate),
|
2021-12-08 17:11:19 +00:00
|
|
|
on(SectorProveReplicaUpdateFailed{}, ReplicaUpdateFailed),
|
|
|
|
on(SectorDealsExpired{}, SnapDealsDealsExpired),
|
|
|
|
on(SectorInvalidDealIDs{}, SnapDealsRecoverDealIDs),
|
2022-01-21 17:39:18 +00:00
|
|
|
on(SectorAbortUpgrade{}, AbortUpgrade),
|
2021-12-08 17:11:19 +00:00
|
|
|
),
|
2022-05-02 20:18:31 +00:00
|
|
|
FinalizeReplicaUpdate: planOne(
|
|
|
|
on(SectorFinalized{}, SubmitReplicaUpdate),
|
|
|
|
on(SectorFinalizeFailed{}, FinalizeReplicaUpdateFailed),
|
|
|
|
),
|
2021-12-08 17:11:19 +00:00
|
|
|
SubmitReplicaUpdate: planOne(
|
|
|
|
on(SectorReplicaUpdateSubmitted{}, ReplicaUpdateWait),
|
|
|
|
on(SectorSubmitReplicaUpdateFailed{}, ReplicaUpdateFailed),
|
|
|
|
),
|
|
|
|
ReplicaUpdateWait: planOne(
|
2022-05-02 20:18:31 +00:00
|
|
|
on(SectorReplicaUpdateLanded{}, UpdateActivating),
|
2021-12-08 17:11:19 +00:00
|
|
|
on(SectorSubmitReplicaUpdateFailed{}, ReplicaUpdateFailed),
|
|
|
|
on(SectorAbortUpgrade{}, AbortUpgrade),
|
|
|
|
),
|
2022-02-09 11:41:39 +00:00
|
|
|
UpdateActivating: planOne(
|
|
|
|
on(SectorUpdateActive{}, ReleaseSectorKey),
|
|
|
|
),
|
|
|
|
ReleaseSectorKey: planOne(
|
|
|
|
on(SectorKeyReleased{}, Proving),
|
|
|
|
on(SectorReleaseKeyFailed{}, ReleaseSectorKeyFailed),
|
2021-12-08 17:11:19 +00:00
|
|
|
),
|
2020-06-22 16:42:38 +00:00
|
|
|
// Sealing errors
|
2020-01-16 02:53:59 +00:00
|
|
|
|
2021-10-04 18:00:07 +00:00
|
|
|
AddPieceFailed: planOne(
|
|
|
|
on(SectorRetryWaitDeals{}, WaitDeals),
|
|
|
|
apply(SectorStartPacking{}),
|
|
|
|
apply(SectorAddPiece{}),
|
|
|
|
),
|
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),
|
2020-11-03 17:46:33 +00:00
|
|
|
on(SectorRetryPreCommitWait{}, PreCommitWait),
|
2020-04-06 20:23:37 +00:00
|
|
|
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),
|
2022-09-09 12:38:23 +00:00
|
|
|
onWithCB(SectorDealsExpired{}, DealsExpired, maybeNotifyRemoteDone(false, "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
|
|
|
),
|
2022-09-09 10:54:48 +00:00
|
|
|
RemoteCommitFailed: planOne(
|
2022-09-09 08:32:27 +00:00
|
|
|
on(SectorRetryComputeProof{}, Committing),
|
|
|
|
),
|
2021-06-11 09:42:54 +00:00
|
|
|
CommitFinalizeFailed: planOne(
|
2021-06-18 04:09:02 +00:00
|
|
|
on(SectorRetryFinalize{}, CommitFinalize),
|
2021-06-11 09:42:54 +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-11-03 17:46:33 +00:00
|
|
|
on(SectorRetrySubmitCommit{}, SubmitCommit),
|
2022-09-09 12:38:23 +00:00
|
|
|
onWithCB(SectorDealsExpired{}, DealsExpired, maybeNotifyRemoteDone(false, "DealsExpired")),
|
2020-08-27 19:04:43 +00:00
|
|
|
on(SectorInvalidDealIDs{}, RecoverDealIDs),
|
2022-09-09 12:38:23 +00:00
|
|
|
onWithCB(SectorTicketExpired{}, Removing, maybeNotifyRemoteDone(false, "Removing")),
|
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
|
|
|
|
2021-12-08 17:11:19 +00:00
|
|
|
// Snap Deals Errors
|
|
|
|
SnapDealsAddPieceFailed: planOne(
|
|
|
|
on(SectorRetryWaitDeals{}, SnapDealsWaitDeals),
|
|
|
|
apply(SectorStartPacking{}),
|
|
|
|
apply(SectorAddPiece{}),
|
2022-01-21 17:39:18 +00:00
|
|
|
on(SectorAbortUpgrade{}, AbortUpgrade),
|
2021-12-08 17:11:19 +00:00
|
|
|
),
|
|
|
|
SnapDealsDealsExpired: planOne(
|
|
|
|
on(SectorAbortUpgrade{}, AbortUpgrade),
|
|
|
|
),
|
|
|
|
SnapDealsRecoverDealIDs: planOne(
|
|
|
|
on(SectorUpdateDealIDs{}, SubmitReplicaUpdate),
|
|
|
|
on(SectorAbortUpgrade{}, AbortUpgrade),
|
|
|
|
),
|
|
|
|
AbortUpgrade: planOneOrIgnore(
|
|
|
|
on(SectorRevertUpgradeToProving{}, Proving),
|
|
|
|
),
|
|
|
|
ReplicaUpdateFailed: planOne(
|
|
|
|
on(SectorRetrySubmitReplicaUpdateWait{}, ReplicaUpdateWait),
|
|
|
|
on(SectorRetrySubmitReplicaUpdate{}, SubmitReplicaUpdate),
|
|
|
|
on(SectorRetryReplicaUpdate{}, UpdateReplica),
|
|
|
|
on(SectorRetryProveReplicaUpdate{}, ProveReplicaUpdate),
|
|
|
|
on(SectorInvalidDealIDs{}, SnapDealsRecoverDealIDs),
|
|
|
|
on(SectorDealsExpired{}, SnapDealsDealsExpired),
|
2022-01-21 17:39:18 +00:00
|
|
|
on(SectorAbortUpgrade{}, AbortUpgrade),
|
2021-12-08 17:11:19 +00:00
|
|
|
),
|
2022-02-09 11:41:39 +00:00
|
|
|
ReleaseSectorKeyFailed: planOne(
|
|
|
|
on(SectorUpdateActive{}, ReleaseSectorKey),
|
|
|
|
),
|
2022-03-02 16:33:33 +00:00
|
|
|
FinalizeReplicaUpdateFailed: planOne(
|
|
|
|
on(SectorRetryFinalize{}, FinalizeReplicaUpdate),
|
|
|
|
),
|
2021-12-08 17:11:19 +00:00
|
|
|
|
2020-06-22 16:42:38 +00:00
|
|
|
// Post-seal
|
|
|
|
|
|
|
|
Proving: planOne(
|
|
|
|
on(SectorFaultReported{}, FaultReported),
|
|
|
|
on(SectorFaulty{}, Faulty),
|
2022-03-16 16:33:05 +00:00
|
|
|
on(SectorMarkForUpdate{}, Available),
|
|
|
|
),
|
|
|
|
Available: planOne(
|
2021-12-08 17:11:19 +00:00
|
|
|
on(SectorStartCCUpdate{}, SnapDealsWaitDeals),
|
2022-03-16 17:53:54 +00:00
|
|
|
on(SectorAbortUpgrade{}, Proving),
|
2020-06-22 16:42:38 +00:00
|
|
|
),
|
2021-01-12 23:42:01 +00:00
|
|
|
Terminating: planOne(
|
|
|
|
on(SectorTerminating{}, TerminateWait),
|
|
|
|
on(SectorTerminateFailed{}, TerminateFailed),
|
|
|
|
),
|
|
|
|
TerminateWait: planOne(
|
|
|
|
on(SectorTerminated{}, TerminateFinality),
|
|
|
|
on(SectorTerminateFailed{}, TerminateFailed),
|
|
|
|
),
|
|
|
|
TerminateFinality: planOne(
|
|
|
|
on(SectorTerminateFailed{}, TerminateFailed),
|
|
|
|
// SectorRemove (global)
|
|
|
|
),
|
|
|
|
TerminateFailed: planOne(
|
|
|
|
// SectorTerminating (global)
|
|
|
|
),
|
2021-12-08 17:11:19 +00:00
|
|
|
Removing: planOneOrIgnore(
|
2020-06-22 16:42:38 +00:00
|
|
|
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-11-26 09:57:47 +00:00
|
|
|
FaultReported: final, // not really supported right now
|
|
|
|
|
2020-04-06 18:07:26 +00:00
|
|
|
FaultedFinal: final,
|
2022-03-28 11:07:12 +00:00
|
|
|
Removed: finalRemoved,
|
2020-11-26 09:57:47 +00:00
|
|
|
|
|
|
|
FailedUnrecoverable: final,
|
2020-01-16 01:25:49 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 20:03:03 +00:00
|
|
|
func (state *SectorInfo) logAppend(l Log) {
|
|
|
|
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:]...)
|
|
|
|
}
|
|
|
|
|
|
|
|
state.Log = append(state.Log, l)
|
|
|
|
}
|
|
|
|
|
2021-03-11 11:52:34 +00:00
|
|
|
func (m *Sealing) logEvents(events []statemachine.Event, state *SectorInfo) {
|
2020-01-22 20:29:19 +00:00
|
|
|
for _, event := range events {
|
2021-05-30 13:13:38 +00:00
|
|
|
log.Debugw("sector event", "sector", state.SectorNumber, "type", fmt.Sprintf("%T", event.User), "event", event.User)
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-03-11 11:52:34 +00:00
|
|
|
if event.User == (SectorRestart{}) {
|
|
|
|
continue // don't log on every fsm restart
|
|
|
|
}
|
|
|
|
|
2021-05-30 17:24:42 +00:00
|
|
|
if len(e) > 8000 {
|
|
|
|
e = []byte(string(e[:8000]) + "... truncated")
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2022-03-02 20:03:03 +00:00
|
|
|
state.logAppend(l)
|
2020-01-22 20:29:19 +00:00
|
|
|
}
|
2021-03-11 11:52:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Sealing) plan(events []statemachine.Event, state *SectorInfo) (func(statemachine.Context, SectorInfo) error, uint64, error) {
|
|
|
|
/////
|
|
|
|
// First process all events
|
|
|
|
|
|
|
|
m.logEvents(events, state)
|
2020-01-22 20:29:19 +00:00
|
|
|
|
2020-08-11 12:22:35 +00:00
|
|
|
if m.notifee != nil {
|
|
|
|
defer func(before SectorInfo) {
|
|
|
|
m.notifee(before, *state)
|
|
|
|
}(*state) // take safe-ish copy of the before state (except for nested pointers)
|
|
|
|
}
|
|
|
|
|
2020-01-16 01:25:49 +00:00
|
|
|
p := fsmPlanners[state.State]
|
|
|
|
if p == nil {
|
2021-04-05 16:25:29 +00:00
|
|
|
if len(events) == 1 {
|
|
|
|
if _, ok := events[0].User.(globalMutator); ok {
|
|
|
|
p = planOne() // in case we're in a really weird state, allow restart / update state / remove
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if p == nil {
|
|
|
|
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 {
|
2022-03-17 14:40:11 +00:00
|
|
|
return nil, processed, 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
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
2021-01-18 13:26:03 +00:00
|
|
|
UndefinedSectorState (start)
|
|
|
|
v |
|
|
|
|
*<- WaitDeals <-> AddPiece |
|
|
|
|
| | /--------------------/
|
|
|
|
| v v
|
2020-08-27 10:57:08 +00:00
|
|
|
*<- Packing <- incoming committed capacity
|
|
|
|
| |
|
|
|
|
| v
|
2020-09-29 07:57:36 +00:00
|
|
|
| GetTicket
|
|
|
|
| | ^
|
|
|
|
| v |
|
2020-08-27 10:57:08 +00:00
|
|
|
*<- PreCommit1 <--> SealPreCommit1Failed
|
|
|
|
| | ^ ^^
|
|
|
|
| | *----------++----\
|
|
|
|
| v v || |
|
|
|
|
*<- PreCommit2 --------++--> SealPreCommit2Failed
|
|
|
|
| | ||
|
|
|
|
| v /-------/|
|
|
|
|
* PreCommitting <-----+---> PreCommitFailed
|
|
|
|
| | | ^
|
|
|
|
| v | |
|
|
|
|
*<- WaitSeed -----------+-----/
|
|
|
|
| ||| ^ |
|
|
|
|
| ||| \--------*-----/
|
|
|
|
| ||| |
|
|
|
|
| vvv v----+----> ComputeProofFailed
|
|
|
|
*<- Committing |
|
|
|
|
| | ^--> CommitFailed
|
|
|
|
| v ^
|
2021-09-23 02:39:39 +00:00
|
|
|
| SubmitCommit |
|
|
|
|
| | |
|
|
|
|
| v |
|
2020-08-27 10:57:08 +00:00
|
|
|
*<- CommitWait ---/
|
|
|
|
| |
|
|
|
|
| v
|
|
|
|
| FinalizeSector <--> FinalizeFailed
|
|
|
|
| |
|
|
|
|
| v
|
|
|
|
*<- Proving
|
|
|
|
|
|
|
|
|
v
|
|
|
|
FailedUnrecoverable
|
|
|
|
|
2020-01-15 20:49:11 +00:00
|
|
|
*/
|
|
|
|
|
2021-03-12 13:54:10 +00:00
|
|
|
if err := m.onUpdateSector(context.TODO(), state); err != nil {
|
|
|
|
log.Errorw("update sector stats", "error", err)
|
|
|
|
}
|
2020-08-18 14:54:05 +00:00
|
|
|
|
2020-01-15 20:49:11 +00:00
|
|
|
switch state.State {
|
2022-08-31 10:43:40 +00:00
|
|
|
case ReceiveSector:
|
|
|
|
return m.handleReceiveSector, processed, nil
|
|
|
|
|
2020-01-15 20:49:11 +00:00
|
|
|
// Happy path
|
2020-06-26 15:29:08 +00:00
|
|
|
case Empty:
|
|
|
|
fallthrough
|
|
|
|
case WaitDeals:
|
2021-01-18 13:26:03 +00:00
|
|
|
return m.handleWaitDeals, processed, nil
|
|
|
|
case AddPiece:
|
|
|
|
return m.handleAddPiece, processed, nil
|
2020-04-06 18:07:26 +00:00
|
|
|
case Packing:
|
2020-08-27 10:39:20 +00:00
|
|
|
return m.handlePacking, processed, nil
|
2020-09-29 07:57:36 +00:00
|
|
|
case GetTicket:
|
|
|
|
return m.handleGetTicket, 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
|
2021-05-18 15:21:10 +00:00
|
|
|
case SubmitPreCommitBatch:
|
|
|
|
return m.handleSubmitPreCommitBatch, processed, nil
|
2021-05-18 15:37:52 +00:00
|
|
|
case PreCommitBatchWait:
|
|
|
|
fallthrough
|
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
|
2021-05-18 15:21:10 +00:00
|
|
|
case SubmitCommitAggregate:
|
|
|
|
return m.handleSubmitCommitAggregate, processed, nil
|
2021-03-10 15:16:44 +00:00
|
|
|
case CommitAggregateWait:
|
|
|
|
fallthrough
|
2020-04-06 18:07:26 +00:00
|
|
|
case CommitWait:
|
2020-08-27 10:39:20 +00:00
|
|
|
return m.handleCommitWait, processed, nil
|
2021-06-11 09:41:28 +00:00
|
|
|
case CommitFinalize:
|
|
|
|
fallthrough
|
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
|
|
|
|
2021-12-08 17:11:19 +00:00
|
|
|
// Snap deals updates
|
|
|
|
case SnapDealsWaitDeals:
|
|
|
|
return m.handleWaitDeals, processed, nil
|
|
|
|
case SnapDealsAddPiece:
|
|
|
|
return m.handleAddPiece, processed, nil
|
|
|
|
case SnapDealsPacking:
|
|
|
|
return m.handlePacking, processed, nil
|
|
|
|
case UpdateReplica:
|
|
|
|
return m.handleReplicaUpdate, processed, nil
|
|
|
|
case ProveReplicaUpdate:
|
|
|
|
return m.handleProveReplicaUpdate, processed, nil
|
|
|
|
case SubmitReplicaUpdate:
|
|
|
|
return m.handleSubmitReplicaUpdate, processed, nil
|
|
|
|
case ReplicaUpdateWait:
|
|
|
|
return m.handleReplicaUpdateWait, processed, nil
|
|
|
|
case FinalizeReplicaUpdate:
|
|
|
|
return m.handleFinalizeReplicaUpdate, processed, nil
|
2022-02-09 11:41:39 +00:00
|
|
|
case UpdateActivating:
|
|
|
|
return m.handleUpdateActivating, processed, nil
|
|
|
|
case ReleaseSectorKey:
|
|
|
|
return m.handleReleaseSectorKey, processed, nil
|
2021-12-08 17:11:19 +00:00
|
|
|
|
2020-01-15 20:49:11 +00:00
|
|
|
// Handled failure modes
|
2021-10-04 18:00:07 +00:00
|
|
|
case AddPieceFailed:
|
|
|
|
return m.handleAddPieceFailed, processed, nil
|
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
|
2022-09-09 10:54:48 +00:00
|
|
|
case RemoteCommitFailed:
|
|
|
|
return m.handleRemoteCommitFailed, 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
|
2021-06-11 09:42:54 +00:00
|
|
|
case CommitFinalizeFailed:
|
|
|
|
fallthrough
|
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:
|
2021-12-08 17:11:19 +00:00
|
|
|
return m.HandleRecoverDealIDs, processed, nil
|
|
|
|
|
|
|
|
// Snap Deals failure modes
|
|
|
|
case SnapDealsAddPieceFailed:
|
|
|
|
return m.handleAddPieceFailed, processed, nil
|
|
|
|
|
|
|
|
case SnapDealsDealsExpired:
|
|
|
|
return m.handleDealsExpiredSnapDeals, processed, nil
|
|
|
|
case SnapDealsRecoverDealIDs:
|
|
|
|
return m.handleSnapDealsRecoverDealIDs, processed, nil
|
|
|
|
case ReplicaUpdateFailed:
|
|
|
|
return m.handleSubmitReplicaUpdateFailed, processed, nil
|
2022-02-09 11:41:39 +00:00
|
|
|
case ReleaseSectorKeyFailed:
|
|
|
|
return m.handleReleaseSectorKeyFailed, 0, err
|
2022-03-02 16:33:33 +00:00
|
|
|
case FinalizeReplicaUpdateFailed:
|
|
|
|
return m.handleFinalizeFailed, processed, nil
|
2021-12-08 17:11:19 +00:00
|
|
|
case AbortUpgrade:
|
|
|
|
return m.handleAbortUpgrade, 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
|
2022-03-16 16:33:05 +00:00
|
|
|
case Available:
|
|
|
|
return m.handleAvailableSector, processed, nil
|
2021-01-12 23:42:01 +00:00
|
|
|
case Terminating:
|
|
|
|
return m.handleTerminating, processed, nil
|
|
|
|
case TerminateWait:
|
|
|
|
return m.handleTerminateWait, processed, nil
|
|
|
|
case TerminateFinality:
|
|
|
|
return m.handleTerminateFinality, processed, nil
|
|
|
|
case TerminateFailed:
|
|
|
|
return m.handleTerminateFailed, 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-06-22 16:42:38 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-03-12 13:54:10 +00:00
|
|
|
func (m *Sealing) onUpdateSector(ctx context.Context, state *SectorInfo) error {
|
2021-03-12 13:56:46 +00:00
|
|
|
if m.getConfig == nil {
|
|
|
|
return nil // tests
|
|
|
|
}
|
|
|
|
|
2021-03-12 13:54:10 +00:00
|
|
|
cfg, err := m.getConfig()
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting config: %w", err)
|
|
|
|
}
|
|
|
|
|
2021-10-19 16:52:54 +00:00
|
|
|
shouldUpdateInput := m.stats.updateSector(ctx, cfg, m.minerSectorID(state.SectorNumber), state.State)
|
2021-03-12 13:54:10 +00:00
|
|
|
|
|
|
|
// trigger more input processing when we've dipped below max sealing limits
|
|
|
|
if shouldUpdateInput {
|
2021-05-27 03:53:33 +00:00
|
|
|
sp, err := m.currentSealProof(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting seal proof type: %w", err)
|
|
|
|
}
|
|
|
|
|
2021-03-12 13:54:10 +00:00
|
|
|
go func() {
|
2021-03-12 14:01:00 +00:00
|
|
|
m.inputLk.Lock()
|
2021-03-12 13:54:10 +00:00
|
|
|
defer m.inputLk.Unlock()
|
|
|
|
|
|
|
|
if err := m.updateInput(ctx, sp); err != nil {
|
|
|
|
log.Errorf("%+v", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
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
|
2021-06-11 09:41:28 +00:00
|
|
|
case SectorProofReady: // early finalize
|
|
|
|
e.apply(state)
|
|
|
|
state.State = CommitFinalize
|
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
|
2022-09-09 10:54:48 +00:00
|
|
|
case SectorRemoteCommit1Failed, SectorRemoteCommit2Failed:
|
|
|
|
state.State = RemoteCommitFailed
|
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 {
|
2021-06-15 19:04:11 +00:00
|
|
|
defer m.startupWait.Done()
|
|
|
|
|
2020-01-15 20:49:11 +00:00
|
|
|
trackedSectors, err := m.ListSectors()
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("loading sector list: %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
2021-06-15 19:04:11 +00:00
|
|
|
m.startupWait.Wait()
|
2020-01-15 20:49:11 +00:00
|
|
|
return m.sectors.Send(id, SectorForceState{state})
|
|
|
|
}
|
2020-01-16 01:25:49 +00:00
|
|
|
|
2022-03-28 11:07:12 +00:00
|
|
|
// as sector has been removed, it's no needs to care about later events,
|
|
|
|
// just returns length of events as `processed` is ok.
|
|
|
|
func finalRemoved(events []statemachine.Event, state *SectorInfo) (uint64, error) {
|
|
|
|
return uint64(len(events)), nil
|
|
|
|
}
|
|
|
|
|
2020-08-27 10:39:20 +00:00
|
|
|
func final(events []statemachine.Event, state *SectorInfo) (uint64, error) {
|
2020-11-12 18:37:54 +00:00
|
|
|
if len(events) > 0 {
|
|
|
|
if gm, ok := events[0].User.(globalMutator); ok {
|
|
|
|
gm.applyGlobal(state)
|
|
|
|
return 1, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-27 10:39:20 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-01-18 20:59:34 +00:00
|
|
|
func on(mut mutator, next SectorState) func() (mutator, func(*SectorInfo) (bool, error)) {
|
|
|
|
return func() (mutator, func(*SectorInfo) (bool, error)) {
|
|
|
|
return mut, func(state *SectorInfo) (bool, error) {
|
2020-08-27 19:04:43 +00:00
|
|
|
state.State = next
|
2021-01-18 20:59:34 +00:00
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-09 12:38:23 +00:00
|
|
|
func onWithCB(mut mutator, next SectorState, cb func(info *SectorInfo)) func() (mutator, func(*SectorInfo) (bool, error)) {
|
|
|
|
return func() (mutator, func(*SectorInfo) (bool, error)) {
|
|
|
|
return mut, func(state *SectorInfo) (bool, error) {
|
|
|
|
cb(state)
|
|
|
|
state.State = next
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-18 20:59:34 +00:00
|
|
|
// like `on`, but doesn't change state
|
|
|
|
func apply(mut mutator) func() (mutator, func(*SectorInfo) (bool, error)) {
|
|
|
|
return func() (mutator, func(*SectorInfo) (bool, error)) {
|
|
|
|
return mut, func(state *SectorInfo) (bool, error) {
|
|
|
|
return true, nil
|
2020-08-27 19:04:43 +00:00
|
|
|
}
|
2020-01-16 01:25:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-18 20:59:34 +00:00
|
|
|
func onReturning(mut mutator) func() (mutator, func(*SectorInfo) (bool, error)) {
|
|
|
|
return func() (mutator, func(*SectorInfo) (bool, error)) {
|
|
|
|
return mut, func(state *SectorInfo) (bool, error) {
|
2020-08-27 19:04:43 +00:00
|
|
|
if state.Return == "" {
|
2021-01-18 20:59:34 +00:00
|
|
|
return false, xerrors.Errorf("return state not set")
|
2020-01-16 02:53:59 +00:00
|
|
|
}
|
2020-08-27 19:04:43 +00:00
|
|
|
|
|
|
|
state.State = SectorState(state.Return)
|
|
|
|
state.Return = ""
|
2021-01-18 20:59:34 +00:00
|
|
|
return false, nil
|
2020-01-16 01:25:49 +00:00
|
|
|
}
|
2020-08-27 19:04:43 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-16 01:25:49 +00:00
|
|
|
|
2021-01-18 20:59:34 +00:00
|
|
|
func planOne(ts ...func() (mut mutator, next func(*SectorInfo) (more bool, err 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) {
|
2021-04-14 18:26:07 +00:00
|
|
|
eloop:
|
2021-01-18 20:59:34 +00:00
|
|
|
for i, event := range events {
|
|
|
|
if gm, ok := event.User.(globalMutator); ok {
|
|
|
|
gm.applyGlobal(state)
|
|
|
|
return uint64(i + 1), nil
|
|
|
|
}
|
2020-01-22 18:30:56 +00:00
|
|
|
|
2021-01-18 20:59:34 +00:00
|
|
|
for _, t := range ts {
|
|
|
|
mut, next := t()
|
2020-01-16 01:25:49 +00:00
|
|
|
|
2021-01-18 20:59:34 +00:00
|
|
|
if reflect.TypeOf(event.User) != reflect.TypeOf(mut) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if err, iserr := event.User.(error); iserr {
|
|
|
|
log.Warnf("sector %d got error event %T: %+v", state.SectorNumber, event.User, err)
|
|
|
|
}
|
2020-01-16 01:25:49 +00:00
|
|
|
|
2021-01-18 20:59:34 +00:00
|
|
|
event.User.(mutator).apply(state)
|
|
|
|
more, err := next(state)
|
|
|
|
if err != nil || !more {
|
|
|
|
return uint64(i + 1), err
|
|
|
|
}
|
2021-04-14 18:26:07 +00:00
|
|
|
|
|
|
|
continue eloop
|
2020-01-21 16:05:10 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 20:59:34 +00:00
|
|
|
_, ok := event.User.(Ignorable)
|
|
|
|
if ok {
|
|
|
|
continue
|
|
|
|
}
|
2020-01-16 01:25:49 +00:00
|
|
|
|
2021-01-18 20:59:34 +00:00
|
|
|
return uint64(i + 1), xerrors.Errorf("planner for state %s received unexpected event %T (%+v)", state.State, event.User, event)
|
2020-07-06 17:04:11 +00:00
|
|
|
}
|
|
|
|
|
2021-01-18 20:59:34 +00:00
|
|
|
return uint64(len(events)), nil
|
2020-01-16 01:25:49 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-08 17:11:19 +00:00
|
|
|
|
|
|
|
// planOne but ignores unhandled states without erroring, this prevents the need to handle all possible events creating
|
|
|
|
// error during forced override
|
|
|
|
func planOneOrIgnore(ts ...func() (mut mutator, next func(*SectorInfo) (more bool, err error))) func(events []statemachine.Event, state *SectorInfo) (uint64, error) {
|
|
|
|
f := planOne(ts...)
|
|
|
|
return func(events []statemachine.Event, state *SectorInfo) (uint64, error) {
|
|
|
|
cnt, err := f(events, state)
|
|
|
|
if err != nil {
|
|
|
|
log.Warnf("planOneOrIgnore: ignoring error from planOne: %s", err)
|
|
|
|
}
|
|
|
|
return cnt, nil
|
|
|
|
}
|
|
|
|
}
|
2022-09-09 12:38:23 +00:00
|
|
|
|
2022-09-19 10:16:11 +00:00
|
|
|
// maybeNotifyRemoteDone will send sealing-done notification to the RemoteSealingDone
|
|
|
|
// if the RemoteSealingDoneEndpoint is set. If RemoteSealingDoneEndpoint is not set,
|
|
|
|
// this is no-op
|
2022-09-09 12:38:23 +00:00
|
|
|
func maybeNotifyRemoteDone(success bool, state string) func(*SectorInfo) {
|
|
|
|
return func(sector *SectorInfo) {
|
|
|
|
if sector.RemoteSealingDoneEndpoint == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
reqData := api.RemoteSealingDoneParams{
|
|
|
|
Successful: success,
|
|
|
|
State: state,
|
|
|
|
CommitMessage: sector.CommitMessage,
|
|
|
|
}
|
|
|
|
reqBody, err := json.Marshal(&reqData)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("marshaling remote done notification request params: %s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
req, err := http.NewRequest("POST", sector.RemoteSealingDoneEndpoint, bytes.NewReader(reqBody))
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("creating new remote done notification request: %s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
req.Header.Set("Content-Type", "application/json")
|
|
|
|
resp, err := http.DefaultClient.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("sending remote done notification: %s", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-09-09 12:57:56 +00:00
|
|
|
defer resp.Body.Close() //nolint:errcheck
|
2022-09-09 12:38:23 +00:00
|
|
|
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
|
|
log.Errorf("remote done notification received non-200 http response %s", resp.Status)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|