Moved IBFT Message factory to use wrapped message types (#744)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
tmohay 6 years ago committed by GitHub
parent 00f0dbfb13
commit 5b796a4d07
  1. 69
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/RoundSpecificPeers.java
  2. 22
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestHelpers.java
  3. 42
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/ValidatorPeer.java
  4. 38
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/FutureHeightTest.java
  5. 11
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/FutureRoundTest.java
  6. 43
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/GossipTest.java
  7. 14
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/LocalNodeIsProposerTest.java
  8. 14
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/LocalNodeNotProposerTest.java
  9. 36
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/ReceivedNewRoundTest.java
  10. 110
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/RoundChangeTest.java
  11. 14
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/SpuriousBehaviourTest.java
  12. 10
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/messagewrappers/NewRound.java
  13. 16
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/IbftMessageTransmitter.java
  14. 25
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/payload/MessageFactory.java
  15. 7
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/payload/NewRoundPayload.java
  16. 14
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/payload/RoundChangeCertificate.java
  17. 5
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftBlockHeightManager.java
  18. 22
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftRound.java
  19. 51
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/IbftHelpersTest.java
  20. 27
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/TestHelpers.java
  21. 51
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java
  22. 64
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftRoundTest.java
  23. 16
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/RoundChangeManagerTest.java
  24. 103
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/RoundStateTest.java
  25. 107
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/validation/MessageValidatorTest.java
  26. 135
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/validation/NewRoundMessageValidatorTest.java
  27. 77
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/validation/RoundChangeMessageValidatorTest.java

@ -23,6 +23,8 @@ import tech.pegasys.pantheon.consensus.ibft.messagedata.NewRoundMessageData;
import tech.pegasys.pantheon.consensus.ibft.messagedata.PrepareMessageData; import tech.pegasys.pantheon.consensus.ibft.messagedata.PrepareMessageData;
import tech.pegasys.pantheon.consensus.ibft.messagedata.ProposalMessageData; import tech.pegasys.pantheon.consensus.ibft.messagedata.ProposalMessageData;
import tech.pegasys.pantheon.consensus.ibft.messagedata.RoundChangeMessageData; import tech.pegasys.pantheon.consensus.ibft.messagedata.RoundChangeMessageData;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.IbftMessage;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.RoundChange;
import tech.pegasys.pantheon.consensus.ibft.payload.Payload; import tech.pegasys.pantheon.consensus.ibft.payload.Payload;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparePayload; import tech.pegasys.pantheon.consensus.ibft.payload.PreparePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate; import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate;
@ -80,7 +82,7 @@ public class RoundSpecificPeers {
final ConsensusRoundIdentifier targetRound) { final ConsensusRoundIdentifier targetRound) {
return nonProposingPeers return nonProposingPeers
.stream() .stream()
.map(peer -> peer.injectRoundChange(targetRound, empty())) .map(peer -> peer.injectRoundChange(targetRound, empty()).getSignedPayload())
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@ -89,20 +91,24 @@ public class RoundSpecificPeers {
} }
public List<SignedData<RoundChangePayload>> roundChange(final ConsensusRoundIdentifier roundId) { public List<SignedData<RoundChangePayload>> roundChange(final ConsensusRoundIdentifier roundId) {
final List<SignedData<RoundChangePayload>> changes = Lists.newArrayList(); final List<RoundChange> changes = Lists.newArrayList();
for (final ValidatorPeer peer : peers) { for (final ValidatorPeer peer : peers) {
changes.add(peer.injectRoundChange(roundId, empty())); changes.add(peer.injectRoundChange(roundId, empty()));
} }
return changes; return changes.stream().map(RoundChange::getSignedPayload).collect(Collectors.toList());
} }
public List<SignedData<RoundChangePayload>> createSignedRoundChangePayload( public List<SignedData<RoundChangePayload>> createSignedRoundChangePayload(
final ConsensusRoundIdentifier roundId) { final ConsensusRoundIdentifier roundId) {
return peers return peers
.stream() .stream()
.map(p -> p.getMessageFactory().createSignedRoundChangePayload(roundId, empty())) .map(
p ->
p.getMessageFactory()
.createSignedRoundChangePayload(roundId, empty())
.getSignedPayload())
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@ -113,7 +119,8 @@ public class RoundSpecificPeers {
.map( .map(
p -> p ->
p.getMessageFactory() p.getMessageFactory()
.createSignedRoundChangePayload(roundId, Optional.of(preparedCertificate))) .createSignedRoundChangePayload(roundId, Optional.of(preparedCertificate))
.getSignedPayload())
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@ -125,11 +132,15 @@ public class RoundSpecificPeers {
nonProposingPeers.forEach(peer -> peer.injectCommit(roundId, hash)); nonProposingPeers.forEach(peer -> peer.injectCommit(roundId, hash));
} }
Collection<SignedData<PreparePayload>> createSignedPreparePayloadOfNonProposing( public Collection<SignedData<PreparePayload>> createSignedPreparePayloadOfNonProposing(
final ConsensusRoundIdentifier preparedRound, final Hash hash) { final ConsensusRoundIdentifier preparedRound, final Hash hash) {
return nonProposingPeers return nonProposingPeers
.stream() .stream()
.map(role -> role.getMessageFactory().createSignedPreparePayload(preparedRound, hash)) .map(
role ->
role.getMessageFactory()
.createSignedPreparePayload(preparedRound, hash)
.getSignedPayload())
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@ -146,38 +157,35 @@ public class RoundSpecificPeers {
} }
@SafeVarargs @SafeVarargs
public final void verifyMessagesReceivedPropser(final SignedData<? extends Payload>... msgs) { public final void verifyMessagesReceivedProposer(final IbftMessage<? extends Payload>... msgs) {
verifyMessagesReceived(ImmutableList.of(proposer), msgs); verifyMessagesReceived(ImmutableList.of(proposer), msgs);
} }
@SafeVarargs @SafeVarargs
public final void verifyMessagesReceivedNonPropsingExcluding( public final void verifyMessagesReceivedNonPropsingExcluding(
final ValidatorPeer exclude, final SignedData<? extends Payload>... msgs) { final ValidatorPeer exclude, final IbftMessage<? extends Payload>... msgs) {
final Collection<ValidatorPeer> candidates = Lists.newArrayList(nonProposingPeers); final Collection<ValidatorPeer> candidates = Lists.newArrayList(nonProposingPeers);
candidates.remove(exclude); candidates.remove(exclude);
verifyMessagesReceived(candidates, msgs); verifyMessagesReceived(candidates, msgs);
} }
@SafeVarargs public final void verifyMessagesReceivedNonPropsing(final IbftMessage<?>... msgs) {
public final void verifyMessagesReceivedNonPropsing(final SignedData<? extends Payload>... msgs) {
verifyMessagesReceived(nonProposingPeers, msgs); verifyMessagesReceived(nonProposingPeers, msgs);
} }
@SafeVarargs public final void verifyMessagesReceived(final IbftMessage<?>... msgs) {
public final void verifyMessagesReceived(final SignedData<? extends Payload>... msgs) {
verifyMessagesReceived(peers, msgs); verifyMessagesReceived(peers, msgs);
} }
@SafeVarargs private void verifyMessagesReceived(
private final void verifyMessagesReceived( final Collection<ValidatorPeer> candidates, final IbftMessage<?>... msgs) {
final Collection<ValidatorPeer> candidates, final SignedData<? extends Payload>... msgs) {
candidates.forEach(n -> assertThat(n.getReceivedMessages().size()).isEqualTo(msgs.length)); candidates.forEach(n -> assertThat(n.getReceivedMessages().size()).isEqualTo(msgs.length));
List<SignedData<? extends Payload>> msgList = Arrays.asList(msgs); List<IbftMessage<? extends Payload>> msgList = Arrays.asList(msgs);
for (int i = 0; i < msgList.size(); i++) { for (int i = 0; i < msgList.size(); i++) {
final int index = i; final int index = i;
final SignedData<? extends Payload> msg = msgList.get(index); final IbftMessage<? extends Payload> msg = msgList.get(index);
candidates.forEach( candidates.forEach(
n -> { n -> {
final List<MessageData> rxMsgs = n.getReceivedMessages(); final List<MessageData> rxMsgs = n.getReceivedMessages();
@ -188,36 +196,29 @@ public class RoundSpecificPeers {
candidates.forEach(ValidatorPeer::clearReceivedMessages); candidates.forEach(ValidatorPeer::clearReceivedMessages);
} }
private void verifyMessage( private void verifyMessage(final MessageData actual, final IbftMessage<?> expectedMessage) {
final MessageData actual, final SignedData<? extends Payload> signedExpectedPayload) { IbftMessage<?> actualSignedPayload = null;
final Payload expectedPayload = signedExpectedPayload.getPayload();
SignedData<?> actualSignedPayload = null;
switch (expectedPayload.getMessageType()) { switch (expectedMessage.getMessageType()) {
case IbftV2.PROPOSAL: case IbftV2.PROPOSAL:
actualSignedPayload = actualSignedPayload = ProposalMessageData.fromMessageData(actual).decode();
ProposalMessageData.fromMessageData(actual).decode().getSignedPayload();
break; break;
case IbftV2.PREPARE: case IbftV2.PREPARE:
actualSignedPayload = actualSignedPayload = PrepareMessageData.fromMessageData(actual).decode();
PrepareMessageData.fromMessageData(actual).decode().getSignedPayload();
break; break;
case IbftV2.COMMIT: case IbftV2.COMMIT:
actualSignedPayload = CommitMessageData.fromMessageData(actual).decode().getSignedPayload(); actualSignedPayload = CommitMessageData.fromMessageData(actual).decode();
break; break;
case IbftV2.NEW_ROUND: case IbftV2.NEW_ROUND:
actualSignedPayload = actualSignedPayload = NewRoundMessageData.fromMessageData(actual).decode();
NewRoundMessageData.fromMessageData(actual).decode().getSignedPayload();
break; break;
case IbftV2.ROUND_CHANGE: case IbftV2.ROUND_CHANGE:
actualSignedPayload = actualSignedPayload = RoundChangeMessageData.fromMessageData(actual).decode();
RoundChangeMessageData.fromMessageData(actual).decode().getSignedPayload();
break; break;
default: default:
fail("Illegal IBFTV2 message type."); fail("Illegal IBFTV2 message type.");
break; break;
} }
assertThat(signedExpectedPayload) assertThat(expectedMessage).isEqualToComparingFieldByFieldRecursively(actualSignedPayload);
.isEqualToComparingFieldByFieldRecursively(actualSignedPayload);
} }
} }

@ -15,11 +15,11 @@ package tech.pegasys.pantheon.consensus.ibft.support;
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier; import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.IbftBlockHashing; import tech.pegasys.pantheon.consensus.ibft.IbftBlockHashing;
import tech.pegasys.pantheon.consensus.ibft.IbftExtraData; import tech.pegasys.pantheon.consensus.ibft.IbftExtraData;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.NewRound;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Proposal;
import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload; import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.NewRoundPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate; import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate;
import tech.pegasys.pantheon.consensus.ibft.payload.ProposalPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangeCertificate; import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangeCertificate;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangePayload; import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData; import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
@ -44,7 +44,9 @@ public class TestHelpers {
final MessageFactory messageFactory = new MessageFactory(signingKeyPair); final MessageFactory messageFactory = new MessageFactory(signingKeyPair);
return messageFactory.createSignedCommitPayload(roundId, block.getHash(), commitSeal); return messageFactory
.createSignedCommitPayload(roundId, block.getHash(), commitSeal)
.getSignedPayload();
} }
public static PreparedCertificate createValidPreparedCertificate( public static PreparedCertificate createValidPreparedCertificate(
@ -52,20 +54,26 @@ public class TestHelpers {
final RoundSpecificPeers peers = context.roundSpecificPeers(preparedRound); final RoundSpecificPeers peers = context.roundSpecificPeers(preparedRound);
return new PreparedCertificate( return new PreparedCertificate(
peers.getProposer().getMessageFactory().createSignedProposalPayload(preparedRound, block), peers
.getProposer()
.getMessageFactory()
.createSignedProposalPayload(preparedRound, block)
.getSignedPayload(),
peers.createSignedPreparePayloadOfNonProposing(preparedRound, block.getHash())); peers.createSignedPreparePayloadOfNonProposing(preparedRound, block.getHash()));
} }
public static SignedData<NewRoundPayload> injectEmptyNewRound( public static NewRound injectEmptyNewRound(
final ConsensusRoundIdentifier targetRoundId, final ConsensusRoundIdentifier targetRoundId,
final ValidatorPeer proposer, final ValidatorPeer proposer,
final List<SignedData<RoundChangePayload>> roundChangePayloads, final List<SignedData<RoundChangePayload>> roundChangePayloads,
final Block blockToPropose) { final Block blockToPropose) {
final SignedData<ProposalPayload> proposal = final Proposal proposal =
proposer.getMessageFactory().createSignedProposalPayload(targetRoundId, blockToPropose); proposer.getMessageFactory().createSignedProposalPayload(targetRoundId, blockToPropose);
return proposer.injectNewRound( return proposer.injectNewRound(
targetRoundId, new RoundChangeCertificate(roundChangePayloads), proposal); targetRoundId,
new RoundChangeCertificate(roundChangePayloads),
proposal.getSignedPayload());
} }
} }

@ -25,14 +25,10 @@ import tech.pegasys.pantheon.consensus.ibft.messagewrappers.NewRound;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Prepare; import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Prepare;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Proposal; import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Proposal;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.RoundChange; import tech.pegasys.pantheon.consensus.ibft.messagewrappers.RoundChange;
import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.NewRoundPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate; import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate;
import tech.pegasys.pantheon.consensus.ibft.payload.ProposalPayload; import tech.pegasys.pantheon.consensus.ibft.payload.ProposalPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangeCertificate; 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.payload.SignedData;
import tech.pegasys.pantheon.crypto.SECP256K1; import tech.pegasys.pantheon.crypto.SECP256K1;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
@ -82,20 +78,16 @@ public class ValidatorPeer {
return nodeKeys; return nodeKeys;
} }
public SignedData<ProposalPayload> injectProposal( public Proposal injectProposal(final ConsensusRoundIdentifier rId, final Block block) {
final ConsensusRoundIdentifier rId, final Block block) { final Proposal payload = messageFactory.createSignedProposalPayload(rId, block);
final SignedData<ProposalPayload> payload =
messageFactory.createSignedProposalPayload(rId, block);
injectMessage(ProposalMessageData.create(new Proposal(payload))); injectMessage(ProposalMessageData.create(payload));
return payload; return payload;
} }
public SignedData<PreparePayload> injectPrepare( public Prepare injectPrepare(final ConsensusRoundIdentifier rId, final Hash digest) {
final ConsensusRoundIdentifier rId, final Hash digest) { final Prepare payload = messageFactory.createSignedPreparePayload(rId, digest);
final SignedData<PreparePayload> payload = injectMessage(PrepareMessageData.create(payload));
messageFactory.createSignedPreparePayload(rId, digest);
injectMessage(PrepareMessageData.create(new Prepare(payload)));
return payload; return payload;
} }
@ -103,37 +95,35 @@ public class ValidatorPeer {
return SECP256K1.sign(digest, nodeKeys); return SECP256K1.sign(digest, nodeKeys);
} }
public SignedData<CommitPayload> injectCommit( public Commit injectCommit(final ConsensusRoundIdentifier rId, final Hash digest) {
final ConsensusRoundIdentifier rId, final Hash digest) {
final Signature commitSeal = SECP256K1.sign(digest, nodeKeys); final Signature commitSeal = SECP256K1.sign(digest, nodeKeys);
return injectCommit(rId, digest, commitSeal); return injectCommit(rId, digest, commitSeal);
} }
public SignedData<CommitPayload> injectCommit( public Commit injectCommit(
final ConsensusRoundIdentifier rId, final Hash digest, final Signature commitSeal) { final ConsensusRoundIdentifier rId, final Hash digest, final Signature commitSeal) {
final SignedData<CommitPayload> payload = final Commit payload = messageFactory.createSignedCommitPayload(rId, digest, commitSeal);
messageFactory.createSignedCommitPayload(rId, digest, commitSeal); injectMessage(CommitMessageData.create(payload));
injectMessage(CommitMessageData.create(new Commit(payload)));
return payload; return payload;
} }
public SignedData<NewRoundPayload> injectNewRound( public NewRound injectNewRound(
final ConsensusRoundIdentifier rId, final ConsensusRoundIdentifier rId,
final RoundChangeCertificate roundChangeCertificate, final RoundChangeCertificate roundChangeCertificate,
final SignedData<ProposalPayload> proposalPayload) { final SignedData<ProposalPayload> proposalPayload) {
final SignedData<NewRoundPayload> payload = final NewRound payload =
messageFactory.createSignedNewRoundPayload(rId, roundChangeCertificate, proposalPayload); messageFactory.createSignedNewRoundPayload(rId, roundChangeCertificate, proposalPayload);
injectMessage(NewRoundMessageData.create(new NewRound(payload))); injectMessage(NewRoundMessageData.create(payload));
return payload; return payload;
} }
public SignedData<RoundChangePayload> injectRoundChange( public RoundChange injectRoundChange(
final ConsensusRoundIdentifier rId, final Optional<PreparedCertificate> preparedCertificate) { final ConsensusRoundIdentifier rId, final Optional<PreparedCertificate> preparedCertificate) {
final SignedData<RoundChangePayload> payload = final RoundChange payload =
messageFactory.createSignedRoundChangePayload(rId, preparedCertificate); messageFactory.createSignedRoundChangePayload(rId, preparedCertificate);
injectMessage(RoundChangeMessageData.create(new RoundChange(payload))); injectMessage(RoundChangeMessageData.create(payload));
return payload; return payload;
} }

@ -19,10 +19,9 @@ import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createSig
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier; import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.IbftHelpers; import tech.pegasys.pantheon.consensus.ibft.IbftHelpers;
import tech.pegasys.pantheon.consensus.ibft.ibftevent.NewChainHead; import tech.pegasys.pantheon.consensus.ibft.ibftevent.NewChainHead;
import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload; import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Commit;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Prepare;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.support.RoundSpecificPeers; import tech.pegasys.pantheon.consensus.ibft.support.RoundSpecificPeers;
import tech.pegasys.pantheon.consensus.ibft.support.TestContext; import tech.pegasys.pantheon.consensus.ibft.support.TestContext;
import tech.pegasys.pantheon.consensus.ibft.support.TestContextBuilder; import tech.pegasys.pantheon.consensus.ibft.support.TestContextBuilder;
@ -89,13 +88,16 @@ public class FutureHeightTest {
.getController() .getController()
.handleNewBlockEvent(new NewChainHead(signedCurrentHeightBlock.getHeader())); .handleNewBlockEvent(new NewChainHead(signedCurrentHeightBlock.getHeader()));
final SignedData<PreparePayload> expectedPrepareMessage = final Prepare expectedPrepareMessage =
localNodeMessageFactory.createSignedPreparePayload( localNodeMessageFactory.createSignedPreparePayload(
futureHeightRoundId, futureHeightBlock.getHash()); futureHeightRoundId, futureHeightBlock.getHash());
final SignedData<CommitPayload> expectedCommitMessage = final Commit expectedCommitMessage =
createSignedCommitPayload( new Commit(
futureHeightRoundId, futureHeightBlock, context.getLocalNodeParams().getNodeKeyPair()); createSignedCommitPayload(
futureHeightRoundId,
futureHeightBlock,
context.getLocalNodeParams().getNodeKeyPair()));
peers.verifyMessagesReceived(expectedPrepareMessage, expectedCommitMessage); peers.verifyMessagesReceived(expectedPrepareMessage, expectedCommitMessage);
assertThat(context.getCurrentChainHeight()).isEqualTo(2); assertThat(context.getCurrentChainHeight()).isEqualTo(2);
@ -110,7 +112,7 @@ public class FutureHeightTest {
peers.getProposer().injectProposal(roundId, currentHeightBlock); peers.getProposer().injectProposal(roundId, currentHeightBlock);
peers.getNonProposing(0).injectPrepare(roundId, currentHeightBlock.getHash()); peers.getNonProposing(0).injectPrepare(roundId, currentHeightBlock.getHash());
final SignedData<PreparePayload> expectedPrepareMessage = final Prepare expectedPrepareMessage =
localNodeMessageFactory.createSignedPreparePayload(roundId, currentHeightBlock.getHash()); localNodeMessageFactory.createSignedPreparePayload(roundId, currentHeightBlock.getHash());
peers.verifyMessagesReceived(expectedPrepareMessage); peers.verifyMessagesReceived(expectedPrepareMessage);
@ -148,9 +150,10 @@ public class FutureHeightTest {
// Should only require 1 more prepare to close it out // Should only require 1 more prepare to close it out
peers.getNonProposing(1).injectPrepare(roundId, currentHeightBlock.getHash()); peers.getNonProposing(1).injectPrepare(roundId, currentHeightBlock.getHash());
final SignedData<CommitPayload> expectedCommitMessage = final Commit expectedCommitMessage =
createSignedCommitPayload( new Commit(
roundId, currentHeightBlock, context.getLocalNodeParams().getNodeKeyPair()); createSignedCommitPayload(
roundId, currentHeightBlock, context.getLocalNodeParams().getNodeKeyPair()));
peers.verifyMessagesReceived(expectedCommitMessage); peers.verifyMessagesReceived(expectedCommitMessage);
} }
@ -185,7 +188,7 @@ public class FutureHeightTest {
peers.verifyNoMessagesReceived(); peers.verifyNoMessagesReceived();
peers.getProposer().injectProposal(nextHeightRoundId, nextHeightBlock); peers.getProposer().injectProposal(nextHeightRoundId, nextHeightBlock);
final SignedData<PreparePayload> expectedPrepareMessage = final Prepare expectedPrepareMessage =
localNodeMessageFactory.createSignedPreparePayload( localNodeMessageFactory.createSignedPreparePayload(
nextHeightRoundId, nextHeightBlock.getHash()); nextHeightRoundId, nextHeightBlock.getHash());
@ -202,13 +205,16 @@ public class FutureHeightTest {
.getController() .getController()
.handleNewBlockEvent(new NewChainHead(signedNextHeightBlock.getHeader())); .handleNewBlockEvent(new NewChainHead(signedNextHeightBlock.getHeader()));
final SignedData<PreparePayload> expectedFuturePrepareMessage = final Prepare expectedFuturePrepareMessage =
localNodeMessageFactory.createSignedPreparePayload( localNodeMessageFactory.createSignedPreparePayload(
futureHeightRoundId, futureHeightBlock.getHash()); futureHeightRoundId, futureHeightBlock.getHash());
final SignedData<CommitPayload> expectedCommitMessage = final Commit expectedCommitMessage =
createSignedCommitPayload( new Commit(
futureHeightRoundId, futureHeightBlock, context.getLocalNodeParams().getNodeKeyPair()); createSignedCommitPayload(
futureHeightRoundId,
futureHeightBlock,
context.getLocalNodeParams().getNodeKeyPair()));
// Assert ONLY a prepare message was received, not any commits (i.e. futureHeightRoundId // Assert ONLY a prepare message was received, not any commits (i.e. futureHeightRoundId
// messages have not been used. // messages have not been used.

@ -17,10 +17,9 @@ import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.injectEmp
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier; import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.IbftHelpers; import tech.pegasys.pantheon.consensus.ibft.IbftHelpers;
import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload; import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Commit;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Prepare;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.support.RoundSpecificPeers; import tech.pegasys.pantheon.consensus.ibft.support.RoundSpecificPeers;
import tech.pegasys.pantheon.consensus.ibft.support.TestContext; import tech.pegasys.pantheon.consensus.ibft.support.TestContext;
import tech.pegasys.pantheon.consensus.ibft.support.TestContextBuilder; import tech.pegasys.pantheon.consensus.ibft.support.TestContextBuilder;
@ -99,7 +98,7 @@ public class FutureRoundTest {
futurePeers.createSignedRoundChangePayload(futureRoundId), futurePeers.createSignedRoundChangePayload(futureRoundId),
futureBlock); futureBlock);
final SignedData<PreparePayload> expectedPrepare = final Prepare expectedPrepare =
localNodeMessageFactory.createSignedPreparePayload(futureRoundId, futureBlock.getHash()); localNodeMessageFactory.createSignedPreparePayload(futureRoundId, futureBlock.getHash());
peers.verifyMessagesReceived(expectedPrepare); peers.verifyMessagesReceived(expectedPrepare);
@ -107,7 +106,7 @@ public class FutureRoundTest {
// following 1 more prepare, a commit msg will be sent // following 1 more prepare, a commit msg will be sent
futurePeers.getNonProposing(quorum - 3).injectPrepare(futureRoundId, futureBlock.getHash()); futurePeers.getNonProposing(quorum - 3).injectPrepare(futureRoundId, futureBlock.getHash());
final SignedData<CommitPayload> expectedCommit = final Commit expectedCommit =
localNodeMessageFactory.createSignedCommitPayload( localNodeMessageFactory.createSignedCommitPayload(
futureRoundId, futureRoundId,
futureBlock.getHash(), futureBlock.getHash(),
@ -143,7 +142,7 @@ public class FutureRoundTest {
futurePeers.createSignedRoundChangePayload(futureRoundId), futurePeers.createSignedRoundChangePayload(futureRoundId),
futureBlock); futureBlock);
final SignedData<PreparePayload> expectedFuturePrepare = final Prepare expectedFuturePrepare =
localNodeMessageFactory.createSignedPreparePayload(futureRoundId, futureBlock.getHash()); localNodeMessageFactory.createSignedPreparePayload(futureRoundId, futureBlock.getHash());
peers.verifyMessagesReceived(expectedFuturePrepare); peers.verifyMessagesReceived(expectedFuturePrepare);

@ -19,15 +19,13 @@ import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.IbftHelpers; import tech.pegasys.pantheon.consensus.ibft.IbftHelpers;
import tech.pegasys.pantheon.consensus.ibft.ibftevent.NewChainHead; import tech.pegasys.pantheon.consensus.ibft.ibftevent.NewChainHead;
import tech.pegasys.pantheon.consensus.ibft.messagedata.ProposalMessageData; import tech.pegasys.pantheon.consensus.ibft.messagedata.ProposalMessageData;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Commit;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.NewRound;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Prepare;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Proposal; import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Proposal;
import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload; import tech.pegasys.pantheon.consensus.ibft.messagewrappers.RoundChange;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.NewRoundPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.ProposalPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangeCertificate; 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.support.RoundSpecificPeers; import tech.pegasys.pantheon.consensus.ibft.support.RoundSpecificPeers;
import tech.pegasys.pantheon.consensus.ibft.support.TestContext; import tech.pegasys.pantheon.consensus.ibft.support.TestContext;
import tech.pegasys.pantheon.consensus.ibft.support.TestContextBuilder; import tech.pegasys.pantheon.consensus.ibft.support.TestContextBuilder;
@ -75,29 +73,29 @@ public class GossipTest {
@Test @Test
public void gossipMessagesToPeers() { public void gossipMessagesToPeers() {
SignedData<PreparePayload> localPrepare = final Prepare localPrepare =
context.getLocalNodeMessageFactory().createSignedPreparePayload(roundId, block.getHash()); context.getLocalNodeMessageFactory().createSignedPreparePayload(roundId, block.getHash());
peers.verifyNoMessagesReceivedNonProposing(); peers.verifyNoMessagesReceivedNonProposing();
final SignedData<ProposalPayload> proposal = sender.injectProposal(roundId, block); final Proposal proposal = sender.injectProposal(roundId, block);
// sender node will have a prepare message as an effect of the proposal being sent // sender node will have a prepare message as an effect of the proposal being sent
peers.verifyMessagesReceivedNonPropsing(proposal, localPrepare); peers.verifyMessagesReceivedNonPropsing(proposal, localPrepare);
peers.verifyMessagesReceivedPropser(localPrepare); peers.verifyMessagesReceivedProposer(localPrepare);
final SignedData<PreparePayload> prepare = sender.injectPrepare(roundId, block.getHash()); final Prepare prepare = sender.injectPrepare(roundId, block.getHash());
peers.verifyMessagesReceivedNonPropsing(prepare); peers.verifyMessagesReceivedNonPropsing(prepare);
peers.verifyNoMessagesReceivedProposer(); peers.verifyNoMessagesReceivedProposer();
final SignedData<CommitPayload> commit = sender.injectCommit(roundId, block.getHash()); final Commit commit = sender.injectCommit(roundId, block.getHash());
peers.verifyMessagesReceivedNonPropsing(commit); peers.verifyMessagesReceivedNonPropsing(commit);
peers.verifyNoMessagesReceivedProposer(); peers.verifyNoMessagesReceivedProposer();
final SignedData<RoundChangePayload> roundChange = final RoundChange roundChange =
msgFactory.createSignedRoundChangePayload(roundId, Optional.empty()); msgFactory.createSignedRoundChangePayload(roundId, Optional.empty());
final RoundChangeCertificate roundChangeCert = final RoundChangeCertificate roundChangeCert =
new RoundChangeCertificate(singleton(roundChange)); new RoundChangeCertificate(singleton(roundChange.getSignedPayload()));
SignedData<NewRoundPayload> newRound = final NewRound newRound =
sender.injectNewRound(roundId, roundChangeCert, proposal); sender.injectNewRound(roundId, roundChangeCert, proposal.getSignedPayload());
peers.verifyMessagesReceivedNonPropsing(newRound); peers.verifyMessagesReceivedNonPropsing(newRound);
peers.verifyNoMessagesReceivedProposer(); peers.verifyNoMessagesReceivedProposer();
@ -108,7 +106,7 @@ public class GossipTest {
@Test @Test
public void onlyGossipOnce() { public void onlyGossipOnce() {
final SignedData<PreparePayload> prepare = sender.injectPrepare(roundId, block.getHash()); final Prepare prepare = sender.injectPrepare(roundId, block.getHash());
peers.verifyMessagesReceivedNonPropsing(prepare); peers.verifyMessagesReceivedNonPropsing(prepare);
sender.injectPrepare(roundId, block.getHash()); sender.injectPrepare(roundId, block.getHash());
@ -122,10 +120,10 @@ public class GossipTest {
public void messageWithUnknownValidatorIsNotGossiped() { public void messageWithUnknownValidatorIsNotGossiped() {
final KeyPair unknownKeyPair = KeyPair.generate(); final KeyPair unknownKeyPair = KeyPair.generate();
final MessageFactory unknownMsgFactory = new MessageFactory(unknownKeyPair); final MessageFactory unknownMsgFactory = new MessageFactory(unknownKeyPair);
final SignedData<ProposalPayload> unknownProposal = final Proposal unknownProposal = unknownMsgFactory.createSignedProposalPayload(roundId, block);
unknownMsgFactory.createSignedProposalPayload(roundId, block);
sender.injectMessage(ProposalMessageData.create(new Proposal(unknownProposal))); sender.injectMessage(
ProposalMessageData.create(new Proposal(unknownProposal.getSignedPayload())));
peers.verifyNoMessagesReceived(); peers.verifyNoMessagesReceived();
} }
@ -133,10 +131,9 @@ public class GossipTest {
public void messageIsNotGossipedToSenderOrCreator() { public void messageIsNotGossipedToSenderOrCreator() {
final ValidatorPeer msgCreator = peers.getFirstNonProposer(); final ValidatorPeer msgCreator = peers.getFirstNonProposer();
final MessageFactory peerMsgFactory = msgCreator.getMessageFactory(); final MessageFactory peerMsgFactory = msgCreator.getMessageFactory();
final SignedData<ProposalPayload> proposalFromPeer = final Proposal proposalFromPeer = peerMsgFactory.createSignedProposalPayload(roundId, block);
peerMsgFactory.createSignedProposalPayload(roundId, block);
sender.injectMessage(ProposalMessageData.create(new Proposal(proposalFromPeer))); sender.injectMessage(ProposalMessageData.create(proposalFromPeer));
peers.verifyMessagesReceivedNonPropsingExcluding(msgCreator, proposalFromPeer); peers.verifyMessagesReceivedNonPropsingExcluding(msgCreator, proposalFromPeer);
peers.verifyNoMessagesReceivedProposer(); peers.verifyNoMessagesReceivedProposer();
@ -164,7 +161,7 @@ public class GossipTest {
IbftHelpers.createSealedBlock(block, peers.sign(block.getHash())); IbftHelpers.createSealedBlock(block, peers.sign(block.getHash()));
ConsensusRoundIdentifier futureRoundId = new ConsensusRoundIdentifier(2, 0); ConsensusRoundIdentifier futureRoundId = new ConsensusRoundIdentifier(2, 0);
SignedData<PreparePayload> futurePrepare = sender.injectPrepare(futureRoundId, block.getHash()); Prepare futurePrepare = sender.injectPrepare(futureRoundId, block.getHash());
peers.verifyNoMessagesReceivedNonProposing(); peers.verifyNoMessagesReceivedNonProposing();
; ;

@ -17,10 +17,9 @@ import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createSig
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier; import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.ibftevent.BlockTimerExpiry; import tech.pegasys.pantheon.consensus.ibft.ibftevent.BlockTimerExpiry;
import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload; import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Commit;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Proposal;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.ProposalPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.support.RoundSpecificPeers; import tech.pegasys.pantheon.consensus.ibft.support.RoundSpecificPeers;
import tech.pegasys.pantheon.consensus.ibft.support.TestContext; import tech.pegasys.pantheon.consensus.ibft.support.TestContext;
import tech.pegasys.pantheon.consensus.ibft.support.TestContextBuilder; import tech.pegasys.pantheon.consensus.ibft.support.TestContextBuilder;
@ -58,8 +57,8 @@ public class LocalNodeIsProposerTest {
private final MessageFactory localNodeMessageFactory = context.getLocalNodeMessageFactory(); private final MessageFactory localNodeMessageFactory = context.getLocalNodeMessageFactory();
private Block expectedProposedBlock; private Block expectedProposedBlock;
private SignedData<ProposalPayload> expectedTxProposal; private Proposal expectedTxProposal;
private SignedData<CommitPayload> expectedTxCommit; private Commit expectedTxCommit;
@Before @Before
public void setup() { public void setup() {
@ -68,8 +67,9 @@ public class LocalNodeIsProposerTest {
localNodeMessageFactory.createSignedProposalPayload(roundId, expectedProposedBlock); localNodeMessageFactory.createSignedProposalPayload(roundId, expectedProposedBlock);
expectedTxCommit = expectedTxCommit =
createSignedCommitPayload( new Commit(
roundId, expectedProposedBlock, context.getLocalNodeParams().getNodeKeyPair()); createSignedCommitPayload(
roundId, expectedProposedBlock, context.getLocalNodeParams().getNodeKeyPair()));
// Start the Controller, and trigger "block timer" to send proposal. // Start the Controller, and trigger "block timer" to send proposal.
context.getController().start(); context.getController().start();

@ -16,10 +16,9 @@ import static org.assertj.core.api.Assertions.assertThat;
import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createSignedCommitPayload; import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createSignedCommitPayload;
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier; import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload; import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Commit;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Prepare;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.support.RoundSpecificPeers; import tech.pegasys.pantheon.consensus.ibft.support.RoundSpecificPeers;
import tech.pegasys.pantheon.consensus.ibft.support.TestContext; import tech.pegasys.pantheon.consensus.ibft.support.TestContext;
import tech.pegasys.pantheon.consensus.ibft.support.TestContextBuilder; import tech.pegasys.pantheon.consensus.ibft.support.TestContextBuilder;
@ -46,8 +45,8 @@ public class LocalNodeNotProposerTest {
private final Block blockToPropose = context.createBlockForProposalFromChainHead(0, 15); private final Block blockToPropose = context.createBlockForProposalFromChainHead(0, 15);
private SignedData<PreparePayload> expectedTxPrepare; private Prepare expectedTxPrepare;
private SignedData<CommitPayload> expectedTxCommit; private Commit expectedTxCommit;
@Before @Before
public void setup() { public void setup() {
@ -55,8 +54,9 @@ public class LocalNodeNotProposerTest {
localNodeMessageFactory.createSignedPreparePayload(roundId, blockToPropose.getHash()); localNodeMessageFactory.createSignedPreparePayload(roundId, blockToPropose.getHash());
expectedTxCommit = expectedTxCommit =
createSignedCommitPayload( new Commit(
roundId, blockToPropose, context.getLocalNodeParams().getNodeKeyPair()); createSignedCommitPayload(
roundId, blockToPropose, context.getLocalNodeParams().getNodeKeyPair()));
context.getController().start(); context.getController().start();
} }

@ -15,11 +15,11 @@ package tech.pegasys.pantheon.consensus.ibft.tests;
import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createValidPreparedCertificate; import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createValidPreparedCertificate;
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier; import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload; import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Commit;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Prepare;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Proposal;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate; import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate;
import tech.pegasys.pantheon.consensus.ibft.payload.ProposalPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangeCertificate; import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangeCertificate;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangePayload; import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData; import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
@ -71,9 +71,12 @@ public class ReceivedNewRoundTest {
nextProposer.injectNewRound( nextProposer.injectNewRound(
targetRound, targetRound,
new RoundChangeCertificate(roundChanges), new RoundChangeCertificate(roundChanges),
nextProposer.getMessageFactory().createSignedProposalPayload(targetRound, blockToPropose)); nextProposer
.getMessageFactory()
.createSignedProposalPayload(targetRound, blockToPropose)
.getSignedPayload());
final SignedData<PreparePayload> expectedPrepare = final Prepare expectedPrepare =
localNodeMessageFactory.createSignedPreparePayload(targetRound, blockToPropose.getHash()); localNodeMessageFactory.createSignedPreparePayload(targetRound, blockToPropose.getHash());
peers.verifyMessagesReceived(expectedPrepare); peers.verifyMessagesReceived(expectedPrepare);
@ -96,7 +99,8 @@ public class ReceivedNewRoundTest {
new RoundChangeCertificate(roundChanges), new RoundChangeCertificate(roundChanges),
illegalProposer illegalProposer
.getMessageFactory() .getMessageFactory()
.createSignedProposalPayload(nextRoundId, blockToPropose)); .createSignedProposalPayload(nextRoundId, blockToPropose)
.getSignedPayload());
peers.verifyNoMessagesReceived(); peers.verifyNoMessagesReceived();
} }
@ -121,7 +125,8 @@ public class ReceivedNewRoundTest {
peers peers
.getNonProposing(0) .getNonProposing(0)
.getMessageFactory() .getMessageFactory()
.createSignedProposalPayload(nextRoundId, reproposedBlock)); .createSignedProposalPayload(nextRoundId, reproposedBlock)
.getSignedPayload());
peers.verifyMessagesReceived( peers.verifyMessagesReceived(
localNodeMessageFactory.createSignedPreparePayload(nextRoundId, reproposedBlock.getHash())); localNodeMessageFactory.createSignedPreparePayload(nextRoundId, reproposedBlock.getHash()));
@ -141,14 +146,14 @@ public class ReceivedNewRoundTest {
final ValidatorPeer interimRoundProposer = final ValidatorPeer interimRoundProposer =
context.roundSpecificPeers(interimRound).getProposer(); context.roundSpecificPeers(interimRound).getProposer();
final SignedData<ProposalPayload> proposal = final Proposal proposal =
interimRoundProposer interimRoundProposer
.getMessageFactory() .getMessageFactory()
.createSignedProposalPayload( .createSignedProposalPayload(
interimRound, context.createBlockForProposalFromChainHead(1, 30)); interimRound, context.createBlockForProposalFromChainHead(1, 30));
interimRoundProposer.injectNewRound( interimRoundProposer.injectNewRound(
interimRound, new RoundChangeCertificate(roundChangePayloads), proposal); interimRound, new RoundChangeCertificate(roundChangePayloads), proposal.getSignedPayload());
peers.verifyNoMessagesReceived(); peers.verifyNoMessagesReceived();
} }
@ -174,7 +179,8 @@ public class ReceivedNewRoundTest {
peers peers
.getNonProposing(0) .getNonProposing(0)
.getMessageFactory() .getMessageFactory()
.createSignedProposalPayload(nextRoundId, reproposedBlock)); .createSignedProposalPayload(nextRoundId, reproposedBlock)
.getSignedPayload());
peers.verifyMessagesReceived( peers.verifyMessagesReceived(
localNodeMessageFactory.createSignedPreparePayload(nextRoundId, reproposedBlock.getHash())); localNodeMessageFactory.createSignedPreparePayload(nextRoundId, reproposedBlock.getHash()));
@ -189,15 +195,17 @@ public class ReceivedNewRoundTest {
peers peers
.getNonProposing(0) .getNonProposing(0)
.getMessageFactory() .getMessageFactory()
.createSignedProposalPayload(nextRoundId, reproposedBlock)); .createSignedProposalPayload(nextRoundId, reproposedBlock)
.getSignedPayload());
peers.verifyNoMessagesReceived(); peers.verifyNoMessagesReceived();
nextRoles.getNonProposing(1).injectPrepare(nextRoundId, reproposedBlock.getHash()); nextRoles.getNonProposing(1).injectPrepare(nextRoundId, reproposedBlock.getHash());
final SignedData<CommitPayload> expectedCommit = final Commit expectedCommit =
TestHelpers.createSignedCommitPayload( new Commit(
nextRoundId, reproposedBlock, context.getLocalNodeParams().getNodeKeyPair()); TestHelpers.createSignedCommitPayload(
nextRoundId, reproposedBlock, context.getLocalNodeParams().getNodeKeyPair()));
peers.verifyMessagesReceived(expectedCommit); peers.verifyMessagesReceived(expectedCommit);
} }

@ -19,11 +19,12 @@ import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createVal
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier; import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.IbftHelpers; import tech.pegasys.pantheon.consensus.ibft.IbftHelpers;
import tech.pegasys.pantheon.consensus.ibft.ibftevent.RoundExpiry; import tech.pegasys.pantheon.consensus.ibft.ibftevent.RoundExpiry;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.NewRound;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Prepare;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Proposal;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.RoundChange;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.NewRoundPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate; import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate;
import tech.pegasys.pantheon.consensus.ibft.payload.ProposalPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangeCertificate; import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangeCertificate;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangePayload; import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData; import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
@ -75,7 +76,7 @@ public class RoundChangeTest {
// NOTE: The prepare certificate will be empty as insufficient Prepare msgs have been received. // NOTE: The prepare certificate will be empty as insufficient Prepare msgs have been received.
final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 1); final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 1);
final SignedData<RoundChangePayload> expectedTxRoundChange = final RoundChange expectedTxRoundChange =
localNodeMessageFactory.createSignedRoundChangePayload(targetRound, empty()); localNodeMessageFactory.createSignedRoundChangePayload(targetRound, empty());
context.getController().handleRoundExpiry(new RoundExpiry(roundId)); context.getController().handleRoundExpiry(new RoundExpiry(roundId));
peers.verifyMessagesReceived(expectedTxRoundChange); peers.verifyMessagesReceived(expectedTxRoundChange);
@ -84,7 +85,7 @@ public class RoundChangeTest {
@Test @Test
public void roundChangeHasEmptyCertificateIfNoPrepareMessagesReceived() { public void roundChangeHasEmptyCertificateIfNoPrepareMessagesReceived() {
final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 1); final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 1);
final SignedData<RoundChangePayload> expectedTxRoundChange = final RoundChange expectedTxRoundChange =
localNodeMessageFactory.createSignedRoundChangePayload(targetRound, empty()); localNodeMessageFactory.createSignedRoundChangePayload(targetRound, empty());
peers.getProposer().injectProposal(roundId, blockToPropose); peers.getProposer().injectProposal(roundId, blockToPropose);
@ -99,7 +100,7 @@ public class RoundChangeTest {
// Note: There are 4 validators, thus Quorum is 3 and Prepare Msgs are 2 - thus // Note: There are 4 validators, thus Quorum is 3 and Prepare Msgs are 2 - thus
// receiving only a single Prepare msg will result in no PreparedCert. // receiving only a single Prepare msg will result in no PreparedCert.
final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 1); final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 1);
final SignedData<RoundChangePayload> expectedTxRoundChange = final RoundChange expectedTxRoundChange =
localNodeMessageFactory.createSignedRoundChangePayload(targetRound, empty()); localNodeMessageFactory.createSignedRoundChangePayload(targetRound, empty());
peers.getProposer().injectProposal(roundId, blockToPropose); peers.getProposer().injectProposal(roundId, blockToPropose);
@ -113,27 +114,28 @@ public class RoundChangeTest {
@Test @Test
public void roundChangeHasPopulatedCertificateIfQuorumPrepareMessagesAndProposalAreReceived() { public void roundChangeHasPopulatedCertificateIfQuorumPrepareMessagesAndProposalAreReceived() {
final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 1); final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 1);
final SignedData<PreparePayload> localPrepareMessage = final Prepare localPrepareMessage =
localNodeMessageFactory.createSignedPreparePayload(roundId, blockToPropose.getHash()); localNodeMessageFactory.createSignedPreparePayload(roundId, blockToPropose.getHash());
final SignedData<ProposalPayload> proposal = final Proposal proposal = peers.getProposer().injectProposal(roundId, blockToPropose);
peers.getProposer().injectProposal(roundId, blockToPropose);
peers.clearReceivedMessages(); peers.clearReceivedMessages();
final SignedData<PreparePayload> p1 = final Prepare p1 = peers.getNonProposing(0).injectPrepare(roundId, blockToPropose.getHash());
peers.getNonProposing(0).injectPrepare(roundId, blockToPropose.getHash());
peers.clearReceivedMessages(); peers.clearReceivedMessages();
final SignedData<PreparePayload> p2 = final Prepare p2 = peers.getNonProposing(1).injectPrepare(roundId, blockToPropose.getHash());
peers.getNonProposing(1).injectPrepare(roundId, blockToPropose.getHash());
peers.clearReceivedMessages(); peers.clearReceivedMessages();
final SignedData<RoundChangePayload> expectedTxRoundChange = final RoundChange expectedTxRoundChange =
localNodeMessageFactory.createSignedRoundChangePayload( localNodeMessageFactory.createSignedRoundChangePayload(
targetRound, targetRound,
Optional.of( Optional.of(
new PreparedCertificate( new PreparedCertificate(
proposal, Lists.newArrayList(localPrepareMessage, p1, p2)))); proposal.getSignedPayload(),
Lists.newArrayList(
localPrepareMessage.getSignedPayload(),
p1.getSignedPayload(),
p2.getSignedPayload()))));
context.getController().handleRoundExpiry(new RoundExpiry(roundId)); context.getController().handleRoundExpiry(new RoundExpiry(roundId));
peers.verifyMessagesReceived(expectedTxRoundChange); peers.verifyMessagesReceived(expectedTxRoundChange);
@ -146,20 +148,23 @@ public class RoundChangeTest {
final Block locallyProposedBlock = final Block locallyProposedBlock =
context.createBlockForProposalFromChainHead(targetRound.getRoundNumber(), blockTimeStamp); context.createBlockForProposalFromChainHead(targetRound.getRoundNumber(), blockTimeStamp);
final SignedData<RoundChangePayload> rc1 = final RoundChange rc1 = peers.getNonProposing(0).injectRoundChange(targetRound, empty());
peers.getNonProposing(0).injectRoundChange(targetRound, empty()); final RoundChange rc2 = peers.getNonProposing(1).injectRoundChange(targetRound, empty());
final SignedData<RoundChangePayload> rc2 = final RoundChange rc3 = peers.getNonProposing(2).injectRoundChange(targetRound, empty());
peers.getNonProposing(1).injectRoundChange(targetRound, empty()); final RoundChange rc4 = peers.getProposer().injectRoundChange(targetRound, empty());
final SignedData<RoundChangePayload> rc3 =
peers.getNonProposing(2).injectRoundChange(targetRound, empty());
final SignedData<RoundChangePayload> rc4 =
peers.getProposer().injectRoundChange(targetRound, empty());
final SignedData<NewRoundPayload> expectedNewRound = final NewRound expectedNewRound =
localNodeMessageFactory.createSignedNewRoundPayload( localNodeMessageFactory.createSignedNewRoundPayload(
targetRound, targetRound,
new RoundChangeCertificate(Lists.newArrayList(rc1, rc2, rc3, rc4)), new RoundChangeCertificate(
localNodeMessageFactory.createSignedProposalPayload(targetRound, locallyProposedBlock)); Lists.newArrayList(
rc1.getSignedPayload(),
rc2.getSignedPayload(),
rc3.getSignedPayload(),
rc4.getSignedPayload())),
localNodeMessageFactory
.createSignedProposalPayload(targetRound, locallyProposedBlock)
.getSignedPayload());
peers.verifyMessagesReceived(expectedNewRound); peers.verifyMessagesReceived(expectedNewRound);
} }
@ -182,19 +187,18 @@ public class RoundChangeTest {
final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 4); final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 4);
final SignedData<RoundChangePayload> rc1 = final RoundChange rc1 = peers.getNonProposing(0).injectRoundChange(targetRound, empty());
peers.getNonProposing(0).injectRoundChange(targetRound, empty());
// Create a roundChange with a PreparedCertificate from an earlier Round (should not be used // Create a roundChange with a PreparedCertificate from an earlier Round (should not be used
final SignedData<RoundChangePayload> rc2 = final RoundChange rc2 =
peers.getNonProposing(1).injectRoundChange(targetRound, Optional.of(earlierPrepCert)); peers.getNonProposing(1).injectRoundChange(targetRound, Optional.of(earlierPrepCert));
// Create a roundChange with a PreparedCertificate from an earlier Round (should not be used // Create a roundChange with a PreparedCertificate from an earlier Round (should not be used
final SignedData<RoundChangePayload> rc3 = final RoundChange rc3 =
peers.getNonProposing(2).injectRoundChange(targetRound, Optional.of(earlierPrepCert)); peers.getNonProposing(2).injectRoundChange(targetRound, Optional.of(earlierPrepCert));
// Create a roundChange containing a PreparedCertificate // Create a roundChange containing a PreparedCertificate
final SignedData<RoundChangePayload> rc4 = final RoundChange rc4 =
peers.getProposer().injectRoundChange(targetRound, Optional.of(bestPrepCert)); peers.getProposer().injectRoundChange(targetRound, Optional.of(bestPrepCert));
// Expected to use the block with "ARBITRARY_BLOCKTIME" (i.e. latter block) but with the target // Expected to use the block with "ARBITRARY_BLOCKTIME" (i.e. latter block) but with the target
@ -203,12 +207,18 @@ public class RoundChangeTest {
context.createBlockForProposalFromChainHead( context.createBlockForProposalFromChainHead(
targetRound.getRoundNumber(), ARBITRARY_BLOCKTIME); targetRound.getRoundNumber(), ARBITRARY_BLOCKTIME);
final SignedData<NewRoundPayload> expectedNewRound = final NewRound expectedNewRound =
localNodeMessageFactory.createSignedNewRoundPayload( localNodeMessageFactory.createSignedNewRoundPayload(
targetRound, targetRound,
new RoundChangeCertificate(Lists.newArrayList(rc1, rc2, rc3, rc4)), new RoundChangeCertificate(
localNodeMessageFactory.createSignedProposalPayload( Lists.newArrayList(
targetRound, expectedBlockToPropose)); rc1.getSignedPayload(),
rc2.getSignedPayload(),
rc3.getSignedPayload(),
rc4.getSignedPayload())),
localNodeMessageFactory
.createSignedProposalPayload(targetRound, expectedBlockToPropose)
.getSignedPayload());
peers.verifyMessagesReceived(expectedNewRound); peers.verifyMessagesReceived(expectedNewRound);
} }
@ -226,11 +236,13 @@ public class RoundChangeTest {
final Block locallyProposedBlock = final Block locallyProposedBlock =
context.createBlockForProposalFromChainHead(futureRound.getRoundNumber(), blockTimeStamp); context.createBlockForProposalFromChainHead(futureRound.getRoundNumber(), blockTimeStamp);
final SignedData<NewRoundPayload> expectedNewRound = final NewRound expectedNewRound =
localNodeMessageFactory.createSignedNewRoundPayload( localNodeMessageFactory.createSignedNewRoundPayload(
futureRound, futureRound,
new RoundChangeCertificate(roundChangeMessages), new RoundChangeCertificate(roundChangeMessages),
localNodeMessageFactory.createSignedProposalPayload(futureRound, locallyProposedBlock)); localNodeMessageFactory
.createSignedProposalPayload(futureRound, locallyProposedBlock)
.getSignedPayload());
peers.verifyMessagesReceived(expectedNewRound); peers.verifyMessagesReceived(expectedNewRound);
} }
@ -264,7 +276,10 @@ public class RoundChangeTest {
List<SignedData<RoundChangePayload>> roundChangeMessages = Lists.newArrayList(); List<SignedData<RoundChangePayload>> roundChangeMessages = Lists.newArrayList();
// Create a roundChange containing a PreparedCertificate // Create a roundChange containing a PreparedCertificate
roundChangeMessages.add( roundChangeMessages.add(
peers.getProposer().injectRoundChange(targetRound, Optional.of(prepCert))); peers
.getProposer()
.injectRoundChange(targetRound, Optional.of(prepCert))
.getSignedPayload());
// Attempt to override the previously received RoundChange (but now without a payload). // Attempt to override the previously received RoundChange (but now without a payload).
peers.getProposer().injectRoundChange(targetRound, empty()); peers.getProposer().injectRoundChange(targetRound, empty());
@ -275,12 +290,13 @@ public class RoundChangeTest {
context.createBlockForProposalFromChainHead( context.createBlockForProposalFromChainHead(
targetRound.getRoundNumber(), ARBITRARY_BLOCKTIME); targetRound.getRoundNumber(), ARBITRARY_BLOCKTIME);
final SignedData<NewRoundPayload> expectedNewRound = final NewRound expectedNewRound =
localNodeMessageFactory.createSignedNewRoundPayload( localNodeMessageFactory.createSignedNewRoundPayload(
targetRound, targetRound,
new RoundChangeCertificate(Lists.newArrayList(roundChangeMessages)), new RoundChangeCertificate(Lists.newArrayList(roundChangeMessages)),
localNodeMessageFactory.createSignedProposalPayload( localNodeMessageFactory
targetRound, expectedBlockToPropose)); .createSignedProposalPayload(targetRound, expectedBlockToPropose)
.getSignedPayload());
peers.verifyMessagesReceived(expectedNewRound); peers.verifyMessagesReceived(expectedNewRound);
} }
@ -312,12 +328,9 @@ public class RoundChangeTest {
public void illegallyConstructedRoundChangeMessageIsDiscarded() { public void illegallyConstructedRoundChangeMessageIsDiscarded() {
final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 4); final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 4);
final SignedData<RoundChangePayload> rc1 = final RoundChange rc1 = peers.getNonProposing(0).injectRoundChange(targetRound, empty());
peers.getNonProposing(0).injectRoundChange(targetRound, empty()); final RoundChange rc2 = peers.getNonProposing(1).injectRoundChange(targetRound, empty());
final SignedData<RoundChangePayload> rc2 = final RoundChange rc3 = peers.getNonProposing(2).injectRoundChange(targetRound, empty());
peers.getNonProposing(1).injectRoundChange(targetRound, empty());
final SignedData<RoundChangePayload> rc3 =
peers.getNonProposing(2).injectRoundChange(targetRound, empty());
// create illegal RoundChangeMessage // create illegal RoundChangeMessage
final PreparedCertificate illegalPreparedCertificate = final PreparedCertificate illegalPreparedCertificate =
@ -325,7 +338,8 @@ public class RoundChangeTest {
peers peers
.getNonProposing(0) .getNonProposing(0)
.getMessageFactory() .getMessageFactory()
.createSignedProposalPayload(roundId, blockToPropose), .createSignedProposalPayload(roundId, blockToPropose)
.getSignedPayload(),
emptyList()); emptyList());
peers peers

@ -17,10 +17,9 @@ import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createSig
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier; import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.messagedata.IbftV2; import tech.pegasys.pantheon.consensus.ibft.messagedata.IbftV2;
import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload; import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Commit;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Prepare;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.support.NodeParams; import tech.pegasys.pantheon.consensus.ibft.support.NodeParams;
import tech.pegasys.pantheon.consensus.ibft.support.RoundSpecificPeers; import tech.pegasys.pantheon.consensus.ibft.support.RoundSpecificPeers;
import tech.pegasys.pantheon.consensus.ibft.support.TestContext; import tech.pegasys.pantheon.consensus.ibft.support.TestContext;
@ -63,8 +62,8 @@ public class SpuriousBehaviourTest {
private final RoundSpecificPeers peers = context.roundSpecificPeers(roundId); private final RoundSpecificPeers peers = context.roundSpecificPeers(roundId);
private Block proposedBlock = context.createBlockForProposalFromChainHead(0, 30); private Block proposedBlock = context.createBlockForProposalFromChainHead(0, 30);
private SignedData<PreparePayload> expectedPrepare; private Prepare expectedPrepare;
private SignedData<CommitPayload> expectedCommit; private Commit expectedCommit;
@Before @Before
public void setup() { public void setup() {
@ -75,8 +74,9 @@ public class SpuriousBehaviourTest {
.getLocalNodeMessageFactory() .getLocalNodeMessageFactory()
.createSignedPreparePayload(roundId, proposedBlock.getHash()); .createSignedPreparePayload(roundId, proposedBlock.getHash());
expectedCommit = expectedCommit =
createSignedCommitPayload( new Commit(
roundId, proposedBlock, context.getLocalNodeParams().getNodeKeyPair()); createSignedCommitPayload(
roundId, proposedBlock, context.getLocalNodeParams().getNodeKeyPair()));
} }
@Test @Test

@ -13,6 +13,8 @@
package tech.pegasys.pantheon.consensus.ibft.messagewrappers; package tech.pegasys.pantheon.consensus.ibft.messagewrappers;
import tech.pegasys.pantheon.consensus.ibft.payload.NewRoundPayload; import tech.pegasys.pantheon.consensus.ibft.payload.NewRoundPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.ProposalPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangeCertificate;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData; import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
public class NewRound extends IbftMessage<NewRoundPayload> { public class NewRound extends IbftMessage<NewRoundPayload> {
@ -20,4 +22,12 @@ public class NewRound extends IbftMessage<NewRoundPayload> {
public NewRound(final SignedData<NewRoundPayload> payload) { public NewRound(final SignedData<NewRoundPayload> payload) {
super(payload); super(payload);
} }
public RoundChangeCertificate getRoundChangeCertificate() {
return getSignedPayload().getPayload().getRoundChangeCertificate();
}
public SignedData<ProposalPayload> getProposalPayload() {
return getSignedPayload().getPayload().getProposalPayload();
}
} }

@ -46,8 +46,7 @@ public class IbftMessageTransmitter {
} }
public void multicastProposal(final ConsensusRoundIdentifier roundIdentifier, final Block block) { public void multicastProposal(final ConsensusRoundIdentifier roundIdentifier, final Block block) {
final Proposal data = final Proposal data = messageFactory.createSignedProposalPayload(roundIdentifier, block);
new Proposal(messageFactory.createSignedProposalPayload(roundIdentifier, block));
final ProposalMessageData message = ProposalMessageData.create(data); final ProposalMessageData message = ProposalMessageData.create(data);
@ -55,8 +54,7 @@ public class IbftMessageTransmitter {
} }
public void multicastPrepare(final ConsensusRoundIdentifier roundIdentifier, final Hash digest) { public void multicastPrepare(final ConsensusRoundIdentifier roundIdentifier, final Hash digest) {
final Prepare data = final Prepare data = messageFactory.createSignedPreparePayload(roundIdentifier, digest);
new Prepare(messageFactory.createSignedPreparePayload(roundIdentifier, digest));
final PrepareMessageData message = PrepareMessageData.create(data); final PrepareMessageData message = PrepareMessageData.create(data);
@ -68,7 +66,7 @@ public class IbftMessageTransmitter {
final Hash digest, final Hash digest,
final Signature commitSeal) { final Signature commitSeal) {
final Commit data = final Commit data =
new Commit(messageFactory.createSignedCommitPayload(roundIdentifier, digest, commitSeal)); messageFactory.createSignedCommitPayload(roundIdentifier, digest, commitSeal);
final CommitMessageData message = CommitMessageData.create(data); final CommitMessageData message = CommitMessageData.create(data);
@ -80,8 +78,7 @@ public class IbftMessageTransmitter {
final Optional<PreparedCertificate> preparedCertificate) { final Optional<PreparedCertificate> preparedCertificate) {
final RoundChange data = final RoundChange data =
new RoundChange( messageFactory.createSignedRoundChangePayload(roundIdentifier, preparedCertificate);
messageFactory.createSignedRoundChangePayload(roundIdentifier, preparedCertificate));
final RoundChangeMessageData message = RoundChangeMessageData.create(data); final RoundChangeMessageData message = RoundChangeMessageData.create(data);
@ -94,9 +91,8 @@ public class IbftMessageTransmitter {
final SignedData<ProposalPayload> proposalPayload) { final SignedData<ProposalPayload> proposalPayload) {
final NewRound signedPayload = final NewRound signedPayload =
new NewRound( messageFactory.createSignedNewRoundPayload(
messageFactory.createSignedNewRoundPayload( roundIdentifier, roundChangeCertificate, proposalPayload);
roundIdentifier, roundChangeCertificate, proposalPayload));
final NewRoundMessageData message = NewRoundMessageData.create(signedPayload); final NewRoundMessageData message = NewRoundMessageData.create(signedPayload);

@ -13,6 +13,11 @@
package tech.pegasys.pantheon.consensus.ibft.payload; package tech.pegasys.pantheon.consensus.ibft.payload;
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier; import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Commit;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.NewRound;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Prepare;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Proposal;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.RoundChange;
import tech.pegasys.pantheon.crypto.SECP256K1; import tech.pegasys.pantheon.crypto.SECP256K1;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.crypto.SECP256K1.Signature; import tech.pegasys.pantheon.crypto.SECP256K1.Signature;
@ -31,42 +36,42 @@ public class MessageFactory {
this.validatorKeyPair = validatorKeyPair; this.validatorKeyPair = validatorKeyPair;
} }
public SignedData<ProposalPayload> createSignedProposalPayload( public Proposal createSignedProposalPayload(
final ConsensusRoundIdentifier roundIdentifier, final Block block) { final ConsensusRoundIdentifier roundIdentifier, final Block block) {
final ProposalPayload payload = new ProposalPayload(roundIdentifier, block); final ProposalPayload payload = new ProposalPayload(roundIdentifier, block);
return createSignedMessage(payload); return new Proposal(createSignedMessage(payload));
} }
public SignedData<PreparePayload> createSignedPreparePayload( public Prepare createSignedPreparePayload(
final ConsensusRoundIdentifier roundIdentifier, final Hash digest) { final ConsensusRoundIdentifier roundIdentifier, final Hash digest) {
final PreparePayload payload = new PreparePayload(roundIdentifier, digest); final PreparePayload payload = new PreparePayload(roundIdentifier, digest);
return createSignedMessage(payload); return new Prepare(createSignedMessage(payload));
} }
public SignedData<CommitPayload> createSignedCommitPayload( public Commit createSignedCommitPayload(
final ConsensusRoundIdentifier roundIdentifier, final ConsensusRoundIdentifier roundIdentifier,
final Hash digest, final Hash digest,
final Signature commitSeal) { final Signature commitSeal) {
final CommitPayload payload = new CommitPayload(roundIdentifier, digest, commitSeal); final CommitPayload payload = new CommitPayload(roundIdentifier, digest, commitSeal);
return createSignedMessage(payload); return new Commit(createSignedMessage(payload));
} }
public SignedData<RoundChangePayload> createSignedRoundChangePayload( public RoundChange createSignedRoundChangePayload(
final ConsensusRoundIdentifier roundIdentifier, final ConsensusRoundIdentifier roundIdentifier,
final Optional<PreparedCertificate> preparedCertificate) { final Optional<PreparedCertificate> preparedCertificate) {
final RoundChangePayload payload = new RoundChangePayload(roundIdentifier, preparedCertificate); final RoundChangePayload payload = new RoundChangePayload(roundIdentifier, preparedCertificate);
return createSignedMessage(payload); return new RoundChange(createSignedMessage(payload));
} }
public SignedData<NewRoundPayload> createSignedNewRoundPayload( public NewRound createSignedNewRoundPayload(
final ConsensusRoundIdentifier roundIdentifier, final ConsensusRoundIdentifier roundIdentifier,
final RoundChangeCertificate roundChangeCertificate, final RoundChangeCertificate roundChangeCertificate,
final SignedData<ProposalPayload> proposalPayload) { final SignedData<ProposalPayload> proposalPayload) {
@ -74,7 +79,7 @@ public class MessageFactory {
final NewRoundPayload payload = final NewRoundPayload payload =
new NewRoundPayload(roundIdentifier, roundChangeCertificate, proposalPayload); new NewRoundPayload(roundIdentifier, roundChangeCertificate, proposalPayload);
return createSignedMessage(payload); return new NewRound(createSignedMessage(payload));
} }
private <M extends Payload> SignedData<M> createSignedMessage(final M payload) { private <M extends Payload> SignedData<M> createSignedMessage(final M payload) {

@ -14,6 +14,7 @@ package tech.pegasys.pantheon.consensus.ibft.payload;
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier; import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.messagedata.IbftV2; import tech.pegasys.pantheon.consensus.ibft.messagedata.IbftV2;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.NewRound;
import tech.pegasys.pantheon.ethereum.rlp.RLPInput; import tech.pegasys.pantheon.ethereum.rlp.RLPInput;
import tech.pegasys.pantheon.ethereum.rlp.RLPOutput; import tech.pegasys.pantheon.ethereum.rlp.RLPOutput;
@ -122,9 +123,11 @@ public class NewRoundPayload implements Payload {
this.proposalPayload = proposalPayload; this.proposalPayload = proposalPayload;
} }
public static Builder fromExisting(final NewRoundPayload payload) { public static Builder fromExisting(final NewRound payload) {
return new Builder( return new Builder(
payload.roundChangeIdentifier, payload.roundChangeCertificate, payload.proposalPayload); payload.getRoundIdentifier(),
payload.getRoundChangeCertificate(),
payload.getProposalPayload());
} }
public void setRoundChangeIdentifier(final ConsensusRoundIdentifier roundChangeIdentifier) { public void setRoundChangeIdentifier(final ConsensusRoundIdentifier roundChangeIdentifier) {

@ -12,6 +12,7 @@
*/ */
package tech.pegasys.pantheon.consensus.ibft.payload; package tech.pegasys.pantheon.consensus.ibft.payload;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.RoundChange;
import tech.pegasys.pantheon.ethereum.rlp.RLPInput; import tech.pegasys.pantheon.ethereum.rlp.RLPInput;
import tech.pegasys.pantheon.ethereum.rlp.RLPOutput; import tech.pegasys.pantheon.ethereum.rlp.RLPOutput;
@ -20,10 +21,12 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.StringJoiner; import java.util.StringJoiner;
import java.util.stream.Collectors;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
public class RoundChangeCertificate { public class RoundChangeCertificate {
private final Collection<SignedData<RoundChangePayload>> roundChangePayloads; private final Collection<SignedData<RoundChangePayload>> roundChangePayloads;
public RoundChangeCertificate( public RoundChangeCertificate(
@ -52,16 +55,21 @@ public class RoundChangeCertificate {
} }
public static class Builder { public static class Builder {
private final List<SignedData<RoundChangePayload>> roundChangePayloads = Lists.newArrayList();
private final List<RoundChange> roundChangePayloads = Lists.newArrayList();
public Builder() {} public Builder() {}
public void appendRoundChangeMessage(final SignedData<RoundChangePayload> msg) { public void appendRoundChangeMessage(final RoundChange msg) {
roundChangePayloads.add(msg); roundChangePayloads.add(msg);
} }
public RoundChangeCertificate buildCertificate() { public RoundChangeCertificate buildCertificate() {
return new RoundChangeCertificate(roundChangePayloads); return new RoundChangeCertificate(
roundChangePayloads
.stream()
.map(RoundChange::getSignedPayload)
.collect(Collectors.toList()));
} }
} }

@ -144,9 +144,8 @@ public class IbftBlockHeightManager implements BlockHeightManager {
startNewRound(currentRound.getRoundIdentifier().getRoundNumber() + 1); startNewRound(currentRound.getRoundIdentifier().getRoundNumber() + 1);
final RoundChange localRoundChange = final RoundChange localRoundChange =
new RoundChange( messageFactory.createSignedRoundChangePayload(
messageFactory.createSignedRoundChangePayload( currentRound.getRoundIdentifier(), latestPreparedCertificate);
currentRound.getRoundIdentifier(), latestPreparedCertificate));
transmitter.multicastRoundChange(currentRound.getRoundIdentifier(), latestPreparedCertificate); transmitter.multicastRoundChange(currentRound.getRoundIdentifier(), latestPreparedCertificate);
// Its possible the locally created RoundChange triggers the transmission of a NewRound // Its possible the locally created RoundChange triggers the transmission of a NewRound

@ -93,8 +93,7 @@ public class IbftRound {
transmitter.multicastProposal(roundState.getRoundIdentifier(), block); transmitter.multicastProposal(roundState.getRoundIdentifier(), block);
updateStateWithProposedBlock( updateStateWithProposedBlock(
new Proposal( messageFactory.createSignedProposalPayload(roundState.getRoundIdentifier(), block));
messageFactory.createSignedProposalPayload(roundState.getRoundIdentifier(), block)));
} }
public void startRoundWith( public void startRoundWith(
@ -106,8 +105,7 @@ public class IbftRound {
if (!latestCertificate.isPresent()) { if (!latestCertificate.isPresent()) {
LOG.trace("Multicasting NewRound with new block. round={}", roundState.getRoundIdentifier()); LOG.trace("Multicasting NewRound with new block. round={}", roundState.getRoundIdentifier());
final Block block = blockCreator.createBlock(headerTimestamp); final Block block = blockCreator.createBlock(headerTimestamp);
proposal = proposal = messageFactory.createSignedProposalPayload(getRoundIdentifier(), block);
new Proposal(messageFactory.createSignedProposalPayload(getRoundIdentifier(), block));
} else { } else {
LOG.trace( LOG.trace(
"Multicasting NewRound from PreparedCertificate. round={}", "Multicasting NewRound from PreparedCertificate. round={}",
@ -145,7 +143,7 @@ public class IbftRound {
"Created proposal from prepared certificate blockHeader={} extraData={}", "Created proposal from prepared certificate blockHeader={} extraData={}",
block.getHeader(), block.getHeader(),
extraDataToPublish); extraDataToPublish);
return new Proposal(messageFactory.createSignedProposalPayload(getRoundIdentifier(), newBlock)); return messageFactory.createSignedProposalPayload(getRoundIdentifier(), newBlock);
} }
public void handleProposalMessage(final Proposal msg) { public void handleProposalMessage(final Proposal msg) {
@ -175,9 +173,8 @@ public class IbftRound {
LOG.info("Sending prepare message."); LOG.info("Sending prepare message.");
transmitter.multicastPrepare(getRoundIdentifier(), block.getHash()); transmitter.multicastPrepare(getRoundIdentifier(), block.getHash());
final Prepare localPrepareMessage = final Prepare localPrepareMessage =
new Prepare( messageFactory.createSignedPreparePayload(
messageFactory.createSignedPreparePayload( roundState.getRoundIdentifier(), block.getHash());
roundState.getRoundIdentifier(), block.getHash()));
peerIsPrepared(localPrepareMessage); peerIsPrepared(localPrepareMessage);
} }
} }
@ -212,11 +209,10 @@ public class IbftRound {
} }
final Commit localCommitMessage = final Commit localCommitMessage =
new Commit( messageFactory.createSignedCommitPayload(
messageFactory.createSignedCommitPayload( roundState.getRoundIdentifier(),
roundState.getRoundIdentifier(), msg.getSignedPayload().getPayload().getBlock().getHash(),
msg.getSignedPayload().getPayload().getBlock().getHash(), createCommitSeal(roundState.getProposedBlock().get()));
createCommitSeal(roundState.getProposedBlock().get())));
peerIsCommitted(localCommitMessage); peerIsCommitted(localCommitMessage);
} }

@ -17,10 +17,9 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import static tech.pegasys.pantheon.consensus.ibft.IbftHelpers.calculateRequiredValidatorQuorum; import static tech.pegasys.pantheon.consensus.ibft.IbftHelpers.calculateRequiredValidatorQuorum;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Proposal;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate; import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate;
import tech.pegasys.pantheon.consensus.ibft.payload.ProposalPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.core.Block; import tech.pegasys.pantheon.ethereum.core.Block;
import tech.pegasys.pantheon.ethereum.core.Hash; import tech.pegasys.pantheon.ethereum.core.Hash;
@ -90,42 +89,48 @@ public class IbftHelpersTest {
final ConsensusRoundIdentifier roundIdentifier = new ConsensusRoundIdentifier(1, 4); final ConsensusRoundIdentifier roundIdentifier = new ConsensusRoundIdentifier(1, 4);
final ConsensusRoundIdentifier preparedRound = TestHelpers.createFrom(roundIdentifier, 0, -1); final ConsensusRoundIdentifier preparedRound = TestHelpers.createFrom(roundIdentifier, 0, -1);
final SignedData<ProposalPayload> differentProposal = final Proposal differentProposal =
proposerMessageFactory.createSignedProposalPayload(preparedRound, proposedBlock); proposerMessageFactory.createSignedProposalPayload(preparedRound, proposedBlock);
final Optional<PreparedCertificate> latterPreparedCert = final Optional<PreparedCertificate> latterPreparedCert =
Optional.of( Optional.of(
new PreparedCertificate( new PreparedCertificate(
differentProposal, differentProposal.getSignedPayload(),
Lists.newArrayList( Lists.newArrayList(
proposerMessageFactory.createSignedPreparePayload( proposerMessageFactory
roundIdentifier, proposedBlock.getHash()), .createSignedPreparePayload(roundIdentifier, proposedBlock.getHash())
proposerMessageFactory.createSignedPreparePayload( .getSignedPayload(),
roundIdentifier, proposedBlock.getHash())))); proposerMessageFactory
.createSignedPreparePayload(roundIdentifier, proposedBlock.getHash())
.getSignedPayload())));
// An earlier PrepareCert is added to ensure the path to find the latest PrepareCert // An earlier PrepareCert is added to ensure the path to find the latest PrepareCert
// is correctly followed. // is correctly followed.
final ConsensusRoundIdentifier earlierPreparedRound = final ConsensusRoundIdentifier earlierPreparedRound =
TestHelpers.createFrom(roundIdentifier, 0, -2); TestHelpers.createFrom(roundIdentifier, 0, -2);
final SignedData<ProposalPayload> earlierProposal = final Proposal earlierProposal =
proposerMessageFactory.createSignedProposalPayload(earlierPreparedRound, proposedBlock); proposerMessageFactory.createSignedProposalPayload(earlierPreparedRound, proposedBlock);
final Optional<PreparedCertificate> earlierPreparedCert = final Optional<PreparedCertificate> earlierPreparedCert =
Optional.of( Optional.of(
new PreparedCertificate( new PreparedCertificate(
earlierProposal, earlierProposal.getSignedPayload(),
Lists.newArrayList( Lists.newArrayList(
proposerMessageFactory.createSignedPreparePayload( proposerMessageFactory
earlierPreparedRound, proposedBlock.getHash()), .createSignedPreparePayload(earlierPreparedRound, proposedBlock.getHash())
proposerMessageFactory.createSignedPreparePayload( .getSignedPayload(),
earlierPreparedRound, proposedBlock.getHash())))); proposerMessageFactory
.createSignedPreparePayload(earlierPreparedRound, proposedBlock.getHash())
.getSignedPayload())));
final Optional<PreparedCertificate> newestCert = final Optional<PreparedCertificate> newestCert =
IbftHelpers.findLatestPreparedCertificate( IbftHelpers.findLatestPreparedCertificate(
Lists.newArrayList( Lists.newArrayList(
proposerMessageFactory.createSignedRoundChangePayload( proposerMessageFactory
roundIdentifier, earlierPreparedCert), .createSignedRoundChangePayload(roundIdentifier, earlierPreparedCert)
proposerMessageFactory.createSignedRoundChangePayload( .getSignedPayload(),
roundIdentifier, latterPreparedCert))); proposerMessageFactory
.createSignedRoundChangePayload(roundIdentifier, latterPreparedCert)
.getSignedPayload()));
assertThat(newestCert).isEqualTo(latterPreparedCert); assertThat(newestCert).isEqualTo(latterPreparedCert);
} }
@ -139,10 +144,12 @@ public class IbftHelpersTest {
final Optional<PreparedCertificate> newestCert = final Optional<PreparedCertificate> newestCert =
IbftHelpers.findLatestPreparedCertificate( IbftHelpers.findLatestPreparedCertificate(
Lists.newArrayList( Lists.newArrayList(
proposerMessageFactory.createSignedRoundChangePayload( proposerMessageFactory
roundIdentifier, Optional.empty()), .createSignedRoundChangePayload(roundIdentifier, Optional.empty())
proposerMessageFactory.createSignedRoundChangePayload( .getSignedPayload(),
roundIdentifier, Optional.empty()))); proposerMessageFactory
.createSignedRoundChangePayload(roundIdentifier, Optional.empty())
.getSignedPayload()));
assertThat(newestCert).isEmpty(); assertThat(newestCert).isEmpty();
} }

@ -72,34 +72,32 @@ public class TestHelpers {
new ConsensusRoundIdentifier(0x1234567890ABCDEFL, round); new ConsensusRoundIdentifier(0x1234567890ABCDEFL, round);
final Block block = final Block block =
TestHelpers.createProposalBlock(singletonList(AddressHelpers.ofValue(1)), 0); TestHelpers.createProposalBlock(singletonList(AddressHelpers.ofValue(1)), 0);
return new Proposal(messageFactory.createSignedProposalPayload(roundIdentifier, block)); return messageFactory.createSignedProposalPayload(roundIdentifier, block);
} }
public static Prepare createSignedPreparePayload(final KeyPair signerKeys) { public static Prepare createSignedPreparePayload(final KeyPair signerKeys) {
final MessageFactory messageFactory = new MessageFactory(signerKeys); final MessageFactory messageFactory = new MessageFactory(signerKeys);
final ConsensusRoundIdentifier roundIdentifier = final ConsensusRoundIdentifier roundIdentifier =
new ConsensusRoundIdentifier(0x1234567890ABCDEFL, 0xFEDCBA98); new ConsensusRoundIdentifier(0x1234567890ABCDEFL, 0xFEDCBA98);
return new Prepare( return messageFactory.createSignedPreparePayload(
messageFactory.createSignedPreparePayload(roundIdentifier, Hash.fromHexStringLenient("0"))); roundIdentifier, Hash.fromHexStringLenient("0"));
} }
public static Commit createSignedCommitPayload(final KeyPair signerKeys) { public static Commit createSignedCommitPayload(final KeyPair signerKeys) {
final MessageFactory messageFactory = new MessageFactory(signerKeys); final MessageFactory messageFactory = new MessageFactory(signerKeys);
final ConsensusRoundIdentifier roundIdentifier = final ConsensusRoundIdentifier roundIdentifier =
new ConsensusRoundIdentifier(0x1234567890ABCDEFL, 0xFEDCBA98); new ConsensusRoundIdentifier(0x1234567890ABCDEFL, 0xFEDCBA98);
return new Commit( return messageFactory.createSignedCommitPayload(
messageFactory.createSignedCommitPayload( roundIdentifier,
roundIdentifier, Hash.fromHexStringLenient("0"),
Hash.fromHexStringLenient("0"), Signature.create(BigInteger.ONE, BigInteger.TEN, (byte) 0));
Signature.create(BigInteger.ONE, BigInteger.TEN, (byte) 0)));
} }
public static RoundChange createSignedRoundChangePayload(final KeyPair signerKeys) { public static RoundChange createSignedRoundChangePayload(final KeyPair signerKeys) {
final MessageFactory messageFactory = new MessageFactory(signerKeys); final MessageFactory messageFactory = new MessageFactory(signerKeys);
final ConsensusRoundIdentifier roundIdentifier = final ConsensusRoundIdentifier roundIdentifier =
new ConsensusRoundIdentifier(0x1234567890ABCDEFL, 0xFEDCBA98); new ConsensusRoundIdentifier(0x1234567890ABCDEFL, 0xFEDCBA98);
return new RoundChange( return messageFactory.createSignedRoundChangePayload(roundIdentifier, Optional.empty());
messageFactory.createSignedRoundChangePayload(roundIdentifier, Optional.empty()));
} }
public static NewRound createSignedNewRoundPayload(final KeyPair signerKeys) { public static NewRound createSignedNewRoundPayload(final KeyPair signerKeys) {
@ -107,10 +105,9 @@ public class TestHelpers {
final ConsensusRoundIdentifier roundIdentifier = final ConsensusRoundIdentifier roundIdentifier =
new ConsensusRoundIdentifier(0x1234567890ABCDEFL, 0xFEDCBA98); new ConsensusRoundIdentifier(0x1234567890ABCDEFL, 0xFEDCBA98);
final Proposal proposalPayload = createSignedProposalPayload(signerKeys); final Proposal proposalPayload = createSignedProposalPayload(signerKeys);
return new NewRound( return messageFactory.createSignedNewRoundPayload(
messageFactory.createSignedNewRoundPayload( roundIdentifier,
roundIdentifier, new RoundChangeCertificate(newArrayList()),
new RoundChangeCertificate(newArrayList()), proposalPayload.getSignedPayload());
proposalPayload.getSignedPayload()));
} }
} }

@ -217,8 +217,7 @@ public class IbftBlockHeightManagerTest {
public void onRoundChangeReceptionRoundChangeManagerIsInvokedAndNewRoundStarted() { public void onRoundChangeReceptionRoundChangeManagerIsInvokedAndNewRoundStarted() {
final ConsensusRoundIdentifier futureRoundIdentifier = createFrom(roundIdentifier, 0, +2); final ConsensusRoundIdentifier futureRoundIdentifier = createFrom(roundIdentifier, 0, +2);
final RoundChange roundChange = final RoundChange roundChange =
new RoundChange( messageFactory.createSignedRoundChangePayload(futureRoundIdentifier, Optional.empty());
messageFactory.createSignedRoundChangePayload(futureRoundIdentifier, Optional.empty()));
when(roundChangeManager.appendRoundChangeMessage(any())) when(roundChangeManager.appendRoundChangeMessage(any()))
.thenReturn( .thenReturn(
Optional.of(new RoundChangeCertificate(singletonList(roundChange.getSignedPayload())))); Optional.of(new RoundChangeCertificate(singletonList(roundChange.getSignedPayload()))));
@ -263,8 +262,7 @@ public class IbftBlockHeightManagerTest {
public void whenSufficientRoundChangesAreReceivedANewRoundMessageIsTransmitted() { public void whenSufficientRoundChangesAreReceivedANewRoundMessageIsTransmitted() {
final ConsensusRoundIdentifier futureRoundIdentifier = createFrom(roundIdentifier, 0, +2); final ConsensusRoundIdentifier futureRoundIdentifier = createFrom(roundIdentifier, 0, +2);
final RoundChange roundChange = final RoundChange roundChange =
new RoundChange( messageFactory.createSignedRoundChangePayload(futureRoundIdentifier, Optional.empty());
messageFactory.createSignedRoundChangePayload(futureRoundIdentifier, Optional.empty()));
final RoundChangeCertificate roundChangCert = final RoundChangeCertificate roundChangCert =
new RoundChangeCertificate(singletonList(roundChange.getSignedPayload())); new RoundChangeCertificate(singletonList(roundChange.getSignedPayload()));
@ -303,29 +301,28 @@ public class IbftBlockHeightManagerTest {
manager.start(); manager.start();
final Prepare prepare = final Prepare prepare =
new Prepare( validatorMessageFactory
validatorMessageFactory .get(0)
.get(0) .createSignedPreparePayload(futureRoundIdentifier, Hash.fromHexStringLenient("0"));
.createSignedPreparePayload(futureRoundIdentifier, Hash.fromHexStringLenient("0")));
final Commit commit = final Commit commit =
new Commit( validatorMessageFactory
validatorMessageFactory .get(1)
.get(1) .createSignedCommitPayload(
.createSignedCommitPayload( futureRoundIdentifier,
futureRoundIdentifier, Hash.fromHexStringLenient("0"),
Hash.fromHexStringLenient("0"), Signature.create(BigInteger.ONE, BigInteger.ONE, (byte) 1));
Signature.create(BigInteger.ONE, BigInteger.ONE, (byte) 1)));
manager.handlePreparePayload(prepare); manager.handlePreparePayload(prepare);
manager.handleCommitPayload(commit); manager.handleCommitPayload(commit);
// Force a new round to be started at new round number. // Force a new round to be started at new round number.
final NewRound newRound = final NewRound newRound =
new NewRound( messageFactory.createSignedNewRoundPayload(
messageFactory.createSignedNewRoundPayload( futureRoundIdentifier,
futureRoundIdentifier, new RoundChangeCertificate(Collections.emptyList()),
new RoundChangeCertificate(Collections.emptyList()), messageFactory
messageFactory.createSignedProposalPayload(futureRoundIdentifier, createdBlock))); .createSignedProposalPayload(futureRoundIdentifier, createdBlock)
.getSignedPayload());
manager.handleNewRoundPayload(newRound); manager.handleNewRoundPayload(newRound);
@ -348,15 +345,13 @@ public class IbftBlockHeightManagerTest {
manager.handleBlockTimerExpiry(roundIdentifier); // Trigger a Proposal creation. manager.handleBlockTimerExpiry(roundIdentifier); // Trigger a Proposal creation.
final Prepare firstPrepare = final Prepare firstPrepare =
new Prepare( validatorMessageFactory
validatorMessageFactory .get(0)
.get(0) .createSignedPreparePayload(roundIdentifier, Hash.fromHexStringLenient("0"));
.createSignedPreparePayload(roundIdentifier, Hash.fromHexStringLenient("0")));
final Prepare secondPrepare = final Prepare secondPrepare =
new Prepare( validatorMessageFactory
validatorMessageFactory .get(1)
.get(1) .createSignedPreparePayload(roundIdentifier, Hash.fromHexStringLenient("0"));
.createSignedPreparePayload(roundIdentifier, Hash.fromHexStringLenient("0")));
manager.handlePreparePayload(firstPrepare); manager.handlePreparePayload(firstPrepare);
manager.handlePreparePayload(secondPrepare); manager.handlePreparePayload(secondPrepare);

@ -28,9 +28,6 @@ import tech.pegasys.pantheon.consensus.ibft.IbftBlockHashing;
import tech.pegasys.pantheon.consensus.ibft.IbftContext; import tech.pegasys.pantheon.consensus.ibft.IbftContext;
import tech.pegasys.pantheon.consensus.ibft.IbftExtraData; import tech.pegasys.pantheon.consensus.ibft.IbftExtraData;
import tech.pegasys.pantheon.consensus.ibft.blockcreation.IbftBlockCreator; import tech.pegasys.pantheon.consensus.ibft.blockcreation.IbftBlockCreator;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Commit;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Prepare;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Proposal;
import tech.pegasys.pantheon.consensus.ibft.network.IbftMessageTransmitter; import tech.pegasys.pantheon.consensus.ibft.network.IbftMessageTransmitter;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate; import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate;
@ -140,7 +137,7 @@ public class IbftRoundTest {
transmitter); transmitter);
round.handleProposalMessage( round.handleProposalMessage(
new Proposal(messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock))); messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock));
verify(transmitter, times(1)).multicastPrepare(roundIdentifier, proposedBlock.getHash()); verify(transmitter, times(1)).multicastPrepare(roundIdentifier, proposedBlock.getHash());
verify(transmitter, never()).multicastCommit(any(), any(), any()); verify(transmitter, never()).multicastCommit(any(), any(), any());
} }
@ -206,7 +203,7 @@ public class IbftRoundTest {
// Receive Proposal Message // Receive Proposal Message
round.handleProposalMessage( round.handleProposalMessage(
new Proposal(messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock))); messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock));
verify(transmitter, times(1)).multicastPrepare(roundIdentifier, proposedBlock.getHash()); verify(transmitter, times(1)).multicastPrepare(roundIdentifier, proposedBlock.getHash());
verify(transmitter, times(1)) verify(transmitter, times(1))
.multicastCommit(roundIdentifier, proposedBlock.getHash(), localCommitSeal); .multicastCommit(roundIdentifier, proposedBlock.getHash(), localCommitSeal);
@ -215,9 +212,8 @@ public class IbftRoundTest {
// Receive Commit Message // Receive Commit Message
round.handleCommitMessage( round.handleCommitMessage(
new Commit( messageFactory.createSignedCommitPayload(
messageFactory.createSignedCommitPayload( roundIdentifier, proposedBlock.getHash(), remoteCommitSeal));
roundIdentifier, proposedBlock.getHash(), remoteCommitSeal)));
// Should import block when both commit seals are available. // Should import block when both commit seals are available.
ArgumentCaptor<Block> capturedBlock = ArgumentCaptor.forClass(Block.class); ArgumentCaptor<Block> capturedBlock = ArgumentCaptor.forClass(Block.class);
@ -253,17 +249,15 @@ public class IbftRoundTest {
verify(blockImporter, never()).importBlock(any(), any(), any()); verify(blockImporter, never()).importBlock(any(), any(), any());
round.handlePrepareMessage( round.handlePrepareMessage(
new Prepare( messageFactory.createSignedPreparePayload(roundIdentifier, proposedBlock.getHash()));
messageFactory.createSignedPreparePayload(roundIdentifier, proposedBlock.getHash())));
verify(transmitter, times(1)) verify(transmitter, times(1))
.multicastCommit(roundIdentifier, proposedBlock.getHash(), localCommitSeal); .multicastCommit(roundIdentifier, proposedBlock.getHash(), localCommitSeal);
verify(blockImporter, never()).importBlock(any(), any(), any()); verify(blockImporter, never()).importBlock(any(), any(), any());
round.handleCommitMessage( round.handleCommitMessage(
new Commit( messageFactory.createSignedCommitPayload(
messageFactory.createSignedCommitPayload( roundIdentifier, proposedBlock.getHash(), remoteCommitSeal));
roundIdentifier, proposedBlock.getHash(), remoteCommitSeal)));
verify(blockImporter, times(1)).importBlock(any(), any(), any()); verify(blockImporter, times(1)).importBlock(any(), any(), any());
} }
@ -307,15 +301,17 @@ public class IbftRoundTest {
final RoundChangeCertificate roundChangeCertificate = final RoundChangeCertificate roundChangeCertificate =
new RoundChangeCertificate( new RoundChangeCertificate(
Collections.singletonList( Collections.singletonList(
messageFactory.createSignedRoundChangePayload( messageFactory
roundIdentifier, .createSignedRoundChangePayload(
Optional.of( roundIdentifier,
new PreparedCertificate( Optional.of(
messageFactory.createSignedProposalPayload( new PreparedCertificate(
priorRoundChange, proposedBlock), messageFactory
Collections .createSignedProposalPayload(priorRoundChange, proposedBlock)
.emptyList()))))); // NOTE: IbftRound assumes the prepare's are .getSignedPayload(),
// valid Collections.emptyList())))
.getSignedPayload()));
// NOTE: IbftRound assumes the prepare's are valid
round.startRoundWith(roundChangeCertificate, 15); round.startRoundWith(roundChangeCertificate, 15);
verify(transmitter, times(1)) verify(transmitter, times(1))
@ -330,8 +326,7 @@ public class IbftRoundTest {
// Inject a single Prepare message, and confirm the roundState has gone to Prepared (which // Inject a single Prepare message, and confirm the roundState has gone to Prepared (which
// indicates the block has entered the roundState (note: all msgs are deemed valid due to mocks) // indicates the block has entered the roundState (note: all msgs are deemed valid due to mocks)
round.handlePrepareMessage( round.handlePrepareMessage(
new Prepare( messageFactory.createSignedPreparePayload(roundIdentifier, proposedBlock.getHash()));
messageFactory.createSignedPreparePayload(roundIdentifier, proposedBlock.getHash())));
assertThat(roundState.isPrepared()).isTrue(); assertThat(roundState.isPrepared()).isTrue();
} }
@ -352,7 +347,9 @@ public class IbftRoundTest {
final RoundChangeCertificate roundChangeCertificate = final RoundChangeCertificate roundChangeCertificate =
new RoundChangeCertificate( new RoundChangeCertificate(
Collections.singletonList( Collections.singletonList(
messageFactory.createSignedRoundChangePayload(roundIdentifier, Optional.empty()))); messageFactory
.createSignedRoundChangePayload(roundIdentifier, Optional.empty())
.getSignedPayload()));
round.startRoundWith(roundChangeCertificate, 15); round.startRoundWith(roundChangeCertificate, 15);
verify(transmitter, times(1)) verify(transmitter, times(1))
@ -362,8 +359,7 @@ public class IbftRoundTest {
// Inject a single Prepare message, and confirm the roundState has gone to Prepared (which // Inject a single Prepare message, and confirm the roundState has gone to Prepared (which
// indicates the block has entered the roundState (note: all msgs are deemed valid due to mocks) // indicates the block has entered the roundState (note: all msgs are deemed valid due to mocks)
round.handlePrepareMessage( round.handlePrepareMessage(
new Prepare( messageFactory.createSignedPreparePayload(roundIdentifier, proposedBlock.getHash()));
messageFactory.createSignedPreparePayload(roundIdentifier, proposedBlock.getHash())));
assertThat(roundState.isPrepared()).isTrue(); assertThat(roundState.isPrepared()).isTrue();
} }
@ -401,12 +397,11 @@ public class IbftRoundTest {
transmitter); transmitter);
round.handleCommitMessage( round.handleCommitMessage(
new Commit( messageFactory.createSignedCommitPayload(
messageFactory.createSignedCommitPayload( roundIdentifier, proposedBlock.getHash(), remoteCommitSeal));
roundIdentifier, proposedBlock.getHash(), remoteCommitSeal)));
round.handleProposalMessage( round.handleProposalMessage(
new Proposal(messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock))); messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock));
verify(blockImporter, times(1)).importBlock(any(), any(), any()); verify(blockImporter, times(1)).importBlock(any(), any(), any());
} }
@ -427,12 +422,11 @@ public class IbftRoundTest {
transmitter); transmitter);
round.handleCommitMessage( round.handleCommitMessage(
new Commit( messageFactory.createSignedCommitPayload(
messageFactory.createSignedCommitPayload( roundIdentifier, proposedBlock.getHash(), remoteCommitSeal));
roundIdentifier, proposedBlock.getHash(), remoteCommitSeal)));
round.handleProposalMessage( round.handleProposalMessage(
new Proposal(messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock))); messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock));
verify(blockImporter, times(1)).importBlock(any(), any(), any()); verify(blockImporter, times(1)).importBlock(any(), any(), any());
} }

@ -21,11 +21,11 @@ import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.IbftContext; import tech.pegasys.pantheon.consensus.ibft.IbftContext;
import tech.pegasys.pantheon.consensus.ibft.IbftHelpers; import tech.pegasys.pantheon.consensus.ibft.IbftHelpers;
import tech.pegasys.pantheon.consensus.ibft.TestHelpers; import tech.pegasys.pantheon.consensus.ibft.TestHelpers;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Proposal;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.RoundChange; import tech.pegasys.pantheon.consensus.ibft.messagewrappers.RoundChange;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparePayload; import tech.pegasys.pantheon.consensus.ibft.payload.PreparePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate; import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate;
import tech.pegasys.pantheon.consensus.ibft.payload.ProposalPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData; import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.validation.MessageValidator; import tech.pegasys.pantheon.consensus.ibft.validation.MessageValidator;
import tech.pegasys.pantheon.consensus.ibft.validation.RoundChangeMessageValidator; import tech.pegasys.pantheon.consensus.ibft.validation.RoundChangeMessageValidator;
@ -129,7 +129,7 @@ public class RoundChangeManagerTest {
private RoundChange makeRoundChangeMessage( private RoundChange makeRoundChangeMessage(
final KeyPair key, final ConsensusRoundIdentifier round) { final KeyPair key, final ConsensusRoundIdentifier round) {
MessageFactory messageFactory = new MessageFactory(key); MessageFactory messageFactory = new MessageFactory(key);
return new RoundChange(messageFactory.createSignedRoundChangePayload(round, Optional.empty())); return messageFactory.createSignedRoundChangePayload(round, Optional.empty());
} }
private RoundChange makeRoundChangeMessageWithPreparedCert( private RoundChange makeRoundChangeMessageWithPreparedCert(
@ -143,8 +143,7 @@ public class RoundChangeManagerTest {
final ConsensusRoundIdentifier proposalRound = TestHelpers.createFrom(round, 0, -1); final ConsensusRoundIdentifier proposalRound = TestHelpers.createFrom(round, 0, -1);
final Block block = TestHelpers.createProposalBlock(validators, proposalRound.getRoundNumber()); final Block block = TestHelpers.createProposalBlock(validators, proposalRound.getRoundNumber());
// Proposal must come from an earlier round. // Proposal must come from an earlier round.
final SignedData<ProposalPayload> proposal = final Proposal proposal = messageFactory.createSignedProposalPayload(proposalRound, block);
messageFactory.createSignedProposalPayload(proposalRound, block);
final List<SignedData<PreparePayload>> preparePayloads = final List<SignedData<PreparePayload>> preparePayloads =
prepareProviders prepareProviders
@ -152,13 +151,16 @@ public class RoundChangeManagerTest {
.map( .map(
k -> { k -> {
final MessageFactory prepareFactory = new MessageFactory(k); final MessageFactory prepareFactory = new MessageFactory(k);
return prepareFactory.createSignedPreparePayload(proposalRound, block.getHash()); return prepareFactory
.createSignedPreparePayload(proposalRound, block.getHash())
.getSignedPayload();
}) })
.collect(Collectors.toList()); .collect(Collectors.toList());
final PreparedCertificate cert = new PreparedCertificate(proposal, preparePayloads); final PreparedCertificate cert =
new PreparedCertificate(proposal.getSignedPayload(), preparePayloads);
return new RoundChange(messageFactory.createSignedRoundChangePayload(round, Optional.of(cert))); return messageFactory.createSignedRoundChangePayload(round, Optional.of(cert));
} }
@Test @Test

@ -23,8 +23,6 @@ import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Commit;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Prepare; import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Prepare;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Proposal; import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Proposal;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.validation.MessageValidator; import tech.pegasys.pantheon.consensus.ibft.validation.MessageValidator;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.crypto.SECP256K1.Signature; import tech.pegasys.pantheon.crypto.SECP256K1.Signature;
@ -82,8 +80,7 @@ public class RoundStateTest {
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator); final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator);
final Proposal proposal = final Proposal proposal =
new Proposal( validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block);
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block));
assertThat(roundState.setProposedBlock(proposal)).isFalse(); assertThat(roundState.setProposedBlock(proposal)).isFalse();
assertThat(roundState.isPrepared()).isFalse(); assertThat(roundState.isPrepared()).isFalse();
@ -97,8 +94,7 @@ public class RoundStateTest {
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator); final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator);
final Proposal proposal = final Proposal proposal =
new Proposal( validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block);
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block));
assertThat(roundState.setProposedBlock(proposal)).isTrue(); assertThat(roundState.setProposedBlock(proposal)).isTrue();
assertThat(roundState.isPrepared()).isTrue(); assertThat(roundState.isPrepared()).isTrue();
@ -116,21 +112,19 @@ public class RoundStateTest {
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator); final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator);
final Proposal proposal = final Proposal proposal =
new Proposal( validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block);
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block));
assertThat(roundState.setProposedBlock(proposal)).isTrue(); assertThat(roundState.setProposedBlock(proposal)).isTrue();
assertThat(roundState.isPrepared()).isTrue(); assertThat(roundState.isPrepared()).isTrue();
assertThat(roundState.isCommitted()).isFalse(); assertThat(roundState.isCommitted()).isFalse();
final Commit commit = final Commit commit =
new Commit( validatorMessageFactories
validatorMessageFactories .get(0)
.get(0) .createSignedCommitPayload(
.createSignedCommitPayload( roundIdentifier,
roundIdentifier, block.getHash(),
block.getHash(), Signature.create(BigInteger.ONE, BigInteger.ONE, (byte) 1));
Signature.create(BigInteger.ONE, BigInteger.ONE, (byte) 1)));
roundState.addCommitMessage(commit); roundState.addCommitMessage(commit);
assertThat(roundState.isPrepared()).isTrue(); assertThat(roundState.isPrepared()).isTrue();
@ -146,16 +140,14 @@ public class RoundStateTest {
final RoundState roundState = new RoundState(roundIdentifier, 3, messageValidator); final RoundState roundState = new RoundState(roundIdentifier, 3, messageValidator);
final Prepare firstPrepare = final Prepare firstPrepare =
new Prepare( validatorMessageFactories
validatorMessageFactories .get(1)
.get(1) .createSignedPreparePayload(roundIdentifier, block.getHash());
.createSignedPreparePayload(roundIdentifier, block.getHash()));
final Prepare secondPrepare = final Prepare secondPrepare =
new Prepare( validatorMessageFactories
validatorMessageFactories .get(2)
.get(2) .createSignedPreparePayload(roundIdentifier, block.getHash());
.createSignedPreparePayload(roundIdentifier, block.getHash()));
roundState.addPrepareMessage(firstPrepare); roundState.addPrepareMessage(firstPrepare);
assertThat(roundState.isPrepared()).isFalse(); assertThat(roundState.isPrepared()).isFalse();
@ -168,8 +160,7 @@ public class RoundStateTest {
assertThat(roundState.constructPreparedCertificate()).isEmpty(); assertThat(roundState.constructPreparedCertificate()).isEmpty();
final Proposal proposal = final Proposal proposal =
new Proposal( validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block);
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block));
assertThat(roundState.setProposedBlock(proposal)).isTrue(); assertThat(roundState.setProposedBlock(proposal)).isTrue();
assertThat(roundState.isPrepared()).isTrue(); assertThat(roundState.isPrepared()).isTrue();
assertThat(roundState.isCommitted()).isFalse(); assertThat(roundState.isCommitted()).isFalse();
@ -178,12 +169,12 @@ public class RoundStateTest {
@Test @Test
public void invalidPriorPrepareMessagesAreDiscardedUponSubsequentProposal() { public void invalidPriorPrepareMessagesAreDiscardedUponSubsequentProposal() {
final SignedData<PreparePayload> firstPrepare = final Prepare firstPrepare =
validatorMessageFactories validatorMessageFactories
.get(1) .get(1)
.createSignedPreparePayload(roundIdentifier, block.getHash()); .createSignedPreparePayload(roundIdentifier, block.getHash());
final SignedData<PreparePayload> secondPrepare = final Prepare secondPrepare =
validatorMessageFactories validatorMessageFactories
.get(2) .get(2)
.createSignedPreparePayload(roundIdentifier, block.getHash()); .createSignedPreparePayload(roundIdentifier, block.getHash());
@ -193,16 +184,16 @@ public class RoundStateTest {
final RoundState roundState = new RoundState(roundIdentifier, 3, messageValidator); final RoundState roundState = new RoundState(roundIdentifier, 3, messageValidator);
when(messageValidator.addSignedProposalPayload(any())).thenReturn(true); when(messageValidator.addSignedProposalPayload(any())).thenReturn(true);
when(messageValidator.validatePrepareMessage(firstPrepare)).thenReturn(true); when(messageValidator.validatePrepareMessage(firstPrepare.getSignedPayload())).thenReturn(true);
when(messageValidator.validatePrepareMessage(secondPrepare)).thenReturn(false); when(messageValidator.validatePrepareMessage(secondPrepare.getSignedPayload()))
.thenReturn(false);
roundState.addPrepareMessage(new Prepare(firstPrepare)); roundState.addPrepareMessage(firstPrepare);
roundState.addPrepareMessage(new Prepare(secondPrepare)); roundState.addPrepareMessage(secondPrepare);
verify(messageValidator, never()).validatePrepareMessage(any()); verify(messageValidator, never()).validatePrepareMessage(any());
final Proposal proposal = final Proposal proposal =
new Proposal( validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block);
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block));
assertThat(roundState.setProposedBlock(proposal)).isTrue(); assertThat(roundState.setProposedBlock(proposal)).isTrue();
assertThat(roundState.isPrepared()).isFalse(); assertThat(roundState.isPrepared()).isFalse();
@ -214,31 +205,32 @@ public class RoundStateTest {
public void prepareMessageIsValidatedAgainstExitingProposal() { public void prepareMessageIsValidatedAgainstExitingProposal() {
final RoundState roundState = new RoundState(roundIdentifier, 2, messageValidator); final RoundState roundState = new RoundState(roundIdentifier, 2, messageValidator);
final SignedData<PreparePayload> firstPrepare = final Prepare firstPrepare =
validatorMessageFactories validatorMessageFactories
.get(1) .get(1)
.createSignedPreparePayload(roundIdentifier, block.getHash()); .createSignedPreparePayload(roundIdentifier, block.getHash());
final SignedData<PreparePayload> secondPrepare = final Prepare secondPrepare =
validatorMessageFactories validatorMessageFactories
.get(2) .get(2)
.createSignedPreparePayload(roundIdentifier, block.getHash()); .createSignedPreparePayload(roundIdentifier, block.getHash());
final Proposal proposal = final Proposal proposal =
new Proposal( validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block);
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block));
when(messageValidator.addSignedProposalPayload(any())).thenReturn(true); when(messageValidator.addSignedProposalPayload(any())).thenReturn(true);
when(messageValidator.validatePrepareMessage(firstPrepare)).thenReturn(false); when(messageValidator.validatePrepareMessage(firstPrepare.getSignedPayload()))
when(messageValidator.validatePrepareMessage(secondPrepare)).thenReturn(true); .thenReturn(false);
when(messageValidator.validatePrepareMessage(secondPrepare.getSignedPayload()))
.thenReturn(true);
roundState.setProposedBlock(proposal); roundState.setProposedBlock(proposal);
assertThat(roundState.isPrepared()).isFalse(); assertThat(roundState.isPrepared()).isFalse();
roundState.addPrepareMessage(new Prepare(firstPrepare)); roundState.addPrepareMessage(firstPrepare);
assertThat(roundState.isPrepared()).isFalse(); assertThat(roundState.isPrepared()).isFalse();
roundState.addPrepareMessage(new Prepare(secondPrepare)); roundState.addPrepareMessage(secondPrepare);
assertThat(roundState.isPrepared()).isTrue(); assertThat(roundState.isPrepared()).isTrue();
} }
@ -250,26 +242,23 @@ public class RoundStateTest {
final RoundState roundState = new RoundState(roundIdentifier, 2, messageValidator); final RoundState roundState = new RoundState(roundIdentifier, 2, messageValidator);
final Commit firstCommit = final Commit firstCommit =
new Commit( validatorMessageFactories
validatorMessageFactories .get(1)
.get(1) .createSignedCommitPayload(
.createSignedCommitPayload( roundIdentifier,
roundIdentifier, block.getHash(),
block.getHash(), Signature.create(BigInteger.ONE, BigInteger.TEN, (byte) 1));
Signature.create(BigInteger.ONE, BigInteger.TEN, (byte) 1)));
final Commit secondCommit = final Commit secondCommit =
new Commit( validatorMessageFactories
validatorMessageFactories .get(2)
.get(2) .createSignedCommitPayload(
.createSignedCommitPayload( roundIdentifier,
roundIdentifier, block.getHash(),
block.getHash(), Signature.create(BigInteger.TEN, BigInteger.TEN, (byte) 1));
Signature.create(BigInteger.TEN, BigInteger.TEN, (byte) 1)));
final Proposal proposal = final Proposal proposal =
new Proposal( validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block);
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block));
roundState.setProposedBlock(proposal); roundState.setProposedBlock(proposal);
roundState.addCommitMessage(firstCommit); roundState.addCommitMessage(firstCommit);

@ -21,11 +21,10 @@ import static org.mockito.Mockito.when;
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier; import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.IbftContext; import tech.pegasys.pantheon.consensus.ibft.IbftContext;
import tech.pegasys.pantheon.consensus.ibft.IbftExtraData; import tech.pegasys.pantheon.consensus.ibft.IbftExtraData;
import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload; import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Commit;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Prepare;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Proposal;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.ProposalPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.crypto.SECP256K1; import tech.pegasys.pantheon.crypto.SECP256K1;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.BlockValidator; import tech.pegasys.pantheon.ethereum.BlockValidator;
@ -105,164 +104,164 @@ public class MessageValidatorTest {
@Test @Test
public void receivingAPrepareMessageBeforeProposalFails() { public void receivingAPrepareMessageBeforeProposalFails() {
final SignedData<PreparePayload> prepareMsg = final Prepare prepareMsg =
proposerMessageFactory.createSignedPreparePayload(roundIdentifier, Hash.ZERO); proposerMessageFactory.createSignedPreparePayload(roundIdentifier, Hash.ZERO);
assertThat(validator.validatePrepareMessage(prepareMsg)).isFalse(); assertThat(validator.validatePrepareMessage(prepareMsg.getSignedPayload())).isFalse();
} }
@Test @Test
public void receivingACommitMessageBeforeProposalFails() { public void receivingACommitMessageBeforeProposalFails() {
final SignedData<CommitPayload> commitMsg = final Commit commitMsg =
proposerMessageFactory.createSignedCommitPayload( proposerMessageFactory.createSignedCommitPayload(
roundIdentifier, Hash.ZERO, SECP256K1.sign(Hash.ZERO, proposerKey)); roundIdentifier, Hash.ZERO, SECP256K1.sign(Hash.ZERO, proposerKey));
assertThat(validator.validateCommmitMessage(commitMsg)).isFalse(); assertThat(validator.validateCommmitMessage(commitMsg.getSignedPayload())).isFalse();
} }
@Test @Test
public void receivingProposalMessageFromNonProposerFails() { public void receivingProposalMessageFromNonProposerFails() {
final SignedData<ProposalPayload> proposalMsg = final Proposal proposalMsg =
validatorMessageFactory.createSignedProposalPayload(roundIdentifier, mock(Block.class)); validatorMessageFactory.createSignedProposalPayload(roundIdentifier, mock(Block.class));
assertThat(validator.addSignedProposalPayload(proposalMsg)).isFalse(); assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isFalse();
} }
@Test @Test
public void receivingProposalMessageWithIllegalBlockFails() { public void receivingProposalMessageWithIllegalBlockFails() {
when(blockValidator.validateAndProcessBlock(any(), any(), any(), any())).thenReturn(empty()); when(blockValidator.validateAndProcessBlock(any(), any(), any(), any())).thenReturn(empty());
final SignedData<ProposalPayload> proposalMsg = final Proposal proposalMsg =
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, mock(Block.class)); proposerMessageFactory.createSignedProposalPayload(roundIdentifier, mock(Block.class));
assertThat(validator.addSignedProposalPayload(proposalMsg)).isFalse(); assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isFalse();
} }
@Test @Test
public void receivingPrepareFromProposerFails() { public void receivingPrepareFromProposerFails() {
final SignedData<ProposalPayload> proposalMsg = final Proposal proposalMsg =
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block); proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
final SignedData<PreparePayload> prepareMsg = final Prepare prepareMsg =
proposerMessageFactory.createSignedPreparePayload(roundIdentifier, block.getHash()); proposerMessageFactory.createSignedPreparePayload(roundIdentifier, block.getHash());
assertThat(validator.addSignedProposalPayload(proposalMsg)).isTrue(); assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validatePrepareMessage(prepareMsg)).isFalse(); assertThat(validator.validatePrepareMessage(prepareMsg.getSignedPayload())).isFalse();
} }
@Test @Test
public void receivingPrepareFromNonValidatorFails() { public void receivingPrepareFromNonValidatorFails() {
final SignedData<ProposalPayload> proposalMsg = final Proposal proposalMsg =
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block); proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
final SignedData<PreparePayload> prepareMsg = final Prepare prepareMsg =
nonValidatorMessageFactory.createSignedPreparePayload(roundIdentifier, block.getHash()); nonValidatorMessageFactory.createSignedPreparePayload(roundIdentifier, block.getHash());
assertThat(validator.addSignedProposalPayload(proposalMsg)).isTrue(); assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validatePrepareMessage(prepareMsg)).isFalse(); assertThat(validator.validatePrepareMessage(prepareMsg.getSignedPayload())).isFalse();
} }
@Test @Test
public void receivingMessagesWithDifferentRoundIdFromProposalFails() { public void receivingMessagesWithDifferentRoundIdFromProposalFails() {
final SignedData<ProposalPayload> proposalMsg = final Proposal proposalMsg =
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block); proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
final ConsensusRoundIdentifier invalidRoundIdentifier = final ConsensusRoundIdentifier invalidRoundIdentifier =
new ConsensusRoundIdentifier( new ConsensusRoundIdentifier(
roundIdentifier.getSequenceNumber(), roundIdentifier.getRoundNumber() + 1); roundIdentifier.getSequenceNumber(), roundIdentifier.getRoundNumber() + 1);
final SignedData<PreparePayload> prepareMsg = final Prepare prepareMsg =
validatorMessageFactory.createSignedPreparePayload(invalidRoundIdentifier, block.getHash()); validatorMessageFactory.createSignedPreparePayload(invalidRoundIdentifier, block.getHash());
final SignedData<CommitPayload> commitMsg = final Commit commitMsg =
validatorMessageFactory.createSignedCommitPayload( validatorMessageFactory.createSignedCommitPayload(
invalidRoundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), proposerKey)); invalidRoundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), proposerKey));
assertThat(validator.addSignedProposalPayload(proposalMsg)).isTrue(); assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validatePrepareMessage(prepareMsg)).isFalse(); assertThat(validator.validatePrepareMessage(prepareMsg.getSignedPayload())).isFalse();
assertThat(validator.validateCommmitMessage(commitMsg)).isFalse(); assertThat(validator.validateCommmitMessage(commitMsg.getSignedPayload())).isFalse();
} }
@Test @Test
public void receivingPrepareNonProposerValidatorWithCorrectRoundIsSuccessful() { public void receivingPrepareNonProposerValidatorWithCorrectRoundIsSuccessful() {
final SignedData<ProposalPayload> proposalMsg = final Proposal proposalMsg =
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block); proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
final SignedData<PreparePayload> prepareMsg = final Prepare prepareMsg =
validatorMessageFactory.createSignedPreparePayload(roundIdentifier, block.getHash()); validatorMessageFactory.createSignedPreparePayload(roundIdentifier, block.getHash());
assertThat(validator.addSignedProposalPayload(proposalMsg)).isTrue(); assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validatePrepareMessage(prepareMsg)).isTrue(); assertThat(validator.validatePrepareMessage(prepareMsg.getSignedPayload())).isTrue();
} }
@Test @Test
public void receivingACommitMessageWithAnInvalidCommitSealFails() { public void receivingACommitMessageWithAnInvalidCommitSealFails() {
final SignedData<ProposalPayload> proposalMsg = final Proposal proposalMsg =
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block); proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
final SignedData<CommitPayload> commitMsg = final Commit commitMsg =
proposerMessageFactory.createSignedCommitPayload( proposerMessageFactory.createSignedCommitPayload(
roundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), nonValidatorKey)); roundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), nonValidatorKey));
assertThat(validator.addSignedProposalPayload(proposalMsg)).isTrue(); assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validateCommmitMessage(commitMsg)).isFalse(); assertThat(validator.validateCommmitMessage(commitMsg.getSignedPayload())).isFalse();
} }
@Test @Test
public void commitMessageContainingValidSealFromValidatorIsSuccessful() { public void commitMessageContainingValidSealFromValidatorIsSuccessful() {
final SignedData<ProposalPayload> proposalMsg = final Proposal proposalMsg =
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block); proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
final SignedData<CommitPayload> proposerCommitMsg = final Commit proposerCommitMsg =
proposerMessageFactory.createSignedCommitPayload( proposerMessageFactory.createSignedCommitPayload(
roundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), proposerKey)); roundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), proposerKey));
final SignedData<CommitPayload> validatorCommitMsg = final Commit validatorCommitMsg =
validatorMessageFactory.createSignedCommitPayload( validatorMessageFactory.createSignedCommitPayload(
roundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), validatorKey)); roundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), validatorKey));
assertThat(validator.addSignedProposalPayload(proposalMsg)).isTrue(); assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validateCommmitMessage(proposerCommitMsg)).isTrue(); assertThat(validator.validateCommmitMessage(proposerCommitMsg.getSignedPayload())).isTrue();
assertThat(validator.validateCommmitMessage(validatorCommitMsg)).isTrue(); assertThat(validator.validateCommmitMessage(validatorCommitMsg.getSignedPayload())).isTrue();
} }
@Test @Test
public void subsequentProposalHasDifferentSenderFails() { public void subsequentProposalHasDifferentSenderFails() {
final SignedData<ProposalPayload> proposalMsg = final Proposal proposalMsg =
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block); proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
assertThat(validator.addSignedProposalPayload(proposalMsg)).isTrue(); assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
final SignedData<ProposalPayload> secondProposalMsg = final Proposal secondProposalMsg =
validatorMessageFactory.createSignedProposalPayload(roundIdentifier, block); validatorMessageFactory.createSignedProposalPayload(roundIdentifier, block);
assertThat(validator.addSignedProposalPayload(secondProposalMsg)).isFalse(); assertThat(validator.addSignedProposalPayload(secondProposalMsg.getSignedPayload())).isFalse();
} }
@Test @Test
public void subsequentProposalHasDifferentContentFails() { public void subsequentProposalHasDifferentContentFails() {
final SignedData<ProposalPayload> proposalMsg = final Proposal proposalMsg =
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block); proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
assertThat(validator.addSignedProposalPayload(proposalMsg)).isTrue(); assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
final ConsensusRoundIdentifier newRoundIdentifier = new ConsensusRoundIdentifier(3, 0); final ConsensusRoundIdentifier newRoundIdentifier = new ConsensusRoundIdentifier(3, 0);
final SignedData<ProposalPayload> secondProposalMsg = final Proposal secondProposalMsg =
proposerMessageFactory.createSignedProposalPayload(newRoundIdentifier, block); proposerMessageFactory.createSignedProposalPayload(newRoundIdentifier, block);
assertThat(validator.addSignedProposalPayload(secondProposalMsg)).isFalse(); assertThat(validator.addSignedProposalPayload(secondProposalMsg.getSignedPayload())).isFalse();
} }
@Test @Test
public void subsequentProposalHasIdenticalSenderAndContentIsSuccessful() { public void subsequentProposalHasIdenticalSenderAndContentIsSuccessful() {
final SignedData<ProposalPayload> proposalMsg = final Proposal proposalMsg =
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block); proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
assertThat(validator.addSignedProposalPayload(proposalMsg)).isTrue(); assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
final SignedData<ProposalPayload> secondProposalMsg = final Proposal secondProposalMsg =
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block); proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
assertThat(validator.addSignedProposalPayload(secondProposalMsg)).isTrue(); assertThat(validator.addSignedProposalPayload(secondProposalMsg.getSignedPayload())).isTrue();
} }
@Test @Test
public void blockRoundMisMatchWithMessageRoundFails() { public void blockRoundMisMatchWithMessageRoundFails() {
insertRoundToBlockHeader(roundIdentifier.getRoundNumber() + 1); insertRoundToBlockHeader(roundIdentifier.getRoundNumber() + 1);
final SignedData<ProposalPayload> proposalMsg = final Proposal proposalMsg =
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block); proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
assertThat(validator.addSignedProposalPayload(proposalMsg)).isFalse(); assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isFalse();
} }
} }

