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

Commit

Permalink
IBFT2.1 crushed
Browse files Browse the repository at this point in the history
  • Loading branch information
tmohay committed Feb 6, 2019
1 parent 17b6847 commit 0bc7691
Show file tree
Hide file tree
Showing 36 changed files with 813 additions and 364 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ public NewRound injectNewRound(
final Proposal proposal) {

final NewRound payload =
messageFactory.createNewRound(rId, roundChangeCertificate, proposal.getSignedPayload());
messageFactory.createNewRound(
rId, roundChangeCertificate, proposal.getSignedPayload(), proposal.getBlock());
injectMessage(NewRoundMessageData.create(payload));
return payload;
}
Expand All @@ -124,7 +125,8 @@ public NewRound injectEmptyNewRound(
final List<SignedData<RoundChangePayload>> roundChangePayloads,
final Block blockToPropose) {

final Proposal proposal = messageFactory.createProposal(targetRoundId, blockToPropose);
final Proposal proposal =
messageFactory.createProposal(targetRoundId, blockToPropose);

return injectNewRound(targetRoundId, new RoundChangeCertificate(roundChangePayloads), proposal);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void messagesForFutureRoundAreNotActionedUntilRoundIsActive() {
// required remotely received Prepares = quorum-2
// required remote received commits = quorum-1

// Inject 1 too few Commit messages (but sufficient Prepare
// Inject 1 too few Commit messages (but sufficient Prepare)
for (int i = 0; i < quorum - 3; i++) {
futurePeers.getNonProposing(i).injectPrepare(futureRoundId, futureBlock.getHash());
}
Expand All @@ -91,10 +91,10 @@ public void messagesForFutureRoundAreNotActionedUntilRoundIsActive() {

// inject a newRound to move to 'futureRoundId', and ensure localnode sends prepare, commit
// and updates blockchain
futurePeers
.getProposer()
.injectEmptyNewRound(
futureRoundId, futurePeers.createSignedRoundChangePayload(futureRoundId), futureBlock);
futurePeers.getProposer().injectEmptyNewRound(
futureRoundId,
futurePeers.createSignedRoundChangePayload(futureRoundId),
futureBlock);

final Prepare expectedPrepare =
localNodeMessageFactory.createPrepare(futureRoundId, futureBlock.getHash());
Expand Down Expand Up @@ -134,10 +134,10 @@ public void priorRoundsCannotBeCompletedAfterReceptionOfNewRound() {

peers.clearReceivedMessages();

futurePeers
.getProposer()
.injectEmptyNewRound(
futureRoundId, futurePeers.createSignedRoundChangePayload(futureRoundId), futureBlock);
futurePeers.getProposer().injectEmptyNewRound(
futureRoundId,
futurePeers.createSignedRoundChangePayload(futureRoundId),
futureBlock);

final Prepare expectedFuturePrepare =
localNodeMessageFactory.createPrepare(futureRoundId, futureBlock.getHash());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ public void messageWithUnknownValidatorIsNotGossiped() {
final MessageFactory unknownMsgFactory = new MessageFactory(unknownKeyPair);
final Proposal unknownProposal = unknownMsgFactory.createProposal(roundId, block);

sender.injectMessage(
ProposalMessageData.create(new Proposal(unknownProposal.getSignedPayload())));
sender.injectMessage(ProposalMessageData.create(unknownProposal));
peers.verifyNoMessagesReceived();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ public void whenSufficientRoundChangeMessagesAreReceivedForNewRoundLocalNodeCrea
rc4.getSignedPayload())),
localNodeMessageFactory
.createProposal(targetRound, locallyProposedBlock)
.getSignedPayload());
.getSignedPayload(),
locallyProposedBlock);

peers.verifyMessagesReceived(expectedNewRound);
}
Expand Down Expand Up @@ -214,7 +215,8 @@ public void newRoundMessageContainsBlockOnWhichPeerPrepared() {
rc4.getSignedPayload())),
localNodeMessageFactory
.createProposal(targetRound, expectedBlockToPropose)
.getSignedPayload());
.getSignedPayload(),
expectedBlockToPropose);

peers.verifyMessagesReceived(expectedNewRound);
}
Expand All @@ -238,7 +240,8 @@ public void cannotRoundChangeToAnEarlierRound() {
new RoundChangeCertificate(roundChangeMessages),
localNodeMessageFactory
.createProposal(futureRound, locallyProposedBlock)
.getSignedPayload());
.getSignedPayload(),
locallyProposedBlock);

