do not request duplicate txs.

This commit is contained in:
Christopher Jeffrey 2016-01-29 14:44:43 -08:00
parent b4abeceac3
commit 32c0f8ce3c
2 changed files with 19 additions and 5 deletions

View File

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

View File

@ -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();
});