storageminer: exit PledgeSector after sectors enter sealing pipeline

This commit is contained in:
Łukasz Magiera 2021-02-16 17:41:29 +01:00
parent 46b880a6b9
commit f719765069
3 changed files with 34 additions and 9 deletions

View File

@ -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,
})

View File

@ -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) {

View File

@ -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"
)
@ -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)
}