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-06-04 23:38:38 +00:00
|
|
|
"os"
|
|
|
|
"text/tabwriter"
|
2020-06-02 19:53:24 +00:00
|
|
|
"time"
|
|
|
|
|
2020-07-01 11:47:40 +00:00
|
|
|
cbor "github.com/ipfs/go-ipld-cbor"
|
2020-06-04 23:38:38 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/go-bitfield"
|
|
|
|
rlepluslazy "github.com/filecoin-project/go-bitfield/rle"
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
|
|
|
|
2020-07-01 11:47:40 +00:00
|
|
|
"github.com/filecoin-project/lotus/api/apibstore"
|
2020-04-17 22:02:04 +00:00
|
|
|
"github.com/filecoin-project/lotus/build"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
lcli "github.com/filecoin-project/lotus/cli"
|
2020-07-01 11:47:40 +00:00
|
|
|
"github.com/filecoin-project/lotus/lib/adtutil"
|
2020-04-17 22:02:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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 {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
faults, err := mas.Faults.All(100000000000)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(faults) == 0 {
|
2020-06-24 02:14:20 +00:00
|
|
|
fmt.Println("no faulty sectors")
|
2020-07-05 01:17:10 +00:00
|
|
|
return nil
|
2020-06-22 08:00:29 +00:00
|
|
|
}
|
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)
|
|
|
|
_, _ = fmt.Fprintln(tw, "deadline\tsectors")
|
|
|
|
for deadline, sectors := range deadlines.Due {
|
|
|
|
intersectSectors, _ := bitfield.IntersectBitField(sectors, mas.Faults)
|
|
|
|
if intersectSectors != nil {
|
|
|
|
allSectors, _ := intersectSectors.All(100000000000)
|
|
|
|
for _, num := range allSectors {
|
|
|
|
_, _ = fmt.Fprintf(tw, "%d\t%d\n", deadline, 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 {
|
|
|
|
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-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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
newSectors, err := mas.NewSectors.Count()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
faults, err := mas.Faults.Count()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
recoveries, err := mas.Recoveries.Count()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var provenSectors uint64
|
|
|
|
for _, d := range deadlines.Due {
|
|
|
|
c, err := d.Count()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
provenSectors += c
|
|
|
|
}
|
|
|
|
|
2020-05-13 16:53:07 +00:00
|
|
|
var faultPerc float64
|
|
|
|
if provenSectors > 0 {
|
|
|
|
faultPerc = float64(faults*10000/provenSectors) / 100
|
|
|
|
}
|
|
|
|
|
2020-04-20 17:34:08 +00:00
|
|
|
fmt.Printf("Current Epoch: %d\n", cd.CurrentEpoch)
|
2020-04-21 17:23:49 +00:00
|
|
|
fmt.Printf("Chain Period: %d\n", cd.CurrentEpoch/miner.WPoStProvingPeriod)
|
|
|
|
fmt.Printf("Chain Period Start: %s\n", epochTime(cd.CurrentEpoch, (cd.CurrentEpoch/miner.WPoStProvingPeriod)*miner.WPoStProvingPeriod))
|
|
|
|
fmt.Printf("Chain Period End: %s\n\n", epochTime(cd.CurrentEpoch, (cd.CurrentEpoch/miner.WPoStProvingPeriod+1)*miner.WPoStProvingPeriod))
|
2020-04-20 17:34:08 +00:00
|
|
|
|
2020-04-28 13:21:56 +00:00
|
|
|
fmt.Printf("Proving Period Boundary: %d\n", cd.PeriodStart%miner.WPoStProvingPeriod)
|
2020-04-20 17:34:08 +00:00
|
|
|
fmt.Printf("Proving Period Start: %s\n", epochTime(cd.CurrentEpoch, cd.PeriodStart))
|
2020-04-21 17:23:49 +00:00
|
|
|
fmt.Printf("Next Period Start: %s\n\n", 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-04-24 17:12:30 +00:00
|
|
|
fmt.Printf("Recovering: %d\n", recoveries)
|
|
|
|
fmt.Printf("New Sectors: %d\n\n", newSectors)
|
|
|
|
|
2020-04-20 17:34:08 +00:00
|
|
|
fmt.Printf("Deadline Index: %d\n", cd.Index)
|
2020-07-07 22:56:53 +00:00
|
|
|
|
|
|
|
if cd.Index < uint64(len(deadlines.Due)) {
|
|
|
|
curDeadlineSectors, err := deadlines.Due[cd.Index].Count()
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("counting deadline sectors: %w", err)
|
|
|
|
}
|
|
|
|
fmt.Printf("Deadline Sectors: %d\n", curDeadlineSectors)
|
|
|
|
}
|
|
|
|
|
2020-04-20 17:34:08 +00:00
|
|
|
fmt.Printf("Deadline Open: %s\n", epochTime(cd.CurrentEpoch, cd.Open))
|
|
|
|
fmt.Printf("Deadline Close: %s\n", epochTime(cd.CurrentEpoch, cd.Close))
|
|
|
|
fmt.Printf("Deadline Challenge: %s\n", epochTime(cd.CurrentEpoch, cd.Challenge))
|
|
|
|
fmt.Printf("Deadline FaultCutoff: %s\n", epochTime(cd.CurrentEpoch, cd.FaultCutoff))
|
2020-04-17 22:02:04 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-04-20 17:34:08 +00:00
|
|
|
func epochTime(curr, e abi.ChainEpoch) string {
|
|
|
|
switch {
|
|
|
|
case curr > e:
|
2020-06-30 13:22:48 +00:00
|
|
|
return fmt.Sprintf("%d (%s ago)", e, time.Second*time.Duration(int64(build.BlockDelaySecs)*int64(curr-e)))
|
2020-04-20 17:34:08 +00:00
|
|
|
case curr == e:
|
|
|
|
return fmt.Sprintf("%d (now)", e)
|
|
|
|
case curr < e:
|
2020-06-30 13:22:48 +00:00
|
|
|
return fmt.Sprintf("%d (in %s)", e, time.Second*time.Duration(int64(build.BlockDelaySecs)*int64(e-curr)))
|
2020-04-20 17:34:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
panic("math broke")
|
|
|
|
}
|
|
|
|
|
2020-04-17 22:02:04 +00:00
|
|
|
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 {
|
|
|
|
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
|
2020-07-01 11:47:40 +00:00
|
|
|
var info *miner.MinerInfo
|
2020-04-24 17:12:30 +00:00
|
|
|
{
|
|
|
|
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-01 11:47:40 +00:00
|
|
|
|
|
|
|
info, err = mas.GetInfo(adtutil.NewStore(ctx, cbor.NewCborStore(apibstore.NewAPIBlockstore(api))))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-04-24 17:12:30 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 23:38:38 +00:00
|
|
|
tw := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0)
|
|
|
|
_, _ = fmt.Fprintln(tw, "deadline\tsectors\tpartitions\tproven")
|
|
|
|
|
2020-04-17 22:02:04 +00:00
|
|
|
for i, field := range deadlines.Due {
|
|
|
|
c, err := field.Count()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-07-01 11:47:40 +00:00
|
|
|
firstPartition, sectorCount, err := miner.PartitionsForDeadline(deadlines, info.WindowPoStPartitionSectors, uint64(i))
|
2020-04-24 17:12:30 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-07-01 11:47:40 +00:00
|
|
|
partitionCount := (sectorCount + info.WindowPoStPartitionSectors - 1) / info.WindowPoStPartitionSectors
|
2020-06-04 23:38:38 +00:00
|
|
|
|
|
|
|
var provenPartitions uint64
|
|
|
|
{
|
|
|
|
var maskRuns []rlepluslazy.Run
|
|
|
|
if firstPartition > 0 {
|
|
|
|
maskRuns = append(maskRuns, rlepluslazy.Run{
|
|
|
|
Val: false,
|
|
|
|
Len: firstPartition,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
maskRuns = append(maskRuns, rlepluslazy.Run{
|
|
|
|
Val: true,
|
|
|
|
Len: partitionCount,
|
|
|
|
})
|
|
|
|
|
|
|
|
ppbm, err := bitfield.NewFromIter(&rlepluslazy.RunSliceIterator{Runs: maskRuns})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
pp, err := bitfield.IntersectBitField(ppbm, mas.PostSubmissions)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
provenPartitions, err = pp.Count()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-04-24 17:12:30 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 23:38:38 +00:00
|
|
|
var cur string
|
2020-04-24 17:12:30 +00:00
|
|
|
if di.Index == uint64(i) {
|
2020-06-04 23:38:38 +00:00
|
|
|
cur += "\t(current)"
|
2020-04-24 17:12:30 +00:00
|
|
|
}
|
2020-06-05 22:59:01 +00:00
|
|
|
_, _ = fmt.Fprintf(tw, "%d\t%d\t%d\t%d%s\n", i, c, partitionCount, 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
|
|
|
}
|