Skip to content

Commit

Permalink
fix: add lk.Lock() and move the map copy to avoid miner crash
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRuen committed Nov 3, 2023
1 parent 02929dd commit c0c4e6b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
10 changes: 1 addition & 9 deletions node/impl/storminer.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,7 @@ func (sm *StorageMinerAPI) SectorsListInStates(ctx context.Context, states []api

// Use SectorsSummary from stats (prometheus) for faster result
func (sm *StorageMinerAPI) SectorsSummary(ctx context.Context) (map[api.SectorState]int, error) {
sectorStats := sm.Miner.SectorsSummary(ctx)
out := make(map[api.SectorState]int)

for st, count := range sectorStats {
state := api.SectorState(st)
out[state] = int(count)
}

return out, nil
return sm.Miner.SectorsSummary(ctx), nil
}

func (sm *StorageMinerAPI) StorageLocal(ctx context.Context) (map[storiface.ID]string, error) {
Expand Down
14 changes: 12 additions & 2 deletions storage/pipeline/sealing.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,18 @@ func (m *Sealing) TerminateSector(ctx context.Context, sid abi.SectorNumber) err
return m.sectors.Send(uint64(sid), SectorTerminate{})
}

func (m *Sealing) SectorsSummary(ctx context.Context) map[SectorState]int64 {
return m.stats.byState
func (m *Sealing) SectorsSummary(ctx context.Context) map[api.SectorState]int {
m.stats.lk.Lock()
defer m.stats.lk.Unlock()

out := make(map[api.SectorState]int)

for st, count := range m.stats.byState {
state := api.SectorState(st)
out[state] = int(count)
}

return out
}

func (m *Sealing) TerminateFlush(ctx context.Context) (*cid.Cid, error) {
Expand Down

0 comments on commit c0c4e6b

Please sign in to comment.