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

fix: Reset nonce if wallet is out of funds #791

Closed
wants to merge 3 commits into from

Conversation

arcoraven
Copy link
Contributor

@arcoraven arcoraven commented Dec 6, 2024

PR-Codex overview

This PR focuses on simplifying error handling related to nonce usage and insufficient funds in the transaction process. It refines error checks and modifies the logic for handling insufficient funds, ensuring clearer responses and better nonce management.

Detailed summary

  • Updated isNonceAlreadyUsedError to use direct string checks instead of an array.
  • Simplified isInsufficientFundsError to check for a single phrase.
  • Refactored _sendTransaction to improve handling of insufficient funds and nonce recycling.
  • Added deleteNoncesForBackendWallets call to reset nonce state when funds are insufficient.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

@@ -16,11 +16,9 @@ const _parseMessage = (error: unknown): string | null => {

export const isNonceAlreadyUsedError = (error: unknown) => {
const message = _parseMessage(error);
const errorPhrases = ["nonce too low", "already known"];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

cleanup, no logical change

Comment on lines +360 to +362
if (value === 0n) {
await deleteNoncesForBackendWallets([{ chainId, walletAddress: from }]);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the main change. If a transaction received an "insufficient funds" error from RPC and no value was provided, this wallet must be low on gas. Reset the nonce so the onchain nonce doesn't remain out of sync.

return {
...queuedTransaction,
status: "errored",
errorMessage,
} satisfies ErroredTransaction;
}

if (isNonceAlreadyUsedError(error) || isReplacementGasFeeTooLow(error)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just moving this below the "out of funds" block above. No logic changes.

@arcoraven arcoraven closed this Dec 11, 2024
@arcoraven arcoraven deleted the ph/deleteNoncesIfOutOfFunds branch December 11, 2024 02:32
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