Skip to content

Commit fb98a8c

Browse files
committed
ethstats: cut short unavailable history responses
1 parent 96d1a4a commit fb98a8c

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎ethstats/ethstats.go‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ func (s *Service) reportHistory(conn *websocket.Conn, list []uint64) error {
537537
// Gather the batch of blocks to report
538538
history := make([]*blockStats, len(indexes))
539539
for i, number := range indexes {
540+
// Retrieve the next block if it's known to us
540541
var block *types.Block
541542
if s.eth != nil {
542543
block = s.eth.BlockChain().GetBlockByNumber(number)
@@ -545,13 +546,20 @@ func (s *Service) reportHistory(conn *websocket.Conn, list []uint64) error {
545546
block = types.NewBlockWithHeader(header)
546547
}
547548
}
549+
// If we do have the block, add to the history and continue
548550
if block != nil {
549551
history[len(history)-1-i] = s.assembleBlockStats(block)
552+
continue
550553
}
554+
// Ran out of blocks, cut the report short and send
555+
history = history[len(history)-i:]
551556
}
552557
// Assemble the history report and send it to the server
553-
log.Trace("Sending historical blocks to ethstats", "first", history[0].Number, "last", history[len(history)-1].Number)
554-
558+
if len(history) > 0 {
559+
log.Trace("Sending historical blocks to ethstats", "first", history[0].Number, "last", history[len(history)-1].Number)
560+
} else {
561+
log.Trace("No history to send to stats server")
562+
}
555563
stats := map[string]interface{}{
556564
"id": s.node,
557565
"history": history,

0 commit comments

Comments
 (0)