delete old blocks from cache

This commit is contained in:
Manuel Araoz 2015-04-09 19:42:15 -03:00
parent 12d5c1cffd
commit 16194e5b3f

View File

@ -68,6 +68,7 @@ var BitcoreNode = function(bus, networkMonitor, blockService, transactionService
if (block.height % 100 === 0) { if (block.height % 100 === 0) {
console.log('block', block.id, 'height', block.height); console.log('block', block.id, 'height', block.height);
console.log('cache size', Object.keys(self.blockCache).length);
} }
return Promise.each(blockchainChanges.unconfirmed, function(hash) { return Promise.each(blockchainChanges.unconfirmed, function(hash) {
@ -78,6 +79,13 @@ var BitcoreNode = function(bus, networkMonitor, blockService, transactionService
return self.blockService.confirm(self.blockCache[hash]); return self.blockService.confirm(self.blockCache[hash]);
})); }));
}) })
.then(function() {
var deleteHeight = block.height - 100;
if (deleteHeight > 0) {
var deleteHash = self.blockchain.hashByHeight[deleteHeight];
delete self.blockCache[deleteHash];
}
})
.then(function() { .then(function() {
// TODO: include this // TODO: include this
if (false && _.size(self.inventory) && _.all(_.values(self.inventory))) { if (false && _.size(self.inventory) && _.all(_.values(self.inventory))) {
@ -86,7 +94,7 @@ var BitcoreNode = function(bus, networkMonitor, blockService, transactionService
} }
}) })
.catch(function(error) { .catch(function(error) {
self.abort(error); self.stop(error);
}); });
}); });
@ -154,7 +162,7 @@ BitcoreNode.prototype.start = function() {
}; };
BitcoreNode.prototype.stop = function(reason) { BitcoreNode.prototype.stop = function(reason) {
this.networkMonitor.stop(reason); this.networkMonitor.abort(reason);
}; };
BitcoreNode.prototype.requestFromTip = function() { BitcoreNode.prototype.requestFromTip = function() {