@ -21,12 +21,12 @@ import static org.mockito.Mockito.when;
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier; import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.TestHelpers; import tech.pegasys.pantheon.consensus.ibft.TestHelpers;
import tech.pegasys.pantheon.consensus.ibft.blockcreation.ProposerSelector; import tech.pegasys.pantheon.consensus.ibft.blockcreation.ProposerSelector;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.NewRound;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Proposal;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.NewRoundPayload; import tech.pegasys.pantheon.consensus.ibft.payload.NewRoundPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate; import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate;
import tech.pegasys.pantheon.consensus.ibft.payload.ProposalPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangeCertificate; import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangeCertificate;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.validation.RoundChangeMessageValidator.MessageValidatorForHeightFactory; import tech.pegasys.pantheon.consensus.ibft.validation.RoundChangeMessageValidator.MessageValidatorForHeightFactory;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.Address;
@ -61,7 +61,8 @@ public class NewRoundMessageValidatorTest {
private final MessageValidator messageValidator = mock(MessageValidator.class); private final MessageValidator messageValidator = mock(MessageValidator.class);
private Block proposedBlock; private Block proposedBlock;
private SignedData<NewRoundPayload> validMsg; private NewRound validMsg;
private NewRoundPayload validPayload;
private NewRoundPayload.Builder msgBuilder; private NewRoundPayload.Builder msgBuilder;
@Before @Before
@ -72,7 +73,8 @@ public class NewRoundMessageValidatorTest {
proposedBlock = TestHelpers.createProposalBlock(validators, roundIdentifier.getRoundNumber()); proposedBlock = TestHelpers.createProposalBlock(validators, roundIdentifier.getRoundNumber());
validMsg = createValidNewRoundMessageSignedBy(proposerKey); validMsg = createValidNewRoundMessageSignedBy(proposerKey);
msgBuilder = NewRoundPayload.Builder.fromExisting(validMsg.getPayload()); validPayload = validMsg.getSignedPayload().getPayload();
msgBuilder = NewRoundPayload.Builder.fromExisting(validMsg);
when(proposerSelector.selectProposerForRound(any())).thenReturn(proposerAddress); when(proposerSelector.selectProposerForRound(any())).thenReturn(proposerAddress);
@ -89,7 +91,7 @@ public class NewRoundMessageValidatorTest {
* message. * message.
*/ */
private SignedData<NewRoundPayload> createValidNewRoundMessageSignedBy(final KeyPair signingKey) { private NewRound createValidNewRoundMessageSignedBy(final KeyPair signingKey) {
final MessageFactory messageCreator = new MessageFactory(signingKey); final MessageFactory messageCreator = new MessageFactory(signingKey);
final RoundChangeCertificate.Builder builder = new RoundChangeCertificate.Builder(); final RoundChangeCertificate.Builder builder = new RoundChangeCertificate.Builder();
@ -99,11 +101,12 @@ public class NewRoundMessageValidatorTest {
return messageCreator.createSignedNewRoundPayload( return messageCreator.createSignedNewRoundPayload(
roundIdentifier, roundIdentifier,
builder.buildCertificate(), builder.buildCertificate(),
messageCreator.createSignedProposalPayload(roundIdentifier, proposedBlock)); messageCreator
.createSignedProposalPayload(roundIdentifier, proposedBlock)
.getSignedPayload());
} }
private SignedData<NewRoundPayload> signPayload( private NewRound signPayload(final NewRoundPayload payload, final KeyPair signingKey) {
final NewRoundPayload payload, final KeyPair signingKey) {
final MessageFactory messageCreator = new MessageFactory(signingKey); final MessageFactory messageCreator = new MessageFactory(signingKey);
@ -115,14 +118,14 @@ public class NewRoundMessageValidatorTest {
@Test @Test
public void basicNewRoundMessageIsValid() { public void basicNewRoundMessageIsValid() {
assertThat(validator.validateNewRoundMessage(validMsg)).isTrue(); assertThat(validator.validateNewRoundMessage(validMsg.getSignedPayload())).isTrue();
} }
@Test @Test
public void newRoundFromNonProposerFails() { public void newRoundFromNonProposerFails() {
final SignedData<NewRoundPayload> msg = signPayload(validMsg.getPayload(), validatorKey); final NewRound msg = signPayload(validPayload, validatorKey);
assertThat(validator.validateNewRoundMessage(msg)).isFalse(); assertThat(validator.validateNewRoundMessage(msg.getSignedPayload())).isFalse();
} }
@Test @Test
@ -130,9 +133,9 @@ public class NewRoundMessageValidatorTest {
msgBuilder.setRoundChangeIdentifier( msgBuilder.setRoundChangeIdentifier(
new ConsensusRoundIdentifier(roundIdentifier.getSequenceNumber(), 0)); new ConsensusRoundIdentifier(roundIdentifier.getSequenceNumber(), 0));
final SignedData<NewRoundPayload> inValidMsg = signPayload(msgBuilder.build(), proposerKey); final NewRound inValidMsg = signPayload(msgBuilder.build(), proposerKey);
assertThat(validator.validateNewRoundMessage(inValidMsg)).isFalse(); assertThat(validator.validateNewRoundMessage(inValidMsg.getSignedPayload())).isFalse();
} }
@Test @Test
@ -140,18 +143,18 @@ public class NewRoundMessageValidatorTest {
final ConsensusRoundIdentifier futureRound = TestHelpers.createFrom(roundIdentifier, 1, 0); final ConsensusRoundIdentifier futureRound = TestHelpers.createFrom(roundIdentifier, 1, 0);
msgBuilder.setRoundChangeIdentifier(futureRound); msgBuilder.setRoundChangeIdentifier(futureRound);
final SignedData<NewRoundPayload> inValidMsg = signPayload(msgBuilder.build(), proposerKey); final NewRound inValidMsg = signPayload(msgBuilder.build(), proposerKey);
assertThat(validator.validateNewRoundMessage(inValidMsg)).isFalse(); assertThat(validator.validateNewRoundMessage(inValidMsg.getSignedPayload())).isFalse();
} }
@Test @Test
public void newRoundWithEmptyRoundChangeCertificateFails() { public void newRoundWithEmptyRoundChangeCertificateFails() {
msgBuilder.setRoundChangeCertificate(new RoundChangeCertificate(Collections.emptyList())); msgBuilder.setRoundChangeCertificate(new RoundChangeCertificate(Collections.emptyList()));
final SignedData<NewRoundPayload> inValidMsg = signPayload(msgBuilder.build(), proposerKey); final NewRound inValidMsg = signPayload(msgBuilder.build(), proposerKey);
assertThat(validator.validateNewRoundMessage(inValidMsg)).isFalse(); assertThat(validator.validateNewRoundMessage(inValidMsg.getSignedPayload())).isFalse();
} }
@Test @Test
@ -164,20 +167,25 @@ public class NewRoundMessageValidatorTest {
final PreparedCertificate misMatchedPreparedCertificate = final PreparedCertificate misMatchedPreparedCertificate =
new PreparedCertificate( new PreparedCertificate(
proposerMessageFactory.createSignedProposalPayload(preparedRound, prevProposedBlock), proposerMessageFactory
.createSignedProposalPayload(preparedRound, prevProposedBlock)
.getSignedPayload(),
singletonList( singletonList(
validatorMessageFactory.createSignedPreparePayload( validatorMessageFactory
preparedRound, prevProposedBlock.getHash()))); .createSignedPreparePayload(preparedRound, prevProposedBlock.getHash())
.getSignedPayload()));
msgBuilder.setRoundChangeCertificate( msgBuilder.setRoundChangeCertificate(
new RoundChangeCertificate( new RoundChangeCertificate(
singletonList( singletonList(
validatorMessageFactory.createSignedRoundChangePayload( validatorMessageFactory
roundIdentifier, Optional.of(misMatchedPreparedCertificate))))); .createSignedRoundChangePayload(
roundIdentifier, Optional.of(misMatchedPreparedCertificate))
.getSignedPayload())));
final SignedData<NewRoundPayload> invalidMsg = signPayload(msgBuilder.build(), proposerKey); final NewRound invalidMsg = signPayload(msgBuilder.build(), proposerKey);
assertThat(validator.validateNewRoundMessage(invalidMsg)).isFalse(); assertThat(validator.validateNewRoundMessage(invalidMsg.getSignedPayload())).isFalse();
} }
@Test @Test
@ -192,9 +200,9 @@ public class NewRoundMessageValidatorTest {
msgBuilder.setRoundChangeCertificate(roundChangeBuilder.buildCertificate()); msgBuilder.setRoundChangeCertificate(roundChangeBuilder.buildCertificate());
final SignedData<NewRoundPayload> msg = signPayload(msgBuilder.build(), proposerKey); final NewRound msg = signPayload(msgBuilder.build(), proposerKey);
assertThat(validator.validateNewRoundMessage(msg)).isFalse(); assertThat(validator.validateNewRoundMessage(msg.getSignedPayload())).isFalse();
} }
@Test @Test
@ -207,19 +215,22 @@ public class NewRoundMessageValidatorTest {
roundIdentifier, roundIdentifier,
Optional.of( Optional.of(
new PreparedCertificate( new PreparedCertificate(
proposerMessageFactory.createSignedProposalPayload(prevRound, proposedBlock), proposerMessageFactory
.createSignedProposalPayload(prevRound, proposedBlock)
.getSignedPayload(),
Lists.newArrayList( Lists.newArrayList(
validatorMessageFactory.createSignedPreparePayload( validatorMessageFactory
prevRound, proposedBlock.getHash())))))); .createSignedPreparePayload(prevRound, proposedBlock.getHash())
.getSignedPayload())))));
msgBuilder.setRoundChangeCertificate(roundChangeBuilder.buildCertificate()); msgBuilder.setRoundChangeCertificate(roundChangeBuilder.buildCertificate());
// The prepare Message in the RoundChange Cert will be deemed illegal. // The prepare Message in the RoundChange Cert will be deemed illegal.
when(messageValidator.validatePrepareMessage(any())).thenReturn(false); when(messageValidator.validatePrepareMessage(any())).thenReturn(false);
final SignedData<NewRoundPayload> msg = signPayload(msgBuilder.build(), proposerKey); final NewRound msg = signPayload(msgBuilder.build(), proposerKey);
assertThat(validator.validateNewRoundMessage(msg)).isFalse(); assertThat(validator.validateNewRoundMessage(msg.getSignedPayload())).isFalse();
} }
@Test @Test
@ -227,15 +238,16 @@ public class NewRoundMessageValidatorTest {
final ConsensusRoundIdentifier latterPrepareRound = final ConsensusRoundIdentifier latterPrepareRound =
new ConsensusRoundIdentifier( new ConsensusRoundIdentifier(
roundIdentifier.getSequenceNumber(), roundIdentifier.getRoundNumber() - 1); roundIdentifier.getSequenceNumber(), roundIdentifier.getRoundNumber() - 1);
final SignedData<ProposalPayload> latterProposal = final Proposal latterProposal =
proposerMessageFactory.createSignedProposalPayload(latterPrepareRound, proposedBlock); proposerMessageFactory.createSignedProposalPayload(latterPrepareRound, proposedBlock);
final Optional<PreparedCertificate> preparedCert = final Optional<PreparedCertificate> preparedCert =
Optional.of( Optional.of(
new PreparedCertificate( new PreparedCertificate(
latterProposal, latterProposal.getSignedPayload(),
Lists.newArrayList( Lists.newArrayList(
validatorMessageFactory.createSignedPreparePayload( validatorMessageFactory
roundIdentifier, proposedBlock.getHash())))); .createSignedPreparePayload(roundIdentifier, proposedBlock.getHash())
.getSignedPayload())));
// An earlier PrepareCert is added to ensure the path to find the latest PrepareCert // An earlier PrepareCert is added to ensure the path to find the latest PrepareCert
// is correctly followed. // is correctly followed.
@ -244,54 +256,61 @@ public class NewRoundMessageValidatorTest {
final ConsensusRoundIdentifier earlierPreparedRound = final ConsensusRoundIdentifier earlierPreparedRound =
new ConsensusRoundIdentifier( new ConsensusRoundIdentifier(
roundIdentifier.getSequenceNumber(), roundIdentifier.getRoundNumber() - 2); roundIdentifier.getSequenceNumber(), roundIdentifier.getRoundNumber() - 2);
final SignedData<ProposalPayload> earlierProposal = final Proposal earlierProposal =
proposerMessageFactory.createSignedProposalPayload(earlierPreparedRound, earlierBlock); proposerMessageFactory.createSignedProposalPayload(earlierPreparedRound, earlierBlock);
final Optional<PreparedCertificate> earlierPreparedCert = final Optional<PreparedCertificate> earlierPreparedCert =
Optional.of( Optional.of(
new PreparedCertificate( new PreparedCertificate(
earlierProposal, earlierProposal.getSignedPayload(),
Lists.newArrayList( Lists.newArrayList(
validatorMessageFactory.createSignedPreparePayload( validatorMessageFactory
earlierPreparedRound, earlierBlock.getHash())))); .createSignedPreparePayload(earlierPreparedRound, earlierBlock.getHash())
.getSignedPayload())));
final RoundChangeCertificate roundChangeCert = final RoundChangeCertificate roundChangeCert =
new RoundChangeCertificate( new RoundChangeCertificate(
Lists.newArrayList( Lists.newArrayList(
proposerMessageFactory.createSignedRoundChangePayload( proposerMessageFactory
roundIdentifier, earlierPreparedCert), .createSignedRoundChangePayload(roundIdentifier, earlierPreparedCert)
validatorMessageFactory.createSignedRoundChangePayload( .getSignedPayload(),
roundIdentifier, preparedCert))); validatorMessageFactory
.createSignedRoundChangePayload(roundIdentifier, preparedCert)
.getSignedPayload()));
// Ensure a message containing the earlier proposal fails // Ensure a message containing the earlier proposal fails
final SignedData<NewRoundPayload> newRoundWithEarlierProposal = final NewRound newRoundWithEarlierProposal =
proposerMessageFactory.createSignedNewRoundPayload( proposerMessageFactory.createSignedNewRoundPayload(
roundIdentifier, roundChangeCert, earlierProposal); roundIdentifier, roundChangeCert, earlierProposal.getSignedPayload());
assertThat(validator.validateNewRoundMessage(newRoundWithEarlierProposal)).isFalse(); assertThat(validator.validateNewRoundMessage(newRoundWithEarlierProposal.getSignedPayload()))
.isFalse();
final SignedData<NewRoundPayload> newRoundWithLatterProposal = final NewRound newRoundWithLatterProposal =
proposerMessageFactory.createSignedNewRoundPayload( proposerMessageFactory.createSignedNewRoundPayload(
roundIdentifier, roundChangeCert, latterProposal); roundIdentifier, roundChangeCert, latterProposal.getSignedPayload());
assertThat(validator.validateNewRoundMessage(newRoundWithLatterProposal)).isTrue(); assertThat(validator.validateNewRoundMessage(newRoundWithLatterProposal.getSignedPayload()))
.isTrue();
} }
@Test @Test
public void embeddedProposalFailsValidation() { public void embeddedProposalFailsValidation() {
when(messageValidator.addSignedProposalPayload(any())).thenReturn(false, true); when(messageValidator.addSignedProposalPayload(any())).thenReturn(false, true);
final SignedData<ProposalPayload> proposal = final Proposal proposal =
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock); proposerMessageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock);
final SignedData<NewRoundPayload> msg = final NewRound msg =
proposerMessageFactory.createSignedNewRoundPayload( proposerMessageFactory.createSignedNewRoundPayload(
roundIdentifier, roundIdentifier,
new RoundChangeCertificate( new RoundChangeCertificate(
Lists.newArrayList( Lists.newArrayList(
proposerMessageFactory.createSignedRoundChangePayload( proposerMessageFactory
roundIdentifier, Optional.empty()), .createSignedRoundChangePayload(roundIdentifier, Optional.empty())
validatorMessageFactory.createSignedRoundChangePayload( .getSignedPayload(),
roundIdentifier, Optional.empty()))), validatorMessageFactory
proposal); .createSignedRoundChangePayload(roundIdentifier, Optional.empty())
.getSignedPayload())),
assertThat(validator.validateNewRoundMessage(msg)).isFalse(); proposal.getSignedPayload());
assertThat(validator.validateNewRoundMessage(msg.getSignedPayload())).isFalse();
} }
} }

