-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
upgrade_queue.go
77 lines (62 loc) · 2.19 KB
/
upgrade_queue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package sealing
import (
"context"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-state-types/abi"
market7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/market"
"github.com/filecoin-project/lotus/chain/types"
)
func (m *Sealing) MarkForSnapUpgrade(ctx context.Context, id abi.SectorNumber) error {
si, err := m.GetSectorInfo(id)
if err != nil {
return xerrors.Errorf("getting sector info: %w", err)
}
if si.State != Proving {
return xerrors.Errorf("unable to snap-up sectors not in the 'Proving' state")
}
if si.hasDeals() {
return xerrors.Errorf("not a committed-capacity sector, has deals")
}
ts, 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, ts.Key())
if err != nil {
return xerrors.Errorf("failed to read sector on chain info: %w", err)
}
active, err := m.sectorActive(ctx, ts.Key(), id)
if err != nil {
return xerrors.Errorf("failed to check if sector is active")
}
if !active {
return xerrors.Errorf("cannot mark inactive sector for upgrade")
}
if onChainInfo.Expiration-ts.Height() < 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)
}
return m.sectors.Send(uint64(id), SectorMarkForUpdate{})
}
func (m *Sealing) sectorActive(ctx context.Context, tsk types.TipSetKey, sector abi.SectorNumber) (bool, error) {
dls, err := m.Api.StateMinerDeadlines(ctx, m.maddr, tsk)
if err != nil {
return false, xerrors.Errorf("getting proving deadlines: %w", err)
}
for dl := range dls {
parts, err := m.Api.StateMinerPartitions(ctx, m.maddr, uint64(dl), tsk)
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
}