pool: do not request duplicate txs.

This commit is contained in:
Christopher Jeffrey 2017-02-08 14:40:55 -08:00
parent e3c0b123a0
commit c12a0630aa
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -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