Node/EVM: Another blocktime query retry reason (#3583)

This commit is contained in:
bruce-riley 2023-12-07 15:18:48 -06:00 committed by GitHub
parent af3a8bf414
commit d09dc13918
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -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)
}

View File

@ -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