lotus/cmd/lotus-storage-miner/info.go

152 lines
4.1 KiB
Go
Raw Normal View History

2019-10-11 23:47:29 +00:00
package main
import (
"context"
2019-10-11 23:47:29 +00:00
"fmt"
"gopkg.in/urfave/cli.v2"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/build"
"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",
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()
2019-10-11 23:47:29 +00:00
ctx := lcli.ReqContext(cctx)
maddr, err := nodeApi.ActorAddress(ctx)
if err != nil {
return err
}
fmt.Printf("Miner: %s\n", maddr)
2019-11-07 10:46:11 +00:00
// Sector size
sizeByte, err := api.StateMinerSectorSize(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
fmt.Printf("Sector Size: %s\n", types.NewInt(sizeByte).SizeStr())
2019-11-07 10:46:11 +00:00
pow, err := api.StateMinerPower(ctx, maddr, types.EmptyTSK)
if err != nil {
return err
}
percI := types.BigDiv(types.BigMul(pow.MinerPower, types.NewInt(1000000)), pow.TotalPower)
fmt.Printf("Power: %s / %s (%0.4f%%)\n", pow.MinerPower.SizeStr(), pow.TotalPower.SizeStr(), float64(percI.Int64())/10000)
secCounts, err := api.StateMinerSectorCount(ctx, maddr, types.EmptyTSK)
if err != nil {
return err
}
faults, err := api.StateMinerFaults(ctx, maddr, types.EmptyTSK)
2020-01-30 18:38:03 +00:00
if err != nil {
return err
}
fmt.Printf("\tCommitted: %s\n", types.BigMul(types.NewInt(secCounts.Sset), types.NewInt(sizeByte)).SizeStr())
2020-01-30 18:38:03 +00:00
if len(faults) == 0 {
fmt.Printf("\tProving: %s\n", types.BigMul(types.NewInt(secCounts.Pset), types.NewInt(sizeByte)).SizeStr())
} else {
fmt.Printf("\tProving: %s (%s Faulty, %.2f%%)\n",
2020-01-31 01:27:38 +00:00
types.BigMul(types.NewInt(secCounts.Pset-uint64(len(faults))), types.NewInt(sizeByte)).SizeStr(),
2020-01-30 18:38:03 +00:00
types.BigMul(types.NewInt(uint64(len(faults))), types.NewInt(sizeByte)).SizeStr(),
2020-01-31 01:27:38 +00:00
float64(10000*uint64(len(faults))/secCounts.Pset)/100.)
2020-01-30 18:38:03 +00:00
}
2019-11-08 18:15:13 +00:00
// TODO: indicate whether the post worker is in use
wstat, err := nodeApi.WorkerStats(ctx)
if err != nil {
return err
}
2019-11-21 16:23:42 +00:00
fmt.Printf("Worker use:\n")
2019-11-21 18:38:43 +00:00
fmt.Printf("\tLocal: %d / %d (+%d reserved)\n", wstat.LocalTotal-wstat.LocalReserved-wstat.LocalFree, wstat.LocalTotal-wstat.LocalReserved, wstat.LocalReserved)
fmt.Printf("\tRemote: %d / %d\n", wstat.RemotesTotal-wstat.RemotesFree, wstat.RemotesTotal)
2019-11-08 18:15:13 +00:00
fmt.Printf("Queues:\n")
fmt.Printf("\tAddPiece: %d\n", wstat.AddPieceWait)
fmt.Printf("\tPreCommit: %d\n", wstat.PreCommitWait)
fmt.Printf("\tCommit: %d\n", wstat.CommitWait)
fmt.Printf("\tUnseal: %d\n", wstat.UnsealWait)
eps, err := api.StateMinerElectionPeriodStart(ctx, maddr, types.EmptyTSK)
if err != nil {
return err
}
2019-12-02 16:47:09 +00:00
if eps != 0 {
head, err := api.ChainHead(ctx)
if err != nil {
return err
}
2019-12-02 16:47:09 +00:00
lastEps := int64(head.Height() - eps)
lastEpsS := lastEps * build.BlockDelay
2020-03-19 08:00:42 +00:00
fallback := build.FallbackPoStDelay - lastEps
fallbackS := fallback * build.BlockDelay
2020-03-19 08:00:42 +00:00
next := build.SlashablePowerDelay - lastEps
2019-12-02 16:47:09 +00:00
nextS := next * build.BlockDelay
fmt.Printf("PoSt Submissions:\n")
fmt.Printf("\tPrevious: Epoch %d (%d block(s), ~%dm %ds ago)\n", eps, lastEps, lastEpsS/60, lastEpsS%60)
fmt.Printf("\tFallback: Epoch %d (in %d blocks, ~%dm %ds)\n", eps+build.FallbackPoStDelay, fallback, fallbackS/60, fallbackS%60)
2019-12-02 16:47:09 +00:00
fmt.Printf("\tDeadline: Epoch %d (in %d blocks, ~%dm %ds)\n", eps+build.SlashablePowerDelay, next, nextS/60, nextS%60)
} else {
fmt.Printf("Proving Period: Not Proving\n")
}
sinfo, err := sectorsInfo(ctx, nodeApi)
2019-10-11 23:47:29 +00:00
if err != nil {
return err
}
fmt.Println("Sectors: ", sinfo)
2019-10-11 23:47:29 +00:00
// TODO: grab actr state / info
// * Sealed sectors (count / bytes)
// * Power
return nil
},
}
func sectorsInfo(ctx context.Context, napi api.StorageMiner) (map[string]int, error) {
sectors, err := napi.SectorsList(ctx)
if err != nil {
return nil, err
}
out := map[string]int{
"Total": len(sectors),
}
for _, s := range sectors {
st, err := napi.SectorsStatus(ctx, s)
if err != nil {
return nil, err
}
out[api.SectorStates[st.State]]++
}
return out, nil
}