1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-23 03:36:18 +02:00

Merge pull request #1187 from MetaMask/i1118-IncreaseGasBuffer

I1118 increase gas buffer
This commit is contained in:
Dan Finlay 2017-03-07 21:41:54 -08:00 committed by GitHub
commit de5a30c5ff
3 changed files with 35 additions and 5 deletions

View File

@ -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

View File

@ -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) {

View 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')
})
})
})