Skip to content

Commit c3d9543

Browse files
authored
webui-sector-panic (#648)
1 parent 7708630 commit c3d9543

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

web/api/sector/sector.go

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (c *cfg) getSectors(w http.ResponseWriter, r *http.Request) {
126126
Miner int64 `db:"sp_id"`
127127
Sector int64 `db:"sector_number"`
128128
}
129-
var sectors []sector
129+
var sectors []*sector
130130
var pieces []piece
131131

132132
apihelper.OrHTTPFail(w, c.DB.Select(r.Context(), &sectors, `SELECT
@@ -143,12 +143,12 @@ func (c *cfg) getSectors(w http.ResponseWriter, r *http.Request) {
143143
mID int64
144144
sNum uint64
145145
}
146-
sectorIdx := map[sectorID]int{}
146+
sectorIdx := map[sectorID]*sector{}
147147
for i, s := range sectors {
148148
sectors[i].HasSealed = s.SectorFiletype&int(storiface.FTSealed) != 0 || s.SectorFiletype&int(storiface.FTUpdate) != 0
149149
sectors[i].HasUnsealed = s.SectorFiletype&int(storiface.FTUnsealed) != 0
150150
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]
152152
addr, err := address.NewIDAddress(uint64(s.MinerID))
153153
apihelper.OrHTTPFail(w, err)
154154
sectors[i].MinerAddress = addr
@@ -190,29 +190,35 @@ func (c *cfg) getSectors(w http.ResponseWriter, r *http.Request) {
190190
apihelper.OrHTTPFail(w, err)
191191
for _, chainy := range onChainInfo {
192192
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))
197197
if ss, err := st.SealProof.SectorSize(); err == nil {
198-
sectors[i].SealInfo = ss.ShortString()
198+
s.SealInfo = ss.ShortString()
199199
}
200-
sectors[i].Proving = chainy.active
200+
s.Proving = chainy.active
201201
if st.Expiration < head.Height() {
202202
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+
}
204210
continue
205211
}
206212

207213
dw, vp := .0, .0
208214
f05, ddo := 0, 0
209215
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 {
211217
for _, k := range j {
212218
pi = append(pi, pieces[k])
213219
}
214220
}
215-
estimate := st.Expiration-st.Activation <= 0 || sectors[i].HasSnap
221+
estimate := st.Expiration-st.Activation <= 0 || s.HasSnap
216222
if estimate {
217223
for _, p := range pi {
218224
if p.Proposal != nil {
@@ -248,20 +254,20 @@ func (c *cfg) getSectors(w http.ResponseWriter, r *http.Request) {
248254
}
249255
}
250256
}
251-
sectors[i].DealWeight = "CC"
257+
s.DealWeight = "CC"
252258
if dw > 0 {
253-
sectors[i].DealWeight = units.BytesSize(dw)
259+
s.DealWeight = units.BytesSize(dw)
254260
}
255261
if vp > 0 {
256-
sectors[i].DealWeight = units.BytesSize(vp)
262+
s.DealWeight = units.BytesSize(vp)
257263
}
258-
sectors[i].Deals = fmt.Sprintf("Market: %d, DDO: %d", f05, ddo)
264+
s.Deals = fmt.Sprintf("Market: %d, DDO: %d", f05, ddo)
259265
} else {
260266
// sector is on chain but not in db
261267
if st.Expiration < head.Height() {
262268
continue // skip expired ones
263269
}
264-
s := sector{
270+
s := &sector{
265271
MinerID: minerID,
266272
MinerAddress: maddr,
267273
SectorNum: int64(chainy.onChain.SectorNumber),
@@ -275,6 +281,7 @@ func (c *cfg) getSectors(w http.ResponseWriter, r *http.Request) {
275281
s.SealInfo = ss.ShortString()
276282
}
277283
sectors = append(sectors, s)
284+
sectorIdx[sectorID{minerID, uint64(st.SectorNumber)}] = s
278285
}
279286
}
280287
}

0 commit comments

Comments
 (0)