diff --git a/besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java b/besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java index f77abd63a7..fdf94ceb9e 100644 --- a/besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java +++ b/besu/src/main/java/org/hyperledger/besu/controller/IbftBesuControllerBuilder.java @@ -140,7 +140,7 @@ public class IbftBesuControllerBuilder extends BesuControllerBuilder { final ProposerSelector proposerSelector = new ProposerSelector(blockchain, blockInterface, true, voteTallyCache); - peers = new ValidatorPeers(voteTallyCache); + peers = new ValidatorPeers(voteTallyCache, IbftSubProtocol.NAME); final UniqueMessageMulticaster uniqueMessageMulticaster = new UniqueMessageMulticaster(peers, bftConfig.getGossipedHistoryLimit()); diff --git a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/network/ValidatorPeers.java b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/network/ValidatorPeers.java index b0c6e497f2..d9b4968640 100644 --- a/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/network/ValidatorPeers.java +++ b/consensus/common/src/main/java/org/hyperledger/besu/consensus/common/bft/network/ValidatorPeers.java @@ -39,15 +39,15 @@ public class ValidatorPeers implements ValidatorMulticaster, PeerConnectionTrack private static final Logger LOG = LogManager.getLogger(); - private static final String PROTOCOL_NAME = "IBF"; - // It's possible for multiple connections between peers to exist for brief periods, so map each // address to a set of connections private final Map> connectionsByAddress = new ConcurrentHashMap<>(); private final VoteTallyCache voteTallyCache; + private final String protocolName; - public ValidatorPeers(final VoteTallyCache voteTallyCache) { + public ValidatorPeers(final VoteTallyCache voteTallyCache, final String protocolName) { this.voteTallyCache = voteTallyCache; + this.protocolName = protocolName; } @Override @@ -94,7 +94,7 @@ public class ValidatorPeers implements ValidatorMulticaster, PeerConnectionTrack .forEach( connection -> { try { - connection.sendForProtocol(PROTOCOL_NAME, message); + connection.sendForProtocol(protocolName, message); } catch (final PeerNotConnected peerNotConnected) { LOG.trace( "Lost connection to a validator. remoteAddress={} peerInfo={}", diff --git a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/network/ValidatorPeersTest.java b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/network/ValidatorPeersTest.java index f8e181e354..cc4e1d1a2b 100644 --- a/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/network/ValidatorPeersTest.java +++ b/consensus/common/src/test/java/org/hyperledger/besu/consensus/common/bft/network/ValidatorPeersTest.java @@ -46,6 +46,7 @@ import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class ValidatorPeersTest { + public static final String PROTOCOL_NAME = "BFT"; private final List
validators = newArrayList(); private final List publicKeys = newArrayList(); @@ -81,7 +82,7 @@ public class ValidatorPeersTest { // Only add the first Peer's address to the validators. validators.add(Util.publicKeyToAddress(publicKeys.get(0))); - final ValidatorPeers peers = new ValidatorPeers(voteTallyCache); + final ValidatorPeers peers = new ValidatorPeers(voteTallyCache, PROTOCOL_NAME); for (final PeerConnection peer : peerConnections) { peers.add(peer); } @@ -89,7 +90,7 @@ public class ValidatorPeersTest { final MessageData messageToSend = new RawMessage(1, Bytes.EMPTY); peers.send(messageToSend); - verify(peerConnections.get(0), times(1)).sendForProtocol("IBF", messageToSend); + verify(peerConnections.get(0), times(1)).sendForProtocol(PROTOCOL_NAME, messageToSend); verify(peerConnections.get(1), never()).sendForProtocol(any(), any()); verify(peerConnections.get(2), never()).sendForProtocol(any(), any()); verify(peerConnections.get(3), never()).sendForProtocol(any(), any()); @@ -101,7 +102,7 @@ public class ValidatorPeersTest { validators.add(peer0Address); final PeerConnection duplicatePeer = mockPeerConnection(peer0Address); - final ValidatorPeers peers = new ValidatorPeers(voteTallyCache); + final ValidatorPeers peers = new ValidatorPeers(voteTallyCache, PROTOCOL_NAME); for (final PeerConnection peer : peerConnections) { peers.add(peer); } @@ -110,8 +111,8 @@ public class ValidatorPeersTest { final MessageData messageToSend = new RawMessage(1, Bytes.EMPTY); peers.send(messageToSend); - verify(peerConnections.get(0), times(1)).sendForProtocol("IBF", messageToSend); - verify(duplicatePeer, times(1)).sendForProtocol("IBF", messageToSend); + verify(peerConnections.get(0), times(1)).sendForProtocol(PROTOCOL_NAME, messageToSend); + verify(duplicatePeer, times(1)).sendForProtocol(PROTOCOL_NAME, messageToSend); verify(peerConnections.get(1), never()).sendForProtocol(any(), any()); verify(peerConnections.get(2), never()).sendForProtocol(any(), any()); verify(peerConnections.get(3), never()).sendForProtocol(any(), any()); @@ -123,7 +124,7 @@ public class ValidatorPeersTest { validators.add(peer0Address); final PeerConnection duplicatePeer = mockPeerConnection(peer0Address); - final ValidatorPeers peers = new ValidatorPeers(voteTallyCache); + final ValidatorPeers peers = new ValidatorPeers(voteTallyCache, PROTOCOL_NAME); for (final PeerConnection peer : peerConnections) { peers.add(peer); } @@ -133,7 +134,7 @@ public class ValidatorPeersTest { final MessageData messageToSend = new RawMessage(1, Bytes.EMPTY); peers.send(messageToSend); - verify(peerConnections.get(0), times(1)).sendForProtocol("IBF", messageToSend); + verify(peerConnections.get(0), times(1)).sendForProtocol(PROTOCOL_NAME, messageToSend); verify(duplicatePeer, never()).sendForProtocol("IBF", messageToSend); verify(peerConnections.get(1), never()).sendForProtocol(any(), any()); verify(peerConnections.get(2), never()).sendForProtocol(any(), any()); @@ -144,7 +145,7 @@ public class ValidatorPeersTest { public void doesntSendToValidatorsWhichAreNotDirectlyConnected() throws PeerNotConnected { validators.add(Util.publicKeyToAddress(publicKeys.get(0))); - final ValidatorPeers peers = new ValidatorPeers(voteTallyCache); + final ValidatorPeers peers = new ValidatorPeers(voteTallyCache, PROTOCOL_NAME); // only add peer connections 1, 2 & 3, none of which should be invoked. newArrayList(1, 2, 3).forEach(i -> peers.add(peerConnections.get(i))); @@ -165,7 +166,7 @@ public class ValidatorPeersTest { validators.add(validatorAddress); validators.add(Util.publicKeyToAddress(publicKeys.get(1))); - final ValidatorPeers peers = new ValidatorPeers(voteTallyCache); + final ValidatorPeers peers = new ValidatorPeers(voteTallyCache, PROTOCOL_NAME); for (final PeerConnection peer : peerConnections) { peers.add(peer); }