aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-08-24 14:09:57 +0800
committerDan Finlay <dan@danfinlay.com>2017-08-24 14:13:42 +0800
commit17a71a9b4cb5cc23cbedfc52ba35c562dffdc02e (patch)
tree521c38c0a6199ca1d28fc5b9d1380caba7f29134 /app
parentf42687d25f844efd3be915e077cddcb4ccd458cf (diff)
downloadtangerine-wallet-browser-17a71a9b4cb5cc23cbedfc52ba35c562dffdc02e.tar
tangerine-wallet-browser-17a71a9b4cb5cc23cbedfc52ba35c562dffdc02e.tar.gz
tangerine-wallet-browser-17a71a9b4cb5cc23cbedfc52ba35c562dffdc02e.tar.bz2
tangerine-wallet-browser-17a71a9b4cb5cc23cbedfc52ba35c562dffdc02e.tar.lz
tangerine-wallet-browser-17a71a9b4cb5cc23cbedfc52ba35c562dffdc02e.tar.xz
tangerine-wallet-browser-17a71a9b4cb5cc23cbedfc52ba35c562dffdc02e.tar.zst
tangerine-wallet-browser-17a71a9b4cb5cc23cbedfc52ba35c562dffdc02e.zip
Only cancel pending txs with non continuously high nonces
Diffstat (limited to 'app')
-rw-r--r--app/scripts/migrations/019.js25
1 files changed, 24 insertions, 1 deletions
diff --git a/app/scripts/migrations/019.js b/app/scripts/migrations/019.js
index 9dfe96050..d41b39d1c 100644
--- a/app/scripts/migrations/019.js
+++ b/app/scripts/migrations/019.js
@@ -30,6 +30,7 @@ module.exports = {
function transformState (state) {
const newState = state
const transactions = newState.TransactionController.transactions
+
newState.TransactionController.transactions = transactions.map((txMeta, _, txList) => {
if (txMeta.status !== 'submitted') return txMeta
@@ -38,7 +39,14 @@ function transformState (state) {
.filter((tx) => tx.metamaskNetworkId.from === txMeta.metamaskNetworkId.from)
const highestConfirmedNonce = getHighestNonce(confirmedTxs)
- if (parseInt(txMeta.txParams.nonce, 16) > highestConfirmedNonce + 1) {
+ const pendingTxs = txList.filter((tx) => tx.status === 'submitted')
+ .filter((tx) => tx.txParams.from === txMeta.txParams.from)
+ .filter((tx) => tx.metamaskNetworkId.from === txMeta.metamaskNetworkId.from)
+ const highestContinuousNonce = getHighestContinuousFrom(pendingTxs, highestConfirmedNonce)
+
+ const maxNonce = Math.max(highestContinuousNonce, highestConfirmedNonce)
+
+ if (parseInt(txMeta.txParams.nonce, 16) > maxNonce + 1) {
txMeta.status = 'failed'
txMeta.err = {
message: 'nonce too high',
@@ -50,6 +58,20 @@ function transformState (state) {
return newState
}
+function getHighestContinuousFrom (txList, startPoint) {
+ const nonces = txList.map((txMeta) => {
+ const nonce = txMeta.txParams.nonce
+ return parseInt(nonce, 16)
+ })
+
+ let highest = startPoint
+ while (nonces.includes(highest)) {
+ highest++
+ }
+
+ return { name: 'local', nonce: highest, details: { startPoint, highest } }
+}
+
function getHighestNonce (txList) {
const nonces = txList.map((txMeta) => {
const nonce = txMeta.txParams.nonce
@@ -58,3 +80,4 @@ function getHighestNonce (txList) {
const highestNonce = Math.max.apply(null, nonces)
return highestNonce
}
+