From a1def190adfa27a7f507ab37bb3dcf2b0fd5294a Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Tue, 16 Feb 2016 16:44:44 +0100 Subject: [PATCH] Peer: Disconnect peers without copy of the block chain gracefully. Previously, a protocol exception was thrown, spamming error reporting facilities with useless messages. --- core/src/main/java/org/bitcoinj/core/Peer.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/core/Peer.java b/core/src/main/java/org/bitcoinj/core/Peer.java index a17010e2..437e6b4c 100644 --- a/core/src/main/java/org/bitcoinj/core/Peer.java +++ b/core/src/main/java/org/bitcoinj/core/Peer.java @@ -537,10 +537,15 @@ public class Peer extends PeerSocketHandler { // implementations claim to have a block chain in their services field but then report a height of zero, filter // them out here. if (!vPeerVersionMessage.hasBlockChain() || - (!params.allowEmptyPeerChain() && vPeerVersionMessage.bestHeight <= 0)) { - // Shut down the channel - throw new ProtocolException("Peer does not have a copy of the block chain."); + (!params.allowEmptyPeerChain() && vPeerVersionMessage.bestHeight == 0)) { + // Shut down the channel gracefully. + log.info("{}: Peer does not have a copy of the block chain.", this); + close(); + return; } + if (vPeerVersionMessage.bestHeight < 0) + // In this case, it's a protocol violation. + throw new ProtocolException("Peer reports invalid best height: " + vPeerVersionMessage.bestHeight); versionHandshakeFuture.set(this); }