From ef17dec1950a58ecaf833ebd7c0c418cede126f4 Mon Sep 17 00:00:00 2001 From: cubedro Date: Tue, 28 Apr 2015 07:05:04 +0300 Subject: [PATCH 1/2] fixed debounce delay --- lib/node.js | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/lib/node.js b/lib/node.js index 89cc2b2..d51a978 100644 --- a/lib/node.js +++ b/lib/node.js @@ -113,6 +113,9 @@ function Node() this.updateInterval = false; this.pingInterval = false; + this._lastLatestLog = 0; + this._lastPendingLog = 0; + socket.on('open', function open() { socket.emit('hello', { id: self.id, info: self.info, secret: WS_SECRET }); console.info('The connection has been opened.'); @@ -487,9 +490,21 @@ Node.prototype.setWatches = function() this.pendingFilter = web3.eth.filter('pending'); this.pendingFilter.watch( function(log) { if(PENDING_WORKS) { - debounce(function() { - self.updatePending(); - }, 50); + var now = (new Date()).getTime(); + var time = now - self._lastPendingLog; + + if(time > 50) + { + self.update(); + } + else + { + debounce(function() { + self.updatePending(); + }, 50); + } + + self._lastPendingLog = now; } }); } @@ -501,10 +516,23 @@ Node.prototype.setWatches = function() try { this.chainFilter = web3.eth.filter('latest'); - this.chainFilter.watch(function(log) { - debounce(function() { + this.chainFilter.watch(function(log) + { + var now = (new Date()).getTime(); + var time = now - self._lastLatestLog; + + if(time > 50) + { self.update(); - }, 50); + } + else + { + debounce(function() { + self.update(); + }, 50); + } + + self._lastLatestLog = now; }); } catch (err) From 2ac7cba9f4dfc72a31a8f9d20a4630e7560135b4 Mon Sep 17 00:00:00 2001 From: cubedro Date: Tue, 28 Apr 2015 08:38:37 +0300 Subject: [PATCH 2/2] removed latest filter --- lib/node.js | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/node.js b/lib/node.js index d51a978..3773a01 100644 --- a/lib/node.js +++ b/lib/node.js @@ -40,7 +40,7 @@ var socket = new Socket(process.env.WS_SERVER || 'ws://localhost:3000'); var WS_SECRET = process.env.WS_SECRET || "eth-net-stats-has-a-secret"; var PENDING_WORKS = true; -var MAX_BLOCKS_HISTORY = 36; +var MAX_BLOCKS_HISTORY = 40; var UPDATE_INTERVAL = 5000; var PING_INTERVAL = 2000; var MINERS_LIMIT = 5; @@ -514,32 +514,32 @@ Node.prototype.setWatches = function() console.error(err); } - try { - this.chainFilter = web3.eth.filter('latest'); - this.chainFilter.watch(function(log) - { - var now = (new Date()).getTime(); - var time = now - self._lastLatestLog; + // try { + // this.chainFilter = web3.eth.filter('latest'); + // this.chainFilter.watch(function(log) + // { + // var now = (new Date()).getTime(); + // var time = now - self._lastLatestLog; - if(time > 50) - { - self.update(); - } - else - { - debounce(function() { - self.update(); - }, 50); - } + // if(time > 50) + // { + // self.update(); + // } + // else + // { + // debounce(function() { + // self.update(); + // }, 50); + // } - self._lastLatestLog = now; - }); - } - catch (err) - { - console.error("Couldn't set up chain filter"); - console.error(err); - } + // self._lastLatestLog = now; + // }); + // } + // catch (err) + // { + // console.error("Couldn't set up chain filter"); + // console.error(err); + // } this.updateInterval = setInterval(function(){ self.update();