Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Ibft Integration Tests - Spurious Behaviour #615

Merged
merged 3 commits into from
Jan 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package tech.pegasys.pantheon.consensus.ibft.support;

import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.EventMultiplexer;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.statemachine.IbftController;
import tech.pegasys.pantheon.consensus.ibft.statemachine.IbftFinalState;
Expand All @@ -39,16 +40,19 @@ public class TestContext {
private final MutableBlockchain blockchain;
private final IbftController controller;
private final IbftFinalState finalState;
private final EventMultiplexer eventMultiplexer;

public TestContext(
final Map<Address, ValidatorPeer> remotePeers,
final MutableBlockchain blockchain,
final IbftController controller,
final IbftFinalState finalState) {
final IbftFinalState finalState,
final EventMultiplexer eventMultiplexer) {
this.remotePeers = remotePeers;
this.blockchain = blockchain;
this.controller = controller;
this.finalState = finalState;
this.eventMultiplexer = eventMultiplexer;
}

public MutableBlockchain getBlockchain() {
Expand All @@ -59,6 +63,10 @@ public IbftController getController() {
return controller;
}

public EventMultiplexer getEventMultiplexer() {
return eventMultiplexer;
}

public MessageFactory getLocalNodeMessageFactory() {
return finalState.getMessageFactory();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import tech.pegasys.pantheon.consensus.common.VoteTally;
import tech.pegasys.pantheon.consensus.common.VoteTallyUpdater;
import tech.pegasys.pantheon.consensus.ibft.BlockTimer;
import tech.pegasys.pantheon.consensus.ibft.EventMultiplexer;
import tech.pegasys.pantheon.consensus.ibft.IbftBlockHashing;
import tech.pegasys.pantheon.consensus.ibft.IbftBlockInterface;
import tech.pegasys.pantheon.consensus.ibft.IbftContext;
Expand Down Expand Up @@ -82,10 +83,15 @@ private static class ControllerAndState {

private IbftController controller;
private IbftFinalState finalState;
private EventMultiplexer eventMultiplexer;

public ControllerAndState(final IbftController controller, final IbftFinalState finalState) {
public ControllerAndState(
final IbftController controller,
final IbftFinalState finalState,
final EventMultiplexer eventMultiplexer) {
this.controller = controller;
this.finalState = finalState;
this.eventMultiplexer = eventMultiplexer;
}

public IbftController getController() {
Expand All @@ -95,6 +101,10 @@ public IbftController getController() {
public IbftFinalState getFinalState() {
return finalState;
}

public EventMultiplexer getEventMultiplexer() {
return eventMultiplexer;
}
}

public static final int EPOCH_LENGTH = 10_000;
Expand Down Expand Up @@ -158,7 +168,7 @@ public TestContext build() {
new ValidatorPeer(
nodeParams,
new MessageFactory(nodeParams.getNodeKeyPair()),
controllerAndState.getController()),
controllerAndState.getEventMultiplexer()),
(u, v) -> {
throw new IllegalStateException(String.format("Duplicate key %s", u));
},
Expand All @@ -170,7 +180,8 @@ public TestContext build() {
remotePeers,
blockChain,
controllerAndState.getController(),
controllerAndState.getFinalState());
controllerAndState.getFinalState(),
controllerAndState.getEventMultiplexer());
}

private static Block createGenesisBlock(final Set<Address> validators) {
Expand Down Expand Up @@ -283,8 +294,10 @@ private static ControllerAndState createControllerAndFinalState(
messageValidatorFactory),
new HashMap<>(),
gossiper);

final EventMultiplexer eventMultiplexer = new EventMultiplexer(ibftController);
//////////////////////////// END IBFT PantheonController ////////////////////////////

return new ControllerAndState(ibftController, finalState);
return new ControllerAndState(ibftController, finalState, eventMultiplexer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

public class TestHelpers {

public static SignedData<CommitPayload> createSignedCommentPayload(
public static SignedData<CommitPayload> createSignedCommitPayload(
final ConsensusRoundIdentifier roundId, final Block block, final KeyPair signingKeyPair) {

final IbftExtraData extraData = IbftExtraData.decode(block.getHeader().getExtraData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
package tech.pegasys.pantheon.consensus.ibft.support;

import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.EventMultiplexer;
import tech.pegasys.pantheon.consensus.ibft.ibftevent.IbftEvents;
import tech.pegasys.pantheon.consensus.ibft.ibftevent.IbftReceivedMessageEvent;
import tech.pegasys.pantheon.consensus.ibft.messagedata.CommitMessageData;
import tech.pegasys.pantheon.consensus.ibft.messagedata.NewRoundMessageData;
import tech.pegasys.pantheon.consensus.ibft.messagedata.PrepareMessageData;
Expand All @@ -29,7 +29,6 @@
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangeCertificate;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.statemachine.IbftController;
import tech.pegasys.pantheon.crypto.SECP256K1;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.crypto.SECP256K1.Signature;
Expand All @@ -55,22 +54,26 @@ public class ValidatorPeer {
private final PeerConnection peerConnection = new StubbedPeerConnection();
private final List<MessageData> receivedMessages = Lists.newArrayList();

private final IbftController localNodeController;
private final EventMultiplexer localEventMultiplexer;

public ValidatorPeer(
final NodeParams nodeParams,
final MessageFactory messageFactory,
final IbftController localNodeController) {
final EventMultiplexer localEventMultiplexer) {
this.nodeKeys = nodeParams.getNodeKeyPair();
this.nodeAddress = nodeParams.getAddress();
this.messageFactory = messageFactory;
this.localNodeController = localNodeController;
this.localEventMultiplexer = localEventMultiplexer;
}

public Address getNodeAddress() {
return nodeAddress;
}

public KeyPair getNodeKeys() {
return nodeKeys;
}

public SignedData<ProposalPayload> injectProposal(
final ConsensusRoundIdentifier rId, final Block block) {
final SignedData<ProposalPayload> payload =
Expand All @@ -94,7 +97,13 @@ public Signature getBlockSignature(final Hash digest) {

public SignedData<CommitPayload> injectCommit(
final ConsensusRoundIdentifier rId, final Hash digest) {
final Signature commitSeal = getBlockSignature(digest);
final Signature commitSeal = SECP256K1.sign(digest, nodeKeys);

return injectCommit(rId, digest, commitSeal);
}

public SignedData<CommitPayload> injectCommit(
final ConsensusRoundIdentifier rId, final Hash digest, final Signature commitSeal) {
final SignedData<CommitPayload> payload =
messageFactory.createSignedCommitPayload(rId, digest, commitSeal);
injectMessage(CommitMessageData.create(payload));
Expand Down Expand Up @@ -134,8 +143,7 @@ public void clearReceivedMessages() {

public void injectMessage(final MessageData msgData) {
final DefaultMessage message = new DefaultMessage(peerConnection, msgData);
localNodeController.handleMessageEvent(
(IbftReceivedMessageEvent) IbftEvents.fromMessage(message));
localEventMultiplexer.handleIbftEvent(IbftEvents.fromMessage(message));
}

public MessageFactory getMessageFactory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import static org.assertj.core.util.Lists.emptyList;
import static tech.pegasys.pantheon.consensus.ibft.support.MessageReceptionHelpers.assertPeersReceivedExactly;
import static tech.pegasys.pantheon.consensus.ibft.support.MessageReceptionHelpers.assertPeersReceivedNoMessages;
import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createSignedCommentPayload;
import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createSignedCommitPayload;

import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.IbftHelpers;
Expand Down Expand Up @@ -107,7 +107,7 @@ public void messagesForFutureHeightAreBufferedUntilChainHeightCatchesUp() {
futureHeightRoundId, futureHeightBlock.getHash());

final SignedData<CommitPayload> expectedCommitMessage =
createSignedCommentPayload(
createSignedCommitPayload(
futureHeightRoundId, futureHeightBlock, context.getLocalNodeParams().getNodeKeyPair());

assertPeersReceivedExactly(roles.getAllPeers(), expectedPrepareMessage, expectedCommitMessage);
Expand Down Expand Up @@ -172,7 +172,7 @@ public void multipleNewChainHeadEventsDoesNotRestartCurrentHeightManager() {
roles.getNonProposingPeer(1).injectPrepare(roundId, currentHeightBlock.getHash());

final SignedData<CommitPayload> expectedCommitMessage =
createSignedCommentPayload(
createSignedCommitPayload(
roundId, currentHeightBlock, context.getLocalNodeParams().getNodeKeyPair());
assertPeersReceivedExactly(roles.getAllPeers(), expectedCommitMessage);
}
Expand Down Expand Up @@ -247,7 +247,7 @@ public void correctMessagesAreExtractedFromFutureHeightBuffer() {
futureHeightRoundId, futureHeightBlock.getHash());

final SignedData<CommitPayload> expectedCommitMessage =
createSignedCommentPayload(
createSignedCommitPayload(
futureHeightRoundId, futureHeightBlock, context.getLocalNodeParams().getNodeKeyPair());

// Assert ONLY a prepare message was received, not any commits (i.e. futureHeightRoundId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static tech.pegasys.pantheon.consensus.ibft.support.MessageReceptionHelpers.assertPeersReceivedExactly;
import static tech.pegasys.pantheon.consensus.ibft.support.MessageReceptionHelpers.assertPeersReceivedNoMessages;
import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createSignedCommentPayload;
import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createSignedCommitPayload;

import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.ibftevent.BlockTimerExpiry;
Expand Down Expand Up @@ -70,7 +70,7 @@ public void setup() {
localNodeMessageFactory.createSignedProposalPayload(roundId, expectedProposedBlock);

expectedTxCommit =
createSignedCommentPayload(
createSignedCommitPayload(
roundId, expectedProposedBlock, context.getLocalNodeParams().getNodeKeyPair());

// Start the Controller, and trigger "block timer" to send proposal.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static tech.pegasys.pantheon.consensus.ibft.support.MessageReceptionHelpers.assertPeersReceivedExactly;
import static tech.pegasys.pantheon.consensus.ibft.support.MessageReceptionHelpers.assertPeersReceivedNoMessages;
import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createSignedCommentPayload;
import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createSignedCommitPayload;

import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload;
Expand Down Expand Up @@ -58,7 +58,7 @@ public void setup() {
localNodeMessageFactory.createSignedPreparePayload(roundId, blockToPropose.getHash());

expectedTxCommit =
createSignedCommentPayload(
createSignedCommitPayload(
roundId, blockToPropose, context.getLocalNodeParams().getNodeKeyPair());

context.getController().start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public void receiveRoundStateIsNotLostIfASecondNewRoundMessageIsReceivedForCurre
nextRoles.getNonProposingPeer(1).injectPrepare(nextRoundId, reproposedBlock.getHash());

final SignedData<CommitPayload> expectedCommit =
TestHelpers.createSignedCommentPayload(
TestHelpers.createSignedCommitPayload(
nextRoundId, reproposedBlock, context.getLocalNodeParams().getNodeKeyPair());

assertPeersReceivedExactly(nextRoles.getAllPeers(), expectedCommit);
Expand Down
Loading