2020-01-15 20:49:11 +00:00
|
|
|
package sealing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"golang.org/x/xerrors"
|
2021-02-16 16:41:29 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/specs-storage/storage"
|
2020-02-27 00:54:39 +00:00
|
|
|
)
|
2020-01-25 11:15:28 +00:00
|
|
|
|
2021-02-16 16:41:29 +00:00
|
|
|
func (m *Sealing) PledgeSector(ctx context.Context) (storage.SectorRef, error) {
|
2021-02-16 16:14:59 +00:00
|
|
|
m.inputLk.Lock()
|
|
|
|
defer m.inputLk.Unlock()
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2020-08-18 17:26:17 +00:00
|
|
|
cfg, err := m.getConfig()
|
|
|
|
if err != nil {
|
2021-02-16 16:41:29 +00:00
|
|
|
return storage.SectorRef{}, xerrors.Errorf("getting config: %w", err)
|
2020-08-18 17:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if cfg.MaxSealingSectors > 0 {
|
2020-12-10 03:04:42 +00:00
|
|
|
if m.stats.curSealing() >= cfg.MaxSealingSectors {
|
2021-02-16 16:41:29 +00:00
|
|
|
return storage.SectorRef{}, xerrors.Errorf("too many sectors sealing (curSealing: %d, max: %d)", m.stats.curSealing(), cfg.MaxSealingSectors)
|
2020-08-18 17:26:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-16 16:14:59 +00:00
|
|
|
spt, err := m.currentSealProof(ctx)
|
|
|
|
if err != nil {
|
2021-02-16 16:41:29 +00:00
|
|
|
return storage.SectorRef{}, xerrors.Errorf("getting seal proof type: %w", err)
|
2021-02-16 16:14:59 +00:00
|
|
|
}
|
2020-01-15 20:49:11 +00:00
|
|
|
|
2021-02-16 16:14:59 +00:00
|
|
|
sid, err := m.sc.Next()
|
|
|
|
if err != nil {
|
2021-02-16 16:41:29 +00:00
|
|
|
return storage.SectorRef{}, xerrors.Errorf("generating sector number: %w", err)
|
2021-02-16 16:14:59 +00:00
|
|
|
}
|
|
|
|
sectorID := m.minerSector(spt, sid)
|
|
|
|
err = m.sealer.NewSector(ctx, sectorID)
|
|
|
|
if err != nil {
|
2021-02-16 16:41:29 +00:00
|
|
|
return storage.SectorRef{}, xerrors.Errorf("notifying sealer of the new sector: %w", err)
|
2021-02-16 16:14:59 +00:00
|
|
|
}
|
2020-04-07 21:44:33 +00:00
|
|
|
|
2021-02-16 16:14:59 +00:00
|
|
|
log.Infof("Creating CC sector %d", sid)
|
2021-02-16 16:41:29 +00:00
|
|
|
return sectorID, m.sectors.Send(uint64(sid), SectorStartCC{
|
2021-02-16 16:14:59 +00:00
|
|
|
ID: sid,
|
|
|
|
SectorType: spt,
|
|
|
|
})
|
2020-01-15 20:49:11 +00:00
|
|
|
}
|