pool: fix inv. do not hold lock for bip151 msgs.
This commit is contained in:
parent
cdcdb7bd52
commit
f0f9f798c5
@ -669,7 +669,7 @@ Peer.prototype.announceBlock = function announceBlock(blocks) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.sendInv(inv);
|
||||
this.queueInv(inv);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -722,7 +722,7 @@ Peer.prototype.announceTX = function announceTX(txs) {
|
||||
inv.push(tx.toInv());
|
||||
}
|
||||
|
||||
this.sendInv(inv);
|
||||
this.queueInv(inv);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -730,7 +730,7 @@ Peer.prototype.announceTX = function announceTX(txs) {
|
||||
* @param {InvItem[]} items
|
||||
*/
|
||||
|
||||
Peer.prototype.sendInv = function sendInv(items) {
|
||||
Peer.prototype.queueInv = function queueInv(items) {
|
||||
var hasBlock = false;
|
||||
var i, item;
|
||||
|
||||
@ -792,11 +792,30 @@ Peer.prototype.flushInv = function flushInv() {
|
||||
* @param {InvItem[]} items
|
||||
*/
|
||||
|
||||
Peer.prototype.forceInv = function forceInv(items) {
|
||||
Peer.prototype.sendInv = function sendInv(items) {
|
||||
var i, item, chunk;
|
||||
|
||||
if (!this.handshake)
|
||||
return;
|
||||
|
||||
if (this.destroyed)
|
||||
return;
|
||||
|
||||
if (!Array.isArray(items))
|
||||
items = [items];
|
||||
|
||||
this.send(new packets.InvPacket(items));
|
||||
for (i = 0; i < items.length; i++) {
|
||||
item = items[i];
|
||||
this.invFilter.add(item.hash, 'hex');
|
||||
}
|
||||
|
||||
if (items.length === 0)
|
||||
return;
|
||||
|
||||
for (i = 0; i < items.length; i += 1000) {
|
||||
chunk = items.slice(i, i + 1000);
|
||||
this.send(new packets.InvPacket(chunk));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1378,13 +1397,22 @@ Peer.prototype.getTX = function getTX(hashes) {
|
||||
*/
|
||||
|
||||
Peer.prototype.readPacket = co(function* readPacket(packet) {
|
||||
var unlock = yield this.locker.lock();
|
||||
try {
|
||||
this.socket.pause();
|
||||
return yield this.handlePacket(packet);
|
||||
} finally {
|
||||
this.socket.resume();
|
||||
unlock();
|
||||
var unlock;
|
||||
|
||||
switch (packet.type) {
|
||||
case packetTypes.ENCINIT:
|
||||
case packetTypes.ENCACK:
|
||||
return yield this.handlePacket(packet);
|
||||
default:
|
||||
unlock = yield this.locker.lock();
|
||||
try {
|
||||
this.socket.pause();
|
||||
return yield this.handlePacket(packet);
|
||||
} finally {
|
||||
this.socket.resume();
|
||||
unlock();
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -1356,7 +1356,7 @@ Pool.prototype.handleGetData = co(function* handleGetData(peer, packet) {
|
||||
}
|
||||
|
||||
if (item.hash === peer.hashContinue) {
|
||||
peer.forceInv([new InvItem(invTypes.BLOCK, this.chain.tip.hash)]);
|
||||
peer.sendInv([new InvItem(invTypes.BLOCK, this.chain.tip.hash)]);
|
||||
peer.hashContinue = null;
|
||||
}
|
||||
}
|
||||
@ -1943,7 +1943,7 @@ Pool.prototype.handleMempool = co(function* handleMempool(peer, packet) {
|
||||
|
||||
this.logger.debug('Sending mempool snapshot (%s).', peer.hostname);
|
||||
|
||||
peer.sendInv(items);
|
||||
peer.queueInv(items);
|
||||
|
||||
this.emit('mempool', packet, peer);
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user