From fd90c030183d63172597cbd57fd6ff8502897795 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 16 Feb 2021 19:16:35 +0100 Subject: [PATCH] Roturn SectorID from PledgeSector --- api/api_storage.go | 2 +- api/apistruct/struct.go | 4 ++-- cmd/lotus-storage-miner/sectors.go | 9 ++++++++- documentation/en/api-methods-miner.md | 8 +++++++- node/impl/storminer.go | 10 +++++----- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/api/api_storage.go b/api/api_storage.go index eb4584e10..3f8143433 100644 --- a/api/api_storage.go +++ b/api/api_storage.go @@ -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) diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index ded34ac5a..53d7dc24a 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -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"` @@ -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) } diff --git a/cmd/lotus-storage-miner/sectors.go b/cmd/lotus-storage-miner/sectors.go index fb9358382..ad7d61068 100644 --- a/cmd/lotus-storage-miner/sectors.go +++ b/cmd/lotus-storage-miner/sectors.go @@ -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 }, } diff --git a/documentation/en/api-methods-miner.md b/documentation/en/api-methods-miner.md index aa84ebdf2..e72a53f62 100644 --- a/documentation/en/api-methods-miner.md +++ b/documentation/en/api-methods-miner.md @@ -1142,7 +1142,13 @@ Perms: write Inputs: `null` -Response: `{}` +Response: +```json +{ + "Miner": 1000, + "Number": 9 +} +``` ## Return diff --git a/node/impl/storminer.go b/node/impl/storminer.go index b9ecfb574..cde168bea 100644 --- a/node/impl/storminer.go +++ b/node/impl/storminer.go @@ -121,10 +121,10 @@ 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 @@ -132,17 +132,17 @@ func (sm *StorageMinerAPI) PledgeSector(ctx context.Context) error { 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() } } }