From d112fd18b1e59459c596c5776283b467713974ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 4 Dec 2019 01:44:29 +0100 Subject: [PATCH] Persist sector sealing errors --- api/api_storage.go | 1 + chain/blocksync/cbor_gen.go | 2 +- chain/types/cbor_gen.go | 2 +- cmd/lotus-storage-miner/sectors.go | 3 +++ node/impl/storminer.go | 2 ++ storage/cbor_gen.go | 21 +++++++++++++++++++-- storage/sector_types.go | 3 +++ storage/sectors.go | 6 ++++++ 8 files changed, 36 insertions(+), 4 deletions(-) diff --git a/api/api_storage.go b/api/api_storage.go index 09abbbf7c..f878e5d82 100644 --- a/api/api_storage.go +++ b/api/api_storage.go @@ -82,6 +82,7 @@ type SectorInfo struct { Deals []uint64 Ticket sectorbuilder.SealTicket Seed sectorbuilder.SealSeed + LastErr string } type SealedRef struct { diff --git a/chain/blocksync/cbor_gen.go b/chain/blocksync/cbor_gen.go index 4af61a490..579b3f857 100644 --- a/chain/blocksync/cbor_gen.go +++ b/chain/blocksync/cbor_gen.go @@ -5,7 +5,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 d2b60f268..fc7a7888c 100644 --- a/chain/types/cbor_gen.go +++ b/chain/types/cbor_gen.go @@ -5,7 +5,7 @@ import ( "io" "math" - "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/sectors.go b/cmd/lotus-storage-miner/sectors.go index 23076b155..774b29bd3 100644 --- a/cmd/lotus-storage-miner/sectors.go +++ b/cmd/lotus-storage-miner/sectors.go @@ -70,6 +70,9 @@ var sectorsStatusCmd = &cli.Command{ fmt.Printf("SeedH:\t\t%d\n", status.Seed.BlockHeight) fmt.Printf("Proof:\t\t%x\n", status.Proof) fmt.Printf("Deals:\t\t%v\n", status.Deals) + if status.LastErr != "" { + fmt.Printf("Last Error:\t\t%s\n", status.LastErr) + } return nil }, } diff --git a/node/impl/storminer.go b/node/impl/storminer.go index 04f162c30..1eac4a551 100644 --- a/node/impl/storminer.go +++ b/node/impl/storminer.go @@ -60,6 +60,8 @@ func (sm *StorageMinerAPI) SectorsStatus(ctx context.Context, sid uint64) (api.S Deals: deals, Ticket: info.Ticket.SB(), Seed: info.Seed.SB(), + + LastErr: info.LastErr, }, nil } diff --git a/storage/cbor_gen.go b/storage/cbor_gen.go index 1bc604e4a..41de25822 100644 --- a/storage/cbor_gen.go +++ b/storage/cbor_gen.go @@ -239,7 +239,7 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { _, err := w.Write(cbg.CborNull) return err } - if _, err := w.Write([]byte{140}); err != nil { + if _, err := w.Write([]byte{141}); err != nil { return err } @@ -337,6 +337,13 @@ func (t *SectorInfo) MarshalCBOR(w io.Writer) error { } } + // t.t.LastErr (string) (string) + if _, err := w.Write(cbg.CborEncodeMajorType(cbg.MajTextString, uint64(len(t.LastErr)))); err != nil { + return err + } + if _, err := w.Write([]byte(t.LastErr)); err != nil { + return err + } return nil } @@ -351,7 +358,7 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { return fmt.Errorf("cbor input should be of type array") } - if extra != 12 { + if extra != 13 { return fmt.Errorf("cbor input had wrong number of fields") } @@ -552,5 +559,15 @@ func (t *SectorInfo) UnmarshalCBOR(r io.Reader) error { } } + // t.t.LastErr (string) (string) + + { + sval, err := cbg.ReadString(br) + if err != nil { + return err + } + + t.LastErr = string(sval) + } return nil } diff --git a/storage/sector_types.go b/storage/sector_types.go index 179a7bbc6..20dff0161 100644 --- a/storage/sector_types.go +++ b/storage/sector_types.go @@ -69,6 +69,9 @@ type SectorInfo struct { // Committing CommitMessage *cid.Cid + + // Debug + LastErr string } func (t *SectorInfo) upd() *sectorUpdate { diff --git a/storage/sectors.go b/storage/sectors.go index 8b50b1616..929708880 100644 --- a/storage/sectors.go +++ b/storage/sectors.go @@ -2,6 +2,7 @@ package storage import ( "context" + "fmt" "io" xerrors "golang.org/x/xerrors" @@ -154,6 +155,11 @@ func (m *Miner) onSectorUpdated(ctx context.Context, update sectorUpdate) { var sector SectorInfo err := m.sectors.Mutate(update.id, func(s *SectorInfo) error { s.State = update.newState + s.LastErr = "" + if update.err != nil { + s.LastErr = fmt.Sprintf("%+v", update.err) + } + if update.mut != nil { update.mut(s) }