From b190c4ccf02926f7d6722d6b5095877ae10a17a0 Mon Sep 17 00:00:00 2001 From: tom123222 <160735201+tom123222@users.noreply.github.com> Date: Thu, 7 Mar 2024 11:21:02 +0800 Subject: [PATCH] opt(cli): ouput deadline open time (#11678) * opt(cli): ouput deadline open time * chore: use a const for the format string --- cmd/lotus-miner/proving.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/cmd/lotus-miner/proving.go b/cmd/lotus-miner/proving.go index 2fc1427b520..575dded5a7c 100644 --- a/cmd/lotus-miner/proving.go +++ b/cmd/lotus-miner/proving.go @@ -19,6 +19,7 @@ import ( "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/dline" "github.com/filecoin-project/go-state-types/proof" "github.com/filecoin-project/lotus/blockstore" @@ -237,10 +238,15 @@ var provingDeadlinesCmd = &cli.Command{ return xerrors.Errorf("getting deadlines: %w", err) } + head, err := api.ChainHead(ctx) + if err != nil { + return err + } + fmt.Printf("Miner: %s\n", color.BlueString("%s", maddr)) tw := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0) - _, _ = fmt.Fprintln(tw, "deadline\tpartitions\tsectors (faults)\tproven partitions") + _, _ = fmt.Fprintln(tw, "deadline\topen\tpartitions\tsectors (faults)\tproven partitions") for dlIdx, deadline := range deadlines { partitions, err := api.StateMinerPartitions(ctx, maddr, uint64(dlIdx), types.EmptyTSK) @@ -291,13 +297,25 @@ var provingDeadlinesCmd = &cli.Command{ if di.Index == uint64(dlIdx) { cur += "\t(current)" } - _, _ = fmt.Fprintf(tw, "%d\t%d\t%d (%d)\t%d%s\n", dlIdx, partitionCount, sectors, faults, provenPartitions, cur) + + _, _ = fmt.Fprintf(tw, "%d\t%s\t%d\t%d (%d)\t%d%s\n", dlIdx, deadlineOpenTime(head, uint64(dlIdx), di), + partitionCount, sectors, faults, provenPartitions, cur) } return tw.Flush() }, } +func deadlineOpenTime(ts *types.TipSet, dlIdx uint64, di *dline.Info) string { + gapIdx := dlIdx - di.Index + gapHeight := uint64(di.WPoStProvingPeriod) / di.WPoStPeriodDeadlines * gapIdx + + openHeight := di.Open + abi.ChainEpoch(gapHeight) + genesisBlockTimestamp := ts.MinTimestamp() - uint64(ts.Height())*build.BlockDelaySecs + + return time.Unix(int64(genesisBlockTimestamp+build.BlockDelaySecs*uint64(openHeight)), 0).Format(time.TimeOnly) +} + var provingDeadlineInfoCmd = &cli.Command{ Name: "deadline", Usage: "View the current proving period deadline information by its index", @@ -353,12 +371,18 @@ var provingDeadlineInfoCmd = &cli.Command{ return xerrors.Errorf("getting partitions for deadline %d: %w", dlIdx, err) } + head, err := api.ChainHead(ctx) + if err != nil { + return err + } + provenPartitions, err := deadlines[dlIdx].PostSubmissions.Count() if err != nil { return err } fmt.Printf("Deadline Index: %d\n", dlIdx) + fmt.Printf("Deadline Open: %s\n", deadlineOpenTime(head, dlIdx, di)) fmt.Printf("Partitions: %d\n", len(partitions)) fmt.Printf("Proven Partitions: %d\n", provenPartitions) fmt.Printf("Current: %t\n\n", di.Index == dlIdx)