2019-10-11 23:47:29 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-04-24 17:35:41 +00:00
|
|
|
"bytes"
|
2019-10-14 02:32:32 +00:00
|
|
|
"context"
|
2019-10-11 23:47:29 +00:00
|
|
|
"fmt"
|
2020-05-01 12:06:19 +00:00
|
|
|
"sort"
|
2020-06-04 15:10:41 +00:00
|
|
|
"time"
|
2019-10-11 23:47:29 +00:00
|
|
|
|
2020-05-01 12:06:19 +00:00
|
|
|
"github.com/fatih/color"
|
2020-06-02 18:12:53 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2020-06-05 22:59:01 +00:00
|
|
|
"golang.org/x/xerrors"
|
2019-10-11 23:47:29 +00:00
|
|
|
|
2020-04-24 17:35:41 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
|
2020-06-23 21:25:45 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/builtin/power"
|
2020-04-24 17:35:41 +00:00
|
|
|
sealing "github.com/filecoin-project/storage-fsm"
|
|
|
|
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2020-06-04 15:10:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/build"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
lcli "github.com/filecoin-project/lotus/cli"
|
2019-10-11 23:47:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var infoCmd = &cli.Command{
|
|
|
|
Name: "info",
|
|
|
|
Usage: "Print storage miner info",
|
2020-05-01 12:06:19 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.BoolFlag{Name: "color"},
|
|
|
|
},
|
2019-10-11 23:47:29 +00:00
|
|
|
Action: func(cctx *cli.Context) error {
|
2020-05-01 12:06:19 +00:00
|
|
|
color.NoColor = !cctx.Bool("color")
|
|
|
|
|
2019-10-11 23:47:29 +00:00
|
|
|
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
2019-10-14 02:32:32 +00:00
|
|
|
|
|
|
|
api, acloser, err := lcli.GetFullNodeAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer acloser()
|
|
|
|
|
2019-10-11 23:47:29 +00:00
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
|
2020-07-03 17:45:21 +00:00
|
|
|
maddr, err := getActorAddress(ctx, nodeApi, cctx.String("actor"))
|
2019-10-14 02:32:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-24 17:35:41 +00:00
|
|
|
mact, err := api.StateGetActor(ctx, maddr, types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
var mas miner.State
|
|
|
|
{
|
|
|
|
rmas, err := api.ChainReadObj(ctx, mact.Head)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := mas.UnmarshalCBOR(bytes.NewReader(rmas)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-01 12:06:19 +00:00
|
|
|
fmt.Printf("Miner: %s\n", color.BlueString("%s", maddr))
|
2019-10-14 02:32:32 +00:00
|
|
|
|
2019-11-07 10:46:11 +00:00
|
|
|
// Sector size
|
2020-04-16 17:36:36 +00:00
|
|
|
mi, err := api.StateMinerInfo(ctx, maddr, types.EmptyTSK)
|
2019-11-07 10:46:11 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-11-07 12:05:03 +00:00
|
|
|
|
2020-04-16 17:36:36 +00:00
|
|
|
fmt.Printf("Sector Size: %s\n", types.SizeStr(types.NewInt(uint64(mi.SectorSize))))
|
2019-11-07 10:46:11 +00:00
|
|
|
|
2020-02-11 23:29:45 +00:00
|
|
|
pow, err := api.StateMinerPower(ctx, maddr, types.EmptyTSK)
|
2019-10-14 02:32:32 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-04-17 22:02:04 +00:00
|
|
|
rpercI := types.BigDiv(types.BigMul(pow.MinerPower.RawBytePower, types.NewInt(1000000)), pow.TotalPower.RawBytePower)
|
|
|
|
qpercI := types.BigDiv(types.BigMul(pow.MinerPower.QualityAdjPower, types.NewInt(1000000)), pow.TotalPower.QualityAdjPower)
|
2020-05-01 12:06:19 +00:00
|
|
|
|
|
|
|
fmt.Printf("Byte Power: %s / %s (%0.4f%%)\n",
|
|
|
|
color.BlueString(types.SizeStr(pow.MinerPower.RawBytePower)),
|
|
|
|
types.SizeStr(pow.TotalPower.RawBytePower),
|
|
|
|
float64(rpercI.Int64())/10000)
|
|
|
|
|
|
|
|
fmt.Printf("Actual Power: %s / %s (%0.4f%%)\n",
|
|
|
|
color.GreenString(types.DeciStr(pow.MinerPower.QualityAdjPower)),
|
|
|
|
types.DeciStr(pow.TotalPower.QualityAdjPower),
|
|
|
|
float64(qpercI.Int64())/10000)
|
|
|
|
|
2020-02-11 23:29:45 +00:00
|
|
|
secCounts, err := api.StateMinerSectorCount(ctx, maddr, types.EmptyTSK)
|
2019-12-12 12:02:20 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-02-11 23:29:45 +00:00
|
|
|
faults, err := api.StateMinerFaults(ctx, maddr, types.EmptyTSK)
|
2020-01-30 18:38:03 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-05-16 21:50:50 +00:00
|
|
|
nfaults, err := faults.Count()
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("counting faults: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-04-16 17:36:36 +00:00
|
|
|
fmt.Printf("\tCommitted: %s\n", types.SizeStr(types.BigMul(types.NewInt(secCounts.Sset), types.NewInt(uint64(mi.SectorSize)))))
|
2020-05-16 21:50:50 +00:00
|
|
|
if nfaults == 0 {
|
2020-04-16 17:36:36 +00:00
|
|
|
fmt.Printf("\tProving: %s\n", types.SizeStr(types.BigMul(types.NewInt(secCounts.Pset), types.NewInt(uint64(mi.SectorSize)))))
|
2020-01-30 18:38:03 +00:00
|
|
|
} else {
|
2020-05-16 18:35:24 +00:00
|
|
|
var faultyPercentage float64
|
2020-05-20 03:58:58 +00:00
|
|
|
if secCounts.Sset != 0 {
|
2020-05-16 21:50:50 +00:00
|
|
|
faultyPercentage = float64(10000*nfaults/secCounts.Sset) / 100.
|
2020-05-16 18:35:24 +00:00
|
|
|
}
|
2020-01-30 18:38:03 +00:00
|
|
|
fmt.Printf("\tProving: %s (%s Faulty, %.2f%%)\n",
|
2020-05-20 03:58:58 +00:00
|
|
|
types.SizeStr(types.BigMul(types.NewInt(secCounts.Pset), types.NewInt(uint64(mi.SectorSize)))),
|
2020-05-16 21:50:50 +00:00
|
|
|
types.SizeStr(types.BigMul(types.NewInt(nfaults), types.NewInt(uint64(mi.SectorSize)))),
|
2020-05-16 18:35:24 +00:00
|
|
|
faultyPercentage)
|
2020-01-30 18:38:03 +00:00
|
|
|
}
|
2019-12-12 12:02:20 +00:00
|
|
|
|
2020-06-22 15:42:26 +00:00
|
|
|
if pow.MinerPower.RawBytePower.LessThan(power.ConsensusMinerMinPower) {
|
|
|
|
fmt.Print("Below minimum power threshold, no blocks will be won")
|
|
|
|
} else {
|
|
|
|
expWinChance := float64(types.BigMul(qpercI, types.NewInt(build.BlocksPerEpoch)).Int64()) / 1000000
|
|
|
|
if expWinChance > 0 {
|
|
|
|
if expWinChance > 1 {
|
|
|
|
expWinChance = 1
|
|
|
|
}
|
2020-06-30 13:22:48 +00:00
|
|
|
winRate := time.Duration(float64(time.Second*time.Duration(build.BlockDelaySecs)) / expWinChance)
|
2020-06-22 15:42:26 +00:00
|
|
|
winPerDay := float64(time.Hour*24) / float64(winRate)
|
|
|
|
|
|
|
|
fmt.Print("Expected block win rate: ")
|
|
|
|
color.Blue("%.4f/day (every %s)", winPerDay, winRate.Truncate(time.Second))
|
2020-06-04 15:10:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-01 12:06:19 +00:00
|
|
|
fmt.Println()
|
|
|
|
|
|
|
|
fmt.Printf("Miner Balance: %s\n", color.YellowString("%s", types.FIL(mact.Balance)))
|
2020-04-24 17:35:41 +00:00
|
|
|
fmt.Printf("\tPreCommit: %s\n", types.FIL(mas.PreCommitDeposits))
|
|
|
|
fmt.Printf("\tLocked: %s\n", types.FIL(mas.LockedFunds))
|
2020-05-01 12:06:19 +00:00
|
|
|
color.Green("\tAvailable: %s", types.FIL(types.BigSub(mact.Balance, types.BigAdd(mas.LockedFunds, mas.PreCommitDeposits))))
|
2020-04-24 17:35:41 +00:00
|
|
|
wb, err := api.WalletBalance(ctx, mi.Worker)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting worker balance: %w", err)
|
|
|
|
}
|
2020-05-01 12:06:19 +00:00
|
|
|
color.Cyan("Worker Balance: %s", types.FIL(wb))
|
2020-04-24 17:35:41 +00:00
|
|
|
|
|
|
|
mb, err := api.StateMarketBalance(ctx, maddr, types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting market balance: %w", err)
|
|
|
|
}
|
|
|
|
fmt.Printf("Market (Escrow): %s\n", types.FIL(mb.Escrow))
|
|
|
|
fmt.Printf("Market (Locked): %s\n", types.FIL(mb.Locked))
|
|
|
|
|
2020-05-01 12:06:19 +00:00
|
|
|
fmt.Println()
|
2019-12-06 00:27:32 +00:00
|
|
|
|
2020-05-01 12:06:19 +00:00
|
|
|
fmt.Println("Sectors:")
|
|
|
|
err = sectorsInfo(ctx, nodeApi)
|
2019-11-09 09:49:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-10-14 02:32:32 +00:00
|
|
|
|
2019-10-11 23:47:29 +00:00
|
|
|
// TODO: grab actr state / info
|
|
|
|
// * Sealed sectors (count / bytes)
|
|
|
|
// * Power
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2019-10-14 02:32:32 +00:00
|
|
|
|
2020-05-01 19:51:31 +00:00
|
|
|
type stateMeta struct {
|
|
|
|
i int
|
|
|
|
col color.Attribute
|
2020-05-01 12:06:19 +00:00
|
|
|
state sealing.SectorState
|
|
|
|
}
|
|
|
|
|
|
|
|
var stateOrder = map[sealing.SectorState]stateMeta{}
|
|
|
|
var stateList = []stateMeta{
|
|
|
|
{col: 39, state: "Total"},
|
|
|
|
{col: color.FgGreen, state: sealing.Proving},
|
|
|
|
|
|
|
|
{col: color.FgRed, state: sealing.UndefinedSectorState},
|
|
|
|
{col: color.FgYellow, state: sealing.Empty},
|
|
|
|
{col: color.FgYellow, state: sealing.Packing},
|
|
|
|
{col: color.FgYellow, state: sealing.PreCommit1},
|
|
|
|
{col: color.FgYellow, state: sealing.PreCommit2},
|
|
|
|
{col: color.FgYellow, state: sealing.PreCommitting},
|
2020-06-04 15:10:41 +00:00
|
|
|
{col: color.FgYellow, state: sealing.PreCommitWait},
|
2020-05-01 12:06:19 +00:00
|
|
|
{col: color.FgYellow, state: sealing.WaitSeed},
|
|
|
|
{col: color.FgYellow, state: sealing.Committing},
|
|
|
|
{col: color.FgYellow, state: sealing.CommitWait},
|
|
|
|
{col: color.FgYellow, state: sealing.FinalizeSector},
|
|
|
|
|
|
|
|
{col: color.FgRed, state: sealing.FailedUnrecoverable},
|
2020-06-04 19:22:53 +00:00
|
|
|
{col: color.FgRed, state: sealing.SealPreCommit1Failed},
|
|
|
|
{col: color.FgRed, state: sealing.SealPreCommit2Failed},
|
2020-05-01 12:06:19 +00:00
|
|
|
{col: color.FgRed, state: sealing.PreCommitFailed},
|
|
|
|
{col: color.FgRed, state: sealing.ComputeProofFailed},
|
|
|
|
{col: color.FgRed, state: sealing.CommitFailed},
|
|
|
|
{col: color.FgRed, state: sealing.PackingFailed},
|
2020-06-04 15:10:41 +00:00
|
|
|
{col: color.FgRed, state: sealing.FinalizeFailed},
|
2020-05-01 12:06:19 +00:00
|
|
|
{col: color.FgRed, state: sealing.Faulty},
|
|
|
|
{col: color.FgRed, state: sealing.FaultReported},
|
|
|
|
{col: color.FgRed, state: sealing.FaultedFinal},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
for i, state := range stateList {
|
|
|
|
stateOrder[state.state] = stateMeta{
|
2020-05-01 19:51:31 +00:00
|
|
|
i: i,
|
|
|
|
col: state.col,
|
2020-05-01 12:06:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func sectorsInfo(ctx context.Context, napi api.StorageMiner) error {
|
2019-10-14 02:32:32 +00:00
|
|
|
sectors, err := napi.SectorsList(ctx)
|
|
|
|
if err != nil {
|
2020-05-01 12:06:19 +00:00
|
|
|
return err
|
2019-10-14 02:32:32 +00:00
|
|
|
}
|
|
|
|
|
2020-05-01 12:06:19 +00:00
|
|
|
buckets := map[sealing.SectorState]int{
|
2019-11-01 03:57:10 +00:00
|
|
|
"Total": len(sectors),
|
2019-10-14 02:32:32 +00:00
|
|
|
}
|
|
|
|
for _, s := range sectors {
|
|
|
|
st, err := napi.SectorsStatus(ctx, s)
|
|
|
|
if err != nil {
|
2020-05-01 12:06:19 +00:00
|
|
|
return err
|
2019-10-14 02:32:32 +00:00
|
|
|
}
|
|
|
|
|
2020-05-01 12:06:19 +00:00
|
|
|
buckets[sealing.SectorState(st.State)]++
|
|
|
|
}
|
|
|
|
|
|
|
|
var sorted []stateMeta
|
|
|
|
for state, i := range buckets {
|
|
|
|
sorted = append(sorted, stateMeta{i: i, state: state})
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(sorted, func(i, j int) bool {
|
|
|
|
return stateOrder[sorted[i].state].i < stateOrder[sorted[j].state].i
|
|
|
|
})
|
|
|
|
|
|
|
|
for _, s := range sorted {
|
|
|
|
_, _ = color.New(stateOrder[s.state].col).Printf("\t%s: %d\n", s.state, s.i)
|
2019-10-14 02:32:32 +00:00
|
|
|
}
|
|
|
|
|
2020-05-01 12:06:19 +00:00
|
|
|
return nil
|
2019-10-14 02:32:32 +00:00
|
|
|
}
|