diff --git a/cbor_gen.go b/cbor_gen.go index 42ad7c029..b69e95c68 100644 --- a/cbor_gen.go +++ b/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/fsm.go b/fsm.go index 0911bfba5..a2951d807 100644 --- a/fsm.go +++ b/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/states_failed.go b/states_failed.go index d5667f57e..da5227683 100644 --- a/states_failed.go +++ b/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():