diff --git a/lib/services/bitcoind.js b/lib/services/bitcoind.js index 216c72ae..c9dbf4e8 100644 --- a/lib/services/bitcoind.js +++ b/lib/services/bitcoind.js @@ -70,6 +70,7 @@ Bitcoin.prototype._initCaches = function() { this.rawBlockCache = LRU(72); this.blockHeaderCache = LRU(288); this.zmqKnownTransactions = LRU(50); + this.zmqKnownBlocks = LRU(50); this.zmqLastBlock = 0; this.zmqUpdateTipTimeout = false; }; @@ -322,7 +323,7 @@ Bitcoin.prototype._zmqBlockHandler = function(node, message) { } } - // Prevent a rapid succession of updates + // Prevent a rapid succession of tip updates if (new Date() - self.zmqLastBlock > 1000) { self.zmqLastBlock = new Date(); updateChain(); @@ -334,8 +335,15 @@ Bitcoin.prototype._zmqBlockHandler = function(node, message) { } // Notify block subscribers - for (var i = 0; i < this.subscriptions.block.length; i++) { - this.subscriptions.block[i].emit('bitcoind/block', message.toString('hex')); + var id = message.toString('binary'); + if (!self.zmqKnownBlocks[id]) { + self.zmqKnownBlocks[id] = true; + self.emit('block', message); + + for (var i = 0; i < this.subscriptions.block.length; i++) { + this.subscriptions.block[i].emit('bitcoind/block', message.toString('hex')); + } + } };