diff --git a/lib/sectorbuilder/mock.go b/lib/sectorbuilder/mock.go index 481b982b4..e9661ada1 100644 --- a/lib/sectorbuilder/mock.go +++ b/lib/sectorbuilder/mock.go @@ -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 } diff --git a/lib/sectorbuilder/sectorbuilder.go b/lib/sectorbuilder/sectorbuilder.go index bdc8d5a66..9c2b24af2 100644 --- a/lib/sectorbuilder/sectorbuilder.go +++ b/lib/sectorbuilder/sectorbuilder.go @@ -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 diff --git a/node/builder.go b/node/builder.go index 0956a67c1..da37bb95f 100644 --- a/node/builder.go +++ b/node/builder.go @@ -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), diff --git a/node/modules/storageminer.go b/node/modules/storageminer.go index 3c827c550..0c97710cb 100644 --- a/node/modules/storageminer.go +++ b/node/modules/storageminer.go @@ -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)