diff --git a/lib/bcoin/peer.js b/lib/bcoin/peer.js index 3b0f7b43..4f0f602a 100644 --- a/lib/bcoin/peer.js +++ b/lib/bcoin/peer.js @@ -537,6 +537,8 @@ Peer.prototype._handleGetAddr = function handleGetAddr() { Peer.prototype._handleInv = function handleInv(items) { var req, i, block, hash; + this.emit('inv', items); + // Always request advertised TXs var txs = items.filter(function(item) { return item.type === 'tx'; diff --git a/lib/bcoin/pool.js b/lib/bcoin/pool.js index 46b3f369..7b82783e 100644 --- a/lib/bcoin/pool.js +++ b/lib/bcoin/pool.js @@ -133,6 +133,11 @@ function Pool(options) { invalid: {} }; + this.tx = { + have: {}, + count: 0 + }; + this.request = { map: {}, active: 0, @@ -341,11 +346,9 @@ Pool.prototype._addLoader = function _addLoader() { return; if (!this.options.headers && !this.options.multiplePeers) { - this.request = { - map: {}, - active: 0, - queue: [] - }; + this.request.map = {}; + this.request.active = 0; + this.request.queue = []; } peer = this._createPeer(750 * Math.random(), true); @@ -833,8 +836,17 @@ Pool.prototype._createPeer = function _createPeer(backoff, priority) { peer.on('txs', function(txs) { self.emit('txs', txs, peer); txs.forEach(function(hash) { + hash = utils.toHex(hash); + if (self.tx.have[hash]) + return; + self.tx.have[hash] = true; + self.tx.count++; self._request('tx', hash, peer); }); + if (self.tx.count > 10000) { + self.tx.have = {}; + self.tx.count = 0; + } self._scheduleRequests(); });