diff options
author | Thomas Huang <tmashuang@users.noreply.github.com> | 2017-05-24 05:14:42 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-24 05:14:42 +0800 |
commit | f4158d26f61aed1882ca5734f561e12f68726972 (patch) | |
tree | 36d149b30911297369e4859f18657ab2b0329304 | |
parent | 1491e6fe0728b0c82cdf5b8dcaa18ef0adbcd55d (diff) | |
parent | 4dab68c48f63e51c50d1ea4cc551d006b4c3d9ea (diff) | |
download | tangerine-wallet-browser-f4158d26f61aed1882ca5734f561e12f68726972.tar tangerine-wallet-browser-f4158d26f61aed1882ca5734f561e12f68726972.tar.gz tangerine-wallet-browser-f4158d26f61aed1882ca5734f561e12f68726972.tar.bz2 tangerine-wallet-browser-f4158d26f61aed1882ca5734f561e12f68726972.tar.lz tangerine-wallet-browser-f4158d26f61aed1882ca5734f561e12f68726972.tar.xz tangerine-wallet-browser-f4158d26f61aed1882ca5734f561e12f68726972.tar.zst tangerine-wallet-browser-f4158d26f61aed1882ca5734f561e12f68726972.zip |
Merge pull request #1478 from MetaMask/i1409-StalledTxs
Continually resubmit pending txs
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | app/scripts/controllers/transactions.js | 54 |
2 files changed, 53 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index dab16c89a..88d7a81e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Add Transaction Number (nonce) to transaction list. - Label the pending tx icon with a tooltip. - Fix bug where website filters would pile up and not deallocate when leaving a site. +- Continually resubmit pending txs for a period of time to ensure successful broadcast. - ENS names will no longer resolve to their owner if no resolver is set. Resolvers must be explicitly set and configured. ## 3.6.5 2017-5-17 diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 21dd25b30..3d86a171e 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -7,6 +7,10 @@ const ethUtil = require('ethereumjs-util') const EthQuery = require('eth-query') const TxProviderUtil = require('../lib/tx-utils') const createId = require('../lib/random-id') +const denodeify = require('denodeify') + +const RETRY_LIMIT = 200 +const RESUBMIT_INTERVAL = 10000 // Ten seconds module.exports = class TransactionManager extends EventEmitter { constructor (opts) { @@ -31,6 +35,8 @@ module.exports = class TransactionManager extends EventEmitter { this.store.subscribe(() => this._updateMemstore()) this.networkStore.subscribe(() => this._updateMemstore()) this.preferencesStore.subscribe(() => this._updateMemstore()) + + this.continuallyResubmitPendingTxs() } getState () { @@ -230,7 +236,11 @@ module.exports = class TransactionManager extends EventEmitter { }) } - publishTransaction (txId, rawTx, cb) { + publishTransaction (txId, rawTx, cb = warn) { + const txMeta = this.getTx(txId) + txMeta.rawTx = rawTx + this.updateTx(txMeta) + this.txProviderUtils.publishTransaction(rawTx, (err, txHash) => { if (err) return cb(err) this.setTxHash(txId, txHash) @@ -353,7 +363,7 @@ module.exports = class TransactionManager extends EventEmitter { message: 'There was a problem loading this transaction.', } this.updateTx(txMeta) - return console.error(err) + return log.error(err) } if (txParams.blockNumber) { this.setTxStatusConfirmed(txId) @@ -379,6 +389,7 @@ module.exports = class TransactionManager extends EventEmitter { this.emit(`${txMeta.id}:${status}`, txId) if (status === 'submitted' || status === 'rejected') { this.emit(`${txMeta.id}:finished`, txMeta) + } this.updateTx(txMeta) this.emit('updateBadge') @@ -398,6 +409,45 @@ module.exports = class TransactionManager extends EventEmitter { }) this.memStore.updateState({ unapprovedTxs, selectedAddressTxList }) } + + continuallyResubmitPendingTxs () { + const pending = this.getTxsByMetaData('status', 'submitted') + const resubmit = denodeify(this.resubmitTx.bind(this)) + Promise.all(pending.map(txMeta => resubmit(txMeta))) + .catch((reason) => { + log.info('Problem resubmitting tx', reason) + }) + .then(() => { + global.setTimeout(() => { + this.continuallyResubmitPendingTxs() + }, RESUBMIT_INTERVAL) + }) + } + + resubmitTx (txMeta, cb) { + // Increment a try counter. + if (!('retryCount' in txMeta)) { + txMeta.retryCount = 0 + } + + // Only auto-submit already-signed txs: + if (!('rawTx' in txMeta)) { + return cb() + } + + if (txMeta.retryCount > RETRY_LIMIT) { + txMeta.err = { + isWarning: true, + message: 'Gave up submitting tx.', + } + this.updateTx(txMeta) + return log.error(txMeta.err.message) + } + + txMeta.retryCount++ + const rawTx = txMeta.rawTx + this.txProviderUtils.publishTransaction(rawTx, cb) + } } |