Refactor gas limit estimation when gas limit specified (#8485)

The `analyzeGasUsage` function is skipped entirely now when the gas
limit is specified. This is functionally equivalent to how it worked
before.
feature/default_network_editable
Mark Stacey 5 years ago committed by GitHub
parent afa2ff65b7
commit 157cc98c3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      app/scripts/controllers/transactions/index.js
  2. 14
      app/scripts/controllers/transactions/tx-gas-utils.js

@ -274,10 +274,13 @@ export default class TransactionController extends EventEmitter {
// set gasLimit // set gasLimit
if ( if (txParams.gas) {
txMeta.estimatedGas = txParams.gas
txMeta.gasLimitSpecified = Boolean(txParams.gas)
return txMeta
} else if (
txParams.to && txParams.to &&
txMeta.transactionCategory === SEND_ETHER_ACTION_KEY && txMeta.transactionCategory === SEND_ETHER_ACTION_KEY
!txParams.gas
) { ) {
// if there's data in the params, but there's no contract code, it's not a valid transaction // if there's data in the params, but there's no contract code, it's not a valid transaction
if (txParams.data) { if (txParams.data) {

@ -48,14 +48,6 @@ export default class TxGasUtil {
async estimateTxGas (txMeta, blockGasLimitHex) { async estimateTxGas (txMeta, blockGasLimitHex) {
const txParams = txMeta.txParams const txParams = txMeta.txParams
// check if gasLimit is already specified
txMeta.gasLimitSpecified = Boolean(txParams.gas)
// if it is, use that value
if (txMeta.gasLimitSpecified) {
return txParams.gas
}
// fallback to block gasLimit // fallback to block gasLimit
const blockGasLimitBN = hexToBn(blockGasLimitHex) const blockGasLimitBN = hexToBn(blockGasLimitHex)
const saferGasLimitBN = BnMultiplyByFraction(blockGasLimitBN, 19, 20) const saferGasLimitBN = BnMultiplyByFraction(blockGasLimitBN, 19, 20)
@ -75,12 +67,6 @@ export default class TxGasUtil {
txMeta.estimatedGas = addHexPrefix(estimatedGasHex) txMeta.estimatedGas = addHexPrefix(estimatedGasHex)
const txParams = txMeta.txParams const txParams = txMeta.txParams
// if gasLimit was specified and doesnt OOG,
// use original specified amount
if (txMeta.gasLimitSpecified) {
txMeta.estimatedGas = txParams.gas
return
}
// if gasLimit not originally specified, // if gasLimit not originally specified,
// try adding an additional gas buffer to our estimation for safety // try adding an additional gas buffer to our estimation for safety
const recommendedGasHex = this.addGasBuffer(txMeta.estimatedGas, blockGasLimitHex) const recommendedGasHex = this.addGasBuffer(txMeta.estimatedGas, blockGasLimitHex)

Loading…
Cancel
Save