From 0fd32e67d4c8e911cd5cd88b81f04d11b2202609 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Wed, 14 Jun 2017 12:01:45 -0700 Subject: Do not mark slowly mined txs as failed. Fixes #1567 Also seems to fix #1556 Also improves resubmit performance by only resubmitting on `latest`. --- app/scripts/controllers/transactions.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'app') diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 2db8041eb..931f01855 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -25,7 +25,7 @@ module.exports = class TransactionController extends EventEmitter { this.query = opts.ethQuery this.txProviderUtils = new TxProviderUtil(this.query) this.blockTracker.on('block', this.checkForTxInBlock.bind(this)) - this.blockTracker.on('block', this.resubmitPendingTxs.bind(this)) + this.blockTracker.on('latest', this.resubmitPendingTxs.bind(this)) this.signEthTx = opts.signTransaction this.nonceLock = Semaphore(1) @@ -339,7 +339,7 @@ module.exports = class TransactionController extends EventEmitter { // checks if a signed tx is in a block and // if included sets the tx status as 'confirmed' checkForTxInBlock () { - var signedTxList = this.getFilteredTxList({status: 'submitted'}) + var signedTxList = this.getFilteredTxList({ status: 'submitted' }) if (!signedTxList.length) return signedTxList.forEach((txMeta) => { var txHash = txMeta.hash @@ -430,12 +430,8 @@ module.exports = class TransactionController extends EventEmitter { } if (txMeta.retryCount > RETRY_LIMIT) { - txMeta.err = { - isWarning: true, - message: 'Gave up submitting tx.', - } - this.updateTx(txMeta) - return log.error(txMeta.err.message) + const message = 'Gave up submitting tx ' + txMeta.hash + return log.warning(message) } txMeta.retryCount++ -- cgit From 07539a63e4378153778b5bb264aaffad7e46cf34 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Wed, 14 Jun 2017 21:52:49 -0700 Subject: remove unnecessary log --- app/scripts/controllers/transactions.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'app') diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 931f01855..2769a8d59 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -429,10 +429,7 @@ module.exports = class TransactionController extends EventEmitter { return cb() } - if (txMeta.retryCount > RETRY_LIMIT) { - const message = 'Gave up submitting tx ' + txMeta.hash - return log.warning(message) - } + if (txMeta.retryCount > RETRY_LIMIT) return txMeta.retryCount++ const rawTx = txMeta.rawTx -- cgit From 2e5deef2b0bdaaa67ee1584da52b7001cc9e849b Mon Sep 17 00:00:00 2001 From: frankiebee Date: Thu, 15 Jun 2017 13:48:48 -0700 Subject: check nonce and balance when resubmiting tx --- app/scripts/controllers/transactions.js | 27 ++++++++++++++++----------- app/scripts/metamask-controller.js | 1 + 2 files changed, 17 insertions(+), 11 deletions(-) (limited to 'app') diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 2769a8d59..58dc8a6ab 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -25,10 +25,10 @@ module.exports = class TransactionController extends EventEmitter { this.query = opts.ethQuery this.txProviderUtils = new TxProviderUtil(this.query) this.blockTracker.on('block', this.checkForTxInBlock.bind(this)) - this.blockTracker.on('latest', this.resubmitPendingTxs.bind(this)) + this.provider._blockTracker.on('latest', this.resubmitPendingTxs.bind(this)) this.signEthTx = opts.signTransaction this.nonceLock = Semaphore(1) - + this.ethStore = opts.ethStore // memstore is computed from a few different stores this._updateMemstore() this.store.subscribe(() => this._updateMemstore()) @@ -411,26 +411,31 @@ module.exports = class TransactionController extends EventEmitter { const pending = this.getTxsByMetaData('status', 'submitted') // only try resubmitting if their are transactions to resubmit if (!pending.length) return - const resubmit = denodeify(this.resubmitTx.bind(this)) + const resubmit = denodeify(this._resubmitTx.bind(this)) Promise.all(pending.map(txMeta => resubmit(txMeta))) .catch((reason) => { log.info('Problem resubmitting tx', reason) }) } - resubmitTx (txMeta, cb) { - // Increment a try counter. - if (!('retryCount' in txMeta)) { - txMeta.retryCount = 0 - } + _resubmitTx (txMeta, cb) { + const address = txMeta.txParams.from + const balance = this.ethStore.getState().accounts[address].balance + const nonce = Number.parseInt(this.ethStore.getState().accounts[address].nonce) + const txNonce = Number.parseInt(txMeta.txParams.nonce) + const gtBalance = Number.parseInt(txMeta.txParams.value) > Number.parseInt(balance) + if (!('retryCount' in txMeta)) txMeta.retryCount = 0 + // if the value of the transaction is greater then the balance + // or the nonce of the transaction is lower then the accounts nonce + // dont resubmit the tx + if (gtBalance || txNonce < nonce) return cb() // Only auto-submit already-signed txs: - if (!('rawTx' in txMeta)) { - return cb() - } + if (!('rawTx' in txMeta)) return cb() if (txMeta.retryCount > RETRY_LIMIT) return + // Increment a try counter. txMeta.retryCount++ const rawTx = txMeta.rawTx this.txProviderUtils.publishTransaction(rawTx, cb) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index a7eb3d056..727c19fb7 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -98,6 +98,7 @@ module.exports = class MetamaskController extends EventEmitter { provider: this.provider, blockTracker: this.provider, ethQuery: this.ethQuery, + ethStore: this.ethStore, }) // notices -- cgit From 9c2ead3d528046e4a6eed5bc45e82c972000354d Mon Sep 17 00:00:00 2001 From: frankiebee Date: Fri, 16 Jun 2017 16:43:38 -0700 Subject: put event back on the "blockTracker:/provider" --- app/scripts/controllers/transactions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index f6eb4e4d9..042d8e66d 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -27,7 +27,7 @@ module.exports = class TransactionController extends EventEmitter { this.blockTracker.on('block', this.checkForTxInBlock.bind(this)) // provider-engine only exploses the 'block' event, not 'latest' for 'sync' this.provider._blockTracker.on('sync', this.queryPendingTxs.bind(this)) - this.provider._blockTracker.on('latest', this.resubmitPendingTxs.bind(this)) + this.blockTracker.on('latest', this.resubmitPendingTxs.bind(this)) this.signEthTx = opts.signTransaction this.nonceLock = Semaphore(1) this.ethStore = opts.ethStore -- cgit