Merge pull request #9109 from filecoin-project/feat/dlinfo-enchantments
feat: miner cli: proving deadline command enchantments
This commit is contained in:
commit
453b454b7b
@ -1,10 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -13,6 +15,7 @@ import (
|
|||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"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/abi"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/blockstore"
|
"github.com/filecoin-project/lotus/blockstore"
|
||||||
@ -197,6 +200,13 @@ var provingInfoCmd = &cli.Command{
|
|||||||
var provingDeadlinesCmd = &cli.Command{
|
var provingDeadlinesCmd = &cli.Command{
|
||||||
Name: "deadlines",
|
Name: "deadlines",
|
||||||
Usage: "View the current proving period deadlines information",
|
Usage: "View the current proving period deadlines information",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "all",
|
||||||
|
Usage: "Count all sectors (only live sectors are counted by default)",
|
||||||
|
Aliases: []string{"a"},
|
||||||
|
},
|
||||||
|
},
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
api, acloser, err := lcli.GetFullNodeAPI(cctx)
|
api, acloser, err := lcli.GetFullNodeAPI(cctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -239,14 +249,29 @@ var provingDeadlinesCmd = &cli.Command{
|
|||||||
|
|
||||||
sectors := uint64(0)
|
sectors := uint64(0)
|
||||||
faults := uint64(0)
|
faults := uint64(0)
|
||||||
|
var partitionCount int
|
||||||
|
|
||||||
for _, partition := range partitions {
|
for _, partition := range partitions {
|
||||||
sc, err := partition.AllSectors.Count()
|
if !cctx.Bool("all") {
|
||||||
if err != nil {
|
sc, err := partition.LiveSectors.Count()
|
||||||
return err
|
if err != nil {
|
||||||
}
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
sectors += sc
|
if sc > 0 {
|
||||||
|
partitionCount++
|
||||||
|
}
|
||||||
|
|
||||||
|
sectors += sc
|
||||||
|
} else {
|
||||||
|
sc, err := partition.AllSectors.Count()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
partitionCount++
|
||||||
|
sectors += sc
|
||||||
|
}
|
||||||
|
|
||||||
fc, err := partition.FaultySectors.Count()
|
fc, err := partition.FaultySectors.Count()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -260,7 +285,7 @@ var provingDeadlinesCmd = &cli.Command{
|
|||||||
if di.Index == uint64(dlIdx) {
|
if di.Index == uint64(dlIdx) {
|
||||||
cur += "\t(current)"
|
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, partitionCount, sectors, faults, provenPartitions, cur)
|
||||||
}
|
}
|
||||||
|
|
||||||
return tw.Flush()
|
return tw.Flush()
|
||||||
@ -276,6 +301,11 @@ var provingDeadlineInfoCmd = &cli.Command{
|
|||||||
Aliases: []string{"n"},
|
Aliases: []string{"n"},
|
||||||
Usage: "Print sector/fault numbers belonging to this deadline",
|
Usage: "Print sector/fault numbers belonging to this deadline",
|
||||||
},
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "bitfield",
|
||||||
|
Aliases: []string{"b"},
|
||||||
|
Usage: "Print partition bitfield stats",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
ArgsUsage: "<deadlineIdx>",
|
ArgsUsage: "<deadlineIdx>",
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
@ -328,34 +358,75 @@ var provingDeadlineInfoCmd = &cli.Command{
|
|||||||
fmt.Printf("Current: %t\n\n", di.Index == dlIdx)
|
fmt.Printf("Current: %t\n\n", di.Index == dlIdx)
|
||||||
|
|
||||||
for pIdx, partition := range partitions {
|
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
|
|
||||||
}
|
|
||||||
|
|
||||||
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("Partition Index: %d\n", pIdx)
|
||||||
fmt.Printf("\tSectors: %d\n", sectorCount)
|
|
||||||
if cctx.Bool("sector-nums") {
|
printStats := func(bf bitfield.BitField, name string) error {
|
||||||
fmt.Printf("\tSector Numbers: %v\n", sectorNumbers)
|
count, err := bf.Count()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
rit, err := bf.RunIterator()
|
||||||
|
if err != nil {
|
||||||
|
return 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++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
} 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)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Printf("\t%s Sector Numbers:%s%v\n", name, strings.Repeat(" ", 12-len(name)), nums)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
fmt.Printf("\tFaults: %d\n", faultsCount)
|
|
||||||
if cctx.Bool("sector-nums") {
|
if err := printStats(partition.AllSectors, "All"); err != nil {
|
||||||
fmt.Printf("\tFaulty Sectors: %d\n", fn)
|
return err
|
||||||
|
}
|
||||||
|
if err := printStats(partition.LiveSectors, "Live"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := printStats(partition.ActiveSectors, "Active"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := printStats(partition.FaultySectors, "Faulty"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := printStats(partition.RecoveringSectors, "Recovering"); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -2055,7 +2055,7 @@ USAGE:
|
|||||||
lotus-miner proving deadlines [command options] [arguments...]
|
lotus-miner proving deadlines [command options] [arguments...]
|
||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
--help, -h show help (default: false)
|
--all, -a Count all sectors (only live sectors are counted by default) (default: false)
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -2068,6 +2068,7 @@ USAGE:
|
|||||||
lotus-miner proving deadline [command options] <deadlineIdx>
|
lotus-miner proving deadline [command options] <deadlineIdx>
|
||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
|
--bitfield, -b Print partition bitfield stats (default: false)
|
||||||
--sector-nums, -n Print sector/fault numbers belonging to this deadline (default: false)
|
--sector-nums, -n Print sector/fault numbers belonging to this deadline (default: false)
|
||||||
|
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user