Skip to content

Commit 2d1b7c0

Browse files
authored
Merge pull request #1757 from MetaMask/resubmit-fix
Resubmit fix
2 parents fd6caf8 + 512b6ca commit 2d1b7c0

File tree

3 files changed

+53
-6
lines changed

3 files changed

+53
-6
lines changed

app/scripts/controllers/transactions.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -417,23 +417,28 @@ module.exports = class TransactionController extends EventEmitter {
417417
// only try resubmitting if their are transactions to resubmit
418418
if (!pending.length) return
419419
const resubmit = denodeify(this._resubmitTx.bind(this))
420-
pending.forEach((txMeta) => resubmit(txMeta)
421-
.catch((reason) => {
420+
pending.forEach((txMeta) => resubmit(txMeta).catch((err) => {
422421
/*
423422
Dont marked as failed if the error is a "known" transaction warning
424423
"there is already a transaction with the same sender-nonce
425424
but higher/same gas price"
426425
*/
427-
const errorMessage = reason.message.toLowerCase()
426+
const errorMessage = err.message.toLowerCase()
428427
const isKnownTx = (
429428
// geth
430429
errorMessage === 'replacement transaction underpriced'
431430
|| errorMessage.startsWith('known transaction')
432431
// parity
433432
|| errorMessage === 'gas price too low to replace'
433+
|| errorMessage === 'transaction with the same hash was already imported.'
434434
)
435435
// ignore resubmit warnings, return early
436-
if (!isKnownTx) this.setTxStatusFailed(txMeta.id, reason.message)
436+
if (isKnownTx) return
437+
// encountered real error - transition to error state
438+
this.setTxStatusFailed(txMeta.id, {
439+
errCode: err.errCode || err,
440+
message: err.message,
441+
})
437442
}))
438443
}
439444

@@ -448,15 +453,15 @@ module.exports = class TransactionController extends EventEmitter {
448453
// if the value of the transaction is greater then the balance, fail.
449454
if (gtBalance) {
450455
const message = 'Insufficient balance.'
451-
this.setTxStatusFailed(txMeta.id, message)
456+
this.setTxStatusFailed(txMeta.id, { message })
452457
cb()
453458
return log.error(message)
454459
}
455460

456461
// if the nonce of the transaction is lower then the accounts nonce, fail.
457462
if (txNonce < nonce) {
458463
const message = 'Invalid nonce.'
459-
this.setTxStatusFailed(txMeta.id, message)
464+
this.setTxStatusFailed(txMeta.id, { message })
460465
cb()
461466
return log.error(message)
462467
}

app/scripts/migrations/016.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const version = 16
2+
3+
/*
4+
5+
This migration sets transactions with the 'Gave up submitting tx.' err message
6+
to a 'failed' stated
7+
8+
*/
9+
10+
const clone = require('clone')
11+
12+
module.exports = {
13+
version,
14+
15+
migrate: function (originalVersionedData) {
16+
const versionedData = clone(originalVersionedData)
17+
versionedData.meta.version = version
18+
try {
19+
const state = versionedData.data
20+
const newState = transformState(state)
21+
versionedData.data = newState
22+
} catch (err) {
23+
console.warn(`MetaMask Migration #${version}` + err.stack)
24+
}
25+
return Promise.resolve(versionedData)
26+
},
27+
}
28+
29+
function transformState (state) {
30+
const newState = state
31+
const transactions = newState.TransactionController.transactions
32+
newState.TransactionController.transactions = transactions.map((txMeta) => {
33+
if (!txMeta.err) return txMeta
34+
if (txMeta.err === 'transaction with the same hash was already imported.') {
35+
txMeta.status = 'submitted'
36+
delete txMeta.err
37+
}
38+
return txMeta
39+
})
40+
return newState
41+
}

app/scripts/migrations/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ module.exports = [
2626
require('./013'),
2727
require('./014'),
2828
require('./015'),
29+
require('./016'),
2930
]

0 commit comments

Comments
 (0)