aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-10-07 03:51:13 +0800
committerDan Finlay <dan@danfinlay.com>2017-10-07 03:51:13 +0800
commita417fab0ebd71d22f51a8e30590c259b32164fd2 (patch)
treed4ace491cfd417fc9afca2733b141b92e2a157d2 /app/scripts
parent94513cae7bf3c8310ae6a248e12a9b7dd73e306f (diff)
downloadtangerine-wallet-browser-a417fab0ebd71d22f51a8e30590c259b32164fd2.tar
tangerine-wallet-browser-a417fab0ebd71d22f51a8e30590c259b32164fd2.tar.gz
tangerine-wallet-browser-a417fab0ebd71d22f51a8e30590c259b32164fd2.tar.bz2
tangerine-wallet-browser-a417fab0ebd71d22f51a8e30590c259b32164fd2.tar.lz
tangerine-wallet-browser-a417fab0ebd71d22f51a8e30590c259b32164fd2.tar.xz
tangerine-wallet-browser-a417fab0ebd71d22f51a8e30590c259b32164fd2.tar.zst
tangerine-wallet-browser-a417fab0ebd71d22f51a8e30590c259b32164fd2.zip
When checking pending txs, check for successful txs with same nonce.
If a successful tx with the same nonce exists, transition tx to the failed state. Fixes #2294
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/lib/pending-tx-tracker.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/app/scripts/lib/pending-tx-tracker.js b/app/scripts/lib/pending-tx-tracker.js
index 8a626e222..2d8f22ae8 100644
--- a/app/scripts/lib/pending-tx-tracker.js
+++ b/app/scripts/lib/pending-tx-tracker.js
@@ -25,6 +25,7 @@ module.exports = class PendingTransactionTracker extends EventEmitter {
// default is one day
this.retryTimePeriod = config.retryTimePeriod || 86400000
this.getPendingTransactions = config.getPendingTransactions
+ this.getCompletedTransactions = config.getCompletedTransactions
this.publishTransaction = config.publishTransaction
}
@@ -120,6 +121,7 @@ module.exports = class PendingTransactionTracker extends EventEmitter {
async _checkPendingTx (txMeta) {
const txHash = txMeta.hash
const txId = txMeta.id
+
// extra check in case there was an uncaught error during the
// signature and submission process
if (!txHash) {
@@ -128,6 +130,15 @@ module.exports = class PendingTransactionTracker extends EventEmitter {
this.emit('tx:failed', txId, noTxHashErr)
return
}
+
+ // If another tx with the same nonce is mined, set as failed.
+ const taken = await this._checkIfNonceIsTaken(txMeta)
+ if (taken) {
+ const nonceTakenErr = new Error('Another transaction with this nonce has been mined.')
+ nonceTakenErr.name = 'NonceTakenErr'
+ return this.emit('tx:failed', txId, nonceTakenErr)
+ }
+
// get latest transaction status
let txParams
try {
@@ -159,4 +170,13 @@ module.exports = class PendingTransactionTracker extends EventEmitter {
}
nonceGlobalLock.releaseLock()
}
+
+ async _checkIfNonceIsTaken (txMeta) {
+ const completed = this.getCompletedTransactions()
+ const sameNonce = completed.filter((otherMeta) => {
+ return otherMeta.txParams.nonce === txMeta.txParams.nonce
+ })
+ return sameNonce.length > 0
+ }
+
}