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

Renamed IBFT message classes #333

Merged
merged 3 commits into from
Dec 6, 2018
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 @@ -12,36 +12,36 @@
*/
package tech.pegasys.pantheon.consensus.ibft;

import tech.pegasys.pantheon.consensus.ibft.ibftmessage.IbftCommitMessage;
import tech.pegasys.pantheon.consensus.ibft.ibftmessage.IbftNewRoundMessage;
import tech.pegasys.pantheon.consensus.ibft.ibftmessage.IbftPrePrepareMessage;
import tech.pegasys.pantheon.consensus.ibft.ibftmessage.IbftPrepareMessage;
import tech.pegasys.pantheon.consensus.ibft.ibftmessage.IbftRoundChangeMessage;
import tech.pegasys.pantheon.consensus.ibft.ibftmessage.CommitMessage;
import tech.pegasys.pantheon.consensus.ibft.ibftmessage.IbftV2;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.IbftSignedMessageData;
import tech.pegasys.pantheon.consensus.ibft.ibftmessage.NewRoundMessage;
import tech.pegasys.pantheon.consensus.ibft.ibftmessage.PrepareMessage;
import tech.pegasys.pantheon.consensus.ibft.ibftmessage.ProposalMessage;
import tech.pegasys.pantheon.consensus.ibft.ibftmessage.RoundChangeMessage;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.SignedData;
import tech.pegasys.pantheon.ethereum.p2p.api.Message;
import tech.pegasys.pantheon.ethereum.p2p.api.MessageData;

