Change api.SectorState to a string
This commit is contained in:
parent
847bdb203a
commit
a1b35aa9d5
@ -15,79 +15,33 @@ import (
|
|||||||
"github.com/filecoin-project/sector-storage/stores"
|
"github.com/filecoin-project/sector-storage/stores"
|
||||||
)
|
)
|
||||||
|
|
||||||
// alias because cbor-gen doesn't like non-alias types
|
type SectorState string
|
||||||
type SectorState = uint64
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
UndefinedSectorState SectorState = iota
|
UndefinedSectorState SectorState = ""
|
||||||
|
|
||||||
// happy path
|
// happy path
|
||||||
Empty
|
Empty SectorState = "Empty"
|
||||||
Packing // sector not in sealStore, and not on chain
|
Packing SectorState = "Packing" // sector not in sealStore, and not on chain
|
||||||
|
Unsealed SectorState = "Unsealed" // sealing / queued
|
||||||
Unsealed // sealing / queued
|
PreCommitting SectorState = "PreCommitting" // on chain pre-commit
|
||||||
PreCommitting // on chain pre-commit
|
WaitSeed SectorState = "WaitSeed" // waiting for seed
|
||||||
WaitSeed // waiting for seed
|
Committing SectorState = "Committing"
|
||||||
Committing
|
CommitWait SectorState = "CommitWait" // waiting for message to land on chain
|
||||||
CommitWait // waiting for message to land on chain
|
FinalizeSector SectorState = "FinalizeSector"
|
||||||
FinalizeSector
|
Proving SectorState = "Proving"
|
||||||
Proving
|
|
||||||
_ // reserved
|
|
||||||
_
|
|
||||||
_
|
|
||||||
|
|
||||||
// recovery handling
|
|
||||||
// Reseal
|
|
||||||
_
|
|
||||||
_
|
|
||||||
_
|
|
||||||
_
|
|
||||||
_
|
|
||||||
_
|
|
||||||
_
|
|
||||||
|
|
||||||
// error modes
|
// error modes
|
||||||
FailedUnrecoverable
|
FailedUnrecoverable SectorState = "FailedUnrecoverable"
|
||||||
|
SealFailed SectorState = "SealFailed"
|
||||||
SealFailed
|
PreCommitFailed SectorState = "PreCommitFailed"
|
||||||
PreCommitFailed
|
SealCommitFailed SectorState = "SealCommitFailed"
|
||||||
SealCommitFailed
|
CommitFailed SectorState = "CommitFailed"
|
||||||
CommitFailed
|
PackingFailed SectorState = "PackingFailed"
|
||||||
PackingFailed
|
Faulty SectorState = "Faulty" // sector is corrupted or gone for some reason
|
||||||
_
|
FaultReported SectorState = "FaultReported" // sector has been declared as a fault on chain
|
||||||
_
|
FaultedFinal SectorState = "FaultedFinal" // fault declared on chain
|
||||||
_
|
|
||||||
|
|
||||||
Faulty // sector is corrupted or gone for some reason
|
|
||||||
FaultReported // sector has been declared as a fault on chain
|
|
||||||
FaultedFinal // fault declared on chain
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var SectorStates = []string{
|
|
||||||
UndefinedSectorState: "UndefinedSectorState",
|
|
||||||
Empty: "Empty",
|
|
||||||
Packing: "Packing",
|
|
||||||
Unsealed: "Unsealed",
|
|
||||||
PreCommitting: "PreCommitting",
|
|
||||||
WaitSeed: "WaitSeed",
|
|
||||||
Committing: "Committing",
|
|
||||||
CommitWait: "CommitWait",
|
|
||||||
FinalizeSector: "FinalizeSector",
|
|
||||||
Proving: "Proving",
|
|
||||||
|
|
||||||
SealFailed: "SealFailed",
|
|
||||||
PreCommitFailed: "PreCommitFailed",
|
|
||||||
SealCommitFailed: "SealCommitFailed",
|
|
||||||
CommitFailed: "CommitFailed",
|
|
||||||
PackingFailed: "PackingFailed",
|
|
||||||
|
|
||||||
FailedUnrecoverable: "FailedUnrecoverable",
|
|
||||||
|
|
||||||
Faulty: "Faulty",
|
|
||||||
FaultReported: "FaultReported",
|
|
||||||
FaultedFinal: "FaultedFinal",
|
|
||||||
}
|
|
||||||
|
|
||||||
// StorageMiner is a low-level interface to the Filecoin network storage miner node
|
// StorageMiner is a low-level interface to the Filecoin network storage miner node
|
||||||
type StorageMiner interface {
|
type StorageMiner interface {
|
||||||
Common
|
Common
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/ipfs/go-cid"
|
cid "github.com/ipfs/go-cid"
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
xerrors "golang.org/x/xerrors"
|
xerrors "golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||||
"github.com/filecoin-project/specs-actors/actors/crypto"
|
"github.com/filecoin-project/specs-actors/actors/crypto"
|
||||||
"github.com/filecoin-project/specs-actors/actors/runtime/exitcode"
|
"github.com/filecoin-project/specs-actors/actors/runtime/exitcode"
|
||||||
"github.com/ipfs/go-cid"
|
cid "github.com/ipfs/go-cid"
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
xerrors "golang.org/x/xerrors"
|
xerrors "golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
|
@ -127,13 +127,13 @@ var infoCmd = &cli.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func sectorsInfo(ctx context.Context, napi api.StorageMiner) (map[string]int, error) {
|
func sectorsInfo(ctx context.Context, napi api.StorageMiner) (map[api.SectorState]int, error) {
|
||||||
sectors, err := napi.SectorsList(ctx)
|
sectors, err := napi.SectorsList(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
out := map[string]int{
|
out := map[api.SectorState]int{
|
||||||
"Total": len(sectors),
|
"Total": len(sectors),
|
||||||
}
|
}
|
||||||
for _, s := range sectors {
|
for _, s := range sectors {
|
||||||
@ -142,7 +142,7 @@ func sectorsInfo(ctx context.Context, napi api.StorageMiner) (map[string]int, er
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
out[api.SectorStates[st.State]]++
|
out[st.State]++
|
||||||
}
|
}
|
||||||
|
|
||||||
return out, nil
|
return out, nil
|
||||||
|
@ -77,7 +77,7 @@ var sectorsStatusCmd = &cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("SectorID:\t%d\n", status.SectorID)
|
fmt.Printf("SectorID:\t%d\n", status.SectorID)
|
||||||
fmt.Printf("Status:\t%s\n", api.SectorStates[status.State])
|
fmt.Printf("Status:\t%s\n", status.State)
|
||||||
fmt.Printf("CommD:\t\t%x\n", status.CommD)
|
fmt.Printf("CommD:\t\t%x\n", status.CommD)
|
||||||
fmt.Printf("CommR:\t\t%x\n", status.CommR)
|
fmt.Printf("CommR:\t\t%x\n", status.CommR)
|
||||||
fmt.Printf("Ticket:\t\t%x\n", status.Ticket.Value)
|
fmt.Printf("Ticket:\t\t%x\n", status.Ticket.Value)
|
||||||
@ -169,7 +169,7 @@ var sectorsListCmd = &cli.Command{
|
|||||||
|
|
||||||
fmt.Fprintf(w, "%d: %s\tsSet: %s\tpSet: %s\ttktH: %d\tseedH: %d\tdeals: %v\n",
|
fmt.Fprintf(w, "%d: %s\tsSet: %s\tpSet: %s\ttktH: %d\tseedH: %d\tdeals: %v\n",
|
||||||
s,
|
s,
|
||||||
api.SectorStates[st.State],
|
st.State,
|
||||||
yesno(inSSet),
|
yesno(inSSet),
|
||||||
yesno(inPSet),
|
yesno(inPSet),
|
||||||
st.Ticket.Epoch,
|
st.Ticket.Epoch,
|
||||||
@ -236,14 +236,7 @@ var sectorsUpdateCmd = &cli.Command{
|
|||||||
return xerrors.Errorf("could not parse sector ID: %w", err)
|
return xerrors.Errorf("could not parse sector ID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var st api.SectorState
|
return nodeApi.SectorsUpdate(ctx, abi.SectorNumber(id), api.SectorState(cctx.Args().Get(1)))
|
||||||
for i, s := range api.SectorStates {
|
|
||||||
if cctx.Args().Get(1) == s {
|
|
||||||
st = api.SectorState(i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nodeApi.SectorsUpdate(ctx, abi.SectorNumber(id), st)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||||
"github.com/ipfs/go-cid"
|
cid "github.com/ipfs/go-cid"
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
xerrors "golang.org/x/xerrors"
|
xerrors "golang.org/x/xerrors"
|
||||||
)
|
)
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
xerrors "golang.org/x/xerrors"
|
xerrors "golang.org/x/xerrors"
|
||||||
@ -181,7 +182,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// t.State (uint64) (uint64)
|
// t.State (api.SectorState) (string)
|
||||||
if len("State") > cbg.MaxLength {
|
if len("State") > cbg.MaxLength {
|
||||||
return xerrors.Errorf("Value in field \"State\" was too long")
|
return xerrors.Errorf("Value in field \"State\" was too long")
|
||||||
}
|
}
|
||||||
@ -193,7 +194,14 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajUnsignedInt, uint64(t.State))); err != nil {
|
if len(t.State) > cbg.MaxLength {
|
||||||
|
return xerrors.Errorf("Value in field t.State was too long")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.State)))); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := w.Write([]byte(t.State)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,20 +529,16 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch name {
|
switch name {
|
||||||
// t.State (uint64) (uint64)
|
// t.State (api.SectorState) (string)
|
||||||
case "State":
|
case "State":
|
||||||
|
|
||||||
{
|
{
|
||||||
|
sval, err := cbg.ReadString(br)
|
||||||
maj, extra, err = cbg.CborReadHeader(br)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if maj != cbg.MajUnsignedInt {
|
|
||||||
return fmt.Errorf("wrong type for uint64 field")
|
|
||||||
}
|
|
||||||
t.State = uint64(extra)
|
|
||||||
|
|
||||||
|
t.State = api.SectorState(sval)
|
||||||
}
|
}
|
||||||
// t.SectorID (abi.SectorNumber) (uint64)
|
// t.SectorID (abi.SectorNumber) (uint64)
|
||||||
case "SectorID":
|
case "SectorID":
|
||||||
|
@ -32,7 +32,7 @@ func (m *Sealing) Plan(events []statemachine.Event, user interface{}) (interface
|
|||||||
}, uint64(len(events)), nil // TODO: This processed event count is not very correct
|
}, uint64(len(events)), nil // TODO: This processed event count is not very correct
|
||||||
}
|
}
|
||||||
|
|
||||||
var fsmPlanners = []func(events []statemachine.Event, state *SectorInfo) error{
|
var fsmPlanners = map[api.SectorState]func(events []statemachine.Event, state *SectorInfo) error{
|
||||||
api.UndefinedSectorState: planOne(on(SectorStart{}, api.Packing)),
|
api.UndefinedSectorState: planOne(on(SectorStart{}, api.Packing)),
|
||||||
api.Packing: planOne(on(SectorPacked{}, api.Unsealed)),
|
api.Packing: planOne(on(SectorPacked{}, api.Unsealed)),
|
||||||
api.Unsealed: planOne(
|
api.Unsealed: planOne(
|
||||||
@ -105,11 +105,11 @@ func (m *Sealing) plan(events []statemachine.Event, state *SectorInfo) (func(sta
|
|||||||
|
|
||||||
p := fsmPlanners[state.State]
|
p := fsmPlanners[state.State]
|
||||||
if p == nil {
|
if p == nil {
|
||||||
return nil, xerrors.Errorf("planner for state %s not found", api.SectorStates[state.State])
|
return nil, xerrors.Errorf("planner for state %s not found", state.State)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := p(events, state); err != nil {
|
if err := p(events, state); err != nil {
|
||||||
return nil, xerrors.Errorf("running planner for state %s failed: %w", api.SectorStates[state.State], err)
|
return nil, xerrors.Errorf("running planner for state %s failed: %w", state.State, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
/////
|
/////
|
||||||
@ -251,7 +251,7 @@ func (m *Sealing) ForceSectorState(ctx context.Context, id abi.SectorNumber, sta
|
|||||||
}
|
}
|
||||||
|
|
||||||
func final(events []statemachine.Event, state *SectorInfo) error {
|
func final(events []statemachine.Event, state *SectorInfo) error {
|
||||||
return xerrors.Errorf("didn't expect any events in state %s, got %+v", api.SectorStates[state.State], events)
|
return xerrors.Errorf("didn't expect any events in state %s, got %+v", state.State, events)
|
||||||
}
|
}
|
||||||
|
|
||||||
func on(mut mutator, next api.SectorState) func() (mutator, api.SectorState) {
|
func on(mut mutator, next api.SectorState) func() (mutator, api.SectorState) {
|
||||||
@ -269,7 +269,7 @@ func planOne(ts ...func() (mut mutator, next api.SectorState)) func(events []sta
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return xerrors.Errorf("planner for state %s only has a plan for a single event only, got %+v", api.SectorStates[state.State], events)
|
return xerrors.Errorf("planner for state %s only has a plan for a single event only, got %+v", state.State, events)
|
||||||
}
|
}
|
||||||
|
|
||||||
if gm, ok := events[0].User.(globalMutator); ok {
|
if gm, ok := events[0].User.(globalMutator); ok {
|
||||||
@ -293,6 +293,6 @@ func planOne(ts ...func() (mut mutator, next api.SectorState)) func(events []sta
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return xerrors.Errorf("planner for state %s received unexpected event %T (%+v)", api.SectorStates[state.State], events[0].User, events[0])
|
return xerrors.Errorf("planner for state %s received unexpected event %T (%+v)", state.State, events[0].User, events[0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import (
|
|||||||
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/api"
|
|
||||||
"github.com/filecoin-project/lotus/api/apibstore"
|
"github.com/filecoin-project/lotus/api/apibstore"
|
||||||
"github.com/filecoin-project/lotus/chain/store"
|
"github.com/filecoin-project/lotus/chain/store"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
@ -20,7 +19,7 @@ const minRetryTime = 1 * time.Minute
|
|||||||
func failedCooldown(ctx statemachine.Context, sector SectorInfo) error {
|
func failedCooldown(ctx statemachine.Context, sector SectorInfo) error {
|
||||||
retryStart := time.Unix(int64(sector.Log[len(sector.Log)-1].Timestamp), 0).Add(minRetryTime)
|
retryStart := time.Unix(int64(sector.Log[len(sector.Log)-1].Timestamp), 0).Add(minRetryTime)
|
||||||
if len(sector.Log) > 0 && !time.Now().After(retryStart) {
|
if len(sector.Log) > 0 && !time.Now().After(retryStart) {
|
||||||
log.Infof("%s(%d), waiting %s before retrying", api.SectorStates[sector.State], sector.SectorID, time.Until(retryStart))
|
log.Infof("%s(%d), waiting %s before retrying", sector.State, sector.SectorID, time.Until(retryStart))
|
||||||
select {
|
select {
|
||||||
case <-time.After(time.Until(retryStart)):
|
case <-time.After(time.Until(retryStart)):
|
||||||
case <-ctx.Context().Done():
|
case <-ctx.Context().Done():
|
||||||
|
Loading…
Reference in New Issue
Block a user