Skip to content

Commit

Permalink
fix(relayer): retroactively fix old relayer messages (#15691) (#15735)
Browse files Browse the repository at this point in the history
Co-authored-by: xiaodino <[email protected]>
  • Loading branch information
cyberhorsey and xiaodino authored Feb 11, 2024
1 parent 739a268 commit 4588f04
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions packages/relayer/indexer/handle_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package indexer
import (

This comment has been minimized.

Copy link
@BurnToken1

BurnToken1 Mar 4, 2024

nice line

"context"
"encoding/json"
"fmt"
"math/big"
"time"

Expand Down Expand Up @@ -78,13 +79,6 @@ func (i *Indexer) handleEvent(
return errors.Wrap(err, "svc.eventStatusFromMsgHash")
}

// if the message is not status new, and we are iterating crawling past blocks,
// we also dont want to handle this event. it has already been handled.
if i.watchMode == CrawlPastBlocks && eventStatus != relayer.EventStatusNew {
// we can return early, this message has been processed as expected.
return nil
}

marshaled, err := json.Marshal(event)
if err != nil {
return errors.Wrap(err, "json.Marshal(event)")
Expand Down Expand Up @@ -139,6 +133,21 @@ func (i *Indexer) handleEvent(
} else {
// otherwise, we can use the existing event ID for the body.
id = existingEvent.ID

if i.watchMode == CrawlPastBlocks && eventStatus == existingEvent.Status {
// If the status from contract matches the existing event status,
// we can return early as this message has been processed as expected.
return nil
}

// If the status from contract is done, update the database
if i.watchMode == CrawlPastBlocks && eventStatus == relayer.EventStatusDone {
if err := i.eventRepo.UpdateStatus(ctx, id, relayer.EventStatusDone); err != nil {
return errors.Wrap(err, fmt.Sprintf("i.eventRepo.UpdateStatus, id: %v", id))
}

return nil
}
}

msg := queue.QueueMessageBody{
Expand Down

0 comments on commit 4588f04

Please sign in to comment.