diff options
author | frankiebee <frankie.diamond@gmail.com> | 2017-07-06 03:00:42 +0800 |
---|---|---|
committer | frankiebee <frankie.diamond@gmail.com> | 2017-07-06 03:00:42 +0800 |
commit | 6d2cddaac9348b0e9c8a6cc4a6621927765e7c17 (patch) | |
tree | 3571638ae7b68e4effd4b0ab9cb39ea44198c7fc /app/scripts/lib/nonce-tracker.js | |
parent | 690685d20de310b4c4589e92a5053afd9c56e85a (diff) | |
download | tangerine-wallet-browser-6d2cddaac9348b0e9c8a6cc4a6621927765e7c17.tar tangerine-wallet-browser-6d2cddaac9348b0e9c8a6cc4a6621927765e7c17.tar.gz tangerine-wallet-browser-6d2cddaac9348b0e9c8a6cc4a6621927765e7c17.tar.bz2 tangerine-wallet-browser-6d2cddaac9348b0e9c8a6cc4a6621927765e7c17.tar.lz tangerine-wallet-browser-6d2cddaac9348b0e9c8a6cc4a6621927765e7c17.tar.xz tangerine-wallet-browser-6d2cddaac9348b0e9c8a6cc4a6621927765e7c17.tar.zst tangerine-wallet-browser-6d2cddaac9348b0e9c8a6cc4a6621927765e7c17.zip |
fix nonce calculation order
Diffstat (limited to 'app/scripts/lib/nonce-tracker.js')
-rw-r--r-- | app/scripts/lib/nonce-tracker.js | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/app/scripts/lib/nonce-tracker.js b/app/scripts/lib/nonce-tracker.js index 9ef7706f9..ab2893b10 100644 --- a/app/scripts/lib/nonce-tracker.js +++ b/app/scripts/lib/nonce-tracker.js @@ -12,14 +12,16 @@ class NonceTracker { // releaseLock must be called // releaseLock must be called after adding signed tx to pending transactions (or discarding) async getNonceLock (address) { - const pendingTransactions = this.getPendingTransactions(address) // await lock free - if (pendingTransactions.length) await this.lockMap[address] - else if (this.lockMap[address]) await this.lockMap[address]() + await this.lockMap[address] // take lock const releaseLock = this._takeLock(address) // calculate next nonce - const baseCount = await this._getTxCount(address) + // we need to make sure our base count + // and pending count are from the same block + const currentBlock = await this._getCurrentBlock() + const pendingTransactions = this.getPendingTransactions(address) + const baseCount = await this._getTxCount(address, currentBlock) const nextNonce = parseInt(baseCount) + pendingTransactions.length // return next nonce and release cb return { nextNonce: nextNonce.toString(16), releaseLock } @@ -43,8 +45,7 @@ class NonceTracker { return releaseLock } - async _getTxCount (address) { - const currentBlock = await this._getCurrentBlock() + async _getTxCount (address, currentBlock) { const blockNumber = currentBlock.number return new Promise((resolve, reject) => { this.ethQuery.getTransactionCount(address, blockNumber, (err, result) => { |