Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix cctp submitter race #2853

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions services/cctp-relayer/relayer/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package relayer

import (
"context"
"errors"
"fmt"
"sync"
"time"
Expand Down Expand Up @@ -304,11 +305,13 @@ func (c *CCTPRelayer) Run(parentCtx context.Context) error {
})

g.Go(func() error {
err := c.txSubmitter.Start(ctx)
if err != nil {
err = fmt.Errorf("could not start tx submitter: %w", err)
if !c.txSubmitter.Started() {
err := c.txSubmitter.Start(ctx)
if err != nil && !errors.Is(err, submitter.ErrSubmitterAlreadyStarted) {
return fmt.Errorf("could not start tx submitter: %w", err)
}
Comment on lines +308 to +312
Copy link
Contributor

Choose a reason for hiding this comment

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

Error Handling Improvement: Check if txSubmitter has already started.

The added check ensures that the transaction submitter is not started multiple times, preventing redundant operations and potential errors. However, the conditional block can be simplified for better readability.

-		if !c.txSubmitter.Started() {
-			err := c.txSubmitter.Start(ctx)
-			if err != nil && !errors.Is(err, submitter.ErrSubmitterAlreadyStarted) {
-				return fmt.Errorf("could not start tx submitter: %w", err)
-			}
-		}
+		if c.txSubmitter.Started() {
+			return nil
+		}
+		err := c.txSubmitter.Start(ctx)
+		if err != nil && !errors.Is(err, submitter.ErrSubmitterAlreadyStarted) {
+			return fmt.Errorf("could not start tx submitter: %w", err)
+		}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if !c.txSubmitter.Started() {
err := c.txSubmitter.Start(ctx)
if err != nil && !errors.Is(err, submitter.ErrSubmitterAlreadyStarted) {
return fmt.Errorf("could not start tx submitter: %w", err)
}
if c.txSubmitter.Started() {
return nil
}
err := c.txSubmitter.Start(ctx)
if err != nil && !errors.Is(err, submitter.ErrSubmitterAlreadyStarted) {
return fmt.Errorf("could not start tx submitter: %w", err)
}

}
return err
return nil
})

g.Go(func() error {
Expand Down
Loading