From 2375df2b62d710dd427d89b5658c0cf185cc6be8 Mon Sep 17 00:00:00 2001 From: beck Date: Wed, 25 May 2022 11:11:23 +0800 Subject: [PATCH 1/3] Feat/add provingDeadlinesCmd live option --- cmd/lotus-miner/proving.go | 57 ++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/cmd/lotus-miner/proving.go b/cmd/lotus-miner/proving.go index faae5e955..8b3bde610 100644 --- a/cmd/lotus-miner/proving.go +++ b/cmd/lotus-miner/proving.go @@ -197,6 +197,14 @@ var provingInfoCmd = &cli.Command{ var provingDeadlinesCmd = &cli.Command{ Name: "deadlines", Usage: "View the current proving period deadlines information", + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "live", + Usage: "View live deadlines information", + Value: false, + Aliases: []string{"l"}, + }, + }, Action: func(cctx *cli.Context) error { api, acloser, err := lcli.GetFullNodeAPI(cctx) if err != nil { @@ -239,28 +247,53 @@ var provingDeadlinesCmd = &cli.Command{ sectors := uint64(0) faults := uint64(0) + var PartitionSum int + + if cctx.Bool("live") { + for _, partition := range partitions { + sc, err := partition.LiveSectors.Count() + if err != nil { + return err + } + + if sc > 0 { + PartitionSum++ + } + + sectors += sc + + fc, err := partition.FaultySectors.Count() + if err != nil { + return err + } + + faults += fc - for _, partition := range partitions { - sc, err := partition.AllSectors.Count() - if err != nil { - return err } + } else { + for _, partition := range partitions { + PartitionSum++ - sectors += sc + sc, err := partition.AllSectors.Count() + if err != nil { + return err + } - fc, err := partition.FaultySectors.Count() - if err != nil { - return err + sectors += sc + + fc, err := partition.FaultySectors.Count() + if err != nil { + return err + } + + faults += fc } - - faults += fc } - var cur string if di.Index == uint64(dlIdx) { cur += "\t(current)" } - _, _ = fmt.Fprintf(tw, "%d\t%d\t%d (%d)\t%d%s\n", dlIdx, len(partitions), sectors, faults, provenPartitions, cur) + _, _ = fmt.Fprintf(tw, "%d\t%d\t%d (%d)\t%d%s\n", dlIdx, PartitionSum, sectors, faults, provenPartitions, cur) } return tw.Flush() From 43ec14fa9c40d8b220e2272663572a86d7583286 Mon Sep 17 00:00:00 2001 From: beck Date: Wed, 25 May 2022 11:12:32 +0800 Subject: [PATCH 2/3] Feat/add provingDeadlineInfoCmd live option --- cmd/lotus-miner/proving.go | 83 ++++++++++++++++++++++++++++---------- 1 file changed, 61 insertions(+), 22 deletions(-) diff --git a/cmd/lotus-miner/proving.go b/cmd/lotus-miner/proving.go index 8b3bde610..51149baf6 100644 --- a/cmd/lotus-miner/proving.go +++ b/cmd/lotus-miner/proving.go @@ -304,6 +304,14 @@ var provingDeadlineInfoCmd = &cli.Command{ Name: "deadline", Usage: "View the current proving period deadline information by its index ", ArgsUsage: "", + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "live", + Usage: "View deadline live sectors", + Value: false, + Aliases: []string{"l"}, + }, + }, Action: func(cctx *cli.Context) error { if cctx.Args().Len() != 1 { @@ -353,33 +361,64 @@ var provingDeadlineInfoCmd = &cli.Command{ fmt.Printf("Proven Partitions: %d\n", provenPartitions) fmt.Printf("Current: %t\n\n", di.Index == dlIdx) - for pIdx, partition := range partitions { - sectorCount, err := partition.AllSectors.Count() - if err != nil { - return err - } + if !cctx.Bool("live") { + for pIdx, partition := range partitions { + sectorCount, err := partition.AllSectors.Count() + if err != nil { + return err + } - sectorNumbers, err := partition.AllSectors.All(sectorCount) - if err != nil { - return err - } + sectorNumbers, err := partition.AllSectors.All(sectorCount) + if err != nil { + return err + } - faultsCount, err := partition.FaultySectors.Count() - if err != nil { - return err - } + faultsCount, err := partition.FaultySectors.Count() + if err != nil { + return err + } - fn, err := partition.FaultySectors.All(faultsCount) - if err != nil { - return err - } + fn, err := partition.FaultySectors.All(faultsCount) + if err != nil { + return err + } - fmt.Printf("Partition Index: %d\n", pIdx) - fmt.Printf("Sectors: %d\n", sectorCount) - fmt.Printf("Sector Numbers: %v\n", sectorNumbers) - fmt.Printf("Faults: %d\n", faultsCount) - fmt.Printf("Faulty Sectors: %d\n", fn) + fmt.Printf("Partition Index: %d\n", pIdx) + fmt.Printf("Sectors: %d\n", sectorCount) + fmt.Printf("Sector Numbers: %v\n", sectorNumbers) + fmt.Printf("Faults: %d\n", faultsCount) + fmt.Printf("Faulty Sectors: %d\n", fn) + } + } else { + for pIdx, partition := range partitions { + sectorCount, err := partition.LiveSectors.Count() + if err != nil { + return err + } + + sectorNumbers, err := partition.LiveSectors.All(sectorCount) + if err != nil { + return err + } + + faultsCount, err := partition.FaultySectors.Count() + if err != nil { + return err + } + + fn, err := partition.FaultySectors.All(faultsCount) + if err != nil { + return err + } + + fmt.Printf("Partition Index: %d\n", pIdx) + fmt.Printf("Sectors: %d\n", sectorCount) + fmt.Printf("Sector Numbers: %v\n", sectorNumbers) + fmt.Printf("Faults: %d\n", faultsCount) + fmt.Printf("Faulty Sectors: %d\n", fn) + } } + return nil }, } From 6583a44a928d42003d4ca2961aa7faf6edb4a03d Mon Sep 17 00:00:00 2001 From: beck Date: Wed, 20 Jul 2022 10:21:52 +0800 Subject: [PATCH 3/3] reduce redundant code --- cmd/lotus-miner/proving.go | 102 +++++++++++++++---------------------- 1 file changed, 40 insertions(+), 62 deletions(-) diff --git a/cmd/lotus-miner/proving.go b/cmd/lotus-miner/proving.go index 51149baf6..9655e1fd0 100644 --- a/cmd/lotus-miner/proving.go +++ b/cmd/lotus-miner/proving.go @@ -249,8 +249,8 @@ var provingDeadlinesCmd = &cli.Command{ faults := uint64(0) var PartitionSum int - if cctx.Bool("live") { - for _, partition := range partitions { + for _, partition := range partitions { + if cctx.Bool("live") { sc, err := partition.LiveSectors.Count() if err != nil { return err @@ -261,34 +261,24 @@ var provingDeadlinesCmd = &cli.Command{ } sectors += sc - - fc, err := partition.FaultySectors.Count() - if err != nil { - return err - } - - faults += fc - - } - } else { - for _, partition := range partitions { - PartitionSum++ - + } else { sc, err := partition.AllSectors.Count() if err != nil { return err } + PartitionSum++ sectors += sc - - fc, err := partition.FaultySectors.Count() - if err != nil { - return err - } - - faults += fc } + + fc, err := partition.FaultySectors.Count() + if err != nil { + return err + } + + faults += fc } + var cur string if di.Index == uint64(dlIdx) { cur += "\t(current)" @@ -361,64 +351,52 @@ var provingDeadlineInfoCmd = &cli.Command{ fmt.Printf("Proven Partitions: %d\n", provenPartitions) fmt.Printf("Current: %t\n\n", di.Index == dlIdx) - if !cctx.Bool("live") { - for pIdx, partition := range partitions { - sectorCount, err := partition.AllSectors.Count() + var sectorCount uint64 + var sectorNumbers []uint64 + + for pIdx, partition := range partitions { + if !cctx.Bool("live") { + sectorCount, err = partition.AllSectors.Count() if err != nil { return err } - sectorNumbers, err := partition.AllSectors.All(sectorCount) + sectorNumbers, err = partition.AllSectors.All(sectorCount) if err != nil { return err } - faultsCount, err := partition.FaultySectors.Count() + } else { + sectorCount, err = partition.LiveSectors.Count() if err != nil { return err } - fn, err := partition.FaultySectors.All(faultsCount) - if err != nil { - return err + if sectorCount != 0 { + sectorNumbers, err = partition.LiveSectors.All(sectorCount) + if err != nil { + return err + } } - fmt.Printf("Partition Index: %d\n", pIdx) - fmt.Printf("Sectors: %d\n", sectorCount) - fmt.Printf("Sector Numbers: %v\n", sectorNumbers) - fmt.Printf("Faults: %d\n", faultsCount) - fmt.Printf("Faulty Sectors: %d\n", fn) } - } else { - for pIdx, partition := range partitions { - sectorCount, err := partition.LiveSectors.Count() - if err != nil { - return err - } - sectorNumbers, err := partition.LiveSectors.All(sectorCount) - if err != nil { - return err - } - - faultsCount, err := partition.FaultySectors.Count() - if err != nil { - return err - } - - fn, err := partition.FaultySectors.All(faultsCount) - if err != nil { - return err - } - - fmt.Printf("Partition Index: %d\n", pIdx) - fmt.Printf("Sectors: %d\n", sectorCount) - fmt.Printf("Sector Numbers: %v\n", sectorNumbers) - fmt.Printf("Faults: %d\n", faultsCount) - fmt.Printf("Faulty Sectors: %d\n", fn) + faultsCount, err := partition.FaultySectors.Count() + if err != nil { + return err } + + fn, err := partition.FaultySectors.All(faultsCount) + if err != nil { + return err + } + + fmt.Printf("Partition Index: %d\n", pIdx) + fmt.Printf("Sectors: %d\n", sectorCount) + fmt.Printf("Sector Numbers: %v\n", sectorNumbers) + fmt.Printf("Faults: %d\n", faultsCount) + fmt.Printf("Faulty Sectors: %d\n", fn) } - return nil }, }