2020-04-17 22:02:04 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-04-24 17:12:30 +00:00
|
|
|
"bytes"
|
2020-04-17 22:02:04 +00:00
|
|
|
"fmt"
|
2020-09-15 10:09:43 +00:00
|
|
|
"os"
|
|
|
|
"text/tabwriter"
|
|
|
|
|
2020-07-14 12:31:15 +00:00
|
|
|
"github.com/fatih/color"
|
2020-06-04 23:38:38 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
|
|
|
|
2020-04-17 22:02:04 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
lcli "github.com/filecoin-project/lotus/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
var provingCmd = &cli.Command{
|
2020-06-15 09:43:42 +00:00
|
|
|
Name: "proving",
|
|
|
|
Usage: "View proving information",
|
2020-04-17 22:02:04 +00:00
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
provingInfoCmd,
|
|
|
|
provingDeadlinesCmd,
|
2020-06-22 08:00:29 +00:00
|
|
|
provingFaultsCmd,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var provingFaultsCmd = &cli.Command{
|
|
|
|
Name: "faults",
|
|
|
|
Usage: "View the currently known proving faulty sectors information",
|
|
|
|
Action: func(cctx *cli.Context) error {
|
2020-07-14 12:31:15 +00:00
|
|
|
color.NoColor = !cctx.Bool("color")
|
|
|
|
|
2020-06-22 08:00:29 +00:00
|
|
|
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
api, acloser, err := lcli.GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer acloser()
|
|
|
|
|
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
|
2020-07-03 17:45:21 +00:00
|
|
|
maddr, err := getActorAddress(ctx, nodeApi, cctx.String("actor"))
|
2020-06-22 08:00:29 +00:00
|
|
|
if err != nil {
|
2020-07-03 17:35:20 +00:00
|
|
|
return err
|
2020-06-22 08:00:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var mas miner.State
|
|
|
|
{
|
|
|
|
mact, err := api.StateGetActor(ctx, maddr, types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
rmas, err := api.ChainReadObj(ctx, mact.Head)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := mas.UnmarshalCBOR(bytes.NewReader(rmas)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-07-14 20:14:37 +00:00
|
|
|
|
2020-07-14 12:31:15 +00:00
|
|
|
fmt.Printf("Miner: %s\n", color.BlueString("%s", maddr))
|
|
|
|
|
2020-06-24 02:14:20 +00:00
|
|
|
head, err := api.ChainHead(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting chain head: %w", err)
|
|
|
|
}
|
|
|
|
deadlines, err := api.StateMinerDeadlines(ctx, maddr, head.Key())
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting miner deadlines: %w", err)
|
|
|
|
}
|
|
|
|
tw := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0)
|
2020-07-14 20:14:37 +00:00
|
|
|
_, _ = fmt.Fprintln(tw, "deadline\tpartition\tsectors")
|
|
|
|
for dlIdx := range deadlines {
|
|
|
|
partitions, err := api.StateMinerPartitions(ctx, maddr, uint64(dlIdx), types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("loading partitions for deadline %d: %w", dlIdx, err)
|
2020-06-24 02:14:20 +00:00
|
|
|
}
|
|
|
|
|
2020-07-14 20:14:37 +00:00
|
|
|
for partIdx, partition := range partitions {
|
|
|
|
faulty, err := partition.Faults.All(10000000)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, num := range faulty {
|
|
|
|
_, _ = fmt.Fprintf(tw, "%d\t%d\t%d\n", dlIdx, partIdx, num)
|
|
|
|
}
|
|
|
|
}
|
2020-06-22 08:00:29 +00:00
|
|
|
}
|
2020-06-24 02:14:20 +00:00
|
|
|
return tw.Flush()
|
2020-04-17 22:02:04 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var provingInfoCmd = &cli.Command{
|
2020-06-15 09:43:42 +00:00
|
|
|
Name: "info",
|
|
|
|
Usage: "View current state information",
|
2020-04-17 22:02:04 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
2020-07-14 12:31:15 +00:00
|
|
|
color.NoColor = !cctx.Bool("color")
|
|
|
|
|
2020-04-17 22:02:04 +00:00
|
|
|
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
api, acloser, err := lcli.GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer acloser()
|
|
|
|
|
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
|
2020-07-03 17:45:21 +00:00
|
|
|
maddr, err := getActorAddress(ctx, nodeApi, cctx.String("actor"))
|
2020-04-17 22:02:04 +00:00
|
|
|
if err != nil {
|
2020-07-03 17:35:20 +00:00
|
|
|
return err
|
2020-04-17 22:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
head, err := api.ChainHead(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting chain head: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-04-24 17:12:30 +00:00
|
|
|
cd, err := api.StateMinerProvingDeadline(ctx, maddr, head.Key())
|
2020-04-17 22:02:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting miner info: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
deadlines, err := api.StateMinerDeadlines(ctx, maddr, head.Key())
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting miner deadlines: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-07-14 12:31:15 +00:00
|
|
|
fmt.Printf("Miner: %s\n", color.BlueString("%s", maddr))
|
|
|
|
|
2020-04-24 17:12:30 +00:00
|
|
|
var mas miner.State
|
|
|
|
{
|
|
|
|
mact, err := api.StateGetActor(ctx, maddr, types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
rmas, err := api.ChainReadObj(ctx, mact.Head)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := mas.UnmarshalCBOR(bytes.NewReader(rmas)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-14 20:14:37 +00:00
|
|
|
parts := map[uint64][]*miner.Partition{}
|
|
|
|
for dlIdx := range deadlines {
|
|
|
|
part, err := api.StateMinerPartitions(ctx, maddr, uint64(dlIdx), types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting miner partition: %w", err)
|
|
|
|
}
|
2020-04-24 17:12:30 +00:00
|
|
|
|
2020-07-14 20:14:37 +00:00
|
|
|
parts[uint64(dlIdx)] = part
|
2020-04-24 17:12:30 +00:00
|
|
|
}
|
|
|
|
|
2020-07-14 20:14:37 +00:00
|
|
|
proving := uint64(0)
|
|
|
|
faults := uint64(0)
|
|
|
|
recovering := uint64(0)
|
2020-04-24 17:12:30 +00:00
|
|
|
|
2020-07-14 20:14:37 +00:00
|
|
|
for _, partitions := range parts {
|
|
|
|
for _, partition := range partitions {
|
|
|
|
sc, err := partition.Sectors.Count()
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("count partition sectors: %w", err)
|
|
|
|
}
|
|
|
|
proving += sc
|
|
|
|
|
|
|
|
fc, err := partition.Faults.Count()
|
|
|
|
if err != nil {
|
2020-08-24 06:56:44 +00:00
|
|
|
return xerrors.Errorf("count partition faults: %w", err)
|
2020-07-14 20:14:37 +00:00
|
|
|
}
|
|
|
|
faults += fc
|
|
|
|
|
2020-08-24 06:56:44 +00:00
|
|
|
rc, err := partition.Recoveries.Count()
|
2020-07-14 20:14:37 +00:00
|
|
|
if err != nil {
|
2020-08-24 06:56:44 +00:00
|
|
|
return xerrors.Errorf("count partition recoveries: %w", err)
|
2020-07-14 20:14:37 +00:00
|
|
|
}
|
|
|
|
recovering += rc
|
2020-04-24 17:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-13 16:53:07 +00:00
|
|
|
var faultPerc float64
|
2020-07-14 20:14:37 +00:00
|
|
|
if proving > 0 {
|
|
|
|
faultPerc = float64(faults*10000/proving) / 100
|
2020-05-13 16:53:07 +00:00
|
|
|
}
|
|
|
|
|
2020-04-20 17:34:08 +00:00
|
|
|
fmt.Printf("Current Epoch: %d\n", cd.CurrentEpoch)
|
|
|
|
|
2020-04-28 13:21:56 +00:00
|
|
|
fmt.Printf("Proving Period Boundary: %d\n", cd.PeriodStart%miner.WPoStProvingPeriod)
|
2020-09-14 23:36:36 +00:00
|
|
|
fmt.Printf("Proving Period Start: %s\n", lcli.EpochTime(cd.CurrentEpoch, cd.PeriodStart))
|
|
|
|
fmt.Printf("Next Period Start: %s\n\n", lcli.EpochTime(cd.CurrentEpoch, cd.PeriodStart+miner.WPoStProvingPeriod))
|
2020-04-20 17:34:08 +00:00
|
|
|
|
2020-05-13 16:53:07 +00:00
|
|
|
fmt.Printf("Faults: %d (%.2f%%)\n", faults, faultPerc)
|
2020-07-14 20:14:37 +00:00
|
|
|
fmt.Printf("Recovering: %d\n", recovering)
|
2020-04-24 17:12:30 +00:00
|
|
|
|
2020-04-20 17:34:08 +00:00
|
|
|
fmt.Printf("Deadline Index: %d\n", cd.Index)
|
2020-07-07 22:56:53 +00:00
|
|
|
|
2020-07-14 20:14:37 +00:00
|
|
|
if cd.Index < miner.WPoStPeriodDeadlines {
|
|
|
|
curDeadlineSectors := uint64(0)
|
|
|
|
for _, partition := range parts[cd.Index] {
|
|
|
|
sc, err := partition.Sectors.Count()
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("counting current deadline sectors: %w", err)
|
|
|
|
}
|
|
|
|
curDeadlineSectors += sc
|
2020-07-07 22:56:53 +00:00
|
|
|
}
|
2020-07-14 20:14:37 +00:00
|
|
|
|
2020-07-07 22:56:53 +00:00
|
|
|
fmt.Printf("Deadline Sectors: %d\n", curDeadlineSectors)
|
|
|
|
}
|
|
|
|
|
2020-09-14 23:36:36 +00:00
|
|
|
fmt.Printf("Deadline Open: %s\n", lcli.EpochTime(cd.CurrentEpoch, cd.Open))
|
|
|
|
fmt.Printf("Deadline Close: %s\n", lcli.EpochTime(cd.CurrentEpoch, cd.Close))
|
|
|
|
fmt.Printf("Deadline Challenge: %s\n", lcli.EpochTime(cd.CurrentEpoch, cd.Challenge))
|
|
|
|
fmt.Printf("Deadline FaultCutoff: %s\n", lcli.EpochTime(cd.CurrentEpoch, cd.FaultCutoff))
|
2020-04-17 22:02:04 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var provingDeadlinesCmd = &cli.Command{
|
2020-06-15 09:43:42 +00:00
|
|
|
Name: "deadlines",
|
|
|
|
Usage: "View the current proving period deadlines information",
|
2020-04-17 22:02:04 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
2020-07-14 12:31:15 +00:00
|
|
|
color.NoColor = !cctx.Bool("color")
|
|
|
|
|
2020-04-17 22:02:04 +00:00
|
|
|
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
|
|
|
api, acloser, err := lcli.GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer acloser()
|
|
|
|
|
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
|
2020-07-03 17:45:21 +00:00
|
|
|
maddr, err := getActorAddress(ctx, nodeApi, cctx.String("actor"))
|
2020-04-17 22:02:04 +00:00
|
|
|
if err != nil {
|
2020-07-03 17:35:20 +00:00
|
|
|
return err
|
2020-04-17 22:02:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
deadlines, err := api.StateMinerDeadlines(ctx, maddr, types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting deadlines: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-04-24 17:12:30 +00:00
|
|
|
di, err := api.StateMinerProvingDeadline(ctx, maddr, types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting deadlines: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var mas miner.State
|
|
|
|
{
|
|
|
|
mact, err := api.StateGetActor(ctx, maddr, types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
rmas, err := api.ChainReadObj(ctx, mact.Head)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := mas.UnmarshalCBOR(bytes.NewReader(rmas)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-14 12:31:15 +00:00
|
|
|
fmt.Printf("Miner: %s\n", color.BlueString("%s", maddr))
|
|
|
|
|
2020-06-04 23:38:38 +00:00
|
|
|
tw := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0)
|
2020-07-27 16:15:47 +00:00
|
|
|
_, _ = fmt.Fprintln(tw, "deadline\tpartitions\tsectors (faults)\tproven partitions")
|
2020-06-04 23:38:38 +00:00
|
|
|
|
2020-07-14 20:14:37 +00:00
|
|
|
for dlIdx, deadline := range deadlines {
|
|
|
|
partitions, err := api.StateMinerPartitions(ctx, maddr, uint64(dlIdx), types.EmptyTSK)
|
2020-04-17 22:02:04 +00:00
|
|
|
if err != nil {
|
2020-07-14 20:14:37 +00:00
|
|
|
return xerrors.Errorf("getting partitions for deadline %d: %w", dlIdx, err)
|
2020-04-17 22:02:04 +00:00
|
|
|
}
|
|
|
|
|
2020-07-14 20:14:37 +00:00
|
|
|
provenPartitions, err := deadline.PostSubmissions.Count()
|
2020-04-24 17:12:30 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-07-27 16:15:47 +00:00
|
|
|
sectors := uint64(0)
|
|
|
|
faults := uint64(0)
|
|
|
|
|
|
|
|
for _, partition := range partitions {
|
|
|
|
sc, err := partition.Sectors.Count()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
sectors += sc
|
|
|
|
|
|
|
|
fc, err := partition.Faults.Count()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
faults += fc
|
|
|
|
}
|
|
|
|
|
2020-06-04 23:38:38 +00:00
|
|
|
var cur string
|
2020-07-14 20:14:37 +00:00
|
|
|
if di.Index == uint64(dlIdx) {
|
2020-06-04 23:38:38 +00:00
|
|
|
cur += "\t(current)"
|
2020-04-24 17:12:30 +00:00
|
|
|
}
|
2020-07-27 16:15:47 +00:00
|
|
|
_, _ = fmt.Fprintf(tw, "%d\t%d\t%d (%d)\t%d%s\n", dlIdx, len(partitions), sectors, faults, provenPartitions, cur)
|
2020-04-17 22:02:04 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 23:38:38 +00:00
|
|
|
return tw.Flush()
|
2020-04-17 22:02:04 +00:00
|
|
|
},
|
2020-04-17 22:02:43 +00:00
|
|
|
}
|