2019-10-11 23:47:29 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-10-14 02:32:32 +00:00
|
|
|
"context"
|
2019-10-11 23:47:29 +00:00
|
|
|
"fmt"
|
2021-05-21 11:03:45 +00:00
|
|
|
"math"
|
|
|
|
corebig "math/big"
|
2021-07-08 17:02:18 +00:00
|
|
|
"os"
|
2020-05-01 12:06:19 +00:00
|
|
|
"sort"
|
2021-07-08 17:02:18 +00:00
|
|
|
"strings"
|
|
|
|
"text/tabwriter"
|
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-08-22 17:15:08 +00:00
|
|
|
cbor "github.com/ipfs/go-ipld-cbor"
|
|
|
|
|
2021-07-08 17:39:58 +00:00
|
|
|
"github.com/filecoin-project/go-fil-markets/retrievalmarket"
|
2020-08-22 17:15:08 +00:00
|
|
|
"github.com/filecoin-project/go-fil-markets/storagemarket"
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2020-12-01 18:43:22 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/big"
|
2020-08-17 13:39:33 +00:00
|
|
|
sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
|
2020-04-24 17:35:41 +00:00
|
|
|
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2021-01-29 20:01:00 +00:00
|
|
|
"github.com/filecoin-project/lotus/blockstore"
|
2020-06-04 15:10:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/build"
|
2020-09-18 21:46:42 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/adt"
|
2021-05-21 11:03:45 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
2020-09-18 21:46:42 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
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",
|
2020-07-11 08:55:13 +00:00
|
|
|
Usage: "Print miner info",
|
2020-08-04 18:57:40 +00:00
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
infoAllCmd,
|
|
|
|
},
|
2020-09-28 19:34:06 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.BoolFlag{
|
|
|
|
Name: "hide-sectors-info",
|
|
|
|
Usage: "hide sectors info",
|
|
|
|
},
|
|
|
|
},
|
2020-08-04 18:57:40 +00:00
|
|
|
Action: infoCmdAct,
|
|
|
|
}
|
2020-05-01 12:06:19 +00:00
|
|
|
|
2020-08-04 18:57:40 +00:00
|
|
|
func infoCmdAct(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-12-01 17:56:43 +00:00
|
|
|
fmt.Print("Chain: ")
|
2020-10-30 18:39:31 +00:00
|
|
|
|
|
|
|
head, err := api.ChainHead(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
switch {
|
|
|
|
case time.Now().Unix()-int64(head.MinTimestamp()) < int64(build.BlockDelaySecs*3/2): // within 1.5 epochs
|
|
|
|
fmt.Printf("[%s]", color.GreenString("sync ok"))
|
|
|
|
case time.Now().Unix()-int64(head.MinTimestamp()) < int64(build.BlockDelaySecs*5): // within 5 epochs
|
|
|
|
fmt.Printf("[%s]", color.YellowString("sync slow (%s behind)", time.Now().Sub(time.Unix(int64(head.MinTimestamp()), 0)).Truncate(time.Second)))
|
|
|
|
default:
|
|
|
|
fmt.Printf("[%s]", color.RedString("sync behind! (%s behind)", time.Now().Sub(time.Unix(int64(head.MinTimestamp()), 0)).Truncate(time.Second)))
|
|
|
|
}
|
|
|
|
|
2020-12-01 17:56:43 +00:00
|
|
|
basefee := head.MinTicketBlock().ParentBaseFee
|
|
|
|
gasCol := []color.Attribute{color.FgBlue}
|
|
|
|
switch {
|
|
|
|
case basefee.GreaterThan(big.NewInt(7000_000_000)): // 7 nFIL
|
|
|
|
gasCol = []color.Attribute{color.BgRed, color.FgBlack}
|
|
|
|
case basefee.GreaterThan(big.NewInt(3000_000_000)): // 3 nFIL
|
|
|
|
gasCol = []color.Attribute{color.FgRed}
|
|
|
|
case basefee.GreaterThan(big.NewInt(750_000_000)): // 750 uFIL
|
|
|
|
gasCol = []color.Attribute{color.FgYellow}
|
|
|
|
case basefee.GreaterThan(big.NewInt(100_000_000)): // 100 uFIL
|
|
|
|
gasCol = []color.Attribute{color.FgGreen}
|
|
|
|
}
|
2020-12-01 18:15:20 +00:00
|
|
|
fmt.Printf(" [basefee %s]", color.New(gasCol...).Sprint(types.FIL(basefee).Short()))
|
2020-12-01 17:56:43 +00:00
|
|
|
|
2020-10-30 18:39:31 +00:00
|
|
|
fmt.Println()
|
|
|
|
|
2021-03-28 05:21:09 +00:00
|
|
|
maddr, err := getActorAddress(ctx, cctx)
|
2020-08-04 18:57:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
mact, err := api.StateGetActor(ctx, maddr, types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-09-18 21:46:42 +00:00
|
|
|
|
2021-01-29 20:01:00 +00:00
|
|
|
tbs := blockstore.NewTieredBstore(blockstore.NewAPIBlockstore(api), blockstore.NewMemory())
|
2020-09-18 21:46:42 +00:00
|
|
|
mas, err := miner.Load(adt.WrapStore(ctx, cbor.NewCborStore(tbs)), mact)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2020-08-04 18:57:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sector size
|
|
|
|
mi, err := api.StateMinerInfo(ctx, maddr, types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-12-01 18:01:08 +00:00
|
|
|
ssize := types.SizeStr(types.NewInt(uint64(mi.SectorSize)))
|
|
|
|
fmt.Printf("Miner: %s (%s sectors)\n", color.BlueString("%s", maddr), ssize)
|
2020-08-04 18:57:40 +00:00
|
|
|
|
|
|
|
pow, err := api.StateMinerPower(ctx, maddr, types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-12-01 18:43:22 +00:00
|
|
|
fmt.Printf("Power: %s / %s (%0.4f%%)\n",
|
2020-08-04 18:57:40 +00:00
|
|
|
color.GreenString(types.DeciStr(pow.MinerPower.QualityAdjPower)),
|
|
|
|
types.DeciStr(pow.TotalPower.QualityAdjPower),
|
2021-05-21 11:03:45 +00:00
|
|
|
types.BigDivFloat(
|
|
|
|
types.BigMul(pow.MinerPower.QualityAdjPower, big.NewInt(100)),
|
|
|
|
pow.TotalPower.QualityAdjPower,
|
|
|
|
),
|
|
|
|
)
|
2020-08-04 18:57:40 +00:00
|
|
|
|
2020-12-01 18:43:22 +00:00
|
|
|
fmt.Printf("\tRaw: %s / %s (%0.4f%%)\n",
|
|
|
|
color.BlueString(types.SizeStr(pow.MinerPower.RawBytePower)),
|
|
|
|
types.SizeStr(pow.TotalPower.RawBytePower),
|
2021-05-21 11:03:45 +00:00
|
|
|
types.BigDivFloat(
|
|
|
|
types.BigMul(pow.MinerPower.RawBytePower, big.NewInt(100)),
|
|
|
|
pow.TotalPower.RawBytePower,
|
|
|
|
),
|
|
|
|
)
|
2020-08-04 18:57:40 +00:00
|
|
|
secCounts, err := api.StateMinerSectorCount(ctx, maddr, types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-09-15 19:09:39 +00:00
|
|
|
proving := secCounts.Active + secCounts.Faulty
|
|
|
|
nfaults := secCounts.Faulty
|
|
|
|
fmt.Printf("\tCommitted: %s\n", types.SizeStr(types.BigMul(types.NewInt(secCounts.Live), types.NewInt(uint64(mi.SectorSize)))))
|
2020-08-04 18:57:40 +00:00
|
|
|
if nfaults == 0 {
|
2020-09-15 19:09:39 +00:00
|
|
|
fmt.Printf("\tProving: %s\n", types.SizeStr(types.BigMul(types.NewInt(proving), types.NewInt(uint64(mi.SectorSize)))))
|
2020-08-04 18:57:40 +00:00
|
|
|
} else {
|
|
|
|
var faultyPercentage float64
|
2020-09-15 19:09:39 +00:00
|
|
|
if secCounts.Live != 0 {
|
2021-05-21 11:03:45 +00:00
|
|
|
faultyPercentage = float64(100*nfaults) / float64(secCounts.Live)
|
2020-08-04 18:57:40 +00:00
|
|
|
}
|
|
|
|
fmt.Printf("\tProving: %s (%s Faulty, %.2f%%)\n",
|
2020-09-15 19:09:39 +00:00
|
|
|
types.SizeStr(types.BigMul(types.NewInt(proving), types.NewInt(uint64(mi.SectorSize)))),
|
2020-08-04 18:57:40 +00:00
|
|
|
types.SizeStr(types.BigMul(types.NewInt(nfaults), types.NewInt(uint64(mi.SectorSize)))),
|
|
|
|
faultyPercentage)
|
|
|
|
}
|
|
|
|
|
2020-09-16 05:49:33 +00:00
|
|
|
if !pow.HasMinPower {
|
2020-08-04 18:57:40 +00:00
|
|
|
fmt.Print("Below minimum power threshold, no blocks will be won")
|
|
|
|
} else {
|
2021-05-21 11:03:45 +00:00
|
|
|
|
2021-06-14 21:41:43 +00:00
|
|
|
winRatio := new(corebig.Rat).SetFrac(
|
|
|
|
types.BigMul(pow.MinerPower.QualityAdjPower, types.NewInt(build.BlocksPerEpoch)).Int,
|
|
|
|
pow.TotalPower.QualityAdjPower.Int,
|
2021-05-21 11:03:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if winRatioFloat, _ := winRatio.Float64(); winRatioFloat > 0 {
|
|
|
|
|
2021-06-14 21:41:43 +00:00
|
|
|
// if the corresponding poisson distribution isn't infinitely small then
|
|
|
|
// throw it into the mix as well, accounting for multi-wins
|
|
|
|
winRationWithPoissonFloat := -math.Expm1(-winRatioFloat)
|
|
|
|
winRationWithPoisson := new(corebig.Rat).SetFloat64(winRationWithPoissonFloat)
|
|
|
|
if winRationWithPoisson != nil {
|
|
|
|
winRatio = winRationWithPoisson
|
|
|
|
winRatioFloat = winRationWithPoissonFloat
|
2020-06-04 15:10:41 +00:00
|
|
|
}
|
2020-08-04 18:57:40 +00:00
|
|
|
|
2021-05-21 11:03:45 +00:00
|
|
|
weekly, _ := new(corebig.Rat).Mul(
|
|
|
|
winRatio,
|
|
|
|
new(corebig.Rat).SetInt64(7*builtin.EpochsInDay),
|
|
|
|
).Float64()
|
|
|
|
|
|
|
|
avgDuration, _ := new(corebig.Rat).Mul(
|
|
|
|
new(corebig.Rat).SetInt64(builtin.EpochDurationSeconds),
|
|
|
|
new(corebig.Rat).Inv(winRatio),
|
|
|
|
).Float64()
|
|
|
|
|
|
|
|
fmt.Print("Projected average block win rate: ")
|
|
|
|
color.Blue(
|
|
|
|
"%.02f/week (every %s)",
|
|
|
|
weekly,
|
|
|
|
(time.Second * time.Duration(avgDuration)).Truncate(time.Second).String(),
|
|
|
|
)
|
|
|
|
|
2021-06-14 21:41:43 +00:00
|
|
|
// Geometric distribution of P(Y < k) calculated as described in https://en.wikipedia.org/wiki/Geometric_distribution#Probability_Outcomes_Examples
|
|
|
|
// https://www.wolframalpha.com/input/?i=t+%3E+0%3B+p+%3E+0%3B+p+%3C+1%3B+c+%3E+0%3B+c+%3C1%3B+1-%281-p%29%5E%28t%29%3Dc%3B+solve+t
|
|
|
|
// t == how many dice-rolls (epochs) before win
|
|
|
|
// p == winRate == ( minerPower / netPower )
|
|
|
|
// c == target probability of win ( 99.9% in this case )
|
2021-05-21 11:03:45 +00:00
|
|
|
fmt.Print("Projected block win with ")
|
|
|
|
color.Green(
|
|
|
|
"99.9%% probability every %s",
|
|
|
|
(time.Second * time.Duration(
|
|
|
|
builtin.EpochDurationSeconds*math.Log(1-0.999)/
|
|
|
|
math.Log(1-winRatioFloat),
|
|
|
|
)).Truncate(time.Second).String(),
|
|
|
|
)
|
|
|
|
fmt.Println("(projections DO NOT account for future network and miner growth)")
|
2020-08-04 18:57:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println()
|
|
|
|
|
2020-08-22 17:15:08 +00:00
|
|
|
deals, err := nodeApi.MarketListIncompleteDeals(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-07-08 17:02:18 +00:00
|
|
|
type dealStat struct {
|
|
|
|
count, verifCount int
|
2021-07-08 17:39:58 +00:00
|
|
|
bytes, verifBytes uint64
|
2021-07-08 17:02:18 +00:00
|
|
|
}
|
|
|
|
dsAdd := func(ds *dealStat, deal storagemarket.MinerDeal) {
|
|
|
|
ds.count++
|
2021-07-08 17:39:58 +00:00
|
|
|
ds.bytes += uint64(deal.Proposal.PieceSize)
|
2021-07-08 17:02:18 +00:00
|
|
|
if deal.Proposal.VerifiedDeal {
|
|
|
|
ds.verifCount++
|
2021-07-08 17:39:58 +00:00
|
|
|
ds.verifBytes += uint64(deal.Proposal.PieceSize)
|
2021-07-08 17:02:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
showDealStates := map[storagemarket.StorageDealStatus]struct{}{
|
2021-07-08 17:39:58 +00:00
|
|
|
storagemarket.StorageDealActive: {},
|
|
|
|
storagemarket.StorageDealTransferring: {},
|
|
|
|
storagemarket.StorageDealStaged: {},
|
|
|
|
storagemarket.StorageDealAwaitingPreCommit: {},
|
|
|
|
storagemarket.StorageDealSealing: {},
|
|
|
|
storagemarket.StorageDealPublish: {},
|
2021-07-08 17:02:18 +00:00
|
|
|
storagemarket.StorageDealCheckForAcceptance: {},
|
2021-07-08 17:39:58 +00:00
|
|
|
storagemarket.StorageDealPublishing: {},
|
2021-07-08 17:02:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var total dealStat
|
|
|
|
perState := map[storagemarket.StorageDealStatus]*dealStat{}
|
2020-08-22 17:15:08 +00:00
|
|
|
for _, deal := range deals {
|
2021-07-08 17:02:18 +00:00
|
|
|
if _, ok := showDealStates[deal.State]; !ok {
|
2020-12-01 18:15:20 +00:00
|
|
|
continue
|
|
|
|
}
|
2021-07-08 17:02:18 +00:00
|
|
|
if perState[deal.State] == nil {
|
|
|
|
perState[deal.State] = new(dealStat)
|
|
|
|
}
|
2020-12-01 18:15:20 +00:00
|
|
|
|
2021-07-08 17:02:18 +00:00
|
|
|
dsAdd(&total, deal)
|
|
|
|
dsAdd(perState[deal.State], deal)
|
|
|
|
}
|
2020-08-22 17:15:08 +00:00
|
|
|
|
2021-07-08 17:02:18 +00:00
|
|
|
type wstr struct {
|
|
|
|
str string
|
|
|
|
status storagemarket.StorageDealStatus
|
|
|
|
}
|
|
|
|
sorted := make([]wstr, 0, len(perState))
|
|
|
|
for status, stat := range perState {
|
|
|
|
st := strings.TrimPrefix(storagemarket.DealStates[status], "StorageDeal")
|
|
|
|
sorted = append(sorted, wstr{
|
2021-07-08 17:39:58 +00:00
|
|
|
str: fmt.Sprintf(" %s:\t%d\t\t%s\t(Verified: %d\t%s)\n", st, stat.count, types.SizeStr(types.NewInt(stat.bytes)), stat.verifCount, types.SizeStr(types.NewInt(stat.verifBytes))),
|
2021-07-08 17:02:18 +00:00
|
|
|
status: status,
|
|
|
|
},
|
|
|
|
)
|
2020-08-22 17:15:08 +00:00
|
|
|
}
|
2021-07-08 17:02:18 +00:00
|
|
|
sort.Slice(sorted, func(i, j int) bool {
|
|
|
|
if sorted[i].status == storagemarket.StorageDealActive || sorted[j].status == storagemarket.StorageDealActive {
|
|
|
|
return sorted[i].status == storagemarket.StorageDealActive
|
|
|
|
}
|
|
|
|
return sorted[i].status > sorted[j].status
|
|
|
|
})
|
2020-08-22 17:15:08 +00:00
|
|
|
|
2021-07-08 17:39:58 +00:00
|
|
|
fmt.Printf("Storage Deals: %d, %s\n", total.count, types.SizeStr(types.NewInt(total.bytes)))
|
|
|
|
|
2021-07-08 17:02:18 +00:00
|
|
|
tw := tabwriter.NewWriter(os.Stdout, 1, 1, 1, ' ', 0)
|
|
|
|
for _, e := range sorted {
|
|
|
|
_, _ = tw.Write([]byte(e.str))
|
|
|
|
}
|
2021-07-08 17:39:58 +00:00
|
|
|
|
2021-07-08 17:02:18 +00:00
|
|
|
_ = tw.Flush()
|
2020-08-22 17:15:08 +00:00
|
|
|
fmt.Println()
|
|
|
|
|
2021-07-08 17:39:58 +00:00
|
|
|
retrievals, err := nodeApi.MarketListRetrievalDeals(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting retrieval deal list: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var retrComplete dealStat
|
|
|
|
for _, retrieval := range retrievals {
|
|
|
|
if retrieval.Status == retrievalmarket.DealStatusCompleted {
|
|
|
|
retrComplete.count++
|
|
|
|
retrComplete.bytes += retrieval.TotalSent
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Retrieval Deals (complete): %d, %s\n", retrComplete.count, types.SizeStr(types.NewInt(retrComplete.bytes)))
|
|
|
|
|
|
|
|
fmt.Println()
|
|
|
|
|
2020-12-01 18:56:47 +00:00
|
|
|
spendable := big.Zero()
|
|
|
|
|
2020-09-18 21:46:42 +00:00
|
|
|
// NOTE: there's no need to unlock anything here. Funds only
|
|
|
|
// vest on deadline boundaries, and they're unlocked by cron.
|
|
|
|
lockedFunds, err := mas.LockedFunds()
|
2020-08-22 17:15:08 +00:00
|
|
|
if err != nil {
|
2020-09-18 21:46:42 +00:00
|
|
|
return xerrors.Errorf("getting locked funds: %w", err)
|
|
|
|
}
|
|
|
|
availBalance, err := mas.AvailableBalance(mact.Balance)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting available balance: %w", err)
|
2020-08-22 17:15:08 +00:00
|
|
|
}
|
2020-12-01 18:56:47 +00:00
|
|
|
spendable = big.Add(spendable, availBalance)
|
|
|
|
|
2020-12-01 18:43:22 +00:00
|
|
|
fmt.Printf("Miner Balance: %s\n", color.YellowString("%s", types.FIL(mact.Balance).Short()))
|
|
|
|
fmt.Printf(" PreCommit: %s\n", types.FIL(lockedFunds.PreCommitDeposits).Short())
|
|
|
|
fmt.Printf(" Pledge: %s\n", types.FIL(lockedFunds.InitialPledgeRequirement).Short())
|
|
|
|
fmt.Printf(" Vesting: %s\n", types.FIL(lockedFunds.VestingFunds).Short())
|
2021-01-14 08:39:39 +00:00
|
|
|
colorTokenAmount(" Available: %s\n", availBalance)
|
2020-08-04 18:57:40 +00:00
|
|
|
|
|
|
|
mb, err := api.StateMarketBalance(ctx, maddr, types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting market balance: %w", err)
|
|
|
|
}
|
2020-12-01 18:56:47 +00:00
|
|
|
spendable = big.Add(spendable, big.Sub(mb.Escrow, mb.Locked))
|
|
|
|
|
2020-12-01 18:43:22 +00:00
|
|
|
fmt.Printf("Market Balance: %s\n", types.FIL(mb.Escrow).Short())
|
|
|
|
fmt.Printf(" Locked: %s\n", types.FIL(mb.Locked).Short())
|
2021-01-14 08:39:39 +00:00
|
|
|
colorTokenAmount(" Available: %s\n", big.Sub(mb.Escrow, mb.Locked))
|
2020-12-01 18:22:57 +00:00
|
|
|
|
|
|
|
wb, err := api.WalletBalance(ctx, mi.Worker)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting worker balance: %w", err)
|
|
|
|
}
|
2020-12-01 18:56:47 +00:00
|
|
|
spendable = big.Add(spendable, wb)
|
2020-12-01 18:43:22 +00:00
|
|
|
color.Cyan("Worker Balance: %s", types.FIL(wb).Short())
|
2020-12-01 18:56:47 +00:00
|
|
|
if len(mi.ControlAddresses) > 0 {
|
|
|
|
cbsum := big.Zero()
|
|
|
|
for _, ca := range mi.ControlAddresses {
|
|
|
|
b, err := api.WalletBalance(ctx, ca)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting control address balance: %w", err)
|
|
|
|
}
|
|
|
|
cbsum = big.Add(cbsum, b)
|
|
|
|
}
|
|
|
|
spendable = big.Add(spendable, cbsum)
|
|
|
|
|
|
|
|
fmt.Printf(" Control: %s\n", types.FIL(cbsum).Short())
|
|
|
|
}
|
2021-01-14 08:39:39 +00:00
|
|
|
colorTokenAmount("Total Spendable: %s\n", spendable)
|
2020-08-04 18:57:40 +00:00
|
|
|
|
|
|
|
fmt.Println()
|
|
|
|
|
2020-09-28 19:34:06 +00:00
|
|
|
if !cctx.Bool("hide-sectors-info") {
|
|
|
|
fmt.Println("Sectors:")
|
|
|
|
err = sectorsInfo(ctx, nodeApi)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-04 18:57:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: grab actr state / info
|
|
|
|
// * Sealed sectors (count / bytes)
|
|
|
|
// * Power
|
|
|
|
return nil
|
2019-10-11 23:47:29 +00:00
|
|
|
}
|
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},
|
|
|
|
|
2020-08-27 10:41:12 +00:00
|
|
|
{col: color.FgBlue, state: sealing.Empty},
|
|
|
|
{col: color.FgBlue, state: sealing.WaitDeals},
|
2021-01-18 13:26:03 +00:00
|
|
|
{col: color.FgBlue, state: sealing.AddPiece},
|
2020-08-27 10:41:12 +00:00
|
|
|
|
2020-05-01 12:06:19 +00:00
|
|
|
{col: color.FgRed, state: sealing.UndefinedSectorState},
|
|
|
|
{col: color.FgYellow, state: sealing.Packing},
|
2020-11-26 09:53:31 +00:00
|
|
|
{col: color.FgYellow, state: sealing.GetTicket},
|
2020-05-01 12:06:19 +00:00
|
|
|
{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},
|
2021-05-18 15:21:10 +00:00
|
|
|
{col: color.FgYellow, state: sealing.SubmitPreCommitBatch},
|
|
|
|
{col: color.FgYellow, state: sealing.PreCommitBatchWait},
|
2020-05-01 12:06:19 +00:00
|
|
|
{col: color.FgYellow, state: sealing.WaitSeed},
|
|
|
|
{col: color.FgYellow, state: sealing.Committing},
|
2021-06-11 09:41:28 +00:00
|
|
|
{col: color.FgYellow, state: sealing.CommitFinalize},
|
2020-08-27 10:57:08 +00:00
|
|
|
{col: color.FgYellow, state: sealing.SubmitCommit},
|
2020-05-01 12:06:19 +00:00
|
|
|
{col: color.FgYellow, state: sealing.CommitWait},
|
2021-03-10 15:16:44 +00:00
|
|
|
{col: color.FgYellow, state: sealing.SubmitCommitAggregate},
|
|
|
|
{col: color.FgYellow, state: sealing.CommitAggregateWait},
|
2020-05-01 12:06:19 +00:00
|
|
|
{col: color.FgYellow, state: sealing.FinalizeSector},
|
|
|
|
|
2021-01-14 11:44:27 +00:00
|
|
|
{col: color.FgCyan, state: sealing.Terminating},
|
|
|
|
{col: color.FgCyan, state: sealing.TerminateWait},
|
|
|
|
{col: color.FgCyan, state: sealing.TerminateFinality},
|
|
|
|
{col: color.FgCyan, state: sealing.TerminateFailed},
|
2020-08-27 10:41:12 +00:00
|
|
|
{col: color.FgCyan, state: sealing.Removing},
|
|
|
|
{col: color.FgCyan, state: sealing.Removed},
|
|
|
|
|
2020-05-01 12:06:19 +00:00
|
|
|
{col: color.FgRed, state: sealing.FailedUnrecoverable},
|
2021-01-20 17:42:22 +00:00
|
|
|
{col: color.FgRed, state: sealing.AddPieceFailed},
|
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},
|
2021-06-11 09:41:28 +00:00
|
|
|
{col: color.FgRed, state: sealing.CommitFinalizeFailed},
|
2020-05-01 12:06:19 +00:00
|
|
|
{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},
|
2020-08-27 10:41:12 +00:00
|
|
|
{col: color.FgRed, state: sealing.RemoveFailed},
|
2020-08-27 11:51:13 +00:00
|
|
|
{col: color.FgRed, state: sealing.DealsExpired},
|
2020-08-27 20:41:35 +00:00
|
|
|
{col: color.FgRed, state: sealing.RecoverDealIDs},
|
2020-05-01 12:06:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2020-12-06 00:51:48 +00:00
|
|
|
summary, err := napi.SectorsSummary(ctx)
|
2019-10-14 02:32:32 +00:00
|
|
|
if err != nil {
|
2020-05-01 12:06:19 +00:00
|
|
|
return err
|
2019-10-14 02:32:32 +00:00
|
|
|
}
|
|
|
|
|
2020-12-06 00:51:48 +00:00
|
|
|
buckets := make(map[sealing.SectorState]int)
|
|
|
|
var total int
|
|
|
|
for s, c := range summary {
|
|
|
|
buckets[sealing.SectorState(s)] = c
|
|
|
|
total += c
|
2020-05-01 12:06:19 +00:00
|
|
|
}
|
2020-12-06 00:51:48 +00:00
|
|
|
buckets["Total"] = total
|
2020-05-01 12:06:19 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
2021-01-14 08:39:39 +00:00
|
|
|
|
|
|
|
func colorTokenAmount(format string, amount abi.TokenAmount) {
|
|
|
|
if amount.GreaterThan(big.Zero()) {
|
2021-01-15 03:48:07 +00:00
|
|
|
color.Green(format, types.FIL(amount).Short())
|
2021-01-14 08:39:39 +00:00
|
|
|
} else if amount.Equals(big.Zero()) {
|
2021-01-15 03:48:07 +00:00
|
|
|
color.Yellow(format, types.FIL(amount).Short())
|
2021-01-14 08:39:39 +00:00
|
|
|
} else {
|
2021-01-15 03:48:07 +00:00
|
|
|
color.Red(format, types.FIL(amount).Short())
|
2021-01-14 08:39:39 +00:00
|
|
|
}
|
|
|
|
}
|