Skip to content

Commit

Permalink
Roturn SectorID from PledgeSector
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Feb 16, 2021
1 parent f719765 commit fd90c03
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion api/api_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type StorageMiner interface {
MiningBase(context.Context) (*types.TipSet, error)

// Temp api for testing
PledgeSector(context.Context) error
PledgeSector(context.Context) (abi.SectorID, error)

// Get the status of a given sector by ID
SectorsStatus(ctx context.Context, sid abi.SectorNumber, showOnChainInfo bool) (SectorInfo, error)
Expand Down
4 changes: 2 additions & 2 deletions api/apistruct/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ type StorageMinerStruct struct {
MarketPendingDeals func(ctx context.Context) (api.PendingDealInfo, error) `perm:"write"`
MarketPublishPendingDeals func(ctx context.Context) error `perm:"admin"`

PledgeSector func(context.Context) error `perm:"write"`
PledgeSector func(context.Context) (abi.SectorID, error) `perm:"write"`

SectorsStatus func(ctx context.Context, sid abi.SectorNumber, showOnChainInfo bool) (api.SectorInfo, error) `perm:"read"`
SectorsList func(context.Context) ([]abi.SectorNumber, error) `perm:"read"`
Expand Down Expand Up @@ -1274,7 +1274,7 @@ func (c *StorageMinerStruct) ActorAddressConfig(ctx context.Context) (api.Addres
return c.Internal.ActorAddressConfig(ctx)
}

func (c *StorageMinerStruct) PledgeSector(ctx context.Context) error {
func (c *StorageMinerStruct) PledgeSector(ctx context.Context) (abi.SectorID, error) {
return c.Internal.PledgeSector(ctx)
}

Expand Down
9 changes: 8 additions & 1 deletion cmd/lotus-storage-miner/sectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ var sectorsPledgeCmd = &cli.Command{
defer closer()
ctx := lcli.ReqContext(cctx)

return nodeApi.PledgeSector(ctx)
id, err := nodeApi.PledgeSector(ctx)
if err != nil {
return err
}

fmt.Println("Created CC sector: ", id.Number)

return nil
},
}

Expand Down
8 changes: 7 additions & 1 deletion documentation/en/api-methods-miner.md
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,13 @@ Perms: write

Inputs: `null`

Response: `{}`
Response:
```json
{
"Miner": 1000,
"Number": 9
}
```

## Return

Expand Down
10 changes: 5 additions & 5 deletions node/impl/storminer.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,28 +121,28 @@ func (sm *StorageMinerAPI) ActorSectorSize(ctx context.Context, addr address.Add
return mi.SectorSize, nil
}

func (sm *StorageMinerAPI) PledgeSector(ctx context.Context) error {
func (sm *StorageMinerAPI) PledgeSector(ctx context.Context) (abi.SectorID, error) {
sr, err := sm.Miner.PledgeSector(ctx)
if err != nil {
return err
return abi.SectorID{}, err
}

// wait for the sector to enter the Packing state
// TODO: instead of polling implement some pubsub-type thing in storagefsm
for {
info, err := sm.Miner.GetSectorInfo(sr.ID.Number)
if err != nil {
return xerrors.Errorf("getting pledged sector info: %w", err)
return abi.SectorID{}, xerrors.Errorf("getting pledged sector info: %w", err)
}

if info.State != sealing.UndefinedSectorState {
return nil
return sr.ID, nil
}

select {
case <-time.After(10 * time.Millisecond):
case <-ctx.Done():
return ctx.Err()
return abi.SectorID{}, ctx.Err()
}
}
}
Expand Down

0 comments on commit fd90c03

Please sign in to comment.