Commit 7f42e184 authored by Matthew Slipper's avatar Matthew Slipper Committed by GitHub

Merge pull request #2272 from mslipper/bugfix/metrics

indexer: fix metrics, reduce DB load
parents 29799d9d f02b940e
......@@ -43,8 +43,8 @@ func NewMetrics(monitoredTokens map[string]string) *Metrics {
return &Metrics{
SyncHeight: promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "l1_sync_height",
Help: "The max height of the indexer's last batch of L1 blocks.",
Name: "sync_height",
Help: "The max height of the indexer's last batch of L1/L1 blocks.",
Namespace: metricsNamespace,
}, []string{
"chain",
......@@ -66,7 +66,7 @@ func NewMetrics(monitoredTokens map[string]string) *Metrics {
"symbol",
}),
StateBatchesCount: prometheus.NewCounter(prometheus.CounterOpts{
StateBatchesCount: promauto.NewCounter(prometheus.CounterOpts{
Name: "state_batches_count",
Help: "The number of state batches indexed.",
Namespace: metricsNamespace,
......@@ -101,7 +101,7 @@ func NewMetrics(monitoredTokens map[string]string) *Metrics {
"chain",
}),
CachedTokensCount: prometheus.NewCounterVec(prometheus.CounterOpts{
CachedTokensCount: promauto.NewCounterVec(prometheus.CounterOpts{
Name: "cached_tokens_count",
Help: "How many tokens are in the cache",
Namespace: metricsNamespace,
......@@ -118,7 +118,7 @@ func (m *Metrics) SetL1SyncHeight(height uint64) {
}
func (m *Metrics) SetL2SyncHeight(height uint64) {
m.SyncHeight.WithLabelValues("l1").Set(float64(height))
m.SyncHeight.WithLabelValues("l2").Set(float64(height))
}
func (m *Metrics) RecordDeposit(addr common.Address) {
......
......@@ -289,10 +289,15 @@ func (s *Service) Update(newHeader *types.Header) error {
logger.Error("Error querying state batches", "err", err)
}
for _, header := range headers {
for i, header := range headers {
blockHash := header.Hash
number := header.Number.Uint64()
deposits := depositsByBlockHash[blockHash]
batches := stateBatches[blockHash]
if len(deposits) == 0 && len(batches) == 0 && i != len(headers)-1 {
continue
}
block := &db.IndexedL1Block{
Hash: blockHash,
......@@ -313,7 +318,6 @@ func (s *Service) Update(newHeader *types.Header) error {
return err
}
batches := stateBatches[blockHash]
err = s.cfg.DB.AddStateBatch(batches)
if err != nil {
logger.Error(
......
......@@ -267,11 +267,15 @@ func (s *Service) Update(newHeader *types.Header) error {
}
}
for _, header := range headers {
for i, header := range headers {
blockHash := header.Hash()
number := header.Number.Uint64()
withdrawals := withdrawalsByBlockHash[blockHash]
if len(withdrawals) == 0 && i != len(headers)-1 {
continue
}
block := &db.IndexedL2Block{
Hash: blockHash,
ParentHash: header.ParentHash,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment