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"
|
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"
|
2022-06-14 15:00:51 +00:00
|
|
|
cbor "github.com/ipfs/go-ipld-cbor"
|
2021-08-27 11:36:40 +00:00
|
|
|
"github.com/mattn/go-isatty"
|
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
|
|
|
|
2021-01-05 09:53:27 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
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"
|
2021-01-05 09:53:27 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/builtin"
|
2020-04-24 17:35:41 +00:00
|
|
|
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
2022-09-09 11:42:34 +00:00
|
|
|
"github.com/filecoin-project/lotus/api/v1api"
|
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"
|
|
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
|
2021-01-05 09:53:27 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/actors/builtin/reward"
|
2019-10-18 04:47:41 +00:00
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
lcli "github.com/filecoin-project/lotus/cli"
|
2024-04-01 15:30:35 +00:00
|
|
|
"github.com/filecoin-project/lotus/cli/spcli"
|
2022-10-31 12:32:00 +00:00
|
|
|
cliutil "github.com/filecoin-project/lotus/cli/util"
|
2021-08-17 13:29:38 +00:00
|
|
|
"github.com/filecoin-project/lotus/journal/alerting"
|
2022-06-14 17:41:59 +00:00
|
|
|
sealing "github.com/filecoin-project/lotus/storage/pipeline"
|
2022-06-14 18:03:38 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/sealer/sealtasks"
|
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",
|
|
|
|
},
|
2021-01-05 09:53:27 +00:00
|
|
|
&cli.IntFlag{
|
|
|
|
Name: "blocks",
|
|
|
|
Usage: "Log of produced <blocks> newest blocks and rewards(Miner Fee excluded)",
|
|
|
|
},
|
2020-09-28 19:34:06 +00:00
|
|
|
},
|
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 {
|
2021-07-29 11:51:26 +00:00
|
|
|
minerApi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer()
|
|
|
|
|
2022-09-09 11:42:34 +00:00
|
|
|
fullapi, acloser, err := lcli.GetFullNodeAPIV1(cctx)
|
2020-08-04 18:57:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer acloser()
|
|
|
|
|
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
|
2021-07-29 11:51:26 +00:00
|
|
|
subsystems, err := minerApi.RuntimeSubsystems(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-02-28 08:55:47 +00:00
|
|
|
fmt.Println("Enabled subsystems:", subsystems)
|
2021-07-28 09:10:17 +00:00
|
|
|
|
2022-12-09 09:23:49 +00:00
|
|
|
start, err := minerApi.StartTime(ctx)
|
2022-10-05 19:44:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Printf("StartTime: %s (started at %s)\n", time.Now().Sub(start).Truncate(time.Second), start.Truncate(time.Second))
|
|
|
|
|
2020-12-01 17:56:43 +00:00
|
|
|
fmt.Print("Chain: ")
|
2020-10-30 18:39:31 +00:00
|
|
|
|
2022-09-09 11:42:34 +00:00
|
|
|
err = lcli.SyncBasefeeCheck(ctx, fullapi)
|
2020-10-30 18:39:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println()
|
|
|
|
|
2021-08-17 13:29:38 +00:00
|
|
|
alerts, err := minerApi.LogAlerts(ctx)
|
|
|
|
if err != nil {
|
2022-02-10 11:45:57 +00:00
|
|
|
fmt.Printf("ERROR: getting alerts: %s\n", err)
|
2021-08-17 13:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
activeAlerts := make([]alerting.Alert, 0)
|
|
|
|
for _, alert := range alerts {
|
|
|
|
if alert.Active {
|
|
|
|
activeAlerts = append(activeAlerts, alert)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(activeAlerts) > 0 {
|
|
|
|
fmt.Printf("%s (check %s)\n", color.RedString("⚠ %d Active alerts", len(activeAlerts)), color.YellowString("lotus-miner log alerts"))
|
|
|
|
}
|
|
|
|
|
2021-07-29 11:51:26 +00:00
|
|
|
err = handleMiningInfo(ctx, cctx, fullapi, minerApi)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-07-28 14:30:59 +00:00
|
|
|
}
|
2020-08-04 18:57:40 +00:00
|
|
|
|
2021-07-28 14:30:59 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-08-04 18:57:40 +00:00
|
|
|
|
2022-09-09 11:42:34 +00:00
|
|
|
func handleMiningInfo(ctx context.Context, cctx *cli.Context, fullapi v1api.FullNode, nodeApi api.StorageMiner) error {
|
2021-07-28 14:30:59 +00:00
|
|
|
maddr, err := getActorAddress(ctx, cctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-04 18:57:40 +00:00
|
|
|
|
2021-07-28 14:30:59 +00:00
|
|
|
mact, err := fullapi.StateGetActor(ctx, maddr, types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-04 18:57:40 +00:00
|
|
|
|
2021-07-28 14:30:59 +00:00
|
|
|
tbs := blockstore.NewTieredBstore(blockstore.NewAPIBlockstore(fullapi), blockstore.NewMemory())
|
2021-01-05 09:53:27 +00:00
|
|
|
|
2021-07-28 14:30:59 +00:00
|
|
|
mas, err := miner.Load(adt.WrapStore(ctx, cbor.NewCborStore(tbs)), mact)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-05-21 11:03:45 +00:00
|
|
|
|
2021-07-28 14:30:59 +00:00
|
|
|
// Sector size
|
|
|
|
mi, err := fullapi.StateMinerInfo(ctx, maddr, types.EmptyTSK)
|
2021-01-05 09:53:27 +00:00
|
|
|
|
2021-07-28 14:30:59 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-05-21 11:03:45 +00:00
|
|
|
|
2021-07-28 14:30:59 +00:00
|
|
|
ssize := types.SizeStr(types.NewInt(uint64(mi.SectorSize)))
|
|
|
|
fmt.Printf("Miner: %s (%s sectors)\n", color.BlueString("%s", maddr), ssize)
|
2021-05-21 11:03:45 +00:00
|
|
|
|
2021-07-28 14:30:59 +00:00
|
|
|
pow, err := fullapi.StateMinerPower(ctx, maddr, types.EmptyTSK)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Power: %s / %s (%0.4f%%)\n",
|
|
|
|
color.GreenString(types.DeciStr(pow.MinerPower.QualityAdjPower)),
|
|
|
|
types.DeciStr(pow.TotalPower.QualityAdjPower),
|
|
|
|
types.BigDivFloat(
|
|
|
|
types.BigMul(pow.MinerPower.QualityAdjPower, big.NewInt(100)),
|
|
|
|
pow.TotalPower.QualityAdjPower,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
fmt.Printf("\tRaw: %s / %s (%0.4f%%)\n",
|
|
|
|
color.BlueString(types.SizeStr(pow.MinerPower.RawBytePower)),
|
|
|
|
types.SizeStr(pow.TotalPower.RawBytePower),
|
|
|
|
types.BigDivFloat(
|
|
|
|
types.BigMul(pow.MinerPower.RawBytePower, big.NewInt(100)),
|
|
|
|
pow.TotalPower.RawBytePower,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
secCounts, err := fullapi.StateMinerSectorCount(ctx, maddr, types.EmptyTSK)
|
2021-01-05 09:53:27 +00:00
|
|
|
|
2021-07-28 14:30:59 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
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)))))
|
|
|
|
if nfaults == 0 {
|
|
|
|
fmt.Printf("\tProving: %s\n", types.SizeStr(types.BigMul(types.NewInt(proving), types.NewInt(uint64(mi.SectorSize)))))
|
|
|
|
} else {
|
|
|
|
var faultyPercentage float64
|
|
|
|
if secCounts.Live != 0 {
|
|
|
|
faultyPercentage = float64(100*nfaults) / float64(secCounts.Live)
|
2021-07-28 09:10:17 +00:00
|
|
|
}
|
2021-07-28 14:30:59 +00:00
|
|
|
fmt.Printf("\tProving: %s (%s Faulty, %.2f%%)\n",
|
|
|
|
types.SizeStr(types.BigMul(types.NewInt(proving), types.NewInt(uint64(mi.SectorSize)))),
|
|
|
|
types.SizeStr(types.BigMul(types.NewInt(nfaults), types.NewInt(uint64(mi.SectorSize)))),
|
|
|
|
faultyPercentage)
|
|
|
|
}
|
2020-08-04 18:57:40 +00:00
|
|
|
|
2021-07-28 14:30:59 +00:00
|
|
|
if !pow.HasMinPower {
|
|
|
|
fmt.Print("Below minimum power threshold, no blocks will be won")
|
|
|
|
} else {
|
2021-05-21 11:03:45 +00:00
|
|
|
|
2021-07-28 14:30:59 +00:00
|
|
|
winRatio := new(corebig.Rat).SetFrac(
|
|
|
|
types.BigMul(pow.MinerPower.QualityAdjPower, types.NewInt(build.BlocksPerEpoch)).Int,
|
|
|
|
pow.TotalPower.QualityAdjPower.Int,
|
|
|
|
)
|
2021-07-28 09:10:17 +00:00
|
|
|
|
2021-07-28 14:30:59 +00:00
|
|
|
if winRatioFloat, _ := winRatio.Float64(); winRatioFloat > 0 {
|
2020-08-04 18:57:40 +00:00
|
|
|
|
2021-07-28 14:30:59 +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-08-04 18:57:40 +00:00
|
|
|
|
2021-07-28 14:30:59 +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(),
|
|
|
|
)
|
2020-08-22 17:15:08 +00:00
|
|
|
|
2021-07-28 14:30:59 +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 )
|
|
|
|
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)")
|
2021-07-28 09:10:17 +00:00
|
|
|
}
|
2021-07-28 14:30:59 +00:00
|
|
|
}
|
2021-07-08 17:02:18 +00:00
|
|
|
|
2021-07-28 14:30:59 +00:00
|
|
|
fmt.Println()
|
2021-07-08 17:02:18 +00:00
|
|
|
|
2021-07-28 14:30:59 +00:00
|
|
|
spendable := big.Zero()
|
2020-12-01 18:15:20 +00:00
|
|
|
|
2021-07-28 14:30:59 +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()
|
|
|
|
if err != nil {
|
|
|
|
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)
|
|
|
|
}
|
2022-08-18 13:31:14 +00:00
|
|
|
|
|
|
|
if availBalance.GreaterThan(big.Zero()) {
|
|
|
|
spendable = big.Add(spendable, availBalance)
|
|
|
|
}
|
2020-08-22 17:15:08 +00:00
|
|
|
|
2021-07-28 14:30:59 +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())
|
|
|
|
colorTokenAmount(" Available: %s\n", availBalance)
|
2020-08-22 17:15:08 +00:00
|
|
|
|
2021-07-28 14:30:59 +00:00
|
|
|
mb, err := fullapi.StateMarketBalance(ctx, maddr, types.EmptyTSK)
|
2021-01-05 09:53:27 +00:00
|
|
|
|
2021-07-28 14:30:59 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting market balance: %w", err)
|
|
|
|
}
|
|
|
|
spendable = big.Add(spendable, big.Sub(mb.Escrow, mb.Locked))
|
2021-07-08 17:39:58 +00:00
|
|
|
|
2021-07-28 14:30:59 +00:00
|
|
|
fmt.Printf("Market Balance: %s\n", types.FIL(mb.Escrow).Short())
|
|
|
|
fmt.Printf(" Locked: %s\n", types.FIL(mb.Locked).Short())
|
|
|
|
colorTokenAmount(" Available: %s\n", big.Sub(mb.Escrow, mb.Locked))
|
2021-07-08 17:39:58 +00:00
|
|
|
|
2021-07-28 14:30:59 +00:00
|
|
|
wb, err := fullapi.WalletBalance(ctx, mi.Worker)
|
2021-01-05 09:53:27 +00:00
|
|
|
|
2021-07-28 14:30:59 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting worker balance: %w", err)
|
|
|
|
}
|
|
|
|
spendable = big.Add(spendable, wb)
|
|
|
|
color.Cyan("Worker Balance: %s", types.FIL(wb).Short())
|
|
|
|
if len(mi.ControlAddresses) > 0 {
|
|
|
|
cbsum := big.Zero()
|
|
|
|
for _, ca := range mi.ControlAddresses {
|
|
|
|
b, err := fullapi.WalletBalance(ctx, ca)
|
2021-07-28 09:10:17 +00:00
|
|
|
if err != nil {
|
2021-07-28 14:30:59 +00:00
|
|
|
return xerrors.Errorf("getting control address balance: %w", err)
|
2021-07-28 09:10:17 +00:00
|
|
|
}
|
2021-07-28 14:30:59 +00:00
|
|
|
cbsum = big.Add(cbsum, b)
|
2021-07-28 09:10:17 +00:00
|
|
|
}
|
2021-07-28 14:30:59 +00:00
|
|
|
spendable = big.Add(spendable, cbsum)
|
2020-08-22 17:15:08 +00:00
|
|
|
|
2021-07-28 14:30:59 +00:00
|
|
|
fmt.Printf(" Control: %s\n", types.FIL(cbsum).Short())
|
2021-07-08 17:39:58 +00:00
|
|
|
}
|
2021-07-28 14:30:59 +00:00
|
|
|
colorTokenAmount("Total Spendable: %s\n", spendable)
|
2021-07-08 17:39:58 +00:00
|
|
|
|
2022-09-14 05:04:15 +00:00
|
|
|
if mi.Beneficiary != address.Undef {
|
|
|
|
fmt.Println()
|
|
|
|
fmt.Printf("Beneficiary:\t%s\n", mi.Beneficiary)
|
|
|
|
if mi.Beneficiary != mi.Owner {
|
|
|
|
fmt.Printf("Beneficiary Quota:\t%s\n", mi.BeneficiaryTerm.Quota)
|
|
|
|
fmt.Printf("Beneficiary Used Quota:\t%s\n", mi.BeneficiaryTerm.UsedQuota)
|
|
|
|
fmt.Printf("Beneficiary Expiration:\t%s\n", mi.BeneficiaryTerm.Expiration)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if mi.PendingBeneficiaryTerm != nil {
|
|
|
|
fmt.Printf("Pending Beneficiary Term:\n")
|
|
|
|
fmt.Printf("New Beneficiary:\t%s\n", mi.PendingBeneficiaryTerm.NewBeneficiary)
|
|
|
|
fmt.Printf("New Quota:\t%s\n", mi.PendingBeneficiaryTerm.NewQuota)
|
|
|
|
fmt.Printf("New Expiration:\t%s\n", mi.PendingBeneficiaryTerm.NewExpiration)
|
|
|
|
fmt.Printf("Approved By Beneficiary:\t%t\n", mi.PendingBeneficiaryTerm.ApprovedByBeneficiary)
|
|
|
|
fmt.Printf("Approved By Nominee:\t%t\n", mi.PendingBeneficiaryTerm.ApprovedByNominee)
|
|
|
|
}
|
2021-07-28 14:30:59 +00:00
|
|
|
fmt.Println()
|
|
|
|
|
|
|
|
if !cctx.Bool("hide-sectors-info") {
|
|
|
|
fmt.Println("Sectors:")
|
|
|
|
err = sectorsInfo(ctx, nodeApi)
|
2021-07-28 09:10:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2021-07-08 17:39:58 +00:00
|
|
|
}
|
2021-07-28 14:30:59 +00:00
|
|
|
}
|
2021-07-08 17:39:58 +00:00
|
|
|
|
2023-02-21 10:10:38 +00:00
|
|
|
fmt.Println()
|
2022-03-18 20:31:15 +00:00
|
|
|
|
2023-02-21 10:10:38 +00:00
|
|
|
ws, err := nodeApi.WorkerStats(ctx)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("ERROR: getting worker stats: %s\n", err)
|
|
|
|
} else {
|
2022-03-24 22:28:45 +00:00
|
|
|
workersByType := map[string]int{
|
|
|
|
sealtasks.WorkerSealing: 0,
|
|
|
|
sealtasks.WorkerWindowPoSt: 0,
|
|
|
|
sealtasks.WorkerWinningPoSt: 0,
|
|
|
|
}
|
2022-03-18 20:31:15 +00:00
|
|
|
|
|
|
|
wloop:
|
|
|
|
for _, st := range ws {
|
|
|
|
if !st.Enabled {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, task := range st.Tasks {
|
2022-03-24 22:28:45 +00:00
|
|
|
if task.WorkerType() != sealtasks.WorkerSealing {
|
|
|
|
workersByType[task.WorkerType()]++
|
2022-03-18 20:31:15 +00:00
|
|
|
continue wloop
|
|
|
|
}
|
|
|
|
}
|
2022-03-24 22:28:45 +00:00
|
|
|
workersByType[sealtasks.WorkerSealing]++
|
2022-03-18 20:31:15 +00:00
|
|
|
}
|
|
|
|
|
2022-03-24 22:28:45 +00:00
|
|
|
fmt.Printf("Workers: Seal(%d) WdPoSt(%d) WinPoSt(%d)\n",
|
|
|
|
workersByType[sealtasks.WorkerSealing],
|
|
|
|
workersByType[sealtasks.WorkerWindowPoSt],
|
|
|
|
workersByType[sealtasks.WorkerWinningPoSt])
|
2022-03-18 20:31:15 +00:00
|
|
|
}
|
|
|
|
|
2021-01-05 09:53:27 +00:00
|
|
|
if cctx.IsSet("blocks") {
|
|
|
|
fmt.Println("Produced newest blocks:")
|
2021-08-04 07:49:35 +00:00
|
|
|
err = producedBlocks(ctx, cctx.Int("blocks"), maddr, fullapi)
|
2021-01-05 09:53:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2021-07-08 17:39:58 +00:00
|
|
|
|
2021-07-28 14:30:59 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-12-01 18:56:47 +00:00
|
|
|
|
2021-01-05 09:53:27 +00:00
|
|
|
func sectorsInfo(ctx context.Context, mapi api.StorageMiner) error {
|
|
|
|
summary, err := mapi.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
|
|
|
|
2024-04-01 15:30:35 +00:00
|
|
|
var sorted []spcli.StateMeta
|
2020-05-01 12:06:19 +00:00
|
|
|
for state, i := range buckets {
|
2024-04-01 15:30:35 +00:00
|
|
|
sorted = append(sorted, spcli.StateMeta{I: i, State: state})
|
2020-05-01 12:06:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(sorted, func(i, j int) bool {
|
2024-04-01 15:30:35 +00:00
|
|
|
return spcli.StateOrder[sorted[i].State].I < spcli.StateOrder[sorted[j].State].I
|
2020-05-01 12:06:19 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
for _, s := range sorted {
|
2024-04-01 15:30:35 +00:00
|
|
|
_, _ = color.New(spcli.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
|
|
|
}
|
|
|
|
}
|
2021-01-05 09:53:27 +00:00
|
|
|
|
2022-09-09 11:42:34 +00:00
|
|
|
func producedBlocks(ctx context.Context, count int, maddr address.Address, napi v1api.FullNode) error {
|
2021-01-05 09:53:27 +00:00
|
|
|
var err error
|
2021-08-04 07:49:35 +00:00
|
|
|
head, err := napi.ChainHead(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-08-27 11:20:05 +00:00
|
|
|
|
|
|
|
tbs := blockstore.NewTieredBstore(blockstore.NewAPIBlockstore(napi), blockstore.NewMemory())
|
|
|
|
|
2021-08-27 11:36:40 +00:00
|
|
|
tty := isatty.IsTerminal(os.Stderr.Fd())
|
|
|
|
|
2021-01-05 09:53:27 +00:00
|
|
|
ts := head
|
|
|
|
fmt.Printf(" Epoch | Block ID | Reward\n")
|
|
|
|
for count > 0 {
|
|
|
|
tsk := ts.Key()
|
|
|
|
bhs := ts.Blocks()
|
|
|
|
for _, bh := range bhs {
|
2021-08-27 11:36:40 +00:00
|
|
|
if ctx.Err() != nil {
|
|
|
|
return ctx.Err()
|
|
|
|
}
|
|
|
|
|
2021-01-05 09:53:27 +00:00
|
|
|
if bh.Miner == maddr {
|
2021-08-27 11:36:40 +00:00
|
|
|
if tty {
|
|
|
|
_, _ = fmt.Fprint(os.Stderr, "\r\x1b[0K")
|
|
|
|
}
|
|
|
|
|
2021-01-05 09:53:27 +00:00
|
|
|
rewardActor, err := napi.StateGetActor(ctx, reward.Address, tsk)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-08-27 11:20:05 +00:00
|
|
|
rewardActorState, err := reward.Load(adt.WrapStore(ctx, cbor.NewCborStore(tbs)), rewardActor)
|
2021-01-05 09:53:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
blockReward, err := rewardActorState.ThisEpochReward()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-08-27 11:36:40 +00:00
|
|
|
|
|
|
|
minerReward := types.BigDiv(types.BigMul(types.NewInt(uint64(bh.ElectionProof.WinCount)),
|
|
|
|
blockReward), types.NewInt(uint64(builtin.ExpectedLeadersPerEpoch)))
|
|
|
|
|
|
|
|
fmt.Printf("%8d | %s | %s\n", ts.Height(), bh.Cid(), types.FIL(minerReward))
|
2021-01-05 09:53:27 +00:00
|
|
|
count--
|
2021-08-27 11:36:40 +00:00
|
|
|
} else if tty && bh.Height%120 == 0 {
|
2022-10-31 12:32:00 +00:00
|
|
|
_, _ = fmt.Fprintf(os.Stderr, "\r\x1b[0KChecking epoch %s", cliutil.EpochTime(head.Height(), bh.Height))
|
2021-01-05 09:53:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
tsk = ts.Parents()
|
|
|
|
ts, err = napi.ChainGetTipSet(ctx, tsk)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2021-08-27 11:36:40 +00:00
|
|
|
|
|
|
|
if tty {
|
|
|
|
_, _ = fmt.Fprint(os.Stderr, "\r\x1b[0K")
|
|
|
|
}
|
|
|
|
|
2021-01-05 09:53:27 +00:00
|
|
|
return nil
|
|
|
|
}
|