aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/scripts/controllers/transactions/index.js9
-rw-r--r--test/unit/app/controllers/transactions/tx-controller-test.js5
2 files changed, 13 insertions, 1 deletions
diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js
index b44f66f14..1dd410d2c 100644
--- a/app/scripts/controllers/transactions/index.js
+++ b/app/scripts/controllers/transactions/index.js
@@ -229,7 +229,16 @@ class TransactionController extends EventEmitter {
async retryTransaction (originalTxId) {
const originalTxMeta = this.txStateManager.getTx(originalTxId)
+ const { txParams } = originalTxMeta
const lastGasPrice = originalTxMeta.txParams.gasPrice
+ const suggestedGasPriceBN = new ethUtil.BN(ethUtil.stripHexPrefix(this.getGasPrice()), 16)
+ const lastGasPriceBN = new ethUtil.BN(ethUtil.stripHexPrefix(lastGasPrice), 16)
+ // essentially lastGasPrice * 1.1 but
+ // dont trust decimals so a round about way of doing that
+ const lastGasPriceBNBumped = lastGasPriceBN.mul(new ethUtil.BN(110, 10)).div(new ethUtil.BN(100, 10))
+ // transactions that are being retried require a >=%10 bump or the clients will throw an error
+ txParams.gasPrice = suggestedGasPriceBN.gt(lastGasPriceBNBumped) ? `0x${suggestedGasPriceBN.toString(16)}` : `0x${lastGasPriceBNBumped.toString(16)}`
+
const txMeta = this.txStateManager.generateTxMeta({
txParams: originalTxMeta.txParams,
lastGasPrice,
diff --git a/test/unit/app/controllers/transactions/tx-controller-test.js b/test/unit/app/controllers/transactions/tx-controller-test.js
index b76f256b9..2fe4c47d1 100644
--- a/test/unit/app/controllers/transactions/tx-controller-test.js
+++ b/test/unit/app/controllers/transactions/tx-controller-test.js
@@ -28,6 +28,7 @@ describe('Transaction Controller', function () {
blockTrackerStub.getLatestBlock = noop
txController = new TransactionController({
provider,
+ getGasPrice: function () { return '0xee6b2800' },
networkStore: new ObservableStore(currentNetworkId),
txHistoryLimit: 10,
blockTracker: blockTrackerStub,
@@ -415,8 +416,9 @@ describe('Transaction Controller', function () {
})
describe('#retryTransaction', function () {
- it('should create a new txMeta with the same txParams as the original one', function (done) {
+ it('should create a new txMeta with the same txParams as the original one but with a higher gasPrice', function (done) {
const txParams = {
+ gasPrice: '0xee6b2800',
nonce: '0x00',
from: '0xB09d8505E1F4EF1CeA089D47094f5DD3464083d4',
to: '0xB09d8505E1F4EF1CeA089D47094f5DD3464083d4',
@@ -427,6 +429,7 @@ describe('Transaction Controller', function () {
])
txController.retryTransaction(1)
.then((txMeta) => {
+ assert.equal(txMeta.txParams.gasPrice, '0x10642ac00', 'gasPrice should have a %10 gasPrice bump')
assert.equal(txMeta.txParams.nonce, txParams.nonce, 'nonce should be the same')
assert.equal(txMeta.txParams.from, txParams.from, 'from should be the same')
assert.equal(txMeta.txParams.to, txParams.to, 'to should be the same')