pool._addTX to prevent duplicate requests.

This commit is contained in:
Christopher Jeffrey 2016-01-29 14:51:36 -08:00
parent 7ce5348cd9
commit e880dc5a5c

View File

@ -820,6 +820,8 @@ Pool.prototype._createPeer = function _createPeer(backoff, priority) {
else
utils.debug('Received unrequested TX: %s', tx.rhash);
self._addTX(tx);
self.emit('tx', tx, peer);
if (!self.options.fullNode && tx.block)
@ -839,16 +841,9 @@ Pool.prototype._createPeer = function _createPeer(backoff, priority) {
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._addTX(hash))
self._request('tx', hash, peer);
});
if (self.tx.count > 10000) {
self.tx.have = {};
self.tx.count = 0;
}
self._scheduleRequests();
});
@ -941,6 +936,26 @@ Pool.prototype._addPeer = function _addPeer(backoff) {
});
};
Pool.prototype._addTX = function(hash) {
if (utils.isBuffer(hash))
hash = utils.toHex(hash);
else if (hash.hash)
hash = hash.hash('hex');
if (this.tx.count >= 10000) {
this.tx.have = {};
this.tx.count = 0;
}
if (!this.tx.have[hash]) {
this.tx.have[hash] = true;
this.tx.count++;
return true;
}
return false;
};
Pool.prototype.bestPeer = function bestPeer() {
return this.peers.block.reduce(function(best, peer) {
if (!peer.version || !peer.socket)