diff --git a/lib/node.js b/lib/node.js index 6a8e799..c76ee8f 100644 --- a/lib/node.js +++ b/lib/node.js @@ -105,7 +105,6 @@ function Node () this._socket = false; this._latestQueue = null; - this._chainDebouncer = 0; this.pendingFilter = false; this.chainFilter = false; this.updateInterval = false; @@ -114,7 +113,9 @@ function Node () this._lastChainLog = 0; this._lastPendingLog = 0; + this._chainDebouncer = 0; this._connection_attempts = 0 + this._timeOffset = null; this.startWeb3Connection(); @@ -216,7 +217,8 @@ Node.prototype.setupSockets = function() }) .on('node-pong', function(data) { - var latency = Math.ceil( (_.now() - self._latency) / 2 ); + var now = _.now(); + var latency = Math.ceil( (now - data.clientTime) / 2 ); socket.emit('latency', { id: self.id, @@ -339,7 +341,7 @@ Node.prototype.setUptime = function() Node.prototype.formatBlock = function (block) { - if( !_.isUndefined(block) && !_.isUndefined(block.number) && block.number >= 0 && !_.isUndefined(block.difficulty) && !_.isUndefined(block.totalDifficulty) ) + if( !_.isNull(block) && !_.isUndefined(block) && !_.isUndefined(block.number) && block.number >= 0 && !_.isUndefined(block.difficulty) && !_.isUndefined(block.totalDifficulty) ) { block.difficulty = block.difficulty.toString(10); block.totalDifficulty = block.totalDifficulty.toString(10); @@ -629,7 +631,10 @@ Node.prototype.sendStatsUpdate = function (force) Node.prototype.ping = function() { this._latency = _.now(); - socket.emit('node-ping', { id: this.id }); + socket.emit('node-ping', { + id: this.id, + clientTime: _.now() + }); }; Node.prototype.setWatches = function()