Skip to content

Commit

Permalink
Fix bug in updating last poll block for filter (#10462)
Browse files Browse the repository at this point in the history
  • Loading branch information
infiloop2 authored Sep 4, 2023
1 parent 39f7cde commit fe6fd64
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func (p *logEventProvider) readLogs(ctx context.Context, latest int64, filters [
// maxBurst will be used to increase the burst limit to allow a long range scan
maxBurst := int(lookbackBlocks + 1)

for _, filter := range filters {
for i, filter := range filters {
if len(filter.addr) == 0 {
continue
}
Expand Down Expand Up @@ -408,7 +408,9 @@ func (p *logEventProvider) readLogs(ctx context.Context, latest int64, filters [

p.buffer.enqueue(filter.upkeepID, filteredLogs...)

filter.lastPollBlock = latest
// Update the lastPollBlock for filter in slice this is then
// updated into filter store in updateFiltersLastPoll
filters[i].lastPollBlock = latest
}

return merr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ func TestLogEventProvider_ReadLogs(t *testing.T) {
},
}, nil)

p := NewLogProvider(logger.TestLogger(t), mp, &mockedPacker{}, NewUpkeepFilterStore(), NewOptions(200))
filterStore := NewUpkeepFilterStore()
p := NewLogProvider(logger.TestLogger(t), mp, &mockedPacker{}, filterStore, NewOptions(200))

var ids []*big.Int
for i := 0; i < 10; i++ {
Expand All @@ -277,6 +278,15 @@ func TestLogEventProvider_ReadLogs(t *testing.T) {
require.NoError(t, p.ReadLogs(ctx, ids[:2]...))
logs := p.buffer.peek(10)
require.Len(t, logs, 2)

var updatedFilters []upkeepFilter
filterStore.RangeFiltersByIDs(func(i int, f upkeepFilter) {
updatedFilters = append(updatedFilters, f.Clone())
}, ids[:2]...)
for _, f := range updatedFilters {
// Last poll block should be updated
require.Equal(t, int64(1), f.lastPollBlock)
}
})

// TODO: test rate limiting
Expand Down

0 comments on commit fe6fd64

Please sign in to comment.