diff options
author | Dan <danjm.com@gmail.com> | 2017-12-06 04:51:14 +0800 |
---|---|---|
committer | Dan <danjm.com@gmail.com> | 2017-12-06 04:51:14 +0800 |
commit | ae2a4d78e8c7733da1963965e38e154351d54a20 (patch) | |
tree | 29db56b4949caec647c3fa38a5678f8e5bdf974e /app/scripts/lib | |
parent | c30b543a8069c3925bb254716699752e38eaf97a (diff) | |
download | tangerine-wallet-browser-ae2a4d78e8c7733da1963965e38e154351d54a20.tar.gz tangerine-wallet-browser-ae2a4d78e8c7733da1963965e38e154351d54a20.tar.zst tangerine-wallet-browser-ae2a4d78e8c7733da1963965e38e154351d54a20.zip |
Exponentional backoff on transaction retry in pending-tx-tracker
Diffstat (limited to 'app/scripts/lib')
-rw-r--r-- | app/scripts/lib/pending-tx-tracker.js | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/app/scripts/lib/pending-tx-tracker.js b/app/scripts/lib/pending-tx-tracker.js index 0d7c6a92c..60c837040 100644 --- a/app/scripts/lib/pending-tx-tracker.js +++ b/app/scripts/lib/pending-tx-tracker.js @@ -65,7 +65,7 @@ module.exports = class PendingTransactionTracker extends EventEmitter { } - resubmitPendingTxs () { + resubmitPendingTxs (block) { const pending = this.getPendingTransactions() // only try resubmitting if their are transactions to resubmit if (!pending.length) return @@ -101,13 +101,25 @@ module.exports = class PendingTransactionTracker extends EventEmitter { })) } - async _resubmitTx (txMeta) { + async _resubmitTx (txMeta, latestBlockNumber) { + if (!txMeta.firstRetryBlockNumber) { + this.emit('tx:block-update', txMeta, latestBlockNumber) + } + 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) } + const firstRetryBlockNumber = txMeta.firstRetryBlockNumber + const txBlockDistance = Number.parseInt(latestBlockNumber, 16) - Number.parseInt(firstRetryBlockNumber, 16) + + const retryCount = txMeta.retryCount || 0 + + // Exponential backoff to limit retries at publishing + if (txBlockDistance <= Math.pow(2, retryCount) - 1) return + // Only auto-submit already-signed txs: if (!('rawTx' in txMeta)) return |