Add partition info to the 'sectors status' command

This commit is contained in:
Łukasz Magiera 2021-09-01 11:59:47 +02:00
parent 6a02237f6f
commit fea430a553
2 changed files with 111 additions and 8 deletions

View File

@ -3,6 +3,7 @@ package main
import ( import (
"bufio" "bufio"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"os" "os"
"sort" "sort"
@ -87,10 +88,21 @@ var sectorsStatusCmd = &cli.Command{
&cli.BoolFlag{ &cli.BoolFlag{
Name: "log", Name: "log",
Usage: "display event log", Usage: "display event log",
Aliases: []string{"l"},
}, },
&cli.BoolFlag{ &cli.BoolFlag{
Name: "on-chain-info", Name: "on-chain-info",
Usage: "show sector on chain info", Usage: "show sector on chain info",
Aliases: []string{"c"},
},
&cli.BoolFlag{
Name: "partition-info",
Usage: "show partition related info",
Aliases: []string{"p"},
},
&cli.BoolFlag{
Name: "proof",
Usage: "print snark proof bytes as hex",
}, },
}, },
Action: func(cctx *cli.Context) error { Action: func(cctx *cli.Context) error {
@ -126,7 +138,9 @@ var sectorsStatusCmd = &cli.Command{
fmt.Printf("SeedH:\t\t%d\n", status.Seed.Epoch) fmt.Printf("SeedH:\t\t%d\n", status.Seed.Epoch)
fmt.Printf("Precommit:\t%s\n", status.PreCommitMsg) fmt.Printf("Precommit:\t%s\n", status.PreCommitMsg)
fmt.Printf("Commit:\t\t%s\n", status.CommitMsg) fmt.Printf("Commit:\t\t%s\n", status.CommitMsg)
if cctx.Bool("proof") {
fmt.Printf("Proof:\t\t%x\n", status.Proof) fmt.Printf("Proof:\t\t%x\n", status.Proof)
}
fmt.Printf("Deals:\t\t%v\n", status.Deals) fmt.Printf("Deals:\t\t%v\n", status.Deals)
fmt.Printf("Retries:\t%d\n", status.Retries) fmt.Printf("Retries:\t%d\n", status.Retries)
if status.LastErr != "" { if status.LastErr != "" {
@ -146,6 +160,93 @@ var sectorsStatusCmd = &cli.Command{
fmt.Printf("Early:\t\t%v\n", status.Early) fmt.Printf("Early:\t\t%v\n", status.Early)
} }
if cctx.Bool("partition-info") {
fullApi, nCloser, err := lcli.GetFullNodeAPI(cctx)
if err != nil {
return err
}
defer nCloser()
maddr, err := getActorAddress(ctx, cctx)
if err != nil {
return err
}
mact, err := fullApi.StateGetActor(ctx, maddr, types.EmptyTSK)
if err != nil {
return err
}
tbs := blockstore.NewTieredBstore(blockstore.NewAPIBlockstore(fullApi), blockstore.NewMemory())
mas, err := miner.Load(adt.WrapStore(ctx, cbor.NewCborStore(tbs)), mact)
if err != nil {
return err
}
errFound := errors.New("found")
if err := mas.ForEachDeadline(func(dlIdx uint64, dl miner.Deadline) error {
return dl.ForEachPartition(func(partIdx uint64, part miner.Partition) error {
pas, err := part.AllSectors()
if err != nil {
return err
}
set, err := pas.IsSet(id)
if err != nil {
return err
}
if set {
fmt.Printf("\nDeadline:\t%d\n", dlIdx)
fmt.Printf("Partition:\t%d\n", partIdx)
checkIn := func(name string, bg func() (bitfield.BitField, error)) error {
bf, err := bg()
if err != nil {
return err
}
set, err := bf.IsSet(id)
if err != nil {
return err
}
setstr := "no"
if set {
setstr = "yes"
}
fmt.Printf("%s: \t%s\n", name, setstr)
return nil
}
if err := checkIn("Unproven", part.UnprovenSectors); err != nil {
return err
}
if err := checkIn("Live", part.LiveSectors); err != nil {
return err
}
if err := checkIn("Active", part.ActiveSectors); err != nil {
return err
}
if err := checkIn("Faulty", part.FaultySectors); err != nil {
return err
}
if err := checkIn("Recovering", part.RecoveringSectors); err != nil {
return err
}
return errFound
}
return nil
})
}); err != errFound {
if err != nil {
return err
}
fmt.Println("\nNot found in any partition")
}
}
if cctx.Bool("log") { if cctx.Bool("log") {
fmt.Printf("--------\nEvent Log:\n") fmt.Printf("--------\nEvent Log:\n")

View File

@ -1515,8 +1515,10 @@ USAGE:
lotus-miner sectors status [command options] <sectorNum> lotus-miner sectors status [command options] <sectorNum>
OPTIONS: OPTIONS:
--log display event log (default: false) --log, -l display event log (default: false)
--on-chain-info show sector on chain info (default: false) --on-chain-info, -c show sector on chain info (default: false)
--partition-info, -p show partition related info (default: false)
--proof print snark proof bytes as hex (default: false)
--help, -h show help (default: false) --help, -h show help (default: false)
``` ```