diff --git a/api/api_storage.go b/api/api_storage.go index 4ceb07b76..6c7c27c19 100644 --- a/api/api_storage.go +++ b/api/api_storage.go @@ -15,79 +15,33 @@ import ( "github.com/filecoin-project/sector-storage/stores" ) -// alias because cbor-gen doesn't like non-alias types -type SectorState = uint64 +type SectorState string const ( - UndefinedSectorState SectorState = iota + UndefinedSectorState SectorState = "" // happy path - Empty - Packing // sector not in sealStore, and not on chain - - Unsealed // sealing / queued - PreCommitting // on chain pre-commit - WaitSeed // waiting for seed - Committing - CommitWait // waiting for message to land on chain - FinalizeSector - Proving - _ // reserved - _ - _ - - // recovery handling - // Reseal - _ - _ - _ - _ - _ - _ - _ - + Empty SectorState = "Empty" + Packing SectorState = "Packing" // sector not in sealStore, and not on chain + Unsealed SectorState = "Unsealed" // sealing / queued + PreCommitting SectorState = "PreCommitting" // on chain pre-commit + WaitSeed SectorState = "WaitSeed" // waiting for seed + Committing SectorState = "Committing" + CommitWait SectorState = "CommitWait" // waiting for message to land on chain + FinalizeSector SectorState = "FinalizeSector" + Proving SectorState = "Proving" // error modes - FailedUnrecoverable - - SealFailed - PreCommitFailed - SealCommitFailed - CommitFailed - PackingFailed - _ - _ - _ - - Faulty // sector is corrupted or gone for some reason - FaultReported // sector has been declared as a fault on chain - FaultedFinal // fault declared on chain + FailedUnrecoverable SectorState = "FailedUnrecoverable" + SealFailed SectorState = "SealFailed" + PreCommitFailed SectorState = "PreCommitFailed" + SealCommitFailed SectorState = "SealCommitFailed" + CommitFailed SectorState = "CommitFailed" + PackingFailed SectorState = "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 ) -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 type StorageMiner interface { Common diff --git a/chain/blocksync/cbor_gen.go b/chain/blocksync/cbor_gen.go index 60cb1c0b3..6668eb3a6 100644 --- a/chain/blocksync/cbor_gen.go +++ b/chain/blocksync/cbor_gen.go @@ -7,7 +7,7 @@ import ( "io" "github.com/filecoin-project/lotus/chain/types" - "github.com/ipfs/go-cid" + cid "github.com/ipfs/go-cid" cbg "github.com/whyrusleeping/cbor-gen" xerrors "golang.org/x/xerrors" ) diff --git a/chain/types/cbor_gen.go b/chain/types/cbor_gen.go index 6a7a3b12e..e1c3e4474 100644 --- a/chain/types/cbor_gen.go +++ b/chain/types/cbor_gen.go @@ -9,7 +9,7 @@ import ( "github.com/filecoin-project/specs-actors/actors/abi" "github.com/filecoin-project/specs-actors/actors/crypto" "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" xerrors "golang.org/x/xerrors" ) diff --git a/cmd/lotus-storage-miner/info.go b/cmd/lotus-storage-miner/info.go index e00e14cfe..fe8d1a71f 100644 --- a/cmd/lotus-storage-miner/info.go +++ b/cmd/lotus-storage-miner/info.go @@ -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) if err != nil { return nil, err } - out := map[string]int{ + out := map[api.SectorState]int{ "Total": len(sectors), } for _, s := range sectors { @@ -142,7 +142,7 @@ func sectorsInfo(ctx context.Context, napi api.StorageMiner) (map[string]int, er return nil, err } - out[api.SectorStates[st.State]]++ + out[st.State]++ } return out, nil diff --git a/cmd/lotus-storage-miner/sectors.go b/cmd/lotus-storage-miner/sectors.go index 75add6ea7..288397767 100644 --- a/cmd/lotus-storage-miner/sectors.go +++ b/cmd/lotus-storage-miner/sectors.go @@ -77,7 +77,7 @@ var sectorsStatusCmd = &cli.Command{ } 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("CommR:\t\t%x\n", status.CommR) 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", s, - api.SectorStates[st.State], + st.State, yesno(inSSet), yesno(inPSet), st.Ticket.Epoch, @@ -236,14 +236,7 @@ var sectorsUpdateCmd = &cli.Command{ return xerrors.Errorf("could not parse sector ID: %w", err) } - var st api.SectorState - for i, s := range api.SectorStates { - if cctx.Args().Get(1) == s { - st = api.SectorState(i) - } - } - - return nodeApi.SectorsUpdate(ctx, abi.SectorNumber(id), st) + return nodeApi.SectorsUpdate(ctx, abi.SectorNumber(id), api.SectorState(cctx.Args().Get(1))) }, } diff --git a/node/hello/cbor_gen.go b/node/hello/cbor_gen.go index 5185496b9..f65beaeff 100644 --- a/node/hello/cbor_gen.go +++ b/node/hello/cbor_gen.go @@ -7,7 +7,7 @@ import ( "io" "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" xerrors "golang.org/x/xerrors" ) diff --git a/storage/sealing/cbor_gen.go b/storage/sealing/cbor_gen.go index 42ad7c029..b69e95c68 100644 --- a/storage/sealing/cbor_gen.go +++ b/storage/sealing/cbor_gen.go @@ -6,6 +6,7 @@ import ( "fmt" "io" + "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/specs-actors/actors/abi" cbg "github.com/whyrusleeping/cbor-gen" xerrors "golang.org/x/xerrors" @@ -181,7 +182,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { return err } - // t.State (uint64) (uint64) + // t.State (api.SectorState) (string) if len("State") > cbg.MaxLength { return xerrors.Errorf("Value in field \"State\" was too long") } @@ -193,7 +194,14 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { 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 } @@ -521,20 +529,16 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { } switch name { - // t.State (uint64) (uint64) + // t.State (api.SectorState) (string) case "State": { - - maj, extra, err = cbg.CborReadHeader(br) + sval, err := cbg.ReadString(br) if err != nil { 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) case "SectorID": diff --git a/storage/sealing/fsm.go b/storage/sealing/fsm.go index 0911bfba5..a2951d807 100644 --- a/storage/sealing/fsm.go +++ b/storage/sealing/fsm.go @@ -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 } -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.Packing: planOne(on(SectorPacked{}, api.Unsealed)), api.Unsealed: planOne( @@ -105,11 +105,11 @@ func (m *Sealing) plan(events []statemachine.Event, state *SectorInfo) (func(sta p := fsmPlanners[state.State] 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 { - 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 { - 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) { @@ -269,7 +269,7 @@ func planOne(ts ...func() (mut mutator, next api.SectorState)) func(events []sta 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 { @@ -293,6 +293,6 @@ func planOne(ts ...func() (mut mutator, next api.SectorState)) func(events []sta 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]) } } diff --git a/storage/sealing/states_failed.go b/storage/sealing/states_failed.go index d5667f57e..da5227683 100644 --- a/storage/sealing/states_failed.go +++ b/storage/sealing/states_failed.go @@ -9,7 +9,6 @@ import ( "github.com/filecoin-project/specs-actors/actors/util/adt" "golang.org/x/xerrors" - "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/api/apibstore" "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" @@ -20,7 +19,7 @@ const minRetryTime = 1 * time.Minute func failedCooldown(ctx statemachine.Context, sector SectorInfo) error { retryStart := time.Unix(int64(sector.Log[len(sector.Log)-1].Timestamp), 0).Add(minRetryTime) 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 { case <-time.After(time.Until(retryStart)): case <-ctx.Context().Done():