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
Show file tree
Hide file tree
Changes from all commits
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 @@

import (
"context"
"errors"
"fmt"
"sync"
"time"
Expand Down Expand Up @@ -304,11 +305,13 @@
})

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)
}

Check warning on line 312 in services/cctp-relayer/relayer/relayer.go

View check run for this annotation

Codecov / codecov/patch

services/cctp-relayer/relayer/relayer.go#L311-L312

Added lines #L311 - L312 were not covered by tests
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
10 changes: 7 additions & 3 deletions services/rfq/relayer/service/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"context"
"errors"
"fmt"
"math/big"
"sync"
Expand Down Expand Up @@ -237,9 +238,12 @@
})

g.Go(func() error {
err := r.submitter.Start(ctx)
if err != nil {
return fmt.Errorf("could not start submitter: %w", err)
if !r.submitter.Started() {
err := r.submitter.Start(ctx)
if err != nil && !errors.Is(err, submitter.ErrSubmitterAlreadyStarted) {
return fmt.Errorf("could not start submitter: %w", err)
}
return nil

Check warning on line 246 in services/rfq/relayer/service/relayer.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/service/relayer.go#L241-L246

Added lines #L241 - L246 were not covered by tests
Comment on lines +241 to +246
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 submitter 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 !r.submitter.Started() {
-			err := r.submitter.Start(ctx)
-			if err != nil && !errors.Is(err, submitter.ErrSubmitterAlreadyStarted) {
-				return fmt.Errorf("could not start submitter: %w", err)
-			}
-			return nil
-		}
+		if r.submitter.Started() {
+			return nil
+		}
+		err := r.submitter.Start(ctx)
+		if err != nil && !errors.Is(err, submitter.ErrSubmitterAlreadyStarted) {
+			return fmt.Errorf("could not start submitter: %w", err)
+		}
+		return nil
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 !r.submitter.Started() {
err := r.submitter.Start(ctx)
if err != nil && !errors.Is(err, submitter.ErrSubmitterAlreadyStarted) {
return fmt.Errorf("could not start submitter: %w", err)
}
return nil
if r.submitter.Started() {
return nil
}
err := r.submitter.Start(ctx)
if err != nil && !errors.Is(err, submitter.ErrSubmitterAlreadyStarted) {
return fmt.Errorf("could not start submitter: %w", err)
}
return nil

}
return nil
})
Expand Down
Loading