aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib
diff options
context:
space:
mode:
authorChi Kei Chan <chikeichan@gmail.com>2017-12-07 13:13:29 +0800
committerGitHub <noreply@github.com>2017-12-07 13:13:29 +0800
commit373f8b72d048d84f537d97d87c7f106e0b8db087 (patch)
tree94fb9302fad2d52b927bc5a48339ab2965e003fe /app/scripts/lib
parentec6c3c33bdbe2d90dc71649d0cc5fb3c07d96af7 (diff)
parenta78cc013d199547ba865a0d1c2fec9a328ce7e0b (diff)
downloadtangerine-wallet-browser-373f8b72d048d84f537d97d87c7f106e0b8db087.tar
tangerine-wallet-browser-373f8b72d048d84f537d97d87c7f106e0b8db087.tar.gz
tangerine-wallet-browser-373f8b72d048d84f537d97d87c7f106e0b8db087.tar.bz2
tangerine-wallet-browser-373f8b72d048d84f537d97d87c7f106e0b8db087.tar.lz
tangerine-wallet-browser-373f8b72d048d84f537d97d87c7f106e0b8db087.tar.xz
tangerine-wallet-browser-373f8b72d048d84f537d97d87c7f106e0b8db087.tar.zst
tangerine-wallet-browser-373f8b72d048d84f537d97d87c7f106e0b8db087.zip
Merge branch 'master' into NewUI-flat
Diffstat (limited to 'app/scripts/lib')
-rw-r--r--app/scripts/lib/pending-tx-tracker.js18
1 files changed, 15 insertions, 3 deletions
diff --git a/app/scripts/lib/pending-tx-tracker.js b/app/scripts/lib/pending-tx-tracker.js
index 0d7c6a92c..dc6e526fd 100644
--- a/app/scripts/lib/pending-tx-tracker.js
+++ b/app/scripts/lib/pending-tx-tracker.js
@@ -65,11 +65,11 @@ 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
- pending.forEach((txMeta) => this._resubmitTx(txMeta).catch((err) => {
+ pending.forEach((txMeta) => this._resubmitTx(txMeta, block.number).catch((err) => {
/*
Dont marked as failed if the error is a "known" transaction warning
"there is already a transaction with the same sender-nonce
@@ -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 || latestBlockNumber
+ 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