Rename IBFT networking classes (#555)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
tmohay 6 years ago committed by GitHub
parent 00ff29919d
commit 1cee74dc78
  1. 13
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/StubValidatorMulticaster.java
  2. 10
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestContextFactory.java
  3. 18
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/IbftGossip.java
  4. 17
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/IbftMessageTransmitter.java
  5. 22
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/PeerConnectionTracker.java
  6. 7
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/ValidatorMulticaster.java
  7. 21
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/ValidatorPeers.java
  8. 13
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/protocol/IbftProtocolManager.java
  9. 1
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftBlockHeightManager.java
  10. 2
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftController.java
  11. 15
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftFinalState.java
  12. 1
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftRound.java
  13. 30
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/IbftGossipTest.java
  14. 20
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/network/ValidatorPeersTest.java
  15. 1
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java
  16. 1
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftRoundTest.java
  17. 6
      pantheon/src/main/java/tech/pegasys/pantheon/controller/IbftPantheonController.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<ValidatorPeer> validatorNodes = Lists.newArrayList();
public StubIbftMulticaster() {}
public StubValidatorMulticaster() {}
public void addNetworkPeers(final Collection<ValidatorPeer> 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<Address> exceptAddresses) {
public void send(final MessageData message, final Collection<Address> blackList) {
validatorNodes
.stream()
.filter(peer -> !exceptAddresses.contains(peer.getNodeAddress()))
.filter(peer -> !blackList.contains(peer.getNodeAddress()))
.forEach(peer -> peer.handleReceivedMessage(message));
}
}

@ -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(

@ -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<Address> excludeAddressesList =
Lists.newArrayList(
message.getConnection().getPeer().getAddress(), signedData.getSender());
peers.multicastToValidatorsExcept(messageData, excludeAddressesList);
multicaster.send(messageData, excludeAddressesList);
seenMessages.add(signature);
return true;
}

@ -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);
}
}

@ -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);
}

@ -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<Address> exceptAddresses);
void send(final MessageData message, final Collection<Address> blackList);
}

@ -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<Address, PeerConnection> 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<Address> validators = validatorProvider.getValidators();
sendMessageToSpecificAddresses(validators, message);
}
@Override
public void multicastToValidatorsExcept(
final MessageData message, final Collection<Address> exceptAddresses) {
public void send(final MessageData message, final Collection<Address> blackList) {
final Collection<Address> includedValidators =
validatorProvider
.getValidators()
.stream()
.filter(a -> !exceptAddresses.contains(a))
.filter(a -> !blackList.contains(a))
.collect(Collectors.toSet());
sendMessageToSpecificAddresses(includedValidators, message);
}

@ -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

@ -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;

@ -61,7 +61,7 @@ public class IbftController {
ibftFinalState,
ibftBlockHeightManagerFactory,
Maps.newHashMap(),
new IbftGossip(ibftFinalState.getPeers()));
new IbftGossip(ibftFinalState.getValidatorMulticaster()));
}
@VisibleForTesting

@ -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() {

@ -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;

@ -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 <P extends Payload> 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<ProposalPayload> 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<ProposalPayload> 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()));
}
}

@ -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<Address> validators = newArrayList();
private final List<PublicKey> 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());

@ -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;

@ -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;

@ -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<IbftContext> {
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<IbftContext> blockHeaderValidator =
IbftBlockHeaderValidationRulesetFactory.ibftProposedBlockValidator(

Loading…
Cancel
Save