sectorbuilder: Call destroy in DI module

This commit is contained in:
Łukasz Magiera 2019-11-08 21:30:50 +01:00
parent f3ae7eb7a3
commit 3d360167df
4 changed files with 19 additions and 17 deletions

View File

@ -46,7 +46,7 @@ func TempSectorbuilderDir(dir string, sectorSize uint64, ds dtypes.MetadataDS) (
WorkerThreads: 2,
Miner: addr,
}, ds, nil)
}, ds)
if err != nil {
return nil, err
}

View File

@ -1,7 +1,6 @@
package sectorbuilder
import (
"context"
"fmt"
"io"
"os"
@ -13,7 +12,6 @@ import (
sectorbuilder "github.com/filecoin-project/go-sectorbuilder"
"github.com/ipfs/go-datastore"
logging "github.com/ipfs/go-log"
"go.uber.org/fx"
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/chain/address"
@ -77,7 +75,7 @@ type Config struct {
MetadataDir string
}
func New(cfg *Config, ds dtypes.MetadataDS, lc fx.Lifecycle) (*SectorBuilder, error) {
func New(cfg *Config, ds dtypes.MetadataDS) (*SectorBuilder, error) {
if cfg.WorkerThreads <= PoStReservedWorkers {
return nil, xerrors.Errorf("minimum worker threads is %d, specified %d", PoStReservedWorkers+1, cfg.WorkerThreads)
}
@ -126,15 +124,6 @@ func New(cfg *Config, ds dtypes.MetadataDS, lc fx.Lifecycle) (*SectorBuilder, er
rateLimit: make(chan struct{}, cfg.WorkerThreads-PoStReservedWorkers),
}
if lc != nil {
lc.Append(fx.Hook{
OnStop: func(context.Context) error {
sb.Destroy()
return nil
},
})
}
return sb, nil
}
@ -196,9 +185,6 @@ func (sb *SectorBuilder) AddPiece(pieceSize uint64, sectorId uint64, file io.Rea
if err != nil {
return PublicPieceInfo{}, err
}
/*if writeUnpadded != pieceSize {
return PublicPieceInfo{}, xerrors.Errorf("writeUnpadded != pieceSize: %d != %d", writeUnpadded, pieceSize)
}*/
if err := stagedFile.Close(); err != nil {
return PublicPieceInfo{}, err

View File

@ -230,7 +230,7 @@ func Online() Option {
// Storage miner
ApplyIf(func(s *Settings) bool { return s.nodeType == repo.RepoStorageMiner },
Override(new(*sectorbuilder.SectorBuilder), sectorbuilder.New),
Override(new(*sectorblocks.SectorBlocks), sectorblocks.NewSectorBlocks),
Override(new(*sectorblocks.SectorBlocks), modules.SectorBuilder),
Override(new(storage.TicketFn), modules.SealTicketGen),
Override(new(*storage.Miner), modules.StorageMiner),

View File

@ -176,6 +176,22 @@ func RegisterMiner(lc fx.Lifecycle, ds dtypes.MetadataDS, api api.FullNode) erro
return nil
}
func SectorBuilder(lc fx.Lifecycle, cfg *sectorbuilder.Config, ds dtypes.MetadataDS) (*sectorbuilder.SectorBuilder, error) {
sb, err := sectorbuilder.New(cfg, ds)
if err != nil {
return nil, err
}
lc.Append(fx.Hook{
OnStop: func(context.Context) error {
sb.Destroy()
return nil
},
})
return sb, nil
}
func SealTicketGen(api api.FullNode) storage.TicketFn {
return func(ctx context.Context) (*sectorbuilder.SealTicket, error) {
ts, err := api.ChainHead(ctx)