mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge pull request #1187 from MetaMask/i1118-IncreaseGasBuffer
I1118 increase gas buffer
This commit is contained in:
commit
de5a30c5ff
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
- Add personal_sign method support.
|
- Add personal_sign method support.
|
||||||
- Add ability to customize gas and gasPrice on the transaction approval screen.
|
- Add ability to customize gas and gasPrice on the transaction approval screen.
|
||||||
|
- Increase default gas buffer to 1.5x estimated gas value.
|
||||||
|
|
||||||
## 3.3.0 2017-2-20
|
## 3.3.0 2017-2-20
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ module.exports = class txProviderUtils {
|
|||||||
// try adding an additional gas buffer to our estimation for safety
|
// try adding an additional gas buffer to our estimation for safety
|
||||||
const estimatedGasBn = new BN(ethUtil.stripHexPrefix(txData.estimatedGas), 16)
|
const estimatedGasBn = new BN(ethUtil.stripHexPrefix(txData.estimatedGas), 16)
|
||||||
const blockGasLimitBn = new BN(ethUtil.stripHexPrefix(blockGasLimitHex), 16)
|
const blockGasLimitBn = new BN(ethUtil.stripHexPrefix(blockGasLimitHex), 16)
|
||||||
const estimationWithBuffer = new BN(this.addGasBuffer(estimatedGasBn), 16)
|
const estimationWithBuffer = new BN(this.addGasBuffer(estimatedGasBn, blockGasLimitHex), 16)
|
||||||
// added gas buffer is too high
|
// added gas buffer is too high
|
||||||
if (estimationWithBuffer.gt(blockGasLimitBn)) {
|
if (estimationWithBuffer.gt(blockGasLimitBn)) {
|
||||||
txParams.gas = txData.estimatedGas
|
txParams.gas = txData.estimatedGas
|
||||||
@ -68,11 +68,14 @@ module.exports = class txProviderUtils {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
addGasBuffer (gas) {
|
addGasBuffer (gas, blockGasLimitHex) {
|
||||||
const gasBuffer = new BN('100000', 10)
|
const blockGasLimitBn = new BN(ethUtil.stripHexPrefix(blockGasLimitHex), 16)
|
||||||
const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16)
|
const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16)
|
||||||
const correct = bnGas.add(gasBuffer)
|
const bufferedGas = bnGas.muln(1.5)
|
||||||
return ethUtil.addHexPrefix(correct.toString(16))
|
|
||||||
|
if (bnGas.gt(blockGasLimitBn)) return gas
|
||||||
|
if (bufferedGas.lt(blockGasLimitBn)) return ethUtil.addHexPrefix(bufferedGas.toString(16))
|
||||||
|
return ethUtil.addHexPrefix(blockGasLimitBn.toString(16))
|
||||||
}
|
}
|
||||||
|
|
||||||
fillInTxParams (txParams, cb) {
|
fillInTxParams (txParams, cb) {
|
||||||
|
26
test/unit/tx-utils-test.js
Normal file
26
test/unit/tx-utils-test.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
const assert = require('assert')
|
||||||
|
const ethUtil = require('ethereumjs-util')
|
||||||
|
const BN = ethUtil.BN
|
||||||
|
|
||||||
|
const TxUtils = require('../../app/scripts/lib/tx-utils')
|
||||||
|
|
||||||
|
|
||||||
|
describe('txUtils', function() {
|
||||||
|
let txUtils
|
||||||
|
|
||||||
|
before(function() {
|
||||||
|
txUtils = new TxUtils()
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('addGasBuffer', function() {
|
||||||
|
it('multiplies by 1.5', function() {
|
||||||
|
const input = '0x123fad'
|
||||||
|
const output = txUtils.addGasBuffer(input, '0x3d4c52') //0x3d4c52 is 4mil for dummy gas limit
|
||||||
|
|
||||||
|
const inputBn = new BN(ethUtil.stripHexPrefix(input), 'hex')
|
||||||
|
const outputBn = new BN(ethUtil.stripHexPrefix(output), 'hex')
|
||||||
|
const expectedBn = inputBn.muln(1.5)
|
||||||
|
assert(outputBn.eq(expectedBn), 'returns 1.5 the input value')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user