From 2375df2b62d710dd427d89b5658c0cf185cc6be8 Mon Sep 17 00:00:00 2001 From: beck Date: Wed, 25 May 2022 11:11:23 +0800 Subject: [PATCH 1/8] 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/8] 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/8] 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 }, } From 65ba7bd37d6ac10618c5eaa01b2daf0091d2abd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 2 Aug 2022 10:12:24 +0200 Subject: [PATCH 4/8] cli: clueanup deadlines command --- cmd/lotus-miner/proving.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/cmd/lotus-miner/proving.go b/cmd/lotus-miner/proving.go index bec2c07ce..57d063282 100644 --- a/cmd/lotus-miner/proving.go +++ b/cmd/lotus-miner/proving.go @@ -247,7 +247,7 @@ var provingDeadlinesCmd = &cli.Command{ sectors := uint64(0) faults := uint64(0) - var PartitionSum int + var partitionCount int for _, partition := range partitions { if cctx.Bool("live") { @@ -257,7 +257,7 @@ var provingDeadlinesCmd = &cli.Command{ } if sc > 0 { - PartitionSum++ + partitionCount++ } sectors += sc @@ -267,7 +267,7 @@ var provingDeadlinesCmd = &cli.Command{ return err } - PartitionSum++ + partitionCount++ sectors += sc } @@ -283,7 +283,7 @@ 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, PartitionSum, sectors, faults, provenPartitions, cur) + _, _ = fmt.Fprintf(tw, "%d\t%d\t%d (%d)\t%d%s\n", dlIdx, partitionCount, sectors, faults, provenPartitions, cur) } return tw.Flush() @@ -299,9 +299,6 @@ var provingDeadlineInfoCmd = &cli.Command{ Aliases: []string{"n"}, Usage: "Print sector/fault numbers belonging to this deadline", }, - }, - ArgsUsage: "", - Flags: []cli.Flag{ &cli.BoolFlag{ Name: "live", Usage: "View deadline live sectors", @@ -309,6 +306,7 @@ var provingDeadlineInfoCmd = &cli.Command{ Aliases: []string{"l"}, }, }, + ArgsUsage: "", Action: func(cctx *cli.Context) error { if cctx.Args().Len() != 1 { From 8c1d1bfd4af2499c0e39890307378b0a0abc6581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 2 Aug 2022 10:15:12 +0200 Subject: [PATCH 5/8] cli: show live sectors in the deadlines command by default --- cmd/lotus-miner/proving.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cmd/lotus-miner/proving.go b/cmd/lotus-miner/proving.go index 57d063282..708dd4083 100644 --- a/cmd/lotus-miner/proving.go +++ b/cmd/lotus-miner/proving.go @@ -199,10 +199,9 @@ var provingDeadlinesCmd = &cli.Command{ 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"}, + Name: "all", + Usage: "Count all sectors (only live sectors are counted by default)", + Aliases: []string{"a"}, }, }, Action: func(cctx *cli.Context) error { @@ -250,7 +249,7 @@ var provingDeadlinesCmd = &cli.Command{ var partitionCount int for _, partition := range partitions { - if cctx.Bool("live") { + if !cctx.Bool("all") { sc, err := partition.LiveSectors.Count() if err != nil { return err From 4548cea0004a8f3f621895e699a091e0983696f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 2 Aug 2022 10:40:34 +0200 Subject: [PATCH 6/8] cli: More verbose deadline command --- cmd/lotus-miner/proving.go | 83 ++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 34 deletions(-) diff --git a/cmd/lotus-miner/proving.go b/cmd/lotus-miner/proving.go index 708dd4083..e2b89483a 100644 --- a/cmd/lotus-miner/proving.go +++ b/cmd/lotus-miner/proving.go @@ -1,10 +1,13 @@ package main import ( + "bytes" "encoding/json" "fmt" + "github.com/filecoin-project/go-bitfield" "os" "strconv" + "strings" "text/tabwriter" "time" @@ -298,12 +301,6 @@ var provingDeadlineInfoCmd = &cli.Command{ Aliases: []string{"n"}, Usage: "Print sector/fault numbers belonging to this deadline", }, - &cli.BoolFlag{ - Name: "live", - Usage: "View deadline live sectors", - Value: false, - Aliases: []string{"l"}, - }, }, ArgsUsage: "", Action: func(cctx *cli.Context) error { @@ -355,54 +352,72 @@ var provingDeadlineInfoCmd = &cli.Command{ fmt.Printf("Proven Partitions: %d\n", provenPartitions) fmt.Printf("Current: %t\n\n", di.Index == dlIdx) - var sectorCount uint64 - var sectorNumbers []uint64 - for pIdx, partition := range partitions { - if !cctx.Bool("live") { - sectorCount, err = partition.AllSectors.Count() + fmt.Printf("Partition Index: %d\n", pIdx) + + printStats := func(bf bitfield.BitField, name string) error { + count, err := bf.Count() if err != nil { return err } - sectorNumbers, err = partition.AllSectors.All(sectorCount) + rit, err := bf.RunIterator() if err != nil { return err } - } else { - sectorCount, err = partition.LiveSectors.Count() - if err != nil { - return err - } - - if sectorCount != 0 { - sectorNumbers, err = partition.LiveSectors.All(sectorCount) + var ones, zeros, oneRuns, zeroRuns, invalid uint64 + for rit.HasNext() { + r, err := rit.NextRun() if err != nil { - return err + return xerrors.Errorf("next run: %w", err) + } + if !r.Valid() { + invalid++ + } + if r.Val { + ones += r.Len + oneRuns++ + } else { + zeros += r.Len + zeroRuns++ } } + var buf bytes.Buffer + if err := bf.MarshalCBOR(&buf); err != nil { + return err + } + sz := len(buf.Bytes()) + szstr := types.SizeStr(types.NewInt(uint64(sz))) + + fmt.Printf("\t%s Sectors:%s%d (bitfield - runs %d+%d=%d - %d 0s %d 1s - %d inv - %s %dB)\n", name, strings.Repeat(" ", 18-len(name)), count, zeroRuns, oneRuns, zeroRuns+oneRuns, zeros, ones, invalid, szstr, sz) + + if cctx.Bool("sector-nums") { + nums, err := bf.All(count) + if err != nil { + return err + } + fmt.Printf("\t%s Sector Numbers:%s%v\n", name, strings.Repeat(" ", 12-len(name)), nums) + } + + return nil } - faultsCount, err := partition.FaultySectors.Count() - if err != nil { + if err := printStats(partition.AllSectors, "All"); err != nil { return err } - - fn, err := partition.FaultySectors.All(faultsCount) - if err != nil { + if err := printStats(partition.LiveSectors, "Live"); err != nil { return err } - - fmt.Printf("Partition Index: %d\n", pIdx) - fmt.Printf("\tSectors: %d\n", sectorCount) - if cctx.Bool("sector-nums") { - fmt.Printf("\tSector Numbers: %v\n", sectorNumbers) + if err := printStats(partition.ActiveSectors, "Active"); err != nil { + return err } - fmt.Printf("\tFaults: %d\n", faultsCount) - if cctx.Bool("sector-nums") { - fmt.Printf("\tFaulty Sectors: %d\n", fn) + if err := printStats(partition.FaultySectors, "Faulty"); err != nil { + return err + } + if err := printStats(partition.RecoveringSectors, "Recovering"); err != nil { + return err } } return nil From 9a5ca5017b0f1c9aac2e1f4cd0143b3d47f6a6d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 2 Aug 2022 10:45:20 +0200 Subject: [PATCH 7/8] gen --- cmd/lotus-miner/proving.go | 2 +- documentation/en/cli-lotus-miner.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/lotus-miner/proving.go b/cmd/lotus-miner/proving.go index e2b89483a..c758176b0 100644 --- a/cmd/lotus-miner/proving.go +++ b/cmd/lotus-miner/proving.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/json" "fmt" - "github.com/filecoin-project/go-bitfield" "os" "strconv" "strings" @@ -16,6 +15,7 @@ import ( "golang.org/x/xerrors" "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-bitfield" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/lotus/blockstore" diff --git a/documentation/en/cli-lotus-miner.md b/documentation/en/cli-lotus-miner.md index 2af074d0b..7b852a83b 100644 --- a/documentation/en/cli-lotus-miner.md +++ b/documentation/en/cli-lotus-miner.md @@ -2055,7 +2055,7 @@ USAGE: lotus-miner proving deadlines [command options] [arguments...] OPTIONS: - --help, -h show help (default: false) + --all, -a Count all sectors (only live sectors are counted by default) (default: false) ``` From 4818d784325ee97bbd744ef281558540695f5328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Wed, 3 Aug 2022 11:06:05 +0200 Subject: [PATCH 8/8] cli: Put bitfield stats in 'proving deadline' behind a flag --- cmd/lotus-miner/proving.go | 55 +++++++++++++++++------------ documentation/en/cli-lotus-miner.md | 1 + 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/cmd/lotus-miner/proving.go b/cmd/lotus-miner/proving.go index c758176b0..5ff49c25f 100644 --- a/cmd/lotus-miner/proving.go +++ b/cmd/lotus-miner/proving.go @@ -301,6 +301,11 @@ var provingDeadlineInfoCmd = &cli.Command{ Aliases: []string{"n"}, Usage: "Print sector/fault numbers belonging to this deadline", }, + &cli.BoolFlag{ + Name: "bitfield", + Aliases: []string{"b"}, + Usage: "Print partition bitfield stats", + }, }, ArgsUsage: "", Action: func(cctx *cli.Context) error { @@ -366,32 +371,36 @@ var provingDeadlineInfoCmd = &cli.Command{ return err } - var ones, zeros, oneRuns, zeroRuns, invalid uint64 - for rit.HasNext() { - r, err := rit.NextRun() - if err != nil { - return xerrors.Errorf("next run: %w", err) + if cctx.Bool("bitfield") { + var ones, zeros, oneRuns, zeroRuns, invalid uint64 + for rit.HasNext() { + r, err := rit.NextRun() + if err != nil { + return xerrors.Errorf("next run: %w", err) + } + if !r.Valid() { + invalid++ + } + if r.Val { + ones += r.Len + oneRuns++ + } else { + zeros += r.Len + zeroRuns++ + } } - if !r.Valid() { - invalid++ - } - if r.Val { - ones += r.Len - oneRuns++ - } else { - zeros += r.Len - zeroRuns++ - } - } - var buf bytes.Buffer - if err := bf.MarshalCBOR(&buf); err != nil { - return err - } - sz := len(buf.Bytes()) - szstr := types.SizeStr(types.NewInt(uint64(sz))) + var buf bytes.Buffer + if err := bf.MarshalCBOR(&buf); err != nil { + return err + } + sz := len(buf.Bytes()) + szstr := types.SizeStr(types.NewInt(uint64(sz))) - fmt.Printf("\t%s Sectors:%s%d (bitfield - runs %d+%d=%d - %d 0s %d 1s - %d inv - %s %dB)\n", name, strings.Repeat(" ", 18-len(name)), count, zeroRuns, oneRuns, zeroRuns+oneRuns, zeros, ones, invalid, szstr, sz) + fmt.Printf("\t%s Sectors:%s%d (bitfield - runs %d+%d=%d - %d 0s %d 1s - %d inv - %s %dB)\n", name, strings.Repeat(" ", 18-len(name)), count, zeroRuns, oneRuns, zeroRuns+oneRuns, zeros, ones, invalid, szstr, sz) + } else { + fmt.Printf("\t%s Sectors:%s%d\n", name, strings.Repeat(" ", 18-len(name)), count) + } if cctx.Bool("sector-nums") { nums, err := bf.All(count) diff --git a/documentation/en/cli-lotus-miner.md b/documentation/en/cli-lotus-miner.md index 7b852a83b..883c66ae8 100644 --- a/documentation/en/cli-lotus-miner.md +++ b/documentation/en/cli-lotus-miner.md @@ -2068,6 +2068,7 @@ USAGE: lotus-miner proving deadline [command options] OPTIONS: + --bitfield, -b Print partition bitfield stats (default: false) --sector-nums, -n Print sector/fault numbers belonging to this deadline (default: false) ```