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.ProposalMessageData;
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.PreparePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate;
@ -80,7 +82,7 @@ public class RoundSpecificPeers {
final ConsensusRoundIdentifier targetRound) {
return nonProposingPeers
.stream()
.map(peer -> peer.injectRoundChange(targetRound, empty()))
.map(peer -> peer.injectRoundChange(targetRound, empty()).getSignedPayload())
.collect(Collectors.toList());
}
@ -89,20 +91,24 @@ public class RoundSpecificPeers {
}
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) {
changes.add(peer.injectRoundChange(roundId, empty()));
}
return changes;
return changes.stream().map(RoundChange::getSignedPayload).collect(Collectors.toList());
}
public List<SignedData<RoundChangePayload>> createSignedRoundChangePayload(
final ConsensusRoundIdentifier roundId) {
return peers
.stream()
.map(p -> p.getMessageFactory().createSignedRoundChangePayload(roundId, empty()))
.map(
p ->
p.getMessageFactory()
.createSignedRoundChangePayload(roundId, empty())
.getSignedPayload())
.collect(Collectors.toList());
}
@ -113,7 +119,8 @@ public class RoundSpecificPeers {
.map(
p ->
p.getMessageFactory()
.createSignedRoundChangePayload(roundId, Optional.of(preparedCertificate)))
.createSignedRoundChangePayload(roundId, Optional.of(preparedCertificate))
.getSignedPayload())
.collect(Collectors.toList());
}
@ -125,11 +132,15 @@ public class RoundSpecificPeers {
nonProposingPeers.forEach(peer -> peer.injectCommit(roundId, hash));
}
Collection<SignedData<PreparePayload>> createSignedPreparePayloadOfNonProposing(
public Collection<SignedData<PreparePayload>> createSignedPreparePayloadOfNonProposing(
final ConsensusRoundIdentifier preparedRound, final Hash hash) {
return nonProposingPeers
.stream()
.map(role -> role.getMessageFactory().createSignedPreparePayload(preparedRound, hash))
.map(
role ->
role.getMessageFactory()
.createSignedPreparePayload(preparedRound, hash)
.getSignedPayload())
.collect(Collectors.toList());
}
@ -146,38 +157,35 @@ public class RoundSpecificPeers {
}
@SafeVarargs
public final void verifyMessagesReceivedPropser(final SignedData<? extends Payload>... msgs) {
public final void verifyMessagesReceivedProposer(final IbftMessage<? extends Payload>... msgs) {
verifyMessagesReceived(ImmutableList.of(proposer), msgs);
}
@SafeVarargs
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);
candidates.remove(exclude);
verifyMessagesReceived(candidates, msgs);
}
@SafeVarargs
public final void verifyMessagesReceivedNonPropsing(final SignedData<? extends Payload>... msgs) {
public final void verifyMessagesReceivedNonPropsing(final IbftMessage<?>... msgs) {
verifyMessagesReceived(nonProposingPeers, msgs);
}
@SafeVarargs
public final void verifyMessagesReceived(final SignedData<? extends Payload>... msgs) {
public final void verifyMessagesReceived(final IbftMessage<?>... msgs) {
verifyMessagesReceived(peers, msgs);
}
@SafeVarargs
private final void verifyMessagesReceived(
final Collection<ValidatorPeer> candidates, final SignedData<? extends Payload>... msgs) {
private void verifyMessagesReceived(
final Collection<ValidatorPeer> candidates, final IbftMessage<?>... msgs) {
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++) {
final int index = i;
final SignedData<? extends Payload> msg = msgList.get(index);
final IbftMessage<? extends Payload> msg = msgList.get(index);
candidates.forEach(
n -> {
final List<MessageData> rxMsgs = n.getReceivedMessages();
@ -188,36 +196,29 @@ public class RoundSpecificPeers {
candidates.forEach(ValidatorPeer::clearReceivedMessages);
}
private void verifyMessage(
final MessageData actual, final SignedData<? extends Payload> signedExpectedPayload) {
final Payload expectedPayload = signedExpectedPayload.getPayload();
SignedData<?> actualSignedPayload = null;
private void verifyMessage(final MessageData actual, final IbftMessage<?> expectedMessage) {
IbftMessage<?> actualSignedPayload = null;
switch (expectedPayload.getMessageType()) {
switch (expectedMessage.getMessageType()) {
case IbftV2.PROPOSAL:
actualSignedPayload =
ProposalMessageData.fromMessageData(actual).decode().getSignedPayload();
actualSignedPayload = ProposalMessageData.fromMessageData(actual).decode();
break;
case IbftV2.PREPARE:
actualSignedPayload =
PrepareMessageData.fromMessageData(actual).decode().getSignedPayload();
actualSignedPayload = PrepareMessageData.fromMessageData(actual).decode();
break;
case IbftV2.COMMIT:
actualSignedPayload = CommitMessageData.fromMessageData(actual).decode().getSignedPayload();
actualSignedPayload = CommitMessageData.fromMessageData(actual).decode();
break;
case IbftV2.NEW_ROUND:
actualSignedPayload =
NewRoundMessageData.fromMessageData(actual).decode().getSignedPayload();
actualSignedPayload = NewRoundMessageData.fromMessageData(actual).decode();
break;
case IbftV2.ROUND_CHANGE:
actualSignedPayload =
RoundChangeMessageData.fromMessageData(actual).decode().getSignedPayload();
actualSignedPayload = RoundChangeMessageData.fromMessageData(actual).decode();
break;
default:
fail("Illegal IBFTV2 message type.");
break;
}
assertThat(signedExpectedPayload)
.isEqualToComparingFieldByFieldRecursively(actualSignedPayload);
assertThat(expectedMessage).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.IbftBlockHashing;
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.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.NewRoundPayload;
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.RoundChangePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
@ -44,7 +44,9 @@ public class TestHelpers {
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(
@ -52,20 +54,26 @@ public class TestHelpers {
final RoundSpecificPeers peers = context.roundSpecificPeers(preparedRound);
return new PreparedCertificate(
peers.getProposer().getMessageFactory().createSignedProposalPayload(preparedRound, block),
peers
.getProposer()
.getMessageFactory()
.createSignedProposalPayload(preparedRound, block)
.getSignedPayload(),
peers.createSignedPreparePayloadOfNonProposing(preparedRound, block.getHash()));
}
public static SignedData<NewRoundPayload> injectEmptyNewRound(
public static NewRound injectEmptyNewRound(
final ConsensusRoundIdentifier targetRoundId,
final ValidatorPeer proposer,
final List<SignedData<RoundChangePayload>> roundChangePayloads,
final Block blockToPropose) {
final SignedData<ProposalPayload> proposal =
final Proposal proposal =
proposer.getMessageFactory().createSignedProposalPayload(targetRoundId, blockToPropose);
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.Proposal;
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.NewRoundPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparePayload;
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.RoundChangePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.crypto.SECP256K1;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
@ -82,20 +78,16 @@ public class ValidatorPeer {
return nodeKeys;
}
public SignedData<ProposalPayload> injectProposal(
final ConsensusRoundIdentifier rId, final Block block) {
final SignedData<ProposalPayload> payload =
messageFactory.createSignedProposalPayload(rId, block);
public Proposal injectProposal(final ConsensusRoundIdentifier rId, final Block block) {
final Proposal payload = messageFactory.createSignedProposalPayload(rId, block);
injectMessage(ProposalMessageData.create(new Proposal(payload)));
injectMessage(ProposalMessageData.create(payload));
return payload;
}
public SignedData<PreparePayload> injectPrepare(
final ConsensusRoundIdentifier rId, final Hash digest) {
final SignedData<PreparePayload> payload =
messageFactory.createSignedPreparePayload(rId, digest);
injectMessage(PrepareMessageData.create(new Prepare(payload)));
public Prepare injectPrepare(final ConsensusRoundIdentifier rId, final Hash digest) {
final Prepare payload = messageFactory.createSignedPreparePayload(rId, digest);
injectMessage(PrepareMessageData.create(payload));
return payload;
}
@ -103,37 +95,35 @@ public class ValidatorPeer {
return SECP256K1.sign(digest, nodeKeys);
}
public SignedData<CommitPayload> injectCommit(
final ConsensusRoundIdentifier rId, final Hash digest) {
public Commit injectCommit(final ConsensusRoundIdentifier rId, final Hash digest) {
final Signature commitSeal = SECP256K1.sign(digest, nodeKeys);
return injectCommit(rId, digest, commitSeal);
}
public SignedData<CommitPayload> injectCommit(
public Commit injectCommit(
final ConsensusRoundIdentifier rId, final Hash digest, final Signature commitSeal) {
final SignedData<CommitPayload> payload =
messageFactory.createSignedCommitPayload(rId, digest, commitSeal);
injectMessage(CommitMessageData.create(new Commit(payload)));
final Commit payload = messageFactory.createSignedCommitPayload(rId, digest, commitSeal);
injectMessage(CommitMessageData.create(payload));
return payload;
}
public SignedData<NewRoundPayload> injectNewRound(
public NewRound injectNewRound(
final ConsensusRoundIdentifier rId,
final RoundChangeCertificate roundChangeCertificate,
final SignedData<ProposalPayload> proposalPayload) {
final SignedData<NewRoundPayload> payload =
final NewRound payload =
messageFactory.createSignedNewRoundPayload(rId, roundChangeCertificate, proposalPayload);
injectMessage(NewRoundMessageData.create(new NewRound(payload)));
injectMessage(NewRoundMessageData.create(payload));
return payload;
}
public SignedData<RoundChangePayload> injectRoundChange(
public RoundChange injectRoundChange(
final ConsensusRoundIdentifier rId, final Optional<PreparedCertificate> preparedCertificate) {
final SignedData<RoundChangePayload> payload =
final RoundChange payload =
messageFactory.createSignedRoundChangePayload(rId, preparedCertificate);
injectMessage(RoundChangeMessageData.create(new RoundChange(payload)));
injectMessage(RoundChangeMessageData.create(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.IbftHelpers;
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.PreparePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.support.RoundSpecificPeers;
import tech.pegasys.pantheon.consensus.ibft.support.TestContext;
import tech.pegasys.pantheon.consensus.ibft.support.TestContextBuilder;
@ -89,13 +88,16 @@ public class FutureHeightTest {
.getController()
.handleNewBlockEvent(new NewChainHead(signedCurrentHeightBlock.getHeader()));
final SignedData<PreparePayload> expectedPrepareMessage =
final Prepare expectedPrepareMessage =
localNodeMessageFactory.createSignedPreparePayload(
futureHeightRoundId, futureHeightBlock.getHash());
final SignedData<CommitPayload> expectedCommitMessage =
createSignedCommitPayload(
futureHeightRoundId, futureHeightBlock, context.getLocalNodeParams().getNodeKeyPair());
final Commit expectedCommitMessage =
new Commit(
createSignedCommitPayload(
futureHeightRoundId,
futureHeightBlock,
context.getLocalNodeParams().getNodeKeyPair()));
peers.verifyMessagesReceived(expectedPrepareMessage, expectedCommitMessage);
assertThat(context.getCurrentChainHeight()).isEqualTo(2);
@ -110,7 +112,7 @@ public class FutureHeightTest {
peers.getProposer().injectProposal(roundId, currentHeightBlock);
peers.getNonProposing(0).injectPrepare(roundId, currentHeightBlock.getHash());
final SignedData<PreparePayload> expectedPrepareMessage =
final Prepare expectedPrepareMessage =
localNodeMessageFactory.createSignedPreparePayload(roundId, currentHeightBlock.getHash());
peers.verifyMessagesReceived(expectedPrepareMessage);
@ -148,9 +150,10 @@ public class FutureHeightTest {
// Should only require 1 more prepare to close it out
peers.getNonProposing(1).injectPrepare(roundId, currentHeightBlock.getHash());
final SignedData<CommitPayload> expectedCommitMessage =
createSignedCommitPayload(
roundId, currentHeightBlock, context.getLocalNodeParams().getNodeKeyPair());
final Commit expectedCommitMessage =
new Commit(
createSignedCommitPayload(
roundId, currentHeightBlock, context.getLocalNodeParams().getNodeKeyPair()));
peers.verifyMessagesReceived(expectedCommitMessage);
}
@ -185,7 +188,7 @@ public class FutureHeightTest {
peers.verifyNoMessagesReceived();
peers.getProposer().injectProposal(nextHeightRoundId, nextHeightBlock);
final SignedData<PreparePayload> expectedPrepareMessage =
final Prepare expectedPrepareMessage =
localNodeMessageFactory.createSignedPreparePayload(
nextHeightRoundId, nextHeightBlock.getHash());
@ -202,13 +205,16 @@ public class FutureHeightTest {
.getController()
.handleNewBlockEvent(new NewChainHead(signedNextHeightBlock.getHeader()));
final SignedData<PreparePayload> expectedFuturePrepareMessage =
final Prepare expectedFuturePrepareMessage =
localNodeMessageFactory.createSignedPreparePayload(
futureHeightRoundId, futureHeightBlock.getHash());
final SignedData<CommitPayload> expectedCommitMessage =
createSignedCommitPayload(
futureHeightRoundId, futureHeightBlock, context.getLocalNodeParams().getNodeKeyPair());
final Commit expectedCommitMessage =
new Commit(
createSignedCommitPayload(
futureHeightRoundId,
futureHeightBlock,
context.getLocalNodeParams().getNodeKeyPair()));
// Assert ONLY a prepare message was received, not any commits (i.e. futureHeightRoundId
// 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.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.PreparePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.support.RoundSpecificPeers;
import tech.pegasys.pantheon.consensus.ibft.support.TestContext;
import tech.pegasys.pantheon.consensus.ibft.support.TestContextBuilder;
@ -99,7 +98,7 @@ public class FutureRoundTest {
futurePeers.createSignedRoundChangePayload(futureRoundId),
futureBlock);
final SignedData<PreparePayload> expectedPrepare =
final Prepare expectedPrepare =
localNodeMessageFactory.createSignedPreparePayload(futureRoundId, futureBlock.getHash());
peers.verifyMessagesReceived(expectedPrepare);
@ -107,7 +106,7 @@ public class FutureRoundTest {
// following 1 more prepare, a commit msg will be sent
futurePeers.getNonProposing(quorum - 3).injectPrepare(futureRoundId, futureBlock.getHash());
final SignedData<CommitPayload> expectedCommit =
final Commit expectedCommit =
localNodeMessageFactory.createSignedCommitPayload(
futureRoundId,
futureBlock.getHash(),
@ -143,7 +142,7 @@ public class FutureRoundTest {
futurePeers.createSignedRoundChangePayload(futureRoundId),
futureBlock);
final SignedData<PreparePayload> expectedFuturePrepare =
final Prepare expectedFuturePrepare =
localNodeMessageFactory.createSignedPreparePayload(futureRoundId, futureBlock.getHash());
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.ibftevent.NewChainHead;
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.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.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.RoundChangePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.support.RoundSpecificPeers;
import tech.pegasys.pantheon.consensus.ibft.support.TestContext;
import tech.pegasys.pantheon.consensus.ibft.support.TestContextBuilder;
@ -75,29 +73,29 @@ public class GossipTest {
@Test
public void gossipMessagesToPeers() {
SignedData<PreparePayload> localPrepare =
final Prepare localPrepare =
context.getLocalNodeMessageFactory().createSignedPreparePayload(roundId, block.getHash());
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
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.verifyNoMessagesReceivedProposer();
final SignedData<CommitPayload> commit = sender.injectCommit(roundId, block.getHash());
final Commit commit = sender.injectCommit(roundId, block.getHash());
peers.verifyMessagesReceivedNonPropsing(commit);
peers.verifyNoMessagesReceivedProposer();
final SignedData<RoundChangePayload> roundChange =
final RoundChange roundChange =
msgFactory.createSignedRoundChangePayload(roundId, Optional.empty());
final RoundChangeCertificate roundChangeCert =
new RoundChangeCertificate(singleton(roundChange));
SignedData<NewRoundPayload> newRound =
sender.injectNewRound(roundId, roundChangeCert, proposal);
new RoundChangeCertificate(singleton(roundChange.getSignedPayload()));
final NewRound newRound =
sender.injectNewRound(roundId, roundChangeCert, proposal.getSignedPayload());
peers.verifyMessagesReceivedNonPropsing(newRound);
peers.verifyNoMessagesReceivedProposer();
@ -108,7 +106,7 @@ public class GossipTest {
@Test
public void onlyGossipOnce() {
final SignedData<PreparePayload> prepare = sender.injectPrepare(roundId, block.getHash());
final Prepare prepare = sender.injectPrepare(roundId, block.getHash());
peers.verifyMessagesReceivedNonPropsing(prepare);
sender.injectPrepare(roundId, block.getHash());
@ -122,10 +120,10 @@ public class GossipTest {
public void messageWithUnknownValidatorIsNotGossiped() {
final KeyPair unknownKeyPair = KeyPair.generate();
final MessageFactory unknownMsgFactory = new MessageFactory(unknownKeyPair);
final SignedData<ProposalPayload> unknownProposal =
unknownMsgFactory.createSignedProposalPayload(roundId, block);
final Proposal unknownProposal = unknownMsgFactory.createSignedProposalPayload(roundId, block);
sender.injectMessage(ProposalMessageData.create(new Proposal(unknownProposal)));
sender.injectMessage(
ProposalMessageData.create(new Proposal(unknownProposal.getSignedPayload())));
peers.verifyNoMessagesReceived();
}
@ -133,10 +131,9 @@ public class GossipTest {
public void messageIsNotGossipedToSenderOrCreator() {
final ValidatorPeer msgCreator = peers.getFirstNonProposer();
final MessageFactory peerMsgFactory = msgCreator.getMessageFactory();
final SignedData<ProposalPayload> proposalFromPeer =
peerMsgFactory.createSignedProposalPayload(roundId, block);
final Proposal proposalFromPeer = peerMsgFactory.createSignedProposalPayload(roundId, block);
sender.injectMessage(ProposalMessageData.create(new Proposal(proposalFromPeer)));
sender.injectMessage(ProposalMessageData.create(proposalFromPeer));
peers.verifyMessagesReceivedNonPropsingExcluding(msgCreator, proposalFromPeer);
peers.verifyNoMessagesReceivedProposer();
@ -164,7 +161,7 @@ public class GossipTest {
IbftHelpers.createSealedBlock(block, peers.sign(block.getHash()));
ConsensusRoundIdentifier futureRoundId = new ConsensusRoundIdentifier(2, 0);
SignedData<PreparePayload> futurePrepare = sender.injectPrepare(futureRoundId, block.getHash());
Prepare futurePrepare = sender.injectPrepare(futureRoundId, block.getHash());
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.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.ProposalPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.support.RoundSpecificPeers;
import tech.pegasys.pantheon.consensus.ibft.support.TestContext;
import tech.pegasys.pantheon.consensus.ibft.support.TestContextBuilder;
@ -58,8 +57,8 @@ public class LocalNodeIsProposerTest {
private final MessageFactory localNodeMessageFactory = context.getLocalNodeMessageFactory();
private Block expectedProposedBlock;
private SignedData<ProposalPayload> expectedTxProposal;
private SignedData<CommitPayload> expectedTxCommit;
private Proposal expectedTxProposal;
private Commit expectedTxCommit;
@Before
public void setup() {
@ -68,8 +67,9 @@ public class LocalNodeIsProposerTest {
localNodeMessageFactory.createSignedProposalPayload(roundId, expectedProposedBlock);
expectedTxCommit =
createSignedCommitPayload(
roundId, expectedProposedBlock, context.getLocalNodeParams().getNodeKeyPair());
new Commit(
createSignedCommitPayload(
roundId, expectedProposedBlock, context.getLocalNodeParams().getNodeKeyPair()));
// Start the Controller, and trigger "block timer" to send proposal.
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 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.PreparePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.support.RoundSpecificPeers;
import tech.pegasys.pantheon.consensus.ibft.support.TestContext;
import tech.pegasys.pantheon.consensus.ibft.support.TestContextBuilder;
@ -46,8 +45,8 @@ public class LocalNodeNotProposerTest {
private final Block blockToPropose = context.createBlockForProposalFromChainHead(0, 15);
private SignedData<PreparePayload> expectedTxPrepare;
private SignedData<CommitPayload> expectedTxCommit;
private Prepare expectedTxPrepare;
private Commit expectedTxCommit;
@Before
public void setup() {
@ -55,8 +54,9 @@ public class LocalNodeNotProposerTest {
localNodeMessageFactory.createSignedPreparePayload(roundId, blockToPropose.getHash());
expectedTxCommit =
createSignedCommitPayload(
roundId, blockToPropose, context.getLocalNodeParams().getNodeKeyPair());
new Commit(
createSignedCommitPayload(
roundId, blockToPropose, context.getLocalNodeParams().getNodeKeyPair()));
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 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.PreparePayload;
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.RoundChangePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
@ -71,9 +71,12 @@ public class ReceivedNewRoundTest {
nextProposer.injectNewRound(
targetRound,
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());
peers.verifyMessagesReceived(expectedPrepare);
@ -96,7 +99,8 @@ public class ReceivedNewRoundTest {
new RoundChangeCertificate(roundChanges),
illegalProposer
.getMessageFactory()
.createSignedProposalPayload(nextRoundId, blockToPropose));
.createSignedProposalPayload(nextRoundId, blockToPropose)
.getSignedPayload());
peers.verifyNoMessagesReceived();
}
@ -121,7 +125,8 @@ public class ReceivedNewRoundTest {
peers
.getNonProposing(0)
.getMessageFactory()
.createSignedProposalPayload(nextRoundId, reproposedBlock));
.createSignedProposalPayload(nextRoundId, reproposedBlock)
.getSignedPayload());
peers.verifyMessagesReceived(
localNodeMessageFactory.createSignedPreparePayload(nextRoundId, reproposedBlock.getHash()));
@ -141,14 +146,14 @@ public class ReceivedNewRoundTest {
final ValidatorPeer interimRoundProposer =
context.roundSpecificPeers(interimRound).getProposer();
final SignedData<ProposalPayload> proposal =
final Proposal proposal =
interimRoundProposer
.getMessageFactory()
.createSignedProposalPayload(
interimRound, context.createBlockForProposalFromChainHead(1, 30));
interimRoundProposer.injectNewRound(
interimRound, new RoundChangeCertificate(roundChangePayloads), proposal);
interimRound, new RoundChangeCertificate(roundChangePayloads), proposal.getSignedPayload());
peers.verifyNoMessagesReceived();
}
@ -174,7 +179,8 @@ public class ReceivedNewRoundTest {
peers
.getNonProposing(0)
.getMessageFactory()
.createSignedProposalPayload(nextRoundId, reproposedBlock));
.createSignedProposalPayload(nextRoundId, reproposedBlock)
.getSignedPayload());
peers.verifyMessagesReceived(
localNodeMessageFactory.createSignedPreparePayload(nextRoundId, reproposedBlock.getHash()));
@ -189,15 +195,17 @@ public class ReceivedNewRoundTest {
peers
.getNonProposing(0)
.getMessageFactory()
.createSignedProposalPayload(nextRoundId, reproposedBlock));
.createSignedProposalPayload(nextRoundId, reproposedBlock)
.getSignedPayload());
peers.verifyNoMessagesReceived();
nextRoles.getNonProposing(1).injectPrepare(nextRoundId, reproposedBlock.getHash());
final SignedData<CommitPayload> expectedCommit =
TestHelpers.createSignedCommitPayload(
nextRoundId, reproposedBlock, context.getLocalNodeParams().getNodeKeyPair());
final Commit expectedCommit =
new Commit(
TestHelpers.createSignedCommitPayload(
nextRoundId, reproposedBlock, context.getLocalNodeParams().getNodeKeyPair()));
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.IbftHelpers;
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.NewRoundPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparePayload;
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.RoundChangePayload;
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.
final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 1);
final SignedData<RoundChangePayload> expectedTxRoundChange =
final RoundChange expectedTxRoundChange =
localNodeMessageFactory.createSignedRoundChangePayload(targetRound, empty());
context.getController().handleRoundExpiry(new RoundExpiry(roundId));
peers.verifyMessagesReceived(expectedTxRoundChange);
@ -84,7 +85,7 @@ public class RoundChangeTest {
@Test
public void roundChangeHasEmptyCertificateIfNoPrepareMessagesReceived() {
final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 1);
final SignedData<RoundChangePayload> expectedTxRoundChange =
final RoundChange expectedTxRoundChange =
localNodeMessageFactory.createSignedRoundChangePayload(targetRound, empty());
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
// receiving only a single Prepare msg will result in no PreparedCert.
final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 1);
final SignedData<RoundChangePayload> expectedTxRoundChange =
final RoundChange expectedTxRoundChange =
localNodeMessageFactory.createSignedRoundChangePayload(targetRound, empty());
peers.getProposer().injectProposal(roundId, blockToPropose);
@ -113,27 +114,28 @@ public class RoundChangeTest {
@Test
public void roundChangeHasPopulatedCertificateIfQuorumPrepareMessagesAndProposalAreReceived() {
final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 1);
final SignedData<PreparePayload> localPrepareMessage =
final Prepare localPrepareMessage =
localNodeMessageFactory.createSignedPreparePayload(roundId, blockToPropose.getHash());
final SignedData<ProposalPayload> proposal =
peers.getProposer().injectProposal(roundId, blockToPropose);
final Proposal proposal = peers.getProposer().injectProposal(roundId, blockToPropose);
peers.clearReceivedMessages();
final SignedData<PreparePayload> p1 =
peers.getNonProposing(0).injectPrepare(roundId, blockToPropose.getHash());
final Prepare p1 = peers.getNonProposing(0).injectPrepare(roundId, blockToPropose.getHash());
peers.clearReceivedMessages();
final SignedData<PreparePayload> p2 =
peers.getNonProposing(1).injectPrepare(roundId, blockToPropose.getHash());
final Prepare p2 = peers.getNonProposing(1).injectPrepare(roundId, blockToPropose.getHash());
peers.clearReceivedMessages();
final SignedData<RoundChangePayload> expectedTxRoundChange =
final RoundChange expectedTxRoundChange =
localNodeMessageFactory.createSignedRoundChangePayload(
targetRound,
Optional.of(
new PreparedCertificate(
proposal, Lists.newArrayList(localPrepareMessage, p1, p2))));
proposal.getSignedPayload(),
Lists.newArrayList(
localPrepareMessage.getSignedPayload(),
p1.getSignedPayload(),
p2.getSignedPayload()))));
context.getController().handleRoundExpiry(new RoundExpiry(roundId));
peers.verifyMessagesReceived(expectedTxRoundChange);
@ -146,20 +148,23 @@ public class RoundChangeTest {
final Block locallyProposedBlock =
context.createBlockForProposalFromChainHead(targetRound.getRoundNumber(), blockTimeStamp);
final SignedData<RoundChangePayload> rc1 =
peers.getNonProposing(0).injectRoundChange(targetRound, empty());
final SignedData<RoundChangePayload> rc2 =
peers.getNonProposing(1).injectRoundChange(targetRound, empty());
final SignedData<RoundChangePayload> rc3 =
peers.getNonProposing(2).injectRoundChange(targetRound, empty());
final SignedData<RoundChangePayload> rc4 =
peers.getProposer().injectRoundChange(targetRound, empty());
final RoundChange rc1 = peers.getNonProposing(0).injectRoundChange(targetRound, empty());
final RoundChange rc2 = peers.getNonProposing(1).injectRoundChange(targetRound, empty());
final RoundChange rc3 = peers.getNonProposing(2).injectRoundChange(targetRound, empty());
final RoundChange rc4 = peers.getProposer().injectRoundChange(targetRound, empty());
final SignedData<NewRoundPayload> expectedNewRound =
final NewRound expectedNewRound =
localNodeMessageFactory.createSignedNewRoundPayload(
targetRound,
new RoundChangeCertificate(Lists.newArrayList(rc1, rc2, rc3, rc4)),
localNodeMessageFactory.createSignedProposalPayload(targetRound, locallyProposedBlock));
new RoundChangeCertificate(
Lists.newArrayList(
rc1.getSignedPayload(),
rc2.getSignedPayload(),
rc3.getSignedPayload(),
rc4.getSignedPayload())),
localNodeMessageFactory
.createSignedProposalPayload(targetRound, locallyProposedBlock)
.getSignedPayload());
peers.verifyMessagesReceived(expectedNewRound);
}
@ -182,19 +187,18 @@ public class RoundChangeTest {
final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 4);
final SignedData<RoundChangePayload> rc1 =
peers.getNonProposing(0).injectRoundChange(targetRound, empty());
final RoundChange rc1 = peers.getNonProposing(0).injectRoundChange(targetRound, empty());
// 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));
// 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));
// Create a roundChange containing a PreparedCertificate
final SignedData<RoundChangePayload> rc4 =
final RoundChange rc4 =
peers.getProposer().injectRoundChange(targetRound, Optional.of(bestPrepCert));
// 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(
targetRound.getRoundNumber(), ARBITRARY_BLOCKTIME);
final SignedData<NewRoundPayload> expectedNewRound =
final NewRound expectedNewRound =
localNodeMessageFactory.createSignedNewRoundPayload(
targetRound,
new RoundChangeCertificate(Lists.newArrayList(rc1, rc2, rc3, rc4)),
localNodeMessageFactory.createSignedProposalPayload(
targetRound, expectedBlockToPropose));
new RoundChangeCertificate(
Lists.newArrayList(
rc1.getSignedPayload(),
rc2.getSignedPayload(),
rc3.getSignedPayload(),
rc4.getSignedPayload())),
localNodeMessageFactory
.createSignedProposalPayload(targetRound, expectedBlockToPropose)
.getSignedPayload());
peers.verifyMessagesReceived(expectedNewRound);
}
@ -226,11 +236,13 @@ public class RoundChangeTest {
final Block locallyProposedBlock =
context.createBlockForProposalFromChainHead(futureRound.getRoundNumber(), blockTimeStamp);
final SignedData<NewRoundPayload> expectedNewRound =
final NewRound expectedNewRound =
localNodeMessageFactory.createSignedNewRoundPayload(
futureRound,
new RoundChangeCertificate(roundChangeMessages),
localNodeMessageFactory.createSignedProposalPayload(futureRound, locallyProposedBlock));
localNodeMessageFactory
.createSignedProposalPayload(futureRound, locallyProposedBlock)
.getSignedPayload());
peers.verifyMessagesReceived(expectedNewRound);
}
@ -264,7 +276,10 @@ public class RoundChangeTest {
List<SignedData<RoundChangePayload>> roundChangeMessages = Lists.newArrayList();
// Create a roundChange containing a PreparedCertificate
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).
peers.getProposer().injectRoundChange(targetRound, empty());
@ -275,12 +290,13 @@ public class RoundChangeTest {
context.createBlockForProposalFromChainHead(
targetRound.getRoundNumber(), ARBITRARY_BLOCKTIME);
final SignedData<NewRoundPayload> expectedNewRound =
final NewRound expectedNewRound =
localNodeMessageFactory.createSignedNewRoundPayload(
targetRound,
new RoundChangeCertificate(Lists.newArrayList(roundChangeMessages)),
localNodeMessageFactory.createSignedProposalPayload(
targetRound, expectedBlockToPropose));
localNodeMessageFactory
.createSignedProposalPayload(targetRound, expectedBlockToPropose)
.getSignedPayload());
peers.verifyMessagesReceived(expectedNewRound);
}
@ -312,12 +328,9 @@ public class RoundChangeTest {
public void illegallyConstructedRoundChangeMessageIsDiscarded() {
final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 4);
final SignedData<RoundChangePayload> rc1 =
peers.getNonProposing(0).injectRoundChange(targetRound, empty());
final SignedData<RoundChangePayload> rc2 =
peers.getNonProposing(1).injectRoundChange(targetRound, empty());
final SignedData<RoundChangePayload> rc3 =
peers.getNonProposing(2).injectRoundChange(targetRound, empty());
final RoundChange rc1 = peers.getNonProposing(0).injectRoundChange(targetRound, empty());
final RoundChange rc2 = peers.getNonProposing(1).injectRoundChange(targetRound, empty());
final RoundChange rc3 = peers.getNonProposing(2).injectRoundChange(targetRound, empty());
// create illegal RoundChangeMessage
final PreparedCertificate illegalPreparedCertificate =
@ -325,7 +338,8 @@ public class RoundChangeTest {
peers
.getNonProposing(0)
.getMessageFactory()
.createSignedProposalPayload(roundId, blockToPropose),
.createSignedProposalPayload(roundId, blockToPropose)
.getSignedPayload(),
emptyList());
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.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.PreparePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.support.NodeParams;
import tech.pegasys.pantheon.consensus.ibft.support.RoundSpecificPeers;
import tech.pegasys.pantheon.consensus.ibft.support.TestContext;
@ -63,8 +62,8 @@ public class SpuriousBehaviourTest {
private final RoundSpecificPeers peers = context.roundSpecificPeers(roundId);
private Block proposedBlock = context.createBlockForProposalFromChainHead(0, 30);
private SignedData<PreparePayload> expectedPrepare;
private SignedData<CommitPayload> expectedCommit;
private Prepare expectedPrepare;
private Commit expectedCommit;
@Before
public void setup() {
@ -75,8 +74,9 @@ public class SpuriousBehaviourTest {
.getLocalNodeMessageFactory()
.createSignedPreparePayload(roundId, proposedBlock.getHash());
expectedCommit =
createSignedCommitPayload(
roundId, proposedBlock, context.getLocalNodeParams().getNodeKeyPair());
new Commit(
createSignedCommitPayload(
roundId, proposedBlock, context.getLocalNodeParams().getNodeKeyPair()));
}
@Test

@ -13,6 +13,8 @@
package tech.pegasys.pantheon.consensus.ibft.messagewrappers;
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;
public class NewRound extends IbftMessage<NewRoundPayload> {
@ -20,4 +22,12 @@ public class NewRound extends IbftMessage<NewRoundPayload> {
public NewRound(final SignedData<NewRoundPayload> 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) {
final Proposal data =
new Proposal(messageFactory.createSignedProposalPayload(roundIdentifier, block));
final Proposal data = messageFactory.createSignedProposalPayload(roundIdentifier, block);
final ProposalMessageData message = ProposalMessageData.create(data);
@ -55,8 +54,7 @@ public class IbftMessageTransmitter {
}
public void multicastPrepare(final ConsensusRoundIdentifier roundIdentifier, final Hash digest) {
final Prepare data =
new Prepare(messageFactory.createSignedPreparePayload(roundIdentifier, digest));
final Prepare data = messageFactory.createSignedPreparePayload(roundIdentifier, digest);
final PrepareMessageData message = PrepareMessageData.create(data);
@ -68,7 +66,7 @@ public class IbftMessageTransmitter {
final Hash digest,
final Signature commitSeal) {
final Commit data =
new Commit(messageFactory.createSignedCommitPayload(roundIdentifier, digest, commitSeal));
messageFactory.createSignedCommitPayload(roundIdentifier, digest, commitSeal);
final CommitMessageData message = CommitMessageData.create(data);
@ -80,8 +78,7 @@ public class IbftMessageTransmitter {
final Optional<PreparedCertificate> preparedCertificate) {
final RoundChange data =
new RoundChange(
messageFactory.createSignedRoundChangePayload(roundIdentifier, preparedCertificate));
messageFactory.createSignedRoundChangePayload(roundIdentifier, preparedCertificate);
final RoundChangeMessageData message = RoundChangeMessageData.create(data);
@ -94,9 +91,8 @@ public class IbftMessageTransmitter {
final SignedData<ProposalPayload> proposalPayload) {
final NewRound signedPayload =
new NewRound(
messageFactory.createSignedNewRoundPayload(
roundIdentifier, roundChangeCertificate, proposalPayload));
messageFactory.createSignedNewRoundPayload(
roundIdentifier, roundChangeCertificate, proposalPayload);
final NewRoundMessageData message = NewRoundMessageData.create(signedPayload);

@ -13,6 +13,11 @@
package tech.pegasys.pantheon.consensus.ibft.payload;
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.KeyPair;
import tech.pegasys.pantheon.crypto.SECP256K1.Signature;
@ -31,42 +36,42 @@ public class MessageFactory {
this.validatorKeyPair = validatorKeyPair;
}
public SignedData<ProposalPayload> createSignedProposalPayload(
public Proposal createSignedProposalPayload(
final ConsensusRoundIdentifier roundIdentifier, final Block 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 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 Hash digest,
final Signature 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 Optional<PreparedCertificate> 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 RoundChangeCertificate roundChangeCertificate,
final SignedData<ProposalPayload> proposalPayload) {
@ -74,7 +79,7 @@ public class MessageFactory {
final NewRoundPayload payload =
new NewRoundPayload(roundIdentifier, roundChangeCertificate, proposalPayload);
return createSignedMessage(payload);
return new NewRound(createSignedMessage(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.messagedata.IbftV2;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.NewRound;
import tech.pegasys.pantheon.ethereum.rlp.RLPInput;
import tech.pegasys.pantheon.ethereum.rlp.RLPOutput;
@ -122,9 +123,11 @@ public class NewRoundPayload implements Payload {
this.proposalPayload = proposalPayload;
}
public static Builder fromExisting(final NewRoundPayload payload) {
public static Builder fromExisting(final NewRound payload) {
return new Builder(
payload.roundChangeIdentifier, payload.roundChangeCertificate, payload.proposalPayload);
payload.getRoundIdentifier(),
payload.getRoundChangeCertificate(),
payload.getProposalPayload());
}
public void setRoundChangeIdentifier(final ConsensusRoundIdentifier roundChangeIdentifier) {

@ -12,6 +12,7 @@
*/
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.RLPOutput;
@ -20,10 +21,12 @@ import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.StringJoiner;
import java.util.stream.Collectors;
import com.google.common.collect.Lists;
public class RoundChangeCertificate {
private final Collection<SignedData<RoundChangePayload>> roundChangePayloads;
public RoundChangeCertificate(
@ -52,16 +55,21 @@ public class RoundChangeCertificate {
}
public static class Builder {
private final List<SignedData<RoundChangePayload>> roundChangePayloads = Lists.newArrayList();
private final List<RoundChange> roundChangePayloads = Lists.newArrayList();
public Builder() {}
public void appendRoundChangeMessage(final SignedData<RoundChangePayload> msg) {
public void appendRoundChangeMessage(final RoundChange msg) {
roundChangePayloads.add(msg);
}
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);
final RoundChange localRoundChange =
new RoundChange(
messageFactory.createSignedRoundChangePayload(
currentRound.getRoundIdentifier(), latestPreparedCertificate));
messageFactory.createSignedRoundChangePayload(
currentRound.getRoundIdentifier(), latestPreparedCertificate);
transmitter.multicastRoundChange(currentRound.getRoundIdentifier(), latestPreparedCertificate);
// Its possible the locally created RoundChange triggers the transmission of a NewRound

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

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

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

@ -217,8 +217,7 @@ public class IbftBlockHeightManagerTest {
public void onRoundChangeReceptionRoundChangeManagerIsInvokedAndNewRoundStarted() {
final ConsensusRoundIdentifier futureRoundIdentifier = createFrom(roundIdentifier, 0, +2);
final RoundChange roundChange =
new RoundChange(
messageFactory.createSignedRoundChangePayload(futureRoundIdentifier, Optional.empty()));
messageFactory.createSignedRoundChangePayload(futureRoundIdentifier, Optional.empty());
when(roundChangeManager.appendRoundChangeMessage(any()))
.thenReturn(
Optional.of(new RoundChangeCertificate(singletonList(roundChange.getSignedPayload()))));
@ -263,8 +262,7 @@ public class IbftBlockHeightManagerTest {
public void whenSufficientRoundChangesAreReceivedANewRoundMessageIsTransmitted() {
final ConsensusRoundIdentifier futureRoundIdentifier = createFrom(roundIdentifier, 0, +2);
final RoundChange roundChange =
new RoundChange(
messageFactory.createSignedRoundChangePayload(futureRoundIdentifier, Optional.empty()));
messageFactory.createSignedRoundChangePayload(futureRoundIdentifier, Optional.empty());
final RoundChangeCertificate roundChangCert =
new RoundChangeCertificate(singletonList(roundChange.getSignedPayload()));
@ -303,29 +301,28 @@ public class IbftBlockHeightManagerTest {
manager.start();
final Prepare prepare =
new Prepare(
validatorMessageFactory
.get(0)
.createSignedPreparePayload(futureRoundIdentifier, Hash.fromHexStringLenient("0")));
validatorMessageFactory
.get(0)
.createSignedPreparePayload(futureRoundIdentifier, Hash.fromHexStringLenient("0"));
final Commit commit =
new Commit(
validatorMessageFactory
.get(1)
.createSignedCommitPayload(
futureRoundIdentifier,
Hash.fromHexStringLenient("0"),
Signature.create(BigInteger.ONE, BigInteger.ONE, (byte) 1)));
validatorMessageFactory
.get(1)
.createSignedCommitPayload(
futureRoundIdentifier,
Hash.fromHexStringLenient("0"),
Signature.create(BigInteger.ONE, BigInteger.ONE, (byte) 1));
manager.handlePreparePayload(prepare);
manager.handleCommitPayload(commit);
// Force a new round to be started at new round number.
final NewRound newRound =
new NewRound(
messageFactory.createSignedNewRoundPayload(
futureRoundIdentifier,
new RoundChangeCertificate(Collections.emptyList()),
messageFactory.createSignedProposalPayload(futureRoundIdentifier, createdBlock)));
messageFactory.createSignedNewRoundPayload(
futureRoundIdentifier,
new RoundChangeCertificate(Collections.emptyList()),
messageFactory
.createSignedProposalPayload(futureRoundIdentifier, createdBlock)
.getSignedPayload());
manager.handleNewRoundPayload(newRound);
@ -348,15 +345,13 @@ public class IbftBlockHeightManagerTest {
manager.handleBlockTimerExpiry(roundIdentifier); // Trigger a Proposal creation.
final Prepare firstPrepare =
new Prepare(
validatorMessageFactory
.get(0)
.createSignedPreparePayload(roundIdentifier, Hash.fromHexStringLenient("0")));
validatorMessageFactory
.get(0)
.createSignedPreparePayload(roundIdentifier, Hash.fromHexStringLenient("0"));
final Prepare secondPrepare =
new Prepare(
validatorMessageFactory
.get(1)
.createSignedPreparePayload(roundIdentifier, Hash.fromHexStringLenient("0")));
validatorMessageFactory
.get(1)
.createSignedPreparePayload(roundIdentifier, Hash.fromHexStringLenient("0"));
manager.handlePreparePayload(firstPrepare);
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.IbftExtraData;
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.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate;
@ -140,7 +137,7 @@ public class IbftRoundTest {
transmitter);
round.handleProposalMessage(
new Proposal(messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock)));
messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock));
verify(transmitter, times(1)).multicastPrepare(roundIdentifier, proposedBlock.getHash());
verify(transmitter, never()).multicastCommit(any(), any(), any());
}
@ -206,7 +203,7 @@ public class IbftRoundTest {
// Receive Proposal Message
round.handleProposalMessage(
new Proposal(messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock)));
messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock));
verify(transmitter, times(1)).multicastPrepare(roundIdentifier, proposedBlock.getHash());
verify(transmitter, times(1))
.multicastCommit(roundIdentifier, proposedBlock.getHash(), localCommitSeal);
@ -215,9 +212,8 @@ public class IbftRoundTest {
// Receive Commit Message
round.handleCommitMessage(
new Commit(
messageFactory.createSignedCommitPayload(
roundIdentifier, proposedBlock.getHash(), remoteCommitSeal)));
messageFactory.createSignedCommitPayload(
roundIdentifier, proposedBlock.getHash(), remoteCommitSeal));
// Should import block when both commit seals are available.
ArgumentCaptor<Block> capturedBlock = ArgumentCaptor.forClass(Block.class);
@ -253,17 +249,15 @@ public class IbftRoundTest {
verify(blockImporter, never()).importBlock(any(), any(), any());
round.handlePrepareMessage(
new Prepare(
messageFactory.createSignedPreparePayload(roundIdentifier, proposedBlock.getHash())));
messageFactory.createSignedPreparePayload(roundIdentifier, proposedBlock.getHash()));
verify(transmitter, times(1))
.multicastCommit(roundIdentifier, proposedBlock.getHash(), localCommitSeal);
verify(blockImporter, never()).importBlock(any(), any(), any());
round.handleCommitMessage(
new Commit(
messageFactory.createSignedCommitPayload(
roundIdentifier, proposedBlock.getHash(), remoteCommitSeal)));
messageFactory.createSignedCommitPayload(
roundIdentifier, proposedBlock.getHash(), remoteCommitSeal));
verify(blockImporter, times(1)).importBlock(any(), any(), any());
}
@ -307,15 +301,17 @@ public class IbftRoundTest {
final RoundChangeCertificate roundChangeCertificate =
new RoundChangeCertificate(
Collections.singletonList(
messageFactory.createSignedRoundChangePayload(
roundIdentifier,
Optional.of(
new PreparedCertificate(
messageFactory.createSignedProposalPayload(
priorRoundChange, proposedBlock),
Collections
.emptyList()))))); // NOTE: IbftRound assumes the prepare's are
// valid
messageFactory
.createSignedRoundChangePayload(
roundIdentifier,
Optional.of(
new PreparedCertificate(
messageFactory
.createSignedProposalPayload(priorRoundChange, proposedBlock)
.getSignedPayload(),
Collections.emptyList())))
.getSignedPayload()));
// NOTE: IbftRound assumes the prepare's are valid
round.startRoundWith(roundChangeCertificate, 15);
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
// indicates the block has entered the roundState (note: all msgs are deemed valid due to mocks)
round.handlePrepareMessage(
new Prepare(
messageFactory.createSignedPreparePayload(roundIdentifier, proposedBlock.getHash())));
messageFactory.createSignedPreparePayload(roundIdentifier, proposedBlock.getHash()));
assertThat(roundState.isPrepared()).isTrue();
}
@ -352,7 +347,9 @@ public class IbftRoundTest {
final RoundChangeCertificate roundChangeCertificate =
new RoundChangeCertificate(
Collections.singletonList(
messageFactory.createSignedRoundChangePayload(roundIdentifier, Optional.empty())));
messageFactory
.createSignedRoundChangePayload(roundIdentifier, Optional.empty())
.getSignedPayload()));
round.startRoundWith(roundChangeCertificate, 15);
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
// indicates the block has entered the roundState (note: all msgs are deemed valid due to mocks)
round.handlePrepareMessage(
new Prepare(
messageFactory.createSignedPreparePayload(roundIdentifier, proposedBlock.getHash())));
messageFactory.createSignedPreparePayload(roundIdentifier, proposedBlock.getHash()));
assertThat(roundState.isPrepared()).isTrue();
}
@ -401,12 +397,11 @@ public class IbftRoundTest {
transmitter);
round.handleCommitMessage(
new Commit(
messageFactory.createSignedCommitPayload(
roundIdentifier, proposedBlock.getHash(), remoteCommitSeal)));
messageFactory.createSignedCommitPayload(
roundIdentifier, proposedBlock.getHash(), remoteCommitSeal));
round.handleProposalMessage(
new Proposal(messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock)));
messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock));
verify(blockImporter, times(1)).importBlock(any(), any(), any());
}
@ -427,12 +422,11 @@ public class IbftRoundTest {
transmitter);
round.handleCommitMessage(
new Commit(
messageFactory.createSignedCommitPayload(
roundIdentifier, proposedBlock.getHash(), remoteCommitSeal)));
messageFactory.createSignedCommitPayload(
roundIdentifier, proposedBlock.getHash(), remoteCommitSeal));
round.handleProposalMessage(
new Proposal(messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock)));
messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock));
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.IbftHelpers;
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.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.ProposalPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.validation.MessageValidator;
import tech.pegasys.pantheon.consensus.ibft.validation.RoundChangeMessageValidator;
@ -129,7 +129,7 @@ public class RoundChangeManagerTest {
private RoundChange makeRoundChangeMessage(
final KeyPair key, final ConsensusRoundIdentifier round) {
MessageFactory messageFactory = new MessageFactory(key);
return new RoundChange(messageFactory.createSignedRoundChangePayload(round, Optional.empty()));
return messageFactory.createSignedRoundChangePayload(round, Optional.empty());
}
private RoundChange makeRoundChangeMessageWithPreparedCert(
@ -143,8 +143,7 @@ public class RoundChangeManagerTest {
final ConsensusRoundIdentifier proposalRound = TestHelpers.createFrom(round, 0, -1);
final Block block = TestHelpers.createProposalBlock(validators, proposalRound.getRoundNumber());
// Proposal must come from an earlier round.
final SignedData<ProposalPayload> proposal =
messageFactory.createSignedProposalPayload(proposalRound, block);
final Proposal proposal = messageFactory.createSignedProposalPayload(proposalRound, block);
final List<SignedData<PreparePayload>> preparePayloads =
prepareProviders
@ -152,13 +151,16 @@ public class RoundChangeManagerTest {
.map(
k -> {
final MessageFactory prepareFactory = new MessageFactory(k);
return prepareFactory.createSignedPreparePayload(proposalRound, block.getHash());
return prepareFactory
.createSignedPreparePayload(proposalRound, block.getHash())
.getSignedPayload();
})
.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

@ -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.Proposal;
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.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.crypto.SECP256K1.Signature;
@ -82,8 +80,7 @@ public class RoundStateTest {
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator);
final Proposal proposal =
new Proposal(
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block));
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block);
assertThat(roundState.setProposedBlock(proposal)).isFalse();
assertThat(roundState.isPrepared()).isFalse();
@ -97,8 +94,7 @@ public class RoundStateTest {
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator);
final Proposal proposal =
new Proposal(
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block));
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block);
assertThat(roundState.setProposedBlock(proposal)).isTrue();
assertThat(roundState.isPrepared()).isTrue();
@ -116,21 +112,19 @@ public class RoundStateTest {
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator);
final Proposal proposal =
new Proposal(
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block));
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block);
assertThat(roundState.setProposedBlock(proposal)).isTrue();
assertThat(roundState.isPrepared()).isTrue();
assertThat(roundState.isCommitted()).isFalse();
final Commit commit =
new Commit(
validatorMessageFactories
.get(0)
.createSignedCommitPayload(
roundIdentifier,
block.getHash(),
Signature.create(BigInteger.ONE, BigInteger.ONE, (byte) 1)));
validatorMessageFactories
.get(0)
.createSignedCommitPayload(
roundIdentifier,
block.getHash(),
Signature.create(BigInteger.ONE, BigInteger.ONE, (byte) 1));
roundState.addCommitMessage(commit);
assertThat(roundState.isPrepared()).isTrue();
@ -146,16 +140,14 @@ public class RoundStateTest {
final RoundState roundState = new RoundState(roundIdentifier, 3, messageValidator);
final Prepare firstPrepare =
new Prepare(
validatorMessageFactories
.get(1)
.createSignedPreparePayload(roundIdentifier, block.getHash()));
validatorMessageFactories
.get(1)
.createSignedPreparePayload(roundIdentifier, block.getHash());
final Prepare secondPrepare =
new Prepare(
validatorMessageFactories
.get(2)
.createSignedPreparePayload(roundIdentifier, block.getHash()));
validatorMessageFactories
.get(2)
.createSignedPreparePayload(roundIdentifier, block.getHash());
roundState.addPrepareMessage(firstPrepare);
assertThat(roundState.isPrepared()).isFalse();
@ -168,8 +160,7 @@ public class RoundStateTest {
assertThat(roundState.constructPreparedCertificate()).isEmpty();
final Proposal proposal =
new Proposal(
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block));
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block);
assertThat(roundState.setProposedBlock(proposal)).isTrue();
assertThat(roundState.isPrepared()).isTrue();
assertThat(roundState.isCommitted()).isFalse();
@ -178,12 +169,12 @@ public class RoundStateTest {
@Test
public void invalidPriorPrepareMessagesAreDiscardedUponSubsequentProposal() {
final SignedData<PreparePayload> firstPrepare =
final Prepare firstPrepare =
validatorMessageFactories
.get(1)
.createSignedPreparePayload(roundIdentifier, block.getHash());
final SignedData<PreparePayload> secondPrepare =
final Prepare secondPrepare =
validatorMessageFactories
.get(2)
.createSignedPreparePayload(roundIdentifier, block.getHash());
@ -193,16 +184,16 @@ public class RoundStateTest {
final RoundState roundState = new RoundState(roundIdentifier, 3, messageValidator);
when(messageValidator.addSignedProposalPayload(any())).thenReturn(true);
when(messageValidator.validatePrepareMessage(firstPrepare)).thenReturn(true);
when(messageValidator.validatePrepareMessage(secondPrepare)).thenReturn(false);
when(messageValidator.validatePrepareMessage(firstPrepare.getSignedPayload())).thenReturn(true);
when(messageValidator.validatePrepareMessage(secondPrepare.getSignedPayload()))
.thenReturn(false);
roundState.addPrepareMessage(new Prepare(firstPrepare));
roundState.addPrepareMessage(new Prepare(secondPrepare));
roundState.addPrepareMessage(firstPrepare);
roundState.addPrepareMessage(secondPrepare);
verify(messageValidator, never()).validatePrepareMessage(any());
final Proposal proposal =
new Proposal(
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block));
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block);
assertThat(roundState.setProposedBlock(proposal)).isTrue();
assertThat(roundState.isPrepared()).isFalse();
@ -214,31 +205,32 @@ public class RoundStateTest {
public void prepareMessageIsValidatedAgainstExitingProposal() {
final RoundState roundState = new RoundState(roundIdentifier, 2, messageValidator);
final SignedData<PreparePayload> firstPrepare =
final Prepare firstPrepare =
validatorMessageFactories
.get(1)
.createSignedPreparePayload(roundIdentifier, block.getHash());
final SignedData<PreparePayload> secondPrepare =
final Prepare secondPrepare =
validatorMessageFactories
.get(2)
.createSignedPreparePayload(roundIdentifier, block.getHash());
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.validatePrepareMessage(firstPrepare)).thenReturn(false);
when(messageValidator.validatePrepareMessage(secondPrepare)).thenReturn(true);
when(messageValidator.validatePrepareMessage(firstPrepare.getSignedPayload()))
.thenReturn(false);
when(messageValidator.validatePrepareMessage(secondPrepare.getSignedPayload()))
.thenReturn(true);
roundState.setProposedBlock(proposal);
assertThat(roundState.isPrepared()).isFalse();
roundState.addPrepareMessage(new Prepare(firstPrepare));
roundState.addPrepareMessage(firstPrepare);
assertThat(roundState.isPrepared()).isFalse();
roundState.addPrepareMessage(new Prepare(secondPrepare));
roundState.addPrepareMessage(secondPrepare);
assertThat(roundState.isPrepared()).isTrue();
}
@ -250,26 +242,23 @@ public class RoundStateTest {
final RoundState roundState = new RoundState(roundIdentifier, 2, messageValidator);
final Commit firstCommit =
new Commit(
validatorMessageFactories
.get(1)
.createSignedCommitPayload(
roundIdentifier,
block.getHash(),
Signature.create(BigInteger.ONE, BigInteger.TEN, (byte) 1)));
validatorMessageFactories
.get(1)
.createSignedCommitPayload(
roundIdentifier,
block.getHash(),
Signature.create(BigInteger.ONE, BigInteger.TEN, (byte) 1));
final Commit secondCommit =
new Commit(
validatorMessageFactories
.get(2)
.createSignedCommitPayload(
roundIdentifier,
block.getHash(),
Signature.create(BigInteger.TEN, BigInteger.TEN, (byte) 1)));
validatorMessageFactories
.get(2)
.createSignedCommitPayload(
roundIdentifier,
block.getHash(),
Signature.create(BigInteger.TEN, BigInteger.TEN, (byte) 1));
final Proposal proposal =
new Proposal(
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block));
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block);
roundState.setProposedBlock(proposal);
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.IbftContext;
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.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.KeyPair;
import tech.pegasys.pantheon.ethereum.BlockValidator;
@ -105,164 +104,164 @@ public class MessageValidatorTest {
@Test
public void receivingAPrepareMessageBeforeProposalFails() {
final SignedData<PreparePayload> prepareMsg =
final Prepare prepareMsg =
proposerMessageFactory.createSignedPreparePayload(roundIdentifier, Hash.ZERO);
assertThat(validator.validatePrepareMessage(prepareMsg)).isFalse();
assertThat(validator.validatePrepareMessage(prepareMsg.getSignedPayload())).isFalse();
}
@Test
public void receivingACommitMessageBeforeProposalFails() {
final SignedData<CommitPayload> commitMsg =
final Commit commitMsg =
proposerMessageFactory.createSignedCommitPayload(
roundIdentifier, Hash.ZERO, SECP256K1.sign(Hash.ZERO, proposerKey));
assertThat(validator.validateCommmitMessage(commitMsg)).isFalse();
assertThat(validator.validateCommmitMessage(commitMsg.getSignedPayload())).isFalse();
}
@Test
public void receivingProposalMessageFromNonProposerFails() {
final SignedData<ProposalPayload> proposalMsg =
final Proposal proposalMsg =
validatorMessageFactory.createSignedProposalPayload(roundIdentifier, mock(Block.class));
assertThat(validator.addSignedProposalPayload(proposalMsg)).isFalse();
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isFalse();
}
@Test
public void receivingProposalMessageWithIllegalBlockFails() {
when(blockValidator.validateAndProcessBlock(any(), any(), any(), any())).thenReturn(empty());
final SignedData<ProposalPayload> proposalMsg =
final Proposal proposalMsg =
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, mock(Block.class));
assertThat(validator.addSignedProposalPayload(proposalMsg)).isFalse();
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isFalse();
}
@Test
public void receivingPrepareFromProposerFails() {
final SignedData<ProposalPayload> proposalMsg =
final Proposal proposalMsg =
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
final SignedData<PreparePayload> prepareMsg =
final Prepare prepareMsg =
proposerMessageFactory.createSignedPreparePayload(roundIdentifier, block.getHash());
assertThat(validator.addSignedProposalPayload(proposalMsg)).isTrue();
assertThat(validator.validatePrepareMessage(prepareMsg)).isFalse();
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validatePrepareMessage(prepareMsg.getSignedPayload())).isFalse();
}
@Test
public void receivingPrepareFromNonValidatorFails() {
final SignedData<ProposalPayload> proposalMsg =
final Proposal proposalMsg =
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
final SignedData<PreparePayload> prepareMsg =
final Prepare prepareMsg =
nonValidatorMessageFactory.createSignedPreparePayload(roundIdentifier, block.getHash());
assertThat(validator.addSignedProposalPayload(proposalMsg)).isTrue();
assertThat(validator.validatePrepareMessage(prepareMsg)).isFalse();
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validatePrepareMessage(prepareMsg.getSignedPayload())).isFalse();
}
@Test
public void receivingMessagesWithDifferentRoundIdFromProposalFails() {
final SignedData<ProposalPayload> proposalMsg =
final Proposal proposalMsg =
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
final ConsensusRoundIdentifier invalidRoundIdentifier =
new ConsensusRoundIdentifier(
roundIdentifier.getSequenceNumber(), roundIdentifier.getRoundNumber() + 1);
final SignedData<PreparePayload> prepareMsg =
final Prepare prepareMsg =
validatorMessageFactory.createSignedPreparePayload(invalidRoundIdentifier, block.getHash());
final SignedData<CommitPayload> commitMsg =
final Commit commitMsg =
validatorMessageFactory.createSignedCommitPayload(
invalidRoundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), proposerKey));
assertThat(validator.addSignedProposalPayload(proposalMsg)).isTrue();
assertThat(validator.validatePrepareMessage(prepareMsg)).isFalse();
assertThat(validator.validateCommmitMessage(commitMsg)).isFalse();
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validatePrepareMessage(prepareMsg.getSignedPayload())).isFalse();
assertThat(validator.validateCommmitMessage(commitMsg.getSignedPayload())).isFalse();
}
@Test
public void receivingPrepareNonProposerValidatorWithCorrectRoundIsSuccessful() {
final SignedData<ProposalPayload> proposalMsg =
final Proposal proposalMsg =
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
final SignedData<PreparePayload> prepareMsg =
final Prepare prepareMsg =
validatorMessageFactory.createSignedPreparePayload(roundIdentifier, block.getHash());
assertThat(validator.addSignedProposalPayload(proposalMsg)).isTrue();
assertThat(validator.validatePrepareMessage(prepareMsg)).isTrue();
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validatePrepareMessage(prepareMsg.getSignedPayload())).isTrue();
}
@Test
public void receivingACommitMessageWithAnInvalidCommitSealFails() {
final SignedData<ProposalPayload> proposalMsg =
final Proposal proposalMsg =
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
final SignedData<CommitPayload> commitMsg =
final Commit commitMsg =
proposerMessageFactory.createSignedCommitPayload(
roundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), nonValidatorKey));
assertThat(validator.addSignedProposalPayload(proposalMsg)).isTrue();
assertThat(validator.validateCommmitMessage(commitMsg)).isFalse();
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validateCommmitMessage(commitMsg.getSignedPayload())).isFalse();
}
@Test
public void commitMessageContainingValidSealFromValidatorIsSuccessful() {
final SignedData<ProposalPayload> proposalMsg =
final Proposal proposalMsg =
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
final SignedData<CommitPayload> proposerCommitMsg =
final Commit proposerCommitMsg =
proposerMessageFactory.createSignedCommitPayload(
roundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), proposerKey));
final SignedData<CommitPayload> validatorCommitMsg =
final Commit validatorCommitMsg =
validatorMessageFactory.createSignedCommitPayload(
roundIdentifier, block.getHash(), SECP256K1.sign(block.getHash(), validatorKey));
assertThat(validator.addSignedProposalPayload(proposalMsg)).isTrue();
assertThat(validator.validateCommmitMessage(proposerCommitMsg)).isTrue();
assertThat(validator.validateCommmitMessage(validatorCommitMsg)).isTrue();
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
assertThat(validator.validateCommmitMessage(proposerCommitMsg.getSignedPayload())).isTrue();
assertThat(validator.validateCommmitMessage(validatorCommitMsg.getSignedPayload())).isTrue();
}
@Test
public void subsequentProposalHasDifferentSenderFails() {
final SignedData<ProposalPayload> proposalMsg =
final Proposal proposalMsg =
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);
assertThat(validator.addSignedProposalPayload(secondProposalMsg)).isFalse();
assertThat(validator.addSignedProposalPayload(secondProposalMsg.getSignedPayload())).isFalse();
}
@Test
public void subsequentProposalHasDifferentContentFails() {
final SignedData<ProposalPayload> proposalMsg =
final Proposal proposalMsg =
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, block);
assertThat(validator.addSignedProposalPayload(proposalMsg)).isTrue();
assertThat(validator.addSignedProposalPayload(proposalMsg.getSignedPayload())).isTrue();
final ConsensusRoundIdentifier newRoundIdentifier = new ConsensusRoundIdentifier(3, 0);
final SignedData<ProposalPayload> secondProposalMsg =
final Proposal secondProposalMsg =
proposerMessageFactory.createSignedProposalPayload(newRoundIdentifier, block);
assertThat(validator.addSignedProposalPayload(secondProposalMsg)).isFalse();
assertThat(validator.addSignedProposalPayload(secondProposalMsg.getSignedPayload())).isFalse();
}
@Test
public void subsequentProposalHasIdenticalSenderAndContentIsSuccessful() {
final SignedData<ProposalPayload> proposalMsg =
final Proposal proposalMsg =
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);
assertThat(validator.addSignedProposalPayload(secondProposalMsg)).isTrue();
assertThat(validator.addSignedProposalPayload(secondProposalMsg.getSignedPayload())).isTrue();
}
@Test
public void blockRoundMisMatchWithMessageRoundFails() {
insertRoundToBlockHeader(roundIdentifier.getRoundNumber() + 1);
final SignedData<ProposalPayload> proposalMsg =
final Proposal proposalMsg =
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.TestHelpers;
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.NewRoundPayload;
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.SignedData;
import tech.pegasys.pantheon.consensus.ibft.validation.RoundChangeMessageValidator.MessageValidatorForHeightFactory;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.core.Address;
@ -61,7 +61,8 @@ public class NewRoundMessageValidatorTest {
private final MessageValidator messageValidator = mock(MessageValidator.class);
private Block proposedBlock;
private SignedData<NewRoundPayload> validMsg;
private NewRound validMsg;
private NewRoundPayload validPayload;
private NewRoundPayload.Builder msgBuilder;
@Before
@ -72,7 +73,8 @@ public class NewRoundMessageValidatorTest {
proposedBlock = TestHelpers.createProposalBlock(validators, roundIdentifier.getRoundNumber());
validMsg = createValidNewRoundMessageSignedBy(proposerKey);
msgBuilder = NewRoundPayload.Builder.fromExisting(validMsg.getPayload());
validPayload = validMsg.getSignedPayload().getPayload();
msgBuilder = NewRoundPayload.Builder.fromExisting(validMsg);
when(proposerSelector.selectProposerForRound(any())).thenReturn(proposerAddress);
@ -89,7 +91,7 @@ public class NewRoundMessageValidatorTest {
* message.
*/
private SignedData<NewRoundPayload> createValidNewRoundMessageSignedBy(final KeyPair signingKey) {
private NewRound createValidNewRoundMessageSignedBy(final KeyPair signingKey) {
final MessageFactory messageCreator = new MessageFactory(signingKey);
final RoundChangeCertificate.Builder builder = new RoundChangeCertificate.Builder();
@ -99,11 +101,12 @@ public class NewRoundMessageValidatorTest {
return messageCreator.createSignedNewRoundPayload(
roundIdentifier,
builder.buildCertificate(),
messageCreator.createSignedProposalPayload(roundIdentifier, proposedBlock));
messageCreator
.createSignedProposalPayload(roundIdentifier, proposedBlock)
.getSignedPayload());
}
private SignedData<NewRoundPayload> signPayload(
final NewRoundPayload payload, final KeyPair signingKey) {
private NewRound signPayload(final NewRoundPayload payload, final KeyPair signingKey) {
final MessageFactory messageCreator = new MessageFactory(signingKey);
@ -115,14 +118,14 @@ public class NewRoundMessageValidatorTest {
@Test
public void basicNewRoundMessageIsValid() {
assertThat(validator.validateNewRoundMessage(validMsg)).isTrue();
assertThat(validator.validateNewRoundMessage(validMsg.getSignedPayload())).isTrue();
}
@Test
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
@ -130,9 +133,9 @@ public class NewRoundMessageValidatorTest {
msgBuilder.setRoundChangeIdentifier(
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
@ -140,18 +143,18 @@ public class NewRoundMessageValidatorTest {
final ConsensusRoundIdentifier futureRound = TestHelpers.createFrom(roundIdentifier, 1, 0);
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
public void newRoundWithEmptyRoundChangeCertificateFails() {
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
@ -164,20 +167,25 @@ public class NewRoundMessageValidatorTest {
final PreparedCertificate misMatchedPreparedCertificate =
new PreparedCertificate(
proposerMessageFactory.createSignedProposalPayload(preparedRound, prevProposedBlock),
proposerMessageFactory
.createSignedProposalPayload(preparedRound, prevProposedBlock)
.getSignedPayload(),
singletonList(
validatorMessageFactory.createSignedPreparePayload(
preparedRound, prevProposedBlock.getHash())));
validatorMessageFactory
.createSignedPreparePayload(preparedRound, prevProposedBlock.getHash())
.getSignedPayload()));
msgBuilder.setRoundChangeCertificate(
new RoundChangeCertificate(
singletonList(
validatorMessageFactory.createSignedRoundChangePayload(
roundIdentifier, Optional.of(misMatchedPreparedCertificate)))));
validatorMessageFactory
.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
@ -192,9 +200,9 @@ public class NewRoundMessageValidatorTest {
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
@ -207,19 +215,22 @@ public class NewRoundMessageValidatorTest {
roundIdentifier,
Optional.of(
new PreparedCertificate(
proposerMessageFactory.createSignedProposalPayload(prevRound, proposedBlock),
proposerMessageFactory
.createSignedProposalPayload(prevRound, proposedBlock)
.getSignedPayload(),
Lists.newArrayList(
validatorMessageFactory.createSignedPreparePayload(
prevRound, proposedBlock.getHash()))))));
validatorMessageFactory
.createSignedPreparePayload(prevRound, proposedBlock.getHash())
.getSignedPayload())))));
msgBuilder.setRoundChangeCertificate(roundChangeBuilder.buildCertificate());
// The prepare Message in the RoundChange Cert will be deemed illegal.
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
@ -227,15 +238,16 @@ public class NewRoundMessageValidatorTest {
final ConsensusRoundIdentifier latterPrepareRound =
new ConsensusRoundIdentifier(
roundIdentifier.getSequenceNumber(), roundIdentifier.getRoundNumber() - 1);
final SignedData<ProposalPayload> latterProposal =
final Proposal latterProposal =
proposerMessageFactory.createSignedProposalPayload(latterPrepareRound, proposedBlock);
final Optional<PreparedCertificate> preparedCert =
Optional.of(
new PreparedCertificate(
latterProposal,
latterProposal.getSignedPayload(),
Lists.newArrayList(
validatorMessageFactory.createSignedPreparePayload(
roundIdentifier, proposedBlock.getHash()))));
validatorMessageFactory
.createSignedPreparePayload(roundIdentifier, proposedBlock.getHash())
.getSignedPayload())));
// An earlier PrepareCert is added to ensure the path to find the latest PrepareCert
// is correctly followed.
@ -244,54 +256,61 @@ public class NewRoundMessageValidatorTest {
final ConsensusRoundIdentifier earlierPreparedRound =
new ConsensusRoundIdentifier(
roundIdentifier.getSequenceNumber(), roundIdentifier.getRoundNumber() - 2);
final SignedData<ProposalPayload> earlierProposal =
final Proposal earlierProposal =
proposerMessageFactory.createSignedProposalPayload(earlierPreparedRound, earlierBlock);
final Optional<PreparedCertificate> earlierPreparedCert =
Optional.of(
new PreparedCertificate(
earlierProposal,
earlierProposal.getSignedPayload(),
Lists.newArrayList(
validatorMessageFactory.createSignedPreparePayload(
earlierPreparedRound, earlierBlock.getHash()))));
validatorMessageFactory
.createSignedPreparePayload(earlierPreparedRound, earlierBlock.getHash())
.getSignedPayload())));
final RoundChangeCertificate roundChangeCert =
new RoundChangeCertificate(
Lists.newArrayList(
proposerMessageFactory.createSignedRoundChangePayload(
roundIdentifier, earlierPreparedCert),
validatorMessageFactory.createSignedRoundChangePayload(
roundIdentifier, preparedCert)));
proposerMessageFactory
.createSignedRoundChangePayload(roundIdentifier, earlierPreparedCert)
.getSignedPayload(),
validatorMessageFactory
.createSignedRoundChangePayload(roundIdentifier, preparedCert)
.getSignedPayload()));
// Ensure a message containing the earlier proposal fails
final SignedData<NewRoundPayload> newRoundWithEarlierProposal =
final NewRound newRoundWithEarlierProposal =
proposerMessageFactory.createSignedNewRoundPayload(
roundIdentifier, roundChangeCert, earlierProposal);
assertThat(validator.validateNewRoundMessage(newRoundWithEarlierProposal)).isFalse();
roundIdentifier, roundChangeCert, earlierProposal.getSignedPayload());
assertThat(validator.validateNewRoundMessage(newRoundWithEarlierProposal.getSignedPayload()))
.isFalse();
final SignedData<NewRoundPayload> newRoundWithLatterProposal =
final NewRound newRoundWithLatterProposal =
proposerMessageFactory.createSignedNewRoundPayload(
roundIdentifier, roundChangeCert, latterProposal);
assertThat(validator.validateNewRoundMessage(newRoundWithLatterProposal)).isTrue();
roundIdentifier, roundChangeCert, latterProposal.getSignedPayload());
assertThat(validator.validateNewRoundMessage(newRoundWithLatterProposal.getSignedPayload()))
.isTrue();
}
@Test
public void embeddedProposalFailsValidation() {
when(messageValidator.addSignedProposalPayload(any())).thenReturn(false, true);
final SignedData<ProposalPayload> proposal =
final Proposal proposal =
proposerMessageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock);
final SignedData<NewRoundPayload> msg =
final NewRound msg =
proposerMessageFactory.createSignedNewRoundPayload(
roundIdentifier,
new RoundChangeCertificate(
Lists.newArrayList(
proposerMessageFactory.createSignedRoundChangePayload(
roundIdentifier, Optional.empty()),
validatorMessageFactory.createSignedRoundChangePayload(
roundIdentifier, Optional.empty()))),
proposal);
assertThat(validator.validateNewRoundMessage(msg)).isFalse();
proposerMessageFactory
.createSignedRoundChangePayload(roundIdentifier, Optional.empty())
.getSignedPayload(),
validatorMessageFactory
.createSignedRoundChangePayload(roundIdentifier, Optional.empty())
.getSignedPayload())),
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 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.PreparePayload;
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.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.core.Address;
@ -81,33 +80,35 @@ public class RoundChangeMessageValidatorTest {
@Test
public void roundChangeSentByNonValidatorFails() {
final SignedData<RoundChangePayload> msg =
final RoundChange msg =
nonValidatorMessageFactory.createSignedRoundChangePayload(targetRound, Optional.empty());
assertThat(validator.validateMessage(msg)).isFalse();
assertThat(validator.validateMessage(msg.getSignedPayload())).isFalse();
}
@Test
public void roundChangeContainingNoCertificateIsSuccessful() {
final SignedData<RoundChangePayload> msg =
final RoundChange msg =
proposerMessageFactory.createSignedRoundChangePayload(targetRound, Optional.empty());
assertThat(validator.validateMessage(msg)).isTrue();
assertThat(validator.validateMessage(msg.getSignedPayload())).isTrue();
}
@Test
public void roundChangeContainingInvalidProposalFails() {
final PreparedCertificate prepareCertificate =
new PreparedCertificate(
proposerMessageFactory.createSignedProposalPayload(currentRound, block),
proposerMessageFactory
.createSignedProposalPayload(currentRound, block)
.getSignedPayload(),
Collections.emptyList());
final SignedData<RoundChangePayload> msg =
final RoundChange msg =
proposerMessageFactory.createSignedRoundChangePayload(
targetRound, Optional.of(prepareCertificate));
when(basicValidator.addSignedProposalPayload(any())).thenReturn(false);
assertThat(validator.validateMessage(msg)).isFalse();
assertThat(validator.validateMessage(msg.getSignedPayload())).isFalse();
verify(validatorFactory, times(1))
.createAt(prepareCertificate.getProposalPayload().getPayload().getRoundIdentifier());
verify(basicValidator, times(1))
@ -120,36 +121,40 @@ public class RoundChangeMessageValidatorTest {
public void roundChangeContainingValidProposalButNoPrepareMessagesFails() {
final PreparedCertificate prepareCertificate =
new PreparedCertificate(
proposerMessageFactory.createSignedProposalPayload(currentRound, block),
proposerMessageFactory
.createSignedProposalPayload(currentRound, block)
.getSignedPayload(),
Collections.emptyList());
final SignedData<RoundChangePayload> msg =
final RoundChange msg =
proposerMessageFactory.createSignedRoundChangePayload(
targetRound, Optional.of(prepareCertificate));
when(basicValidator.addSignedProposalPayload(any())).thenReturn(true);
assertThat(validator.validateMessage(msg)).isFalse();
assertThat(validator.validateMessage(msg.getSignedPayload())).isFalse();
}
@Test
public void roundChangeInvalidPrepareMessageFromProposerFails() {
final SignedData<PreparePayload> prepareMsg =
final Prepare prepareMsg =
validatorMessageFactory.createSignedPreparePayload(currentRound, block.getHash());
final PreparedCertificate prepareCertificate =
new PreparedCertificate(
proposerMessageFactory.createSignedProposalPayload(currentRound, block),
Lists.newArrayList(prepareMsg));
proposerMessageFactory
.createSignedProposalPayload(currentRound, block)
.getSignedPayload(),
Lists.newArrayList(prepareMsg.getSignedPayload()));
when(basicValidator.addSignedProposalPayload(any())).thenReturn(true);
when(basicValidator.validatePrepareMessage(any())).thenReturn(false);
final SignedData<RoundChangePayload> msg =
final RoundChange msg =
proposerMessageFactory.createSignedRoundChangePayload(
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());
}
@ -158,11 +163,11 @@ public class RoundChangeMessageValidatorTest {
final ConsensusRoundIdentifier latterRoundIdentifier =
new ConsensusRoundIdentifier(currentRound.getSequenceNumber() + 1, 1);
final SignedData<RoundChangePayload> msg =
final RoundChange msg =
proposerMessageFactory.createSignedRoundChangePayload(
latterRoundIdentifier, Optional.empty());
assertThat(validator.validateMessage(msg)).isFalse();
assertThat(validator.validateMessage(msg.getSignedPayload())).isFalse();
verify(basicValidator, never()).validatePrepareMessage(any());
}
@ -172,45 +177,49 @@ public class RoundChangeMessageValidatorTest {
new ConsensusRoundIdentifier(
currentRound.getSequenceNumber(), currentRound.getRoundNumber() + 2);
final SignedData<PreparePayload> prepareMsg =
final Prepare prepareMsg =
validatorMessageFactory.createSignedPreparePayload(futureRound, block.getHash());
final PreparedCertificate prepareCertificate =
new PreparedCertificate(
proposerMessageFactory.createSignedProposalPayload(futureRound, block),
Lists.newArrayList(prepareMsg));
proposerMessageFactory
.createSignedProposalPayload(futureRound, block)
.getSignedPayload(),
Lists.newArrayList(prepareMsg.getSignedPayload()));
final SignedData<RoundChangePayload> msg =
final RoundChange msg =
proposerMessageFactory.createSignedRoundChangePayload(
targetRound, Optional.of(prepareCertificate));
assertThat(validator.validateMessage(msg)).isFalse();
assertThat(validator.validateMessage(msg.getSignedPayload())).isFalse();
verify(validatorFactory, never()).createAt(any());
verify(basicValidator, never()).validatePrepareMessage(prepareMsg);
verify(basicValidator, never()).validatePrepareMessage(prepareMsg.getSignedPayload());
verify(basicValidator, never()).validateCommmitMessage(any());
}
@Test
public void roundChangeWithPastProposalForCurrentHeightIsSuccessful() {
final SignedData<PreparePayload> prepareMsg =
final Prepare prepareMsg =
validatorMessageFactory.createSignedPreparePayload(currentRound, block.getHash());
final PreparedCertificate prepareCertificate =
new PreparedCertificate(
proposerMessageFactory.createSignedProposalPayload(currentRound, block),
Lists.newArrayList(prepareMsg));
proposerMessageFactory
.createSignedProposalPayload(currentRound, block)
.getSignedPayload(),
Lists.newArrayList(prepareMsg.getSignedPayload()));
final SignedData<RoundChangePayload> msg =
final RoundChange msg =
proposerMessageFactory.createSignedRoundChangePayload(
targetRound, Optional.of(prepareCertificate));
when(basicValidator.addSignedProposalPayload(prepareCertificate.getProposalPayload()))
.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))
.createAt(prepareCertificate.getProposalPayload().getPayload().getRoundIdentifier());
verify(basicValidator, times(1))
.addSignedProposalPayload(prepareCertificate.getProposalPayload());
verify(basicValidator, times(1)).validatePrepareMessage(prepareMsg);
verify(basicValidator, times(1)).validatePrepareMessage(prepareMsg.getSignedPayload());
}
}

Loading…
Cancel
Save