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 3454af5 commit 5f98058
Showing 1 changed file with 32 additions and 21 deletions.
53 changes: 32 additions & 21 deletions internal/blockchain/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,31 +95,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.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 5f98058

Please sign in to comment.