diff --git a/lib/node.js b/lib/node.js index e458ae7..9ff8a77 100644 --- a/lib/node.js +++ b/lib/node.js @@ -174,13 +174,38 @@ Node.prototype.checkWeb3Connection = function() } } +Node.prototype.reconnectWeb3 = function() +{ + this._web3 = false; + + if(this.updateInterval) + clearInterval(this.updateInterval); + + if(this.pingInterval) + clearInterval(this.pingInterval); + + try + { + web3.reset(); + } + catch (err) + { + console.error("Web3 reset error:", err); + } + + this.checkWeb3Connection(); +} + Node.prototype.startSocketConnection = function() { - console.info('wsc', 'Starting socket connection'); + if( !this._socket ) + { + console.info('wsc', 'Starting socket connection'); - socket = new Socket( process.env.WS_SERVER || 'ws://localhost:3000' ); + socket = new Socket( process.env.WS_SERVER || 'ws://localhost:3000' ); - this.setupSockets(); + this.setupSockets(); + } } Node.prototype.setupSockets = function() @@ -327,13 +352,17 @@ Node.prototype.setInactive = function() { this.stats.active = false; this.stats.peers = 0; - this.stats.pending = 0; this.stats.mining = false; this.stats.hashrate = 0; - this.stats.gasPrice = 0; - this.stats.minerName = false; this._down++; + this.setUptime(); + + this.sendStatsUpdate(true); + + // Schedule web3 reconnect + this.reconnectWeb3(); + return this; } @@ -688,6 +717,11 @@ Node.prototype.setWatches = function() var time = now - self._lastChainLog; self._lastChainLog = now; + if(hash === null) + { + hash = web3.eth.blockNumber; + } + console.info('>>>', 'Chain Filter triggered: ', chalk.reset.red(hash), '- last trigger:', chalk.reset.cyan(time)); if(time < 5)