aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
authorfrankiebee <frankie.diamond@gmail.com>2017-08-19 04:54:16 +0800
committerfrankiebee <frankie.diamond@gmail.com>2017-08-19 04:54:16 +0800
commita5a32f3d5742972586893741847ea4516afa19ac (patch)
tree818d4d3d4ed076d17cffdbafd93749f144413665 /app/scripts
parentbf8a62eb39aac454c1f23e549078ce5f4b8a2d2a (diff)
downloadtangerine-wallet-browser-a5a32f3d5742972586893741847ea4516afa19ac.tar
tangerine-wallet-browser-a5a32f3d5742972586893741847ea4516afa19ac.tar.gz
tangerine-wallet-browser-a5a32f3d5742972586893741847ea4516afa19ac.tar.bz2
tangerine-wallet-browser-a5a32f3d5742972586893741847ea4516afa19ac.tar.lz
tangerine-wallet-browser-a5a32f3d5742972586893741847ea4516afa19ac.tar.xz
tangerine-wallet-browser-a5a32f3d5742972586893741847ea4516afa19ac.tar.zst
tangerine-wallet-browser-a5a32f3d5742972586893741847ea4516afa19ac.zip
use "localNonce" when the network returns a nonce that is lower then a known confirmed tx
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/controllers/transactions.js7
-rw-r--r--app/scripts/lib/nonce-tracker.js23
2 files changed, 27 insertions, 3 deletions
diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js
index 58c468e22..f21cb6e00 100644
--- a/app/scripts/controllers/transactions.js
+++ b/app/scripts/controllers/transactions.js
@@ -33,6 +33,13 @@ module.exports = class TransactionController extends EventEmitter {
err: undefined,
})
},
+ getConfirmedTransactions: (address) => {
+ return this.getFilteredTxList({
+ from: address,
+ status: 'confirmed',
+ err: undefined,
+ })
+ },
})
this.query = new EthQuery(this.provider)
this.txProviderUtil = new TxProviderUtil(this.provider)
diff --git a/app/scripts/lib/nonce-tracker.js b/app/scripts/lib/nonce-tracker.js
index 8328e81ec..3a26c374c 100644
--- a/app/scripts/lib/nonce-tracker.js
+++ b/app/scripts/lib/nonce-tracker.js
@@ -4,10 +4,11 @@ const Mutex = require('await-semaphore').Mutex
class NonceTracker {
- constructor ({ provider, getPendingTransactions }) {
+ constructor ({ provider, getPendingTransactions, getConfirmedTransactions }) {
this.provider = provider
this.ethQuery = new EthQuery(provider)
this.getPendingTransactions = getPendingTransactions
+ this.getConfirmedTransactions = getConfirmedTransactions
this.lockMap = {}
}
@@ -28,6 +29,14 @@ class NonceTracker {
// calculate next nonce
// we need to make sure our base count
// and pending count are from the same block
+ const localNonceHex = this._getLocalNonce(address)
+ let localNonce = parseInt(localNonceHex, 16)
+ try {
+ assert(Number.isInteger(localNonce), `nonce-tracker - localNonce is not an integer - got: (${typeof localNonce}) "${localNonce}"`)
+ } catch (e) {
+ // throw out localNonce if not a number
+ localNonce = 0
+ }
const currentBlock = await this._getCurrentBlock()
const pendingTransactions = this.getPendingTransactions(address)
const pendingCount = pendingTransactions.length
@@ -35,11 +44,11 @@ class NonceTracker {
const baseCountHex = await this._getTxCount(address, currentBlock)
const baseCount = parseInt(baseCountHex, 16)
assert(Number.isInteger(baseCount), `nonce-tracker - baseCount is not an integer - got: (${typeof baseCount}) "${baseCount}"`)
- const nextNonce = baseCount + pendingCount
+ const nextNonce = Math.max(baseCount, localNonce + 1) + pendingCount
assert(Number.isInteger(nextNonce), `nonce-tracker - nextNonce is not an integer - got: (${typeof nextNonce}) "${nextNonce}"`)
// collect the numbers used to calculate the nonce for debugging
const blockNumber = currentBlock.number
- const nonceDetails = { blockNumber, baseCount, baseCountHex, pendingCount }
+ const nonceDetails = { blockNumber, baseCount, baseCountHex, pendingCount, localNonceHex, localNonce }
// return nonce and release cb
return { nextNonce, nonceDetails, releaseLock }
}
@@ -83,6 +92,14 @@ class NonceTracker {
return mutex
}
+ _getLocalNonce (address) {
+ const confirmedTransactions = this.getConfirmedTransactions(address)
+ const localNonces = confirmedTransactions.map((txMeta) => txMeta.txParams.nonce)
+ return localNonces.reduce((nonce, highestNonce) => {
+ return parseInt(nonce, 16) > parseInt(highestNonce, 16) ? nonce : highestNonce
+ }, '0x0')
+ }
+
// this is a hotfix for the fact that the blockTracker will
// change when the network changes
_getBlockTracker () {