Skip to content

Conversation

@0xFirekeeper
Copy link
Member

@0xFirekeeper 0xFirekeeper commented Aug 12, 2025

Added support for detecting errors with the message 'incorrect account sequence' in the isNonceAlreadyUsedError utility. This improves error handling for cases where the nonce is invalid due to account sequence issues.


PR-Codex overview

This PR focuses on expanding the error message handling in the src/shared/utils/error.ts file to include an additional condition for error messages.

Detailed summary

  • Modified the conditional return statement to include a new check: message.includes("incorrect account sequence").
  • The updated condition now returns true if the message contains "nonce too low", "already known", or "incorrect account sequence".

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • Bug Fixes
    • Improved detection of nonce-related errors by recognizing “incorrect account sequence” messages alongside existing patterns. This leads to more reliable handling of transaction submission issues, reducing false negatives and improving automatic retries and user feedback when a nonce has already been used, helping prevent confusing failures during busy activity or cross-wallet usage.

Added support for detecting errors with the message 'incorrect account sequence' in the isNonceAlreadyUsedError utility. This improves error handling for cases where the nonce is invalid due to account sequence issues.
@coderabbitai
Copy link

coderabbitai bot commented Aug 12, 2025

Walkthrough

Updated isNonceAlreadyUsedError in src/shared/utils/error.ts to recognize "incorrect account sequence" as an additional indicator of a nonce-already-used error, alongside existing checks for "nonce too low" and "already known", while retaining the fallback to ethers.errors.NONCE_EXPIRED.

Changes

Cohort / File(s) Summary
Error handling utils
src/shared/utils/error.ts
Extended substring checks in isNonceAlreadyUsedError to include "incorrect account sequence"; preserved existing logic and fallback to isEthersErrorCode(error, ethers.errors.NONCE_EXPIRED). No exported signatures changed.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch firekeeper/cosmos-nonce

🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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: 0

🧹 Nitpick comments (2)
src/shared/utils/error.ts (2)

21-23: Refactor to a centralized pattern list and use .some() for maintainability

This logic will be easier to extend and read if we move known substrings into a constant and use .some().

Apply this diff within the selected range:

-    return (
-      message.includes("nonce too low") || message.includes("already known") || message.includes("incorrect account sequence")
-    );
+    return NONCE_ALREADY_USED_PATTERNS.some((p) => message.includes(p));

Add this helper (outside the selected lines, e.g., near the top of the file):

const NONCE_ALREADY_USED_PATTERNS = [
  "nonce too low",
  "already known",
  "incorrect account sequence",
  // Consider adding, if seen in the wild:
  // "nonce too small", "nonce already used", "account sequence mismatch"
] as const;

Optionally, consider applying the same pattern-array approach to isReplacementGasFeeTooLow and isInsufficientFundsError for consistency.


17-17: Nit: Add explicit return type for clarity

Add an explicit boolean return type to align with stricter TS settings and improve readability. Consider doing the same for the other helpers.

-export const isNonceAlreadyUsedError = (error: unknown) => {
+export const isNonceAlreadyUsedError = (error: unknown): boolean => {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 60d9d97 and 67796a1.

📒 Files selected for processing (1)
  • src/shared/utils/error.ts (1 hunks)
🔇 Additional comments (2)
src/shared/utils/error.ts (2)

21-23: LGTM: Added support for "incorrect account sequence" is appropriate

Good call including this message. Cosmos/Ethermint-based EVM nodes (e.g., Cronos/Evmos) often surface stale nonce issues with that phrasing. The lowercase normalization in _parseMessage ensures this matches reliably, and the ethers NONCE_EXPIRED fallback remains intact.


17-27: Confirm handling of “incorrect account sequence” across all callers

The term “incorrect account sequence” can indicate either a stale/low nonce (nonce already used) or a gap/high nonce. We currently lump it into isNonceAlreadyUsedError, but each caller reacts differently:

• src/worker/tasks/send-transaction-worker.ts
– Lines 557–560: on isNonceAlreadyUsedError → resync nonce from chain and retry
– Lines 656–661: on isNonceAlreadyUsedError → assume tx already mined, stop and return null

• src/worker/tasks/cancel-recycled-nonces-worker.ts
– Lines 63–66: on isNonceAlreadyUsedError → skip recycling this nonce

Please verify that treating all “incorrect account sequence” errors as “nonce already used” is correct in each of these contexts. If some callers should only react to “too low” cases, consider refining the string‐matching logic or handling downstream.

@0xFirekeeper 0xFirekeeper merged commit b320e27 into main Aug 12, 2025
8 checks passed
@0xFirekeeper 0xFirekeeper deleted the firekeeper/cosmos-nonce branch August 12, 2025 17:48
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.

2 participants