@ -21,11 +21,10 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier; import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Prepare;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.RoundChange;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory; import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate; import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.validation.RoundChangeMessageValidator.MessageValidatorForHeightFactory; import tech.pegasys.pantheon.consensus.ibft.validation.RoundChangeMessageValidator.MessageValidatorForHeightFactory;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair; import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.core.Address; import tech.pegasys.pantheon.ethereum.core.Address;
@ -81,33 +80,35 @@ public class RoundChangeMessageValidatorTest {
@Test @Test
public void roundChangeSentByNonValidatorFails() { public void roundChangeSentByNonValidatorFails() {
final SignedData<RoundChangePayload> msg = final RoundChange msg =
nonValidatorMessageFactory.createSignedRoundChangePayload(targetRound, Optional.empty()); nonValidatorMessageFactory.createSignedRoundChangePayload(targetRound, Optional.empty());
assertThat(validator.validateMessage(msg)).isFalse(); assertThat(validator.validateMessage(msg.getSignedPayload())).isFalse();
} }
@Test @Test
public void roundChangeContainingNoCertificateIsSuccessful() { public void roundChangeContainingNoCertificateIsSuccessful() {
final SignedData<RoundChangePayload> msg = final RoundChange msg =
proposerMessageFactory.createSignedRoundChangePayload(targetRound, Optional.empty()); proposerMessageFactory.createSignedRoundChangePayload(targetRound, Optional.empty());
assertThat(validator.validateMessage(msg)).isTrue(); assertThat(validator.validateMessage(msg.getSignedPayload())).isTrue();
} }
@Test @Test
public void roundChangeContainingInvalidProposalFails() { public void roundChangeContainingInvalidProposalFails() {
final PreparedCertificate prepareCertificate = final PreparedCertificate prepareCertificate =
new PreparedCertificate( new PreparedCertificate(
proposerMessageFactory.createSignedProposalPayload(currentRound, block), proposerMessageFactory
.createSignedProposalPayload(currentRound, block)
.getSignedPayload(),
Collections.emptyList()); Collections.emptyList());
final SignedData<RoundChangePayload> msg = final RoundChange msg =
proposerMessageFactory.createSignedRoundChangePayload( proposerMessageFactory.createSignedRoundChangePayload(
targetRound, Optional.of(prepareCertificate)); targetRound, Optional.of(prepareCertificate));
when(basicValidator.addSignedProposalPayload(any())).thenReturn(false); when(basicValidator.addSignedProposalPayload(any())).thenReturn(false);
assertThat(validator.validateMessage(msg)).isFalse(); assertThat(validator.validateMessage(msg.getSignedPayload())).isFalse();
verify(validatorFactory, times(1)) verify(validatorFactory, times(1))
.createAt(prepareCertificate.getProposalPayload().getPayload().getRoundIdentifier()); .createAt(prepareCertificate.getProposalPayload().getPayload().getRoundIdentifier());
verify(basicValidator, times(1)) verify(basicValidator, times(1))
@ -120,36 +121,40 @@ public class RoundChangeMessageValidatorTest {
public void roundChangeContainingValidProposalButNoPrepareMessagesFails() { public void roundChangeContainingValidProposalButNoPrepareMessagesFails() {
final PreparedCertificate prepareCertificate = final PreparedCertificate prepareCertificate =
new PreparedCertificate( new PreparedCertificate(
proposerMessageFactory.createSignedProposalPayload(currentRound, block), proposerMessageFactory
.createSignedProposalPayload(currentRound, block)
.getSignedPayload(),
Collections.emptyList()); Collections.emptyList());
final SignedData<RoundChangePayload> msg = final RoundChange msg =
proposerMessageFactory.createSignedRoundChangePayload( proposerMessageFactory.createSignedRoundChangePayload(
targetRound, Optional.of(prepareCertificate)); targetRound, Optional.of(prepareCertificate));
when(basicValidator.addSignedProposalPayload(any())).thenReturn(true); when(basicValidator.addSignedProposalPayload(any())).thenReturn(true);
assertThat(validator.validateMessage(msg)).isFalse(); assertThat(validator.validateMessage(msg.getSignedPayload())).isFalse();
} }
@Test @Test
public void roundChangeInvalidPrepareMessageFromProposerFails() { public void roundChangeInvalidPrepareMessageFromProposerFails() {
final SignedData<PreparePayload> prepareMsg = final Prepare prepareMsg =
validatorMessageFactory.createSignedPreparePayload(currentRound, block.getHash()); validatorMessageFactory.createSignedPreparePayload(currentRound, block.getHash());
final PreparedCertificate prepareCertificate = final PreparedCertificate prepareCertificate =
new PreparedCertificate( new PreparedCertificate(
proposerMessageFactory.createSignedProposalPayload(currentRound, block), proposerMessageFactory
Lists.newArrayList(prepareMsg)); .createSignedProposalPayload(currentRound, block)
.getSignedPayload(),
Lists.newArrayList(prepareMsg.getSignedPayload()));
when(basicValidator.addSignedProposalPayload(any())).thenReturn(true); when(basicValidator.addSignedProposalPayload(any())).thenReturn(true);
when(basicValidator.validatePrepareMessage(any())).thenReturn(false); when(basicValidator.validatePrepareMessage(any())).thenReturn(false);
final SignedData<RoundChangePayload> msg = final RoundChange msg =
proposerMessageFactory.createSignedRoundChangePayload( proposerMessageFactory.createSignedRoundChangePayload(
targetRound, Optional.of(prepareCertificate)); targetRound, Optional.of(prepareCertificate));
assertThat(validator.validateMessage(msg)).isFalse(); assertThat(validator.validateMessage(msg.getSignedPayload())).isFalse();
verify(basicValidator, times(1)).validatePrepareMessage(prepareMsg); verify(basicValidator, times(1)).validatePrepareMessage(prepareMsg.getSignedPayload());
verify(basicValidator, never()).validateCommmitMessage(any()); verify(basicValidator, never()).validateCommmitMessage(any());
} }
@ -158,11 +163,11 @@ public class RoundChangeMessageValidatorTest {
final ConsensusRoundIdentifier latterRoundIdentifier = final ConsensusRoundIdentifier latterRoundIdentifier =
new ConsensusRoundIdentifier(currentRound.getSequenceNumber() + 1, 1); new ConsensusRoundIdentifier(currentRound.getSequenceNumber() + 1, 1);
final SignedData<RoundChangePayload> msg = final RoundChange msg =
proposerMessageFactory.createSignedRoundChangePayload( proposerMessageFactory.createSignedRoundChangePayload(
latterRoundIdentifier, Optional.empty()); latterRoundIdentifier, Optional.empty());
assertThat(validator.validateMessage(msg)).isFalse(); assertThat(validator.validateMessage(msg.getSignedPayload())).isFalse();
verify(basicValidator, never()).validatePrepareMessage(any()); verify(basicValidator, never()).validatePrepareMessage(any());
} }
@ -172,45 +177,49 @@ public class RoundChangeMessageValidatorTest {
new ConsensusRoundIdentifier( new ConsensusRoundIdentifier(
currentRound.getSequenceNumber(), currentRound.getRoundNumber() + 2); currentRound.getSequenceNumber(), currentRound.getRoundNumber() + 2);
final SignedData<PreparePayload> prepareMsg = final Prepare prepareMsg =
validatorMessageFactory.createSignedPreparePayload(futureRound, block.getHash()); validatorMessageFactory.createSignedPreparePayload(futureRound, block.getHash());
final PreparedCertificate prepareCertificate = final PreparedCertificate prepareCertificate =
new PreparedCertificate( new PreparedCertificate(
proposerMessageFactory.createSignedProposalPayload(futureRound, block), proposerMessageFactory
Lists.newArrayList(prepareMsg)); .createSignedProposalPayload(futureRound, block)
.getSignedPayload(),
Lists.newArrayList(prepareMsg.getSignedPayload()));
final SignedData<RoundChangePayload> msg = final RoundChange msg =
proposerMessageFactory.createSignedRoundChangePayload( proposerMessageFactory.createSignedRoundChangePayload(
targetRound, Optional.of(prepareCertificate)); targetRound, Optional.of(prepareCertificate));
assertThat(validator.validateMessage(msg)).isFalse(); assertThat(validator.validateMessage(msg.getSignedPayload())).isFalse();
verify(validatorFactory, never()).createAt(any()); verify(validatorFactory, never()).createAt(any());
verify(basicValidator, never()).validatePrepareMessage(prepareMsg); verify(basicValidator, never()).validatePrepareMessage(prepareMsg.getSignedPayload());
verify(basicValidator, never()).validateCommmitMessage(any()); verify(basicValidator, never()).validateCommmitMessage(any());
} }
@Test @Test
public void roundChangeWithPastProposalForCurrentHeightIsSuccessful() { public void roundChangeWithPastProposalForCurrentHeightIsSuccessful() {
final SignedData<PreparePayload> prepareMsg = final Prepare prepareMsg =
validatorMessageFactory.createSignedPreparePayload(currentRound, block.getHash()); validatorMessageFactory.createSignedPreparePayload(currentRound, block.getHash());
final PreparedCertificate prepareCertificate = final PreparedCertificate prepareCertificate =
new PreparedCertificate( new PreparedCertificate(
proposerMessageFactory.createSignedProposalPayload(currentRound, block), proposerMessageFactory
Lists.newArrayList(prepareMsg)); .createSignedProposalPayload(currentRound, block)
.getSignedPayload(),
Lists.newArrayList(prepareMsg.getSignedPayload()));
final SignedData<RoundChangePayload> msg = final RoundChange msg =
proposerMessageFactory.createSignedRoundChangePayload( proposerMessageFactory.createSignedRoundChangePayload(
targetRound, Optional.of(prepareCertificate)); targetRound, Optional.of(prepareCertificate));
when(basicValidator.addSignedProposalPayload(prepareCertificate.getProposalPayload())) when(basicValidator.addSignedProposalPayload(prepareCertificate.getProposalPayload()))
.thenReturn(true); .thenReturn(true);
when(basicValidator.validatePrepareMessage(prepareMsg)).thenReturn(true); when(basicValidator.validatePrepareMessage(prepareMsg.getSignedPayload())).thenReturn(true);
assertThat(validator.validateMessage(msg)).isTrue(); assertThat(validator.validateMessage(msg.getSignedPayload())).isTrue();
verify(validatorFactory, times(1)) verify(validatorFactory, times(1))
.createAt(prepareCertificate.getProposalPayload().getPayload().getRoundIdentifier()); .createAt(prepareCertificate.getProposalPayload().getPayload().getRoundIdentifier());
verify(basicValidator, times(1)) verify(basicValidator, times(1))
.addSignedProposalPayload(prepareCertificate.getProposalPayload()); .addSignedProposalPayload(prepareCertificate.getProposalPayload());
verify(basicValidator, times(1)).validatePrepareMessage(prepareMsg); verify(basicValidator, times(1)).validatePrepareMessage(prepareMsg.getSignedPayload());
} }
} }

Loading…
Cancel
Save