net: less strict bip152 behavior.
This commit is contained in:
parent
7b516ddd1e
commit
694bab4ad0
@ -1480,10 +1480,8 @@ Peer.prototype.blockType = function blockType() {
|
|||||||
if (this.options.spv)
|
if (this.options.spv)
|
||||||
return invTypes.FILTERED_BLOCK;
|
return invTypes.FILTERED_BLOCK;
|
||||||
|
|
||||||
if (this.options.compact && this.compactMode !== -1) {
|
if (this.options.compact && this.hasCompact())
|
||||||
if (!this.options.hasWitness() || this.compactWitness)
|
return invTypes.CMPCT_BLOCK;
|
||||||
return invTypes.CMPCT_BLOCK;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.hasWitness())
|
if (this.hasWitness())
|
||||||
return invTypes.WITNESS_BLOCK;
|
return invTypes.WITNESS_BLOCK;
|
||||||
@ -1734,8 +1732,11 @@ Peer.prototype.handleVersion = co(function* handleVersion(packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.options.compact) {
|
if (this.options.compact) {
|
||||||
if (!this.hasCompact())
|
if (!this.hasCompactSupport()) {
|
||||||
throw new Error('Peer does not support compact blocks.');
|
this.logger.debug(
|
||||||
|
'Peer does not support compact blocks (%s).',
|
||||||
|
this.hostname());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2209,7 +2210,7 @@ Peer.prototype.hasWitness = function hasWitness() {
|
|||||||
* @returns {Boolean}
|
* @returns {Boolean}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Peer.prototype.hasCompact = function hasCompact() {
|
Peer.prototype.hasCompactSupport = function hasCompactSupport() {
|
||||||
if (this.version < common.COMPACT_VERSION)
|
if (this.version < common.COMPACT_VERSION)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -2222,6 +2223,25 @@ Peer.prototype.hasCompact = function hasCompact() {
|
|||||||
return this.version >= common.COMPACT_WITNESS_VERSION;
|
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.
|
* Inspect the peer.
|
||||||
* @returns {String}
|
* @returns {String}
|
||||||
|
|||||||
@ -1103,7 +1103,7 @@ Pool.prototype.handleOpen = co(function* handleOpen(peer) {
|
|||||||
|
|
||||||
// We want compact blocks!
|
// We want compact blocks!
|
||||||
if (this.options.compact) {
|
if (this.options.compact) {
|
||||||
if (peer.hasCompact())
|
if (peer.hasCompactSupport())
|
||||||
peer.sendCompact(this.options.blockMode);
|
peer.sendCompact(this.options.blockMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2435,6 +2435,15 @@ Pool.prototype.handleCmpctBlock = co(function* handleCmpctBlock(peer, packet) {
|
|||||||
this.logger.info(
|
this.logger.info(
|
||||||
'Peer sent unsolicited cmpctblock (%s).',
|
'Peer sent unsolicited cmpctblock (%s).',
|
||||||
peer.hostname());
|
peer.hostname());
|
||||||
|
this.destroy();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!peer.hasCompactSupport()) {
|
||||||
|
this.logger.info(
|
||||||
|
'Peer sent unsolicited cmpctblock (%s).',
|
||||||
|
peer.hostname());
|
||||||
|
this.destroy();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user