aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJared Pereira <jared@otlw.co>2017-03-08 08:57:57 +0800
committerJared Pereira <jared@otlw.co>2017-03-08 08:57:57 +0800
commit4256e631a6174f04d338412f419ceb0c08d724f1 (patch)
treebff36ecf9ec557c1bf5e607c756be27f18c47a4e
parente78e642eef21c0219eb025f859edea5817363b3f (diff)
downloadtangerine-wallet-browser-4256e631a6174f04d338412f419ceb0c08d724f1.tar.gz
tangerine-wallet-browser-4256e631a6174f04d338412f419ceb0c08d724f1.tar.zst
tangerine-wallet-browser-4256e631a6174f04d338412f419ceb0c08d724f1.zip
remove constant buffer and add multiplier
-rw-r--r--app/scripts/lib/tx-utils.js13
1 files changed, 8 insertions, 5 deletions
diff --git a/app/scripts/lib/tx-utils.js b/app/scripts/lib/tx-utils.js
index 19a2d430e..15cbb5b68 100644
--- a/app/scripts/lib/tx-utils.js
+++ b/app/scripts/lib/tx-utils.js
@@ -55,7 +55,7 @@ module.exports = class txProviderUtils {
// try adding an additional gas buffer to our estimation for safety
const estimatedGasBn = new BN(ethUtil.stripHexPrefix(txData.estimatedGas), 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
if (estimationWithBuffer.gt(blockGasLimitBn)) {
txParams.gas = txData.estimatedGas
@@ -68,11 +68,14 @@ module.exports = class txProviderUtils {
return
}
- addGasBuffer (gas) {
- const gasBuffer = new BN('100000', 10)
+ addGasBuffer (gas, blockGasLimitHex) {
+ const blockGasLimitBn = new BN(ethUtil.stripHexPrefix(blockGasLimitHex), 16)
const bnGas = new BN(ethUtil.stripHexPrefix(gas), 16)
- const correct = bnGas.add(gasBuffer)
- return ethUtil.addHexPrefix(correct.toString(16))
+ const bufferedGas = bnGas.mul(1.5)
+
+ 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) {