Remove Ibft's InRoundPayload interface (#423)

An abstraction existed which allowed for the differentiation of IBFT
messages which were used 'in-round' (Proposal, Prepare, Commit) and
those that were inter-round (RoundChange, NewRound).

This abstraction has not proven useful now that actual capability has
been developed, and as such is being removed.
tmohay 6 years ago committed by GitHub
parent 5bdf698b72
commit 698e7823d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/ibftmessagedata/CommitPayload.java
  2. 19
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/ibftmessagedata/InRoundPayload.java
  3. 3
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/ibftmessagedata/NewRoundPayload.java
  4. 3
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/ibftmessagedata/Payload.java
  5. 2
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/ibftmessagedata/PreparePayload.java
  6. 2
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/ibftmessagedata/ProposalPayload.java
  7. 3
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/ibftmessagedata/RoundChangePayload.java
  8. 2
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/RoundChangeManager.java
  9. 4
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/validation/MessageValidator.java
  10. 8
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/validation/NewRoundMessageValidator.java
  11. 2
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/validation/RoundChangeMessageValidator.java
  12. 4
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/ibftmessagedata/NewRoundPayloadTest.java
  13. 4
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/ibftmessagedata/RoundChangeCertificateTest.java
  14. 6
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/ibftmessagedata/RoundChangePayloadTest.java
  15. 2
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/validation/NewRoundMessageValidatorTest.java

