Skip to content

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

Closed
backseats wants to merge 1 commit into
wevm:mainfrom
backseats:perf/parallel-prepare-transaction-request
Closed

backseats wants to merge 1 commit into
wevm:mainfrom
backseats:perf/parallel-prepare-transaction-request

Conversation

@backseats

Copy link
Copy Markdown
Contributor

prepareTransactionRequest requests the nonce, the latest block, and the priority fee one after another, although none of them depends on the others when the chain has no fee hooks. This PR requests them together. eth_estimateGas still runs last, with the nonce and fees filled in.

Effect

Traced with a local account on Base and 100 ms of simulated latency per RPC, on a node without eth_fillTransaction:

main this PR
Second transaction onward 406 ms (4 sequential requests) 205 ms (2 waves)
First transaction on a client 508 ms 406 ms

The first transaction gains less because the block is needed to detect EIP-1559 support before the priority fee can be requested. That result is cached per client.

With batch: true on the http transport, the three requests are sent as one batch.

Behavior

  • Chains that define a function under fees (baseFeeMultiplier, defaultPriorityFee, estimateFeesPerGas, maxPriorityFeePerGas) keep the sequential order, because those hooks receive the block and the request.
  • The prepared request is the same. Two things differ:
    • If the nonce request and a fee request both fail, the fee error is thrown. Before, the nonce error was.
    • When type: 'eip1559' is forced on a chain without EIP-1559, eth_maxPriorityFeePerGas is sent before the same Eip1559FeesNotSupportedError is thrown.
  • internal_estimateMaxPriorityFeePerGas accepts a block promise as well as a block, so its eth_gasPrice fallback reuses the block request instead of making a second one.

Tests

Two tests in prepareTransactionRequest.test.ts record which requests are pending when each request is sent. One asserts that the three requests overlap, and fails on main. The other asserts that they stay sequential on a chain with a fee hook.

Locally, args: maxFeePerGas (under default tip) (with eth_fillTransaction) and estimateGas > args: blobs fail for me on main as well as on this branch, so I left them alone. I did not run the Tempo suites.

…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.
@vercel

vercel Bot commented Nov 12, 2026

Copy link
Copy Markdown

@backseats is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Nov 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d0b3d03

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

jxom commented Nov 13, 2026

Copy link
Copy Markdown
Member

Thanks @backseats! Superseded by #5505, which keeps your commit and adds the review fixes on top (nonce error precedence, fee hook detection, and http-transport based tests).

@jxom jxom closed this Nov 13, 2026
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