From 1cee74dc78a7b67d0b32eb3ca7448abbd259cee9 Mon Sep 17 00:00:00 2001 From: tmohay <37158202+rain-on@users.noreply.github.com> Date: Wed, 16 Jan 2019 20:58:04 +1100 Subject: [PATCH] Rename IBFT networking classes (#555) Signed-off-by: Adrian Sutton --- ...ter.java => StubValidatorMulticaster.java} | 13 ++++---- .../ibft/support/TestContextFactory.java | 10 +++---- .../pantheon/consensus/ibft/IbftGossip.java | 18 +++++------ .../IbftMessageTransmitter.java | 17 +++++------ .../ibft/network/PeerConnectionTracker.java | 22 ++++++++++++++ ...icaster.java => ValidatorMulticaster.java} | 7 ++--- ...tNetworkPeers.java => ValidatorPeers.java} | 21 ++++++++----- .../ibft/protocol/IbftProtocolManager.java | 13 ++++---- .../statemachine/IbftBlockHeightManager.java | 1 + .../ibft/statemachine/IbftController.java | 2 +- .../ibft/statemachine/IbftFinalState.java | 15 +++++----- .../ibft/statemachine/IbftRound.java | 1 + .../consensus/ibft/IbftGossipTest.java | 30 +++++++++---------- ...PeersTest.java => ValidatorPeersTest.java} | 20 ++++++------- .../IbftBlockHeightManagerTest.java | 1 + .../ibft/statemachine/IbftRoundTest.java | 1 + .../controller/IbftPantheonController.java | 6 ++-- 17 files changed, 114 insertions(+), 84 deletions(-) rename consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/{StubIbftMulticaster.java => StubValidatorMulticaster.java} (74%) rename consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/{statemachine => network}/IbftMessageTransmitter.java (88%) create mode 100644 consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/PeerConnectionTracker.java rename consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/{IbftMulticaster.java => ValidatorMulticaster.java} (79%) rename consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/{IbftNetworkPeers.java => ValidatorPeers.java} (80%) rename consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/network/{IbftNetworkPeersTest.java => ValidatorPeersTest.java} (89%) diff --git a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/StubIbftMulticaster.java b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/StubValidatorMulticaster.java similarity index 74% rename from consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/StubIbftMulticaster.java rename to consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/StubValidatorMulticaster.java index 57d123abd0..d02e0be58f 100644 --- a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/StubIbftMulticaster.java +++ b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/StubValidatorMulticaster.java @@ -12,7 +12,7 @@ */ package tech.pegasys.pantheon.consensus.ibft.support; -import tech.pegasys.pantheon.consensus.ibft.network.IbftMulticaster; +import tech.pegasys.pantheon.consensus.ibft.network.ValidatorMulticaster; import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.p2p.api.MessageData; @@ -21,27 +21,26 @@ import java.util.List; import com.google.common.collect.Lists; -public class StubIbftMulticaster implements IbftMulticaster { +public class StubValidatorMulticaster implements ValidatorMulticaster { private final List validatorNodes = Lists.newArrayList(); - public StubIbftMulticaster() {} + public StubValidatorMulticaster() {} public void addNetworkPeers(final Collection nodes) { validatorNodes.addAll(nodes); } @Override - public void multicastToValidators(final MessageData message) { + public void send(final MessageData message) { validatorNodes.forEach(peer -> peer.handleReceivedMessage(message)); } @Override - public void multicastToValidatorsExcept( - final MessageData message, final Collection
exceptAddresses) { + public void send(final MessageData message, final Collection
blackList) { validatorNodes .stream() - .filter(peer -> !exceptAddresses.contains(peer.getNodeAddress())) + .filter(peer -> !blackList.contains(peer.getNodeAddress())) .forEach(peer -> peer.handleReceivedMessage(message)); } } diff --git a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestContextFactory.java b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestContextFactory.java index 135b65f614..7dc8f95d28 100644 --- a/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestContextFactory.java +++ b/consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestContextFactory.java @@ -125,10 +125,10 @@ public class TestContextFactory { final KeyPair nodeKeys = networkNodes.getLocalNode().getNodeKeyPair(); // Use a stubbed version of the multicaster, to prevent creating PeerConnections etc. - final StubIbftMulticaster stubbedNetworkPeers = new StubIbftMulticaster(); + final StubValidatorMulticaster stubbedMulticaster = new StubValidatorMulticaster(); final ControllerAndState controllerAndState = - createControllerAndFinalState(blockChain, stubbedNetworkPeers, nodeKeys, clock); + createControllerAndFinalState(blockChain, stubbedMulticaster, nodeKeys, clock); // Add each networkNode to the Multicaster (such that each can receive msgs from local node). // NOTE: the remotePeers needs to be ordered based on Address (as this is used to determine @@ -150,7 +150,7 @@ public class TestContextFactory { }, LinkedHashMap::new)); - stubbedNetworkPeers.addNetworkPeers(remotePeers.values()); + stubbedMulticaster.addNetworkPeers(remotePeers.values()); return new TestContext( remotePeers, @@ -186,7 +186,7 @@ public class TestContextFactory { private static ControllerAndState createControllerAndFinalState( final MutableBlockchain blockChain, - final StubIbftMulticaster stubbedNetworkPeers, + final StubValidatorMulticaster stubbedMulticaster, final KeyPair nodeKeys, final Clock clock) { @@ -242,7 +242,7 @@ public class TestContextFactory { nodeKeys, Util.publicKeyToAddress(nodeKeys.getPublicKey()), proposerSelector, - stubbedNetworkPeers, + stubbedMulticaster, new RoundTimer( ibftEventQueue, ROUND_TIMER_SEC * 1000, Executors.newScheduledThreadPool(1)), new BlockTimer( diff --git a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/IbftGossip.java b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/IbftGossip.java index 415d3adbb4..bccd9da18b 100644 --- a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/IbftGossip.java +++ b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/IbftGossip.java @@ -18,7 +18,7 @@ import tech.pegasys.pantheon.consensus.ibft.messagedata.NewRoundMessageData; import tech.pegasys.pantheon.consensus.ibft.messagedata.PrepareMessageData; import tech.pegasys.pantheon.consensus.ibft.messagedata.ProposalMessageData; import tech.pegasys.pantheon.consensus.ibft.messagedata.RoundChangeMessageData; -import tech.pegasys.pantheon.consensus.ibft.network.IbftMulticaster; +import tech.pegasys.pantheon.consensus.ibft.network.ValidatorMulticaster; import tech.pegasys.pantheon.consensus.ibft.payload.SignedData; import tech.pegasys.pantheon.crypto.SECP256K1.Signature; import tech.pegasys.pantheon.ethereum.core.Address; @@ -35,7 +35,7 @@ import com.google.common.collect.Lists; /** Class responsible for rebroadcasting IBFT messages to known validators */ public class IbftGossip { - private final IbftMulticaster peers; + private final ValidatorMulticaster multicaster; // Size of the seenMessages cache, should end up utilising 65bytes * this number + some meta data private final int maxSeenMessages; @@ -50,18 +50,18 @@ public class IbftGossip { } }); - IbftGossip(final IbftMulticaster peers, final int maxSeenMessages) { + IbftGossip(final ValidatorMulticaster multicaster, final int maxSeenMessages) { this.maxSeenMessages = maxSeenMessages; - this.peers = peers; + this.multicaster = multicaster; } /** - * Constructor that attaches gossip logic to a set of peers + * Constructor that attaches gossip logic to a set of multicaster * - * @param peers The always up to date set of connected peers that understand IBFT + * @param multicaster Network connections to the remote validators */ - public IbftGossip(final IbftMulticaster peers) { - this(peers, 10_000); + public IbftGossip(final ValidatorMulticaster multicaster) { + this(multicaster, 10_000); } /** @@ -100,7 +100,7 @@ public class IbftGossip { final List
excludeAddressesList = Lists.newArrayList( message.getConnection().getPeer().getAddress(), signedData.getSender()); - peers.multicastToValidatorsExcept(messageData, excludeAddressesList); + multicaster.send(messageData, excludeAddressesList); seenMessages.add(signature); return true; } diff --git a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftMessageTransmitter.java b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/IbftMessageTransmitter.java similarity index 88% rename from consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftMessageTransmitter.java rename to consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/IbftMessageTransmitter.java index 436d4c0ce9..55cc1cec68 100644 --- a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftMessageTransmitter.java +++ b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/IbftMessageTransmitter.java @@ -10,7 +10,7 @@ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ -package tech.pegasys.pantheon.consensus.ibft.statemachine; +package tech.pegasys.pantheon.consensus.ibft.network; import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier; import tech.pegasys.pantheon.consensus.ibft.messagedata.CommitMessageData; @@ -18,7 +18,6 @@ import tech.pegasys.pantheon.consensus.ibft.messagedata.NewRoundMessageData; import tech.pegasys.pantheon.consensus.ibft.messagedata.PrepareMessageData; import tech.pegasys.pantheon.consensus.ibft.messagedata.ProposalMessageData; import tech.pegasys.pantheon.consensus.ibft.messagedata.RoundChangeMessageData; -import tech.pegasys.pantheon.consensus.ibft.network.IbftMulticaster; import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload; import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; import tech.pegasys.pantheon.consensus.ibft.payload.NewRoundPayload; @@ -37,10 +36,10 @@ import java.util.Optional; public class IbftMessageTransmitter { private final MessageFactory messageFactory; - private final IbftMulticaster multicaster; + private final ValidatorMulticaster multicaster; public IbftMessageTransmitter( - final MessageFactory messageFactory, final IbftMulticaster multicaster) { + final MessageFactory messageFactory, final ValidatorMulticaster multicaster) { this.messageFactory = messageFactory; this.multicaster = multicaster; } @@ -51,7 +50,7 @@ public class IbftMessageTransmitter { final ProposalMessageData message = ProposalMessageData.create(signedPayload); - multicaster.multicastToValidators(message); + multicaster.send(message); } public void multicastPrepare(final ConsensusRoundIdentifier roundIdentifier, final Hash digest) { @@ -60,7 +59,7 @@ public class IbftMessageTransmitter { final PrepareMessageData message = PrepareMessageData.create(signedPayload); - multicaster.multicastToValidators(message); + multicaster.send(message); } public void multicastCommit( @@ -72,7 +71,7 @@ public class IbftMessageTransmitter { final CommitMessageData message = CommitMessageData.create(signedPayload); - multicaster.multicastToValidators(message); + multicaster.send(message); } public void multicastRoundChange( @@ -84,7 +83,7 @@ public class IbftMessageTransmitter { final RoundChangeMessageData message = RoundChangeMessageData.create(signedPayload); - multicaster.multicastToValidators(message); + multicaster.send(message); } public void multicastNewRound( @@ -98,6 +97,6 @@ public class IbftMessageTransmitter { final NewRoundMessageData message = NewRoundMessageData.create(signedPayload); - multicaster.multicastToValidators(message); + multicaster.send(message); } } diff --git a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/PeerConnectionTracker.java b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/PeerConnectionTracker.java new file mode 100644 index 0000000000..1dac1de447 --- /dev/null +++ b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/PeerConnectionTracker.java @@ -0,0 +1,22 @@ +/* + * Copyright 2019 ConsenSys AG. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package tech.pegasys.pantheon.consensus.ibft.network; + +import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection; + +public interface PeerConnectionTracker { + + void add(final PeerConnection newConnection); + + void remove(final PeerConnection removedConnection); +} diff --git a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/IbftMulticaster.java b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/ValidatorMulticaster.java similarity index 79% rename from consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/IbftMulticaster.java rename to consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/ValidatorMulticaster.java index 4e61274f86..991e555730 100644 --- a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/IbftMulticaster.java +++ b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/ValidatorMulticaster.java @@ -17,10 +17,9 @@ import tech.pegasys.pantheon.ethereum.p2p.api.MessageData; import java.util.Collection; -public interface IbftMulticaster { +public interface ValidatorMulticaster { - void multicastToValidators(final MessageData message); + void send(final MessageData message); - void multicastToValidatorsExcept( - final MessageData message, final Collection
exceptAddresses); + void send(final MessageData message, final Collection
blackList); } diff --git a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/IbftNetworkPeers.java b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/ValidatorPeers.java similarity index 80% rename from consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/IbftNetworkPeers.java rename to consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/ValidatorPeers.java index 4482e68d43..ffdcea6d49 100644 --- a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/IbftNetworkPeers.java +++ b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/ValidatorPeers.java @@ -27,7 +27,11 @@ import com.google.common.collect.Maps; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -public class IbftNetworkPeers implements IbftMulticaster { +/** + * Responsible for tracking the network peers which have a connection to this node, then + * multicasting packets to ONLY the peers which have been identified as being validators. + */ +public class ValidatorPeers implements ValidatorMulticaster, PeerConnectionTracker { private static final Logger LOG = LogManager.getLogger(); @@ -36,34 +40,35 @@ public class IbftNetworkPeers implements IbftMulticaster { private final Map peerConnections = Maps.newConcurrentMap(); private final ValidatorProvider validatorProvider; - public IbftNetworkPeers(final ValidatorProvider validatorProvider) { + public ValidatorPeers(final ValidatorProvider validatorProvider) { this.validatorProvider = validatorProvider; } - public void peerAdded(final PeerConnection newConnection) { + @Override + public void add(final PeerConnection newConnection) { final Address peerAddress = newConnection.getPeer().getAddress(); peerConnections.put(peerAddress, newConnection); } - public void peerRemoved(final PeerConnection removedConnection) { + @Override + public void remove(final PeerConnection removedConnection) { final Address peerAddress = removedConnection.getPeer().getAddress(); peerConnections.remove(peerAddress); } @Override - public void multicastToValidators(final MessageData message) { + public void send(final MessageData message) { final Collection
validators = validatorProvider.getValidators(); sendMessageToSpecificAddresses(validators, message); } @Override - public void multicastToValidatorsExcept( - final MessageData message, final Collection
exceptAddresses) { + public void send(final MessageData message, final Collection
blackList) { final Collection
includedValidators = validatorProvider .getValidators() .stream() - .filter(a -> !exceptAddresses.contains(a)) + .filter(a -> !blackList.contains(a)) .collect(Collectors.toSet()); sendMessageToSpecificAddresses(includedValidators, message); } diff --git a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/protocol/IbftProtocolManager.java b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/protocol/IbftProtocolManager.java index 4bc170a049..b00e25281e 100644 --- a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/protocol/IbftProtocolManager.java +++ b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/protocol/IbftProtocolManager.java @@ -15,7 +15,7 @@ package tech.pegasys.pantheon.consensus.ibft.protocol; import tech.pegasys.pantheon.consensus.ibft.IbftEventQueue; import tech.pegasys.pantheon.consensus.ibft.ibftevent.IbftEvent; import tech.pegasys.pantheon.consensus.ibft.ibftevent.IbftEvents; -import tech.pegasys.pantheon.consensus.ibft.network.IbftNetworkPeers; +import tech.pegasys.pantheon.consensus.ibft.network.PeerConnectionTracker; import tech.pegasys.pantheon.ethereum.p2p.api.Message; import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection; import tech.pegasys.pantheon.ethereum.p2p.api.ProtocolManager; @@ -32,15 +32,16 @@ public class IbftProtocolManager implements ProtocolManager { private final IbftEventQueue ibftEventQueue; private final Logger LOG = LogManager.getLogger(); - private final IbftNetworkPeers peers; + private final PeerConnectionTracker peers; /** * Constructor for the ibft protocol manager * * @param ibftEventQueue Entry point into the ibft event processor - * @param peers iBFT network peers + * @param peers Used to track all connected IBFT peers. */ - public IbftProtocolManager(final IbftEventQueue ibftEventQueue, final IbftNetworkPeers peers) { + public IbftProtocolManager( + final IbftEventQueue ibftEventQueue, final PeerConnectionTracker peers) { this.ibftEventQueue = ibftEventQueue; this.peers = peers; } @@ -84,7 +85,7 @@ public class IbftProtocolManager implements ProtocolManager { @Override public void handleNewConnection(final PeerConnection peerConnection) { - peers.peerAdded(peerConnection); + peers.add(peerConnection); } @Override @@ -92,7 +93,7 @@ public class IbftProtocolManager implements ProtocolManager { final PeerConnection peerConnection, final DisconnectReason disconnectReason, final boolean initiatedByPeer) { - peers.peerRemoved(peerConnection); + peers.remove(peerConnection); } @Override diff --git a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftBlockHeightManager.java b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftBlockHeightManager.java index df3f1bf488..b98d464a46 100644 --- a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftBlockHeightManager.java +++ b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftBlockHeightManager.java @@ -20,6 +20,7 @@ import tech.pegasys.pantheon.consensus.ibft.BlockTimer; import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier; import tech.pegasys.pantheon.consensus.ibft.RoundTimer; import tech.pegasys.pantheon.consensus.ibft.ibftevent.RoundExpiry; +import tech.pegasys.pantheon.consensus.ibft.network.IbftMessageTransmitter; import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload; import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; import tech.pegasys.pantheon.consensus.ibft.payload.NewRoundPayload; diff --git a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftController.java b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftController.java index 9d14795c78..cb1edef0a5 100644 --- a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftController.java +++ b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftController.java @@ -61,7 +61,7 @@ public class IbftController { ibftFinalState, ibftBlockHeightManagerFactory, Maps.newHashMap(), - new IbftGossip(ibftFinalState.getPeers())); + new IbftGossip(ibftFinalState.getValidatorMulticaster())); } @VisibleForTesting diff --git a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftFinalState.java b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftFinalState.java index fb55c91155..41e6454210 100644 --- a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftFinalState.java +++ b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftFinalState.java @@ -21,7 +21,8 @@ import tech.pegasys.pantheon.consensus.ibft.IbftContext; import tech.pegasys.pantheon.consensus.ibft.RoundTimer; import tech.pegasys.pantheon.consensus.ibft.blockcreation.IbftBlockCreatorFactory; import tech.pegasys.pantheon.consensus.ibft.blockcreation.ProposerSelector; -import tech.pegasys.pantheon.consensus.ibft.network.IbftMulticaster; +import tech.pegasys.pantheon.consensus.ibft.network.IbftMessageTransmitter; +import tech.pegasys.pantheon.consensus.ibft.network.ValidatorMulticaster; import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; import tech.pegasys.pantheon.ethereum.core.Address; @@ -36,7 +37,7 @@ public class IbftFinalState { private final KeyPair nodeKeys; private final Address localAddress; private final ProposerSelector proposerSelector; - private final IbftMulticaster peers; + private final ValidatorMulticaster validatorMulticaster; private final RoundTimer roundTimer; private final BlockTimer blockTimer; private final IbftBlockCreatorFactory blockCreatorFactory; @@ -50,7 +51,7 @@ public class IbftFinalState { final KeyPair nodeKeys, final Address localAddress, final ProposerSelector proposerSelector, - final IbftMulticaster peers, + final ValidatorMulticaster validatorMulticaster, final RoundTimer roundTimer, final BlockTimer blockTimer, final IbftBlockCreatorFactory blockCreatorFactory, @@ -61,14 +62,14 @@ public class IbftFinalState { this.nodeKeys = nodeKeys; this.localAddress = localAddress; this.proposerSelector = proposerSelector; - this.peers = peers; + this.validatorMulticaster = validatorMulticaster; this.roundTimer = roundTimer; this.blockTimer = blockTimer; this.blockCreatorFactory = blockCreatorFactory; this.messageFactory = messageFactory; this.ibftContextBlockHeaderValidator = ibftContextBlockHeaderValidator; this.clock = clock; - this.messageTransmitter = new IbftMessageTransmitter(messageFactory, peers); + this.messageTransmitter = new IbftMessageTransmitter(messageFactory, validatorMulticaster); } public int getQuorum() { @@ -95,8 +96,8 @@ public class IbftFinalState { return getProposerForRound(roundIdentifier).equals(localAddress); } - public IbftMulticaster getPeers() { - return peers; + public ValidatorMulticaster getValidatorMulticaster() { + return validatorMulticaster; } public RoundTimer getRoundTimer() { diff --git a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftRound.java b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftRound.java index 3d51b2ac55..96f5d81ca5 100644 --- a/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftRound.java +++ b/consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftRound.java @@ -20,6 +20,7 @@ import tech.pegasys.pantheon.consensus.ibft.IbftContext; import tech.pegasys.pantheon.consensus.ibft.IbftExtraData; import tech.pegasys.pantheon.consensus.ibft.IbftHelpers; import tech.pegasys.pantheon.consensus.ibft.blockcreation.IbftBlockCreator; +import tech.pegasys.pantheon.consensus.ibft.network.IbftMessageTransmitter; import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload; import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; import tech.pegasys.pantheon.consensus.ibft.payload.PreparePayload; diff --git a/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/IbftGossipTest.java b/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/IbftGossipTest.java index bd0d104105..e189b9e76c 100644 --- a/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/IbftGossipTest.java +++ b/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/IbftGossipTest.java @@ -22,8 +22,8 @@ import tech.pegasys.pantheon.consensus.ibft.messagedata.NewRoundMessageData; import tech.pegasys.pantheon.consensus.ibft.messagedata.PrepareMessageData; import tech.pegasys.pantheon.consensus.ibft.messagedata.ProposalMessageData; import tech.pegasys.pantheon.consensus.ibft.messagedata.RoundChangeMessageData; -import tech.pegasys.pantheon.consensus.ibft.network.IbftNetworkPeers; import tech.pegasys.pantheon.consensus.ibft.network.MockPeerFactory; +import tech.pegasys.pantheon.consensus.ibft.network.ValidatorMulticaster; import tech.pegasys.pantheon.consensus.ibft.payload.Payload; import tech.pegasys.pantheon.consensus.ibft.payload.ProposalPayload; import tech.pegasys.pantheon.consensus.ibft.payload.SignedData; @@ -46,13 +46,13 @@ import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class IbftGossipTest { private IbftGossip ibftGossip; - @Mock private IbftNetworkPeers ibftNetworkPeers; + @Mock private ValidatorMulticaster validatorMulticaster; private PeerConnection peerConnection; private static final Address senderAddress = AddressHelpers.ofValue(9); @Before public void setup() { - ibftGossip = new IbftGossip(ibftNetworkPeers, 10); + ibftGossip = new IbftGossip(validatorMulticaster, 10); peerConnection = MockPeerFactory.create(senderAddress); } @@ -66,8 +66,8 @@ public class IbftGossipTest { final boolean gossipResult = ibftGossip.gossipMessage(message); assertThat(gossipResult).isTrue(); - verify(ibftNetworkPeers) - .multicastToValidatorsExcept(messageData, newArrayList(senderAddress, payload.getSender())); + verify(validatorMulticaster) + .send(messageData, newArrayList(senderAddress, payload.getSender())); } private

void assertRebroadcastOnlyOnce( @@ -82,8 +82,8 @@ public class IbftGossipTest { final boolean gossip2Result = ibftGossip.gossipMessage(message); assertThat(gossip1Result).isTrue(); assertThat(gossip2Result).isFalse(); - verify(ibftNetworkPeers, times(1)) - .multicastToValidatorsExcept(messageData, newArrayList(senderAddress, payload.getSender())); + verify(validatorMulticaster, times(1)) + .send(messageData, newArrayList(senderAddress, payload.getSender())); } @Test @@ -155,8 +155,8 @@ public class IbftGossipTest { final boolean gossip2Result = ibftGossip.gossipMessage(message); assertThat(gossip1Result).isTrue(); assertThat(gossip2Result).isFalse(); - verify(ibftNetworkPeers, times(1)) - .multicastToValidatorsExcept(messageData, newArrayList(senderAddress, payload.getSender())); + verify(validatorMulticaster, times(1)) + .send(messageData, newArrayList(senderAddress, payload.getSender())); for (int i = 1; i <= 9; i++) { final SignedData nextPayload = @@ -169,8 +169,8 @@ public class IbftGossipTest { final boolean gossip3Result = ibftGossip.gossipMessage(message); assertThat(gossip3Result).isFalse(); - verify(ibftNetworkPeers, times(1)) - .multicastToValidatorsExcept(messageData, newArrayList(senderAddress, payload.getSender())); + verify(validatorMulticaster, times(1)) + .send(messageData, newArrayList(senderAddress, payload.getSender())); { final SignedData nextPayload = @@ -183,12 +183,12 @@ public class IbftGossipTest { final boolean gossip4Result = ibftGossip.gossipMessage(message); assertThat(gossip4Result).isTrue(); - verify(ibftNetworkPeers, times(2)) - .multicastToValidatorsExcept(messageData, newArrayList(senderAddress, payload.getSender())); + verify(validatorMulticaster, times(2)) + .send(messageData, newArrayList(senderAddress, payload.getSender())); final boolean gossip5Result = ibftGossip.gossipMessage(message); assertThat(gossip5Result).isFalse(); - verify(ibftNetworkPeers, times(2)) - .multicastToValidatorsExcept(messageData, newArrayList(senderAddress, payload.getSender())); + verify(validatorMulticaster, times(2)) + .send(messageData, newArrayList(senderAddress, payload.getSender())); } } diff --git a/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/network/IbftNetworkPeersTest.java b/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/network/ValidatorPeersTest.java similarity index 89% rename from consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/network/IbftNetworkPeersTest.java rename to consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/network/ValidatorPeersTest.java index f077ef790a..42d2e442fa 100644 --- a/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/network/IbftNetworkPeersTest.java +++ b/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/network/ValidatorPeersTest.java @@ -40,7 +40,7 @@ import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) -public class IbftNetworkPeersTest { +public class ValidatorPeersTest { private final List

validators = newArrayList(); private final List publicKeys = newArrayList(); @@ -70,13 +70,13 @@ public class IbftNetworkPeersTest { final ValidatorProvider validatorProvider = mock(ValidatorProvider.class); when(validatorProvider.getValidators()).thenReturn(validators); - final IbftNetworkPeers peers = new IbftNetworkPeers(validatorProvider); + final ValidatorPeers peers = new ValidatorPeers(validatorProvider); for (final PeerConnection peer : peerConnections) { - peers.peerAdded(peer); + peers.add(peer); } final MessageData messageToSend = new RawMessage(1, BytesValue.EMPTY); - peers.multicastToValidators(messageToSend); + peers.send(messageToSend); verify(peerConnections.get(0), times(1)).sendForProtocol("IBF", messageToSend); verify(peerConnections.get(1), never()).sendForProtocol(any(), any()); @@ -91,13 +91,13 @@ public class IbftNetworkPeersTest { final ValidatorProvider validatorProvider = mock(ValidatorProvider.class); when(validatorProvider.getValidators()).thenReturn(validators); - final IbftNetworkPeers peers = new IbftNetworkPeers(validatorProvider); + final ValidatorPeers peers = new ValidatorPeers(validatorProvider); // only add peer connections 1, 2 & 3, none of which should be invoked. - newArrayList(1, 2, 3).forEach(i -> peers.peerAdded(peerConnections.get(i))); + newArrayList(1, 2, 3).forEach(i -> peers.add(peerConnections.get(i))); final MessageData messageToSend = new RawMessage(1, BytesValue.EMPTY); - peers.multicastToValidators(messageToSend); + peers.send(messageToSend); verify(peerConnections.get(0), never()).sendForProtocol(any(), any()); verify(peerConnections.get(1), never()).sendForProtocol(any(), any()); @@ -114,13 +114,13 @@ public class IbftNetworkPeersTest { final ValidatorProvider validatorProvider = mock(ValidatorProvider.class); when(validatorProvider.getValidators()).thenReturn(validators); - final IbftNetworkPeers peers = new IbftNetworkPeers(validatorProvider); + final ValidatorPeers peers = new ValidatorPeers(validatorProvider); for (final PeerConnection peer : peerConnections) { - peers.peerAdded(peer); + peers.add(peer); } final MessageData messageToSend = new RawMessage(1, BytesValue.EMPTY); - peers.multicastToValidatorsExcept(messageToSend, newArrayList(validatorAddress)); + peers.send(messageToSend, newArrayList(validatorAddress)); verify(peerConnections.get(0), never()).sendForProtocol(any(), any()); verify(peerConnections.get(1), times(1)).sendForProtocol(any(), any()); diff --git a/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java b/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java index f64432dfdb..b44c7e3fef 100644 --- a/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java +++ b/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java @@ -34,6 +34,7 @@ import tech.pegasys.pantheon.consensus.ibft.IbftExtraData; import tech.pegasys.pantheon.consensus.ibft.RoundTimer; import tech.pegasys.pantheon.consensus.ibft.blockcreation.IbftBlockCreator; import tech.pegasys.pantheon.consensus.ibft.ibftevent.RoundExpiry; +import tech.pegasys.pantheon.consensus.ibft.network.IbftMessageTransmitter; import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload; import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; import tech.pegasys.pantheon.consensus.ibft.payload.NewRoundPayload; diff --git a/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftRoundTest.java b/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftRoundTest.java index 1ade260e2f..1b21e5f4be 100644 --- a/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftRoundTest.java +++ b/consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftRoundTest.java @@ -28,6 +28,7 @@ import tech.pegasys.pantheon.consensus.ibft.IbftBlockHashing; import tech.pegasys.pantheon.consensus.ibft.IbftContext; import tech.pegasys.pantheon.consensus.ibft.IbftExtraData; import tech.pegasys.pantheon.consensus.ibft.blockcreation.IbftBlockCreator; +import tech.pegasys.pantheon.consensus.ibft.network.IbftMessageTransmitter; import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate; import tech.pegasys.pantheon.consensus.ibft.payload.ProposalPayload; diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonController.java b/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonController.java index 5500d491c2..b4974940d2 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonController.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonController.java @@ -33,7 +33,7 @@ import tech.pegasys.pantheon.consensus.ibft.blockcreation.IbftBlockCreatorFactor import tech.pegasys.pantheon.consensus.ibft.blockcreation.IbftMiningCoordinator; import tech.pegasys.pantheon.consensus.ibft.blockcreation.ProposerSelector; import tech.pegasys.pantheon.consensus.ibft.jsonrpc.IbftJsonRpcMethodsFactory; -import tech.pegasys.pantheon.consensus.ibft.network.IbftNetworkPeers; +import tech.pegasys.pantheon.consensus.ibft.network.ValidatorPeers; import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; import tech.pegasys.pantheon.consensus.ibft.protocol.IbftProtocolManager; import tech.pegasys.pantheon.consensus.ibft.protocol.IbftSubProtocol; @@ -199,8 +199,8 @@ public class IbftPantheonController implements PantheonController { final ProposerSelector proposerSelector = new ProposerSelector(blockchain, voteTally, blockInterface, true); - final IbftNetworkPeers peers = - new IbftNetworkPeers(protocolContext.getConsensusState().getVoteTally()); + final ValidatorPeers peers = + new ValidatorPeers(protocolContext.getConsensusState().getVoteTally()); final BlockHeaderValidator blockHeaderValidator = IbftBlockHeaderValidationRulesetFactory.ibftProposedBlockValidator(