feat(bundler): enhance error handling and nonce management in execute…#467
Merged
Merged
Conversation
…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.
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This change hardens sponsored execution in
app/lib/bundler/executeSponsored.tsso/api/bundler/execute-sponsoredrecovers 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.messagecontained 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 putsnonce too low: next nonce …indetailsor nested RPCcauseobjects, 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)frometh_getTransactionCount, and when the RPC includes it, parsesnext nonce Nfrom 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
pnpm dev) with a configured sponsor key and Base (or another EVM chain) RPC used by the bundler.POST /api/bundler/execute-sponsored(EOA + EIP-7702 batch path).Not covered
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
mainBy submitting a PR, I agree to Paycrest's Contributor Code of Conduct and Contribution Guide.