Skip to content

Commit

Permalink
feat(relayer): Simplify event iterator code (#15485)
Browse files Browse the repository at this point in the history
Co-authored-by: David <david@taiko.xyz>
  • Loading branch information
mask-pp and davidtaikocha authored Jan 14, 2024
1 parent 5bf916d commit 77aafd2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 28 deletions.
40 changes: 12 additions & 28 deletions packages/relayer/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ func (i *Indexer) filter(ctx context.Context) error {
return errors.Wrap(err, "bridge.FilterMessageStatusChanged")
}

// we dont need to do anything with msgStatus events except save them to the DB.
// we dont need to process them. they are for exposing via the API.
// we don't need to do anything with msgStatus events except save them to the DB.
// we don't need to process them. they are for exposing via the API.

err = i.saveMessageStatusChangedEvents(ctx, i.srcChainId, messageStatusChangedEvents)
if err != nil {
Expand All @@ -333,21 +333,10 @@ func (i *Indexer) filter(ctx context.Context) error {
return errors.Wrap(err, "bridge.FilterMessageSent")
}

if !messageSentEvents.Next() || messageSentEvents.Event == nil {
// use "end" not "filterEnd" here, because it will be used as the start
// of the next batch.
if err := i.handleNoEventsInBatch(ctx, i.srcChainId, int64(end)); err != nil {
return errors.Wrap(err, "i.handleNoEventsInBatch")
}

continue
}

group, groupCtx := errgroup.WithContext(ctx)

group.SetLimit(i.numGoroutines)

for {
for messageSentEvents.Next() {
event := messageSentEvents.Event

group.Go(func() error {
Expand All @@ -359,24 +348,19 @@ func (i *Indexer) filter(ctx context.Context) error {
} else {
slog.Info("handled event successfully")
}

return nil
})
}

// if there are no more events
if !messageSentEvents.Next() {
// wait for the last of the goroutines to finish
if err := group.Wait(); err != nil {
return errors.Wrap(err, "group.Wait")
}
// handle no events remaining, saving the processing block and restarting the for
// loop
if err := i.handleNoEventsInBatch(ctx, i.srcChainId, int64(end)); err != nil {
return errors.Wrap(err, "i.handleNoEventsInBatch")
}
// wait for the last of the goroutines to finish
if err := group.Wait(); err != nil {
return errors.Wrap(err, "group.Wait")
}

break
}
// handle no events remaining, saving the processing block and restarting the for
// loop
if err := i.handleNoEventsInBatch(ctx, i.srcChainId, int64(end)); err != nil {
return errors.Wrap(err, "i.handleNoEventsInBatch")
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/relayer/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ func (p *Processor) Start() error {
}()

p.wg.Add(1)

go p.eventLoop(ctx)

return nil
Expand Down

2 comments on commit 77aafd2

@vercel
Copy link

@vercel vercel bot commented on 77aafd2 Jan 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

bridge-ui-v2-a6 – ./packages/bridge-ui-v2

bridge-ui-v2-a6.vercel.app
bridge-ui-v2-a6-git-alpha-6-taikoxyz.vercel.app
bridge-ui-v2-a6-taikoxyz.vercel.app
bridge.katla.taiko.xyz

@vercel
Copy link

@vercel vercel bot commented on 77aafd2 Jan 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

bridge-ui-v2-internal – ./packages/bridge-ui-v2

bridge-ui-v2-internal-taikoxyz.vercel.app
bridge-ui-v2-internal.vercel.app
bridge-ui-v2-internal-git-alpha-6-taikoxyz.vercel.app

Please sign in to comment.