Merge pull request #186 from cubedro/develop
Added clean blocks higher than best block
This commit is contained in:
commit
05a23d1f3e
2
dist/js/netstats.min.js
vendored
2
dist/js/netstats.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/js/netstats.min.js.map
vendored
2
dist/js/netstats.min.js.map
vendored
File diff suppressed because one or more lines are too long
@ -28,6 +28,8 @@ Collection.prototype.update = function(id, stats, callback)
|
||||
}
|
||||
else
|
||||
{
|
||||
this._blockchain.clean(this.getBestBlockFromItems());
|
||||
|
||||
var block = this._blockchain.add(stats.block, id);
|
||||
|
||||
if (!block)
|
||||
@ -57,6 +59,8 @@ Collection.prototype.addBlock = function(id, stats, callback)
|
||||
}
|
||||
else
|
||||
{
|
||||
this._blockchain.clean(this.getBestBlockFromItems());
|
||||
|
||||
var block = this._blockchain.add(stats, id);
|
||||
|
||||
if (!block)
|
||||
@ -113,6 +117,8 @@ Collection.prototype.addHistory = function(id, blocks, callback)
|
||||
{
|
||||
blocks = blocks.reverse();
|
||||
|
||||
this._blockchain.clean(this.getBestBlockFromItems());
|
||||
|
||||
for (var i = 0; i <= blocks.length - 1; i++)
|
||||
{
|
||||
this._blockchain.add(blocks[i], id);
|
||||
@ -254,6 +260,13 @@ Collection.prototype.getHistory = function()
|
||||
return this._blockchain;
|
||||
}
|
||||
|
||||
Collection.prototype.getBestBlockFromItems = function()
|
||||
{
|
||||
return _.result(_.max(this._items, function(item) {
|
||||
return item.stats.block.number;
|
||||
}), 'stats.block.number', 0);
|
||||
}
|
||||
|
||||
Collection.prototype.canNodeUpdate = function(id)
|
||||
{
|
||||
var node = this.getNode({id: id});
|
||||
|
@ -126,20 +126,6 @@ History.prototype.add = function(block, id)
|
||||
|
||||
this._save(item);
|
||||
|
||||
changed = true;
|
||||
}
|
||||
else if(this._items.length > 0 && block.arrived - this.bestBlock().arrived > 10*60*1000)
|
||||
{
|
||||
this._items.splice(0,1);
|
||||
|
||||
item.propagTimes.push({
|
||||
node: id,
|
||||
received: now,
|
||||
propagation: block.propagation
|
||||
});
|
||||
|
||||
this._save(item);
|
||||
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
@ -165,6 +151,22 @@ History.prototype._save = function(block)
|
||||
}
|
||||
}
|
||||
|
||||
History.prototype.clean = function(max)
|
||||
{
|
||||
if(max > 0 && this._items.length > 0 && max < this.bestBlockNumber())
|
||||
{
|
||||
console.log("MAX:", max);
|
||||
|
||||
console.log("History items before:", this._items.length);
|
||||
|
||||
this._items = _(this._items).filter(function(item) {
|
||||
return item.height <= max;
|
||||
}).value();
|
||||
|
||||
console.log("History items after:", this._items.length);
|
||||
}
|
||||
}
|
||||
|
||||
History.prototype.search = function(number)
|
||||
{
|
||||
var index = _.findIndex( this._items, { height: number } );
|
||||
|
@ -485,7 +485,7 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, $localStorage, soc
|
||||
return parseInt(node.stats.block.number);
|
||||
}).stats.block.number;
|
||||
|
||||
if( bestBlock > $scope.bestBlock )
|
||||
if( bestBlock !== $scope.bestBlock )
|
||||
{
|
||||
$scope.bestBlock = bestBlock;
|
||||
$scope.bestStats = _.max($scope.nodes, function (node) {
|
||||
|
Loading…
Reference in New Issue
Block a user