From d09dc13918f11705bef5bd266fb634d73ef7bb18 Mon Sep 17 00:00:00 2001 From: bruce-riley <96066700+bruce-riley@users.noreply.github.com> Date: Thu, 7 Dec 2023 15:18:48 -0600 Subject: [PATCH] Node/EVM: Another blocktime query retry reason (#3583) --- node/pkg/watchers/evm/connectors/batch_poller.go | 2 +- node/pkg/watchers/evm/watcher.go | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/node/pkg/watchers/evm/connectors/batch_poller.go b/node/pkg/watchers/evm/connectors/batch_poller.go index 00cdaa74f..fcc2fc47e 100644 --- a/node/pkg/watchers/evm/connectors/batch_poller.go +++ b/node/pkg/watchers/evm/connectors/batch_poller.go @@ -323,7 +323,7 @@ func (b *BatchPollConnector) getBlockRange(ctx context.Context, logger *zap.Logg var n big.Int m := &result.result if m.Number == nil { - logger.Debug("number is nil, treating as zero", zap.Stringer("finality", finality), zap.String("tag", b.batchData[idx].tag)) + logger.Debug("number is nil, treating as zero", zap.Stringer("finality", finality)) } else { n = big.Int(*m.Number) } diff --git a/node/pkg/watchers/evm/watcher.go b/node/pkg/watchers/evm/watcher.go index d102c5f2b..517a4e23b 100644 --- a/node/pkg/watchers/evm/watcher.go +++ b/node/pkg/watchers/evm/watcher.go @@ -488,7 +488,7 @@ func (w *Watcher) Run(parentCtx context.Context) error { blockTime, err := w.getBlockTime(ctx, ev.Raw.BlockHash) if err != nil { ethConnectionErrors.WithLabelValues(w.networkName, "block_by_number_error").Inc() - if err == ethereum.NotFound { + if canRetryGetBlockTime(err) { go w.waitForBlockTime(ctx, logger, errC, ev) continue } @@ -931,6 +931,11 @@ func (w *Watcher) postMessage(logger *zap.Logger, ev *ethabi.AbiLogMessagePublis w.pendingMu.Unlock() } +// canRetryGetBlockTime returns true if the error returned by getBlockTime warrants doing a retry. +func canRetryGetBlockTime(err error) bool { + return err == ethereum.NotFound /* go-ethereum */ || err.Error() == "cannot query unfinalized data" /* avalanche */ +} + // waitForBlockTime is a go routine that repeatedly attempts to read the block time for a single log event. It is used when the initial attempt to read // the block time fails. If it is finally able to read the block time, it posts the event for processing. Otherwise, it will eventually give up. func (w *Watcher) waitForBlockTime(ctx context.Context, logger *zap.Logger, errC chan error, ev *ethabi.AbiLogMessagePublished) { @@ -973,7 +978,7 @@ func (w *Watcher) waitForBlockTime(ctx context.Context, logger *zap.Logger, errC } ethConnectionErrors.WithLabelValues(w.networkName, "block_by_number_error").Inc() - if err != ethereum.NotFound { + if !canRetryGetBlockTime(err) { p2p.DefaultRegistry.AddErrorCount(w.chainID, 1) errC <- fmt.Errorf("failed to request timestamp for block %d, hash %s: %w", ev.Raw.BlockNumber, ev.Raw.BlockHash.String(), err) return