From c12a0630aa16f6972c3906e6df83a6d76fd69c01 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 8 Feb 2017 14:40:55 -0800 Subject: [PATCH] pool: do not request duplicate txs. --- lib/net/pool.js | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/lib/net/pool.js b/lib/net/pool.js index c69ef6ad..00a10f4c 100644 --- a/lib/net/pool.js +++ b/lib/net/pool.js @@ -1469,22 +1469,10 @@ Pool.prototype.handleBlockInv = co(function* handleBlockInv(peer, hashes) { */ Pool.prototype.handleTXInv = co(function* handleTXInv(peer, hashes) { - var items = []; - var i, hash; - if (this.syncing && !this.chain.synced) return; - for (i = 0; i < hashes.length; i++) { - hash = hashes[i]; - - if (this.hasTX(hash)) - continue; - - items.push(hash); - } - - this.getTX(peer, items); + this.ensureTX(peer, hashes); }); /** @@ -2184,7 +2172,7 @@ Pool.prototype._handleTX = co(function* handleTX(peer, packet) { 'Requesting %d missing transactions (%s).', missing.length, peer.hostname()); - this.getTX(peer, missing); + this.ensureTX(peer, missing); } }); @@ -3128,6 +3116,29 @@ Pool.prototype.hasTX = function hasTX(hash) { return false; }; +/** + * Queue a `getdata` request to be sent. + * Check tx existence before requesting. + * @param {Peer} peer + * @param {Hash[]} hashes + */ + +Pool.prototype.ensureTX = function ensureTX(peer, hashes) { + var items = []; + var i, hash; + + for (i = 0; i < hashes.length; i++) { + hash = hashes[i]; + + if (this.hasTX(hash)) + continue; + + items.push(hash); + } + + this.getTX(peer, items); +}; + /** * Fulfill a requested item. * @param {Peer} peer