Commit cde1ab96 authored by Ethen Pociask's avatar Ethen Pociask

[indexer.bridge_offset_fix] Updated starting height logic

parent e178ea1a
...@@ -54,11 +54,17 @@ The indexer service is responsible for polling and processing real-time batches ...@@ -54,11 +54,17 @@ The indexer service is responsible for polling and processing real-time batches
* Process and persist new bridge events * Process and persist new bridge events
* Synchronize L1 proven/finalized withdrawals with their L2 initialization counterparts * Synchronize L1 proven/finalized withdrawals with their L2 initialization counterparts
#### API
### L1 Polling
L1 blocks are only indexed if they contain:
- L1 system contract events
- Batch commitment events
#### API
The indexer service runs a lightweight health server adjacently to the main service. The health server exposes a single endpoint `/healthz` that can be used to check the health of the indexer service. The health assessment doesn't check dependency health (ie. database) but rather checks the health of the indexer service itself. The indexer service runs a lightweight health server adjacently to the main service. The health server exposes a single endpoint `/healthz` that can be used to check the health of the indexer service. The health assessment doesn't check dependency health (ie. database) but rather checks the health of the indexer service itself.
### Database ### Database
The indexer service currently supports a Postgres database for storing L1/L2 OP Stack chain data. The most up-to-date database schemas can be found in the `./migrations` directory. The indexer service currently supports a Postgres database for storing L1/L2 OP Stack chain data. The most up-to-date database schemas can be found in the `./migrations` directory.
## Metrics ## Metrics
The indexer services exposes a set of Prometheus metrics that can be used to monitor the health of the service. The metrics are exposed via the `/metrics` endpoint on the health server. The indexer services exposes a set of Prometheus metrics that can be used to monitor the health of the service. The metrics are exposed via the `/metrics` endpoint on the health server.
\ No newline at end of file \ No newline at end of file
...@@ -5,7 +5,6 @@ import ( ...@@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"math/big" "math/big"
"github.com/ethereum-optimism/optimism/indexer/bigint"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
...@@ -171,14 +170,11 @@ func (db *blocksDB) LatestObservedEpoch(fromL1Height *big.Int, maxL1Range uint64 ...@@ -171,14 +170,11 @@ func (db *blocksDB) LatestObservedEpoch(fromL1Height *big.Int, maxL1Range uint64
// We use timestamps since that translates to both L1 & L2 // We use timestamps since that translates to both L1 & L2
var fromTimestamp, toTimestamp uint64 var fromTimestamp, toTimestamp uint64
if fromL1Height == nil {
fromL1Height = bigint.Zero
}
// Lower Bound (the default `fromTimestamp = l1_starting_heigh` (default=0) suffices genesis representation) // Lower Bound (the default `fromTimestamp = l1_starting_heigh` (default=0) suffices genesis representation)
if fromL1Height.BitLen() > 0 { if fromL1Height != nil {
var header L1BlockHeader var header L1BlockHeader
result := db.gorm.Where("number = ?", fromL1Height).Take(&header) result := db.gorm.Where("number = ?", fromL1Height).Take(&header)
// TODO - Embed logging to db
if result.Error != nil { if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) { if errors.Is(result.Error, gorm.ErrRecordNotFound) {
log.Warn("Could not fetch latest L1 block header in bridge processor", "number", fromL1Height, log.Warn("Could not fetch latest L1 block header in bridge processor", "number", fromL1Height,
...@@ -189,6 +185,17 @@ func (db *blocksDB) LatestObservedEpoch(fromL1Height *big.Int, maxL1Range uint64 ...@@ -189,6 +185,17 @@ func (db *blocksDB) LatestObservedEpoch(fromL1Height *big.Int, maxL1Range uint64
} }
fromTimestamp = header.Timestamp fromTimestamp = header.Timestamp
} else {
var header L1BlockHeader
result := db.gorm.Order("number desc").Take(&header)
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
log.Warn("Could not fetch latest L1 block header in bridge processor", "number", fromL1Height,
"processor", "bridge")
return nil, nil
}
return nil, result.Error
}
} }
// Upper Bound (lowest timestamp indexed between L1/L2 bounded by `maxL1Range`) // Upper Bound (lowest timestamp indexed between L1/L2 bounded by `maxL1Range`)
......
...@@ -98,9 +98,6 @@ func (b *BridgeProcessor) run() error { ...@@ -98,9 +98,6 @@ func (b *BridgeProcessor) run() error {
var lastEpoch *big.Int var lastEpoch *big.Int
if b.LatestL1Header != nil { if b.LatestL1Header != nil {
lastEpoch = b.LatestL1Header.Number lastEpoch = b.LatestL1Header.Number
} else {
b.log.Info("starting processing from supplied genesis epoch", "l1_starting_number", b.chainConfig.L1StartingHeight)
lastEpoch = big.NewInt(int64(b.chainConfig.L1StartingHeight))
} }
latestEpoch, err := b.db.Blocks.LatestObservedEpoch(lastEpoch, maxEpochRange) latestEpoch, err := b.db.Blocks.LatestObservedEpoch(lastEpoch, maxEpochRange)
......
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