From 068133b0217ea9d255e9fa9f3e9f9127a75ead8a Mon Sep 17 00:00:00 2001 From: cubedro Date: Mon, 27 Apr 2015 12:52:36 +0300 Subject: [PATCH 1/4] removed console log --- models/history.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/models/history.js b/models/history.js index 883a958..5791bfd 100644 --- a/models/history.js +++ b/models/history.js @@ -170,8 +170,6 @@ History.prototype.getUncleCount = function(id) }) .value(); - console.log(uncles); - var uncleBins = _.fill(Array(MAX_BINS), 0); var sumMapper = function(array, key) { From 2fd2145d546f394fcd4a9963cd7bbb3d6e41f6de Mon Sep 17 00:00:00 2001 From: cubedro Date: Tue, 28 Apr 2015 02:50:28 +0300 Subject: [PATCH 2/4] better error handling --- app.js | 13 +++++---- models/collection.js | 4 +++ models/history.js | 69 ++++++++++++++++++++++++-------------------- 3 files changed, 49 insertions(+), 37 deletions(-) diff --git a/app.js b/app.js index bec719d..d3ed687 100644 --- a/app.js +++ b/app.js @@ -82,13 +82,16 @@ api.on('connection', function(spark) { data.stats.latency = spark.latency; var stats = Nodes.update(data.id, data.stats); - client.write({action: 'update', data: stats}); + if(stats !== false) + { + client.write({action: 'update', data: stats}); - var blockPropagationChart = Nodes.blockPropagationChart(); - client.write({action: 'blockPropagationChart', data: blockPropagationChart}); + var blockPropagationChart = Nodes.blockPropagationChart(); + client.write({action: 'blockPropagationChart', data: blockPropagationChart}); - var uncleCount = Nodes.getUncleCount(); - client.write({action: 'uncleCount', data: uncleCount}); + var uncleCount = Nodes.getUncleCount(); + client.write({action: 'uncleCount', data: uncleCount}); + } } }); diff --git a/models/collection.js b/models/collection.js index 0243944..c460db6 100644 --- a/models/collection.js +++ b/models/collection.js @@ -27,6 +27,10 @@ Collection.prototype.update = function(id, stats) return false; var block = this._history.add(stats.block, id); + + if(! block) + return false; + var propagationHistory = this._history.getNodePropagation(id); stats.block.arrived = block.arrived; diff --git a/models/history.js b/models/history.js index 5791bfd..4b052f6 100644 --- a/models/history.js +++ b/models/history.js @@ -33,47 +33,52 @@ var History = function History(data) History.prototype.add = function(block, id) { - var historyBlock = this.search(block.number); - - var now = (new Date()).getTime(); - block.arrived = now; - block.received = now; - block.propagation = 0; - - if(historyBlock) + if(typeof block !== 'undefined' && typeof block.number !== 'undefined' && typeof block.uncles !== 'undefined' && typeof block.transactions !== 'undefined') { - var propIndex = _.findIndex(historyBlock.propagTimes, {node: id}); + var historyBlock = this.search(block.number); - if(propIndex === -1) + var now = (new Date()).getTime(); + block.arrived = now; + block.received = now; + block.propagation = 0; + + if(historyBlock) { - block.arrived = historyBlock.block.arrived; - block.received = now; - block.propagation = now - historyBlock.block.received; + var propIndex = _.findIndex(historyBlock.propagTimes, {node: id}); - historyBlock.propagTimes.push({node: id, received: now, propagation: block.propagation}); + if(propIndex === -1) + { + block.arrived = historyBlock.block.arrived; + block.received = now; + block.propagation = now - historyBlock.block.received; + + historyBlock.propagTimes.push({node: id, received: now, propagation: block.propagation}); + } + else + { + block.arrived = historyBlock.block.arrived; + block.received = historyBlock.propagTimes[propIndex].received; + block.propagation = historyBlock.propagTimes[propIndex].propagation; + } } else { - block.arrived = historyBlock.block.arrived; - block.received = historyBlock.propagTimes[propIndex].received; - block.propagation = historyBlock.propagTimes[propIndex].propagation; - } - } - else - { - var item = { - height: block.number, - block: block, - propagTimes: [] - } + var item = { + height: block.number, + block: block, + propagTimes: [] + } - item.propagTimes.push({node: id, received: now, propagation: block.propagation}); - console.log('item: ', item); - this._save(item); - } - this.getNodePropagation(id); + item.propagTimes.push({node: id, received: now, propagation: block.propagation}); + console.log('item: ', item); + this._save(item); + } + this.getNodePropagation(id); - return block; + return block; + } + + return false; } History.prototype._save = function(block) From fbc7e90e7657b488b1566793798ba6763618942c Mon Sep 17 00:00:00 2001 From: cubedro Date: Tue, 28 Apr 2015 03:52:41 +0300 Subject: [PATCH 3/4] removed unnecessary console logs --- app.js | 10 ++-------- models/history.js | 25 ++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/app.js b/app.js index d3ed687..f4eb12d 100644 --- a/app.js +++ b/app.js @@ -43,7 +43,7 @@ api.on('connection', function(spark) { spark.on('hello', function(data) { console.log('Latency: ', spark.latency); - console.log('got hello data from ', spark.id); + console.log('Got hello data from ', spark.id); console.log(data); if(typeof data.secret === 'undefined' || data.secret !== WS_SECRET) @@ -75,7 +75,7 @@ api.on('connection', function(spark) { spark.on('update', function(data) { console.log('Latency: ', spark.latency); - console.log('got update from ' + spark.id); + console.log('Got update from ' + spark.id); if(typeof data.id !== 'undefined' && typeof data.stats !== 'undefined') { @@ -101,9 +101,6 @@ api.on('connection', function(spark) { spark.on('latency', function(data) { - console.log('Latency: ', data.latency); - console.log('got ping from ' + spark.id); - if(typeof data.id !== 'undefined') { var stats = Nodes.updateLatency(data.id, data.latency); @@ -126,9 +123,6 @@ client.on('connection', function(spark) { console.log(spark.query); spark.on('ready', function(data){ - console.log('got hello data from ' + spark.id); - console.log(data); - spark.emit('init', {nodes: Nodes.all()}); var blockPropagationChart = Nodes.blockPropagationChart(); diff --git a/models/history.js b/models/history.js index 4b052f6..38ae779 100644 --- a/models/history.js +++ b/models/history.js @@ -70,7 +70,6 @@ History.prototype.add = function(block, id) } item.propagTimes.push({node: id, received: now, propagation: block.propagation}); - console.log('item: ', item); this._save(item); } this.getNodePropagation(id); @@ -187,6 +186,30 @@ History.prototype.getUncleCount = function(id) return uncleBins; } +History.prototype.getTransactionsCount = function(id) +{ + var uncles = _(this._items) + .sortByOrder('height', false) + .slice(0, MAX_BINS - 1) + .reverse() + .map(function(item) + { + return item.block.transactions.length; + }) + .value(); + + var uncleBins = _.fill(Array(MAX_BINS), 0); + + var sumMapper = function(array, key) { + uncleBins[key] = _.sum(array); + return _.sum(array); + }; + + _.map(_.chunk(uncles, MAX_UNCLES_PER_BIN), sumMapper); + + return uncleBins; +} + History.prototype.history = function() { return _.chain(this._items).sortBy('number').reverse().value(); From ad1913d63a0c054d4fc5fa6f12bc5ddb09b8d861 Mon Sep 17 00:00:00 2001 From: cubedro Date: Tue, 28 Apr 2015 03:53:41 +0300 Subject: [PATCH 4/4] version 0.0.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 43878ab..ef7819b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "eth-netstats", "description": "Ethereum Network Intelligence dashboard", - "version": "0.0.3", + "version": "0.0.4", "private": true, "engines": { "node": "0.12.0",