From c7233e2cc7ba52308528a74e89938deada5394b8 Mon Sep 17 00:00:00 2001 From: Dan Finlay <542863+danfinlay@users.noreply.github.com> Date: Thu, 29 Nov 2018 16:08:03 -0800 Subject: [PATCH] Fixed Vivek's bug (#5860) * Fixed Vivek's bug Fixes #5850 What was happening: It seems that his MetaMask had crashed while some new transactions had been loading defaults. He probably had a network connectivity issue to Infura (which we are working with Infura to address). As a result of this network cutout, his three unapproved transactions were not marked failed, and were not marked as `loadingDefaults = false`, as their gas prices had not yet been estimated. Normally this behavior is supposed to clean itself up when the transaction controller starts up, via the `TransactionController._onBootCleanUp()` function, but in this case, during unlock, that function was unable to do its job because when it requested the transaction list, the current network was in the `loading` state, making it proceed as if there were no pending transactions. To fix this, I am doing two things: - Setting transactions to loadingDefaults = false in more catch blocks. - Calling `onBootCleanUp()` when the network store's status changes, so that it will re-trigger when loading completes. * Fixed reference * Fixed infinite loop bug Was refreshing the tx list on every tx state change instead of just network changes, creating an infinite loop. * Add notes to tx updates to clarify logs --- app/scripts/controllers/transactions/index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js index 1dd410d2c..9cd8429fb 100644 --- a/app/scripts/controllers/transactions/index.js +++ b/app/scripts/controllers/transactions/index.js @@ -96,7 +96,10 @@ class TransactionController extends EventEmitter { // memstore is computed from a few different stores this._updateMemstore() this.txStateManager.store.subscribe(() => this._updateMemstore()) - this.networkStore.subscribe(() => this._updateMemstore()) + this.networkStore.subscribe(() => { + this._onBootCleanUp() + this._updateMemstore() + }) this.preferencesStore.subscribe(() => this._updateMemstore()) // request state update to finalize initialization @@ -191,10 +194,13 @@ class TransactionController extends EventEmitter { txMeta = await this.addTxGasDefaults(txMeta) } catch (error) { log.warn(error) - this.txStateManager.setTxStatusFailed(txMeta.id, error) + txMeta.loadingDefaults = false + this.txStateManager.updateTx(txMeta, 'Failed to calculate gas defaults.') throw error } + txMeta.loadingDefaults = false + // save txMeta this.txStateManager.updateTx(txMeta) @@ -485,6 +491,8 @@ class TransactionController extends EventEmitter { txMeta.loadingDefaults = false this.txStateManager.updateTx(txMeta, 'transactions: gas estimation for tx on boot') }).catch((error) => { + tx.loadingDefaults = false + this.txStateManager.updateTx(tx, 'failed to estimate gas during boot cleanup.') this.txStateManager.setTxStatusFailed(tx.id, error) }) })