From ee34cf612f979f418f022d9c0484dbb45a6da457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 22 Jan 2020 21:29:19 +0100 Subject: [PATCH] sealing: Wire up sector event log --- cbor_gen.go | 43 +------------------------------------------ fsm.go | 16 ++++++++++++++++ types.go | 1 - 3 files changed, 17 insertions(+), 43 deletions(-) diff --git a/cbor_gen.go b/cbor_gen.go index e13bcf43a..f83d35990 100644 --- a/cbor_gen.go +++ b/cbor_gen.go @@ -980,7 +980,7 @@ func (t *Log) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{165}); err != nil { + if _, err := w.Write([]byte{164}); err != nil { return err } @@ -1068,29 +1068,6 @@ func (t *Log) MarshalCBOR(w io.Writer) error { if _, err := w.Write([]byte(t.Kind)); err != nil { return err } - - // t.Params ([]uint8) (slice) - if len("Params") > cbg.MaxLength { - return xerrors.Errorf("Value in field \"Params\" was too long") - } - - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len("Params")))); err != nil { - return err - } - if _, err := w.Write([]byte("Params")); err != nil { - return err - } - - if len(t.Params) > cbg.ByteArrayMaxLen { - return xerrors.Errorf("Byte array in field t.Params was too long") - } - - if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajByteString, uint64(len(t.Params)))); err != nil { - return err - } - if _, err := w.Write(t.Params); err != nil { - return err - } return nil } @@ -1168,24 +1145,6 @@ func (t *Log) UnmarshalCBOR(r io.Reader) error { t.Kind = string(sval) } - // t.Params ([]uint8) (slice) - case "Params": - - maj, extra, err = cbg.CborReadHeader(br) - if err != nil { - return err - } - - if extra > cbg.ByteArrayMaxLen { - return fmt.Errorf("t.Params: byte array too large (%d)", extra) - } - if maj != cbg.MajByteString { - return fmt.Errorf("expected byte array") - } - t.Params = make([]byte, extra) - if _, err := io.ReadFull(br, t.Params); err != nil { - return err - } default: return fmt.Errorf("unknown struct field %d: '%s'", i, name) diff --git a/fsm.go b/fsm.go index ba2702696..fced052aa 100644 --- a/fsm.go +++ b/fsm.go @@ -2,7 +2,9 @@ package sealing import ( "context" + "fmt" "reflect" + "time" "golang.org/x/xerrors" @@ -66,6 +68,20 @@ func (m *Sealing) plan(events []statemachine.Event, state *SectorInfo) (func(sta ///// // First process all events + for _, event := range events { + l := Log{ + Timestamp: uint64(time.Now().Unix()), + Message: fmt.Sprintf("%+v", event), + Kind: fmt.Sprintf("event;%T", event.User), + } + + if err, iserr := event.User.(xerrors.Formatter); iserr { + l.Trace = fmt.Sprintf("%+v", err) + } + + state.Log = append(state.Log, l) + } + p := fsmPlanners[state.State] if p == nil { return nil, xerrors.Errorf("planner for state %d not found", state.State) diff --git a/types.go b/types.go index ae8d7ac23..952c5ec22 100644 --- a/types.go +++ b/types.go @@ -53,7 +53,6 @@ type Log struct { // additional data (Event info) Kind string - Params []byte } type SectorInfo struct {