Skip to content

Commit

Permalink
indexer: Fix startup errors
Browse files Browse the repository at this point in the history
- The block locator was being initialized with a zero hash, which caused `Update` return `nil` and crash the process.
- Adds an L2 conf depth parameter, since L2 can now reorg.
  • Loading branch information
mslipper committed Jan 11, 2023
1 parent 585a94a commit ecf0cc5
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .changeset/slimy-files-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/indexer': minor
---

Fix startup issues, add L2 conf depth
13 changes: 9 additions & 4 deletions indexer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ type Config struct {
// L1StartBlockNumber is the block number to start indexing L1 from.
L1StartBlockNumber uint64

// ConfDepth is the number of confirmations after which headers are
// considered confirmed.
ConfDepth uint64
// L1ConfDepth is the number of confirmations after which headers are
// considered confirmed on L1.
L1ConfDepth uint64

// L2ConfDepth is the number of confirmations after which headers are
// considered confirmed on L2.
L2ConfDepth uint64

// MaxHeaderBatchSize is the maximum number of headers to request as a
// batch.
Expand Down Expand Up @@ -122,7 +126,8 @@ func NewConfig(ctx *cli.Context) (Config, error) {
LogLevel: ctx.GlobalString(flags.LogLevelFlag.Name),
LogTerminal: ctx.GlobalBool(flags.LogTerminalFlag.Name),
L1StartBlockNumber: ctx.GlobalUint64(flags.L1StartBlockNumberFlag.Name),
ConfDepth: ctx.GlobalUint64(flags.ConfDepthFlag.Name),
L1ConfDepth: ctx.GlobalUint64(flags.L1ConfDepthFlag.Name),
L2ConfDepth: ctx.GlobalUint64(flags.L2ConfDepthFlag.Name),
MaxHeaderBatchSize: ctx.GlobalUint64(flags.MaxHeaderBatchSizeFlag.Name),
MetricsServerEnable: ctx.GlobalBool(flags.MetricsServerEnableFlag.Name),
RESTHostname: ctx.GlobalString(flags.RESTHostnameFlag.Name),
Expand Down
17 changes: 12 additions & 5 deletions indexer/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,17 @@ var (
Value: 0,
EnvVar: prefixEnvVar("START_BLOCK_NUMBER"),
}
ConfDepthFlag = cli.Uint64Flag{
Name: "conf-depth",
Usage: "The number of confirmations after which headers are considered confirmed",
L1ConfDepthFlag = cli.Uint64Flag{
Name: "l1-conf-depth",
Usage: "The number of confirmations after which headers are considered confirmed on L1",
Value: 20,
EnvVar: prefixEnvVar("CONF_DEPTH"),
EnvVar: prefixEnvVar("L1_CONF_DEPTH"),
}
L2ConfDepthFlag = cli.Uint64Flag{
Name: "l2-conf-depth",
Usage: "The number of confirmations after which headers are considered confirmed on L1",
Value: 24,
EnvVar: prefixEnvVar("L2_CONF_DEPTH"),
}
MaxHeaderBatchSizeFlag = cli.Uint64Flag{
Name: "max-header-batch-size",
Expand Down Expand Up @@ -203,7 +209,8 @@ var optionalFlags = []cli.Flag{
SentryEnableFlag,
SentryDsnFlag,
SentryTraceRateFlag,
ConfDepthFlag,
L1ConfDepthFlag,
L2ConfDepthFlag,
MaxHeaderBatchSizeFlag,
L1StartBlockNumberFlag,
RESTHostnameFlag,
Expand Down
4 changes: 2 additions & 2 deletions indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func NewIndexer(cfg Config) (*Indexer, error) {
ChainID: new(big.Int).SetUint64(cfg.ChainID),
AddressManager: addrManager,
DB: db,
ConfDepth: cfg.ConfDepth,
ConfDepth: cfg.L1ConfDepth,
MaxHeaderBatchSize: cfg.MaxHeaderBatchSize,
StartBlockNumber: cfg.L1StartBlockNumber,
Bedrock: cfg.Bedrock,
Expand All @@ -179,7 +179,7 @@ func NewIndexer(cfg Config) (*Indexer, error) {
L2RPC: l2RPC,
L2Client: l2Client,
DB: db,
ConfDepth: cfg.ConfDepth,
ConfDepth: cfg.L2ConfDepth,
MaxHeaderBatchSize: cfg.MaxHeaderBatchSize,
StartBlockNumber: uint64(0),
Bedrock: cfg.Bedrock,
Expand Down
3 changes: 2 additions & 1 deletion indexer/integration_tests/bedrock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ func TestBedrockIndexer(t *testing.T) {
LogLevel: "info",
LogTerminal: true,
L1StartBlockNumber: 0,
ConfDepth: 1,
L1ConfDepth: 1,
L2ConfDepth: 1,
MaxHeaderBatchSize: 2,
RESTHostname: "127.0.0.1",
RESTPort: 7980,
Expand Down
56 changes: 35 additions & 21 deletions indexer/services/l1/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type Service struct {
batchScanner *scc.StateCommitmentChainFilterer
latestHeader uint64
headerSelector *ConfirmedHeaderSelector
l1Client *ethclient.Client

metrics *metrics.Metrics
tokenCache map[common.Address]*db.Token
Expand Down Expand Up @@ -143,6 +144,7 @@ func NewService(cfg ServiceConfig) (*Service, error) {
ZeroAddress: db.ETHL1Token,
},
isBedrock: cfg.Bedrock,
l1Client: cfg.L1Client,
}
service.wg.Add(1)
return service, nil
Expand Down Expand Up @@ -202,16 +204,22 @@ func (s *Service) loop() {
}

func (s *Service) Update(newHeader *types.Header) error {
var lowest = db.BlockLocator{
Number: s.cfg.StartBlockNumber,
}
var lowest db.BlockLocator
highestConfirmed, err := s.cfg.DB.GetHighestL1Block()
if err != nil {
return err
}
if highestConfirmed != nil {
lowest = *highestConfirmed
if highestConfirmed == nil {
startHeader, err := s.l1Client.HeaderByNumber(s.ctx, new(big.Int).SetUint64(s.cfg.StartBlockNumber))
if err != nil {
return fmt.Errorf("error fetching header by number: %w", err)
}
highestConfirmed = &db.BlockLocator{
Number: s.cfg.StartBlockNumber,
Hash: startHeader.Hash(),
}
}
lowest = *highestConfirmed

headers, err := s.headerSelector.NewHead(s.ctx, lowest.Number, newHeader, s.cfg.RawL1Client)
if err != nil {
Expand Down Expand Up @@ -260,22 +268,28 @@ func (s *Service) Update(newHeader *types.Header) error {
bridgeDepositsCh <- deposits
}(bridgeImpl)
}
go func() {
provenWithdrawals, err := s.portal.GetProvenWithdrawalsByBlockRange(s.ctx, startHeight, endHeight)
if err != nil {
errCh <- err
return
}
provenWithdrawalsCh <- provenWithdrawals
}()
go func() {
finalizedWithdrawals, err := s.portal.GetFinalizedWithdrawalsByBlockRange(s.ctx, startHeight, endHeight)
if err != nil {
errCh <- err
return
}
finalizedWithdrawalsCh <- finalizedWithdrawals
}()

if s.isBedrock {
go func() {
provenWithdrawals, err := s.portal.GetProvenWithdrawalsByBlockRange(s.ctx, startHeight, endHeight)
if err != nil {
errCh <- err
return
}
provenWithdrawalsCh <- provenWithdrawals
}()
go func() {
finalizedWithdrawals, err := s.portal.GetFinalizedWithdrawalsByBlockRange(s.ctx, startHeight, endHeight)
if err != nil {
errCh <- err
return
}
finalizedWithdrawalsCh <- finalizedWithdrawals
}()
} else {
provenWithdrawalsCh <- make(bridge.ProvenWithdrawalsMap)
finalizedWithdrawalsCh <- make(bridge.FinalizedWithdrawalsMap)
}

var receives int
for {
Expand Down

0 comments on commit ecf0cc5

Please sign in to comment.