diff --git a/core/common/block.go b/core/common/block.go index 535b651..30b2a5b 100644 --- a/core/common/block.go +++ b/core/common/block.go @@ -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), } } diff --git a/core/providers/tezbake/baker.go b/core/providers/tezbake/baker.go index b3109ec..5afcbf6 100644 --- a/core/providers/tezbake/baker.go +++ b/core/providers/tezbake/baker.go @@ -117,8 +117,6 @@ func setupBakerStatusProviders(ctx context.Context, bakers []string, statusChann common.UnsubscribeFromBlockHeaderEvents(blockChannelId) }() - level := int64(0) - for { select { case <-ctx.Done(): @@ -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, }, }