Skip to content

Commit

Permalink
optimize block event source
Browse files Browse the repository at this point in the history
  • Loading branch information
cryi committed Jul 29, 2024
1 parent d91b387 commit fac57c0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 9 additions & 1 deletion core/common/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,16 @@ func (es *BlockEventSource) RemoveBlockMonitor(id uuid.UUID) {
}

func NewBlockEventSource() *BlockEventSource {
lastLevel := int64(0)

return &BlockEventSource{
EventSource: NewEventSource[*rpc.BlockHeaderLogEntry](nil),
EventSource: NewEventSource(func(h *rpc.BlockHeaderLogEntry) bool {
if h.Level <= lastLevel {
return true
}
lastLevel = h.Level
return false
}),
blockMonitors: make(map[uuid.UUID]blockMonitor),
}
}
Expand Down
8 changes: 1 addition & 7 deletions core/providers/tezbake/baker.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ func setupBakerStatusProviders(ctx context.Context, bakers []string, statusChann
common.UnsubscribeFromBlockHeaderEvents(blockChannelId)
}()

level := int64(0)

for {
select {
case <-ctx.Done():
Expand All @@ -133,17 +131,13 @@ func setupBakerStatusProviders(ctx context.Context, bakers []string, statusChann
return
}

if level >= block.Level {
continue
}

bakersStatus := map[string]*BakerStakingStatus{}
for _, baker := range bakers {
bakersStatus[baker], _ = getBakerStatusFor(ctx, baker)
}
statusChannel <- &BakersStatusUpdate{
BakersStatus: BakersStatus{
Level: level,
Level: block.Level,
Bakers: bakersStatus,
},
}
Expand Down

0 comments on commit fac57c0

Please sign in to comment.