do not request duplicate txs.
This commit is contained in:
parent
b4abeceac3
commit
32c0f8ce3c
@ -537,6 +537,8 @@ Peer.prototype._handleGetAddr = function handleGetAddr() {
|
|||||||
Peer.prototype._handleInv = function handleInv(items) {
|
Peer.prototype._handleInv = function handleInv(items) {
|
||||||
var req, i, block, hash;
|
var req, i, block, hash;
|
||||||
|
|
||||||
|
this.emit('inv', items);
|
||||||
|
|
||||||
// Always request advertised TXs
|
// Always request advertised TXs
|
||||||
var txs = items.filter(function(item) {
|
var txs = items.filter(function(item) {
|
||||||
return item.type === 'tx';
|
return item.type === 'tx';
|
||||||
|
|||||||
@ -133,6 +133,11 @@ function Pool(options) {
|
|||||||
invalid: {}
|
invalid: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.tx = {
|
||||||
|
have: {},
|
||||||
|
count: 0
|
||||||
|
};
|
||||||
|
|
||||||
this.request = {
|
this.request = {
|
||||||
map: {},
|
map: {},
|
||||||
active: 0,
|
active: 0,
|
||||||
@ -341,11 +346,9 @@ Pool.prototype._addLoader = function _addLoader() {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (!this.options.headers && !this.options.multiplePeers) {
|
if (!this.options.headers && !this.options.multiplePeers) {
|
||||||
this.request = {
|
this.request.map = {};
|
||||||
map: {},
|
this.request.active = 0;
|
||||||
active: 0,
|
this.request.queue = [];
|
||||||
queue: []
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
peer = this._createPeer(750 * Math.random(), true);
|
peer = this._createPeer(750 * Math.random(), true);
|
||||||
@ -833,8 +836,17 @@ Pool.prototype._createPeer = function _createPeer(backoff, priority) {
|
|||||||
peer.on('txs', function(txs) {
|
peer.on('txs', function(txs) {
|
||||||
self.emit('txs', txs, peer);
|
self.emit('txs', txs, peer);
|
||||||
txs.forEach(function(hash) {
|
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);
|
self._request('tx', hash, peer);
|
||||||
});
|
});
|
||||||
|
if (self.tx.count > 10000) {
|
||||||
|
self.tx.have = {};
|
||||||
|
self.tx.count = 0;
|
||||||
|
}
|
||||||
self._scheduleRequests();
|
self._scheduleRequests();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user