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(rollup-relayer): graceful restart #1564

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

colinlyguo
Copy link
Member

@colinlyguo colinlyguo commented Nov 15, 2024

Purpose or design rationale of this PR

a bug found during testing scroll-sdk.

PR title

Your PR title must follow conventional commits (as we are doing squash merge for each PR), so it must start with one of the following types:

  • fix: A bug fix

Deployment tag versioning

Has tag in common/version.go been updated or have you added bump-version label to this PR?

  • Yes

Breaking change label

Does this PR have the breaking-change label?

  • No, this PR is not a breaking change

Summary by CodeRabbit

  • New Features

    • Updated version number to v4.4.73, indicating a new software release.
    • Enhanced transaction handling logic for improved clarity and error reporting.
  • Bug Fixes

    • Improved error handling for transaction creation and sending processes.
  • Tests

    • Refined test suite to align with updated transaction handling methods, ensuring robust validation of transaction processes.

@colinlyguo colinlyguo added the bump-version Bump the version tag for deployment label Nov 15, 2024
Copy link

coderabbitai bot commented Nov 15, 2024

Walkthrough

The changes in this pull request involve an update to the version tag in the common/version/version.go file, changing it from "v4.4.72" to "v4.4.73". Additionally, modifications were made to the sender package, including renaming methods for clarity and improving error handling in transaction processing. The test suite for the sender package was also updated to reflect these method name changes and to enhance the clarity and robustness of transaction handling tests.

Changes

File Change Summary
common/version/version.go Updated version tag from "v4.4.72" to "v4.4.73".
rollup/internal/controller/sender/sender.go Renamed createAndSendTx to createTx, moved sending logic to SendTransaction, refined error handling, and renamed resubmitTransaction to createReplacingTransaction.
rollup/internal/controller/sender/sender_test.go Updated test methods to reflect the renaming of methods in the sender package, improved error handling, and ensured comprehensive test coverage for transaction types.

Possibly related PRs

Suggested reviewers

  • georgehao
  • 0xmountaintop

🐇 In the code, I hop and play,
Version numbers change today!
From four point four to seventy-three,
Clarity in sending, oh so key!
With tests that check each little byte,
Our code now dances, pure delight! 🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1e95eec and 187a995.

📒 Files selected for processing (1)
  • rollup/internal/controller/sender/sender.go (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • rollup/internal/controller/sender/sender.go

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (4)
rollup/internal/controller/sender/sender.go (4)

220-220: Consider renaming the metric for clarity

The metric sendTransactionFailureSendTx is incremented when createTx fails. To improve clarity and maintainability, consider renaming this metric to reflect that it tracks transaction creation failures, such as createTransactionFailureTotal.


238-240: Use robust error handling instead of string matching

Relying on string matching with strings.Contains(err.Error(), "nonce too low") can be fragile, as error messages may change. Consider checking for specific error types or error codes to handle the "nonce too low" error more reliably.

Apply this diff to improve error handling:

-if strings.Contains(err.Error(), "nonce too low") {
+if isNonceTooLowError(err) {
     s.resetNonce(context.Background())
 }

And define the error checking function:

func isNonceTooLowError(err error) bool {
    // Implement error type assertion or error code checking here
    // Example for illustrative purposes:
    return errors.Is(err, ethereum.NonceTooLowError)
}

476-478: Add metric for failed transaction resubmissions

When createTx fails during a resubmission, there is no metric being incremented to track this failure. Consider incrementing a metric, such as resubmitTransactionFailedTotal, to monitor failed resubmission attempts.

Apply this diff to include the metric:

 if err != nil {
+    s.metrics.resubmitTransactionFailedTotal.WithLabelValues(s.service, s.name).Inc()
     log.Error("failed to create signed tx (resubmit case)", "from", s.transactionSigner.GetAddr().String(), "nonce", nonce, "err", err)
     return nil, err
 }

220-220: Ensure consistent metric naming for error tracking

The metric sendTransactionFailureSendTx may not accurately reflect that it's tracking failures in transaction creation. For consistency and clarity, consider renaming it to align with other failure metrics used elsewhere in the codebase.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3ab5752 and 1e95eec.

📒 Files selected for processing (3)
  • common/version/version.go (1 hunks)
  • rollup/internal/controller/sender/sender.go (7 hunks)
  • rollup/internal/controller/sender/sender_test.go (5 hunks)
✅ Files skipped from review due to trivial changes (1)
  • common/version/version.go
🔇 Additional comments (7)
rollup/internal/controller/sender/sender_test.go (6)

285-289: LGTM! Improved separation of concerns.

The separation of transaction creation and sending into distinct steps improves code clarity and follows the single responsibility principle.


293-295: LGTM! Consistent method naming and explicit transaction handling.

The renaming to createReplacingTransaction better describes its purpose, and the explicit transaction sending maintains consistency with the new pattern.


376-380: LGTM! Consistent implementation of the new pattern.

The changes maintain consistency with the new transaction handling pattern across test cases.


381-383: LGTM! Consistent method naming and transaction handling.

The changes maintain consistency in the transaction replacement pattern.


423-427: LGTM! Maintains consistency in transaction creation pattern.

The changes follow the established pattern of separate transaction creation and sending.


477-479: LGTM! Consistent implementation across test scenarios.

The changes maintain consistency in transaction replacement handling across different test cases (dynamic fee and blob transactions).

Also applies to: 528-530

rollup/internal/controller/sender/sender.go (1)

565-565: 🛠️ Refactor suggestion

⚠️ Potential issue

Avoid premature function exit in error handling within loops

Using return inside the loop will exit the checkPendingTransaction function upon encountering an error, which could prevent the processing of subsequent transactions. Consider using continue to proceed with the next transaction or handle the error appropriately to ensure all transactions are checked.

Apply this diff to fix the issue:

 if err != nil {
     log.Error("failed to get transaction status by tx hash", "hash", originalTx.Hash().String(), "err", err)
-    return
+    continue
 }

Likely invalid or redundant comment.

rollup/internal/controller/sender/sender.go Outdated Show resolved Hide resolved
rollup/internal/controller/sender/sender.go Show resolved Hide resolved
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 36.06557% with 39 lines in your changes missing coverage. Please review.

Project coverage is 52.69%. Comparing base (3ab5752) to head (187a995).

Files with missing lines Patch % Lines
rollup/internal/controller/sender/sender.go 36.06% 29 Missing and 10 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1564      +/-   ##
===========================================
- Coverage    52.78%   52.69%   -0.10%     
===========================================
  Files          157      157              
  Lines        12652    12657       +5     
===========================================
- Hits          6678     6669       -9     
- Misses        5392     5407      +15     
+ Partials       582      581       -1     
Flag Coverage Δ
rollup 58.78% <36.06%> (-0.29%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump-version Bump the version tag for deployment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants