aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2018-06-13 01:55:54 +0800
committerkumavis <aaron@kumavis.me>2018-06-13 02:31:26 +0800
commit8f93e341750b99b8ff0e66f2a6831799c7d9ab58 (patch)
tree4c9df3e348a6dacdb5db3806e10168dbaeef629d
parentf08442e266e4acb2b7f90acfe0f9e54e7704b8aa (diff)
downloadtangerine-wallet-browser-8f93e341750b99b8ff0e66f2a6831799c7d9ab58.tar
tangerine-wallet-browser-8f93e341750b99b8ff0e66f2a6831799c7d9ab58.tar.gz
tangerine-wallet-browser-8f93e341750b99b8ff0e66f2a6831799c7d9ab58.tar.bz2
tangerine-wallet-browser-8f93e341750b99b8ff0e66f2a6831799c7d9ab58.tar.lz
tangerine-wallet-browser-8f93e341750b99b8ff0e66f2a6831799c7d9ab58.tar.xz
tangerine-wallet-browser-8f93e341750b99b8ff0e66f2a6831799c7d9ab58.tar.zst
tangerine-wallet-browser-8f93e341750b99b8ff0e66f2a6831799c7d9ab58.zip
nonce-tracker - wrap nonce calculations in try-catch and release lock on error
-rw-r--r--app/scripts/controllers/transactions/nonce-tracker.js50
1 files changed, 28 insertions, 22 deletions
diff --git a/app/scripts/controllers/transactions/nonce-tracker.js b/app/scripts/controllers/transactions/nonce-tracker.js
index f8cdc5523..ca340bae4 100644
--- a/app/scripts/controllers/transactions/nonce-tracker.js
+++ b/app/scripts/controllers/transactions/nonce-tracker.js
@@ -49,29 +49,35 @@ class NonceTracker {
await this._globalMutexFree()
// await lock free, then take lock
const releaseLock = await this._takeMutex(address)
- // evaluate multiple nextNonce strategies
- const nonceDetails = {}
- const networkNonceResult = await this._getNetworkNextNonce(address)
- const highestLocallyConfirmed = this._getHighestLocallyConfirmed(address)
- const nextNetworkNonce = networkNonceResult.nonce
- const highestSuggested = Math.max(nextNetworkNonce, highestLocallyConfirmed)
-
- const pendingTxs = this.getPendingTransactions(address)
- const localNonceResult = this._getHighestContinuousFrom(pendingTxs, highestSuggested) || 0
-
- nonceDetails.params = {
- highestLocallyConfirmed,
- highestSuggested,
- nextNetworkNonce,
+ try {
+ // evaluate multiple nextNonce strategies
+ const nonceDetails = {}
+ const networkNonceResult = await this._getNetworkNextNonce(address)
+ const highestLocallyConfirmed = this._getHighestLocallyConfirmed(address)
+ const nextNetworkNonce = networkNonceResult.nonce
+ const highestSuggested = Math.max(nextNetworkNonce, highestLocallyConfirmed)
+
+ const pendingTxs = this.getPendingTransactions(address)
+ const localNonceResult = this._getHighestContinuousFrom(pendingTxs, highestSuggested) || 0
+
+ nonceDetails.params = {
+ highestLocallyConfirmed,
+ highestSuggested,
+ nextNetworkNonce,
+ }
+ nonceDetails.local = localNonceResult
+ nonceDetails.network = networkNonceResult
+
+ const nextNonce = Math.max(networkNonceResult.nonce, localNonceResult.nonce)
+ assert(Number.isInteger(nextNonce), `nonce-tracker - nextNonce is not an integer - got: (${typeof nextNonce}) "${nextNonce}"`)
+
+ // return nonce and release cb
+ return { nextNonce, nonceDetails, releaseLock }
+ } catch (err) {
+ // release lock if we encounter an error
+ releaseLock()
+ throw err
}
- nonceDetails.local = localNonceResult
- nonceDetails.network = networkNonceResult
-
- const nextNonce = Math.max(networkNonceResult.nonce, localNonceResult.nonce)
- assert(Number.isInteger(nextNonce), `nonce-tracker - nextNonce is not an integer - got: (${typeof nextNonce}) "${nextNonce}"`)
-
- // return nonce and release cb
- return { nextNonce, nonceDetails, releaseLock }
}
async _getCurrentBlock () {