diff options
author | Chi Kei Chan <chikeichan@gmail.com> | 2017-10-19 14:04:54 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-19 14:04:54 +0800 |
commit | 776e8241f0464939cc3049f7155c150e3375c623 (patch) | |
tree | 017600778515e74eaf15bf4f889e5b26638c56d7 /app/scripts/lib/pending-tx-tracker.js | |
parent | de1da7d1b215ade650fc644adf63384a401dc240 (diff) | |
parent | a8bba2f4b7ca714d46b2e1ca405aec3135aa23b2 (diff) | |
download | tangerine-wallet-browser-776e8241f0464939cc3049f7155c150e3375c623.tar.gz tangerine-wallet-browser-776e8241f0464939cc3049f7155c150e3375c623.tar.zst tangerine-wallet-browser-776e8241f0464939cc3049f7155c150e3375c623.zip |
Merge pull request #2402 from chikeichan/merge
[NewUI] Merge master into NewUI-flat
Diffstat (limited to 'app/scripts/lib/pending-tx-tracker.js')
-rw-r--r-- | app/scripts/lib/pending-tx-tracker.js | 29 |
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 + } + } |