Skip to content

Improve nonce management logic for private mempool handling#6277

Merged
jinchung merged 41 commits intodevelopfrom
@jin/nonce-mgmt
Dec 10, 2024
Merged

Improve nonce management logic for private mempool handling#6277
jinchung merged 41 commits intodevelopfrom
@jin/nonce-mgmt

Conversation

@jinchung
Copy link
Copy Markdown
Member

@jinchung jinchung commented Nov 21, 2024

Fixes APP-2048
Fixes APP-2040

What changed (plus any additional context for devs)

  • Add a placeholder in networks config for per-network configuration for private mempool timeout (default is 2 mins)
  • Populate timestamp param on new txns to keep it up to date when a txn is submitted or re-submitted (speed up/ cancel)
  • Update the nonce management logic as per specification (link in Linear ticket)
  • Add support for a batchedProvider from ethers v5 to submit the pending and latest txCount requests together
  • Removes flashbots logic and UI

Screen recordings / screenshots

ScreenRecording_12-06-2024.22-53-04_1.MP4

What to test

  • Mix of private mempool and public mempool transactions

@linear
Copy link
Copy Markdown

linear Bot commented Nov 21, 2024

hash: tx.hash,
nonce: tx.nonce,
protocol: tx.protocol,
timestamp: Date.now(),
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this function is used from both the "add new txn" flow and the "udpate txn" flow (for speed up / cancel)

Comment thread src/state/nonces/index.ts

const pendingTxCountRequest = provider.getTransactionCount(address, 'pending');
const latestTxCountRequest = provider.getTransactionCount(address, 'latest');
const [pendingTxCountFromPublicRpc, latestTxCountFromPublicRpc] = await Promise.all([pendingTxCountRequest, latestTxCountRequest]);
Copy link
Copy Markdown
Member Author

@jinchung jinchung Nov 21, 2024

Choose a reason for hiding this comment

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

batched provider will batch requests sent on the provider in the same event loop in ethers v5

@jinchung jinchung requested a review from brunobar79 November 21, 2024 22:45
Comment thread src/chains/index.ts
Comment thread src/handlers/web3.ts Outdated
Comment thread src/chains/index.ts
Copy link
Copy Markdown
Contributor

@ibrahimtaveras00 ibrahimtaveras00 left a comment

Choose a reason for hiding this comment

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

all fixes look good, QA Passed 👍🏽

@jinchung jinchung requested a review from derHowie December 2, 2024 17:49
setNonce({
address,
chainId,
currentNonce: currentProviderNonce > currentNonceForChainId ? currentProviderNonce : currentNonceForChainId,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this processNonces function is no longer needed - we don't use latestConfirmedNonce and the currentNonce will have been made up to date already when adding / updating the pending txn

});
const localNonceData = getNonce({ address, chainId });
const localNonce = localNonceData?.currentNonce || 0;
if (transaction.nonce > localNonce) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

now that we can pick up "gapped" nonces, we should check that the txn we are adding / updating has a larger nonce than what already exists before updating via setNonce

@brunobar79 brunobar79 added the release for release blockers and release candidate branches label Dec 2, 2024
@jinchung jinchung marked this pull request as ready for review December 2, 2024 19:20
@linear
Copy link
Copy Markdown

linear Bot commented Dec 2, 2024

Copy link
Copy Markdown
Contributor

@derHowie derHowie left a comment

Choose a reason for hiding this comment

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

code looks great, one v small suggestion 🥳

Comment thread src/state/nonces/index.ts
@brunobar79
Copy link
Copy Markdown
Contributor

Launch in simulator or device for 6661342

@brunobar79
Copy link
Copy Markdown
Contributor

Launch in simulator or device for 6d41812

@brunobar79 brunobar79 removed the release for release blockers and release candidate branches label Dec 5, 2024
@jinchung jinchung marked this pull request as draft December 6, 2024 19:57
@jinchung jinchung marked this pull request as ready for review December 7, 2024 03:56
@brunobar79
Copy link
Copy Markdown
Contributor

Launch in simulator or device for 04969b2

@jinchung jinchung merged commit 044daae into develop Dec 10, 2024
@jinchung jinchung deleted the @jin/nonce-mgmt branch December 10, 2024 21:58
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.

4 participants