diff --git a/core/chains/evm/logpoller/log_poller.go b/core/chains/evm/logpoller/log_poller.go index 57d8879a29..b38091e0cb 100644 --- a/core/chains/evm/logpoller/log_poller.go +++ b/core/chains/evm/logpoller/log_poller.go @@ -1116,11 +1116,11 @@ func (lp *logPoller) PruneExpiredLogs(ctx context.Context) (bool, error) { } func (lp *logPoller) PruneUnmatchedLogs(ctx context.Context) (bool, error) { - ids, err := lp.orm.SelectUnmatchedLogIds(ctx, lp.logPrunePageSize) + ids, err := lp.orm.SelectUnmatchedLogIDs(ctx, lp.logPrunePageSize) if err != nil { return false, err } - rowsRemoved, err := lp.orm.DeleteLogsByRowId(ctx, ids) + rowsRemoved, err := lp.orm.DeleteLogsByRowID(ctx, ids) return lp.logPrunePageSize == 0 || rowsRemoved < lp.logPrunePageSize, err } diff --git a/core/chains/evm/logpoller/observability.go b/core/chains/evm/logpoller/observability.go index 6ac0c2d9a9..59b93fffda 100644 --- a/core/chains/evm/logpoller/observability.go +++ b/core/chains/evm/logpoller/observability.go @@ -136,15 +136,15 @@ func (o *ObservedORM) DeleteLogsAndBlocksAfter(ctx context.Context, start int64) }) } -func (o *ObservedORM) DeleteLogsByRowId(ctx context.Context, rowIds []uint64) (int64, error) { - return withObservedExecAndRowsAffected(o, "DeleteLogsByRowId", del, func() (int64, error) { - return o.ORM.DeleteLogsByRowId(ctx, rowIds) +func (o *ObservedORM) DeleteLogsByRowID(ctx context.Context, rowIDs []uint64) (int64, error) { + return withObservedExecAndRowsAffected(o, "DeleteLogsByRowID", del, func() (int64, error) { + return o.ORM.DeleteLogsByRowID(ctx, rowIDs) }) } -func (o *ObservedORM) SelectUnmatchedLogIds(ctx context.Context, limit int64) (ids []uint64, err error) { - return withObservedQueryAndResults[uint64](o, "SelectUnmatchedLogIds", func() ([]uint64, error) { - return o.ORM.SelectUnmatchedLogIds(ctx, limit) +func (o *ObservedORM) SelectUnmatchedLogIDs(ctx context.Context, limit int64) (ids []uint64, err error) { + return withObservedQueryAndResults[uint64](o, "SelectUnmatchedLogIDs", func() ([]uint64, error) { + return o.ORM.SelectUnmatchedLogIDs(ctx, limit) }) } diff --git a/core/chains/evm/logpoller/orm.go b/core/chains/evm/logpoller/orm.go index 035b55abff..29606d89ab 100644 --- a/core/chains/evm/logpoller/orm.go +++ b/core/chains/evm/logpoller/orm.go @@ -33,11 +33,11 @@ type ORM interface { LoadFilters(ctx context.Context) (map[string]Filter, error) DeleteFilter(ctx context.Context, name string) error - DeleteLogsByRowId(ctx context.Context, rowIds []uint64) (int64, error) + DeleteLogsByRowID(ctx context.Context, rowIDs []uint64) (int64, error) InsertBlock(ctx context.Context, blockHash common.Hash, blockNumber int64, blockTimestamp time.Time, finalizedBlock int64) error DeleteBlocksBefore(ctx context.Context, end int64, limit int64) (int64, error) DeleteLogsAndBlocksAfter(ctx context.Context, start int64) error - SelectUnmatchedLogIds(ctx context.Context, limit int64) (ids []uint64, err error) + SelectUnmatchedLogIDs(ctx context.Context, limit int64) (ids []uint64, err error) DeleteExpiredLogs(ctx context.Context, limit int64) (int64, error) GetBlocksRange(ctx context.Context, start int64, end int64) ([]LogPollerBlock, error) @@ -380,7 +380,7 @@ type Exp struct { ShouldDelete bool } -func (o *DSORM) SelectUnmatchedLogIds(ctx context.Context, limit int64) (ids []uint64, err error) { +func (o *DSORM) SelectUnmatchedLogIDs(ctx context.Context, limit int64) (ids []uint64, err error) { query := ` SELECT l.id FROM evm.logs l JOIN ( SELECT evm_chain_id, address, event @@ -1050,9 +1050,9 @@ func (o *DSORM) FilteredLogs(ctx context.Context, filter []query.Expression, lim return logs, nil } -// DeleteLogsByRowId accepts a list of log row id's to delete -func (o *DSORM) DeleteLogsByRowId(ctx context.Context, rowIds []uint64) (int64, error) { - result, err := o.ds.ExecContext(ctx, `DELETE FROM evm.logs WHERE id = ANY($1)`, rowIds) +// DeleteLogsByRowID accepts a list of log row id's to delete +func (o *DSORM) DeleteLogsByRowID(ctx context.Context, rowIDs []uint64) (int64, error) { + result, err := o.ds.ExecContext(ctx, `DELETE FROM evm.logs WHERE id = ANY($1)`, rowIDs) if err != nil { return 0, err } diff --git a/core/chains/evm/logpoller/orm_test.go b/core/chains/evm/logpoller/orm_test.go index 51544c5892..9af6e84d70 100644 --- a/core/chains/evm/logpoller/orm_test.go +++ b/core/chains/evm/logpoller/orm_test.go @@ -494,7 +494,17 @@ func TestORM(t *testing.T) { // Delete expired logs without page limit deleted, err = o1.DeleteExpiredLogs(ctx, 0) require.NoError(t, err) - assert.Equal(t, int64(2), deleted) + assert.Equal(t, int64(1), deleted) + + // Delete unmatched logs with page limit + ids, err := o1.SelectUnmatchedLogIDs(ctx, 2) + require.NoError(t, err) + assert.Equal(t, int64(2), ids) + + // Delete unmatched logs without page limit + ids, err = o1.SelectUnmatchedLogIDs(ctx, 0) + require.NoError(t, err) + assert.Equal(t, int64(2), ids) // Ensure that both of the logs from the second chain are still there logs, err = o2.SelectLogs(ctx, 0, 100, common.HexToAddress("0x1236"), topic2)