last block gas limit

pull/1/head
yann300 7 years ago
parent d3537b3196
commit d74ad36bb3
  1. 3
      src/app.js
  2. 17
      src/app/execution-context.js
  3. 4
      src/app/renderer.js
  4. 9
      src/app/txRunner.js

@ -475,7 +475,8 @@ var run = function () {
callback(null, executionContext.web3().fromWei(balance, 'ether')) callback(null, executionContext.web3().fromWei(balance, 'ether'))
} }
}) })
} },
currentblockGasLimit: () => { return executionContext.currentblockGasLimit() }
} }
var renderer = new Renderer(rendererAPI, compiler.event) var renderer = new Renderer(rendererAPI, compiler.event)

@ -123,6 +123,23 @@ function ExecutionContext () {
} }
} }
this.currentblockGasLimit = function () {
return this.blockGasLimit
}
this.blockGasLimitDefault = 4300000
this.blockGasLimit = this.blockGasLimitDefault
setInterval(() => {
web3.eth.getBlock('latest', (err, block) => {
if (!err) {
// we can't use the blockGasLimit cause the next blocks could have a lower limit : https://github.com/ethereum/remix/issues/506
this.blockGasLimit = (block && block.gasLimit) ? Math.floor(block.gasLimit - (5 * block.gasLimit) / 1024) : this.blockGasLimitDefault
} else {
this.blockGasLimit = this.blockGasLimitDefault
}
})
}, 15000)
function setProviderFromEndpoint (endpoint) { function setProviderFromEndpoint (endpoint) {
if (endpoint === 'ipc') { if (endpoint === 'ipc') {
web3.setProvider(new web3.providers.IpcProvider()) web3.setProvider(new web3.providers.IpcProvider())

@ -111,6 +111,7 @@ Renderer.prototype.error = function (message, container, options) {
} }
Renderer.prototype.contracts = function (data, source) { Renderer.prototype.contracts = function (data, source) {
var self = this
var retrieveMetadataHash = function (bytecode) { var retrieveMetadataHash = function (bytecode) {
var match = /a165627a7a72305820([0-9a-f]{64})0029$/.exec(bytecode) var match = /a165627a7a72305820([0-9a-f]{64})0029$/.exec(bytecode)
if (match) { if (match) {
@ -210,7 +211,7 @@ Renderer.prototype.contracts = function (data, source) {
code += '\n {' + code += '\n {' +
'\n from: web3.eth.accounts[0], ' + '\n from: web3.eth.accounts[0], ' +
"\n data: '0x" + bytecode + "', " + "\n data: '0x" + bytecode + "', " +
"\n gas: '4700000'" + "\n gas: '" + self.appAPI.currentblockGasLimit() + "'" +
'\n }, function (e, contract){' + '\n }, function (e, contract){' +
'\n console.log(e, contract);' + '\n console.log(e, contract);' +
"\n if (typeof contract.address !== 'undefined') {" + "\n if (typeof contract.address !== 'undefined') {" +
@ -313,7 +314,6 @@ Renderer.prototype.contracts = function (data, source) {
return $('<div class="contractDetails"/>').append(button).append(details) return $('<div class="contractDetails"/>').append(button).append(details)
} }
var self = this
var renderOutputModifier = function (contractName, $contractOutput) { var renderOutputModifier = function (contractName, $contractOutput) {
var contract = data.contracts[contractName] var contract = data.contracts[contractName]
var ctrSource = self.appAPI.currentCompiledSourceCode() var ctrSource = self.appAPI.currentCompiledSourceCode()

@ -69,14 +69,9 @@ TxRunner.prototype.execute = function () {
if (err) { if (err) {
return callback(err, gasEstimation) return callback(err, gasEstimation)
} }
self.web3.eth.getBlock('latest', function (err, block) { var blockGasLimit = self.executionContext.currentblockGasLimit()
if (err) {
return callback(err)
} else {
// NOTE: estimateGas very likely will return a large limit if execution of the code failed // NOTE: estimateGas very likely will return a large limit if execution of the code failed
// we want to be able to run the code in order to debug and find the cause for the failure // we want to be able to run the code in order to debug and find the cause for the failure
// we can't use the blockGasLimit cause the next blocks could have a lower limit : https://github.com/ethereum/remix/issues/506
var blockGasLimit = Math.floor(block.gasLimit - (5 * block.gasLimit) / 1024)
if (gasEstimation > gasLimit) { if (gasEstimation > gasLimit) {
return callback('Gas required exceeds limit: ' + gasLimit) return callback('Gas required exceeds limit: ' + gasLimit)
} }
@ -92,8 +87,6 @@ TxRunner.prototype.execute = function () {
tryTillResponse(self.web3, resp, callback) tryTillResponse(self.web3, resp, callback)
}) })
}
})
}) })
} }
} else { } else {

Loading…
Cancel
Save