Commit cde1ab96 authored by Ethen Pociask's avatar Ethen Pociask

[indexer.bridge_offset_fix] Updated starting height logic

parent e178ea1a
......@@ -54,6 +54,12 @@ The indexer service is responsible for polling and processing real-time batches
* Process and persist new bridge events
* Synchronize L1 proven/finalized withdrawals with their L2 initialization counterparts
### 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.
......
......@@ -5,7 +5,6 @@ import (
"fmt"
"math/big"
"github.com/ethereum-optimism/optimism/indexer/bigint"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
......@@ -171,14 +170,11 @@ func (db *blocksDB) LatestObservedEpoch(fromL1Height *big.Int, maxL1Range uint64
// We use timestamps since that translates to both L1 & L2
var fromTimestamp, toTimestamp uint64
if fromL1Height == nil {
fromL1Height = bigint.Zero
}
// Lower Bound (the default `fromTimestamp = l1_starting_heigh` (default=0) suffices genesis representation)
if fromL1Height.BitLen() > 0 {
if fromL1Height != nil {
var header L1BlockHeader
result := db.gorm.Where("number = ?", fromL1Height).Take(&header)
// TODO - Embed logging to db
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,
......@@ -189,6 +185,17 @@ func (db *blocksDB) LatestObservedEpoch(fromL1Height *big.Int, maxL1Range uint64
}
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`)
......
......@@ -98,9 +98,6 @@ func (b *BridgeProcessor) run() error {
var lastEpoch *big.Int
if b.LatestL1Header != nil {
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)
......
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