Skip to content

Commit

Permalink
fix: don't report latency stats on late blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
0x416e746f6e committed Mar 18, 2024
1 parent d8e279b commit 6770a87
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
11 changes: 10 additions & 1 deletion server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ func (s *Server) handleEventEthNewHeader(
e := g.Endpoint(ename)

e.RegisterBlock(block, ts)
latency_s := g.RegisterBlockAndGetLatency(block, ts).Seconds()
latency := g.RegisterBlockAndGetLatency(block, ts)
if latency == state.Infinity {
l.Warn("Skipping reporting block-latency on a very late block",
zap.String("block", block.String()),
zap.String("endpoint_group", gname),
zap.String("endpoint_name", ename),
)
return
}
latency_s := latency.Seconds()

attrs := []attribute.KeyValue{
{Key: keyTargetName, Value: attribute.StringValue(ename)},
Expand Down
20 changes: 9 additions & 11 deletions state/el_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (
"github.com/flashbots/node-monitor/utils"
)

const (
Infinity = time.Duration(9223372036854775807)
)

const (
maxHistoryBlocks = 1024
)
Expand Down Expand Up @@ -88,19 +92,13 @@ func (g *ELGroup) RegisterBlockAndGetLatency(block *big.Int, ts time.Time) time.
g.mx.RLock()
}

// fill in the gaps (in case of missed block)
if prevTS, exists := g.blockTimes[blockStr]; !exists || ts.Before(prevTS) {
g.mx.RUnlock()
g.mx.Lock()
if prevTS, exists := g.blockTimes[blockStr]; !exists || ts.Before(prevTS) {
delete(g.blockTimes, g.blocks.InsertAndPop(blockStr))
g.blockTimes[blockStr] = ts
}
g.mx.Unlock()
g.mx.RLock()
prevTS, exists := g.blockTimes[blockStr]
if !exists {
// we don't want to report (false) statistics on obviously late blocks
return Infinity
}

return ts.Sub(g.blockTimes[blockStr])
return ts.Sub(prevTS)
}

func (g *ELGroup) TimeSinceHighestBlock() (block int64, timeSince time.Duration) {
Expand Down

0 comments on commit 6770a87

Please sign in to comment.