aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib/pending-tx-tracker.js
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-10-13 00:59:28 +0800
committerDan Finlay <dan@danfinlay.com>2017-10-13 01:25:19 +0800
commitd0d082d70c1e256aeb70f90fcdc864aeca00aed4 (patch)
treea487d9bb888eebeba9c68d570cc55a5541384451 /app/scripts/lib/pending-tx-tracker.js
parent1cba6543a42561c6691736d58f45e97f4832912b (diff)
parent29ee33359e818525549b5241adb6f5903a054bba (diff)
downloadtangerine-wallet-browser-d0d082d70c1e256aeb70f90fcdc864aeca00aed4.tar
tangerine-wallet-browser-d0d082d70c1e256aeb70f90fcdc864aeca00aed4.tar.gz
tangerine-wallet-browser-d0d082d70c1e256aeb70f90fcdc864aeca00aed4.tar.bz2
tangerine-wallet-browser-d0d082d70c1e256aeb70f90fcdc864aeca00aed4.tar.lz
tangerine-wallet-browser-d0d082d70c1e256aeb70f90fcdc864aeca00aed4.tar.xz
tangerine-wallet-browser-d0d082d70c1e256aeb70f90fcdc864aeca00aed4.tar.zst
tangerine-wallet-browser-d0d082d70c1e256aeb70f90fcdc864aeca00aed4.zip
Merge branch 'master' into i1340-SynchronousInjection
Diffstat (limited to 'app/scripts/lib/pending-tx-tracker.js')
-rw-r--r--app/scripts/lib/pending-tx-tracker.js29
1 files changed, 26 insertions, 3 deletions
diff --git a/app/scripts/lib/pending-tx-tracker.js b/app/scripts/lib/pending-tx-tracker.js
index 6f1601586..df504c126 100644
--- a/app/scripts/lib/pending-tx-tracker.js
+++ b/app/scripts/lib/pending-tx-tracker.js
@@ -22,9 +22,12 @@ module.exports = class PendingTransactionTracker extends EventEmitter {
super()
this.query = new EthQuery(config.provider)
this.nonceTracker = config.nonceTracker
- this.retryLimit = config.retryLimit || Infinity
+ // default is one day
+ this.retryTimePeriod = config.retryTimePeriod || 86400000
this.getPendingTransactions = config.getPendingTransactions
+ this.getCompletedTransactions = config.getCompletedTransactions
this.publishTransaction = config.publishTransaction
+ this._checkPendingTxs()
}
// checks if a signed tx is in a block and
@@ -99,8 +102,9 @@ module.exports = class PendingTransactionTracker extends EventEmitter {
}
async _resubmitTx (txMeta) {
- if (txMeta.retryCount > this.retryLimit) {
- const err = new Error(`Gave up submitting after ${this.retryLimit} blocks un-mined.`)
+ if (Date.now() > txMeta.time + this.retryTimePeriod) {
+ const hours = (this.retryTimePeriod / 3.6e+6).toFixed(1)
+ const err = new Error(`Gave up submitting after ${hours} hours.`)
return this.emit('tx:failed', txMeta.id, err)
}
@@ -118,6 +122,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) {
@@ -126,6 +131,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 {
@@ -157,4 +171,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
+ }
+
}