diff --git a/lib/node.js b/lib/node.js index ac644419..eee7c8ac 100644 --- a/lib/node.js +++ b/lib/node.js @@ -68,6 +68,7 @@ var BitcoreNode = function(bus, networkMonitor, blockService, transactionService if (block.height % 100 === 0) { console.log('block', block.id, 'height', block.height); + console.log('cache size', Object.keys(self.blockCache).length); } 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]); })); }) + .then(function() { + var deleteHeight = block.height - 100; + if (deleteHeight > 0) { + var deleteHash = self.blockchain.hashByHeight[deleteHeight]; + delete self.blockCache[deleteHash]; + } + }) .then(function() { // TODO: include this if (false && _.size(self.inventory) && _.all(_.values(self.inventory))) { @@ -86,7 +94,7 @@ var BitcoreNode = function(bus, networkMonitor, blockService, transactionService } }) .catch(function(error) { - self.abort(error); + self.stop(error); }); }); @@ -154,7 +162,7 @@ BitcoreNode.prototype.start = function() { }; BitcoreNode.prototype.stop = function(reason) { - this.networkMonitor.stop(reason); + this.networkMonitor.abort(reason); }; BitcoreNode.prototype.requestFromTip = function() {