Skip to content

feat(bundler): enhance error handling and nonce management in execute…#467

Merged
onahprosper merged 1 commit into
stablefrom
fix/bundler-execute-sponsored-nonce
Apr 18, 2026
Merged

feat(bundler): enhance error handling and nonce management in execute…#467
onahprosper merged 1 commit into
stablefrom
fix/bundler-execute-sponsored-nonce

Conversation

@onahprosper
Copy link
Copy Markdown
Collaborator

Description

This change hardens sponsored execution in app/lib/bundler/executeSponsored.ts so /api/bundler/execute-sponsored recovers when the sponsor wallet nonce is wrong or the RPC reports a stale nonce.

Previously, retry logic only treated an error as “nonce too low” if err.message contained that substring. Viem often puts the human-readable explanation in the top-level message (for example, nonce lower than the account’s current nonce) and puts nonce too low: next nonce … in details or nested RPC cause objects, so retries never ran and users saw 500s.

The implementation now collects text from the full viem error chain (including plain-object causes), matches several nonce-too-low phrasings, retries up to three times, chooses the next nonce with max(latest, pending) from eth_getTransactionCount, and when the RPC includes it, parses next nonce N from the error and uses the maximum of that and the RPC-derived nonce.

There are no API or contract changes. Behavior is limited to the bundler’s sponsor transaction path.

References

Testing

How reviewers can test

  1. Run Noblocks locally (pnpm dev) with a configured sponsor key and Base (or another EVM chain) RPC used by the bundler.
  2. Trigger a flow that calls POST /api/bundler/execute-sponsored (EOA + EIP-7702 batch path).
  3. Confirm the request succeeds when the chain nonce is correct; if a stale nonce scenario is hard to reproduce, temporarily misconfigure or simulate RPC lag only in a dev environment.

Not covered

  • No new automated tests were added for this path; manual verification against a testnet or careful mainnet testing is the practical check.

Environment

  • Developed with Node/pnpm and Next.js as in the Noblocks app; viem 2.x as used by the project.

  • This change adds test coverage for new/changed/fixed functionality

Checklist

  • I have added documentation and tests for new/changed functionality in this PR
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used, if not main

By submitting a PR, I agree to Paycrest's Contributor Code of Conduct and Contribution Guide.

…Sponsored function

- Introduced stringifyViemError to collect detailed error messages from viem error chains.
- Added parseNextNonceFromErrorText to extract the next nonce from error messages.
- Refactored getNextTxNonce to improve nonce retrieval logic.
- Implemented retry mechanism in executeSponsored for handling nonce-related errors with dynamic fee adjustments.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 18, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 249b3cc8-2626-48b0-a1c8-0a9ae4adaccd

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/bundler-execute-sponsored-nonce

Comment @coderabbitai help to get the list of available commands and usage tips.

@onahprosper onahprosper merged commit 6b59c5a into stable Apr 18, 2026
1 check passed
@onahprosper onahprosper deleted the fix/bundler-execute-sponsored-nonce branch April 18, 2026 09:41
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.

1 participant