added best block check before requesting history
This commit is contained in:
@@ -139,9 +139,19 @@ Collection.prototype.getHistory = function()
|
||||
Collection.prototype.canNodeUpdate = function(id)
|
||||
{
|
||||
var node = this.getNode({id: id});
|
||||
|
||||
if(!node)
|
||||
return false;
|
||||
return node.canUpdate();
|
||||
|
||||
if(node.canUpdate())
|
||||
{
|
||||
var diff = this._history.bestBlockNumber() - node.getBlockNumber();
|
||||
|
||||
if(diff <= 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
module.exports = Collection;
|
||||
@@ -128,11 +128,21 @@ History.prototype.prevMaxBlock = function(number)
|
||||
return this._items[index];
|
||||
}
|
||||
|
||||
History.prototype.bestBlock = function(obj)
|
||||
History.prototype.bestBlock = function()
|
||||
{
|
||||
return _.max(this._items, 'height');
|
||||
}
|
||||
|
||||
History.prototype.bestBlockNumber = function()
|
||||
{
|
||||
var best = this.bestBlock();
|
||||
|
||||
if(typeof best.height !== 'undefined')
|
||||
return best.height;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
History.prototype.getNodePropagation = function(id)
|
||||
{
|
||||
var propagation = new Array(MAX_PEER_PROPAGATION);
|
||||
|
||||
@@ -150,6 +150,11 @@ Node.prototype.setState = function(active)
|
||||
this.uptime.history.push({status: (active ? 'up' : 'down'), time: (new Date()).getTime()});
|
||||
}
|
||||
|
||||
Node.prototype.getBlockNumber = function()
|
||||
{
|
||||
return this.stats.block.number;
|
||||
}
|
||||
|
||||
Node.prototype.canUpdate = function()
|
||||
{
|
||||
return this.info.canUpdateHistory || false;
|
||||
|
||||
Reference in New Issue
Block a user