added fetch skipped blocks
This commit is contained in:
parent
1268561567
commit
ebfa5f18de
69
lib/node.js
69
lib/node.js
@ -93,6 +93,7 @@ function Node ()
|
|||||||
uptime: 0
|
uptime: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this._lastBlock = 0;
|
||||||
this._lastStats = JSON.stringify(this.stats);
|
this._lastStats = JSON.stringify(this.stats);
|
||||||
this._lastFetch = 0;
|
this._lastFetch = 0;
|
||||||
this._startBlockFetch = 0;
|
this._startBlockFetch = 0;
|
||||||
@ -278,7 +279,7 @@ Node.prototype.emit = function(message, payload)
|
|||||||
try {
|
try {
|
||||||
socket.emit(message, payload);
|
socket.emit(message, payload);
|
||||||
console.success('wsc', 'Socket emited message:', chalk.reset.cyan(message));
|
console.success('wsc', 'Socket emited message:', chalk.reset.cyan(message));
|
||||||
console.success('wsc', payload);
|
// console.success('wsc', payload);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.error('wsc', 'Socket emit error:', err);
|
console.error('wsc', 'Socket emit error:', err);
|
||||||
@ -336,6 +337,10 @@ Node.prototype.formatBlock = function (block)
|
|||||||
block.difficulty = block.difficulty.toString(10);
|
block.difficulty = block.difficulty.toString(10);
|
||||||
block.totalDifficulty = block.totalDifficulty.toString(10);
|
block.totalDifficulty = block.totalDifficulty.toString(10);
|
||||||
|
|
||||||
|
if( !_.isUndefined(block.logsBloom) ) {
|
||||||
|
delete block.logsBloom;
|
||||||
|
}
|
||||||
|
|
||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,6 +357,7 @@ Node.prototype.getLatestBlock = function ()
|
|||||||
if(this._web3)
|
if(this._web3)
|
||||||
{
|
{
|
||||||
this._startBlockFetch = _.now();
|
this._startBlockFetch = _.now();
|
||||||
|
|
||||||
web3.eth.getBlock('latest', false, function(error, result) {
|
web3.eth.getBlock('latest', false, function(error, result) {
|
||||||
self.validateLatestBlock(error, result);
|
self.validateLatestBlock(error, result);
|
||||||
});
|
});
|
||||||
@ -360,32 +366,45 @@ Node.prototype.getLatestBlock = function ()
|
|||||||
|
|
||||||
Node.prototype.validateLatestBlock = function (error, result)
|
Node.prototype.validateLatestBlock = function (error, result)
|
||||||
{
|
{
|
||||||
if( !error )
|
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
|
|
||||||
{
|
{
|
||||||
console.error("xx>", "getLatestBlock couldn't fetch block...");
|
console.error("xx>", "getLatestBlock couldn't fetch block...");
|
||||||
console.error("xx>", error);
|
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');
|
console.time('=H=', 'his', 'Got history in');
|
||||||
|
|
||||||
if ( _.isUndefined(range) || range === null)
|
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))
|
if (!_.isUndefined(range.list))
|
||||||
interv = range.list;
|
interv = range.list;
|
||||||
|
Loading…
Reference in New Issue
Block a user