Skip to content

Commit 0833d36

Browse files
committed
nit fixes
1 parent 54c15d8 commit 0833d36

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

pkg/logpoller/log_poller.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,7 @@ func (e *reorgError) Error() string {
12211221
}
12221222

12231223
func (lp *logPoller) getUnfinalizedLogs(ctx context.Context, currentBlock *evmtypes.Head, latest, safe, finalized int64, isReplay bool) ([]Block, []Log, error) {
1224+
const maxUnfinalizedBlocks = 2000
12241225
var logs []Log
12251226
var blocks []Block
12261227
for {
@@ -1245,6 +1246,11 @@ func (lp *logPoller) getUnfinalizedLogs(ctx context.Context, currentBlock *evmty
12451246
return blocks, logs, nil
12461247
}
12471248

1249+
if len(blocks) >= maxUnfinalizedBlocks {
1250+
lp.lggr.Warnw("Too many unfinalized blocks, stopping log retrieval to avoid OOM", "currentBlockNumber", currentBlock.Number, "latestBlockNumber", latest)
1251+
return blocks, logs, nil
1252+
}
1253+
12481254
nextBlock, err := lp.headerByNumber(ctx, currentBlock.Number+1)
12491255
if err != nil {
12501256
lp.lggr.Warnw("Unable to get next block header, retrying on next poll", "err", err, "block", currentBlock.Number)

pkg/logpoller/orm.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,7 @@ func (o *DSORM) insertLogsWithinTx(ctx context.Context, logs []Log, tx sqlutil.D
586586
return batchInsert(ctx, tx, q, logs, 4000)
587587
}
588588

589-
func batchInsert[T any](ctx context.Context, ds sqlutil.DataSource, query string, objs []T, batchSize int) error {
590-
batchInsertSize := 4000
589+
func batchInsert[T any](ctx context.Context, ds sqlutil.DataSource, query string, objs []T, batchInsertSize int) error {
591590
for i := 0; i < len(objs); i += batchInsertSize {
592591
start, end := i, i+batchInsertSize
593592
if end > len(objs) {

0 commit comments

Comments
 (0)