Updated IbftRound and RoudnState APIs to use wrapped messages (#740)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
tmohay 6 years ago committed by GitHub
parent bdb5e8367f
commit e388de7b4e
  1. 11
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftBlockHeightManager.java
  2. 62
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftRound.java
  3. 41
      consensus/ibft/src/main/java/tech/pegasys/pantheon/consensus/ibft/statemachine/RoundState.java
  4. 40
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/IbftRoundTest.java
  5. 120
      consensus/ibft/src/test/java/tech/pegasys/pantheon/consensus/ibft/statemachine/RoundStateTest.java

@ -31,7 +31,6 @@ 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.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.validation.MessageValidatorFactory;
import tech.pegasys.pantheon.consensus.ibft.validation.NewRoundMessageValidator;
import tech.pegasys.pantheon.ethereum.core.BlockHeader;
@ -177,18 +176,18 @@ public class IbftBlockHeightManager implements BlockHeightManager {
private <P extends Payload, M extends IbftMessage<P>> void actionOrBufferMessage(
final M ibftMessage,
final Consumer<SignedData<P>> inRoundHandler,
final BiConsumer<RoundState, SignedData<P>> buffer) {
final Consumer<M> inRoundHandler,
final BiConsumer<RoundState, M> buffer) {
final MessageAge messageAge =
determineAgeOfPayload(ibftMessage.getRoundIdentifier().getRoundNumber());
if (messageAge == CURRENT_ROUND) {
inRoundHandler.accept(ibftMessage.getSignedPayload());
inRoundHandler.accept(ibftMessage);
} else if (messageAge == FUTURE_ROUND) {
final ConsensusRoundIdentifier msgRoundId = ibftMessage.getRoundIdentifier();
final RoundState roundstate =
futureRoundStateBuffer.computeIfAbsent(
msgRoundId.getRoundNumber(), k -> roundStateCreator.apply(msgRoundId));
buffer.accept(roundstate, ibftMessage.getSignedPayload());
buffer.accept(roundstate, ibftMessage);
}
}
@ -248,7 +247,7 @@ public class IbftBlockHeightManager implements BlockHeightManager {
if (messageAge == FUTURE_ROUND) {
startNewRound(newRound.getRoundIdentifier().getRoundNumber());
}
currentRound.handleProposalFromNewRound(newRound.getSignedPayload());
currentRound.handleProposalFromNewRound(newRound);
}
}

@ -20,15 +20,14 @@ import tech.pegasys.pantheon.consensus.ibft.IbftContext;
import tech.pegasys.pantheon.consensus.ibft.IbftExtraData;
import tech.pegasys.pantheon.consensus.ibft.IbftHelpers;
import tech.pegasys.pantheon.consensus.ibft.blockcreation.IbftBlockCreator;
import tech.pegasys.pantheon.consensus.ibft.messagewrappers.Commit;
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.network.IbftMessageTransmitter;
import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.NewRoundPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparePayload;
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.crypto.SECP256K1;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
import tech.pegasys.pantheon.crypto.SECP256K1.Signature;
@ -94,7 +93,8 @@ public class IbftRound {
transmitter.multicastProposal(roundState.getRoundIdentifier(), block);
updateStateWithProposedBlock(
messageFactory.createSignedProposalPayload(roundState.getRoundIdentifier(), block));
new Proposal(
messageFactory.createSignedProposalPayload(roundState.getRoundIdentifier(), block)));
}
public void startRoundWith(
@ -102,22 +102,24 @@ public class IbftRound {
final Optional<PreparedCertificate> latestCertificate =
findLatestPreparedCertificate(roundChangeCertificate.getRoundChangePayloads());
SignedData<ProposalPayload> proposal;
Proposal proposal;
if (!latestCertificate.isPresent()) {
LOG.trace("Multicasting NewRound with new block. round={}", roundState.getRoundIdentifier());
final Block block = blockCreator.createBlock(headerTimestamp);
proposal = messageFactory.createSignedProposalPayload(getRoundIdentifier(), block);
proposal =
new Proposal(messageFactory.createSignedProposalPayload(getRoundIdentifier(), block));
} else {
LOG.trace(
"Multicasting NewRound from PreparedCertificate. round={}",
roundState.getRoundIdentifier());
proposal = createProposalFromPreparedCertificate(latestCertificate.get());
}
transmitter.multicastNewRound(getRoundIdentifier(), roundChangeCertificate, proposal);
transmitter.multicastNewRound(
getRoundIdentifier(), roundChangeCertificate, proposal.getSignedPayload());
updateStateWithProposedBlock(proposal);
}
private SignedData<ProposalPayload> createProposalFromPreparedCertificate(
private Proposal createProposalFromPreparedCertificate(
final PreparedCertificate preparedCertificate) {
final Block block = preparedCertificate.getProposalPayload().getPayload().getBlock();
@ -143,10 +145,10 @@ public class IbftRound {
"Created proposal from prepared certificate blockHeader={} extraData={}",
block.getHeader(),
extraDataToPublish);
return messageFactory.createSignedProposalPayload(getRoundIdentifier(), newBlock);
return new Proposal(messageFactory.createSignedProposalPayload(getRoundIdentifier(), newBlock));
}
public void handleProposalMessage(final SignedData<ProposalPayload> msg) {
public void handleProposalMessage(final Proposal msg) {
LOG.info("Handling a Proposal message.");
if (getRoundIdentifier().getRoundNumber() != 0) {
@ -156,35 +158,36 @@ public class IbftRound {
actionReceivedProposal(msg);
}
public void handleProposalFromNewRound(final SignedData<NewRoundPayload> msg) {
public void handleProposalFromNewRound(final NewRound msg) {
LOG.info("Handling a New Round Proposal.");
if (getRoundIdentifier().getRoundNumber() == 0) {
LOG.error("Illegally received a NewRound message when in Round 0.");
return;
}
actionReceivedProposal(msg.getPayload().getProposalPayload());
actionReceivedProposal(new Proposal(msg.getSignedPayload().getPayload().getProposalPayload()));
}
private void actionReceivedProposal(final SignedData<ProposalPayload> msg) {
final Block block = msg.getPayload().getBlock();
private void actionReceivedProposal(final Proposal msg) {
final Block block = msg.getSignedPayload().getPayload().getBlock();
if (updateStateWithProposedBlock(msg)) {
LOG.info("Sending prepare message.");
transmitter.multicastPrepare(getRoundIdentifier(), block.getHash());
final SignedData<PreparePayload> localPrepareMessage =
messageFactory.createSignedPreparePayload(
roundState.getRoundIdentifier(), block.getHash());
final Prepare localPrepareMessage =
new Prepare(
messageFactory.createSignedPreparePayload(
roundState.getRoundIdentifier(), block.getHash()));
peerIsPrepared(localPrepareMessage);
}
}
public void handlePrepareMessage(final SignedData<PreparePayload> msg) {
public void handlePrepareMessage(final Prepare msg) {
LOG.debug("Received a prepare message. round={}", roundState.getRoundIdentifier());
peerIsPrepared(msg);
}
public void handleCommitMessage(final SignedData<CommitPayload> msg) {
public void handleCommitMessage(final Commit msg) {
LOG.debug("Received a commit message. round={}", roundState.getRoundIdentifier());
peerIsCommitted(msg);
}
@ -193,7 +196,7 @@ public class IbftRound {
return roundState.constructPreparedCertificate();
}
private boolean updateStateWithProposedBlock(final SignedData<ProposalPayload> msg) {
private boolean updateStateWithProposedBlock(final Proposal msg) {
final boolean wasPrepared = roundState.isPrepared();
final boolean wasCommitted = roundState.isCommitted();
final boolean blockAccepted = roundState.setProposedBlock(msg);
@ -208,18 +211,19 @@ public class IbftRound {
importBlockToChain();
}
final SignedData<CommitPayload> localCommitMessage =
messageFactory.createSignedCommitPayload(
roundState.getRoundIdentifier(),
msg.getPayload().getBlock().getHash(),
createCommitSeal(roundState.getProposedBlock().get()));
final Commit localCommitMessage =
new Commit(
messageFactory.createSignedCommitPayload(
roundState.getRoundIdentifier(),
msg.getSignedPayload().getPayload().getBlock().getHash(),
createCommitSeal(roundState.getProposedBlock().get())));
peerIsCommitted(localCommitMessage);
}
return blockAccepted;
}
private void peerIsPrepared(final SignedData<PreparePayload> msg) {
private void peerIsPrepared(final Prepare msg) {
final boolean wasPrepared = roundState.isPrepared();
roundState.addPrepareMessage(msg);
if (wasPrepared != roundState.isPrepared()) {
@ -229,7 +233,7 @@ public class IbftRound {
}
}
private void peerIsCommitted(final SignedData<CommitPayload> msg) {
private void peerIsCommitted(final Commit msg) {
final boolean wasCommitted = roundState.isCommitted();
roundState.addCommitMessage(msg);
if (wasCommitted != roundState.isCommitted()) {

@ -15,11 +15,10 @@ package tech.pegasys.pantheon.consensus.ibft.statemachine;
import static tech.pegasys.pantheon.consensus.ibft.IbftHelpers.prepareMessageCountForQuorum;
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparePayload;
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.PreparedCertificate;
import tech.pegasys.pantheon.consensus.ibft.payload.ProposalPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.validation.MessageValidator;
import tech.pegasys.pantheon.crypto.SECP256K1.Signature;
import tech.pegasys.pantheon.ethereum.core.Block;
@ -41,12 +40,12 @@ public class RoundState {
private final MessageValidator validator;
private final long quorum;
private Optional<SignedData<ProposalPayload>> proposalMessage = Optional.empty();
private Optional<Proposal> proposalMessage = Optional.empty();
// Must track the actual Prepare message, not just the sender, as these may need to be reused
// to send out in a PrepareCertificate.
private final Set<SignedData<PreparePayload>> preparePayloads = Sets.newLinkedHashSet();
private final Set<SignedData<CommitPayload>> commitPayloads = Sets.newLinkedHashSet();
private final Set<Prepare> preparePayloads = Sets.newLinkedHashSet();
private final Set<Commit> commitPayloads = Sets.newLinkedHashSet();
private boolean prepared = false;
private boolean committed = false;
@ -64,13 +63,13 @@ public class RoundState {
return roundIdentifier;
}
public boolean setProposedBlock(final SignedData<ProposalPayload> msg) {
public boolean setProposedBlock(final Proposal msg) {
if (!proposalMessage.isPresent()) {
if (validator.addSignedProposalPayload(msg)) {
if (validator.addSignedProposalPayload(msg.getSignedPayload())) {
proposalMessage = Optional.of(msg);
preparePayloads.removeIf(p -> !validator.validatePrepareMessage(p));
commitPayloads.removeIf(p -> !validator.validateCommmitMessage(p));
preparePayloads.removeIf(p -> !validator.validatePrepareMessage(p.getSignedPayload()));
commitPayloads.removeIf(p -> !validator.validateCommmitMessage(p.getSignedPayload()));
updateState();
return true;
}
@ -79,16 +78,16 @@ public class RoundState {
return false;
}
public void addPrepareMessage(final SignedData<PreparePayload> msg) {
if (!proposalMessage.isPresent() || validator.validatePrepareMessage(msg)) {
public void addPrepareMessage(final Prepare msg) {
if (!proposalMessage.isPresent() || validator.validatePrepareMessage(msg.getSignedPayload())) {
preparePayloads.add(msg);
LOG.debug("Round state added prepare message prepare={}", msg);
}
updateState();
}
public void addCommitMessage(final SignedData<CommitPayload> msg) {
if (!proposalMessage.isPresent() || validator.validateCommmitMessage(msg)) {
public void addCommitMessage(final Commit msg) {
if (!proposalMessage.isPresent() || validator.validateCommmitMessage(msg.getSignedPayload())) {
commitPayloads.add(msg);
LOG.debug("Round state added commit message commit={}", msg);
}
@ -111,7 +110,7 @@ public class RoundState {
}
public Optional<Block> getProposedBlock() {
return proposalMessage.map(p -> p.getPayload().getBlock());
return proposalMessage.map(p -> p.getSignedPayload().getPayload().getBlock());
}
public boolean isPrepared() {
@ -125,13 +124,19 @@ public class RoundState {
public Collection<Signature> getCommitSeals() {
return commitPayloads
.stream()
.map(cp -> cp.getPayload().getCommitSeal())
.map(cp -> cp.getSignedPayload().getPayload().getCommitSeal())
.collect(Collectors.toList());
}
public Optional<PreparedCertificate> constructPreparedCertificate() {
if (isPrepared()) {
return Optional.of(new PreparedCertificate(proposalMessage.get(), preparePayloads));
return Optional.of(
new PreparedCertificate(
proposalMessage.get().getSignedPayload(),
preparePayloads
.stream()
.map(Prepare::getSignedPayload)
.collect(Collectors.toList())));
}
return Optional.empty();
}

@ -28,6 +28,9 @@ import tech.pegasys.pantheon.consensus.ibft.IbftBlockHashing;
import tech.pegasys.pantheon.consensus.ibft.IbftContext;
import tech.pegasys.pantheon.consensus.ibft.IbftExtraData;
import tech.pegasys.pantheon.consensus.ibft.blockcreation.IbftBlockCreator;
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.network.IbftMessageTransmitter;
import tech.pegasys.pantheon.consensus.ibft.payload.MessageFactory;
import tech.pegasys.pantheon.consensus.ibft.payload.PreparedCertificate;
@ -137,7 +140,7 @@ public class IbftRoundTest {
transmitter);
round.handleProposalMessage(
messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock));
new Proposal(messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock)));
verify(transmitter, times(1)).multicastPrepare(roundIdentifier, proposedBlock.getHash());
verify(transmitter, never()).multicastCommit(any(), any(), any());
}
@ -203,7 +206,7 @@ public class IbftRoundTest {
// Receive Proposal Message
round.handleProposalMessage(
messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock));
new Proposal(messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock)));
verify(transmitter, times(1)).multicastPrepare(roundIdentifier, proposedBlock.getHash());
verify(transmitter, times(1))
.multicastCommit(roundIdentifier, proposedBlock.getHash(), localCommitSeal);
@ -212,8 +215,9 @@ public class IbftRoundTest {
// Receive Commit Message
round.handleCommitMessage(
messageFactory.createSignedCommitPayload(
roundIdentifier, proposedBlock.getHash(), remoteCommitSeal));
new Commit(
messageFactory.createSignedCommitPayload(
roundIdentifier, proposedBlock.getHash(), remoteCommitSeal)));
// Should import block when both commit seals are available.
ArgumentCaptor<Block> capturedBlock = ArgumentCaptor.forClass(Block.class);
@ -249,15 +253,17 @@ public class IbftRoundTest {
verify(blockImporter, never()).importBlock(any(), any(), any());
round.handlePrepareMessage(
messageFactory.createSignedPreparePayload(roundIdentifier, proposedBlock.getHash()));
new Prepare(
messageFactory.createSignedPreparePayload(roundIdentifier, proposedBlock.getHash())));
verify(transmitter, times(1))
.multicastCommit(roundIdentifier, proposedBlock.getHash(), localCommitSeal);
verify(blockImporter, never()).importBlock(any(), any(), any());
round.handleCommitMessage(
messageFactory.createSignedCommitPayload(
roundIdentifier, proposedBlock.getHash(), remoteCommitSeal));
new Commit(
messageFactory.createSignedCommitPayload(
roundIdentifier, proposedBlock.getHash(), remoteCommitSeal)));
verify(blockImporter, times(1)).importBlock(any(), any(), any());
}
@ -324,7 +330,8 @@ public class IbftRoundTest {
// Inject a single Prepare message, and confirm the roundState has gone to Prepared (which
// indicates the block has entered the roundState (note: all msgs are deemed valid due to mocks)
round.handlePrepareMessage(
messageFactory.createSignedPreparePayload(roundIdentifier, proposedBlock.getHash()));
new Prepare(
messageFactory.createSignedPreparePayload(roundIdentifier, proposedBlock.getHash())));
assertThat(roundState.isPrepared()).isTrue();
}
@ -355,7 +362,8 @@ public class IbftRoundTest {
// Inject a single Prepare message, and confirm the roundState has gone to Prepared (which
// indicates the block has entered the roundState (note: all msgs are deemed valid due to mocks)
round.handlePrepareMessage(
messageFactory.createSignedPreparePayload(roundIdentifier, proposedBlock.getHash()));
new Prepare(
messageFactory.createSignedPreparePayload(roundIdentifier, proposedBlock.getHash())));
assertThat(roundState.isPrepared()).isTrue();
}
@ -393,11 +401,12 @@ public class IbftRoundTest {
transmitter);
round.handleCommitMessage(
messageFactory.createSignedCommitPayload(
roundIdentifier, proposedBlock.getHash(), remoteCommitSeal));
new Commit(
messageFactory.createSignedCommitPayload(
roundIdentifier, proposedBlock.getHash(), remoteCommitSeal)));
round.handleProposalMessage(
messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock));
new Proposal(messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock)));
verify(blockImporter, times(1)).importBlock(any(), any(), any());
}
@ -418,11 +427,12 @@ public class IbftRoundTest {
transmitter);
round.handleCommitMessage(
messageFactory.createSignedCommitPayload(
roundIdentifier, proposedBlock.getHash(), remoteCommitSeal));
new Commit(
messageFactory.createSignedCommitPayload(
roundIdentifier, proposedBlock.getHash(), remoteCommitSeal)));
round.handleProposalMessage(
messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock));
new Proposal(messageFactory.createSignedProposalPayload(roundIdentifier, proposedBlock)));
verify(blockImporter, times(1)).importBlock(any(), any(), any());
}

@ -19,10 +19,11 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import tech.pegasys.pantheon.consensus.ibft.ConsensusRoundIdentifier;
import tech.pegasys.pantheon.consensus.ibft.payload.CommitPayload;
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.PreparePayload;
import tech.pegasys.pantheon.consensus.ibft.payload.ProposalPayload;
import tech.pegasys.pantheon.consensus.ibft.payload.SignedData;
import tech.pegasys.pantheon.consensus.ibft.validation.MessageValidator;
import tech.pegasys.pantheon.crypto.SECP256K1.KeyPair;
@ -80,8 +81,9 @@ public class RoundStateTest {
when(messageValidator.addSignedProposalPayload(any())).thenReturn(false);
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator);
final SignedData<ProposalPayload> proposal =
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block);
final Proposal proposal =
new Proposal(
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block));
assertThat(roundState.setProposedBlock(proposal)).isFalse();
assertThat(roundState.isPrepared()).isFalse();
@ -94,15 +96,16 @@ public class RoundStateTest {
when(messageValidator.addSignedProposalPayload(any())).thenReturn(true);
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator);
final SignedData<ProposalPayload> proposal =
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block);
final Proposal proposal =
new Proposal(
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block));
assertThat(roundState.setProposedBlock(proposal)).isTrue();
assertThat(roundState.isPrepared()).isTrue();
assertThat(roundState.isCommitted()).isFalse();
assertThat(roundState.constructPreparedCertificate()).isNotEmpty();
assertThat(roundState.constructPreparedCertificate().get().getProposalPayload())
.isEqualTo(proposal);
.isEqualTo(proposal.getSignedPayload());
}
@Test
@ -112,20 +115,22 @@ public class RoundStateTest {
final RoundState roundState = new RoundState(roundIdentifier, 1, messageValidator);
final SignedData<ProposalPayload> proposal =
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block);
final Proposal proposal =
new Proposal(
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block));
assertThat(roundState.setProposedBlock(proposal)).isTrue();
assertThat(roundState.isPrepared()).isTrue();
assertThat(roundState.isCommitted()).isFalse();
final SignedData<CommitPayload> commit =
validatorMessageFactories
.get(0)
.createSignedCommitPayload(
roundIdentifier,
block.getHash(),
Signature.create(BigInteger.ONE, BigInteger.ONE, (byte) 1));
final Commit commit =
new Commit(
validatorMessageFactories
.get(0)
.createSignedCommitPayload(
roundIdentifier,
block.getHash(),
Signature.create(BigInteger.ONE, BigInteger.ONE, (byte) 1)));
roundState.addCommitMessage(commit);
assertThat(roundState.isPrepared()).isTrue();
@ -140,15 +145,17 @@ public class RoundStateTest {
final RoundState roundState = new RoundState(roundIdentifier, 3, messageValidator);
final SignedData<PreparePayload> firstPrepare =
validatorMessageFactories
.get(1)
.createSignedPreparePayload(roundIdentifier, block.getHash());
final Prepare firstPrepare =
new Prepare(
validatorMessageFactories
.get(1)
.createSignedPreparePayload(roundIdentifier, block.getHash()));
final SignedData<PreparePayload> secondPrepare =
validatorMessageFactories
.get(2)
.createSignedPreparePayload(roundIdentifier, block.getHash());
final Prepare secondPrepare =
new Prepare(
validatorMessageFactories
.get(2)
.createSignedPreparePayload(roundIdentifier, block.getHash()));
roundState.addPrepareMessage(firstPrepare);
assertThat(roundState.isPrepared()).isFalse();
@ -160,8 +167,9 @@ public class RoundStateTest {
assertThat(roundState.isCommitted()).isFalse();
assertThat(roundState.constructPreparedCertificate()).isEmpty();
final SignedData<ProposalPayload> proposal =
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block);
final Proposal proposal =
new Proposal(
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block));
assertThat(roundState.setProposedBlock(proposal)).isTrue();
assertThat(roundState.isPrepared()).isTrue();
assertThat(roundState.isCommitted()).isFalse();
@ -188,12 +196,13 @@ public class RoundStateTest {
when(messageValidator.validatePrepareMessage(firstPrepare)).thenReturn(true);
when(messageValidator.validatePrepareMessage(secondPrepare)).thenReturn(false);
roundState.addPrepareMessage(firstPrepare);
roundState.addPrepareMessage(secondPrepare);
roundState.addPrepareMessage(new Prepare(firstPrepare));
roundState.addPrepareMessage(new Prepare(secondPrepare));
verify(messageValidator, never()).validatePrepareMessage(any());
final SignedData<ProposalPayload> proposal =
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block);
final Proposal proposal =
new Proposal(
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block));
assertThat(roundState.setProposedBlock(proposal)).isTrue();
assertThat(roundState.isPrepared()).isFalse();
@ -215,8 +224,9 @@ public class RoundStateTest {
.get(2)
.createSignedPreparePayload(roundIdentifier, block.getHash());
final SignedData<ProposalPayload> proposal =
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block);
final Proposal proposal =
new Proposal(
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block));
when(messageValidator.addSignedProposalPayload(any())).thenReturn(true);
when(messageValidator.validatePrepareMessage(firstPrepare)).thenReturn(false);
@ -225,10 +235,10 @@ public class RoundStateTest {
roundState.setProposedBlock(proposal);
assertThat(roundState.isPrepared()).isFalse();
roundState.addPrepareMessage(firstPrepare);
roundState.addPrepareMessage(new Prepare(firstPrepare));
assertThat(roundState.isPrepared()).isFalse();
roundState.addPrepareMessage(secondPrepare);
roundState.addPrepareMessage(new Prepare(secondPrepare));
assertThat(roundState.isPrepared()).isTrue();
}
@ -239,24 +249,27 @@ public class RoundStateTest {
final RoundState roundState = new RoundState(roundIdentifier, 2, messageValidator);
final SignedData<CommitPayload> firstCommit =
validatorMessageFactories
.get(1)
.createSignedCommitPayload(
roundIdentifier,
block.getHash(),
Signature.create(BigInteger.ONE, BigInteger.TEN, (byte) 1));
final SignedData<CommitPayload> secondCommit =
validatorMessageFactories
.get(2)
.createSignedCommitPayload(
roundIdentifier,
block.getHash(),
Signature.create(BigInteger.TEN, BigInteger.TEN, (byte) 1));
final SignedData<ProposalPayload> proposal =
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block);
final Commit firstCommit =
new Commit(
validatorMessageFactories
.get(1)
.createSignedCommitPayload(
roundIdentifier,
block.getHash(),
Signature.create(BigInteger.ONE, BigInteger.TEN, (byte) 1)));
final Commit secondCommit =
new Commit(
validatorMessageFactories
.get(2)
.createSignedCommitPayload(
roundIdentifier,
block.getHash(),
Signature.create(BigInteger.TEN, BigInteger.TEN, (byte) 1)));
final Proposal proposal =
new Proposal(
validatorMessageFactories.get(0).createSignedProposalPayload(roundIdentifier, block));
roundState.setProposedBlock(proposal);
roundState.addCommitMessage(firstCommit);
@ -266,6 +279,7 @@ public class RoundStateTest {
assertThat(roundState.getCommitSeals())
.containsOnly(
firstCommit.getPayload().getCommitSeal(), secondCommit.getPayload().getCommitSeal());
firstCommit.getSignedPayload().getPayload().getCommitSeal(),
secondCommit.getSignedPayload().getPayload().getCommitSeal());
}
}

Loading…
Cancel
Save