From c3a5da85869241d39a39a11a995b52600fcceca4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 23 Jan 2020 15:18:05 +0100 Subject: [PATCH] storageminer: log flag for sector status --- api/api_storage.go | 11 +++++++++++ cmd/lotus-storage-miner/sectors.go | 18 ++++++++++++++++++ go.mod | 2 +- go.sum | 4 ++-- node/impl/storminer.go | 11 +++++++++++ storage/sealing/checks.go | 4 ++-- storage/sealing/types.go | 2 +- 7 files changed, 46 insertions(+), 6 deletions(-) diff --git a/api/api_storage.go b/api/api_storage.go index 9519e5673..f52f9f3a4 100644 --- a/api/api_storage.go +++ b/api/api_storage.go @@ -107,6 +107,15 @@ type StorageMiner interface { WorkerDone(ctx context.Context, task uint64, res sectorbuilder.SealRes) error } +type SectorLog struct { + Kind string + Timestamp uint64 + + Trace string + + Message string +} + type SectorInfo struct { SectorID uint64 State SectorState @@ -119,6 +128,8 @@ type SectorInfo struct { Retries uint64 LastErr string + + Log []SectorLog } type SealedRef struct { diff --git a/cmd/lotus-storage-miner/sectors.go b/cmd/lotus-storage-miner/sectors.go index bdc73f236..9020c9316 100644 --- a/cmd/lotus-storage-miner/sectors.go +++ b/cmd/lotus-storage-miner/sectors.go @@ -4,6 +4,7 @@ import ( "fmt" "sort" "strconv" + "time" "golang.org/x/xerrors" "gopkg.in/urfave/cli.v2" @@ -41,6 +42,12 @@ var sectorsCmd = &cli.Command{ var sectorsStatusCmd = &cli.Command{ Name: "status", Usage: "Get the seal status of a sector by its ID", + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "log", + Usage: "display event log", + }, + }, Action: func(cctx *cli.Context) error { nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) if err != nil { @@ -77,6 +84,17 @@ var sectorsStatusCmd = &cli.Command{ if status.LastErr != "" { fmt.Printf("Last Error:\t\t%s\n", status.LastErr) } + + if cctx.Bool("log") { + fmt.Printf("--------\nEvent Log:\n") + + for i, l := range status.Log { + fmt.Printf("%d.\t%s:\t[%s]\t%s\n", i, time.Unix(int64(l.Timestamp), 0), l.Kind, l.Message) + if l.Trace != "" { + fmt.Printf("\t%s\n", l.Trace) + } + } + } return nil }, } diff --git a/go.mod b/go.mod index 81e54f3d5..e8570aace 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/filecoin-project/go-data-transfer v0.0.0-20191219005021-4accf56bd2ce github.com/filecoin-project/go-fil-markets v0.0.0-20200114015428-74d100f305f8 github.com/filecoin-project/go-paramfetch v0.0.1 - github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200122195713-697609991669 + github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200123134702-99304d8411ed github.com/filecoin-project/go-statestore v0.1.0 github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1 github.com/go-ole/go-ole v1.2.4 // indirect diff --git a/go.sum b/go.sum index 9f88c7178..1dc1f5668 100644 --- a/go.sum +++ b/go.sum @@ -117,8 +117,8 @@ github.com/filecoin-project/go-paramfetch v0.0.0-20200102181131-b20d579f2878/go. github.com/filecoin-project/go-paramfetch v0.0.1 h1:gV7bs5YaqlgpGFMiLxInGK2L1FyCXUE0rimz4L7ghoE= github.com/filecoin-project/go-paramfetch v0.0.1/go.mod h1:fZzmf4tftbwf9S37XRifoJlz7nCjRdIrMGLR07dKLCc= github.com/filecoin-project/go-sectorbuilder v0.0.1/go.mod h1:3OZ4E3B2OuwhJjtxR4r7hPU9bCfB+A+hm4alLEsaeDc= -github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200122195713-697609991669 h1:SpwORqUXMVB2Ejr8c4zIGiihxGM5Tu15skOWa5pvRr8= -github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200122195713-697609991669/go.mod h1:ahsryULdwYoZ94K09HcfqX3QBwevWVldENSV/EdCbNg= +github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200123134702-99304d8411ed h1:XBuYbMEzBePbN8ks0P8BDOOo0KJxcseFP8ggDjsb+sk= +github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200123134702-99304d8411ed/go.mod h1:ahsryULdwYoZ94K09HcfqX3QBwevWVldENSV/EdCbNg= github.com/filecoin-project/go-statestore v0.1.0 h1:t56reH59843TwXHkMcwyuayStBIiWBRilQjQ+5IiwdQ= github.com/filecoin-project/go-statestore v0.1.0/go.mod h1:LFc9hD+fRxPqiHiaqUEZOinUJB4WARkRfNl10O7kTnI= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= diff --git a/node/impl/storminer.go b/node/impl/storminer.go index 0e2093efe..b600dfb7f 100644 --- a/node/impl/storminer.go +++ b/node/impl/storminer.go @@ -160,6 +160,16 @@ func (sm *StorageMinerAPI) SectorsStatus(ctx context.Context, sid uint64) (api.S deals[i] = piece.DealID } + log := make([]api.SectorLog, len(info.Log)) + for i, l := range info.Log { + log[i] = api.SectorLog{ + Kind: l.Kind, + Timestamp: l.Timestamp, + Trace: l.Trace, + Message: l.Message, + } + } + return api.SectorInfo{ SectorID: sid, State: info.State, @@ -172,6 +182,7 @@ func (sm *StorageMinerAPI) SectorsStatus(ctx context.Context, sid uint64) (api.S Retries: info.Nonce, LastErr: info.LastErr, + Log: log, }, nil } diff --git a/storage/sealing/checks.go b/storage/sealing/checks.go index bc95ba0fd..3ec86b9f3 100644 --- a/storage/sealing/checks.go +++ b/storage/sealing/checks.go @@ -87,8 +87,8 @@ func checkSeal(ctx context.Context, maddr address.Address, si SectorInfo, api se return ErrBadCommD(xerrors.Errorf("on chain CommD differs from sector: %x != %x", r.Return, si.CommD)) } - if int64(head.Height()) - int64(si.Ticket.BlockHeight + build.SealRandomnessLookback) > build.SealRandomnessLookbackLimit { - return ErrExpiredTicket(xerrors.Errorf("ticket expired: seal height: %d, head: %d", si.Ticket.BlockHeight + build.SealRandomnessLookback, head.Height())) + if int64(head.Height())-int64(si.Ticket.BlockHeight+build.SealRandomnessLookback) > build.SealRandomnessLookbackLimit { + return ErrExpiredTicket(xerrors.Errorf("ticket expired: seal height: %d, head: %d", si.Ticket.BlockHeight+build.SealRandomnessLookback, head.Height())) } return nil diff --git a/storage/sealing/types.go b/storage/sealing/types.go index 952c5ec22..f0fbe09a4 100644 --- a/storage/sealing/types.go +++ b/storage/sealing/types.go @@ -52,7 +52,7 @@ type Log struct { Message string // additional data (Event info) - Kind string + Kind string } type SectorInfo struct {