storagefsm: common createSector method

This commit is contained in:
Łukasz Magiera 2021-03-12 18:42:17 +01:00
parent e5b5bf1c1b
commit 0974e02089
2 changed files with 26 additions and 23 deletions

View File

@ -28,21 +28,13 @@ func (m *Sealing) PledgeSector(ctx context.Context) (storage.SectorRef, error) {
return storage.SectorRef{}, xerrors.Errorf("getting seal proof type: %w", err) return storage.SectorRef{}, xerrors.Errorf("getting seal proof type: %w", err)
} }
sid, err := m.sc.Next() sid, err := m.createSector(ctx, cfg, spt)
if err != nil { if err != nil {
return storage.SectorRef{}, xerrors.Errorf("generating sector number: %w", err) return storage.SectorRef{}, err
} }
sectorID := m.minerSector(spt, sid)
err = m.sealer.NewSector(ctx, sectorID)
if err != nil {
return storage.SectorRef{}, xerrors.Errorf("notifying sealer of the new sector: %w", err)
}
// update stats early, fsm planner would do that async
m.stats.updateSector(cfg, m.minerSectorID(sid), UndefinedSectorState)
log.Infof("Creating CC sector %d", sid) log.Infof("Creating CC sector %d", sid)
return sectorID, m.sectors.Send(uint64(sid), SectorStartCC{ return m.minerSector(spt, sid), m.sectors.Send(uint64(sid), SectorStartCC{
ID: sid, ID: sid,
SectorType: spt, SectorType: spt,
}) })

View File

@ -16,6 +16,7 @@ import (
sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage" sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage"
"github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" "github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper"
"github.com/filecoin-project/lotus/extern/storage-sealing/sealiface"
) )
func (m *Sealing) handleWaitDeals(ctx statemachine.Context, sector SectorInfo) error { func (m *Sealing) handleWaitDeals(ctx statemachine.Context, sector SectorInfo) error {
@ -388,21 +389,11 @@ func (m *Sealing) tryCreateDealSector(ctx context.Context, sp abi.RegisteredSeal
return nil return nil
} }
// Now actually create a new sector sid, err := m.createSector(ctx, cfg, sp)
sid, err := m.sc.Next()
if err != nil { if err != nil {
return xerrors.Errorf("getting sector number: %w", err) return err
} }
err = m.sealer.NewSector(ctx, m.minerSector(sp, sid))
if err != nil {
return xerrors.Errorf("initializing sector: %w", err)
}
// update stats early, fsm planner would do that async
m.stats.updateSector(cfg, m.minerSectorID(sid), UndefinedSectorState)
log.Infow("Creating sector", "number", sid, "type", "deal", "proofType", sp) log.Infow("Creating sector", "number", sid, "type", "deal", "proofType", sp)
return m.sectors.Send(uint64(sid), SectorStart{ return m.sectors.Send(uint64(sid), SectorStart{
ID: sid, ID: sid,
@ -410,6 +401,26 @@ func (m *Sealing) tryCreateDealSector(ctx context.Context, sp abi.RegisteredSeal
}) })
} }
// call with m.inputLk
func (m *Sealing) createSector(ctx context.Context, cfg sealiface.Config, sp abi.RegisteredSealProof) (abi.SectorNumber, error) {
// Now actually create a new sector
sid, err := m.sc.Next()
if err != nil {
return 0, xerrors.Errorf("getting sector number: %w", err)
}
err = m.sealer.NewSector(ctx, m.minerSector(sp, sid))
if err != nil {
return 0, xerrors.Errorf("initializing sector: %w", err)
}
// update stats early, fsm planner would do that async
m.stats.updateSector(cfg, m.minerSectorID(sid), UndefinedSectorState)
return sid, nil
}
func (m *Sealing) StartPacking(sid abi.SectorNumber) error { func (m *Sealing) StartPacking(sid abi.SectorNumber) error {
return m.sectors.Send(uint64(sid), SectorStartPacking{}) return m.sectors.Send(uint64(sid), SectorStartPacking{})
} }