peers.verifyMessagesReceived(expectedNewRound);
}
Expand Down Expand Up @@ -292,7 +295,8 @@ public void subsequentRoundChangeMessagesFromPeerDoNotOverwritePriorMessage() {
new RoundChangeCertificate(Lists.newArrayList(roundChangeMessages)),
localNodeMessageFactory
.createProposal(targetRound, expectedBlockToPropose)
.getSignedPayload());
.getSignedPayload(),
expectedBlockToPropose);

peers.verifyMessagesReceived(expectedNewRound);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package tech.pegasys.pantheon.consensus.ibft.messagewrappers;

import tech.pegasys.pantheon.consensus.ibft.IbftBlockHashing;
import tech.pegasys.pantheon.consensus.ibft.payload.NewRoundPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.ProposalPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.RoundChangeCertificate;
Expand All @@ -24,8 +25,11 @@

public class NewRound extends IbftMessage<NewRoundPayload> {

public NewRound(final SignedData<NewRoundPayload> payload) {
private final Block proposedBlock;

public NewRound(final SignedData<NewRoundPayload> payload, final Block proposedBlock) {
super(payload);
this.proposedBlock = proposedBlock;
}

public RoundChangeCertificate getRoundChangeCertificate() {
Expand All @@ -37,14 +41,15 @@ public SignedData<ProposalPayload> getProposalPayload() {
}

public Block getBlock() {
return getProposalPayload().getPayload().getBlock();
return proposedBlock;
}

@Override
public BytesValue encode() {
final BytesValueRLPOutput rlpOut = new BytesValueRLPOutput();
rlpOut.startList();
getSignedPayload().writeTo(rlpOut);
proposedBlock.writeTo(rlpOut);
rlpOut.endList();
return rlpOut.encoded();
}
Expand All @@ -53,7 +58,9 @@ public static NewRound decode(final BytesValue data) {
RLPInput rlpIn = RLP.input(data);
rlpIn.enterList();
final SignedData<NewRoundPayload> payload = SignedData.readSignedNewRoundPayloadFrom(rlpIn);
final Block proposedBlock =
Block.readFrom(rlpIn, IbftBlockHashing::calculateDataHashForCommittedSeal);
rlpIn.leaveList();
return new NewRound(payload);
return new NewRound(payload, proposedBlock);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,39 @@
*/
package tech.pegasys.pantheon.consensus.ibft.messagewrappers;

import tech.pegasys.pantheon.consensus.ibft.IbftBlockHashing;
import tech.pegasys.pantheon.consensus.ibft.payload.ProposalPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.ethereum.core.Block;
import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.ethereum.rlp.BytesValueRLPOutput;
import tech.pegasys.pantheon.ethereum.rlp.RLP;
import tech.pegasys.pantheon.ethereum.rlp.RLPInput;
import tech.pegasys.pantheon.util.bytes.BytesValue;

public class Proposal extends IbftMessage<ProposalPayload> {

public Proposal(final SignedData<ProposalPayload> payload) {
private final Block proposedBlock;

public Proposal(final SignedData<ProposalPayload> payload, final Block proposedBlock) {
super(payload);
this.proposedBlock = proposedBlock;
}

public Block getBlock() {
return getPayload().getBlock();
return proposedBlock;
}

public Hash getDigest() {
return getPayload().getDigest();
}

@Override
public BytesValue encode() {
final BytesValueRLPOutput rlpOut = new BytesValueRLPOutput();
rlpOut.startList();
getSignedPayload().writeTo(rlpOut);
proposedBlock.writeTo(rlpOut);
rlpOut.endList();
return rlpOut.encoded();
}
Expand All @@ -43,7 +53,9 @@ public static Proposal decode(final BytesValue data) {
RLPInput rlpIn = RLP.input(data);
rlpIn.enterList();
final SignedData<ProposalPayload> payload = SignedData.readSignedProposalPayloadFrom(rlpIn);
final Block proposedBlock =
Block.readFrom(rlpIn, IbftBlockHashing::calculateDataHashForCommittedSeal);
rlpIn.leaveList();
return new Proposal(payload);
return new Proposal(payload, proposedBlock);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
*/
package tech.pegasys.pantheon.consensus.ibft.messagewrappers;

import tech.pegasys.pantheon.consensus.ibft.IbftBlockHashing;
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.ethereum.core.Block;
import tech.pegasys.pantheon.ethereum.rlp.BytesValueRLPOutput;
import tech.pegasys.pantheon.ethereum.rlp.RLP;
import tech.pegasys.pantheon.ethereum.rlp.RLPInput;
Expand All @@ -24,8 +26,20 @@

public class RoundChange extends IbftMessage<RoundChangePayload> {

private final Optional<Block> proposedBlock;

public RoundChange(final SignedData<RoundChangePayload> payload, final Block proposedBlock) {
super(payload);
this.proposedBlock = Optional.of(proposedBlock);
}

public RoundChange(final SignedData<RoundChangePayload> payload) {
super(payload);
this.proposedBlock = Optional.empty();
}

public Optional<Block> getProposedBlock() {
return proposedBlock;
}

public Optional<PreparedCertificate> getPreparedCertificate() {
Expand All @@ -37,16 +51,32 @@ public BytesValue encode() {
final BytesValueRLPOutput rlpOut = new BytesValueRLPOutput();
rlpOut.startList();
getSignedPayload().writeTo(rlpOut);
if (proposedBlock.isPresent()) {
proposedBlock.get().writeTo(rlpOut);
} else {
rlpOut.writeNull();
}
rlpOut.endList();
return rlpOut.encoded();
}

public static RoundChange decode(final BytesValue data) {
RLPInput rlpIn = RLP.input(data);
RoundChange result;

final RLPInput rlpIn = RLP.input(data);
rlpIn.enterList();
final SignedData<RoundChangePayload> payload =
SignedData.readSignedRoundChangePayloadFrom(rlpIn);
if (!rlpIn.nextIsNull()) {
result =
new RoundChange(
payload, Block.readFrom(rlpIn, IbftBlockHashing::calculateDataHashForCommittedSeal));
} else {
result = new RoundChange(payload);
rlpIn.skipNext();
}
rlpIn.leaveList();
return new RoundChange(payload);

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ public void multicastRoundChange(
public void multicastNewRound(
final ConsensusRoundIdentifier roundIdentifier,
final RoundChangeCertificate roundChangeCertificate,
final SignedData<ProposalPayload> proposalPayload) {
final SignedData<ProposalPayload> proposalPayload,
final Block block) {

final NewRound signedPayload =
messageFactory.createNewRound(roundIdentifier, roundChangeCertificate, proposalPayload);
messageFactory.createNewRound(
roundIdentifier, roundChangeCertificate, proposalPayload, block);

final NewRoundMessageData message = NewRoundMessageData.create(signedPayload);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public MessageFactory(final KeyPair validatorKeyPair) {
public Proposal createProposal(
final ConsensusRoundIdentifier roundIdentifier, final Block block) {

final ProposalPayload payload = new ProposalPayload(roundIdentifier, block);
final ProposalPayload payload = new ProposalPayload(roundIdentifier, block.getHash());

return new Proposal(createSignedMessage(payload));
return new Proposal(createSignedMessage(payload), block);
}

public Prepare createPrepare(final ConsensusRoundIdentifier roundIdentifier, final Hash digest) {
Expand All @@ -66,23 +66,27 @@ public RoundChange createRoundChange(
final ConsensusRoundIdentifier roundIdentifier,
final Optional<PreparedRoundArtifacts> preparedRoundArtifacts) {

final RoundChangePayload payload =
new RoundChangePayload(
roundIdentifier,
preparedRoundArtifacts.map(PreparedRoundArtifacts::getPreparedCertificate));
if (preparedRoundArtifacts.isPresent()) {
final RoundChangePayload payload =
new RoundChangePayload(
roundIdentifier, Optional.of(preparedRoundArtifacts.get().getPreparedCertificate()));
return new RoundChange(createSignedMessage(payload), preparedRoundArtifacts.get().getBlock());
}

final RoundChangePayload payload = new RoundChangePayload(roundIdentifier, Optional.empty());
return new RoundChange(createSignedMessage(payload));
}

public NewRound createNewRound(
final ConsensusRoundIdentifier roundIdentifier,
final RoundChangeCertificate roundChangeCertificate,
final SignedData<ProposalPayload> proposalPayload) {
final SignedData<ProposalPayload> proposalPayload,
final Block block) {

final NewRoundPayload payload =
new NewRoundPayload(roundIdentifier, roundChangeCertificate, proposalPayload);

return new NewRound(createSignedMessage(payload));
return new NewRound(createSignedMessage(payload), block);
}

private <M extends Payload> SignedData<M> createSignedMessage(final M payload) {
Expand Down
Loading

0 comments on commit 0bc7691

Please sign in to comment.