Skip to content

feat: pass the consumed nonce to NonceManager.reset - #5373

Merged
jxom merged 2 commits into
mainfrom
fix/nonce-manager-reset-nonce
Nov 1, 2026
Merged

jxom merged 2 commits into
mainfrom
fix/nonce-manager-reset-nonce

Conversation

@jxom

@jxom jxom commented Nov 1, 2026

Copy link
Copy Markdown
Member

Closes #5352. Supersedes #5369, keeping its commit by @aelmanaa (rebased onto main) with review fixes on top.

When sendTransaction or sendTransactionSync fails after the account's nonce manager consumed a nonce, reset now receives that nonce as an optional nonce field. It is omitted when consume threw. A manager that reserves a nonce per send can use it to release only the failed send's nonce when sends overlap. Existing managers keep working: createNonceManager ignores the field, and a reset typed with only { address, chainId } is still assignable to NonceManager.

Changes on top of #5369:

  • Tests no longer use vi.spyOn or call-count assertions. They use custom nonce managers that keep released nonces in a free list, and snapshot the nonces each broadcast signs. With three concurrent sends where the nonce-6 broadcast fails, only 6 is released and the next send reuses it ([5, 6, 7, 6]). The two release tests fail without the source change.
  • Docs warn that a failed send does not prove the nonce is unused (the node may have accepted it before, for example, a timeout), in the reset TSDoc and on the createNonceManager page.
  • Changeset shortened to one sentence.

Verification: the 4 new tests pass. I ran them with the Anvil beforeAll disabled, since Anvil isn't available in my environment and these tests only use a custom transport. tsc -b reports no errors in changed files; its only errors come from contracts/generated.js missing without Foundry.

Not changed: the reset parameter type stays unexported (as in #5369); implementers can use Parameters<NonceManager['reset']>[0]. The two existing "does not reset an unconsumed nonce" tests still use vi.spyOn.


Generated by Claude Code

aelmanaa and others added 2 commits November 1, 2026 21:47
Port of #5353 to main. Add an optional nonce to reset's parameters, set
to what consume returned and left out when consume threw, in
sendTransaction and sendTransactionSync.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewrite the reset-nonce tests to use custom nonce managers instead of
`vi.spyOn`, asserting the broadcast nonces: a failed send's nonce is the
only one released and the next send reuses it. Document that a failed send
does not prove its nonce is unused, and shorten the changeset to one
sentence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D3nmWi1KSPEvFxpccK5EDN
@vercel

vercel Bot commented Nov 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
viem Building Building Preview Nov 1, 2026 9:54pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Nov 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a960a47

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
viem Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T21:58:46.468219Z a960a47 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@jxom
jxom merged commit ddc2d36 into main Nov 1, 2026
34 of 36 checks passed
@jxom
jxom deleted the fix/nonce-manager-reset-nonce branch November 1, 2026 21:56

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a960a477df

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +374 to +375
transport: custom({
async request({ method, params }) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Run nonce-reset coverage against a real test chain

The four newly added tests replace RPC behavior with custom({ request(...) }) handlers, including synthesizing broadcast failures and successful hashes, so they validate a hand-built fake client rather than the configured chain behavior. Rework these cases to trigger the failure and nonce reuse through the configured Anvil chain or a real ephemeral server, as required by the repository’s explicit prohibition on mocks, stubs, and fake clients.

AGENTS.md reference: AGENTS.md:L153-L157

Useful? React with 👍 / 👎.

Comment thread src/utils/nonceManager.ts
get: (chainId: FunctionParameters & { client: Client }) => Promise<number>
/** Reset a nonce. */
reset: (chainId: FunctionParameters) => void
reset: (chainId: ResetParameters) => void

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add a public type test for the reset parameter

Changing the exported NonceManager.reset parameter is a public type-surface change, but the added runtime tests only consume that type internally and do not verify through a package entrypoint that nonce is exposed or that existing reset implementations remain assignable. Add a colocated .test-d.ts assertion and public type snapshot for this signature.

AGENTS.md reference: AGENTS.md:L72-L73

Useful? React with 👍 / 👎.

type NonceManager,
nonceManager,
} from './nonceManager.js'
import { parseTransaction } from './transaction/parseTransaction.js'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Import parseTransaction through the package entrypoint

parseTransaction is a public root export, so importing its implementation by a relative path makes this test depend on internal file layout instead of exercising the supported consumer surface. Import it from the viem test alias as required for public APIs.

AGENTS.md reference: AGENTS.md:L186-L190

Useful? React with 👍 / 👎.

This branch was successfully deployed

1 active deployment
Preview — a960a477 Deployed Nov 1, 2026 by vercel[bot]
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.

NonceManager.reset gets no nonce, so a per-send manager can't match it to its consume

3 participants