diff --git a/core/chains/evm/logpoller/orm.go b/core/chains/evm/logpoller/orm.go index e8ced08a1e7..08a4d558fbf 100644 --- a/core/chains/evm/logpoller/orm.go +++ b/core/chains/evm/logpoller/orm.go @@ -1,6 +1,7 @@ package logpoller import ( + "context" "database/sql" "math/big" "time" @@ -189,6 +190,12 @@ func (o *ORM) InsertLogs(logs []Log, qopts ...pg.QOpt) error { (:evm_chain_id, :log_index, :block_hash, :block_number, :block_timestamp, :address, :event_sig, :topics, :tx_hash, :data, NOW()) ON CONFLICT DO NOTHING`, logs[start:end]) if err != nil { + if errors.Is(err, context.DeadlineExceeded) && batchInsertSize > 500 { + // In case of DB timeouts, try to insert again with a smaller batch upto a limit + batchInsertSize /= 2 + i -= batchInsertSize // counteract +=batchInsertSize on next loop iteration + continue + } return err } }