Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions go/indexer/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we are using a single metric with l1/l2 labels. Should the Help comment below be updated to reflect the same?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good catch. Fixing now.

Help: "The max height of the indexer's last batch of L1/L1 blocks.",
Namespace: metricsNamespace,
}, []string{
"chain",
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
12 changes: 8 additions & 4 deletions go/indexer/services/l1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ type Service struct {
latestHeader uint64
headerSelector *ConfirmedHeaderSelector

metrics *metrics.Metrics
metrics *metrics.Metrics
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure where these came from, gofmt should have fixed them, thanks.

tokenCache map[common.Address]*db.Token
wg sync.WaitGroup
wg sync.WaitGroup
}

type IndexerStatus struct {
Expand Down Expand Up @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, this saves a lot of unnecessary db call preps.

continue
}

block := &db.IndexedL1Block{
Hash: blockHash,
Expand All @@ -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(
Expand Down
28 changes: 16 additions & 12 deletions go/indexer/services/l2/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ func respondWithJSON(w http.ResponseWriter, code int, payload interface{}) {
}

type ServiceConfig struct {
Context context.Context
Metrics *metrics.Metrics
L2Client *l2ethclient.Client
ChainID *big.Int
ConfDepth uint64
MaxHeaderBatchSize uint64
StartBlockNumber uint64
StartBlockHash string
DB *db.Database
Context context.Context
Metrics *metrics.Metrics
L2Client *l2ethclient.Client
ChainID *big.Int
ConfDepth uint64
MaxHeaderBatchSize uint64
StartBlockNumber uint64
StartBlockHash string
DB *db.Database
}

type Service struct {
Expand All @@ -89,9 +89,9 @@ type Service struct {
latestHeader uint64
headerSelector *ConfirmedHeaderSelector

metrics *metrics.Metrics
metrics *metrics.Metrics
tokenCache map[common.Address]*db.Token
wg sync.WaitGroup
wg sync.WaitGroup
}

type IndexerStatus struct {
Expand Down Expand Up @@ -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,
Expand Down