2019-07-27 21:08:10 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"gopkg.in/urfave/cli.v2"
|
|
|
|
|
2019-11-08 20:11:56 +00:00
|
|
|
"github.com/filecoin-project/lotus/api"
|
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,
|
2019-11-13 14:48:57 +00:00
|
|
|
sectorsListCmd,
|
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-11-08 18:15:13 +00:00
|
|
|
fmt.Printf("Status:\t%s\n", api.SectorStateStr(status.State))
|
2019-07-27 21:08:10 +00:00
|
|
|
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-11-08 18:15:13 +00:00
|
|
|
fmt.Printf("Seed:\t\t%x\n", status.Seed.TicketBytes)
|
|
|
|
fmt.Printf("SeedH:\t\t%d\n", status.Seed.BlockHeight)
|
2019-07-27 21:08:10 +00:00
|
|
|
fmt.Printf("Proof:\t\t%x\n", status.Proof)
|
2019-11-08 18:15:13 +00:00
|
|
|
fmt.Printf("Deals:\t\t%v\n", status.Deals)
|
2019-07-27 21:08:10 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-11-13 14:48:57 +00:00
|
|
|
var sectorsListCmd = &cli.Command{
|
|
|
|
Name: "list",
|
|
|
|
Usage: "List sectors",
|
2019-07-27 21:08:10 +00:00
|
|
|
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-11-13 14:48:57 +00:00
|
|
|
|
|
|
|
fullApi, closer2, err := lcli.GetFullNodeAPI(cctx) // TODO: consider storing full node address in config
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer closer2()
|
|
|
|
|
2019-07-27 21:08:10 +00:00
|
|
|
ctx := lcli.ReqContext(cctx)
|
|
|
|
|
2019-11-13 14:48:57 +00:00
|
|
|
list, err := nodeApi.SectorsList(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
maddr, err := nodeApi.ActorAddress(ctx)
|
2019-07-27 21:08:10 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-11-13 14:48:57 +00:00
|
|
|
pset, err := fullApi.StateMinerProvingSet(ctx, maddr, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
provingIDs := make(map[uint64]struct{}, len(pset))
|
|
|
|
for _, info := range pset {
|
|
|
|
provingIDs[info.SectorID] = struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
sset, err := fullApi.StateMinerSectors(ctx, maddr, nil)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
commitedIDs := make(map[uint64]struct{}, len(pset))
|
|
|
|
for _, info := range sset {
|
|
|
|
commitedIDs[info.SectorID] = struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, s := range list {
|
|
|
|
st, err := nodeApi.SectorsStatus(ctx, s)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("%d:\tError: %s\n", s, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
_, inSSet := commitedIDs[s]
|
|
|
|
_, inPSet := provingIDs[s]
|
|
|
|
|
|
|
|
fmt.Printf("%d: %s\tsSet: %s\tpSet: %s\ttktH: %d\tseedH: %d\tdeals: %v\n",
|
|
|
|
s,
|
|
|
|
api.SectorStateStr(st.State),
|
|
|
|
yesno(inSSet),
|
|
|
|
yesno(inPSet),
|
|
|
|
st.Ticket.BlockHeight,
|
|
|
|
st.Seed.BlockHeight,
|
|
|
|
st.Deals,
|
|
|
|
)
|
2019-07-27 21:08:10 +00:00
|
|
|
}
|
|
|
|
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 {
|
2019-12-01 17:58:31 +00:00
|
|
|
fmt.Printf("\t%d+%d %d bytes\n", ref.SectorID, ref.Offset, ref.Size)
|
2019-08-26 10:04:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
2019-11-13 14:48:57 +00:00
|
|
|
|
|
|
|
func yesno(b bool) string {
|
|
|
|
if b {
|
|
|
|
return "YES"
|
|
|
|
}
|
|
|
|
return "NO"
|
|
|
|
}
|