1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-22 17:33:23 +01:00

Adjust gas buffer to be 20% over estimate

This commit is contained in:
Dan Finlay 2016-11-08 08:39:41 -08:00
parent 6f39924e60
commit 7068d2e71c
3 changed files with 7 additions and 7 deletions

View File

@ -3,7 +3,7 @@
## Current Master ## Current Master
- Fix bug where gas estimate would sometimes be very high. - Fix bug where gas estimate would sometimes be very high.
- Increased our gas estimate safety buffer to avoid Out of Gas errors. - Increased our gas estimate from 100k gas to 20% of estimate.
- Fix github link on info page to point at current repository. - Fix github link on info page to point at current repository.
## 2.13.6 2016-10-26 ## 2.13.6 2016-10-26

View File

@ -287,9 +287,10 @@ IdentityStore.prototype.checkForDelegateCall = function (codeHex) {
} }
} }
const gasBuffer = new BN('200000', 10)
IdentityStore.prototype.addGasBuffer = function (gas) { IdentityStore.prototype.addGasBuffer = function (gas) {
const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16) const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16)
const five = new BN('5', 10)
const gasBuffer = bnGas.div(five)
const correct = bnGas.add(gasBuffer) const correct = bnGas.add(gasBuffer)
return ethUtil.addHexPrefix(correct.toString(16)) return ethUtil.addHexPrefix(correct.toString(16))
} }

View File

@ -159,7 +159,7 @@ describe('IdentityStore', function() {
assert.equal(result.indexOf('0x'), 0, 'include hex prefix') assert.equal(result.indexOf('0x'), 0, 'include hex prefix')
}) })
it('buffers reasonably', function() { it('buffers 20%', function() {
const idStore = new IdentityStore({ const idStore = new IdentityStore({
configManager: configManagerGen(), configManager: configManagerGen(),
ethStore: { ethStore: {
@ -169,18 +169,17 @@ describe('IdentityStore', function() {
const gas = '0x04ee59' // Actual estimated gas example const gas = '0x04ee59' // Actual estimated gas example
const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16) const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16)
const correctBuffer = new BN('200000', 10) const five = new BN('5', 10)
const correctBuffer = bnGas.div(five)
const correct = bnGas.add(correctBuffer) const correct = bnGas.add(correctBuffer)
const tooBig = new BN(tooBigOutput, 16)
const result = idStore.addGasBuffer(gas) const result = idStore.addGasBuffer(gas)
const bnResult = new BN(ethUtil.stripHexPrefix(result), 16) const bnResult = new BN(ethUtil.stripHexPrefix(result), 16)
assert.equal(result.indexOf('0x'), 0, 'included hex prefix') assert.equal(result.indexOf('0x'), 0, 'included hex prefix')
assert(bnResult.gt(bnGas), 'Estimate increased in value.') assert(bnResult.gt(bnGas), 'Estimate increased in value.')
assert.equal(bnResult.sub(bnGas).toString(10), '100000', 'added 100k gas') assert.equal(bnResult.sub(bnGas).toString(10), correctBuffer.toString(10), 'added 20% gas')
assert.equal(result, '0x' + correct.toString(16), 'Added the right amount') assert.equal(result, '0x' + correct.toString(16), 'Added the right amount')
assert.notEqual(result, tooBigOutput, 'not that bad estimate')
}) })
}) })