Skip to content

Conversation

@L03TJ3
Copy link
Contributor

@L03TJ3 L03TJ3 commented Oct 10, 2025

Description

Web3Wallet did not handle a too-low nonce correctly.
It became part of a generic error handler, and would re-use the latest network nonce for the next transaction.

About # (link your issue here)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • PR title matches follow: (Feature|Bug|Chore) Task Name
  • My code follows the style guidelines of this project
  • I have followed all the instructions described in the initial task (check Definitions of Done)
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have added reference to a related issue in the repository
  • I have added a detailed description of the changes proposed in the pull request. I am as descriptive as possible, assisting reviewers as much as possible.
  • I have added screenshots related to my pull request (for frontend tasks)
  • I have pasted a gif showing the feature.
  • @mentions of the person or team responsible for reviewing proposed changes

Description by Korbit AI

What change is being made?

Add handling for "nonce too low" errors in Web3Wallet.sendTransaction by catching such errors, logging a warning with context, unlocking and advancing the nonce (netNonce + 1), and retrying the transaction.

Why are these changes being made?

To properly recover from situations where the local nonce is behind the network nonce, ensuring transactions with too-low nonces are retried successfully instead of failing. This improves reliability when multiple submissions or race conditions occur.

Is this description stale? Ask me to generate a new description by commenting /korbit-generate-pr-description

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `src/server/blockchain/Web3Wallet.js:1200` </location>
<code_context>
         // increase nonce, since we assume therre's a tx pending with same nonce
         await this.txManager.unlock(currentAddress, currentNonce + 1)

</code_context>

<issue_to_address>
**issue (complexity):** Consider extracting the duplicated nonce retry logic into a helper method to centralize error handling and reduce repetition.

```suggestion
// Extract the "unlock + sendTransaction" retry path into a small helper
private async retryWithNonce(
  nextNonce: number,
  tx: TransactionRequest,
  txCallbacks: TxCallbacks,
  gasParams: GasParams,
  logger: Logger,
  context: { error: string, currentAddress: string, currentNonce: number, netNonce: number, txuuid: string, txHash: string }
) {
  logger.warn('sendTransaction retrying tx with wrong nonce:', context)
  await this.txManager.unlock(context.currentAddress, nextNonce)
  return this.sendTransaction(
    tx,
    txCallbacks,
    gasParams,
    false,
    logger
  )
}



} catch (e) {
  const errMsg = e.message.toLowerCase()

  if (retry && errMsg.includes('nonce')) {
    // pick which nonce bump makes sense
    const nextNonce = errMsg.includes('too low')
      ? netNonce + 1
      : currentNonce + 1

    return this.retryWithNonce(
      nextNonce,
      tx,
      txCallbacks,
      { gas, gasPrice, maxFeePerGas, maxPriorityFeePerGas },
      logger,
      { error: e.message, currentAddress, currentNonce, netNonce, txuuid, txHash }
    )
  }

  if (retry && !errMsg.includes('revert')) {
    logger.warn('sendTransaction retrying non-reverted error:', {
      error: e.message, currentAddress, currentNonce, netNonce, txuuid, txHash, wallet: this.name, network: this.networkId
    })
    // …other retry logic…
  }

  throw e
}
```

Benefits:
- Removes two duplicated `unlock + sendTransaction` blocks
- Centralizes logging and retry invocation
- Keeps linear flow and DRY principle without changing behavior
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

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

I've completed my review and didn't find any issues... but I did find this bunny.

(\(\
( -.-)
o_(")(")
Files scanned
File Path Reviewed
src/server/blockchain/Web3Wallet.js

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X

@L03TJ3 L03TJ3 requested a review from sirpy October 10, 2025 15:19
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