public class IbftMessages {

public static IbftSignedMessageData<?> fromMessage(final Message message) {
public static SignedData<?> fromMessage(final Message message) {
final MessageData messageData = message.getData();

switch (messageData.getCode()) {
case IbftV2.PRE_PREPARE:
return IbftPrePrepareMessage.fromMessage(messageData).decode();
case IbftV2.PROPOSAL:
return ProposalMessage.fromMessage(messageData).decode();

case IbftV2.PREPARE:
return IbftPrepareMessage.fromMessage(messageData).decode();
return PrepareMessage.fromMessage(messageData).decode();

case IbftV2.COMMIT:
return IbftCommitMessage.fromMessage(messageData).decode();
return CommitMessage.fromMessage(messageData).decode();

case IbftV2.ROUND_CHANGE:
return IbftRoundChangeMessage.fromMessage(messageData).decode();
return RoundChangeMessage.fromMessage(messageData).decode();

case IbftV2.NEW_ROUND:
return IbftNewRoundMessage.fromMessage(messageData).decode();
return NewRoundMessage.fromMessage(messageData).decode();

default:
throw new IllegalArgumentException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

/**
* Responsible for determining which member of the validator pool should propose the next block
* (i.e. send the Preprepare message).
* (i.e. send the Proposal message).
*
* <p>It does this by extracting the previous block's proposer from the ProposerSeal (stored in the
* Blocks ExtraData) then iterating through the validator list (stored in {@link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
package tech.pegasys.pantheon.consensus.ibft.ibftmessage;

import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.IbftSignedMessageData;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.SignedData;
import tech.pegasys.pantheon.ethereum.p2p.api.MessageData;
import tech.pegasys.pantheon.ethereum.p2p.wire.AbstractMessageData;
import tech.pegasys.pantheon.util.bytes.BytesValue;
Expand All @@ -24,7 +24,7 @@ protected AbstractIbftMessage(final BytesValue data) {
super(data);
}

public abstract IbftSignedMessageData<?> decode();
public abstract SignedData<?> decode();

protected static <T extends AbstractIbftMessage> T fromMessage(
final MessageData message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,32 @@
*/
package tech.pegasys.pantheon.consensus.ibft.ibftmessage;

import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.IbftSignedMessageData;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.IbftUnsignedCommitMessageData;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.CommitPayload;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.SignedData;
import tech.pegasys.pantheon.ethereum.p2p.api.MessageData;
import tech.pegasys.pantheon.ethereum.rlp.RLP;
import tech.pegasys.pantheon.util.bytes.BytesValue;

public class IbftCommitMessage extends AbstractIbftMessage {
public class CommitMessage extends AbstractIbftMessage {

private static final int MESSAGE_CODE = IbftV2.COMMIT;

private IbftCommitMessage(final BytesValue data) {
private CommitMessage(final BytesValue data) {
super(data);
}

public static IbftCommitMessage fromMessage(final MessageData message) {
return fromMessage(message, MESSAGE_CODE, IbftCommitMessage.class, IbftCommitMessage::new);
public static CommitMessage fromMessage(final MessageData message) {
return fromMessage(message, MESSAGE_CODE, CommitMessage.class, CommitMessage::new);
}

@Override
public IbftSignedMessageData<IbftUnsignedCommitMessageData> decode() {
return IbftSignedMessageData.readIbftSignedCommitMessageDataFrom(RLP.input(data));
public SignedData<CommitPayload> decode() {
return SignedData.readSignedCommitPayloadFrom(RLP.input(data));
}

public static IbftCommitMessage create(
final IbftSignedMessageData<IbftUnsignedCommitMessageData> ibftPrepareMessageDecoded) {
public static CommitMessage create(final SignedData<CommitPayload> signedPayload) {

return new IbftCommitMessage(ibftPrepareMessageDecoded.encode());
return new CommitMessage(signedPayload.encode());
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

/** Message codes for iBFT v2 messages */
public class IbftV2 {
public static final int PRE_PREPARE = 0;
public static final int PROPOSAL = 0;
public static final int PREPARE = 1;
public static final int COMMIT = 2;
public static final int ROUND_CHANGE = 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,32 @@
*/
package tech.pegasys.pantheon.consensus.ibft.ibftmessage;

import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.IbftSignedMessageData;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.IbftUnsignedNewRoundMessageData;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.NewRoundPayload;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.SignedData;
import tech.pegasys.pantheon.ethereum.p2p.api.MessageData;
import tech.pegasys.pantheon.ethereum.rlp.RLP;
import tech.pegasys.pantheon.util.bytes.BytesValue;

public class IbftNewRoundMessage extends AbstractIbftMessage {
public class NewRoundMessage extends AbstractIbftMessage {

private static final int MESSAGE_CODE = IbftV2.NEW_ROUND;

private IbftNewRoundMessage(final BytesValue data) {
private NewRoundMessage(final BytesValue data) {
super(data);
}

public static IbftNewRoundMessage fromMessage(final MessageData message) {
return fromMessage(message, MESSAGE_CODE, IbftNewRoundMessage.class, IbftNewRoundMessage::new);
public static NewRoundMessage fromMessage(final MessageData message) {
return fromMessage(message, MESSAGE_CODE, NewRoundMessage.class, NewRoundMessage::new);
}

@Override
public IbftSignedMessageData<IbftUnsignedNewRoundMessageData> decode() {
return IbftSignedMessageData.readIbftSignedNewRoundMessageDataFrom(RLP.input(data));
public SignedData<NewRoundPayload> decode() {
return SignedData.readSignedNewRoundPayloadFrom(RLP.input(data));
}

public static IbftNewRoundMessage create(
final IbftSignedMessageData<IbftUnsignedNewRoundMessageData> ibftPrepareMessageDecoded) {
public static NewRoundMessage create(final SignedData<NewRoundPayload> signedPayload) {

return new IbftNewRoundMessage(ibftPrepareMessageDecoded.encode());
return new NewRoundMessage(signedPayload.encode());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,32 @@
*/
package tech.pegasys.pantheon.consensus.ibft.ibftmessage;

import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.IbftSignedMessageData;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.IbftUnsignedPrepareMessageData;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.PreparePayload;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.SignedData;
import tech.pegasys.pantheon.ethereum.p2p.api.MessageData;
import tech.pegasys.pantheon.ethereum.rlp.RLP;
import tech.pegasys.pantheon.util.bytes.BytesValue;

public class IbftPrepareMessage extends AbstractIbftMessage {
public class PrepareMessage extends AbstractIbftMessage {

private static final int MESSAGE_CODE = IbftV2.PREPARE;

private IbftPrepareMessage(final BytesValue data) {
private PrepareMessage(final BytesValue data) {
super(data);
}

public static IbftPrepareMessage fromMessage(final MessageData message) {
return fromMessage(message, MESSAGE_CODE, IbftPrepareMessage.class, IbftPrepareMessage::new);
public static PrepareMessage fromMessage(final MessageData message) {
return fromMessage(message, MESSAGE_CODE, PrepareMessage.class, PrepareMessage::new);
}

@Override
public IbftSignedMessageData<IbftUnsignedPrepareMessageData> decode() {
return IbftSignedMessageData.readIbftSignedPrepareMessageDataFrom(RLP.input(data));
public SignedData<PreparePayload> decode() {
return SignedData.readSignedPreparePayloadFrom(RLP.input(data));
}

public static IbftPrepareMessage create(
final IbftSignedMessageData<IbftUnsignedPrepareMessageData> ibftPrepareMessageDecoded) {
public static PrepareMessage create(final SignedData<PreparePayload> signedPayload) {

return new IbftPrepareMessage(ibftPrepareMessageDecoded.encode());
return new PrepareMessage(signedPayload.encode());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2018 ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package tech.pegasys.pantheon.consensus.ibft.ibftmessage;

import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.ProposalPayload;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.SignedData;
import tech.pegasys.pantheon.ethereum.p2p.api.MessageData;
import tech.pegasys.pantheon.ethereum.rlp.RLP;
import tech.pegasys.pantheon.util.bytes.BytesValue;

public class ProposalMessage extends AbstractIbftMessage {

private static final int MESSAGE_CODE = IbftV2.PROPOSAL;

private ProposalMessage(final BytesValue data) {
super(data);
}

public static ProposalMessage fromMessage(final MessageData message) {
return fromMessage(message, MESSAGE_CODE, ProposalMessage.class, ProposalMessage::new);
}

@Override
public SignedData<ProposalPayload> decode() {
return SignedData.readSignedProposalPayloadFrom(RLP.input(data));
}

public static ProposalMessage create(final SignedData<ProposalPayload> signedPayload) {

return new ProposalMessage(signedPayload.encode());
}

@Override
public int getCode() {
return MESSAGE_CODE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,32 @@
*/
package tech.pegasys.pantheon.consensus.ibft.ibftmessage;

import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.IbftSignedMessageData;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.IbftUnsignedRoundChangeMessageData;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.RoundChangePayload;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.SignedData;
import tech.pegasys.pantheon.ethereum.p2p.api.MessageData;
import tech.pegasys.pantheon.ethereum.rlp.RLP;
import tech.pegasys.pantheon.util.bytes.BytesValue;

public class IbftRoundChangeMessage extends AbstractIbftMessage {
public class RoundChangeMessage extends AbstractIbftMessage {

private static final int MESSAGE_CODE = IbftV2.ROUND_CHANGE;

private IbftRoundChangeMessage(final BytesValue data) {
private RoundChangeMessage(final BytesValue data) {
super(data);
}

public static IbftRoundChangeMessage fromMessage(final MessageData message) {
return fromMessage(
message, MESSAGE_CODE, IbftRoundChangeMessage.class, IbftRoundChangeMessage::new);
public static RoundChangeMessage fromMessage(final MessageData message) {
return fromMessage(message, MESSAGE_CODE, RoundChangeMessage.class, RoundChangeMessage::new);
}

@Override
public IbftSignedMessageData<IbftUnsignedRoundChangeMessageData> decode() {
return IbftSignedMessageData.readIbftSignedRoundChangeMessageDataFrom(RLP.input(data));
public SignedData<RoundChangePayload> decode() {
return SignedData.readSignedRoundChangePayloadFrom(RLP.input(data));
}

public static IbftRoundChangeMessage create(
final IbftSignedMessageData<IbftUnsignedRoundChangeMessageData> ibftPrepareMessageDecoded) {
public static RoundChangeMessage create(final SignedData<RoundChangePayload> signedPayload) {

return new IbftRoundChangeMessage(ibftPrepareMessageDecoded.encode());
return new RoundChangeMessage(signedPayload.encode());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import tech.pegasys.pantheon.ethereum.rlp.RLPOutput;
import tech.pegasys.pantheon.util.bytes.BytesValue;

public abstract class AbstractIbftUnsignedMessageData {
public abstract class AbstractPayload {

public abstract void writeTo(final RLPOutput rlpOutput);

Expand Down
Loading