Unverified Commit 1387bf86 authored by yann300's avatar yann300 Committed by GitHub

Merge pull request #711 from ethereum/fixBlockPolling

fix getBlock/SetInterval && update block gas limit when provider change
parents c5722689 3bc91d4b
...@@ -173,6 +173,7 @@ function ExecutionContext () { ...@@ -173,6 +173,7 @@ function ExecutionContext () {
} else { } else {
executionContext = context executionContext = context
web3.setProvider(injectedProvider) web3.setProvider(injectedProvider)
self._updateBlockGasLimit()
self.event.trigger('contextChanged', ['injected']) self.event.trigger('contextChanged', ['injected'])
return cb() return cb()
} }
...@@ -192,8 +193,7 @@ function ExecutionContext () { ...@@ -192,8 +193,7 @@ function ExecutionContext () {
this.listenOnLastBlockId = null this.listenOnLastBlockId = null
} }
this.listenOnLastBlock = function () { this._updateBlockGasLimit = function () {
this.listenOnLastBlockId = setInterval(() => {
if (this.getProvider() !== 'vm') { if (this.getProvider() !== 'vm') {
web3.eth.getBlock('latest', (err, block) => { web3.eth.getBlock('latest', (err, block) => {
if (!err) { if (!err) {
...@@ -202,10 +202,15 @@ function ExecutionContext () { ...@@ -202,10 +202,15 @@ function ExecutionContext () {
} else { } else {
this.blockGasLimit = this.blockGasLimitDefault this.blockGasLimit = this.blockGasLimitDefault
} }
}, 15000)
}
}) })
} }
}
this.listenOnLastBlock = function () {
this.listenOnLastBlockId = setInterval(() => {
this._updateBlockGasLimit()
}, 15000)
}
// TODO: not used here anymore and needs to be moved // TODO: not used here anymore and needs to be moved
function setProviderFromEndpoint (endpoint, context, cb) { function setProviderFromEndpoint (endpoint, context, cb) {
...@@ -218,6 +223,7 @@ function ExecutionContext () { ...@@ -218,6 +223,7 @@ function ExecutionContext () {
} }
if (web3.isConnected()) { if (web3.isConnected()) {
executionContext = context executionContext = context
self._updateBlockGasLimit()
self.event.trigger('contextChanged', ['web3']) self.event.trigger('contextChanged', ['web3'])
self.event.trigger('web3EndpointChanged') self.event.trigger('web3EndpointChanged')
cb() cb()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment