Skip to content

Commit

Permalink
storageminer: exit PledgeSector after sectors enter sealing pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Feb 16, 2021
1 parent 46b880a commit f719765
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
16 changes: 9 additions & 7 deletions extern/storage-sealing/garbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,42 @@ import (
"context"

"golang.org/x/xerrors"

"github.com/filecoin-project/specs-storage/storage"
)

func (m *Sealing) PledgeSector(ctx context.Context) error {
func (m *Sealing) PledgeSector(ctx context.Context) (storage.SectorRef, error) {
m.inputLk.Lock()
defer m.inputLk.Unlock()

cfg, err := m.getConfig()
if err != nil {
return xerrors.Errorf("getting config: %w", err)
return storage.SectorRef{}, xerrors.Errorf("getting config: %w", err)
}

if cfg.MaxSealingSectors > 0 {
if m.stats.curSealing() >= cfg.MaxSealingSectors {
return xerrors.Errorf("too many sectors sealing (curSealing: %d, max: %d)", m.stats.curSealing(), cfg.MaxSealingSectors)
return storage.SectorRef{}, xerrors.Errorf("too many sectors sealing (curSealing: %d, max: %d)", m.stats.curSealing(), cfg.MaxSealingSectors)
}
}

spt, err := m.currentSealProof(ctx)
if err != nil {
return xerrors.Errorf("getting seal proof type: %w", err)
return storage.SectorRef{}, xerrors.Errorf("getting seal proof type: %w", err)
}

sid, err := m.sc.Next()
if err != nil {
return xerrors.Errorf("generating sector number: %w", err)
return storage.SectorRef{}, xerrors.Errorf("generating sector number: %w", err)
}
sectorID := m.minerSector(spt, sid)
err = m.sealer.NewSector(ctx, sectorID)
if err != nil {
return xerrors.Errorf("notifying sealer of the new sector: %w", err)
return storage.SectorRef{}, xerrors.Errorf("notifying sealer of the new sector: %w", err)
}

log.Infof("Creating CC sector %d", sid)
return m.sectors.Send(uint64(sid), SectorStartCC{
return sectorID, m.sectors.Send(uint64(sid), SectorStartCC{
ID: sid,
SectorType: spt,
})
Expand Down
24 changes: 23 additions & 1 deletion node/impl/storminer.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,29 @@ func (sm *StorageMinerAPI) ActorSectorSize(ctx context.Context, addr address.Add
}

func (sm *StorageMinerAPI) PledgeSector(ctx context.Context) error {
return sm.Miner.PledgeSector(ctx)
sr, err := sm.Miner.PledgeSector(ctx)
if err != nil {
return err
}

// wait for the sector to enter the Packing state
// TODO: instead of polling implement some pubsub-type thing in storagefsm
for {
info, err := sm.Miner.GetSectorInfo(sr.ID.Number)
if err != nil {
return xerrors.Errorf("getting pledged sector info: %w", err)
}

if info.State != sealing.UndefinedSectorState {
return nil
}

select {
case <-time.After(10 * time.Millisecond):
case <-ctx.Done():
return ctx.Err()
}
}
}

func (sm *StorageMinerAPI) SectorsStatus(ctx context.Context, sid abi.SectorNumber, showOnChainInfo bool) (api.SectorInfo, error) {
Expand Down
3 changes: 2 additions & 1 deletion storage/sealing.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/specs-storage/storage"

sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
)
Expand All @@ -34,7 +35,7 @@ func (m *Miner) GetSectorInfo(sid abi.SectorNumber) (sealing.SectorInfo, error)
return m.sealing.GetSectorInfo(sid)
}

func (m *Miner) PledgeSector(ctx context.Context) error {
func (m *Miner) PledgeSector(ctx context.Context) (storage.SectorRef, error) {
return m.sealing.PledgeSector(ctx)
}

Expand Down

0 comments on commit f719765

Please sign in to comment.