@@ -126,7 +126,7 @@ func (c *cfg) getSectors(w http.ResponseWriter, r *http.Request) {
126
126
Miner int64 `db:"sp_id"`
127
127
Sector int64 `db:"sector_number"`
128
128
}
129
- var sectors []sector
129
+ var sectors []* sector
130
130
var pieces []piece
131
131
132
132
apihelper .OrHTTPFail (w , c .DB .Select (r .Context (), & sectors , `SELECT
@@ -143,12 +143,12 @@ func (c *cfg) getSectors(w http.ResponseWriter, r *http.Request) {
143
143
mID int64
144
144
sNum uint64
145
145
}
146
- sectorIdx := map [sectorID ]int {}
146
+ sectorIdx := map [sectorID ]* sector {}
147
147
for i , s := range sectors {
148
148
sectors [i ].HasSealed = s .SectorFiletype & int (storiface .FTSealed ) != 0 || s .SectorFiletype & int (storiface .FTUpdate ) != 0
149
149
sectors [i ].HasUnsealed = s .SectorFiletype & int (storiface .FTUnsealed ) != 0
150
150
sectors [i ].HasSnap = s .SectorFiletype & int (storiface .FTUpdate ) != 0
151
- sectorIdx [sectorID {s .MinerID , uint64 (s .SectorNum )}] = i
151
+ sectorIdx [sectorID {s .MinerID , uint64 (s .SectorNum )}] = sectors [ i ]
152
152
addr , err := address .NewIDAddress (uint64 (s .MinerID ))
153
153
apihelper .OrHTTPFail (w , err )
154
154
sectors [i ].MinerAddress = addr
@@ -190,29 +190,35 @@ func (c *cfg) getSectors(w http.ResponseWriter, r *http.Request) {
190
190
apihelper .OrHTTPFail (w , err )
191
191
for _ , chainy := range onChainInfo {
192
192
st := chainy .onChain
193
- if i , ok := sectorIdx [sectorID {minerID , uint64 (st .SectorNumber )}]; ok {
194
- sectors [ i ] .IsOnChain = true
195
- sectors [ i ] .ExpiresAt = st .Expiration
196
- sectors [ i ] .IsFilPlus = st .VerifiedDealWeight .GreaterThan (big .NewInt (0 ))
193
+ if s , ok := sectorIdx [sectorID {minerID , uint64 (st .SectorNumber )}]; ok {
194
+ s .IsOnChain = true
195
+ s .ExpiresAt = st .Expiration
196
+ s .IsFilPlus = st .VerifiedDealWeight .GreaterThan (big .NewInt (0 ))
197
197
if ss , err := st .SealProof .SectorSize (); err == nil {
198
- sectors [ i ] .SealInfo = ss .ShortString ()
198
+ s .SealInfo = ss .ShortString ()
199
199
}
200
- sectors [ i ] .Proving = chainy .active
200
+ s .Proving = chainy .active
201
201
if st .Expiration < head .Height () {
202
202
delete (sectorIdx , sectorID {minerID , uint64 (st .SectorNumber )})
203
- sectors = append (sectors [:i ], sectors [i + 1 :]... )
203
+ // find s in sectors and remove it
204
+ for i , st := range sectors {
205
+ if s .SectorNum == st .SectorNum && s .MinerID == st .MinerID {
206
+ sectors = append (sectors [:i ], sectors [i + 1 :]... )
207
+ break
208
+ }
209
+ }
204
210
continue
205
211
}
206
212
207
213
dw , vp := .0 , .0
208
214
f05 , ddo := 0 , 0
209
215
var pi []piece
210
- if j , ok := pieceIndex [sectorID {sectors [ i ] .MinerID , uint64 (sectors [ i ] .SectorNum )}]; ok {
216
+ if j , ok := pieceIndex [sectorID {s .MinerID , uint64 (s .SectorNum )}]; ok {
211
217
for _ , k := range j {
212
218
pi = append (pi , pieces [k ])
213
219
}
214
220
}
215
- estimate := st .Expiration - st .Activation <= 0 || sectors [ i ] .HasSnap
221
+ estimate := st .Expiration - st .Activation <= 0 || s .HasSnap
216
222
if estimate {
217
223
for _ , p := range pi {
218
224
if p .Proposal != nil {
@@ -248,20 +254,20 @@ func (c *cfg) getSectors(w http.ResponseWriter, r *http.Request) {
248
254
}
249
255
}
250
256
}
251
- sectors [ i ] .DealWeight = "CC"
257
+ s .DealWeight = "CC"
252
258
if dw > 0 {
253
- sectors [ i ] .DealWeight = units .BytesSize (dw )
259
+ s .DealWeight = units .BytesSize (dw )
254
260
}
255
261
if vp > 0 {
256
- sectors [ i ] .DealWeight = units .BytesSize (vp )
262
+ s .DealWeight = units .BytesSize (vp )
257
263
}
258
- sectors [ i ] .Deals = fmt .Sprintf ("Market: %d, DDO: %d" , f05 , ddo )
264
+ s .Deals = fmt .Sprintf ("Market: %d, DDO: %d" , f05 , ddo )
259
265
} else {
260
266
// sector is on chain but not in db
261
267
if st .Expiration < head .Height () {
262
268
continue // skip expired ones
263
269
}
264
- s := sector {
270
+ s := & sector {
265
271
MinerID : minerID ,
266
272
MinerAddress : maddr ,
267
273
SectorNum : int64 (chainy .onChain .SectorNumber ),
@@ -275,6 +281,7 @@ func (c *cfg) getSectors(w http.ResponseWriter, r *http.Request) {
275
281
s .SealInfo = ss .ShortString ()
276
282
}
277
283
sectors = append (sectors , s )
284
+ sectorIdx [sectorID {minerID , uint64 (st .SectorNumber )}] = s
278
285
}
279
286
}
280
287
}
0 commit comments