Rename TerminatedRoundArtefacts to PreparedRoundArtefacts (#781)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
tmohay 6 years ago committed by GitHub
parent 53510a14cf
commit 3228664d06
  1. 7
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/RoundSpecificPeers.java
  2. 6
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/TestHelpers.java
  3. 6
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/support/ValidatorPeer.java
  4. 16
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/ReceivedNewRoundTest.java
  5. 24
      consensus/ibft/src/integration-test/java/tech/pegasys/pantheon/consensus/ibft/tests/RoundChangeTest.java
  6. 6
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/network/IbftMessageTransmitter.java
  7. 6
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/payload/MessageFactory.java
  8. 14
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftBlockHeightManager.java
  9. 4
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftRound.java
  10. 4
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/PreparedRoundArtefacts.java
  11. 4
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/RoundState.java
  12. 16
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/IbftHelpersTest.java
  13. 7
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftBlockHeightManagerTest.java
  14. 2
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftRoundTest.java
  15. 6
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/RoundChangeManagerTest.java
  16. 18
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/RoundStateTest.java
  17. 16
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/validation/NewRoundSignedDataValidatorTest.java
  18. 43
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/validation/RoundChangeSignedDataValidatorTest.java

@ -29,7 +29,7 @@ import tech.pegasys.pantheon.consensus.ibft.payload.Payload;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.statemachine.TerminatedRoundArtefacts;
import tech.pegasys.pantheon.consensus.ibft.statemachine.PreparedRoundArtefacts;
import tech.pegasys.pantheon.crypto.SECP256K1.Signature;
import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.ethereum.p2p.api.MessageData;
@ -109,14 +109,13 @@ public class RoundSpecificPeers {
}
public List<SignedData<RoundChangePayload>> createSignedRoundChangePayload(
final ConsensusRoundIdentifier roundId,
final TerminatedRoundArtefacts terminatedRoundArtefacts) {
final ConsensusRoundIdentifier roundId, final PreparedRoundArtefacts preparedRoundArtefacts) {
return peers
.stream()
.map(
p ->
p.getMessageFactory()
.createRoundChange(roundId, Optional.of(terminatedRoundArtefacts))
.createRoundChange(roundId, Optional.of(preparedRoundArtefacts))
.getSignedPayload())
.collect(Collectors.toList());
}

@ -23,7 +23,7 @@ import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangeCertificate;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.statemachine.TerminatedRoundArtefacts;
import tech.pegasys.pantheon.consensus.ibft.statemachine.PreparedRoundArtefacts;
import tech.pegasys.pantheon.crypto.SECP256K1;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.crypto.SECP256K1.Signature;
@ -49,11 +49,11 @@ public class TestHelpers {
return messageFactory.createCommit(roundId, block.getHash(), commitSeal).getSignedPayload();
}
public static TerminatedRoundArtefacts createValidTerminatedRoundArtefacts(
public static PreparedRoundArtefacts createValidPreparedRoundArtefacts(
final TestContext context, final ConsensusRoundIdentifier preparedRound, final Block block) {
final RoundSpecificPeers peers = context.roundSpecificPeers(preparedRound);
return new TerminatedRoundArtefacts(
return new PreparedRoundArtefacts(
peers.getProposer().getMessageFactory().createProposal(preparedRound, block),
peers
.createSignedPreparePayloadOfNonProposing(preparedRound, block.getHash())

@ -29,7 +29,7 @@ import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
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.statemachine.TerminatedRoundArtefacts;
import tech.pegasys.pantheon.consensus.ibft.statemachine.PreparedRoundArtefacts;
import tech.pegasys.pantheon.crypto.SECP256K1;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.crypto.SECP256K1.Signature;
@ -121,8 +121,8 @@ public class ValidatorPeer {
public RoundChange injectRoundChange(
final ConsensusRoundIdentifier rId,
final Optional<TerminatedRoundArtefacts> terminatedRoundArtefacts) {
final RoundChange payload = messageFactory.createRoundChange(rId, terminatedRoundArtefacts);
final Optional<PreparedRoundArtefacts> preparedRoundArtefacts) {
final RoundChange payload = messageFactory.createRoundChange(rId, preparedRoundArtefacts);
injectMessage(RoundChangeMessageData.create(payload));
return payload;
}

@ -12,7 +12,7 @@
*/
package tech.pegasys.pantheon.consensus.ibft.tests;
import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createValidTerminatedRoundArtefacts;
import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createValidPreparedRoundArtefacts;
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Commit;
@ -22,7 +22,7 @@ import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangeCertificate;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.statemachine.TerminatedRoundArtefacts;
import tech.pegasys.pantheon.consensus.ibft.statemachine.PreparedRoundArtefacts;
import tech.pegasys.pantheon.consensus.ibft.support.RoundSpecificPeers;
import tech.pegasys.pantheon.consensus.ibft.support.TestContext;
import tech.pegasys.pantheon.consensus.ibft.support.TestContextBuilder;
@ -111,11 +111,11 @@ public class ReceivedNewRoundTest {
final Block reproposedBlock = context.createBlockForProposalFromChainHead(1, 15);
final ConsensusRoundIdentifier nextRoundId = new ConsensusRoundIdentifier(1, 1);
final TerminatedRoundArtefacts terminatedRoundArtefacts =
createValidTerminatedRoundArtefacts(context, roundId, initialBlock);
final PreparedRoundArtefacts preparedRoundArtefacts =
createValidPreparedRoundArtefacts(context, roundId, initialBlock);
final List<SignedData<RoundChangePayload>> roundChanges =
peers.createSignedRoundChangePayload(nextRoundId, terminatedRoundArtefacts);
peers.createSignedRoundChangePayload(nextRoundId, preparedRoundArtefacts);
final ValidatorPeer nextProposer = context.roundSpecificPeers(nextRoundId).getProposer();
@ -163,11 +163,11 @@ public class ReceivedNewRoundTest {
final Block reproposedBlock = context.createBlockForProposalFromChainHead(1, 15);
final ConsensusRoundIdentifier nextRoundId = new ConsensusRoundIdentifier(1, 1);
final TerminatedRoundArtefacts terminatedRoundArtefacts =
createValidTerminatedRoundArtefacts(context, roundId, initialBlock);
final PreparedRoundArtefacts preparedRoundArtefacts =
createValidPreparedRoundArtefacts(context, roundId, initialBlock);
final List<SignedData<RoundChangePayload>> roundChanges =
peers.createSignedRoundChangePayload(nextRoundId, terminatedRoundArtefacts);
peers.createSignedRoundChangePayload(nextRoundId, preparedRoundArtefacts);
final RoundSpecificPeers nextRoles = context.roundSpecificPeers(nextRoundId);
final ValidatorPeer nextProposer = nextRoles.getProposer();

@ -14,7 +14,7 @@ package tech.pegasys.pantheon.consensus.ibft.tests;
import static java.util.Collections.emptyList;
import static java.util.Optional.empty;
import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createValidTerminatedRoundArtefacts;
import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createValidPreparedRoundArtefacts;
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.IbftHelpers;
@ -27,7 +27,7 @@ import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangeCertificate;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.statemachine.TerminatedRoundArtefacts;
import tech.pegasys.pantheon.consensus.ibft.statemachine.PreparedRoundArtefacts;
import tech.pegasys.pantheon.consensus.ibft.support.RoundSpecificPeers;
import tech.pegasys.pantheon.consensus.ibft.support.TestContext;
import tech.pegasys.pantheon.consensus.ibft.support.TestContextBuilder;
@ -130,7 +130,7 @@ public class RoundChangeTest {
localNodeMessageFactory.createRoundChange(
targetRound,
Optional.of(
new TerminatedRoundArtefacts(
new PreparedRoundArtefacts(
proposal, Lists.newArrayList(localPrepareMessage, p1, p2))));
context.getController().handleRoundExpiry(new RoundExpiry(roundId));
@ -169,14 +169,14 @@ public class RoundChangeTest {
public void newRoundMessageContainsBlockOnWhichPeerPrepared() {
final long ARBITRARY_BLOCKTIME = 1500;
final TerminatedRoundArtefacts earlierPrepCert =
createValidTerminatedRoundArtefacts(
final PreparedRoundArtefacts earlierPrepCert =
createValidPreparedRoundArtefacts(
context,
new ConsensusRoundIdentifier(1, 1),
context.createBlockForProposalFromChainHead(1, ARBITRARY_BLOCKTIME / 2));
final TerminatedRoundArtefacts bestPrepCert =
createValidTerminatedRoundArtefacts(
final PreparedRoundArtefacts bestPrepCert =
createValidPreparedRoundArtefacts(
context,
new ConsensusRoundIdentifier(1, 2),
context.createBlockForProposalFromChainHead(2, ARBITRARY_BLOCKTIME));
@ -263,8 +263,8 @@ public class RoundChangeTest {
final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 4);
final TerminatedRoundArtefacts prepCert =
createValidTerminatedRoundArtefacts(
final PreparedRoundArtefacts prepCert =
createValidPreparedRoundArtefacts(
context,
new ConsensusRoundIdentifier(1, 2),
context.createBlockForProposalFromChainHead(2, ARBITRARY_BLOCKTIME));
@ -329,14 +329,14 @@ public class RoundChangeTest {
final RoundChange rc3 = peers.getNonProposing(2).injectRoundChange(targetRound, empty());
// create illegal RoundChangeMessage
final TerminatedRoundArtefacts illegalTerminatedRoundArtefacts =
new TerminatedRoundArtefacts(
final PreparedRoundArtefacts illegalPreparedRoundArtefacts =
new PreparedRoundArtefacts(
peers.getNonProposing(0).getMessageFactory().createProposal(roundId, blockToPropose),
emptyList());
peers
.getNonProposing(2)
.injectRoundChange(targetRound, Optional.of(illegalTerminatedRoundArtefacts));
.injectRoundChange(targetRound, Optional.of(illegalPreparedRoundArtefacts));
// Ensure no NewRound message is sent.
peers.verifyNoMessagesReceived();

@ -27,7 +27,7 @@ import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
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.statemachine.TerminatedRoundArtefacts;
import tech.pegasys.pantheon.consensus.ibft.statemachine.PreparedRoundArtefacts;
import tech.pegasys.pantheon.crypto.SECP256K1.Signature;
import tech.pegasys.pantheon.ethereum.core.Block;
import tech.pegasys.pantheon.ethereum.core.Hash;
@ -74,10 +74,10 @@ public class IbftMessageTransmitter {
public void multicastRoundChange(
final ConsensusRoundIdentifier roundIdentifier,
final Optional<TerminatedRoundArtefacts> terminatedRoundArtefacts) {
final Optional<PreparedRoundArtefacts> preparedRoundArtefacts) {
final RoundChange data =
messageFactory.createRoundChange(roundIdentifier, terminatedRoundArtefacts);
messageFactory.createRoundChange(roundIdentifier, preparedRoundArtefacts);
final RoundChangeMessageData message = RoundChangeMessageData.create(data);

@ -18,7 +18,7 @@ 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.statemachine.TerminatedRoundArtefacts;
import tech.pegasys.pantheon.consensus.ibft.statemachine.PreparedRoundArtefacts;
import tech.pegasys.pantheon.crypto.SECP256K1;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.crypto.SECP256K1.Signature;
@ -64,12 +64,12 @@ public class MessageFactory {
public RoundChange createRoundChange(
final ConsensusRoundIdentifier roundIdentifier,
final Optional<TerminatedRoundArtefacts> terminatedRoundArtefacts) {
final Optional<PreparedRoundArtefacts> preparedRoundArtefacts) {
final RoundChangePayload payload =
new RoundChangePayload(
roundIdentifier,
terminatedRoundArtefacts.map(TerminatedRoundArtefacts::getPreparedCertificate));
preparedRoundArtefacts.map(PreparedRoundArtefacts::getPreparedCertificate));
return new RoundChange(createSignedMessage(payload));
}

@ -69,7 +69,7 @@ public class IbftBlockHeightManager implements BlockHeightManager {
private final Function<ConsensusRoundIdentifier, RoundState> roundStateCreator;
private final IbftFinalState finalState;
private Optional<TerminatedRoundArtefacts> latesteTerminatedRoundArtefacts = Optional.empty();
private Optional<PreparedRoundArtefacts> latestPreparedRoundArtefacts = Optional.empty();
private IbftRound currentRound;
@ -133,20 +133,20 @@ public class IbftBlockHeightManager implements BlockHeightManager {
LOG.info(
"Round has expired, creating PreparedCertificate and notifying peers. round={}",
currentRound.getRoundIdentifier());
final Optional<TerminatedRoundArtefacts> terminatedRoundArtefats =
currentRound.constructTerminatedRoundArtefacts();
final Optional<PreparedRoundArtefacts> preparedRoundArtefacts =
currentRound.constructPreparedRoundArtefacts();
if (terminatedRoundArtefats.isPresent()) {
latesteTerminatedRoundArtefacts = terminatedRoundArtefats;
if (preparedRoundArtefacts.isPresent()) {
latestPreparedRoundArtefacts = preparedRoundArtefacts;
}
startNewRound(currentRound.getRoundIdentifier().getRoundNumber() + 1);
final RoundChange localRoundChange =
messageFactory.createRoundChange(
currentRound.getRoundIdentifier(), latesteTerminatedRoundArtefacts);
currentRound.getRoundIdentifier(), latestPreparedRoundArtefacts);
transmitter.multicastRoundChange(
currentRound.getRoundIdentifier(), latesteTerminatedRoundArtefacts);
currentRound.getRoundIdentifier(), latestPreparedRoundArtefacts);
// Its possible the locally created RoundChange triggers the transmission of a NewRound
// message - so it must be handled accordingly.

@ -165,8 +165,8 @@ public class IbftRound {
peerIsCommitted(msg);
}
public Optional<TerminatedRoundArtefacts> constructTerminatedRoundArtefacts() {
return roundState.constructTerminatedRoundArtefacts();
public Optional<PreparedRoundArtefacts> constructPreparedRoundArtefacts() {
return roundState.constructPreparedRoundArtefacts();
}
private boolean updateStateWithProposedBlock(final Proposal msg) {

@ -20,12 +20,12 @@ import tech.pegasys.pantheon.ethereum.core.Block;
import java.util.Collection;
import java.util.stream.Collectors;
public class TerminatedRoundArtefacts {
public class PreparedRoundArtefacts {
private Proposal proposal;
private Collection<Prepare> prepares;
public TerminatedRoundArtefacts(final Proposal proposal, final Collection<Prepare> prepares) {
public PreparedRoundArtefacts(final Proposal proposal, final Collection<Prepare> prepares) {
this.proposal = proposal;
this.prepares = prepares;
}

@ -127,9 +127,9 @@ public class RoundState {
.collect(Collectors.toList());
}
public Optional<TerminatedRoundArtefacts> constructTerminatedRoundArtefacts() {
public Optional<PreparedRoundArtefacts> constructPreparedRoundArtefacts() {
if (isPrepared()) {
return Optional.of(new TerminatedRoundArtefacts(proposalMessage.get(), prepareMessages));
return Optional.of(new PreparedRoundArtefacts(proposalMessage.get(), prepareMessages));
}
return Optional.empty();
}

@ -20,7 +20,7 @@ import static tech.pegasys.pantheon.consensus.ibft.IbftHelpers.calculateRequired
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.statemachine.TerminatedRoundArtefacts;
import tech.pegasys.pantheon.consensus.ibft.statemachine.PreparedRoundArtefacts;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.core.Block;
import tech.pegasys.pantheon.ethereum.core.Hash;
@ -93,9 +93,9 @@ public class IbftHelpersTest {
final Proposal differentProposal =
proposerMessageFactory.createProposal(preparedRound, proposedBlock);
final Optional<TerminatedRoundArtefacts> latterTerminatedRoundArtefacts =
final Optional<PreparedRoundArtefacts> latterPreparedRoundArtefacts =
Optional.of(
new TerminatedRoundArtefacts(
new PreparedRoundArtefacts(
differentProposal,
Lists.newArrayList(
proposerMessageFactory.createPrepare(roundIdentifier, proposedBlock.getHash()),
@ -108,9 +108,9 @@ public class IbftHelpersTest {
TestHelpers.createFrom(roundIdentifier, 0, -2);
final Proposal earlierProposal =
proposerMessageFactory.createProposal(earlierPreparedRound, proposedBlock);
final Optional<TerminatedRoundArtefacts> earlierTerminatedRoundArtefacts =
final Optional<PreparedRoundArtefacts> earlierPreparedRoundArtefacts =
Optional.of(
new TerminatedRoundArtefacts(
new PreparedRoundArtefacts(
earlierProposal,
Lists.newArrayList(
proposerMessageFactory.createPrepare(
@ -122,14 +122,14 @@ public class IbftHelpersTest {
IbftHelpers.findLatestPreparedCertificate(
Lists.newArrayList(
proposerMessageFactory
.createRoundChange(roundIdentifier, earlierTerminatedRoundArtefacts)
.createRoundChange(roundIdentifier, earlierPreparedRoundArtefacts)
.getSignedPayload(),
proposerMessageFactory
.createRoundChange(roundIdentifier, latterTerminatedRoundArtefacts)
.createRoundChange(roundIdentifier, latterPreparedRoundArtefacts)
.getSignedPayload()));
assertThat(newestCert.get())
.isEqualTo(latterTerminatedRoundArtefacts.get().getPreparedCertificate());
.isEqualTo(latterPreparedRoundArtefacts.get().getPreparedCertificate());
}
@Test

@ -92,7 +92,7 @@ public class IbftBlockHeightManagerTest {
@Mock private RoundTimer roundTimer;
@Mock private NewRoundMessageValidator newRoundPayloadValidator;
@Captor private ArgumentCaptor<Optional<TerminatedRoundArtefacts>> terminatedRoundArtefactsCaptor;
@Captor private ArgumentCaptor<Optional<PreparedRoundArtefacts>> preparedRoundArtefactsCaptor;
private final List<KeyPair> validatorKeys = Lists.newArrayList();
private final List<Address> validators = Lists.newArrayList();
@ -356,9 +356,8 @@ public class IbftBlockHeightManagerTest {
final ConsensusRoundIdentifier nextRound = createFrom(roundIdentifier, 0, +1);
verify(messageTransmitter, times(1))
.multicastRoundChange(eq(nextRound), terminatedRoundArtefactsCaptor.capture());
final Optional<TerminatedRoundArtefacts> preparedCert =
terminatedRoundArtefactsCaptor.getValue();
.multicastRoundChange(eq(nextRound), preparedRoundArtefactsCaptor.capture());
final Optional<PreparedRoundArtefacts> preparedCert = preparedRoundArtefactsCaptor.getValue();
assertThat(preparedCert).isNotEmpty();

@ -294,7 +294,7 @@ public class IbftRoundTest {
messageFactory.createRoundChange(
roundIdentifier,
Optional.of(
new TerminatedRoundArtefacts(
new PreparedRoundArtefacts(
messageFactory.createProposal(priorRoundChange, proposedBlock),
emptyList())))));

@ -152,10 +152,10 @@ public class RoundChangeManagerTest {
})
.collect(Collectors.toList());
final TerminatedRoundArtefacts terminatedRoundArtects =
new TerminatedRoundArtefacts(proposal, preparePayloads);
final PreparedRoundArtefacts preparedRoundArtefacts =
new PreparedRoundArtefacts(proposal, preparePayloads);
return messageFactory.createRoundChange(round, Optional.of(terminatedRoundArtects));
return messageFactory.createRoundChange(round, Optional.of(preparedRoundArtefacts));
}
@Test

@ -71,7 +71,7 @@ public class RoundStateTest {
assertThat(roundState.isPrepared()).isFalse();
assertThat(roundState.isCommitted()).isFalse();
assertThat(roundState.constructTerminatedRoundArtefacts()).isEmpty();
assertThat(roundState.constructPreparedRoundArtefacts()).isEmpty();
}
@Test
@ -85,7 +85,7 @@ public class RoundStateTest {
assertThat(roundState.setProposedBlock(proposal)).isFalse();
assertThat(roundState.isPrepared()).isFalse();
assertThat(roundState.isCommitted()).isFalse();
assertThat(roundState.constructTerminatedRoundArtefacts()).isEmpty();
assertThat(roundState.constructPreparedRoundArtefacts()).isEmpty();
}
@Test
@ -99,10 +99,10 @@ public class RoundStateTest {
assertThat(roundState.setProposedBlock(proposal)).isTrue();
assertThat(roundState.isPrepared()).isTrue();
assertThat(roundState.isCommitted()).isFalse();
assertThat(roundState.constructTerminatedRoundArtefacts()).isNotEmpty();
assertThat(roundState.constructPreparedRoundArtefacts()).isNotEmpty();
assertThat(
roundState
.constructTerminatedRoundArtefacts()
.constructPreparedRoundArtefacts()
.get()
.getPreparedCertificate()
.getProposalPayload())
@ -134,7 +134,7 @@ public class RoundStateTest {
roundState.addCommitMessage(commit);
assertThat(roundState.isPrepared()).isTrue();
assertThat(roundState.isCommitted()).isTrue();
assertThat(roundState.constructTerminatedRoundArtefacts()).isNotEmpty();
assertThat(roundState.constructPreparedRoundArtefacts()).isNotEmpty();
}
@Test
@ -153,19 +153,19 @@ public class RoundStateTest {
roundState.addPrepareMessage(firstPrepare);
assertThat(roundState.isPrepared()).isFalse();
assertThat(roundState.isCommitted()).isFalse();
assertThat(roundState.constructTerminatedRoundArtefacts()).isEmpty();
assertThat(roundState.constructPreparedRoundArtefacts()).isEmpty();
roundState.addPrepareMessage(secondPrepare);
assertThat(roundState.isPrepared()).isFalse();
assertThat(roundState.isCommitted()).isFalse();
assertThat(roundState.constructTerminatedRoundArtefacts()).isEmpty();
assertThat(roundState.constructPreparedRoundArtefacts()).isEmpty();
final Proposal proposal =
validatorMessageFactories.get(0).createProposal(roundIdentifier, block);
assertThat(roundState.setProposedBlock(proposal)).isTrue();
assertThat(roundState.isPrepared()).isTrue();
assertThat(roundState.isCommitted()).isFalse();
assertThat(roundState.constructTerminatedRoundArtefacts()).isNotEmpty();
assertThat(roundState.constructPreparedRoundArtefacts()).isNotEmpty();
}
@Test
@ -194,7 +194,7 @@ public class RoundStateTest {
assertThat(roundState.setProposedBlock(proposal)).isTrue();
assertThat(roundState.isPrepared()).isFalse();
assertThat(roundState.isCommitted()).isFalse();
assertThat(roundState.constructTerminatedRoundArtefacts()).isEmpty();
assertThat(roundState.constructPreparedRoundArtefacts()).isEmpty();
}
@Test

@ -26,7 +26,7 @@ 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.RoundChangeCertificate;
import tech.pegasys.pantheon.consensus.ibft.statemachine.TerminatedRoundArtefacts;
import tech.pegasys.pantheon.consensus.ibft.statemachine.PreparedRoundArtefacts;
import tech.pegasys.pantheon.consensus.ibft.validation.RoundChangePayloadValidator.MessageValidatorForHeightFactory;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.core.Address;
@ -163,8 +163,8 @@ public class NewRoundSignedDataValidatorTest {
final Block prevProposedBlock =
TestHelpers.createProposalBlock(validators.subList(0, 1), roundIdentifier.getRoundNumber());
final TerminatedRoundArtefacts mismatchedRoundArtefacts =
new TerminatedRoundArtefacts(
final PreparedRoundArtefacts mismatchedRoundArtefacts =
new PreparedRoundArtefacts(
proposerMessageFactory.createProposal(preparedRound, prevProposedBlock),
singletonList(
validatorMessageFactory.createPrepare(preparedRound, prevProposedBlock.getHash())));
@ -207,7 +207,7 @@ public class NewRoundSignedDataValidatorTest {
proposerMessageFactory.createRoundChange(
roundIdentifier,
Optional.of(
new TerminatedRoundArtefacts(
new PreparedRoundArtefacts(
proposerMessageFactory.createProposal(prevRound, proposedBlock),
Lists.newArrayList(
validatorMessageFactory.createPrepare(
@ -230,9 +230,9 @@ public class NewRoundSignedDataValidatorTest {
roundIdentifier.getSequenceNumber(), roundIdentifier.getRoundNumber() - 1);
final Proposal latterProposal =
proposerMessageFactory.createProposal(latterPrepareRound, proposedBlock);
final Optional<TerminatedRoundArtefacts> preparedCert =
final Optional<PreparedRoundArtefacts> preparedCert =
Optional.of(
new TerminatedRoundArtefacts(
new PreparedRoundArtefacts(
latterProposal,
Lists.newArrayList(
validatorMessageFactory.createPrepare(
@ -247,9 +247,9 @@ public class NewRoundSignedDataValidatorTest {
roundIdentifier.getSequenceNumber(), roundIdentifier.getRoundNumber() - 2);
final Proposal earlierProposal =
proposerMessageFactory.createProposal(earlierPreparedRound, earlierBlock);
final Optional<TerminatedRoundArtefacts> earlierPreparedCert =
final Optional<PreparedRoundArtefacts> earlierPreparedCert =
Optional.of(
new TerminatedRoundArtefacts(
new PreparedRoundArtefacts(
earlierProposal,
Lists.newArrayList(
validatorMessageFactory.createPrepare(

@ -25,7 +25,7 @@ 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.PreparedCertificate;
import tech.pegasys.pantheon.consensus.ibft.statemachine.TerminatedRoundArtefacts;
import tech.pegasys.pantheon.consensus.ibft.statemachine.PreparedRoundArtefacts;
import tech.pegasys.pantheon.consensus.ibft.validation.RoundChangePayloadValidator.MessageValidatorForHeightFactory;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.ethereum.core.Address;
@ -95,16 +95,14 @@ public class RoundChangeSignedDataValidatorTest {
@Test
public void roundChangeContainingInvalidProposalFails() {
final TerminatedRoundArtefacts terminatedRoundArtefacts =
new TerminatedRoundArtefacts(
final PreparedRoundArtefacts preparedRoundArtefacts =
new PreparedRoundArtefacts(
proposerMessageFactory.createProposal(currentRound, block), Collections.emptyList());
final PreparedCertificate prepareCertificate =
terminatedRoundArtefacts.getPreparedCertificate();
final PreparedCertificate prepareCertificate = preparedRoundArtefacts.getPreparedCertificate();
final RoundChange msg =
proposerMessageFactory.createRoundChange(
targetRound, Optional.of(terminatedRoundArtefacts));
proposerMessageFactory.createRoundChange(targetRound, Optional.of(preparedRoundArtefacts));
when(basicValidator.addSignedProposalPayload(any())).thenReturn(false);
@ -119,13 +117,12 @@ public class RoundChangeSignedDataValidatorTest {
@Test
public void roundChangeContainingValidProposalButNoPrepareMessagesFails() {
final TerminatedRoundArtefacts terminatedRoundArtefacts =
new TerminatedRoundArtefacts(
final PreparedRoundArtefacts preparedRoundArtefacts =
new PreparedRoundArtefacts(
proposerMessageFactory.createProposal(currentRound, block), Collections.emptyList());
final RoundChange msg =
proposerMessageFactory.createRoundChange(
targetRound, Optional.of(terminatedRoundArtefacts));
proposerMessageFactory.createRoundChange(targetRound, Optional.of(preparedRoundArtefacts));
when(basicValidator.addSignedProposalPayload(any())).thenReturn(true);
assertThat(validator.validateRoundChange(msg.getSignedPayload())).isFalse();
@ -134,8 +131,8 @@ public class RoundChangeSignedDataValidatorTest {
@Test
public void roundChangeInvalidPrepareMessageFromProposerFails() {
final Prepare prepareMsg = validatorMessageFactory.createPrepare(currentRound, block.getHash());
final TerminatedRoundArtefacts terminatedRoundArtefacts =
new TerminatedRoundArtefacts(
final PreparedRoundArtefacts preparedRoundArtefacts =
new PreparedRoundArtefacts(
proposerMessageFactory.createProposal(currentRound, block),
Lists.newArrayList(prepareMsg));
@ -143,8 +140,7 @@ public class RoundChangeSignedDataValidatorTest {
when(basicValidator.validatePrepareMessage(any())).thenReturn(false);
final RoundChange msg =
proposerMessageFactory.createRoundChange(
targetRound, Optional.of(terminatedRoundArtefacts));
proposerMessageFactory.createRoundChange(targetRound, Optional.of(preparedRoundArtefacts));
assertThat(validator.validateRoundChange(msg.getSignedPayload())).isFalse();
@ -171,14 +167,13 @@ public class RoundChangeSignedDataValidatorTest {
currentRound.getSequenceNumber(), currentRound.getRoundNumber() + 2);
final Prepare prepareMsg = validatorMessageFactory.createPrepare(futureRound, block.getHash());
final TerminatedRoundArtefacts terminatedRoundArtefacts =
new TerminatedRoundArtefacts(
final PreparedRoundArtefacts preparedRoundArtefacts =
new PreparedRoundArtefacts(
proposerMessageFactory.createProposal(futureRound, block),
Lists.newArrayList(prepareMsg));
final RoundChange msg =
proposerMessageFactory.createRoundChange(
targetRound, Optional.of(terminatedRoundArtefacts));
proposerMessageFactory.createRoundChange(targetRound, Optional.of(preparedRoundArtefacts));
assertThat(validator.validateRoundChange(msg.getSignedPayload())).isFalse();
verify(validatorFactory, never()).createAt(any());
@ -189,17 +184,15 @@ public class RoundChangeSignedDataValidatorTest {
@Test
public void roundChangeWithPastProposalForCurrentHeightIsSuccessful() {
final Prepare prepareMsg = validatorMessageFactory.createPrepare(currentRound, block.getHash());
final TerminatedRoundArtefacts terminatedRoundArtefacts =
new TerminatedRoundArtefacts(
final PreparedRoundArtefacts preparedRoundArtefacts =
new PreparedRoundArtefacts(
proposerMessageFactory.createProposal(currentRound, block),
Lists.newArrayList(prepareMsg));
final PreparedCertificate prepareCertificate =
terminatedRoundArtefacts.getPreparedCertificate();
final PreparedCertificate prepareCertificate = preparedRoundArtefacts.getPreparedCertificate();
final RoundChange msg =
proposerMessageFactory.createRoundChange(
targetRound, Optional.of(terminatedRoundArtefacts));
proposerMessageFactory.createRoundChange(targetRound, Optional.of(preparedRoundArtefacts));
when(basicValidator.addSignedProposalPayload(prepareCertificate.getProposalPayload()))
.thenReturn(true);

Loading…
Cancel
Save