Skip to content

Commit f23efec

Browse files
authored
Merge pull request #1830 from MetaMask/providerProxyFix
NonceTracker - Provider proxy fix
2 parents 0deb617 + 55a5514 commit f23efec

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

app/scripts/controllers/transactions.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ module.exports = class TransactionController extends EventEmitter {
2424
this.blockTracker = opts.blockTracker
2525
this.nonceTracker = new NonceTracker({
2626
provider: this.provider,
27-
blockTracker: this.provider._blockTracker,
2827
getPendingTransactions: (address) => {
2928
return this.getFilteredTxList({
3029
from: address,

app/scripts/lib/nonce-tracker.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const Mutex = require('await-semaphore').Mutex
44

55
class NonceTracker {
66

7-
constructor ({ blockTracker, provider, getPendingTransactions }) {
8-
this.blockTracker = blockTracker
7+
constructor ({ provider, getPendingTransactions }) {
8+
this.provider = provider
99
this.ethQuery = new EthQuery(provider)
1010
this.getPendingTransactions = getPendingTransactions
1111
this.lockMap = {}
@@ -39,16 +39,17 @@ class NonceTracker {
3939
assert(Number.isInteger(nextNonce), `nonce-tracker - nextNonce is not an integer - got: (${typeof nextNonce}) "${nextNonce}"`)
4040
// collect the numbers used to calculate the nonce for debugging
4141
const blockNumber = currentBlock.number
42-
const nonceDetails = { blockNumber, baseCount, pendingCount }
42+
const nonceDetails = { blockNumber, baseCount, baseCountHex, pendingCount }
4343
// return nonce and release cb
4444
return { nextNonce, nonceDetails, releaseLock }
4545
}
4646

4747
async _getCurrentBlock () {
48-
const currentBlock = this.blockTracker.getCurrentBlock()
48+
const blockTracker = this._getBlockTracker()
49+
const currentBlock = blockTracker.getCurrentBlock()
4950
if (currentBlock) return currentBlock
5051
return await Promise((reject, resolve) => {
51-
this.blockTracker.once('latest', resolve)
52+
blockTracker.once('latest', resolve)
5253
})
5354
}
5455

@@ -82,6 +83,12 @@ class NonceTracker {
8283
return mutex
8384
}
8485

86+
// this is a hotfix for the fact that the blockTracker will
87+
// change when the network changes
88+
_getBlockTracker () {
89+
return this.provider._blockTracker
90+
}
91+
8592
}
8693

8794
module.exports = NonceTracker

test/unit/nonce-tracker-test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ describe('Nonce Tracker', function () {
1818

1919

2020
getPendingTransactions = () => pendingTxs
21-
provider = { sendAsync: (_, cb) => { cb(undefined, {result: '0x0'}) } }
22-
nonceTracker = new NonceTracker({
23-
blockTracker: {
21+
provider = {
22+
sendAsync: (_, cb) => { cb(undefined, {result: '0x0'}) },
23+
_blockTracker: {
2424
getCurrentBlock: () => '0x11b568',
2525
},
26+
}
27+
nonceTracker = new NonceTracker({
2628
provider,
2729
getPendingTransactions,
2830
})

0 commit comments

Comments
 (0)