Skip to content

perf: fetch nonce, block, and priority fee concurrently in prepareTransactionRequest - #5505

Merged
jxom merged 2 commits into
mainfrom
perf/concurrent-prepare-transaction-request
Nov 13, 2026
Merged

jxom merged 2 commits into
mainfrom
perf/concurrent-prepare-transaction-request

Conversation

@jxom

@jxom jxom commented Nov 13, 2026

Copy link
Copy Markdown
Member

Supersedes #5501 by @backseats. Their commit is kept as is, and the review fixes are in a second commit.

prepareTransactionRequest used to request the nonce, the latest block, and the priority fee one after another, even though none of them depends on the others when the chain has no fee hooks. They are now requested together. eth_estimateGas still runs last, with the nonce and fees filled in.

Effect

Measured against Anvil with a real http transport, 150 ms of added latency per request, and eth_fillTransaction disabled. Each cell shows requests / round trips.

Case main this PR
Nothing supplied, cold type cache 4 / 4 4 / 3
Nothing supplied, warm type cache 4 / 4 4 / 2
type: 'eip1559' 4 / 4 4 / 2
nonce supplied 3 / 3 3 / 3
gasPrice (legacy) 2 / 2 2 / 2
maxFeePerGas + maxPriorityFeePerGas 2 / 2 2 / 2
Only maxFeePerGas 4 / 4 4 / 2
Only maxPriorityFeePerGas 3 / 3 3 / 2
parameters without fees 3 / 3 3 / 2
JSON-RPC account 4 / 4 4 / 3
Local account + nonceManager 4 / 4 4 / 4
Chain with a fee hook 4 / 4 4 / 4
No chain on the client 5 / 5 5 / 4

No case sends extra requests. Nodes that support eth_fillTransaction still use a single request.

Behavior

  • Fee hooks: chains with a function under fees keep the sequential order, so the hooks still receive the block and a request that includes the nonce.
  • Error precedence: a failed nonce request takes precedence over errors from the requests made alongside it, so the same error is thrown as on main. (Review fix.)
  • Extra requests on failure: when the nonce request fails, the block and priority-fee requests have already been sent.
  • Forced type: 'eip1559': on a chain without EIP-1559, eth_maxPriorityFeePerGas is sent before the same Eip1559FeesNotSupportedError is thrown.
  • internal_estimateMaxPriorityFeePerGas: it now accepts a block promise, so its eth_gasPrice fallback reuses the block request. The public estimateMaxPriorityFeePerGas is unchanged.

Tests

  • Concurrency: these tests record pending requests through the http transport's onFetchRequest and onFetchResponse hooks. One test asserts that the three requests overlap, and it fails on main. Another asserts that they stay sequential on a chain with a fee hook.
  • Error precedence: a new test uses createRpcProxy to make both the nonce and the block requests fail. It fails without the fix.
  • Pre-existing failure: with eth_fillTransaction > args: maxFeePerGas (under default tip) also fails on main with Anvil 1.9.0.

backseats and others added 2 commits November 13, 2026 02:43
…nsactionRequest

The nonce, latest block, and priority fee were requested one after another,
although none of them depends on the others when the chain has no fee hooks.
They are now requested together, so preparing a transaction takes two round
trips instead of four once the chain's EIP-1559 support is cached.

Chains that define function fee hooks keep the sequential order, since the
hooks receive the block and the request.

Co-authored-by: jxom <[email protected]>
A failed nonce request now takes precedence over errors from the
parameters fetched concurrently with it. Fee hooks are detected from any
function-valued chain fee, and the concurrency tests record requests with
a real http transport.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1d0ba-847b-7727-be9d-a69b96b1d6b7
Co-authored-by: jxom <[email protected]>
@changeset-bot

changeset-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9cd7df5

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

@vercel

vercel Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
viem Error Error Nov 13, 2026 2:56am UTC

Request Review

@chatgpt-codex-connector

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

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T02:54:13.690080Z 9cd7df5 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.

@github-actions

Copy link
Copy Markdown
Contributor

Published [email protected] under the pr-5505 dist-tag, which follows this pull request until it closes.

pnpm add viem@pr-5505
pnpm add [email protected]

@jxom
jxom merged commit 8d3f29e into main Nov 13, 2026
36 of 38 checks passed
@jxom
jxom deleted the perf/concurrent-prepare-transaction-request branch November 13, 2026 04:49
@github-actions github-actions Bot mentioned this pull request Nov 13, 2026

This branch had an error being deployed

1 failed deployment
Preview — 9cd7df5a Deployed Nov 13, 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.

3 participants