-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(eventindexer): handle reorg (#13841)
Co-authored-by: Roger <50648015+RogerLamTd@users.noreply.github.com> Co-authored-by: Daniel Wang <99078276+dantaik@users.noreply.github.com>
- Loading branch information
1 parent
98017a2
commit 0a26ce5
Showing
17 changed files
with
238 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package indexer | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
func (svc *Service) detectAndHandleReorg(ctx context.Context, event string, blockID int64) error { | ||
existingEvent, err := svc.eventRepo.FindByEventTypeAndBlockID(ctx, event, blockID) | ||
if err != nil { | ||
return errors.Wrap(err, "svc.eventRepo.FindByEventTypeAndBlockID") | ||
} | ||
|
||
if existingEvent != nil { | ||
// reorg detected | ||
err := svc.eventRepo.Delete(ctx, existingEvent.ID) | ||
if err != nil { | ||
return errors.Wrap(err, "svc.eventRepo.Delete") | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package indexer | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/taikoxyz/taiko-mono/packages/relayer" | ||
) | ||
|
||
func (svc *Service) detectAndHandleReorg(ctx context.Context, eventType string, msgHash string) error { | ||
events, err := svc.eventRepo.FindAllByMsgHash(ctx, msgHash) | ||
if err != nil { | ||
return errors.Wrap(err, "svc.eventRepo.FindAllByMsgHash") | ||
} | ||
|
||
if events == nil { | ||
return nil | ||
} | ||
|
||
var existingEvent *relayer.Event | ||
|
||
for _, e := range events { | ||
if e.Event == eventType && e.MsgHash == msgHash { | ||
existingEvent = e | ||
break | ||
} | ||
} | ||
|
||
if existingEvent != nil { | ||
// reorg detected | ||
err := svc.eventRepo.Delete(ctx, existingEvent.ID) | ||
if err != nil { | ||
return errors.Wrap(err, "svc.eventRepo.Delete") | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.