2020-07-01 13:30:25 +00:00
|
|
|
package sealing
|
|
|
|
|
|
|
|
import (
|
2020-07-15 14:51:02 +00:00
|
|
|
"context"
|
|
|
|
|
2022-02-01 06:09:42 +00:00
|
|
|
"github.com/filecoin-project/go-address"
|
2021-12-08 17:11:19 +00:00
|
|
|
market7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/market"
|
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"
|
2020-07-01 13:30:25 +00:00
|
|
|
)
|
|
|
|
|
2021-12-08 17:11:19 +00:00
|
|
|
func (m *Sealing) MarkForSnapUpgrade(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 {
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2021-12-08 17:11:19 +00:00
|
|
|
tok, head, err := m.Api.ChainHead(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("couldnt get chain head: %w", err)
|
|
|
|
}
|
|
|
|
onChainInfo, err := m.Api.StateSectorGetInfo(ctx, m.maddr, id, tok)
|
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("failed to read sector on chain info: %w", err)
|
|
|
|
}
|
2020-07-01 13:30:25 +00:00
|
|
|
|
2022-02-01 06:09:42 +00:00
|
|
|
active, err := sectorActive(ctx, m.Api, m.maddr, tok, 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
|
|
|
|
2021-12-08 17:11:19 +00:00
|
|
|
if onChainInfo.Expiration-head < market7.DealMinDuration {
|
|
|
|
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-02-01 06:09:42 +00:00
|
|
|
func sectorActive(ctx context.Context, api SealingAPI, maddr address.Address, tok TipSetToken, sector abi.SectorNumber) (bool, error) {
|
|
|
|
active, err := api.StateMinerActiveSectors(ctx, maddr, tok)
|
|
|
|
if err != nil {
|
|
|
|
return false, xerrors.Errorf("failed to check active sectors: %w", err)
|
|
|
|
}
|
2022-02-01 06:09:42 +00:00
|
|
|
|
|
|
|
// Ensure the upgraded sector is active
|
2022-02-01 06:09:42 +00:00
|
|
|
var found bool
|
|
|
|
for _, si := range active {
|
|
|
|
if si.SectorNumber == sector {
|
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return found, nil
|
|
|
|
}
|