2019-07-27 21:08:10 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"gopkg.in/urfave/cli.v2"
|
|
|
|
|
2019-10-18 04:47:41 +00:00
|
|
|
lcli "github.com/filecoin-project/lotus/cli"
|
2019-07-27 21:08:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var storeGarbageCmd = &cli.Command{
|
|
|
|
Name: "store-garbage",
|
|
|
|
Usage: "store random data in a sector",
|
|
|
|
Action: func(cctx *cli.Context) error {
|
2019-10-03 18:12:30 +00:00
|
|
|
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
2019-07-27 21:08:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-10-03 18:12:30 +00:00
|
|
|
defer closer()
|
2019-07-27 21:08:10 +00:00
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
|
2019-10-29 17:52:07 +00:00
|
|
|
return nodeApi.StoreGarbageData(ctx)
|
2019-07-27 21:08:10 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var sectorsCmd = &cli.Command{
|
|
|
|
Name: "sectors",
|
|
|
|
Usage: "interact with sector store",
|
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
sectorsStatusCmd,
|
|
|
|
sectorsStagedListCmd,
|
2019-08-26 10:04:57 +00:00
|
|
|
sectorsRefsCmd,
|
2019-07-27 21:08:10 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var sectorsStatusCmd = &cli.Command{
|
|
|
|
Name: "status",
|
|
|
|
Usage: "Get the seal status of a sector by its ID",
|
|
|
|
Action: func(cctx *cli.Context) error {
|
2019-10-03 18:12:30 +00:00
|
|
|
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
2019-07-27 21:08:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-10-03 18:12:30 +00:00
|
|
|
defer closer()
|
2019-07-27 21:08:10 +00:00
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
|
|
|
|
if !cctx.Args().Present() {
|
|
|
|
return fmt.Errorf("must specify sector ID to get status of")
|
|
|
|
}
|
|
|
|
|
|
|
|
id, err := strconv.ParseUint(cctx.Args().First(), 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
status, err := nodeApi.SectorsStatus(ctx, id)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("SectorID:\t%d\n", status.SectorID)
|
2019-09-23 10:50:28 +00:00
|
|
|
fmt.Printf("Status:\t%s\n", status.State.String())
|
2019-07-27 21:08:10 +00:00
|
|
|
fmt.Printf("SealErrorMsg:\t%q\n", status.SealErrorMsg)
|
|
|
|
fmt.Printf("CommD:\t\t%x\n", status.CommD)
|
|
|
|
fmt.Printf("CommR:\t\t%x\n", status.CommR)
|
2019-10-21 11:58:41 +00:00
|
|
|
fmt.Printf("Ticket:\t\t%x\n", status.Ticket.TicketBytes)
|
|
|
|
fmt.Printf("TicketH:\t\t%d\n", status.Ticket.BlockHeight)
|
2019-07-27 21:08:10 +00:00
|
|
|
fmt.Printf("Proof:\t\t%x\n", status.Proof)
|
2019-07-27 21:19:12 +00:00
|
|
|
fmt.Printf("Pieces:\t\t%v\n", status.Pieces)
|
2019-07-27 21:08:10 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var sectorsStagedListCmd = &cli.Command{
|
|
|
|
Name: "list-staged", // TODO: nest this under a 'staged' subcommand? idk
|
|
|
|
Usage: "List staged sectors",
|
|
|
|
Action: func(cctx *cli.Context) error {
|
2019-10-03 18:12:30 +00:00
|
|
|
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
2019-07-27 21:08:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-10-03 18:12:30 +00:00
|
|
|
defer closer()
|
2019-07-27 21:08:10 +00:00
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
|
2019-10-14 02:32:32 +00:00
|
|
|
staged, err := nodeApi.SectorsList(ctx)
|
2019-07-27 21:08:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, s := range staged {
|
|
|
|
fmt.Println(s)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-08-26 10:04:57 +00:00
|
|
|
var sectorsRefsCmd = &cli.Command{
|
|
|
|
Name: "refs",
|
|
|
|
Usage: "List References to sectors",
|
|
|
|
Action: func(cctx *cli.Context) error {
|
2019-10-03 18:12:30 +00:00
|
|
|
nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx)
|
2019-08-26 10:04:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-10-03 18:12:30 +00:00
|
|
|
defer closer()
|
2019-08-26 10:04:57 +00:00
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
|
|
|
|
refs, err := nodeApi.SectorsRefs(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, refs := range refs {
|
|
|
|
fmt.Printf("Block %s:\n", name)
|
|
|
|
for _, ref := range refs {
|
|
|
|
fmt.Printf("\t%s+%d %d bytes\n", ref.Piece, ref.Offset, ref.Size)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|