Skip to content

Commit

Permalink
fix: retry el calls and improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
chliddle committed Dec 11, 2024
1 parent 31ff1e0 commit 5ebb407
Showing 1 changed file with 36 additions and 26 deletions.
62 changes: 36 additions & 26 deletions internal/blockchain/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ func NewBlockProcessor(config *config.Config, metrics *metrics.BlockMetrics, log
}

return &BlockProcessor{
config: config,
logger: logger,
metrics: metrics,
client: client,
config: config,
logger: logger,
metrics: metrics,
client: client,
lastFoundELHeight: 0,
}, nil
}
Expand Down Expand Up @@ -104,32 +104,42 @@ func (p *BlockProcessor) checkExecutionBlocks(clHeight, expectedELHeight int64)
}

foundBlock := false
maxRetries := 6
retryDelay := 2 * time.Second

for height := startHeight; height <= endHeight; height++ {
block, err := p.client.BlockByNumber(context.Background(), big.NewInt(height))
if err != nil {
p.metrics.Errors.Inc()
p.logger.WriteJSONLog("error", "Failed to fetch block", map[string]interface{}{
"height": height,
}, err)
continue
}
for attempt := 0; attempt < maxRetries; attempt++ {
block, err := p.client.BlockByNumber(context.Background(), big.NewInt(height))
if err != nil {
p.metrics.Errors.Inc()
p.logger.WriteJSONLog("error", "Failed to get execution block", map[string]interface{}{
"height": height,
"attempt": attempt + 1,
}, err)
time.Sleep(retryDelay)
continue
}

if block.Coinbase().Hex() == p.config.EVMAddress {
foundBlock = true
p.metrics.ExecutionConfirmed.Inc()
p.lastFoundELHeight = height // Save the found block height
p.logger.WriteJSONLog("success", "Found execution block", map[string]interface{}{
"cl_height": clHeight,
"el_height": height,
"hash": block.Hash().Hex(),
}, nil)

if len(block.Transactions()) == 0 {
p.metrics.EmptyExecutionBlocks.Inc()
p.logger.WriteJSONLog("info", "Empty execution block", map[string]interface{}{
"height": height,
if block.Coinbase().Hex() == p.config.EVMAddress {
foundBlock = true
p.metrics.ExecutionConfirmed.Inc()
p.logger.WriteJSONLog("success", "Found execution block", map[string]interface{}{
"cl_height": clHeight,
"el_height": height,
"hash": block.Hash().Hex(),
}, nil)

if len(block.Transactions()) == 0 {
p.metrics.EmptyExecutionBlocks.Inc()
p.logger.WriteJSONLog("info", "Empty execution block", map[string]interface{}{
"height": height,
}, nil)
}
break
}
}

if foundBlock {
break
}
}
Expand Down

0 comments on commit 5ebb407

Please sign in to comment.