2020-07-01 13:30:25 +00:00
|
|
|
package sealing
|
|
|
|
|
|
|
|
import (
|
2020-07-15 14:51:02 +00:00
|
|
|
"context"
|
2020-09-17 02:34:13 +00:00
|
|
|
|
2020-07-01 13:30:25 +00:00
|
|
|
"golang.org/x/xerrors"
|
|
|
|
|
2020-09-07 03:49:10 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2023-11-13 23:59:34 +00:00
|
|
|
market7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/market"
|
2023-11-14 00:06:11 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
2020-07-01 13:30:25 +00:00
|
|
|
)
|
|
|
|
|
2022-08-09 11:30:34 +00:00
|
|
|
func (m *Sealing) MarkForUpgrade(ctx context.Context, id abi.SectorNumber) error {
|
2020-07-01 13:30:25 +00:00
|
|
|
si, err := m.GetSectorInfo(id)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("getting sector info: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if si.State != Proving {
|
2022-03-25 15:39:53 +00:00
|
|
|
return xerrors.Errorf("unable to snap-up sectors not in the 'Proving' state")
|
2020-07-01 13:30:25 +00:00
|
|
|
}
|
|
|
|
|
2022-03-16 18:53:00 +00:00
|
|
|
if si.hasDeals() {
|
2020-07-01 13:30:25 +00:00
|
|
|
return xerrors.Errorf("not a committed-capacity sector, has deals")
|
|
|
|
}
|
|
|
|
|
2022-06-16 11:15:49 +00:00
|
|
|
ts, err := m.Api.ChainHead(ctx)
|
2021-12-08 17:11:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("couldnt get chain head: %w", err)
|
|
|
|
}
|
2022-06-16 11:15:49 +00:00
|
|
|
onChainInfo, err := m.Api.StateSectorGetInfo(ctx, m.maddr, id, ts.Key())
|
2021-12-08 17:11:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("failed to read sector on chain info: %w", err)
|
|
|
|
}
|
2022-12-12 15:44:08 +00:00
|
|
|
if onChainInfo == nil {
|
|
|
|
return xerrors.Errorf("sector not found %d", id)
|
|
|
|
}
|
2020-07-01 13:30:25 +00:00
|
|
|
|
2022-06-16 11:15:49 +00:00
|
|
|
active, err := m.sectorActive(ctx, ts.Key(), id)
|
2021-12-08 17:11:19 +00:00
|
|
|
if err != nil {
|
2022-02-01 06:09:42 +00:00
|
|
|
return xerrors.Errorf("failed to check if sector is active")
|
2021-12-08 17:11:19 +00:00
|
|
|
}
|
2022-02-01 06:09:42 +00:00
|
|
|
if !active {
|
2021-12-08 17:11:19 +00:00
|
|
|
return xerrors.Errorf("cannot mark inactive sector for upgrade")
|
|
|
|
}
|
2020-07-01 13:30:25 +00:00
|
|
|
|
2022-06-16 11:15:49 +00:00
|
|
|
if onChainInfo.Expiration-ts.Height() < market7.DealMinDuration {
|
2021-12-08 17:11:19 +00:00
|
|
|
return xerrors.Errorf("pointless to upgrade sector %d, expiration %d is less than a min deal duration away from current epoch."+
|
|
|
|
"Upgrade expiration before marking for upgrade", id, onChainInfo.Expiration)
|
|
|
|
}
|
|
|
|
|
2022-03-16 16:33:05 +00:00
|
|
|
return m.sectors.Send(uint64(id), SectorMarkForUpdate{})
|
2020-07-01 13:30:25 +00:00
|
|
|
}
|
|
|
|
|
2022-06-17 09:20:33 +00:00
|
|
|
func (m *Sealing) sectorActive(ctx context.Context, tsk types.TipSetKey, sector abi.SectorNumber) (bool, error) {
|
|
|
|
dls, err := m.Api.StateMinerDeadlines(ctx, m.maddr, tsk)
|
2022-02-01 06:09:42 +00:00
|
|
|
if err != nil {
|
2022-06-16 10:34:29 +00:00
|
|
|
return false, xerrors.Errorf("getting proving deadlines: %w", err)
|
2022-02-01 06:09:42 +00:00
|
|
|
}
|
2022-02-01 06:09:42 +00:00
|
|
|
|
2022-06-16 10:34:29 +00:00
|
|
|
for dl := range dls {
|
2022-06-17 09:20:33 +00:00
|
|
|
parts, err := m.Api.StateMinerPartitions(ctx, m.maddr, uint64(dl), tsk)
|
2022-06-16 10:34:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return false, xerrors.Errorf("getting partitions for deadline %d: %w", dl, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for p, part := range parts {
|
|
|
|
set, err := part.ActiveSectors.IsSet(uint64(sector))
|
|
|
|
if err != nil {
|
|
|
|
return false, xerrors.Errorf("checking if sector %d is in deadline %d partition %d: %w", sector, dl, p, err)
|
|
|
|
}
|
|
|
|
if set {
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false, nil
|
2022-02-01 06:09:42 +00:00
|
|
|
}
|