net: less strict bip152 behavior.

This commit is contained in:
Christopher Jeffrey 2017-03-02 18:09:11 -08:00
parent 7b516ddd1e
commit 694bab4ad0
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 37 additions and 8 deletions

View File

@ -1480,10 +1480,8 @@ Peer.prototype.blockType = function blockType() {
if (this.options.spv)
return invTypes.FILTERED_BLOCK;
if (this.options.compact && this.compactMode !== -1) {
if (!this.options.hasWitness() || this.compactWitness)
return invTypes.CMPCT_BLOCK;
}
if (this.options.compact && this.hasCompact())
return invTypes.CMPCT_BLOCK;
if (this.hasWitness())
return invTypes.WITNESS_BLOCK;
@ -1734,8 +1732,11 @@ Peer.prototype.handleVersion = co(function* handleVersion(packet) {
}
if (this.options.compact) {
if (!this.hasCompact())
throw new Error('Peer does not support compact blocks.');
if (!this.hasCompactSupport()) {
this.logger.debug(
'Peer does not support compact blocks (%s).',
this.hostname());
}
}
}
@ -2209,7 +2210,7 @@ Peer.prototype.hasWitness = function hasWitness() {
* @returns {Boolean}
*/
Peer.prototype.hasCompact = function hasCompact() {
Peer.prototype.hasCompactSupport = function hasCompactSupport() {
if (this.version < common.COMPACT_VERSION)
return false;
@ -2222,6 +2223,25 @@ Peer.prototype.hasCompact = function hasCompact() {
return this.version >= common.COMPACT_WITNESS_VERSION;
};
/**
* Test whether the peer sent us a
* compatible compact block handshake.
* @returns {Boolean}
*/
Peer.prototype.hasCompact = function hasCompact() {
if (this.compactMode === -1)
return false;
if (!this.options.hasWitness())
return true;
if (!this.compactWitness)
return false;
return true;
};
/**
* Inspect the peer.
* @returns {String}

View File

@ -1103,7 +1103,7 @@ Pool.prototype.handleOpen = co(function* handleOpen(peer) {
// We want compact blocks!
if (this.options.compact) {
if (peer.hasCompact())
if (peer.hasCompactSupport())
peer.sendCompact(this.options.blockMode);
}
@ -2435,6 +2435,15 @@ Pool.prototype.handleCmpctBlock = co(function* handleCmpctBlock(peer, packet) {
this.logger.info(
'Peer sent unsolicited cmpctblock (%s).',
peer.hostname());
this.destroy();
return;
}
if (!peer.hasCompactSupport()) {
this.logger.info(
'Peer sent unsolicited cmpctblock (%s).',
peer.hostname());
this.destroy();
return;
}