peer: better options handling and logs.
This commit is contained in:
parent
215a3ad6fc
commit
c18bb98b3c
@ -1561,22 +1561,24 @@ Peer.prototype._sendBlock = co(function* _sendBlock(item, witness) {
|
||||
|
||||
// If we have the same serialization, we
|
||||
// can write the raw binary to the socket.
|
||||
if (witness === !!this.options.witness) {
|
||||
if (witness === this.chain.db.options.witness) {
|
||||
block = yield this.chain.db.getRawBlock(item.hash);
|
||||
|
||||
if (!block)
|
||||
return false;
|
||||
|
||||
yield this.sendRaw('block', block);
|
||||
} else {
|
||||
block = yield this.chain.db.getBlock(item.hash);
|
||||
|
||||
if (!block)
|
||||
return false;
|
||||
|
||||
yield this.send(new packets.BlockPacket(block, witness));
|
||||
return true;
|
||||
}
|
||||
|
||||
block = yield this.chain.db.getBlock(item.hash);
|
||||
|
||||
if (!block)
|
||||
return false;
|
||||
|
||||
yield this.send(new packets.BlockPacket(block, witness));
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
@ -1610,6 +1612,9 @@ Peer.prototype._sendCompactBlock = function _sendCompactBlock(block, witness) {
|
||||
|
||||
Peer.prototype._handleGetData = co(function* _handleGetData(packet) {
|
||||
var notFound = [];
|
||||
var txs = 0;
|
||||
var blocks = 0;
|
||||
var unknown = -1;
|
||||
var items = packet.items;
|
||||
var i, j, item, tx, block, result;
|
||||
|
||||
@ -1639,6 +1644,8 @@ Peer.prototype._handleGetData = co(function* _handleGetData(packet) {
|
||||
|
||||
yield this.send(new packets.TXPacket(tx, item.hasWitness()));
|
||||
|
||||
txs++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1650,6 +1657,7 @@ Peer.prototype._handleGetData = co(function* _handleGetData(packet) {
|
||||
notFound.push(item);
|
||||
continue;
|
||||
}
|
||||
blocks++;
|
||||
break;
|
||||
case constants.inv.FILTERED_BLOCK:
|
||||
case constants.inv.WITNESS_FILTERED_BLOCK:
|
||||
@ -1672,8 +1680,11 @@ Peer.prototype._handleGetData = co(function* _handleGetData(packet) {
|
||||
for (j = 0; j < block.txs.length; j++) {
|
||||
tx = block.txs[j];
|
||||
yield this.send(new packets.TXPacket(tx, item.hasWitness()));
|
||||
txs++;
|
||||
}
|
||||
|
||||
blocks++;
|
||||
|
||||
break;
|
||||
case constants.inv.CMPCT_BLOCK:
|
||||
// Fallback to full block.
|
||||
@ -1683,6 +1694,7 @@ Peer.prototype._handleGetData = co(function* _handleGetData(packet) {
|
||||
notFound.push(item);
|
||||
continue;
|
||||
}
|
||||
blocks++;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1695,12 +1707,11 @@ Peer.prototype._handleGetData = co(function* _handleGetData(packet) {
|
||||
|
||||
yield this._sendCompactBlock(block, this.compactWitness);
|
||||
|
||||
blocks++;
|
||||
|
||||
break;
|
||||
default:
|
||||
this.logger.warning(
|
||||
'Peer sent an unknown getdata type: %s (%s).',
|
||||
item.type,
|
||||
this.hostname);
|
||||
unknown = item.type;
|
||||
notFound.push(item);
|
||||
continue;
|
||||
}
|
||||
@ -1711,14 +1722,26 @@ Peer.prototype._handleGetData = co(function* _handleGetData(packet) {
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.debug(
|
||||
'Served %d items with getdata (notfound=%d) (%s).',
|
||||
items.length - notFound.length,
|
||||
notFound.length,
|
||||
this.hostname);
|
||||
|
||||
if (notFound.length > 0)
|
||||
yield this.send(new packets.NotFoundPacket(notFound));
|
||||
|
||||
if (txs > 0) {
|
||||
this.logger.debug(
|
||||
'Served %d txs with getdata (notfound=%d) (%s).',
|
||||
txs, notFound.length, this.hostname);
|
||||
}
|
||||
|
||||
if (blocks > 0) {
|
||||
this.logger.debug(
|
||||
'Served %d blocks with getdata (notfound=%d) (%s).',
|
||||
blocks, notFound.length, this.hostname);
|
||||
}
|
||||
|
||||
if (unknown !== -1) {
|
||||
this.logger.warning(
|
||||
'Peer sent an unknown getdata type: %s (%d).',
|
||||
unknown, this.hostname);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
@ -2293,7 +2316,9 @@ Peer.prototype.sendGetHeaders = function sendGetHeaders(locator, stop) {
|
||||
if (stop)
|
||||
stop = utils.revHex(stop);
|
||||
|
||||
this.logger.debug('Height: %d, Hash: %s, Stop: %s', height, hash, stop);
|
||||
this.logger.debug(
|
||||
'Height: %d, Hash: %s, Stop: %s',
|
||||
height, hash, stop || null);
|
||||
|
||||
return this.send(packet);
|
||||
};
|
||||
@ -2321,7 +2346,9 @@ Peer.prototype.sendGetBlocks = function getBlocks(locator, stop) {
|
||||
if (stop)
|
||||
stop = utils.revHex(stop);
|
||||
|
||||
this.logger.debug('Height: %d, Hash: %s, Stop: %s', height, hash, stop);
|
||||
this.logger.debug(
|
||||
'Height: %d, Hash: %s, Stop: %s',
|
||||
height, hash, stop || null);
|
||||
|
||||
return this.send(packet);
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user