Skip to content

Commit

Permalink
fix: invalid sp in the sector list page (#152)
Browse files Browse the repository at this point in the history
* fix: invalid sp in the sector list page

* add MinerAddress for getSectors

* fix terminateSectors

* remove json tag
  • Loading branch information
strahe authored Aug 16, 2024
1 parent 5a384d2 commit 1217489
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
32 changes: 19 additions & 13 deletions web/api/sector/sector.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,19 @@ func Routes(r *mux.Router, deps *deps.Deps) {

func (c *cfg) terminateSectors(w http.ResponseWriter, r *http.Request) {
var in []struct {
MinerID uint64
Sector uint64
MinerAddress string
Sector uint64
}
apihelper.OrHTTPFail(w, json.NewDecoder(r.Body).Decode(&in))
toDel := make(map[minerDetail][]sec)
for _, s := range in {
maddr, err := address.NewIDAddress(s.MinerID)
maddr, err := address.NewFromString(s.MinerAddress)
apihelper.OrHTTPFail(w, err)
mid, err := address.IDFromAddress(maddr)
apihelper.OrHTTPFail(w, err)
m := minerDetail{
Addr: maddr,
ID: abi.ActorID(s.MinerID),
ID: abi.ActorID(mid),
}
toDel[m] = append(toDel[m], sec{Sector: abi.SectorNumber(s.Sector), Terminate: false})
}
Expand Down Expand Up @@ -99,6 +101,7 @@ func (c *cfg) getSectors(w http.ResponseWriter, r *http.Request) {
MinerID int64 `db:"miner_id"`
SectorNum int64 `db:"sector_num"`
SectorFiletype int `db:"sector_filetype" json:"-"` // Useless?
MinerAddress address.Address
HasSealed bool
HasUnsealed bool
HasSnap bool
Expand Down Expand Up @@ -148,9 +151,11 @@ func (c *cfg) getSectors(w http.ResponseWriter, r *http.Request) {
sectors[i].HasUnsealed = s.SectorFiletype&int(storiface.FTUnsealed) != 0
sectors[i].HasSnap = s.SectorFiletype&int(storiface.FTUpdate) != 0
sectorIdx[sectorID{s.MinerID, uint64(s.SectorNum)}] = i
addr, err := address.NewIDAddress(uint64(s.MinerID))
apihelper.OrHTTPFail(w, err)
sectors[i].MinerAddress = addr
if _, ok := minerToAddr[s.MinerID]; !ok {
minerToAddr[s.MinerID], err = address.NewIDAddress(uint64(s.MinerID))
apihelper.OrHTTPFail(w, err)
minerToAddr[s.MinerID] = addr
}
}

Expand Down Expand Up @@ -254,13 +259,14 @@ func (c *cfg) getSectors(w http.ResponseWriter, r *http.Request) {
} else {
// sector is on chain but not in db
s := sector{
MinerID: minerID,
SectorNum: int64(chainy.onChain.SectorNumber),
IsOnChain: true,
ExpiresAt: chainy.onChain.Expiration,
IsFilPlus: chainy.onChain.VerifiedDealWeight.GreaterThan(big.NewInt(0)),
Proving: chainy.active,
Flag: true, // All such sectors should be flagged to be terminated
MinerID: minerID,
MinerAddress: maddr,
SectorNum: int64(chainy.onChain.SectorNumber),
IsOnChain: true,
ExpiresAt: chainy.onChain.Expiration,
IsFilPlus: chainy.onChain.VerifiedDealWeight.GreaterThan(big.NewInt(0)),
Proving: chainy.active,
Flag: true, // All such sectors should be flagged to be terminated
}
if ss, err := chainy.onChain.SealProof.SectorSize(); err == nil {
s.SealInfo = ss.ShortString()
Expand Down
8 changes: 4 additions & 4 deletions web/static/sector/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@
ajax: '/api/sector/all',
columns: [
{ title: "", data: null },
{ title: "SpID", data: 'MinerID', },
{ title: "Miner", data: 'MinerAddress', },
{
title: "Sector", data: 'SectorNum', render: function (data, type, row) {
if (type === 'display') {
return `<a href="/pages/sector/?sp=${row.MinerID}&id=${data}">${data}</a>`;
return `<a href="/pages/sector/?sp=${row.MinerAddress}&id=${data}">${data}</a>`;
}
return data;
}
Expand Down Expand Up @@ -106,10 +106,10 @@
text: 'Terminate & Delete',
action: function (e, dt, button, config) {
var res = dt.rows({ selected: true }).data().toArray().map(function (row) {
return { MinerID: row.MinerID, Sector: row.SectorNum };
return { MinerAddress: row.MinerAddress, Sector: row.SectorNum };
});
console.log(res);
var confirmMessage = res.map(obj => `SpID: ${obj.MinerID}, Sector: ${obj.Sector}`).join(", ");
var confirmMessage = res.map(obj => `MinerAddress: ${obj.MinerAddress}, Sector: ${obj.Sector}`).join(", ");

if (confirm("Terminate & Delete: " + confirmMessage)) {
axios.post('/api/sector/terminate', res)
Expand Down

0 comments on commit 1217489

Please sign in to comment.