lotus/extern/storage-sealing/upgrade_queue.go

93 lines
2.1 KiB
Go
Raw Normal View History

2020-07-01 13:30:25 +00:00
package sealing
import (
2020-07-15 14:51:02 +00:00
"context"
2020-07-01 13:30:25 +00:00
"golang.org/x/xerrors"
"github.com/filecoin-project/specs-actors/actors/abi"
2020-07-01 14:33:59 +00:00
"github.com/filecoin-project/specs-actors/actors/abi/big"
"github.com/filecoin-project/specs-actors/actors/builtin/miner"
2020-07-01 13:30:25 +00:00
)
func (m *Sealing) MarkForUpgrade(id abi.SectorNumber) error {
m.upgradeLk.Lock()
defer m.upgradeLk.Unlock()
_, found := m.toUpgrade[id]
if found {
return xerrors.Errorf("sector %d already marked for upgrade", id)
}
si, err := m.GetSectorInfo(id)
if err != nil {
return xerrors.Errorf("getting sector info: %w", err)
}
if si.State != Proving {
return xerrors.Errorf("can't mark sectors not in the 'Proving' state for upgrade")
}
if len(si.Pieces) != 1 {
return xerrors.Errorf("not a committed-capacity sector, expected 1 piece")
}
if si.Pieces[0].DealInfo != nil {
return xerrors.Errorf("not a committed-capacity sector, has deals")
}
// TODO: more checks to match actor constraints
m.toUpgrade[id] = struct{}{}
return nil
}
2020-07-15 14:51:02 +00:00
func (m *Sealing) tryUpgradeSector(ctx context.Context, params *miner.SectorPreCommitInfo) big.Int {
2020-07-01 14:33:59 +00:00
replace := m.maybeUpgradableSector()
if replace != nil {
2020-07-15 14:51:02 +00:00
loc, err := m.api.StateSectorPartition(ctx, m.maddr, *replace, nil)
if err != nil {
log.Errorf("error calling StateSectorPartition for replaced sector: %+v", err)
return big.Zero()
}
2020-07-01 14:33:59 +00:00
params.ReplaceCapacity = true
2020-07-15 14:51:02 +00:00
params.ReplaceSectorNumber = *replace
params.ReplaceSectorDeadline = loc.Deadline
params.ReplaceSectorPartition = loc.Partition
2020-07-01 14:33:59 +00:00
ri, err := m.GetSectorInfo(*replace)
if err != nil {
log.Errorf("error calling GetSectorInfo for replaced sector: %+v", err)
return big.Zero()
}
if params.Expiration < ri.PreCommitInfo.Expiration {
// TODO: Some limit on this
params.Expiration = ri.PreCommitInfo.Expiration
}
return ri.PreCommitDeposit
}
return big.Zero()
}
2020-07-01 13:30:25 +00:00
func (m *Sealing) maybeUpgradableSector() *abi.SectorNumber {
m.upgradeLk.Lock()
defer m.upgradeLk.Unlock()
for number := range m.toUpgrade {
// TODO: checks to match actor constraints
// this one looks good
2020-07-01 13:30:36 +00:00
/*if checks */
{
2020-07-01 13:30:25 +00:00
delete(m.toUpgrade, number)
return &number
}
}
return nil
}