From d43861b4ac0b9ccc41aee4339ddd1c1c83ecf870 Mon Sep 17 00:00:00 2001 From: LexLuthr <88259624+LexLuthr@users.noreply.github.com> Date: Thu, 7 Sep 2023 16:36:47 +0400 Subject: [PATCH] feat: add InUnsealed utility to boostx (#1680) * add InUnsealed utility to boostx * remove api version check --- cmd/boostx/boostd.go | 2 +- cmd/boostx/main.go | 2 +- cmd/boostx/sector.go | 69 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/cmd/boostx/boostd.go b/cmd/boostx/boostd.go index 4ef9b044e..b2117fb11 100644 --- a/cmd/boostx/boostd.go +++ b/cmd/boostx/boostd.go @@ -12,7 +12,7 @@ import ( const metadataNamespace = "/metadata" -var minerCmd = &cli.Command{ +var boostdCmd = &cli.Command{ Name: "boostd", Usage: "boostd utilities", Subcommands: []*cli.Command{ diff --git a/cmd/boostx/main.go b/cmd/boostx/main.go index d3c17ad96..1bf7e11c6 100644 --- a/cmd/boostx/main.go +++ b/cmd/boostx/main.go @@ -47,7 +47,7 @@ func main() { marketWithdrawCmd, statsCmd, sectorCmd, - minerCmd, + boostdCmd, }, } app.Setup() diff --git a/cmd/boostx/sector.go b/cmd/boostx/sector.go index c44cc6bfc..fdcc734d6 100644 --- a/cmd/boostx/sector.go +++ b/cmd/boostx/sector.go @@ -2,12 +2,13 @@ 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{ @@ -15,6 +16,7 @@ var sectorCmd = &cli.Command{ Usage: "Sector commands", Subcommands: []*cli.Command{ sectorUnsealCmd, + isUnsealedCmd, }, } @@ -92,3 +94,66 @@ var sectorUnsealCmd = &cli.Command{ return nil }, } + +var isUnsealedCmd = &cli.Command{ + Name: "is-unsealed", + Usage: "boostx sector is-unsealed ", + 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 + }, +}