Skip to content

Commit

Permalink
Only activate count-based log pruning when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
reductionista committed Oct 8, 2024
1 parent 255be97 commit 45d98f3
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions core/chains/evm/logpoller/log_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ type logPoller struct {
// Usually the only way to recover is to manually remove the offending logs and block from the database.
// LogPoller keeps running in infinite loop, so whenever the invalid state is removed from the database it should
// recover automatically without needing to restart the LogPoller.
finalityViolated *atomic.Bool
finalityViolated *atomic.Bool
countBasedLogPruningActive *atomic.Bool
}

type Opts struct {
Expand Down Expand Up @@ -213,6 +214,12 @@ func (filter *Filter) Contains(other *Filter) bool {
if other == nil {
return true
}
if other.Retention != filter.Retention {
return false
}
if other.MaxLogsKept != filter.MaxLogsKept {
return false
}
addresses := make(map[common.Address]interface{})
for _, addr := range filter.Addresses {
addresses[addr] = struct{}{}
Expand Down Expand Up @@ -278,14 +285,17 @@ func (lp *logPoller) RegisterFilter(ctx context.Context, filter Filter) error {
lp.lggr.Warnw("Filter already present, no-op", "name", filter.Name, "filter", filter)
return nil
}
lp.lggr.Warnw("Updating existing filter with more events or addresses", "name", filter.Name, "filter", filter)
lp.lggr.Warnw("Updating existing filter", "name", filter.Name, "filter", filter)
}

if err := lp.orm.InsertFilter(ctx, filter); err != nil {
return pkgerrors.Wrap(err, "error inserting filter")
}
lp.filters[filter.Name] = filter
lp.filterDirty = true
if filter.MaxLogsKept > 0 {
lp.countBasedLogPruningActive.Store(true)
}
return nil
}

Expand Down Expand Up @@ -1144,6 +1154,10 @@ func (lp *logPoller) PruneExpiredLogs(ctx context.Context) (bool, error) {
done = false
}

if !lp.countBasedLogPruningActive.Load() {
return done, err
}

rowIDs, err := lp.orm.SelectExcessLogIDs(ctx, lp.logPrunePageSize)
if err != nil {
lp.lggr.Errorw("Unable to find excess logs for pruning", "err", err)
Expand Down

0 comments on commit 45d98f3

Please sign in to comment.