mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
fix nonce calculation order
This commit is contained in:
parent
690685d20d
commit
6d2cddaac9
@ -12,14 +12,16 @@ 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
|
||||||
if (pendingTransactions.length) await this.lockMap[address]
|
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 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
|
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 }
|
||||||
@ -43,8 +45,7 @@ class NonceTracker {
|
|||||||
return releaseLock
|
return releaseLock
|
||||||
}
|
}
|
||||||
|
|
||||||
async _getTxCount (address) {
|
async _getTxCount (address, currentBlock) {
|
||||||
const currentBlock = await this._getCurrentBlock()
|
|
||||||
const blockNumber = currentBlock.number
|
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) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user