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) {
|
} catch (e) {
|
||||||
this.emit('error', e);
|
this.emit('error', e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.scheduleRequests(peer);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.emit('tx', tx, peer);
|
this.emit('tx', tx, peer);
|
||||||
@ -1410,6 +1412,8 @@ Pool.prototype.handleTXInv = function handleTXInv(hashes, peer) {
|
|||||||
this.emit('error', e);
|
this.emit('error', e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.scheduleRequests(peer);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1812,7 +1816,7 @@ Pool.prototype.hasBlock = co(function* hasBlock(hash) {
|
|||||||
* in the mempool before requesting.
|
* in the mempool before requesting.
|
||||||
* @param {Peer} peer
|
* @param {Peer} peer
|
||||||
* @param {Hash} hash - TX hash.
|
* @param {Hash} hash - TX hash.
|
||||||
* @returns {Promise}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Pool.prototype.getTX = function getTX(peer, hash) {
|
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);
|
item = new LoadRequest(this, peer, invTypes.TX, hash);
|
||||||
|
|
||||||
if (peer.queueTX.size === 0) {
|
peer.queueTX.push(item);
|
||||||
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());
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
@ -1886,6 +1878,7 @@ Pool.prototype.hasTX = function hasTX(hash) {
|
|||||||
/**
|
/**
|
||||||
* Schedule next batch of `getdata` requests for peer.
|
* Schedule next batch of `getdata` requests for peer.
|
||||||
* @param {Peer} peer
|
* @param {Peer} peer
|
||||||
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Pool.prototype.scheduleRequests = co(function* scheduleRequests(peer) {
|
Pool.prototype.scheduleRequests = co(function* scheduleRequests(peer) {
|
||||||
@ -1896,7 +1889,9 @@ Pool.prototype.scheduleRequests = co(function* scheduleRequests(peer) {
|
|||||||
|
|
||||||
yield this.chain.onDrain();
|
yield this.chain.onDrain();
|
||||||
|
|
||||||
this.sendRequests(peer);
|
this.sendBlockRequests(peer);
|
||||||
|
this.sendTXRequests(peer);
|
||||||
|
|
||||||
this.scheduled = false;
|
this.scheduled = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1906,7 +1901,7 @@ Pool.prototype.scheduleRequests = co(function* scheduleRequests(peer) {
|
|||||||
* @param {Peer} peer
|
* @param {Peer} peer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Pool.prototype.sendRequests = function sendRequests(peer) {
|
Pool.prototype.sendBlockRequests = function sendBlockRequests(peer) {
|
||||||
var i, size, items, item;
|
var i, size, items, item;
|
||||||
|
|
||||||
if (peer.queueBlock.size === 0)
|
if (peer.queueBlock.size === 0)
|
||||||
@ -1940,6 +1935,33 @@ Pool.prototype.sendRequests = function sendRequests(peer) {
|
|||||||
peer.getData(items);
|
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.
|
* Fulfill a requested block.
|
||||||
* @param {Hash}
|
* @param {Hash}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user