From 8e1a9a71e635a36b01a21b9398914124227548e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 29 Oct 2019 18:52:07 +0100 Subject: [PATCH] Run store-garbage in background --- api/api.go | 2 +- api/struct.go | 4 ++-- cmd/lotus-storage-miner/sectors.go | 8 +------- node/impl/storminer.go | 30 +++++++++++++++++------------- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/api/api.go b/api/api.go index 989d42ee8..635901ecb 100644 --- a/api/api.go +++ b/api/api.go @@ -159,7 +159,7 @@ type StorageMiner interface { ActorAddress(context.Context) (address.Address, error) // Temp api for testing - StoreGarbageData(context.Context) (uint64, error) + StoreGarbageData(context.Context) error // Get the status of a given sector by ID SectorsStatus(context.Context, uint64) (sectorbuilder.SectorSealingStatus, error) diff --git a/api/struct.go b/api/struct.go index 3fbbf619c..6eefe41dc 100644 --- a/api/struct.go +++ b/api/struct.go @@ -127,7 +127,7 @@ type StorageMinerStruct struct { Internal struct { ActorAddress func(context.Context) (address.Address, error) `perm:"read"` - StoreGarbageData func(context.Context) (uint64, error) `perm:"write"` + StoreGarbageData func(context.Context) error `perm:"write"` SectorsStatus func(context.Context, uint64) (sectorbuilder.SectorSealingStatus, error) `perm:"read"` SectorsList func(context.Context) ([]uint64, error) `perm:"read"` @@ -461,7 +461,7 @@ func (c *StorageMinerStruct) ActorAddress(ctx context.Context) (address.Address, return c.Internal.ActorAddress(ctx) } -func (c *StorageMinerStruct) StoreGarbageData(ctx context.Context) (uint64, error) { +func (c *StorageMinerStruct) StoreGarbageData(ctx context.Context) error { return c.Internal.StoreGarbageData(ctx) } diff --git a/cmd/lotus-storage-miner/sectors.go b/cmd/lotus-storage-miner/sectors.go index 149e8195d..d49384619 100644 --- a/cmd/lotus-storage-miner/sectors.go +++ b/cmd/lotus-storage-miner/sectors.go @@ -20,13 +20,7 @@ var storeGarbageCmd = &cli.Command{ defer closer() ctx := lcli.ReqContext(cctx) - sectorId, err := nodeApi.StoreGarbageData(ctx) - if err != nil { - return err - } - - fmt.Println(sectorId) - return nil + return nodeApi.StoreGarbageData(ctx) }, } diff --git a/node/impl/storminer.go b/node/impl/storminer.go index e70480651..c763dab5e 100644 --- a/node/impl/storminer.go +++ b/node/impl/storminer.go @@ -31,25 +31,29 @@ func (sm *StorageMinerAPI) ActorAddress(context.Context) (address.Address, error return sm.SectorBuilderConfig.Miner, nil } -func (sm *StorageMinerAPI) StoreGarbageData(ctx context.Context) (uint64, error) { +func (sm *StorageMinerAPI) StoreGarbageData(ctx context.Context) error { ssize, err := sm.Miner.SectorSize(ctx) if err != nil { - return 0, xerrors.Errorf("failed to get miner sector size: %w", err) + return xerrors.Errorf("failed to get miner sector size: %w", err) } - size := sectorbuilder.UserBytesForSectorSize(ssize) + go func() { + size := sectorbuilder.UserBytesForSectorSize(ssize) - // TODO: create a deal - name := fmt.Sprintf("fake-file-%d", rand.Intn(100000000)) - sectorId, err := sm.Sectors.AddPiece(name, size, io.LimitReader(rand.New(rand.NewSource(42)), int64(size))) - if err != nil { - return 0, err - } + // TODO: create a deal + name := fmt.Sprintf("fake-file-%d", rand.Intn(100000000)) + sectorId, err := sm.Sectors.AddPiece(name, size, io.LimitReader(rand.New(rand.NewSource(42)), int64(size))) + if err != nil { + log.Error(err) + return + } - if err := sm.Sectors.SealSector(ctx, sectorId); err != nil { - return sectorId, err - } + if err := sm.Sectors.SealSector(ctx, sectorId); err != nil { + log.Error(err) + return + } + }() - return sectorId, err + return err } func (sm *StorageMinerAPI) SectorsStatus(ctx context.Context, sid uint64) (sectorbuilder.SectorSealingStatus, error) {