pool: schedule txs like blocks.
This commit is contained in:
parent
8b8a65868b
commit
5a0632f449
@ -1192,6 +1192,8 @@ Pool.prototype.handleTX = co(function* handleTX(tx, peer) {
|
||||
} catch (e) {
|
||||
this.emit('error', e);
|
||||
}
|
||||
|
||||
this.scheduleRequests(peer);
|
||||
}
|
||||
|
||||
this.emit('tx', tx, peer);
|
||||
@ -1410,6 +1412,8 @@ Pool.prototype.handleTXInv = function handleTXInv(hashes, peer) {
|
||||
this.emit('error', e);
|
||||
}
|
||||
}
|
||||
|
||||
this.scheduleRequests(peer);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1812,7 +1816,7 @@ Pool.prototype.hasBlock = co(function* hasBlock(hash) {
|
||||
* in the mempool before requesting.
|
||||
* @param {Peer} peer
|
||||
* @param {Hash} hash - TX hash.
|
||||
* @returns {Promise}
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
Pool.prototype.getTX = function getTX(peer, hash) {
|
||||
@ -1833,19 +1837,7 @@ Pool.prototype.getTX = function getTX(peer, hash) {
|
||||
|
||||
item = new LoadRequest(this, peer, invTypes.TX, hash);
|
||||
|
||||
if (peer.queueTX.size === 0) {
|
||||
util.nextTick(function() {
|
||||
self.logger.debug(
|
||||
'Requesting %d/%d txs from peer with getdata (%s).',
|
||||
peer.queueTX.size,
|
||||
self.activeTX,
|
||||
peer.hostname);
|
||||
|
||||
peer.getData(peer.queueTX.slice());
|
||||
});
|
||||
}
|
||||
|
||||
peer.queueTX.push(item.start());
|
||||
peer.queueTX.push(item);
|
||||
|
||||
return false;
|
||||
};
|
||||
@ -1886,6 +1878,7 @@ Pool.prototype.hasTX = function hasTX(hash) {
|
||||
/**
|
||||
* Schedule next batch of `getdata` requests for peer.
|
||||
* @param {Peer} peer
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
Pool.prototype.scheduleRequests = co(function* scheduleRequests(peer) {
|
||||
@ -1896,7 +1889,9 @@ Pool.prototype.scheduleRequests = co(function* scheduleRequests(peer) {
|
||||
|
||||
yield this.chain.onDrain();
|
||||
|
||||
this.sendRequests(peer);
|
||||
this.sendBlockRequests(peer);
|
||||
this.sendTXRequests(peer);
|
||||
|
||||
this.scheduled = false;
|
||||
});
|
||||
|
||||
@ -1906,7 +1901,7 @@ Pool.prototype.scheduleRequests = co(function* scheduleRequests(peer) {
|
||||
* @param {Peer} peer
|
||||
*/
|
||||
|
||||
Pool.prototype.sendRequests = function sendRequests(peer) {
|
||||
Pool.prototype.sendBlockRequests = function sendBlockRequests(peer) {
|
||||
var i, size, items, item;
|
||||
|
||||
if (peer.queueBlock.size === 0)
|
||||
@ -1940,6 +1935,33 @@ Pool.prototype.sendRequests = function sendRequests(peer) {
|
||||
peer.getData(items);
|
||||
};
|
||||
|
||||
/**
|
||||
* Schedule next batch of `getdata` tx requests for peer.
|
||||
* @param {Peer} peer
|
||||
* @returns {Promise}
|
||||
*/
|
||||
|
||||
Pool.prototype.sendTXRequests = function sendTXRequests(peer) {
|
||||
var size = peer.queueTX.size;
|
||||
var i, items, item;
|
||||
|
||||
if (size === 0)
|
||||
return;
|
||||
|
||||
items = peer.queueTX.slice(size);
|
||||
|
||||
for (i = 0; i < items.length; i++) {
|
||||
item = items[i];
|
||||
item.start();
|
||||
}
|
||||
|
||||
this.logger.debug(
|
||||
'Requesting %d/%d txs from peer with getdata (%s).',
|
||||
size, this.activeTX, peer.hostname);
|
||||
|
||||
peer.getData(items);
|
||||
};
|
||||
|
||||
/**
|
||||
* Fulfill a requested block.
|
||||
* @param {Hash}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user