Skip to content

Conversation

@colinlyguo
Copy link
Contributor

@colinlyguo colinlyguo commented Jul 29, 2025

Purpose or design rationale of this PR

When resubmission receives "nonce too low" error, it means the transaction has already been mined. In such cases sender can skip resubmitting such transactions.

This PR also adds another robustness fix about initializing/resetting nonce by setting it as max(pending nonce from the nonce, max db's nonce + 1).

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

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling for "nonce too low" cases during transaction resubmission, ensuring affected transactions are marked as failed and the nonce is reset automatically.
  • New Features

    • Added retrieval of the highest nonce for a sender’s pending transactions to enhance transaction management.
  • Chores

    • Updated the application version to v4.5.36.

@colinlyguo colinlyguo requested review from georgehao and yiweichi July 29, 2025 07:57
@coderabbitai
Copy link

coderabbitai bot commented Jul 29, 2025

Walkthrough

This change updates the version tag to "v4.5.36" and improves nonce initialization by considering both database and client pending nonces. It adds handling for "nonce too low" errors during transaction resubmission by marking the original and replacement transactions as failed. Additionally, it introduces a method to retrieve the maximum nonce by sender address from the database and adds a test for this method.

Changes

Cohort / File(s) Change Summary
Version Update
common/version/version.go
Updated version tag from "v4.5.35" to "v4.5.36".
Nonce Initialization and Error Handling
rollup/internal/controller/sender/sender.go
Refactored nonce initialization to use max of DB max nonce + 1 and client pending nonce; enhanced "nonce too low" error handling by marking transactions as failed and logging warnings; added initializeNonce method and updated resetNonce.
Nonce Retrieval Method and Test
rollup/internal/orm/pending_transaction.go, rollup/internal/orm/orm_test.go
Added method GetMaxNonceBySenderAddress to retrieve max nonce for a sender from DB; added test verifying behavior with empty and populated states.

Sequence Diagram(s)

sequenceDiagram
    participant Sender
    participant ORM
    participant DB

    Sender->>ORM: GetMaxNonceBySenderAddress(sender)
    ORM->>DB: Query max nonce for sender
    DB-->>ORM: Return max nonce
    ORM-->>Sender: Return max nonce

    Sender->>Sender: initializeNonce() = max(DB max nonce + 1, client pending nonce)
    Sender->>Sender: Log nonce initialization/reset

    Sender->>Sender: SendTransaction()
    alt Error contains "nonce too low"
        Sender->>Sender: resetNonce()
        Sender->>Sender: Log nonce reset
        Sender->>Sender: Return error if reset fails
    end

    Sender->>Sender: checkPendingTransaction()
    alt Resubmission "nonce too low" error
        Sender->>Sender: Log warning
        Sender->>DB: Update original and replacement tx status to ConfirmedFailed
        Sender-->>Sender: Return early (no rollback)
    else Other errors
        Sender->>Sender: Existing rollback/error handling
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested labels

bump-version

Suggested reviewers

  • Thegaram
  • jonastheis
  • georgehao

Poem

A hop, a skip, a version bump anew,
With nonce errors handled, we're hopping through!
Transactions marked, the bugs outsmarted,
The sender and ORM, bravely charted.
v4.5.36, a carrot for the code—
Let’s leap ahead on this blockchain road! 🥕✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 167ce20 and 1115c51.

📒 Files selected for processing (2)
  • rollup/internal/controller/sender/sender.go (6 hunks)
  • rollup/internal/orm/pending_transaction.go (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • rollup/internal/controller/sender/sender.go
  • rollup/internal/orm/pending_transaction.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: tests
  • GitHub Check: tests
  • GitHub Check: check
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-gas-oracle-nonce-too-low

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this 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.

@codecov-commenter
Copy link

codecov-commenter commented Jul 29, 2025

Codecov Report

❌ Patch coverage is 44.15584% with 43 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.65%. Comparing base (4bfcd35) to head (a3acf88).

Files with missing lines Patch % Lines
rollup/internal/controller/sender/sender.go 38.63% 23 Missing and 4 partials ⚠️
rollup/internal/orm/pending_transaction.go 51.51% 16 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1712      +/-   ##
===========================================
+ Coverage    39.55%   39.65%   +0.09%     
===========================================
  Files          237      237              
  Lines        18999    19033      +34     
===========================================
+ Hits          7516     7547      +31     
+ Misses       10743    10742       -1     
- Partials       740      744       +4     
Flag Coverage Δ
rollup 45.45% <44.15%> (+0.04%) ⬆️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

colinlyguo added 2 commits July 29, 2025 19:59
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: 0

🧹 Nitpick comments (1)
rollup/internal/orm/orm_test.go (1)

601-657: Well-structured test with good coverage of basic scenarios.

The test properly covers both the empty state (no transactions) and populated state (multiple transactions with different nonces). The test setup is clean and follows established patterns in the file.

Consider adding these test cases for more comprehensive coverage:

  • Multiple transactions with the same nonce for the same sender
  • Transactions for different sender addresses to verify proper filtering
  • Testing with nonce 0 to ensure it's handled correctly

Example of additional test cases:

+	// Test with different sender address to ensure proper filtering
+	differentSender := &SenderMeta{
+		Name:    "differentSender",
+		Service: "testService",
+		Address: common.HexToAddress("0xbeefcafe"),
+		Type:    types.SenderTypeCommitBatch,
+	}
+	tx2 := gethTypes.NewTx(&gethTypes.DynamicFeeTx{
+		Nonce:      5,
+		To:         &common.Address{},
+		Data:       []byte{},
+		Gas:        23000,
+		AccessList: gethTypes.AccessList{},
+		Value:      big.NewInt(0),
+		ChainID:    big.NewInt(1),
+		GasTipCap:  big.NewInt(2),
+		GasFeeCap:  big.NewInt(3),
+		V:          big.NewInt(0),
+		R:          big.NewInt(0),
+		S:          big.NewInt(0),
+	})
+	err = pendingTransactionOrm.InsertPendingTransaction(context.Background(), "test", differentSender, tx2, 0)
+	assert.NoError(t, err)
+
+	// Original sender should still have max nonce 3
+	maxNonce, err = pendingTransactionOrm.GetMaxNonceBySenderAddress(context.Background(), senderMeta.Address.String())
+	assert.NoError(t, err)
+	assert.Equal(t, uint64(3), maxNonce)
+
+	// Different sender should have max nonce 5
+	maxNonce, err = pendingTransactionOrm.GetMaxNonceBySenderAddress(context.Background(), differentSender.Address.String())
+	assert.NoError(t, err)
+	assert.Equal(t, uint64(5), maxNonce)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 637578a and 22a1108.

📒 Files selected for processing (2)
  • rollup/internal/orm/orm_test.go (1 hunks)
  • rollup/internal/orm/pending_transaction.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • rollup/internal/orm/pending_transaction.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: tests
  • GitHub Check: tests
  • GitHub Check: check

@yiweichi yiweichi self-requested a review July 29, 2025 12:43
yiweichi
yiweichi previously approved these changes Jul 29, 2025
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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 22a1108 and 86b18d5.

📒 Files selected for processing (3)
  • rollup/internal/controller/sender/sender.go (6 hunks)
  • rollup/internal/orm/orm_test.go (1 hunks)
  • rollup/internal/orm/pending_transaction.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • rollup/internal/orm/orm_test.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: tests
  • GitHub Check: check
  • GitHub Check: tests
🔇 Additional comments (6)
rollup/internal/orm/pending_transaction.go (2)

6-6: LGTM!

The database/sql import is correctly added to support the sql.NullInt64 type used in the new GetMaxNonceBySenderAddress method.


212-232: LGTM!

The GetMaxNonceBySenderAddress method is well-implemented with proper error handling and null value management. The use of sql.NullInt64 correctly handles the case where no transactions exist for the given address, and returning -1 is appropriately documented and consistent with its usage in the sender logic.

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

108-134: LGTM!

The constructor changes improve nonce initialization by using the resetNonce() method, which now considers both database and client nonces through the new initializeNonce() method. The error handling is appropriate and the approach consolidates nonce initialization logic.


332-360: LGTM!

The initializeNonce method implements robust nonce initialization logic by considering both database and client states. The approach of taking the maximum between pending nonce and (db nonce + 1) ensures consistency, and the comprehensive logging aids in debugging. The error handling is appropriate with descriptive messages.


363-372: LGTM!

The resetNonce method improvements are excellent. The method now returns an error for proper error propagation and uses the new initializeNonce method for consistency. This addresses the past review comment about applying the "maximum of both values" logic to the resetNonce function as well.


244-247: LGTM!

The error handling for the resetNonce() call is appropriate since the method signature now returns an error. The early return on failure and descriptive error messaging maintain consistency with the existing error handling patterns in this method.

yiweichi
yiweichi previously approved these changes Jul 29, 2025
@yiweichi yiweichi self-requested a review July 30, 2025 06:31
@colinlyguo colinlyguo merged commit fc75299 into develop Jul 30, 2025
6 checks passed
@colinlyguo colinlyguo deleted the fix-gas-oracle-nonce-too-low branch July 30, 2025 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants