From 5f98058cf37d46ef68dd219c468a12e8e2037bd5 Mon Sep 17 00:00:00 2001 From: chliddle Date: Wed, 11 Dec 2024 08:25:54 +0000 Subject: [PATCH] fix: retry el calls and improve logging --- internal/blockchain/processor.go | 53 +++++++++++++++++++------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/internal/blockchain/processor.go b/internal/blockchain/processor.go index bd3b0bf..bb22c29 100644 --- a/internal/blockchain/processor.go +++ b/internal/blockchain/processor.go @@ -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 } }