From 736b655fbe844201cf2666b15081e08d24bf683e Mon Sep 17 00:00:00 2001 From: Sri Kidambi <1702865+kidambisrinivas@users.noreply.github.com> Date: Tue, 8 Oct 2024 19:48:06 +0100 Subject: [PATCH] Set cursor direction in Log Event Trigger Capability (#14691) * Set cursor direction * Make query count configurable --- core/capabilities/triggers/logevent/service.go | 1 + core/capabilities/triggers/logevent/trigger.go | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/core/capabilities/triggers/logevent/service.go b/core/capabilities/triggers/logevent/service.go index 52e56d991f9..8a59865e3f5 100644 --- a/core/capabilities/triggers/logevent/service.go +++ b/core/capabilities/triggers/logevent/service.go @@ -40,6 +40,7 @@ type Config struct { Network string `json:"network"` LookbackBlocks uint64 `json:"lookbakBlocks"` PollPeriod uint32 `json:"pollPeriod"` + QueryCount uint64 `json:"queryCount"` } func (config Config) Version(capabilityVersion string) string { diff --git a/core/capabilities/triggers/logevent/trigger.go b/core/capabilities/triggers/logevent/trigger.go index 379d9483c24..1ce8ee5fd78 100644 --- a/core/capabilities/triggers/logevent/trigger.go +++ b/core/capabilities/triggers/logevent/trigger.go @@ -84,6 +84,10 @@ func newLogEventTrigger(ctx context.Context, callbackCh := make(chan capabilities.TriggerResponse, defaultSendChannelBufferSize) ticker := time.NewTicker(time.Duration(logEventConfig.PollPeriod) * time.Millisecond) + if logEventConfig.QueryCount == 0 { + logEventConfig.QueryCount = 20 + } + // Initialise a Log Event Trigger l := &logEventTrigger{ ch: callbackCh, @@ -120,6 +124,7 @@ func (l *logEventTrigger) listen() { cursor := "" limitAndSort := query.LimitAndSort{ SortBy: []query.SortBy{query.NewSortByTimestamp(query.Asc)}, + Limit: query.Limit{Count: l.logEventConfig.QueryCount}, } for { select { @@ -134,7 +139,7 @@ func (l *logEventTrigger) listen() { "startBlockNum", l.startBlockNum, "cursor", cursor) if cursor != "" { - limitAndSort.Limit = query.Limit{Cursor: cursor} + limitAndSort.Limit = query.CursorLimit(cursor, query.CursorFollowing, l.logEventConfig.QueryCount) } logs, err = l.contractReader.QueryKey( ctx,