Skip to content

Commit

Permalink
feat: add InUnsealed utility to boostx (#1680)
Browse files Browse the repository at this point in the history
* add InUnsealed utility to boostx

* remove api version check
  • Loading branch information
LexLuthr authored Sep 7, 2023
1 parent a0509fa commit d43861b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/boostx/boostd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

const metadataNamespace = "/metadata"

var minerCmd = &cli.Command{
var boostdCmd = &cli.Command{
Name: "boostd",
Usage: "boostd utilities",
Subcommands: []*cli.Command{
Expand Down
2 changes: 1 addition & 1 deletion cmd/boostx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func main() {
marketWithdrawCmd,
statsCmd,
sectorCmd,
minerCmd,
boostdCmd,
},
}
app.Setup()
Expand Down
69 changes: 67 additions & 2 deletions cmd/boostx/sector.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ package main

import (
"fmt"
"strconv"
"time"

"github.com/filecoin-project/boost/cmd/lib"
"github.com/filecoin-project/go-state-types/abi"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/urfave/cli/v2"
"strconv"
"time"
)

var sectorCmd = &cli.Command{
Name: "sector",
Usage: "Sector commands",
Subcommands: []*cli.Command{
sectorUnsealCmd,
isUnsealedCmd,
},
}

Expand Down Expand Up @@ -92,3 +94,66 @@ var sectorUnsealCmd = &cli.Command{
return nil
},
}

var isUnsealedCmd = &cli.Command{
Name: "is-unsealed",
Usage: "boostx sector is-unsealed <Sector ID>",
Description: "Check if a particular sector is unsealed using the miner API. This is a definitive method to check for unsealed copies",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "api-fullnode",
Usage: "the endpoint for the full node API",
Required: true,
},
&cli.StringFlag{
Name: "api-storage",
Usage: "the endpoint for the storage node API",
Required: true,
},
},
Action: func(cctx *cli.Context) error {

if !cctx.Args().Present() {
return fmt.Errorf("must pass sector ID as first parameter")
}

sectorIDInt, err := strconv.Atoi(cctx.Args().First())
if err != nil {
return fmt.Errorf("parsing sector ID %s: %w", cctx.Args().First(), err)
}
sectorID := abi.SectorNumber(sectorIDInt)

ctx := lcli.ReqContext(cctx)

// Connect to the full node API
fnApiInfo := cctx.String("api-fullnode")
fullnodeApi, ncloser, err := lib.GetFullNodeApi(ctx, fnApiInfo, log)
if err != nil {
return fmt.Errorf("getting full node API: %w", err)
}
defer ncloser()

// Connect to the storage API and create a sector accessor
storageApiInfo := cctx.String("api-storage")
sa, storageCloser, err := lib.CreateSectorAccessor(ctx, storageApiInfo, fullnodeApi, log)
if err != nil {
return err
}
defer storageCloser()

pieceLength := abi.PaddedPieceSize(1024).Unpadded()
isUnsealed, err := sa.IsUnsealed(ctx, sectorID, 0, pieceLength)
if err != nil {
return fmt.Errorf("getting sealed state of sector: %w", err)
}

if isUnsealed {
fmt.Printf("Sector %d is unsealed\n", sectorID)
return nil
}

fmt.Printf("Sector %d is NOT unsealed\n", sectorID)

return nil
},
}

0 comments on commit d43861b

Please sign in to comment.