From ab01358a480243c9073ac06dc4f510a6089567d0 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Tue, 25 Jul 2017 16:08:31 -0400 Subject: [PATCH 1/5] Add stack traces both in errors and as a way to track txMetas --- CHANGELOG.md | 2 ++ app/scripts/controllers/transactions.js | 30 ++++++++++++++++++------- app/scripts/lib/util.js | 8 +++++++ package.json | 1 + 4 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 app/scripts/lib/util.js diff --git a/CHANGELOG.md b/CHANGELOG.md index bf18bb361..eeeda9d68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Current Master +- Include stack traces in txMeta's to better understand the life cycle of transactions + ## 3.9.1 2017-7-19 - No longer automatically request 1 ropsten ether for the first account in a new vault. diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 5f3d84ebe..4d1a18df7 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -1,10 +1,12 @@ const EventEmitter = require('events') const async = require('async') const extend = require('xtend') +const clone = require('deep-clone') const ObservableStore = require('obs-store') const ethUtil = require('ethereumjs-util') const pify = require('pify') const TxProviderUtil = require('../lib/tx-utils') +const getStack = require('../lib/util').getStack const createId = require('../lib/random-id') const NonceTracker = require('../lib/nonce-tracker') @@ -117,9 +119,14 @@ module.exports = class TransactionController extends EventEmitter { // updateTx (txMeta) { + const txMetaForHistory = clone(txMeta) + txMetaForHistory.stack = getStack() var txId = txMeta.id var txList = this.getFullTxList() var index = txList.findIndex(txData => txData.id === txId) + if (!txMeta.history) txMeta.history = [] + txMeta.history.push(txMetaForHistory) + txList[index] = txMeta this._saveTxList(txList) this.emit('update') @@ -134,7 +141,7 @@ module.exports = class TransactionController extends EventEmitter { } addUnapprovedTransaction (txParams, done) { - let txMeta + let txMeta = {} async.waterfall([ // validate (cb) => this.txProviderUtils.validateTxParams(txParams, cb), @@ -146,6 +153,7 @@ module.exports = class TransactionController extends EventEmitter { status: 'unapproved', metamaskNetworkId: this.getNetwork(), txParams: txParams, + history: [], } cb() }, @@ -165,6 +173,7 @@ module.exports = class TransactionController extends EventEmitter { txParams.value = txParams.value || '0x0' if (!txParams.gasPrice) { this.query.gasPrice((err, gasPrice) => { + if (err) return cb(err) // set gasPrice txParams.gasPrice = gasPrice @@ -201,6 +210,7 @@ module.exports = class TransactionController extends EventEmitter { nonceLock.releaseLock() } catch (err) { this.setTxStatusFailed(txId, { + stack: err.stack || err.message, errCode: err.errCode || err, message: err.message || 'Transaction failed during approval', }) @@ -364,11 +374,11 @@ module.exports = class TransactionController extends EventEmitter { var txId = txMeta.id if (!txHash) { - const errReason = { + return this.setTxStatusFailed(txId, { + stack: 'checkForTxInBlock: custom tx-controller error message Line# 368', errCode: 'No hash was provided', message: 'We had an error while submitting this transaction, please try again.', - } - return this.setTxStatusFailed(txId, errReason) + }) } block.transactions.forEach((tx) => { @@ -452,6 +462,7 @@ module.exports = class TransactionController extends EventEmitter { if (isKnownTx) return // encountered real error - transition to error state this.setTxStatusFailed(txMeta.id, { + stack: err.stack || err.message, errCode: err.errCode || err, message: err.message, }) @@ -466,7 +477,10 @@ module.exports = class TransactionController extends EventEmitter { // if the value of the transaction is greater then the balance, fail. if (!this.txProviderUtils.sufficientBalance(txMeta.txParams, balance)) { const message = 'Insufficient balance.' - this.setTxStatusFailed(txMeta.id, { message }) + this.setTxStatusFailed(txMeta.id, { + stack: '_resubnitTx: custom tx-controller error line# 472', + message, + }) cb() return log.error(message) } @@ -501,11 +515,11 @@ module.exports = class TransactionController extends EventEmitter { // extra check in case there was an uncaught error during the // signature and submission process if (!txHash) { - const errReason = { + this.setTxStatusFailed(txId, { + stack: '_checkPendingTxs: custom tx-controller error message Line# 510', errCode: 'No hash was provided', message: 'We had an error while submitting this transaction, please try again.', - } - this.setTxStatusFailed(txId, errReason) + }) return } // get latest transaction status diff --git a/app/scripts/lib/util.js b/app/scripts/lib/util.js new file mode 100644 index 000000000..bddd60ee8 --- /dev/null +++ b/app/scripts/lib/util.js @@ -0,0 +1,8 @@ +module.exports = { + getStack, +} + +function getStack () { + const stack = new Error('Stack trace generator - not an error').stack + return stack +} diff --git a/package.json b/package.json index 375902d09..f18f84727 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "clone": "^1.0.2", "copy-to-clipboard": "^2.0.0", "debounce": "^1.0.0", + "deep-clone": "^3.0.2", "deep-extend": "^0.4.1", "detect-node": "^2.0.3", "disc": "^1.3.2", From e0a626da3b026fd7dd258e8accf771353c4ea38e Mon Sep 17 00:00:00 2001 From: frankiebee Date: Tue, 25 Jul 2017 18:02:21 -0400 Subject: [PATCH 2/5] remove line numbers --- app/scripts/controllers/transactions.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 4d1a18df7..d96e2236a 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -375,7 +375,7 @@ module.exports = class TransactionController extends EventEmitter { if (!txHash) { return this.setTxStatusFailed(txId, { - stack: 'checkForTxInBlock: custom tx-controller error message Line# 368', + stack: 'checkForTxInBlock: custom tx-controller error me', errCode: 'No hash was provided', message: 'We had an error while submitting this transaction, please try again.', }) @@ -478,7 +478,7 @@ module.exports = class TransactionController extends EventEmitter { if (!this.txProviderUtils.sufficientBalance(txMeta.txParams, balance)) { const message = 'Insufficient balance.' this.setTxStatusFailed(txMeta.id, { - stack: '_resubnitTx: custom tx-controller error line# 472', + stack: '_resubnitTx: custom tx-controller ', message, }) cb() @@ -516,7 +516,7 @@ module.exports = class TransactionController extends EventEmitter { // signature and submission process if (!txHash) { this.setTxStatusFailed(txId, { - stack: '_checkPendingTxs: custom tx-controller error message Line# 510', + stack: '_checkPendingTxs: custom tx-controller error message', errCode: 'No hash was provided', message: 'We had an error while submitting this transaction, please try again.', }) From 1df833bee8a51c304491a3045138560e8c3f2b52 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Tue, 25 Jul 2017 18:21:40 -0400 Subject: [PATCH 3/5] use clone --- app/scripts/controllers/transactions.js | 2 +- package.json | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index d96e2236a..4de2b7db3 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -1,7 +1,7 @@ const EventEmitter = require('events') const async = require('async') const extend = require('xtend') -const clone = require('deep-clone') +const clone = require('clone') const ObservableStore = require('obs-store') const ethUtil = require('ethereumjs-util') const pify = require('pify') diff --git a/package.json b/package.json index f18f84727..375902d09 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,6 @@ "clone": "^1.0.2", "copy-to-clipboard": "^2.0.0", "debounce": "^1.0.0", - "deep-clone": "^3.0.2", "deep-extend": "^0.4.1", "detect-node": "^2.0.3", "disc": "^1.3.2", From b81f8831505b1ebb1d58a474d52b068d42879d56 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Tue, 25 Jul 2017 18:23:17 -0400 Subject: [PATCH 4/5] fix stack wording --- app/scripts/controllers/transactions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 4de2b7db3..5485dc723 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -375,7 +375,7 @@ module.exports = class TransactionController extends EventEmitter { if (!txHash) { return this.setTxStatusFailed(txId, { - stack: 'checkForTxInBlock: custom tx-controller error me', + stack: 'checkForTxInBlock: custom tx-controller error message', errCode: 'No hash was provided', message: 'We had an error while submitting this transaction, please try again.', }) @@ -478,7 +478,7 @@ module.exports = class TransactionController extends EventEmitter { if (!this.txProviderUtils.sufficientBalance(txMeta.txParams, balance)) { const message = 'Insufficient balance.' this.setTxStatusFailed(txMeta.id, { - stack: '_resubnitTx: custom tx-controller ', + stack: '_resubnitTx: custom tx-controller error', message, }) cb() From ba88f7b8dd32b6ffdb46e70b8c9fbd563bb53b69 Mon Sep 17 00:00:00 2001 From: frankiebee Date: Tue, 25 Jul 2017 18:29:02 -0400 Subject: [PATCH 5/5] fix typo --- app/scripts/controllers/transactions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 5485dc723..263424518 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -478,7 +478,7 @@ module.exports = class TransactionController extends EventEmitter { if (!this.txProviderUtils.sufficientBalance(txMeta.txParams, balance)) { const message = 'Insufficient balance.' this.setTxStatusFailed(txMeta.id, { - stack: '_resubnitTx: custom tx-controller error', + stack: '_resubmitTx: custom tx-controller error', message, }) cb()