Skip to content

Commit

Permalink
Node/EVM: Another blocktime query retry reason (#3583)
Browse files Browse the repository at this point in the history
  • Loading branch information
bruce-riley authored Dec 7, 2023
1 parent af3a8bf commit d09dc13
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion node/pkg/watchers/evm/connectors/batch_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
9 changes: 7 additions & 2 deletions node/pkg/watchers/evm/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d09dc13

Please sign in to comment.