sealing: Wire up sector event log

This commit is contained in:
Łukasz Magiera 2020-01-22 21:29:19 +01:00
parent 7463ee72d0
commit ee34cf612f
3 changed files with 17 additions and 43 deletions

View File

@ -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)

16
fsm.go
View File

@ -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)

View File

@ -53,7 +53,6 @@ type Log struct {
// additional data (Event info)
Kind string
Params []byte
}
type SectorInfo struct {