Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: api: Add API and CLI to unseal sector #10626

Merged
merged 1 commit into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/api_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ type StorageMiner interface {
SectorMatchPendingPiecesToOpenSectors(ctx context.Context) error //perm:admin
// SectorAbortUpgrade can be called on sectors that are in the process of being upgraded to abort it
SectorAbortUpgrade(context.Context, abi.SectorNumber) error //perm:admin
// SectorUnseal unseals the provided sector
SectorUnseal(ctx context.Context, number abi.SectorNumber) error //perm:admin

// SectorNumAssignerMeta returns sector number assigner metadata - reserved/allocated
SectorNumAssignerMeta(ctx context.Context) (NumAssignerMeta, error) //perm:read
Expand Down
13 changes: 13 additions & 0 deletions api/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified build/openrpc/full.json.gz
Binary file not shown.
Binary file modified build/openrpc/gateway.json.gz
Binary file not shown.
Binary file modified build/openrpc/miner.json.gz
Binary file not shown.
Binary file modified build/openrpc/worker.json.gz
Binary file not shown.
25 changes: 25 additions & 0 deletions cmd/lotus-miner/sectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ var sectorsCmd = &cli.Command{
sectorsBatching,
sectorsRefreshPieceMatchingCmd,
sectorsCompactPartitionsCmd,
sectorsUnsealCmd,
},
}

Expand Down Expand Up @@ -2254,3 +2255,27 @@ var sectorsNumbersFreeCmd = &cli.Command{
return minerAPI.SectorNumFree(ctx, cctx.Args().First())
},
}

var sectorsUnsealCmd = &cli.Command{
Name: "unseal",
Usage: "unseal a sector",
ArgsUsage: "[sector number]",
Action: func(cctx *cli.Context) error {
minerAPI, closer, err := lcli.GetStorageMinerAPI(cctx)
if err != nil {
return err
}
defer closer()
ctx := lcli.ReqContext(cctx)
if cctx.NArg() != 1 {
return lcli.IncorrectNumArgs(cctx)
}

sectorNum, err := strconv.ParseUint(cctx.Args().Get(0), 10, 64)
if err != nil {
return xerrors.Errorf("could not parse sector number: %w", err)
}

return minerAPI.SectorUnseal(ctx, abi.SectorNumber(sectorNum))
},
}
16 changes: 16 additions & 0 deletions documentation/en/api-v0-methods-miner.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
* [SectorTerminate](#SectorTerminate)
* [SectorTerminateFlush](#SectorTerminateFlush)
* [SectorTerminatePending](#SectorTerminatePending)
* [SectorUnseal](#SectorUnseal)
* [Sectors](#Sectors)
* [SectorsList](#SectorsList)
* [SectorsListInStates](#SectorsListInStates)
Expand Down Expand Up @@ -3415,6 +3416,21 @@ Response:
]
```

### SectorUnseal
SectorUnseal unseals the provided sector


Perms: admin

Inputs:
```json
[
9
]
```

Response: `{}`

## Sectors


Expand Down
14 changes: 14 additions & 0 deletions documentation/en/cli-lotus-miner.md
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,7 @@ COMMANDS:
batching manage batch sector operations
match-pending-pieces force a refreshed match of pending pieces to open sectors without manually waiting for more deals
compact-partitions removes dead sectors from partitions and reduces the number of partitions used if possible
unseal unseal a sector
help, h Shows a list of commands or help for one command

OPTIONS:
Expand Down Expand Up @@ -2086,6 +2087,19 @@ OPTIONS:

```

### lotus-miner sectors unseal
```
NAME:
lotus-miner sectors unseal - unseal a sector

USAGE:
lotus-miner sectors unseal [command options] [sector number]

OPTIONS:
--help, -h show help (default: false)

```

## lotus-miner proving
```
NAME:
Expand Down
27 changes: 27 additions & 0 deletions node/impl/storminer.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,33 @@ func (sm *StorageMinerAPI) SectorsUnsealPiece(ctx context.Context, sector storif
return sm.StorageMgr.SectorsUnsealPiece(ctx, sector, offset, size, randomness, commd)
}

func (sm *StorageMinerAPI) SectorUnseal(ctx context.Context, sectorNum abi.SectorNumber) error {

status, err := sm.Miner.SectorsStatus(ctx, sectorNum, false)
if err != nil {
return err
}

minerAddr, err := sm.ActorAddress(ctx)
if err != nil {
return err
}
minerID, err := address.IDFromAddress(minerAddr)
if err != nil {
return err
}

sector := storiface.SectorRef{
ID: abi.SectorID{
Miner: abi.ActorID(minerID),
Number: sectorNum,
},
ProofType: status.SealProof,
}

return sm.StorageMgr.SectorsUnsealPiece(ctx, sector, storiface.UnpaddedByteIndex(0), abi.UnpaddedPieceSize(0), status.Ticket.Value, status.CommD)
}

// List all staged sectors
func (sm *StorageMinerAPI) SectorsList(context.Context) ([]abi.SectorNumber, error) {
sectors, err := sm.Miner.ListSectors()
Expand Down