pool._addTX to prevent duplicate requests.
This commit is contained in:
parent
7ce5348cd9
commit
e880dc5a5c
@ -820,6 +820,8 @@ Pool.prototype._createPeer = function _createPeer(backoff, priority) {
|
|||||||
else
|
else
|
||||||
utils.debug('Received unrequested TX: %s', tx.rhash);
|
utils.debug('Received unrequested TX: %s', tx.rhash);
|
||||||
|
|
||||||
|
self._addTX(tx);
|
||||||
|
|
||||||
self.emit('tx', tx, peer);
|
self.emit('tx', tx, peer);
|
||||||
|
|
||||||
if (!self.options.fullNode && tx.block)
|
if (!self.options.fullNode && tx.block)
|
||||||
@ -839,16 +841,9 @@ Pool.prototype._createPeer = function _createPeer(backoff, priority) {
|
|||||||
self.emit('txs', txs, peer);
|
self.emit('txs', txs, peer);
|
||||||
txs.forEach(function(hash) {
|
txs.forEach(function(hash) {
|
||||||
hash = utils.toHex(hash);
|
hash = utils.toHex(hash);
|
||||||
if (self.tx.have[hash])
|
if (self._addTX(hash))
|
||||||
return;
|
self._request('tx', hash, peer);
|
||||||
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();
|
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() {
|
Pool.prototype.bestPeer = function bestPeer() {
|
||||||
return this.peers.block.reduce(function(best, peer) {
|
return this.peers.block.reduce(function(best, peer) {
|
||||||
if (!peer.version || !peer.socket)
|
if (!peer.version || !peer.socket)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user