Maintain a map of UnsealedSectorInfos

This commit is contained in:
Aayush Rajasekaran 2020-06-23 17:47:53 -04:00
parent 020f3a173a
commit ff8894f2ec

View File

@ -53,9 +53,16 @@ type Sealing struct {
sc SectorIDCounter
verif ffiwrapper.Verifier
unsealedInfos map[abi.SectorNumber]UnsealedSectorInfo
pcp PreCommitPolicy
}
type UnsealedSectorInfo struct {
// stored should always equal sum of pieceSizes
stored uint64
pieceSizes []abi.UnpaddedPieceSize
}
func New(api SealingAPI, events Events, maddr address.Address, ds datastore.Batching, sealer sectorstorage.SectorManager, sc SectorIDCounter, verif ffiwrapper.Verifier, pcp PreCommitPolicy) *Sealing {
s := &Sealing{
api: api,
@ -65,6 +72,7 @@ func New(api SealingAPI, events Events, maddr address.Address, ds datastore.Batc
sealer: sealer,
sc: sc,
verif: verif,
unsealedInfos: make(map[abi.SectorNumber]UnsealedSectorInfo),
pcp: pcp,
}
@ -130,7 +138,18 @@ func (m *Sealing) AddPieceToAnySector(ctx context.Context, size abi.UnpaddedPiec
func (m *Sealing) addPiece(sectorID abi.SectorNumber, piece Piece) error {
log.Infof("Adding piece to sector %d", sectorID)
return m.sectors.Send(uint64(sectorID), SectorAddPiece{NewPiece: piece})
err := m.sectors.Send(uint64(sectorID), SectorAddPiece{NewPiece: piece})
if err != nil {
return err
}
ui := m.unsealedInfos[sectorID]
m.unsealedInfos[sectorID] = UnsealedSectorInfo{
stored: ui.stored + uint64(piece.Piece.Size.Unpadded()),
pieceSizes: append(ui.pieceSizes, piece.Piece.Size.Unpadded()),
}
return nil
}
func (m *Sealing) Remove(ctx context.Context, sid abi.SectorNumber) error {
@ -139,7 +158,14 @@ func (m *Sealing) Remove(ctx context.Context, sid abi.SectorNumber) error {
func (m *Sealing) StartPacking(sectorID abi.SectorNumber) error {
log.Infof("Starting packing sector %d", sectorID)
return m.sectors.Send(uint64(sectorID), SectorStartPacking{})
err := m.sectors.Send(uint64(sectorID), SectorStartPacking{})
if err != nil {
return err
}
delete(m.unsealedInfos, sectorID)
return nil
}
// newSector creates a new sector for deal storage
@ -150,10 +176,21 @@ func (m *Sealing) newSector(sid abi.SectorNumber) error {
}
log.Infof("Creating sector %d", sid)
return m.sectors.Send(uint64(sid), SectorStart{
err = m.sectors.Send(uint64(sid), SectorStart{
ID: sid,
SectorType: rt,
})
if err != nil {
return err
}
m.unsealedInfos[sid] = UnsealedSectorInfo{
stored: 0,
pieceSizes: nil,
}
return nil
}
// newSectorCC accepts a slice of pieces with no deal (junk data)