mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge pull request #1494 from MetaMask/1472-gasceiling
Add Max GasLimit Ceiling
This commit is contained in:
commit
764806d211
@ -5,6 +5,7 @@
|
||||
- Now when switching networks the extension does not restart
|
||||
- Cleanup decimal bugs in our gas inputs.
|
||||
- Fix bug where submit button was enabled for invalid gas inputs.
|
||||
- Now enforce 95% of block's gasLimit to protect users.
|
||||
|
||||
## 3.7.0 2017-5-23
|
||||
|
||||
|
@ -21,19 +21,30 @@ module.exports = class txProviderUtils {
|
||||
this.query.getBlockByNumber('latest', true, (err, block) => {
|
||||
if (err) return cb(err)
|
||||
async.waterfall([
|
||||
self.setBlockGasLimit.bind(self, txMeta, block.gasLimit),
|
||||
self.estimateTxGas.bind(self, txMeta, block.gasLimit),
|
||||
self.setTxGas.bind(self, txMeta, block.gasLimit),
|
||||
], cb)
|
||||
})
|
||||
}
|
||||
|
||||
setBlockGasLimit (txMeta, blockGasLimitHex, cb) {
|
||||
const blockGasLimitBN = hexToBn(blockGasLimitHex)
|
||||
const saferGasLimitBN = blockGasLimitBN.muln(0.95)
|
||||
txMeta.blockGasLimit = bnToHex(saferGasLimitBN)
|
||||
cb()
|
||||
return
|
||||
}
|
||||
|
||||
estimateTxGas (txMeta, blockGasLimitHex, cb) {
|
||||
const txParams = txMeta.txParams
|
||||
// check if gasLimit is already specified
|
||||
txMeta.gasLimitSpecified = Boolean(txParams.gas)
|
||||
// if not, fallback to block gasLimit
|
||||
if (!txMeta.gasLimitSpecified) {
|
||||
txParams.gas = blockGasLimitHex
|
||||
const blockGasLimitBN = hexToBn(blockGasLimitHex)
|
||||
const saferGasLimitBN = blockGasLimitBN.muln(0.95)
|
||||
txParams.gas = bnToHex(saferGasLimitBN)
|
||||
}
|
||||
// run tx, see if it will OOG
|
||||
this.query.estimateGas(txParams, cb)
|
||||
|
@ -47,6 +47,7 @@ PendingTx.prototype.render = function () {
|
||||
// Gas
|
||||
const gas = txParams.gas
|
||||
const gasBn = hexToBn(gas)
|
||||
const safeGasLimit = parseInt(txMeta.blockGasLimit)
|
||||
|
||||
// Gas Price
|
||||
const gasPrice = txParams.gasPrice || MIN_GAS_PRICE_BN.toString(16)
|
||||
@ -159,6 +160,7 @@ PendingTx.prototype.render = function () {
|
||||
scale: 0,
|
||||
// The hard lower limit for gas.
|
||||
min: MIN_GAS_LIMIT_BN.toString(10),
|
||||
max: safeGasLimit,
|
||||
suffix: 'UNITS',
|
||||
style: {
|
||||
position: 'relative',
|
||||
|
Loading…
Reference in New Issue
Block a user