From b2a780edc88df113c04a9e2018068442bbed3942 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 12 Jun 2023 01:15:58 -0700 Subject: [PATCH 1/4] make sure to return nil --- packages/relayer/repo/event.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/relayer/repo/event.go b/packages/relayer/repo/event.go index eec79c7e8a6..5a0cf657dcb 100644 --- a/packages/relayer/repo/event.go +++ b/packages/relayer/repo/event.go @@ -73,8 +73,8 @@ func (r *EventRepository) FirstByMsgHash( // find all message sent events if err := r.db.GormDB().Where("msg_hash = ?", msgHash). First(&e).Error; err != nil { - if err == gorm.ErrRecordNotFound { - return e, nil + if err == gorm.ErrRecordNotFound || e.ID == 0 { + return nil, nil } return nil, errors.Wrap(err, "r.db.First") From 471715da1929a011527884fbe08ea79dc22bf32e Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 12 Jun 2023 01:16:36 -0700 Subject: [PATCH 2/4] make sure to return nil --- packages/relayer/repo/event.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/relayer/repo/event.go b/packages/relayer/repo/event.go index 5a0cf657dcb..655b76f18c2 100644 --- a/packages/relayer/repo/event.go +++ b/packages/relayer/repo/event.go @@ -73,7 +73,7 @@ func (r *EventRepository) FirstByMsgHash( // find all message sent events if err := r.db.GormDB().Where("msg_hash = ?", msgHash). First(&e).Error; err != nil { - if err == gorm.ErrRecordNotFound || e.ID == 0 { + if err == gorm.ErrRecordNotFound { return nil, nil } From 827ba5079107227e763674bf1ad0be6d0959289a Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 12 Jun 2023 01:18:22 -0700 Subject: [PATCH 3/4] double check msg hash --- packages/relayer/indexer/detect_and_handle_reorg.go | 2 +- packages/relayer/indexer/save_message_status_changed_events.go | 2 +- 2 files changed, 2 insertions(+), 2 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..b450234e37e 100644 --- a/packages/relayer/indexer/save_message_status_changed_events.go +++ b/packages/relayer/indexer/save_message_status_changed_events.go @@ -63,7 +63,7 @@ func (svc *Service) saveMessageStatusChangedEvent( return errors.Wrap(err, "svc.eventRepo.FirstByMsgHash") } - if e == nil { + if e == nil || e.MsgHash == "" { return errors.Wrap(err, "svc.eventRepo.FirstByMsgHash") } From a8750b1ac2e67c5ac65a2bde6552d5500ffdb2af Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Mon, 12 Jun 2023 01:18:42 -0700 Subject: [PATCH 4/4] err msg --- packages/relayer/indexer/save_message_status_changed_events.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/relayer/indexer/save_message_status_changed_events.go b/packages/relayer/indexer/save_message_status_changed_events.go index b450234e37e..f7c4beffe87 100644 --- a/packages/relayer/indexer/save_message_status_changed_events.go +++ b/packages/relayer/indexer/save_message_status_changed_events.go @@ -64,7 +64,7 @@ func (svc *Service) saveMessageStatusChangedEvent( } if e == nil || e.MsgHash == "" { - return errors.Wrap(err, "svc.eventRepo.FirstByMsgHash") + return errors.New("message hash doesnt exist when it should") } _, err = svc.eventRepo.Save(ctx, relayer.SaveEventOpts{