nonce-tracker: only check transactions that are not supposed to be ignored
This commit is contained in:
parent
0ee4502d71
commit
690685d20d
|
@ -26,7 +26,14 @@ module.exports = class TransactionController extends EventEmitter {
|
||||||
this.nonceTracker = new NonceTracker({
|
this.nonceTracker = new NonceTracker({
|
||||||
provider: this.provider,
|
provider: this.provider,
|
||||||
blockTracker: this.provider._blockTracker,
|
blockTracker: this.provider._blockTracker,
|
||||||
getPendingTransactions: (address) => this.getFilteredTxList({ from: address, status: 'submitted', err: undefined }),
|
getPendingTransactions: (address) => {
|
||||||
|
return this.getFilteredTxList({
|
||||||
|
from: address,
|
||||||
|
status: 'submitted',
|
||||||
|
err: undefined,
|
||||||
|
ignore: undefined,
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
this.query = opts.ethQuery
|
this.query = opts.ethQuery
|
||||||
this.txProviderUtils = new TxProviderUtil(this.query)
|
this.txProviderUtils = new TxProviderUtil(this.query)
|
||||||
|
|
|
@ -12,15 +12,14 @@ class NonceTracker {
|
||||||
// releaseLock must be called
|
// releaseLock must be called
|
||||||
// releaseLock must be called after adding signed tx to pending transactions (or discarding)
|
// releaseLock must be called after adding signed tx to pending transactions (or discarding)
|
||||||
async getNonceLock (address) {
|
async getNonceLock (address) {
|
||||||
|
const pendingTransactions = this.getPendingTransactions(address)
|
||||||
// await lock free
|
// await lock free
|
||||||
await this.lockMap[address]
|
if (pendingTransactions.length) await this.lockMap[address]
|
||||||
|
else if (this.lockMap[address]) await this.lockMap[address]()
|
||||||
// take lock
|
// take lock
|
||||||
const releaseLock = this._takeLock(address)
|
const releaseLock = this._takeLock(address)
|
||||||
// calculate next nonce
|
// calculate next nonce
|
||||||
const currentBlock = await this._getCurrentBlock()
|
const baseCount = await this._getTxCount(address)
|
||||||
const blockNumber = currentBlock.number
|
|
||||||
const pendingTransactions = this.getPendingTransactions(address)
|
|
||||||
const baseCount = await this._getTxCount(address, blockNumber)
|
|
||||||
const nextNonce = parseInt(baseCount) + pendingTransactions.length
|
const nextNonce = parseInt(baseCount) + pendingTransactions.length
|
||||||
// return next nonce and release cb
|
// return next nonce and release cb
|
||||||
return { nextNonce: nextNonce.toString(16), releaseLock }
|
return { nextNonce: nextNonce.toString(16), releaseLock }
|
||||||
|
@ -44,7 +43,9 @@ class NonceTracker {
|
||||||
return releaseLock
|
return releaseLock
|
||||||
}
|
}
|
||||||
|
|
||||||
_getTxCount (address, blockNumber) {
|
async _getTxCount (address) {
|
||||||
|
const currentBlock = await this._getCurrentBlock()
|
||||||
|
const blockNumber = currentBlock.number
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.ethQuery.getTransactionCount(address, blockNumber, (err, result) => {
|
this.ethQuery.getTransactionCount(address, blockNumber, (err, result) => {
|
||||||
err ? reject(err) : resolve(result)
|
err ? reject(err) : resolve(result)
|
||||||
|
|
Loading…
Reference in New Issue