Skip to content

Commit

Permalink
right size of elements removed to keep the size within maxDataPoints
Browse files Browse the repository at this point in the history
  • Loading branch information
gatsbyz committed Dec 11, 2023
1 parent 67ba980 commit de65e0c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cmd/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ func monitor(ctx context.Context) error {

ms := new(monitorStatus)
ms.BlocksLock.Lock()
ms.BlockCache, _ = lru.New(blockCacheLimit)
ms.BlockCache, err = lru.New(blockCacheLimit)
if err != nil {
log.Error().Err(err).Msg("Failed to create new LRU cache")
return err
}
ms.BlocksLock.Unlock()

ms.ChainID = big.NewInt(0)
Expand Down Expand Up @@ -192,7 +196,7 @@ func fetchBlocks(ctx context.Context, ec *ethclient.Client, ms *monitorStatus, r
}
observedPendingTxs = append(observedPendingTxs, historicalDataPoint{SampleTime: time.Now(), SampleValue: float64(cs.PendingCount)})
if len(observedPendingTxs) > maxDataPoints {
observedPendingTxs = observedPendingTxs[1:]
observedPendingTxs = observedPendingTxs[len(observedPendingTxs)-maxDataPoints:]
}

log.Debug().Uint64("PeerCount", cs.PeerCount).Uint64("ChainID", cs.ChainID.Uint64()).Uint64("HeadBlock", cs.HeadBlock).Uint64("GasPrice", cs.GasPrice.Uint64()).Msg("Fetching blocks")
Expand Down

0 comments on commit de65e0c

Please sign in to comment.