From ebfa5f18de74778ad55799c69f80883c6e6e3a7e Mon Sep 17 00:00:00 2001 From: cubedro Date: Wed, 27 May 2015 12:19:02 +0300 Subject: [PATCH 1/2] added fetch skipped blocks --- lib/node.js | 69 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/lib/node.js b/lib/node.js index 6133112..74129d1 100644 --- a/lib/node.js +++ b/lib/node.js @@ -93,6 +93,7 @@ function Node () uptime: 0 }; + this._lastBlock = 0; this._lastStats = JSON.stringify(this.stats); this._lastFetch = 0; this._startBlockFetch = 0; @@ -278,7 +279,7 @@ Node.prototype.emit = function(message, payload) try { socket.emit(message, payload); console.success('wsc', 'Socket emited message:', chalk.reset.cyan(message)); - console.success('wsc', payload); + // console.success('wsc', payload); } catch (err) { console.error('wsc', 'Socket emit error:', err); @@ -336,6 +337,10 @@ Node.prototype.formatBlock = function (block) block.difficulty = block.difficulty.toString(10); block.totalDifficulty = block.totalDifficulty.toString(10); + if( !_.isUndefined(block.logsBloom) ) { + delete block.logsBloom; + } + return block; } @@ -352,6 +357,7 @@ Node.prototype.getLatestBlock = function () if(this._web3) { this._startBlockFetch = _.now(); + web3.eth.getBlock('latest', false, function(error, result) { self.validateLatestBlock(error, result); }); @@ -360,32 +366,45 @@ Node.prototype.getLatestBlock = function () Node.prototype.validateLatestBlock = function (error, result) { - if( !error ) - { - var block = this.formatBlock(result); - - if(block !== false) - { - if( this.stats.block.number !== block.number ) - { - this.stats.block = block; - console.success("==>", "Got block:", chalk.reset.cyan(block.number), 'in', chalk.reset.cyan(_.now() - this._startBlockFetch, 'ms')); - this.sendUpdate(); - } - else - { - console.warn("==>", "Got same block:", chalk.reset.cyan(block.number), 'in', chalk.reset.cyan(_.now() - this._startBlockFetch, 'ms')); - } - } - else - { - console.error("xx>", "Got bad block:", chalk.reset.cyan(result), 'in', chalk.reset.cyan(_.now() - this._startBlockFetch, 'ms')); - } - } - else + if( error ) { console.error("xx>", "getLatestBlock couldn't fetch block..."); console.error("xx>", error); + + return false; + } + + var block = this.formatBlock(result); + + if(block === false) + { + console.error("xx>", "Got bad block:", chalk.reset.cyan(result), 'in', chalk.reset.cyan(_.now() - this._startBlockFetch, 'ms')); + + return false; + } + + if( this.stats.block.number === block.number ) + { + console.warn("==>", "Got same block:", chalk.reset.cyan(block.number), 'in', chalk.reset.cyan(_.now() - this._startBlockFetch, 'ms')); + + return false; + } + + + this.stats.block = block; + console.success("==>", "Got block:", chalk.reset.red(block.number), 'in', chalk.reset.cyan(_.now() - this._startBlockFetch, 'ms')); + this.sendUpdate(); + + if(this.stats.block.number - this._lastBlock > 1) + { + var range = _.range( Math.max(this.stats.block.number - MAX_BLOCKS_HISTORY, this._lastBlock + 1), Math.max(this.stats.block.number, 0), 1 ); + + this.getHistory({ list: range }); + } + + if(this.stats.block.number > this._lastBlock) + { + this._lastBlock = this.stats.block.number; } } @@ -474,7 +493,7 @@ Node.prototype.getHistory = function (range) console.time('=H=', 'his', 'Got history in'); if ( _.isUndefined(range) || range === null) - interv = _.range(this.stats.block.number - 1, MAX_HISTORY_UPDATE); + interv = _.range(this.stats.block.number - 1, this.stats.block.number - MAX_HISTORY_UPDATE); if (!_.isUndefined(range.list)) interv = range.list; From 6fd4a908a6900eacc7b05a8568a21e1966ad6639 Mon Sep 17 00:00:00 2001 From: cubedro Date: Wed, 27 May 2015 12:20:44 +0300 Subject: [PATCH 2/2] version 0.0.10 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 73989cc..0636e25 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "eth-net-intelligence-api", "description": "Ethereum Network Intelligence API", - "version": "0.0.9", + "version": "0.0.10", "private": true, "main": "./app.js", "directories": {