-
Notifications
You must be signed in to change notification settings - Fork 579
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
chore: migrate nonce state #5395
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f8bcda5
chore: migrate nonce state
skylarbarrera 2b0aeee
try
skylarbarrera bd90dbc
audit: ip
skylarbarrera 26404e1
Merge branch '@skylar/audit-ip' into @skylar/nonces
skylarbarrera bce7816
clean up
skylarbarrera 19b48e2
rm redux dep
skylarbarrera 3ba0a31
disable tests
skylarbarrera File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +0,0 @@ | ||
import { useCallback } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { EthereumAddress } from '@/entities'; | ||
import { getProviderForNetwork } from '@/handlers/web3'; | ||
import { Network } from '@/helpers/networkTypes'; | ||
import { AppState } from '@/redux/store'; | ||
import logger from '@/utils/logger'; | ||
|
||
export default function useCurrentNonce(accountAddress: EthereumAddress, network?: Network) { | ||
const nonceInState = useSelector((state: AppState) => { | ||
if (!network || !accountAddress) return undefined; | ||
return state.nonceManager[accountAddress.toLowerCase()]?.[network]?.nonce; | ||
}); | ||
const getNextNonce = useCallback(async () => { | ||
try { | ||
if (!network || !accountAddress) return undefined; | ||
const provider = await getProviderForNetwork(network); | ||
const transactionCount = await provider.getTransactionCount(accountAddress, 'pending'); | ||
const transactionIndex = transactionCount - 1; | ||
const nextNonceBase = !nonceInState || transactionIndex > nonceInState ? transactionIndex : nonceInState; | ||
const nextNonce = nextNonceBase + 1; | ||
|
||
logger.log('Use current nonce: ', { | ||
accountAddress, | ||
network, | ||
nextNonce, | ||
nonceInState, | ||
transactionCount, | ||
}); | ||
|
||
return nextNonce; | ||
} catch (e) { | ||
logger.log('Error determining next nonce: ', e); | ||
return undefined; | ||
} | ||
}, [accountAddress, network, nonceInState]); | ||
|
||
return getNextNonce; | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ import { StaticJsonRpcProvider, TransactionResponse } from '@ethersproject/provi | |
import { isEmpty, isNil, mapValues, partition } from 'lodash'; | ||
import { Dispatch } from 'redux'; | ||
import { ThunkDispatch } from 'redux-thunk'; | ||
import { decrementNonce, incrementNonce } from './nonceManager'; | ||
import { AppGetState, AppState } from './store'; | ||
import { | ||
NativeCurrencyKeys, | ||
|
@@ -43,6 +42,7 @@ import { queryClient } from '@/react-query'; | |
import { RainbowAddressAssets } from '@/resources/assets/types'; | ||
import { nftsQueryKey } from '@/resources/nfts'; | ||
import { getProvider } from 'e2e/helpers'; | ||
import { nonceStore } from '@/state/nonces'; | ||
|
||
const BACKUP_SHEET_DELAY_MS = android ? 10000 : 3000; | ||
|
||
|
@@ -358,9 +358,9 @@ const checkForUpdatedNonce = | |
const [latestTx] = txSortedByDescendingNonce; | ||
const addressFrom = latestTx?.address_from; | ||
const nonce = latestTx?.nonce; | ||
if (addressFrom && nonce) { | ||
// @ts-ignore-next-line | ||
dispatch(incrementNonce(addressFrom!, nonce, network)); | ||
if (!isNil(addressFrom) && nonce) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ts check |
||
const { setNonce } = nonceStore.getState(); | ||
setNonce({ address: addressFrom, currentNonce: nonce, network }); | ||
} | ||
} | ||
}; | ||
|
@@ -587,11 +587,9 @@ export const dataAddNewTransaction = | |
|
||
loggr.debug('dataAddNewTransaction: adding pending transactions', {}, loggr.DebugContext.f2c); | ||
|
||
if (parsedTransaction.from && parsedTransaction.nonce) { | ||
dispatch( | ||
// @ts-ignore-next-line | ||
incrementNonce(parsedTransaction.from, parsedTransaction.nonce, parsedTransaction.network) | ||
); | ||
if (parsedTransaction.from && parsedTransaction.nonce && parsedTransaction.network) { | ||
const { setNonce } = nonceStore.getState(); | ||
setNonce({ address: parsedTransaction.from, currentNonce: parsedTransaction.nonce, network: parsedTransaction.network }); | ||
} | ||
if (!disableTxnWatcher || network !== Network.mainnet || parsedTransaction?.network) { | ||
loggr.debug('dataAddNewTransaction: watching new pending transactions', {}, loggr.DebugContext.f2c); | ||
|
@@ -714,9 +712,13 @@ export const dataWatchPendingTransactions = | |
pendingTransactionData = await getTransactionFlashbotStatus(updatedPendingTransaction, txHash); | ||
if (pendingTransactionData && !pendingTransactionData.pending) { | ||
txStatusesDidChange = true; | ||
// decrement the nonce since it was dropped | ||
// @ts-ignore-next-line | ||
dispatch(decrementNonce(tx.from!, tx.nonce!, Network.mainnet)); | ||
if (tx.from && tx.network) { | ||
const { setNonce, nonces } = nonceStore.getState(); | ||
const currentNonce = nonces[tx.from!][tx.network].currentNonce; | ||
if (currentNonce) { | ||
setNonce({ address: tx.from, currentNonce: currentNonce - 1, network: tx.network }); | ||
} | ||
} | ||
} | ||
} | ||
if (pendingTransactionData) { | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can rename these but meh, we should slowly try to remove all of these
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick but can you rename these to p1, p2, p3, p4, p5, p6