pool: do not request duplicate txs.
This commit is contained in:
parent
e3c0b123a0
commit
c12a0630aa
@ -1469,22 +1469,10 @@ Pool.prototype.handleBlockInv = co(function* handleBlockInv(peer, hashes) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Pool.prototype.handleTXInv = co(function* handleTXInv(peer, hashes) {
|
Pool.prototype.handleTXInv = co(function* handleTXInv(peer, hashes) {
|
||||||
var items = [];
|
|
||||||
var i, hash;
|
|
||||||
|
|
||||||
if (this.syncing && !this.chain.synced)
|
if (this.syncing && !this.chain.synced)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (i = 0; i < hashes.length; i++) {
|
this.ensureTX(peer, hashes);
|
||||||
hash = hashes[i];
|
|
||||||
|
|
||||||
if (this.hasTX(hash))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
items.push(hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.getTX(peer, items);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2184,7 +2172,7 @@ Pool.prototype._handleTX = co(function* handleTX(peer, packet) {
|
|||||||
'Requesting %d missing transactions (%s).',
|
'Requesting %d missing transactions (%s).',
|
||||||
missing.length, peer.hostname());
|
missing.length, peer.hostname());
|
||||||
|
|
||||||
this.getTX(peer, missing);
|
this.ensureTX(peer, missing);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -3128,6 +3116,29 @@ Pool.prototype.hasTX = function hasTX(hash) {
|
|||||||
return false;
|
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.
|
* Fulfill a requested item.
|
||||||
* @param {Peer} peer
|
* @param {Peer} peer
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user