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

Added TerminatedRoundArtefacts #756

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
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;
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.crypto.SECP256K1.Signature;
import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.ethereum.p2p.api.MessageData;
Expand Down Expand Up @@ -113,13 +113,14 @@ public List<SignedData<RoundChangePayload>> createSignedRoundChangePayload(
}

public List<SignedData<RoundChangePayload>> createSignedRoundChangePayload(
final ConsensusRoundIdentifier roundId, final PreparedCertificate preparedCertificate) {
final ConsensusRoundIdentifier roundId,
final TerminatedRoundArtefacts terminatedRoundArtefacts) {
return peers
.stream()
.map(
p ->
p.getMessageFactory()
.createSignedRoundChangePayload(roundId, Optional.of(preparedCertificate))
.createSignedRoundChangePayload(roundId, Optional.of(terminatedRoundArtefacts))
.getSignedPayload())
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@
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.Prepare;
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.PreparedCertificate;
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.crypto.SECP256K1;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.crypto.SECP256K1.Signature;
import tech.pegasys.pantheon.ethereum.core.Block;

import java.util.List;
import java.util.stream.Collectors;

public class TestHelpers {

Expand All @@ -49,17 +51,17 @@ public static SignedData<CommitPayload> createSignedCommitPayload(
.getSignedPayload();
}

public static PreparedCertificate createValidPreparedCertificate(
public static TerminatedRoundArtefacts createValidTerminatedRoundArtefacts(
final TestContext context, final ConsensusRoundIdentifier preparedRound, final Block block) {
final RoundSpecificPeers peers = context.roundSpecificPeers(preparedRound);

return new PreparedCertificate(
return new TerminatedRoundArtefacts(
peers.getProposer().getMessageFactory().createSignedProposalPayload(preparedRound, block),
peers
.getProposer()
.getMessageFactory()
.createSignedProposalPayload(preparedRound, block)
.getSignedPayload(),
peers.createSignedPreparePayloadOfNonProposing(preparedRound, block.getHash()));
.createSignedPreparePayloadOfNonProposing(preparedRound, block.getHash())
.stream()
.map(Prepare::new)
.collect(Collectors.toList()));
}

public static NewRound injectEmptyNewRound(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
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.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.statemachine.TerminatedRoundArtefacts;
import tech.pegasys.pantheon.crypto.SECP256K1;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.crypto.SECP256K1.Signature;
Expand Down Expand Up @@ -120,9 +120,10 @@ public NewRound injectNewRound(
}

public RoundChange injectRoundChange(
final ConsensusRoundIdentifier rId, final Optional<PreparedCertificate> preparedCertificate) {
final ConsensusRoundIdentifier rId,
final Optional<TerminatedRoundArtefacts> terminatedRoundArtefacts) {
final RoundChange payload =
messageFactory.createSignedRoundChangePayload(rId, preparedCertificate);
messageFactory.createSignedRoundChangePayload(rId, terminatedRoundArtefacts);
injectMessage(RoundChangeMessageData.create(payload));
return payload;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
*/
package tech.pegasys.pantheon.consensus.ibft.tests;

import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createValidPreparedCertificate;
import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createValidTerminatedRoundArtefacts;

import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
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.PreparedCertificate;
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.support.RoundSpecificPeers;
import tech.pegasys.pantheon.consensus.ibft.support.TestContext;
import tech.pegasys.pantheon.consensus.ibft.support.TestContextBuilder;
Expand Down Expand Up @@ -111,11 +111,11 @@ public void newRoundWithPrepareCertificateResultsInNewRoundStartingWithExpectedB
final Block reproposedBlock = context.createBlockForProposalFromChainHead(1, 15);
final ConsensusRoundIdentifier nextRoundId = new ConsensusRoundIdentifier(1, 1);

final PreparedCertificate preparedCertificate =
createValidPreparedCertificate(context, roundId, initialBlock);
final TerminatedRoundArtefacts terminatedRoundArtefacts =
createValidTerminatedRoundArtefacts(context, roundId, initialBlock);

final List<SignedData<RoundChangePayload>> roundChanges =
peers.createSignedRoundChangePayload(nextRoundId, preparedCertificate);
peers.createSignedRoundChangePayload(nextRoundId, terminatedRoundArtefacts);

final ValidatorPeer nextProposer = context.roundSpecificPeers(nextRoundId).getProposer();

Expand Down Expand Up @@ -164,11 +164,11 @@ public void receiveRoundStateIsNotLostIfASecondNewRoundMessageIsReceivedForCurre
final Block reproposedBlock = context.createBlockForProposalFromChainHead(1, 15);
final ConsensusRoundIdentifier nextRoundId = new ConsensusRoundIdentifier(1, 1);

final PreparedCertificate preparedCertificate =
createValidPreparedCertificate(context, roundId, initialBlock);
final TerminatedRoundArtefacts terminatedRoundArtefacts =
createValidTerminatedRoundArtefacts(context, roundId, initialBlock);

final List<SignedData<RoundChangePayload>> roundChanges =
peers.createSignedRoundChangePayload(nextRoundId, preparedCertificate);
peers.createSignedRoundChangePayload(nextRoundId, terminatedRoundArtefacts);

final RoundSpecificPeers nextRoles = context.roundSpecificPeers(nextRoundId);
final ValidatorPeer nextProposer = nextRoles.getProposer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import static java.util.Collections.emptyList;
import static java.util.Optional.empty;
import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createValidPreparedCertificate;
import static tech.pegasys.pantheon.consensus.ibft.support.TestHelpers.createValidTerminatedRoundArtefacts;

import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.IbftHelpers;
Expand All @@ -24,10 +24,10 @@
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.PreparedCertificate;
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.support.RoundSpecificPeers;
import tech.pegasys.pantheon.consensus.ibft.support.TestContext;
import tech.pegasys.pantheon.consensus.ibft.support.TestContextBuilder;
Expand Down Expand Up @@ -130,12 +130,8 @@ public void roundChangeHasPopulatedCertificateIfQuorumPrepareMessagesAndProposal
localNodeMessageFactory.createSignedRoundChangePayload(
targetRound,
Optional.of(
new PreparedCertificate(
proposal.getSignedPayload(),
Lists.newArrayList(
localPrepareMessage.getSignedPayload(),
p1.getSignedPayload(),
p2.getSignedPayload()))));
new TerminatedRoundArtefacts(
proposal, Lists.newArrayList(localPrepareMessage, p1, p2))));

context.getController().handleRoundExpiry(new RoundExpiry(roundId));
peers.verifyMessagesReceived(expectedTxRoundChange);
Expand Down Expand Up @@ -173,14 +169,14 @@ public void whenSufficientRoundChangeMessagesAreReceivedForNewRoundLocalNodeCrea
public void newRoundMessageContainsBlockOnWhichPeerPrepared() {
final long ARBITRARY_BLOCKTIME = 1500;

final PreparedCertificate earlierPrepCert =
createValidPreparedCertificate(
final TerminatedRoundArtefacts earlierPrepCert =
createValidTerminatedRoundArtefacts(
context,
new ConsensusRoundIdentifier(1, 1),
context.createBlockForProposalFromChainHead(1, ARBITRARY_BLOCKTIME / 2));

final PreparedCertificate bestPrepCert =
createValidPreparedCertificate(
final TerminatedRoundArtefacts bestPrepCert =
createValidTerminatedRoundArtefacts(
context,
new ConsensusRoundIdentifier(1, 2),
context.createBlockForProposalFromChainHead(2, ARBITRARY_BLOCKTIME));
Expand Down Expand Up @@ -267,8 +263,8 @@ public void subsequentRoundChangeMessagesFromPeerDoNotOverwritePriorMessage() {

final ConsensusRoundIdentifier targetRound = new ConsensusRoundIdentifier(1, 4);

final PreparedCertificate prepCert =
createValidPreparedCertificate(
final TerminatedRoundArtefacts prepCert =
createValidTerminatedRoundArtefacts(
context,
new ConsensusRoundIdentifier(1, 2),
context.createBlockForProposalFromChainHead(2, ARBITRARY_BLOCKTIME));
Expand Down Expand Up @@ -333,18 +329,17 @@ public void illegallyConstructedRoundChangeMessageIsDiscarded() {
final RoundChange rc3 = peers.getNonProposing(2).injectRoundChange(targetRound, empty());

// create illegal RoundChangeMessage
final PreparedCertificate illegalPreparedCertificate =
new PreparedCertificate(
final TerminatedRoundArtefacts illegalTerminatedRoundArtefacts =
new TerminatedRoundArtefacts(
peers
.getNonProposing(0)
.getMessageFactory()
.createSignedProposalPayload(roundId, blockToPropose)
.getSignedPayload(),
.createSignedProposalPayload(roundId, blockToPropose),
emptyList());

peers
.getNonProposing(2)
.injectRoundChange(targetRound, Optional.of(illegalPreparedCertificate));
.injectRoundChange(targetRound, Optional.of(illegalTerminatedRoundArtefacts));

// Ensure no NewRound message is sent.
peers.verifyNoMessagesReceived();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@

import tech.pegasys.pantheon.consensus.ibft.payload.ProposalPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.ethereum.core.Block;

public class Proposal extends IbftMessage<ProposalPayload> {

public Proposal(final SignedData<ProposalPayload> payload) {
super(payload);
}

public Block getBlock() {
return getSignedPayload().getPayload().getBlock();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
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.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.statemachine.TerminatedRoundArtefacts;
import tech.pegasys.pantheon.crypto.SECP256K1.Signature;
import tech.pegasys.pantheon.ethereum.core.Block;
import tech.pegasys.pantheon.ethereum.core.Hash;
Expand Down Expand Up @@ -75,10 +75,10 @@ public void multicastCommit(

public void multicastRoundChange(
final ConsensusRoundIdentifier roundIdentifier,
final Optional<PreparedCertificate> preparedCertificate) {
final Optional<TerminatedRoundArtefacts> terminatedRoundArtefacts) {

final RoundChange data =
messageFactory.createSignedRoundChangePayload(roundIdentifier, preparedCertificate);
messageFactory.createSignedRoundChangePayload(roundIdentifier, terminatedRoundArtefacts);

final RoundChangeMessageData message = RoundChangeMessageData.create(data);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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.crypto.SECP256K1;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.crypto.SECP256K1.Signature;
Expand Down Expand Up @@ -64,9 +65,12 @@ public Commit createSignedCommitPayload(

public RoundChange createSignedRoundChangePayload(
final ConsensusRoundIdentifier roundIdentifier,
final Optional<PreparedCertificate> preparedCertificate) {
final Optional<TerminatedRoundArtefacts> terminatedRoundArtefacts) {

final RoundChangePayload payload = new RoundChangePayload(roundIdentifier, preparedCertificate);
final RoundChangePayload payload =
new RoundChangePayload(
roundIdentifier,
terminatedRoundArtefacts.map(TerminatedRoundArtefacts::getPreparedCertificate));

return new RoundChange(createSignedMessage(payload));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import tech.pegasys.pantheon.consensus.ibft.network.IbftMessageTransmitter;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.Payload;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangeCertificate;
import tech.pegasys.pantheon.consensus.ibft.validation.MessageValidatorFactory;
import tech.pegasys.pantheon.consensus.ibft.validation.NewRoundMessageValidator;
Expand Down Expand Up @@ -70,7 +69,7 @@ public class IbftBlockHeightManager implements BlockHeightManager {
private final Function<ConsensusRoundIdentifier, RoundState> roundStateCreator;
private final IbftFinalState finalState;

private Optional<PreparedCertificate> latestPreparedCertificate = Optional.empty();
private Optional<TerminatedRoundArtefacts> latesteTerminatedRoundArtefacts = Optional.empty();

private IbftRound currentRound;

Expand Down Expand Up @@ -134,19 +133,20 @@ public void roundExpired(final RoundExpiry expire) {
LOG.info(
"Round has expired, creating PreparedCertificate and notifying peers. round={}",
currentRound.getRoundIdentifier());
final Optional<PreparedCertificate> preparedCertificate =
currentRound.createPrepareCertificate();
final Optional<TerminatedRoundArtefacts> terminatedRoundArtefats =
currentRound.constructTerminatedRoundArtefacts();

if (preparedCertificate.isPresent()) {
latestPreparedCertificate = preparedCertificate;
if (terminatedRoundArtefats.isPresent()) {
latesteTerminatedRoundArtefacts = terminatedRoundArtefats;
}

startNewRound(currentRound.getRoundIdentifier().getRoundNumber() + 1);

final RoundChange localRoundChange =
messageFactory.createSignedRoundChangePayload(
currentRound.getRoundIdentifier(), latestPreparedCertificate);
transmitter.multicastRoundChange(currentRound.getRoundIdentifier(), latestPreparedCertificate);
currentRound.getRoundIdentifier(), latesteTerminatedRoundArtefacts);
transmitter.multicastRoundChange(
currentRound.getRoundIdentifier(), latesteTerminatedRoundArtefacts);

// Its possible the locally created RoundChange triggers the transmission of a NewRound
// message - so it must be handled accordingly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ public void handleCommitMessage(final Commit msg) {
peerIsCommitted(msg);
}

public Optional<PreparedCertificate> createPrepareCertificate() {
return roundState.constructPreparedCertificate();
public Optional<TerminatedRoundArtefacts> constructTerminatedRoundArtefacts() {
return roundState.constructTerminatedRoundArtefacts();
}

private boolean updateStateWithProposedBlock(final Proposal msg) {
Expand Down
Loading