-
Notifications
You must be signed in to change notification settings - Fork 64
/
resolver_sealingpipeline.go
275 lines (234 loc) · 6.11 KB
/
resolver_sealingpipeline.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
package gql
import (
"context"
gqltypes "github.com/filecoin-project/boost/gql/types"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/api/v1api"
"github.com/filecoin-project/lotus/chain/types"
"github.com/graph-gophers/graphql-go"
)
// query: sealingpipeline: [SealingPipeline]
func (r *resolver) SealingPipeline(ctx context.Context) (*sealingPipelineState, error) {
res, err := r.spApi.WorkerJobs(ctx)
if err != nil {
return nil, err
}
var workers []*worker
for workerId, jobs := range res {
for _, j := range jobs {
workers = append(workers, &worker{
ID: workerId.String(),
Start: graphql.Time{Time: j.Start},
Stage: j.Task.Short(),
Sector: int32(j.Sector.Number),
})
}
}
summary, err := r.spApi.SectorsSummary(ctx)
if err != nil {
return nil, err
}
minerAddr, err := r.spApi.ActorAddress(ctx)
if err != nil {
return nil, err
}
ssize, err := getSectorSize(ctx, r.fullNode, minerAddr)
if err != nil {
return nil, err
}
wdSectors, err := r.spApi.SectorsListInStates(ctx, []api.SectorState{"WaitDeals"})
if err != nil {
return nil, err
}
sdwdSectors, err := r.spApi.SectorsListInStates(ctx, []api.SectorState{"SnapDealsWaitDeals"})
if err != nil {
return nil, err
}
waitDealsSectors, err := r.populateWaitDealsSectors(ctx, wdSectors, ssize)
if err != nil {
return nil, err
}
snapDealsWaitDealsSectors, err := r.populateWaitDealsSectors(ctx, sdwdSectors, ssize)
if err != nil {
return nil, err
}
var ss sectorStates
for order, state := range allSectorStates {
count, ok := summary[api.SectorState(state)]
if !ok {
continue
}
if count == 0 {
continue
}
if _, ok := normalSectors[state]; ok {
ss.Regular = append(ss.Regular, §orState{
Key: state,
Value: int32(count),
Order: int32(order),
})
continue
}
if _, ok := normalErredSectors[state]; ok {
ss.RegularError = append(ss.RegularError, §orState{
Key: state,
Value: int32(count),
Order: int32(order),
})
continue
}
if _, ok := snapdealsSectors[state]; ok {
ss.SnapDeals = append(ss.SnapDeals, §orState{
Key: state,
Value: int32(count),
Order: int32(order),
})
continue
}
if _, ok := snapdealsSectors[state]; ok {
ss.SnapDealsError = append(ss.SnapDealsError, §orState{
Key: state,
Value: int32(count),
Order: int32(order),
})
continue
}
}
return &sealingPipelineState{
WaitDealsSectors: waitDealsSectors,
SnapDealsWaitDealsSectors: snapDealsWaitDealsSectors,
SectorStates: ss,
Workers: workers,
}, nil
}
type sectorState struct {
Key string
Value int32
Order int32
}
type waitDeal struct {
ID graphql.ID
Size gqltypes.Uint64
IsLegacy bool
}
type waitDealSector struct {
SectorID gqltypes.Uint64
Deals []*waitDeal
Used gqltypes.Uint64
SectorSize gqltypes.Uint64
}
type sectorStates struct {
Regular []*sectorState
SnapDeals []*sectorState
RegularError []*sectorState
SnapDealsError []*sectorState
}
type worker struct {
ID string
Start graphql.Time
Stage string
Sector int32
}
type sealingPipelineState struct {
WaitDealsSectors []*waitDealSector
SnapDealsWaitDealsSectors []*waitDealSector
SectorStates sectorStates
Workers []*worker
}
func getSectorSize(ctx context.Context, fullNode v1api.FullNode, maddr address.Address) (uint64, error) {
mi, err := fullNode.StateMinerInfo(ctx, maddr, types.EmptyTSK)
if err != nil {
return 0, err
}
return uint64(mi.SectorSize), nil
}
func (r *resolver) populateWaitDealsSectors(ctx context.Context, sectorNumbers []abi.SectorNumber, ssize uint64) ([]*waitDealSector, error) {
waitDealsSectors := []*waitDealSector{}
for _, s := range sectorNumbers {
used := uint64(0)
deals := []*waitDeal{}
wdSectorStatus, err := r.spApi.SectorsStatus(ctx, s, false)
if err != nil {
return nil, err
}
for _, p := range wdSectorStatus.Pieces {
if p.DealInfo == nil {
continue
}
publishCid := p.DealInfo.PublishCid
if publishCid == nil {
continue
}
dcid, err := p.DealInfo.DealProposal.Cid()
if err != nil {
return nil, err
}
ds, err := r.dealsByPublishCID(ctx, *publishCid)
if err != nil {
return nil, err
}
var i int
if len(ds) > 1 { // compare by deal proposal cid
for ; i < len(ds); i++ {
cid, err := ds[i].ClientDealProposal.Proposal.Cid()
if err != nil {
return nil, err
}
if cid.Equals(dcid) {
break
}
}
}
// we matched the deal from piece with a deal from the boost db
// single deal in publish message; i == 0; len(ds) == 1;
// multiple deals in publish message; i == smth; len(ds) > 1;
if i < len(ds) {
deals = append(deals, &waitDeal{
ID: graphql.ID(ds[i].DealUuid.String()),
Size: gqltypes.Uint64(p.Piece.Size),
IsLegacy: false,
})
used += uint64(p.Piece.Size)
continue
}
// match not found in boost db - fallback to legacy deals list
lds, err := r.legacyProv.ListLocalDeals()
if err != nil {
return nil, err
}
var j int
for ; j < len(lds); j++ {
l := lds[j]
if l.PublishCid == nil {
continue
}
lpcid, err := l.ClientDealProposal.Proposal.Cid()
if err != nil {
return nil, err
}
if l.PublishCid.Equals(*publishCid) && lpcid.Equals(dcid) {
break
}
}
if j == len(lds) {
log.Errorw("couldnt match deal to boost or legacy market deal based on publish cid and proposal cid", "publishCid", publishCid, "dealProposalCid", dcid)
continue
}
deals = append(deals, &waitDeal{
ID: graphql.ID(lds[j].ProposalCid.String()),
Size: gqltypes.Uint64(p.Piece.Size),
IsLegacy: true,
})
used += uint64(p.Piece.Size)
}
waitDealsSectors = append(waitDealsSectors, &waitDealSector{
SectorID: gqltypes.Uint64(s),
Deals: deals,
Used: gqltypes.Uint64(used),
SectorSize: gqltypes.Uint64(ssize),
})
}
return waitDealsSectors, nil
}