Skip to content

[BWS, BWC] EVM JIT Nonce#4124

Draft
leolambo wants to merge 9 commits intobitpay:masterfrom
leolambo:evmJitNonce
Draft

[BWS, BWC] EVM JIT Nonce#4124
leolambo wants to merge 9 commits intobitpay:masterfrom
leolambo:evmJitNonce

Conversation

@leolambo
Copy link
Contributor

Description

Link to an issue if one exists and/or briefly describe what problem this PR is solving.

Changelog

  • Add bullet points summarizing your changes.

Testing Notes

Add any helpful notes for reviewers to test your code here.


Checklist

  • I have read CONTRIBUTING.md and verified that this PR follows the guidelines and requirements outlined in it.

leolambo added 9 commits March 5, 2026 12:14
EVM nonces assigned at txp creation time go stale when proposals
sit waiting for signing. Add an opt-in deferNonce boolean so
callers can signal that nonce assignment should happen later.

Field added to ITxProposal interface, TxProposal class,
create(), and fromObj() for persistence round-tripping.
When deferNonce is true, skip the getTransactionCount call during
createTx and pass the flag through to TxProposal.create() so it
persists on the proposal object.
Allow deferred-nonce txps to be published and re-published. Use
prePublishRaw to store the original unsigned tx so proposal
signature verification still works after nonce is assigned later.
Deferred-nonce proposals have nonce=null until assignNonce is
called. Without null guards, the nonce comparison would coerce
null to 0 and falsely trigger TX_NONCE_CONFLICT.
New endpoint lets the client request a fresh nonce just before
signing. The handler fetches the confirmed nonce from the
blockchain, skips past any pending proposal nonces in the
database, and stores the gap-free result on the txp.

Runs under _runLocked to prevent concurrent calls from receiving
the same nonce for the same wallet.
Calls POST /v1/txproposals/{id}/assign-nonce/ so the app can
request a fresh nonce from BWS just before signing a
deferred-nonce transaction proposal.
Cover the full lifecycle: createTx with deferNonce, publishTx
with prePublishRaw, assignNonce with gap-free calculation,
signTx without false nonce conflicts, and broadcast.

Includes a bulk-sign scenario that assigns sequential nonces
to three deferred proposals signed one after another.
The repeated isRepublishEnabled() || deferNonce pattern in
publishTx exists because both Solana blockhash refresh and EVM
deferred nonce share the same need: preserve prePublishRaw for
signature verification after the raw tx changes.

Also remove unnecessary spread-copy before sorting pendingNonces
in assignNonce since filter/map already produces a new array.
Consolidate into the existing integration test file rather than
maintaining a separate file for one feature. Tests are placed
under a new #assignNonce describe block between #signTx and
#broadcastTx to match the transaction lifecycle order.
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