Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve nonce management logic for private mempool handling #6277

Merged
merged 41 commits into from
Dec 10, 2024

Conversation

jinchung
Copy link
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

Copy link

linear bot commented Nov 21, 2024

@@ -148,6 +148,7 @@ export const convertNewTransactionToRainbowTransaction = (tx: NewTransaction): R
hash: tx.hash,
nonce: tx.nonce,
protocol: tx.protocol,
timestamp: Date.now(),
Copy link
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)


const pendingTxCountRequest = provider.getTransactionCount(address, 'pending');
const latestTxCountRequest = provider.getTransactionCount(address, 'latest');
const [pendingTxCountFromPublicRpc, latestTxCountFromPublicRpc] = await Promise.all([pendingTxCountRequest, latestTxCountRequest]);
Copy link
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
src/handlers/web3.ts Outdated Show resolved Hide resolved
src/chains/index.ts Show resolved Hide resolved
Copy link
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
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
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
Copy link

linear bot commented Dec 2, 2024

Copy link
Member

@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 🥳

src/state/nonces/index.ts Outdated Show resolved Hide resolved
@brunobar79
Copy link
Member

Launch in simulator or device for 6661342

@brunobar79
Copy link
Member

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
Member

Launch in simulator or device for 04969b2

@jinchung jinchung merged commit 044daae into develop Dec 10, 2024
8 checks passed
@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