From a00b81db191e176564874b4b7919fc58b83725ac Mon Sep 17 00:00:00 2001 From: Bruce Riley Date: Fri, 24 Jan 2025 13:42:32 -0600 Subject: [PATCH] Node/Aptos: Don't replay old observation on startup --- node/pkg/watchers/aptos/watcher.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/node/pkg/watchers/aptos/watcher.go b/node/pkg/watchers/aptos/watcher.go index 2d01952e83..f3e5228e85 100644 --- a/node/pkg/watchers/aptos/watcher.go +++ b/node/pkg/watchers/aptos/watcher.go @@ -205,15 +205,22 @@ func (e *Watcher) Run(ctx context.Context) error { continue } + eventSeq := eventSequence.Uint() + if nextSequence == 0 && eventSeq != 0 { + // Avoid publishing an old observation on startup. This does not block the first message on a new chain (when eventSeq would be zero). + nextSequence = eventSeq + 1 + continue + } + // this is interesting in the last iteration, whereby we // find the next sequence that comes after the array - nextSequence = eventSequence.Uint() + 1 + nextSequence = eventSeq + 1 data := event.Get("data") if !data.Exists() { continue } - e.observeData(logger, data, eventSequence.Uint(), false) + e.observeData(logger, data, eventSeq, false) } health, err := e.retrievePayload(aptosHealth) @@ -255,6 +262,7 @@ func (e *Watcher) retrievePayload(s string) ([]byte, error) { if err != nil { return nil, err } + defer res.Body.Close() body, err := io.ReadAll(res.Body) if err != nil { return nil, err