added web3 reconnect

This commit is contained in:
cubedro 2015-06-12 22:03:40 +03:00
parent d2ec7e55af
commit c634623bec

View File

@ -174,7 +174,31 @@ 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() Node.prototype.startSocketConnection = function()
{
if( !this._socket )
{ {
console.info('wsc', 'Starting socket connection'); console.info('wsc', 'Starting socket connection');
@ -182,6 +206,7 @@ Node.prototype.startSocketConnection = function()
this.setupSockets(); this.setupSockets();
} }
}
Node.prototype.setupSockets = function() Node.prototype.setupSockets = function()
{ {
@ -327,13 +352,17 @@ Node.prototype.setInactive = function()
{ {
this.stats.active = false; this.stats.active = false;
this.stats.peers = 0; this.stats.peers = 0;
this.stats.pending = 0;
this.stats.mining = false; this.stats.mining = false;
this.stats.hashrate = 0; this.stats.hashrate = 0;
this.stats.gasPrice = 0;
this.stats.minerName = false;
this._down++; this._down++;
this.setUptime();
this.sendStatsUpdate(true);
// Schedule web3 reconnect
this.reconnectWeb3();
return this; return this;
} }
@ -688,6 +717,11 @@ Node.prototype.setWatches = function()
var time = now - self._lastChainLog; var time = now - self._lastChainLog;
self._lastChainLog = now; 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)); console.info('>>>', 'Chain Filter triggered: ', chalk.reset.red(hash), '- last trigger:', chalk.reset.cyan(time));
if(time < 5) if(time < 5)