From e915fbfd9d39c78dd14c69390bf067aa466b7cfe Mon Sep 17 00:00:00 2001 From: jeff <113397187+cyberhorsey@users.noreply.github.com> Date: Mon, 12 Jun 2023 01:20:40 -0700 Subject: [PATCH] fix(relayer): make sure to return nil for first by msg hash (#13967) --- packages/relayer/indexer/detect_and_handle_reorg.go | 2 +- .../relayer/indexer/save_message_status_changed_events.go | 4 ++-- packages/relayer/repo/event.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/relayer/indexer/detect_and_handle_reorg.go b/packages/relayer/indexer/detect_and_handle_reorg.go index fd1beb8a78b..3ff30a81073 100644 --- a/packages/relayer/indexer/detect_and_handle_reorg.go +++ b/packages/relayer/indexer/detect_and_handle_reorg.go @@ -12,7 +12,7 @@ func (svc *Service) detectAndHandleReorg(ctx context.Context, eventType string, return errors.Wrap(err, "svc.eventRepo.FirstByMsgHash") } - if e == nil { + if e == nil || e.MsgHash == "" { return nil } diff --git a/packages/relayer/indexer/save_message_status_changed_events.go b/packages/relayer/indexer/save_message_status_changed_events.go index d50900a4b44..f7c4beffe87 100644 --- a/packages/relayer/indexer/save_message_status_changed_events.go +++ b/packages/relayer/indexer/save_message_status_changed_events.go @@ -63,8 +63,8 @@ func (svc *Service) saveMessageStatusChangedEvent( return errors.Wrap(err, "svc.eventRepo.FirstByMsgHash") } - if e == nil { - return errors.Wrap(err, "svc.eventRepo.FirstByMsgHash") + if e == nil || e.MsgHash == "" { + return errors.New("message hash doesnt exist when it should") } _, err = svc.eventRepo.Save(ctx, relayer.SaveEventOpts{ diff --git a/packages/relayer/repo/event.go b/packages/relayer/repo/event.go index eec79c7e8a6..655b76f18c2 100644 --- a/packages/relayer/repo/event.go +++ b/packages/relayer/repo/event.go @@ -74,7 +74,7 @@ func (r *EventRepository) FirstByMsgHash( if err := r.db.GormDB().Where("msg_hash = ?", msgHash). First(&e).Error; err != nil { if err == gorm.ErrRecordNotFound { - return e, nil + return nil, nil } return nil, errors.Wrap(err, "r.db.First")