Skip to content

Commit

Permalink
Standardize LP filter logging (#11515)
Browse files Browse the repository at this point in the history
* Standardize logs

* Comments

* More PR review

* More

* Fix test
  • Loading branch information
connorwstein authored Dec 12, 2023
1 parent 00e1c55 commit f3d5417
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions core/chains/evm/logpoller/log_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func (filter *Filter) Contains(other *Filter) bool {
// Generally speaking this is harmless. We enforce that EventSigs and Addresses are non-empty,
// which means that anonymous events are not supported and log.Topics >= 1 always (log.Topics[0] is the event signature).
// The filter may be unregistered later by Filter.Name
// Warnings/debug information is keyed by filter name.
func (lp *logPoller) RegisterFilter(filter Filter, qopts ...pg.QOpt) error {
if len(filter.Addresses) == 0 {
return errors.Errorf("at least one address must be specified")
Expand All @@ -242,33 +243,35 @@ func (lp *logPoller) RegisterFilter(filter Filter, qopts ...pg.QOpt) error {
if existingFilter, ok := lp.filters[filter.Name]; ok {
if existingFilter.Contains(&filter) {
// Nothing new in this Filter
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", "filter", filter)
} else {
lp.lggr.Debugw("Creating new filter", "filter", filter)
lp.lggr.Warnw("Updating existing filter with more events or addresses", "name", filter.Name, "filter", filter)
}

if err := lp.orm.InsertFilter(filter, qopts...); err != nil {
return errors.Wrap(err, "RegisterFilter failed to save filter to db")
return errors.Wrap(err, "error inserting filter")
}
lp.filters[filter.Name] = filter
lp.filterDirty = true
return nil
}

// UnregisterFilter will remove the filter with the given name.
// If the name does not exist, it will log an error but not return an error.
// Warnings/debug information is keyed by filter name.
func (lp *logPoller) UnregisterFilter(name string, qopts ...pg.QOpt) error {
lp.filterMu.Lock()
defer lp.filterMu.Unlock()

_, ok := lp.filters[name]
if !ok {
lp.lggr.Errorf("Filter %s not found", name)
lp.lggr.Warnw("Filter not found", "name", name)
return nil
}

if err := lp.orm.DeleteFilter(name, qopts...); err != nil {
return errors.Wrapf(err, "Failed to delete filter %s", name)
return errors.Wrap(err, "error deleting filter")
}
delete(lp.filters, name)
lp.filterDirty = true
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/logpoller/log_poller_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestLogPoller_RegisterFilter(t *testing.T) {
a1 := common.HexToAddress("0x2ab9a2dc53736b361b72d900cdf9f78f9406fbbb")
a2 := common.HexToAddress("0x2ab9a2dc53736b361b72d900cdf9f78f9406fbbc")

lggr, observedLogs := logger.TestObserved(t, zapcore.ErrorLevel)
lggr, observedLogs := logger.TestObserved(t, zapcore.WarnLevel)
chainID := testutils.NewRandomEVMChainID()
db := pgtest.NewSqlxDB(t)

Expand Down

0 comments on commit f3d5417

Please sign in to comment.