From a355b05b2a81539d7da2e7c7c173ee296651feaf Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Tue, 22 Aug 2017 10:22:52 +0200 Subject: [PATCH] Peer: Drop Bitcoin Cash peers early, based on service bit 5. They will fail the difficulty check anyway. --- core/src/main/java/org/bitcoinj/core/Peer.java | 7 +++++++ core/src/main/java/org/bitcoinj/core/VersionMessage.java | 2 ++ 2 files changed, 9 insertions(+) diff --git a/core/src/main/java/org/bitcoinj/core/Peer.java b/core/src/main/java/org/bitcoinj/core/Peer.java index 00064ed0..9f873348 100644 --- a/core/src/main/java/org/bitcoinj/core/Peer.java +++ b/core/src/main/java/org/bitcoinj/core/Peer.java @@ -564,6 +564,13 @@ public class Peer extends PeerSocketHandler { close(); return; } + if ((vPeerVersionMessage.localServices + & VersionMessage.NODE_BITCOIN_CASH) == VersionMessage.NODE_BITCOIN_CASH) { + log.info("{}: Peer follows an incompatible block chain.", this); + // Shut down the channel gracefully. + close(); + return; + } if (vPeerVersionMessage.bestHeight < 0) // In this case, it's a protocol violation. throw new ProtocolException("Peer reports invalid best height: " + vPeerVersionMessage.bestHeight); diff --git a/core/src/main/java/org/bitcoinj/core/VersionMessage.java b/core/src/main/java/org/bitcoinj/core/VersionMessage.java index eac0f54b..7421fd5d 100644 --- a/core/src/main/java/org/bitcoinj/core/VersionMessage.java +++ b/core/src/main/java/org/bitcoinj/core/VersionMessage.java @@ -41,6 +41,8 @@ public class VersionMessage extends Message { public static final int NODE_NETWORK = 1 << 0; /** A service bit that denotes whether the peer supports the getutxos message or not. */ public static final int NODE_GETUTXOS = 1 << 1; + /** A service bit used by Bitcoin-ABC to announce Bitcoin Cash nodes. */ + public static final int NODE_BITCOIN_CASH = 1 << 5; /** * The version number of the protocol spoken.