Skip to content

Commit

Permalink
Merge pull request #7246 from filecoin-project/feat/sectorinfo-partition
Browse files Browse the repository at this point in the history
Add partition info to the 'sectors status' command
  • Loading branch information
magik6k authored Sep 2, 2021
2 parents 4659b92 + fea430a commit 3c2d854
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 8 deletions.
111 changes: 106 additions & 5 deletions cmd/lotus-miner/sectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bufio"
"encoding/json"
"errors"
"fmt"
"os"
"sort"
Expand Down Expand Up @@ -85,12 +86,23 @@ var sectorsStatusCmd = &cli.Command{
ArgsUsage: "<sectorNum>",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "log",
Usage: "display event log",
Name: "log",
Usage: "display event log",
Aliases: []string{"l"},
},
&cli.BoolFlag{
Name: "on-chain-info",
Usage: "show sector on chain info",
Name: "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 {
Expand Down Expand Up @@ -126,7 +138,9 @@ var sectorsStatusCmd = &cli.Command{
fmt.Printf("SeedH:\t\t%d\n", status.Seed.Epoch)
fmt.Printf("Precommit:\t%s\n", status.PreCommitMsg)
fmt.Printf("Commit:\t\t%s\n", status.CommitMsg)
fmt.Printf("Proof:\t\t%x\n", status.Proof)
if cctx.Bool("proof") {
fmt.Printf("Proof:\t\t%x\n", status.Proof)
}
fmt.Printf("Deals:\t\t%v\n", status.Deals)
fmt.Printf("Retries:\t%d\n", status.Retries)
if status.LastErr != "" {
Expand All @@ -146,6 +160,93 @@ var sectorsStatusCmd = &cli.Command{
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") {
fmt.Printf("--------\nEvent Log:\n")

Expand Down
8 changes: 5 additions & 3 deletions documentation/en/cli-lotus-miner.md
Original file line number Diff line number Diff line change
Expand Up @@ -1515,9 +1515,11 @@ USAGE:
lotus-miner sectors status [command options] <sectorNum>
OPTIONS:
--log display event log (default: false)
--on-chain-info show sector on chain info (default: false)
--help, -h show help (default: false)
--log, -l display event log (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)
```

Expand Down

0 comments on commit 3c2d854

Please sign in to comment.