From 56490c6468bb83dccf04941ded5fec1017e5fe2c Mon Sep 17 00:00:00 2001 From: frankiebee Date: Wed, 14 Jun 2017 16:14:15 -0700 Subject: [PATCH 1/4] Bump provider-engine --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2c23d9e10..127211374 100644 --- a/package.json +++ b/package.json @@ -123,7 +123,7 @@ "valid-url": "^1.0.9", "vreme": "^3.0.2", "web3": "0.18.2", - "web3-provider-engine": "^12.2.4", + "web3-provider-engine": "^13.0.0", "web3-stream-provider": "^2.0.6", "xtend": "^4.0.1" }, From 6ae97290f0e744479a41e31507f79309137d94c0 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Wed, 14 Jun 2017 16:14:55 -0700 Subject: [PATCH 2/4] check for the tx in the block that provider engine gives us --- app/scripts/controllers/transactions.js | 20 +++++--------------- package.json | 2 +- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 2db8041eb..71f90c2cd 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -338,12 +338,13 @@ 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 () { + checkForTxInBlock (block) { var signedTxList = this.getFilteredTxList({status: 'submitted'}) if (!signedTxList.length) return signedTxList.forEach((txMeta) => { var txHash = txMeta.hash var txId = txMeta.id + if (!txHash) { const errReason = { errCode: 'No hash was provided', @@ -351,20 +352,9 @@ module.exports = class TransactionController extends EventEmitter { } return this.setTxStatusFailed(txId, errReason) } - this.query.getTransactionByHash(txHash, (err, txParams) => { - if (err || !txParams) { - if (!txParams) return - txMeta.err = { - isWarning: true, - errorCode: err, - message: 'There was a problem loading this transaction.', - } - this.updateTx(txMeta) - return log.error(err) - } - if (txParams.blockNumber) { - this.setTxStatusConfirmed(txId) - } + + block.transactions.forEach((tx) => { + if (tx.hash === txHash) this.setTxStatusConfirmed(txId) }) }) } diff --git a/package.json b/package.json index 127211374..7ee5dc5be 100644 --- a/package.json +++ b/package.json @@ -123,7 +123,7 @@ "valid-url": "^1.0.9", "vreme": "^3.0.2", "web3": "0.18.2", - "web3-provider-engine": "^13.0.0", + "web3-provider-engine": "^13.0.1", "web3-stream-provider": "^2.0.6", "xtend": "^4.0.1" }, From a10740af7e35aa60e0445598403e6bda22382c2f Mon Sep 17 00:00:00 2001 From: frankiebee Date: Wed, 14 Jun 2017 20:17:59 -0700 Subject: [PATCH 3/4] add a check for weather a tx is included in a block when jumping blocks --- app/scripts/controllers/transactions.js | 41 +++++++++++++++++++++++++ test/unit/tx-controller-test.js | 1 + 2 files changed, 42 insertions(+) diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 2db8041eb..41f651458 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -26,6 +26,7 @@ module.exports = class TransactionController extends EventEmitter { this.txProviderUtils = new TxProviderUtil(this.query) this.blockTracker.on('block', this.checkForTxInBlock.bind(this)) this.blockTracker.on('block', this.resubmitPendingTxs.bind(this)) + this.provider._blockTracker.on('sync', this.queryPendingTxs.bind(this)) this.signEthTx = opts.signTransaction this.nonceLock = Semaphore(1) @@ -369,6 +370,15 @@ module.exports = class TransactionController extends EventEmitter { }) } + queryPendingTxs ({oldBlock, newBlock}) { + if (!oldBlock) { + this._checkPendingTxs() + return + } + const diff = Number.parseInt(newBlock.number) - Number.parseInt(oldBlock.number) + if (diff > 1) this._checkPendingTxs() + } + // PRIVATE METHODS // Should find the tx in the tx list and @@ -443,6 +453,37 @@ module.exports = class TransactionController extends EventEmitter { this.txProviderUtils.publishTransaction(rawTx, cb) } + _checkPendingTxs () { + var signedTxList = this.getFilteredTxList({status: 'submitted'}) + if (!signedTxList.length) return + signedTxList.forEach((txMeta) => { + var txHash = txMeta.hash + var txId = txMeta.id + if (!txHash) { + const errReason = { + errCode: 'No hash was provided', + message: 'We had an error while submitting this transaction, please try again.', + } + return this.setTxStatusFailed(txId, errReason) + } + this.query.getTransactionByHash(txHash, (err, txParams) => { + if (err || !txParams) { + if (!txParams) return + txMeta.err = { + isWarning: true, + errorCode: err, + message: 'There was a problem loading this transaction.', + } + this.updateTx(txMeta) + return log.error(err) + } + if (txParams.blockNumber) { + this.setTxStatusConfirmed(txId) + } + }) + }) + } + } diff --git a/test/unit/tx-controller-test.js b/test/unit/tx-controller-test.js index f0d8a706e..0d35cd62c 100644 --- a/test/unit/tx-controller-test.js +++ b/test/unit/tx-controller-test.js @@ -19,6 +19,7 @@ describe('Transaction Controller', function () { txController = new TransactionController({ networkStore: new ObservableStore(currentNetworkId), txHistoryLimit: 10, + provider: { _blockTracker: new EventEmitter()}, blockTracker: new EventEmitter(), ethQuery: new EthQuery(new EventEmitter()), signTransaction: (ethTx) => new Promise((resolve) => { From 27b874f2c48fd1cb9dc0984646cb739173ddaf2c Mon Sep 17 00:00:00 2001 From: kumavis Date: Thu, 15 Jun 2017 14:08:07 -0700 Subject: [PATCH 4/4] transactions controller - add comments --- app/scripts/controllers/transactions.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 41f651458..aa168b736 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -26,6 +26,7 @@ module.exports = class TransactionController extends EventEmitter { this.txProviderUtils = new TxProviderUtil(this.query) this.blockTracker.on('block', this.checkForTxInBlock.bind(this)) this.blockTracker.on('block', this.resubmitPendingTxs.bind(this)) + // provider-engine only exploses the 'block' event, not 'latest' for 'sync' this.provider._blockTracker.on('sync', this.queryPendingTxs.bind(this)) this.signEthTx = opts.signTransaction this.nonceLock = Semaphore(1) @@ -371,10 +372,12 @@ module.exports = class TransactionController extends EventEmitter { } queryPendingTxs ({oldBlock, newBlock}) { + // check pending transactions on start if (!oldBlock) { this._checkPendingTxs() return } + // if we synced by more than one block, check for missed pending transactions const diff = Number.parseInt(newBlock.number) - Number.parseInt(oldBlock.number) if (diff > 1) this._checkPendingTxs() } @@ -453,6 +456,8 @@ module.exports = class TransactionController extends EventEmitter { this.txProviderUtils.publishTransaction(rawTx, cb) } + // checks the network for signed txs and + // if confirmed sets the tx status as 'confirmed' _checkPendingTxs () { var signedTxList = this.getFilteredTxList({status: 'submitted'}) if (!signedTxList.length) return