@ -22,7 +22,7 @@ import tech.pegasys.pantheon.ethereum.rlp.RLPOutput;
import java.util.Objects;
import java.util.StringJoiner;
public class CommitPayload implements InRoundPayload {
public class CommitPayload implements Payload {
private static final int TYPE = IbftV2.COMMIT;
private final ConsensusRoundIdentifier roundIdentifier;
private final Hash digest;

@ -1,19 +0,0 @@
/*
* 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.ibftmessagedata;
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
public interface InRoundPayload extends Payload {
ConsensusRoundIdentifier getRoundIdentifier();
}

@ -36,7 +36,8 @@ public class NewRoundPayload implements Payload {
this.proposalPayload = proposalPayload;
}
public ConsensusRoundIdentifier getRoundChangeIdentifier() {
@Override
public ConsensusRoundIdentifier getRoundIdentifier() {
return roundChangeIdentifier;
}

@ -12,6 +12,7 @@
*/
package tech.pegasys.pantheon.consensus.ibft.ibftmessagedata;
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.ethereum.core.Hash;
import tech.pegasys.pantheon.ethereum.rlp.BytesValueRLPOutput;
import tech.pegasys.pantheon.ethereum.rlp.RLPInput;
@ -22,6 +23,8 @@ public interface Payload {
void writeTo(final RLPOutput rlpOutput);
ConsensusRoundIdentifier getRoundIdentifier();
default BytesValue encoded() {
BytesValueRLPOutput rlpOutput = new BytesValueRLPOutput();
writeTo(rlpOutput);

@ -21,7 +21,7 @@ import tech.pegasys.pantheon.ethereum.rlp.RLPOutput;
import java.util.Objects;
import java.util.StringJoiner;
public class PreparePayload implements InRoundPayload {
public class PreparePayload implements Payload {
private static final int TYPE = IbftV2.PREPARE;
private final ConsensusRoundIdentifier roundIdentifier;
private final Hash digest;

@ -22,7 +22,7 @@ import tech.pegasys.pantheon.ethereum.rlp.RLPOutput;
import java.util.Objects;
import java.util.StringJoiner;
public class ProposalPayload implements InRoundPayload {
public class ProposalPayload implements Payload {
private static final int TYPE = IbftV2.PROPOSAL;
private final ConsensusRoundIdentifier roundIdentifier;
private final Block block;

@ -35,7 +35,8 @@ public class RoundChangePayload implements Payload {
this.preparedCertificate = preparedCertificate;
}
public ConsensusRoundIdentifier getRoundChangeIdentifier() {
@Override
public ConsensusRoundIdentifier getRoundIdentifier() {
return roundChangeIdentifier;
}

@ -121,7 +121,7 @@ public class RoundChangeManager {
}
private RoundChangeStatus storeRoundChangeMessage(final SignedData<RoundChangePayload> msg) {
final ConsensusRoundIdentifier msgTargetRound = msg.getPayload().getRoundChangeIdentifier();
final ConsensusRoundIdentifier msgTargetRound = msg.getPayload().getRoundIdentifier();
final RoundChangeStatus roundChangeStatus =
roundChangeCache.computeIfAbsent(

@ -18,7 +18,7 @@ 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.ibftmessagedata.CommitPayload;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.InRoundPayload;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.Payload;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.PreparePayload;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.ProposalPayload;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.SignedData;
@ -159,7 +159,7 @@ public class MessageValidator {
}
private boolean isMessageForCurrentRoundFromValidatorAndProposalAvailable(
final SignedData<? extends InRoundPayload> msg, final String msgType) {
final SignedData<? extends Payload> msg, final String msgType) {
if (!msg.getPayload().getRoundIdentifier().equals(roundIdentifier)) {
LOG.info("Invalid {} message, does not match current round.", msgType);

@ -55,7 +55,7 @@ public class NewRoundMessageValidator {
public boolean validateNewRoundMessage(final SignedData<NewRoundPayload> msg) {
final NewRoundPayload payload = msg.getPayload();
final ConsensusRoundIdentifier rootRoundIdentifier = payload.getRoundChangeIdentifier();
final ConsensusRoundIdentifier rootRoundIdentifier = payload.getRoundIdentifier();
final Address expectedProposer = proposerSelector.selectProposerForRound(rootRoundIdentifier);
final RoundChangeCertificate roundChangeCert = payload.getRoundChangeCertificate();
@ -64,12 +64,12 @@ public class NewRoundMessageValidator {
return false;
}
if (msg.getPayload().getRoundChangeIdentifier().getSequenceNumber() != chainHeight) {
if (msg.getPayload().getRoundIdentifier().getSequenceNumber() != chainHeight) {
LOG.info("Invalid NewRound message, not valid for local chain height.");
return false;
}
if (msg.getPayload().getRoundChangeIdentifier().getRoundNumber() == 0) {
if (msg.getPayload().getRoundIdentifier().getRoundNumber() == 0) {
LOG.info("Invalid NewRound message, illegally targets a new round of 0.");
return false;
}
@ -110,7 +110,7 @@ public class NewRoundMessageValidator {
if (!roundChangeCert
.getRoundChangePayloads()
.stream()
.allMatch(p -> p.getPayload().getRoundChangeIdentifier().equals(expectedRound))) {
.allMatch(p -> p.getPayload().getRoundIdentifier().equals(expectedRound))) {
LOG.info(
"Invalid NewRound message, not all embedded RoundChange messages have a "
+ "matching target round.");

@ -54,7 +54,7 @@ public class RoundChangeMessageValidator {
return false;
}
final ConsensusRoundIdentifier targetRound = msg.getPayload().getRoundChangeIdentifier();
final ConsensusRoundIdentifier targetRound = msg.getPayload().getRoundIdentifier();
if (targetRound.getSequenceNumber() != chainHeight) {
LOG.info("Invalid RoundChange message, not valid for local chain height.");

@ -54,7 +54,7 @@ public class NewRoundPayloadTest {
final NewRoundPayload newRoundPayload = NewRoundPayload.readFrom(rlpInput);
assertThat(newRoundPayload.getProposalPayload()).isEqualTo(proposalPayloadSignedData);
assertThat(newRoundPayload.getRoundChangeCertificate()).isEqualTo(roundChangeCertificate);
assertThat(newRoundPayload.getRoundChangeIdentifier()).isEqualTo(ROUND_IDENTIFIER);
assertThat(newRoundPayload.getRoundIdentifier()).isEqualTo(ROUND_IDENTIFIER);
assertThat(newRoundPayload.getMessageType()).isEqualTo(IbftV2.NEW_ROUND);
}
@ -87,7 +87,7 @@ public class NewRoundPayloadTest {
final NewRoundPayload newRoundPayload = NewRoundPayload.readFrom(rlpInput);
assertThat(newRoundPayload.getProposalPayload()).isEqualTo(signedProposal);
assertThat(newRoundPayload.getRoundChangeCertificate()).isEqualTo(roundChangeCertificate);
assertThat(newRoundPayload.getRoundChangeIdentifier()).isEqualTo(ROUND_IDENTIFIER);
assertThat(newRoundPayload.getRoundIdentifier()).isEqualTo(ROUND_IDENTIFIER);
assertThat(newRoundPayload.getMessageType()).isEqualTo(IbftV2.NEW_ROUND);
}
}

@ -45,7 +45,7 @@ public class RoundChangeCertificateTest {
RoundChangePayload actualRoundChangePayload = RoundChangePayload.readFrom(rlpInput);
assertThat(actualRoundChangePayload.getPreparedCertificate()).isEqualTo(Optional.empty());
assertThat(actualRoundChangePayload.getRoundChangeIdentifier()).isEqualTo(ROUND_IDENTIFIER);
assertThat(actualRoundChangePayload.getRoundIdentifier()).isEqualTo(ROUND_IDENTIFIER);
assertThat(actualRoundChangePayload.getMessageType()).isEqualTo(IbftV2.ROUND_CHANGE);
}
@ -73,7 +73,7 @@ public class RoundChangeCertificateTest {
assertThat(actualRoundChangePayload.getPreparedCertificate())
.isEqualTo(Optional.of(preparedCert));
assertThat(actualRoundChangePayload.getRoundChangeIdentifier()).isEqualTo(ROUND_IDENTIFIER);
assertThat(actualRoundChangePayload.getRoundIdentifier()).isEqualTo(ROUND_IDENTIFIER);
assertThat(actualRoundChangePayload.getMessageType()).isEqualTo(IbftV2.ROUND_CHANGE);
}
}

@ -46,7 +46,7 @@ public class RoundChangePayloadTest {
final RLPInput rlpInput = RLP.input(rlpOut.encoded());
RoundChangePayload actualRoundChangePayload = RoundChangePayload.readFrom(rlpInput);
assertThat(actualRoundChangePayload.getRoundChangeIdentifier()).isEqualTo(ROUND_IDENTIFIER);
assertThat(actualRoundChangePayload.getRoundIdentifier()).isEqualTo(ROUND_IDENTIFIER);
assertThat(actualRoundChangePayload.getPreparedCertificate()).isEqualTo(Optional.empty());
assertThat(actualRoundChangePayload.getMessageType()).isEqualTo(IbftV2.ROUND_CHANGE);
}
@ -65,7 +65,7 @@ public class RoundChangePayloadTest {
final RLPInput rlpInput = RLP.input(rlpOut.encoded());
RoundChangePayload actualRoundChangePayload = RoundChangePayload.readFrom(rlpInput);
assertThat(actualRoundChangePayload.getRoundChangeIdentifier()).isEqualTo(ROUND_IDENTIFIER);
assertThat(actualRoundChangePayload.getRoundIdentifier()).isEqualTo(ROUND_IDENTIFIER);
assertThat(actualRoundChangePayload.getPreparedCertificate())
.isEqualTo(Optional.of(preparedCertificate));
assertThat(actualRoundChangePayload.getMessageType()).isEqualTo(IbftV2.ROUND_CHANGE);
@ -88,7 +88,7 @@ public class RoundChangePayloadTest {
final RLPInput rlpInput = RLP.input(rlpOut.encoded());
RoundChangePayload actualRoundChangePayload = RoundChangePayload.readFrom(rlpInput);
assertThat(actualRoundChangePayload.getRoundChangeIdentifier()).isEqualTo(ROUND_IDENTIFIER);
assertThat(actualRoundChangePayload.getRoundIdentifier()).isEqualTo(ROUND_IDENTIFIER);
assertThat(actualRoundChangePayload.getPreparedCertificate())
.isEqualTo(Optional.of(preparedCert));
assertThat(actualRoundChangePayload.getMessageType()).isEqualTo(IbftV2.ROUND_CHANGE);

@ -109,7 +109,7 @@ public class NewRoundMessageValidatorTest {
final MessageFactory messageCreator = new MessageFactory(signingKey);
return messageCreator.createSignedNewRoundPayload(
payload.getRoundChangeIdentifier(),
payload.getRoundIdentifier(),
payload.getRoundChangeCertificate(),
payload.getProposalPayload());
}

Loading…
Cancel
Save