aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2018-06-13 01:55:54 +0800
committerkumavis <aaron@kumavis.me>2018-06-13 01:55:54 +0800
commitc86f93588965291837ae905632ba9a8855f496f2 (patch)
tree8a7c43053076e6b7d9639808646a96d31980c0a4 /app/scripts
parent030fea71369411d96a670bde53c40ffa9bb89ec5 (diff)
downloadtangerine-wallet-browser-c86f93588965291837ae905632ba9a8855f496f2.tar
tangerine-wallet-browser-c86f93588965291837ae905632ba9a8855f496f2.tar.gz
tangerine-wallet-browser-c86f93588965291837ae905632ba9a8855f496f2.tar.bz2
tangerine-wallet-browser-c86f93588965291837ae905632ba9a8855f496f2.tar.lz
tangerine-wallet-browser-c86f93588965291837ae905632ba9a8855f496f2.tar.xz
tangerine-wallet-browser-c86f93588965291837ae905632ba9a8855f496f2.tar.zst
tangerine-wallet-browser-c86f93588965291837ae905632ba9a8855f496f2.zip
nonce-tracker - wrap nonce calculations in try-catch and release lock on error
Diffstat (limited to 'app/scripts')
-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 fe2d25fca..14581c998 100644
--- a/app/scripts/controllers/transactions/nonce-tracker.js
+++ b/app/scripts/controllers/transactions/nonce-tracker.js
@@ -50,29 +50,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 _globalMutexFree () {